Skip to content. | Skip to navigation

Personal tools

edslog.cpp

edslog.cpp

edslog.cpp

/////////////////////////////////////////////////////////////////////////////
// EDSLOG.CPP
//
//  Last updated: 07/08/2003
//
//  This file contains code to implement the Engineering Data Stream (EDS)
//  log.
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CEDSLog::Init: Initialize the log
void CEDSLog::Init(int logSize)
{
// Pass the maximum number of log entries in logSize (Usually 100)

	int i;

	LogSize = logSize;
	// Dynamically allocate log arrays
	Data = new edsstr[logSize];
	// Initialize log to empty strings
	for (i=0;i<LogSize;i++)
		Data[i][0] = 0;
	Index = 0;
	LastIndex = -1;
	Last = 0;
	EDSTime = 0;
	EDSTimeIR = 0;
}

/////////////////////////////////////////////////////////////////////////////
// CEDSLog::Add - Add a log entry
void CEDSLog::Add(int messagenum,char* data,...)
{
// This routine adds the string in "data" to the running log.
	char s[1000],s2[1000];
	va_list va;
	struct dostime_t t;

	// Store the message
	va_start(va,data);
	vsprintf(s2,data,va);
	va_end(va);

	// Add the EDSLog entry to the main log
	if (messagenum < 800)
		Log.AddX(s2,messagenum,SHECRED,0);		// 0-799 are errors
	else if (messagenum >= 900)
		Log.AddX(s2,messagenum,SHECGREEN,0);	// 900-999 are successes
	else
		Log.AddX(s2,messagenum,SHECGREEN,1);  // 800-899 are low level data

	// Time stamp and add a message number to the message
	gettime(&t);
	sprintf(s,"%02d%02d%02d%02d%03d%s",t.hour,t.minute,t.second,
		t.hsecond,messagenum,s2);

	// Insure that the log entry isn't longer than 90 chars
	// (leave room for checksum, CR, etc.)
	s[90] = 0;

	// Copy the string into the queue
	strcpy(Data[Last],s);

	// Adjust log indices
	Last++;
	if (Last >= LogSize)
		Last = 0;
	if (Last == LastIndex)
		LastIndex = -1;
	if (Last == Index)
		Index++;
	if (Index >= LogSize)
		Index = 0;
}

