Skip to content. | Skip to navigation

Personal tools

io.cpp

io.cpp

io.cpp

/////////////////////////////////////////////////////////////////////////////
// IO.CPP
//
//  Last updated: 08/29/2004
//
//  Part of the source code for the Vane End Actuator Control System
//
//  This file contains numerous low level I/O routines.
//
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Watchdog: Watchdog update function
void Watchdog()
// Watchdog() must be executed about once a second to keep the watchdog happy,
// or else the emergency stop card triggers.
//
// The watchdog is at address 0x247.  You can send any byte to it to keep
// it happy.
{
#ifdef ENABLEIO
	outp(0x247,0xFF);
#endif

}

/////////////////////////////////////////////////////////////////////////////
// SafeDelay: Watchdog-safe Delay function
void SafeDelay(int DelayTime)
// This routine uses the Clock unit's Delay routine, but calls
// Watchdog() every 100 milliseconds.
{
	int i;
	int dt;

	dt = DelayTime;
	for (i = 0;i < DelayTime / 100;i++)
	{
		if (dt > 100)
			Delay(100);
		else
			Delay(dt);
		Watchdog();
		dt -= 100;
	}
}

/////////////////////////////////////////////////////////////////////////////
// SystemReset: Software based system reset function
void SystemReset()
// Perform a hardware reset on the system.
{
	outp(0x64,0xFE);
}

/////////////////////////////////////////////////////////////////////////////
// InitPorts: Function to configure the serial port parameters and install
// the serial interrupt driver
void InitPorts()
{
// Initialize COM1:, COM2:, COM3:, COM4:, COM5: and COM6:

// Always turn on COM1:, for host-guest debugging etc.
	InitComPort(0,0x3F8,4,38400,"O71",1,0);
#ifdef ENABLEIO
// Only turn on COM2:, COM3:, COM4:, :COM5 and :COM6 in the real computer
	InitComPort(1,0x2F8,3,19200,"N81",1,0);
	InitComPort(2,0x3E8,4,19200,"N81",1,2);
	InitComPort(3,0x2E8,3,19200,"N81",1,2);
	InitComPort(4,0x2F0,4,19200,"N81",1,2);
	InitComPort(5,0x3E0,3,19200,"N81",1,1);
#endif

}

/////////////////////////////////////////////////////////////////////////////
// RespondToHost: Transmit a string to the upstream host computer on COM1:
void RespondToHost(char *message)
// Send a message to the Host computer (upstream).
// The string "message" is transmitted.
// This routine automatically adds the correct Response and
// Address characters to the beginning of the string.
{
	char line[80]; // String buffer

	line[0] = Response;
	line[1] = Address;
	strcpy(&line[2],message);
	Log.Add("RespondToHost(%d): Sending \"%s\" to host computer",VERBOSE,__LINE__,line);
	SerialBufPutString(Host,line);
}

/////////////////////////////////////////////////////////////////////////////
// VerifyChecksum: Verifies that the checksum in a string is correct
int VerifyChecksum(char* s)
// Returns a zero if the string's checksum is OK, and a 1 if not.
// Note that this routine expects a full message, i.e.
//  ":HdataCC" where data is the body of the message, and CC is the
//  checksum.
{
	int i,Checksum;
	char check[10];

	// Start checksum calculation with Vane End address
	Checksum = Address;
	// Binary not all subsequent characters
	for (i=2;i<strlen(s)-2;i++)
		Checksum ^= s[i];
	// Reduce checksum to 1 byte
	Checksum &= 255;
	sprintf(check,"%02X",Checksum);
	if ((s[strlen(s)-2] == check[0]) && (s[strlen(s)-1] == check[1]))
		return(0);
	else
		return(1);
}

/////////////////////////////////////////////////////////////////////////////
// RespondToHostWithChecksum: Add a hex checksum + CR to string and send
void RespondToHostWithChecksum(char* s)
// Calculates the Shec-checksum for a string, and sends the
// string to the host computer (TCS)
{
	int i,Checksum;
	char s2[120];

	// Start checksum calculation with Vane End address
	Checksum = Address;
	// Binary not all subsequent characters
	for (i=0;i<strlen(s);i++)
		Checksum ^= s[i];
	// Reduce checksum to 1 byte
	Checksum &= 255;
	// Append checksum and a carriage return to the string given to us
	sprintf(s2,"%s%02X\r",s,Checksum);
	// Send total message to host
	RespondToHost(s2);
}

Generated by GNU Enscript 1.6.5.2.
Document Actions