Skip to content. | Skip to navigation

Personal tools

edslog.cpp

edslog.cpp

edslog.cpp

/////////////////////////////////////////////////////////////////////////////
// EDSLOG.CPP
//
//  Last updated: 3/12/2002
//
//  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;
}

/////////////////////////////////////////////////////////////////////////////
// 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
	_dos_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]);
	}
	Checksum = Address;
	for (i=0;i<strlen(s);i++)
		Checksum ^= s[i];
	Checksum &= 255;
	sprintf(s2,"%s%02X\r",s,Checksum);
	RespondToHost(s2);
	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 (LastIndex == -1)
	{
		MessageLength = 0;
		sprintf(s,"3%02d%02d",MessageCount,MessageLength);
	}
	else
	{
		MessageLength = strlen(Data[LastIndex]);
		sprintf(s,"3%02d%02d%s",MessageCount,MessageLength,Data[LastIndex]);
	}
	Checksum = Address;
	for (i=0;i<strlen(s);i++)
		Checksum ^= s[i];
	Checksum &= 255;
	sprintf(s2,"%s%02X\r",s,Checksum);
	RespondToHost(s2);
}

/////////////////////////////////////////////////////////////////////////////
// UpdateEDS - Add periodic EDS entries
void UpdateEDS()
{
	unsigned data[7];
	int i;
        int preverrorcount;
        int e;
        char s[100],temp[100];
	char APos[10],BPos[10];

	// Send an EDS entry giving all digital I/O and parallel port data
	// once a second.
	// Also report all subsystem positions.
        if (Timer - EDSTime > 1000)
	{
                EDSTime = Timer;
		// Read all digital I/O
#ifdef ENABLEIO
		for (i=0;i<6;i++)
			data[i] = inp(base_port+i);
#else

		for (i=0;i<6;i++)
			data[i] = 0;
#endif

		// Log Digital I/O and parallel port values
		EDSLog.Add(801,"D%02X%02X%02X%02X%02X%02XP%02X",
							 data[0],data[1],data[2],data[3],data[4],data[5],PARVALUE);
		// Prepare ADC positions in degrees
		if (ADCA.Homed)
			sprintf(APos,"%05.1f",360.0 * ADCA.Position / ADCA.StepsPerRevolution);
		else
			sprintf(APos,"E");
		if (ADCB.Homed)
			sprintf(BPos,"%05.1f",360.0 * ADCB.Position / ADCB.StepsPerRevolution);
		else
			sprintf(BPos,"E");
		// Log all subsystem positions, along with ADC rotator positions
                EDSLog.Add(803,"P%d%d%d%d%d%dA%sB%s",Mirror.Limit,Mirror.Latch,M3Turret->Position,
								M3TurretPin.Limit,ADCTurret->Position,ADCTurretPin.Limit,
                                                                APos,BPos);
                //Logging DGHs
                EDSLog.Add(802,"AC%+07.3fAB%+07.3fBC%+07.3fM%7.3f",DGHs[0].Reading,DGHs[1].Reading,
                                                                DGHs[2].Reading,PresVac.ave*49.0);

                //Log Analog Data
                // Add the new averaged reading to the engineering data stream
                EDSLog.Add(800,"C%+07.3fB%+07.3fA%+07.3fT%+07.3f",AnalogData[0],AnalogData[1],AnalogData[2],AnalogData[3]);

                //log vacuum and pressure pulse width in ms                   
                EDSLog.Add(804,"V%4dP%4d",VacuumPulseWidth,PressurePulseWidth);

                //Log PID vac/pres values
                EDSLog.Add(805,"P%7.3fI%7.3fD%7.3f",PresVac.P,PresVac.I,PresVac.D);

        }       

}

Generated by GNU Enscript 1.6.5.2.
Document Actions