/////////////////////////////////////////////////////////////////////////////
// CEDSLog::SendNextMessage - Take the first message out of the queue and send
void CEDSLog::SendNextMessage()
{
	int MessageCount;
	int Checksum;
	int MessageLength;
	int i;
	char s[120],s2[120];

	MessageCount = Last - Index;
	if (MessageCount < 0)
		MessageCount += LogSize;
	if (MessageCount == 0)
	{
		MessageLength = 0;
		sprintf(s,"2%02d%02d",MessageCount,MessageLength);
	}
	else
	{
		MessageLength = strlen(Data[Index]);
		sprintf(s,"2%02d%02d%s",MessageCount,MessageLength,Data[Index]);
	}
	RespondToHostWithChecksum(s);
	if (MessageCount == 0)
		LastIndex = -1;
	else
	{
		LastIndex = Index;
		Index++;
		if (Index >= LogSize)
			Index = 0;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CEDSLog::RepeatLastMessage - Repeat the last message
void CEDSLog::RepeatLastMessage()
{
	int MessageCount;
	int Checksum;
	int MessageLength;
	int i;
	char s[120],s2[120];

	MessageCount = Last - Index;
	if (MessageCount < 0)
		MessageCount += LogSize;
	if ((MessageCount == 0) || (LastIndex == -1))
		sprintf(s,"30000");
	else
	{
		MessageLength = strlen(Data[LastIndex]);
		sprintf(s,"3%02d%02d%s",MessageCount,MessageLength,Data[LastIndex]);
	}
	RespondToHostWithChecksum(s);
}

/////////////////////////////////////////////////////////////////////////////
// UpdateEDS - Add periodic EDS entries
void UpdateEDS()
{
	char s[100],temp[100];
	int x,y,z,h,v;
	int i,j;

	// Send an EDS entry once a second.
	// Also report all subsystem positions.
	if (Timer - EDSTime > 1000)
	{
		EDSTime = Timer;
		// Current encoder readings + hex encoded motions/status
		EDSLog.Add(800,"%06d%06d%06d%06d%04X",
							 Cell.AE[0],Cell.AE[1],Cell.AE[2],Cell.AE[3],
							 (Cell.AM[0])|      (Cell.AM[1]<<2)|
							 (Cell.AM[2]<<4)   |(Cell.AM[3]<<6)|
							 (Cell.AEOK[0]<<8) |(Cell.AEOK[1]<<10)|
							 (Cell.AEOK[2]<<12)|(Cell.AEOK[3]<<14));
		EDSLog.Add(801,"%06d%06d%06d%06d%04X",
							 Cell.RE[0],Cell.RE[1],Cell.RE[2],Cell.RE[3],
							 (Cell.RM[0])|      (Cell.RM[1]<<2)|
							 (Cell.RM[2]<<4)   |(Cell.RM[3]<<6)|
							 (Cell.REOK[0]<<8) |(Cell.REOK[1]<<10)|
							 (Cell.REOK[2]<<12)|(Cell.REOK[3]<<14));
		// Target encoder readings
		EDSLog.Add(802,"%06d%06d%06d%06d%02X",
							 Cell.DAE[0],Cell.DAE[1],Cell.DAE[2],Cell.DAE[3],
							 (Cell.DAEOK[0])   |(Cell.DAEOK[1]<<2)|
							 (Cell.DAEOK[2]<<4)|(Cell.DAEOK[3]<<6));
		EDSLog.Add(803,"%06d%06d%06d%06d%02X",
							 Cell.DRE[0],Cell.DRE[1],Cell.DRE[2],Cell.DRE[3],
							 (Cell.DREOK[0])   |(Cell.DREOK[1]<<2)|
							 (Cell.DREOK[2]<<4)|(Cell.DREOK[3]<<6));
		// Current Galil switches (limits etc.)
		EDSLog.Add(804,"%02X%02X%02X%02X%02X%02X%02X%02X",
							 Cell.AS[0],Cell.RS[0],Cell.AS[1],Cell.RS[1],
							 Cell.AS[2],Cell.RS[2],Cell.AS[3],Cell.RS[3]);
		// Current Axial DGH Load Cell Readings in mV + hex encoded alarm
		temp[0] = 0;
		strncat(temp,DGHFormat(Cell.DGHs[0].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[1].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[2].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[3].Reading,s),9);
		sprintf(temp,"%s%1X",temp,
						(Cell.DGHs[0].Alarm)   |(Cell.DGHs[1].Alarm<<1)|
						(Cell.DGHs[2].Alarm<<2)|(Cell.DGHs[3].Alarm<<3));
		EDSLog.Add(805,temp);
		// Current Radial DGH Load Cell Readings in mV + hex encoded alarm
		temp[0] = 0;
		strncat(temp,DGHFormat(Cell.DGHs[4].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[5].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[6].Reading,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[7].Reading,s),9);
		sprintf(temp,"%s%1X",temp,
						(Cell.DGHs[4].Alarm)   |(Cell.DGHs[5].Alarm<<1)|
						(Cell.DGHs[6].Alarm<<2)|(Cell.DGHs[7].Alarm<<3));
		EDSLog.Add(806,temp);
		// Current Axial Tensions in pounds + status
		temp[0] = 0;
		strncat(temp,DGHFormat(Cell.DGHs[0].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[1].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[2].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[3].Tension,s),9);
		sprintf(temp,"%s%02X",temp,
						(Cell.DGHs[0].TensionOK)   |(Cell.DGHs[1].TensionOK<<2)|
						(Cell.DGHs[2].TensionOK<<4)|(Cell.DGHs[3].TensionOK<<6));
		EDSLog.Add(807,temp);
		// Current Radial Tensions in pounds + status
		temp[0] = 0;
		strncat(temp,DGHFormat(Cell.DGHs[4].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[5].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[6].Tension,s),9);
		strncat(temp,DGHFormat(Cell.DGHs[7].Tension,s),9);
		sprintf(temp,"%s%02X",temp,
						(Cell.DGHs[4].TensionOK)   |(Cell.DGHs[5].TensionOK<<2)|
						(Cell.DGHs[6].TensionOK<<4)|(Cell.DGHs[7].TensionOK<<6));
		EDSLog.Add(808,temp);
		// Current global coordinates
		x = round(Cell.x);
		y = round(Cell.y);
		z = round(Cell.z);
		h = round(Cell.h);
		v = round(Cell.v);
		EDSLog.Add(809,"%06d%06d%06d%06d%06d",x,y,z,h,v);
		// Target global coordinates
		x = round(Cell.dx);
		y = round(Cell.dy);
		z = round(Cell.dz);
		h = round(Cell.dh);
		v = round(Cell.dv);
		EDSLog.Add(810,"%06d%06d%06d%06d%06d",x,y,z,h,v);
		// Fatal, status, and motion-stage flags
		EDSLog.Add(811,"%04X%02X%02X",Flags.Fatal,Flags.Status,Flags.MoveStage);
		// All instrument rotators
		for (i=0;i<=5;i++)
		{
      if (IRs[i].Enabled)
      {
			  j = (IRs[i].Enabled) |										// Enabled
					  ((IRs[i].ErrorCount > 0) << 1) |			// Com Error
					  ((IRs[i].LastCommand == 2) << 2) |		// Last command a jog
					  (IRs[i].ErrorFlag << 3) |							// Servo error
					  (IRs[i].MotorPower << 4) |						// Motor power
					  (((IRs[i].Motion & IRMCW) > 0) << 5) |  // Clockwise motion
					  (((IRs[i].Motion & IRMCCW) > 0) << 6) |	// Counterclockwise motion
					  (((IRs[i].Limit & IRLCW) > 0) << 7) | 	// Clockwise limit
					  (((IRs[i].Limit & IRLCCW) > 0) << 8) |	// Counterclockwise limit
					  (IRs[i].Brake << 9) |									// Brake status
					  (IRs[i].LockPin << 10) |							// Lockpin in
					  (IRs[i].Homing << 11) |								// Home in progress
					  (IRs[i].Homed << 12) |								// Home completed successfully
					  (IRs[i].Zone << 13);									// CW/CCW Zone
			  EDSLog.Add(820+i,"%d%+07d%+07d%+05d%+03d%04X",i,IRs[i].Req,IRs[i].Val,
								   IRs[i].Vel,IRs[i].Volts,j);
			  EDSLog.Add(830+i,"%d%+011d%+011d%+011d",i,IRs[i].Encoder,
								   IRs[i].Error,IRs[i].Velocity);
			  EDSLog.Add(840+i,"%d%d%d",i,IRs[i].inTol,IRs[i].inTolTime);
			  EDSLog.Add(850+i,"%d%+011.3e%+011.3e%+011.3e%+011.3e%+011.3e",
								i,
								IRs[i].GoSTPos * (360.0 / IRs[i].Revolution),
								IRs[i].GoSTVel * (360.0 / IRs[i].Revolution),
								IRs[i].SpdP * IRs[i].GoSError *
									(360.0 / IRs[i].Revolution),
								IRs[i].SpdI * IRs[i].GoSIntError *
									(360.0 / IRs[i].Revolution),
								IRs[i].SpdD *
									(IRs[i].GoSError - IRs[i].GoSOldError) *
									(360.0 / IRs[i].Revolution));
      }
		}
	}

  if (Timer - EDSTimeIR > 2000)
  {
    EDSTimeIR = Timer;
		// All instrument rotators
		for (i=0;i<=5;i++)
		{
      if (!IRs[i].Enabled)
      {
		    j = (IRs[i].Enabled) |										// Enabled
				    ((IRs[i].ErrorCount > 0) << 1) |			// Com Error
				    ((IRs[i].LastCommand == 2) << 2) |		// Last command a jog
				    (IRs[i].ErrorFlag << 3) |							// Servo error
				    (IRs[i].MotorPower << 4) |						// Motor power
				    (((IRs[i].Motion & IRMCW) > 0) << 5) |  // Clockwise motion
				    (((IRs[i].Motion & IRMCCW) > 0) << 6) |	// Counterclockwise motion
				    (((IRs[i].Limit & IRLCW) > 0) << 7) | 	// Clockwise limit
				    (((IRs[i].Limit & IRLCCW) > 0) << 8) |	// Counterclockwise limit
				    (IRs[i].Brake << 9) |									// Brake status
				    (IRs[i].LockPin << 10) |							// Lockpin in
				    (IRs[i].Homing << 11) |								// Home in progress
				    (IRs[i].Homed << 12) |								// Home completed successfully
				    (IRs[i].Zone << 13);									// CW/CCW Zone
		    EDSLog.Add(820+i,"%d%+07d%+07d%+05d%+03d%04X",i,IRs[i].Req,IRs[i].Val,
							     IRs[i].Vel,IRs[i].Volts,j);
		    EDSLog.Add(830+i,"%d%+011d%+011d%+011d",i,IRs[i].Encoder,
							     IRs[i].Error,IRs[i].Velocity);
		    EDSLog.Add(840+i,"%d%d%d",i,IRs[i].inTol,IRs[i].inTolTime);
		  EDSLog.Add(850+i,"%d%+011.3e%+011.3e%+011.3e%+011.3e%+011.3e",
							i,
							IRs[i].GoSTPos * (360.0 / IRs[i].Revolution),
							IRs[i].GoSTVel * (360.0 / IRs[i].Revolution),
							IRs[i].SpdP * IRs[i].GoSError *
								(360.0 / IRs[i].Revolution),
							IRs[i].SpdI * IRs[i].GoSIntError *
								(360.0 / IRs[i].Revolution),
							IRs[i].SpdD *
								(IRs[i].GoSError - IRs[i].GoSOldError) *
								(360.0 / IRs[i].Revolution));
      }
    }
  }
}

Generated by GNU Enscript 1.6.5.2.
Document Actions