/*** Beginheader */ #ifndef __AIT_BB_LIB #define __AIT_BB_LIB /*** Endheader */ /* START LIBRARY DESCRIPTION ********************************************* AIT_BB.LIB Copyright (c) 2003, Adaptive Internet Technologies DESCRIPTION: AIT Beta-Brite utilities SUPPORT LIBS: AIT_BB.LIB REVISION HISTORY: 1.1 12/12/03 Original Issue END DESCRIPTION **********************************************************/ //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--// /*** Beginheader BB_Init, BB_SetMemory, BB_SendCmd, BB_SendText, BB_SendString */ // Beta-Brite Constants for AIT_BB.LIB #define FINBUFSIZE 255 #define FOUTBUFSIZE 255 #define BB_MAX_LINE 32 #define BB_BAUD 9600 #define BB_SET_COLOR '\x1C' #define BB_RED '1' #define BB_GREEN '2' #define BB_AMBER '3' #define BB_YELLOW '8' #define BB_RAINBOW1 '9' #define BB_RAINBOW2 'A' const char BB_HeaderStr[] = "\x00\x00\x00\x00\x00\x01Z00\x02" ; const char BB_EOT_Char = '\x04'; // Beta-Brite Typedefs for AIT_BB.LIB typedef struct { char ID; // File ID (NULL for end of list) char Type; // 't' = Text, 's' = String char Mode; // Display Letter (page 88) int Size; // Memory Allocation for message int Device; // Index into Sensor Array char *Format; // Display format for message } BB_MESSAGE; void BB_Init(); cofunc void BB_SendCmd(char * Body, int Length); cofunc void BB_SendText(char ID, char * Body, char Mode); cofunc void BB_SendString(char ID, char * Body); cofunc void BB_SetMemory(BB_MESSAGE * Messages); cofunc void BB_SendTextMessages(BB_MESSAGE * Messages); cofunc void BB_SendStringMessages(BB_MESSAGE * Messages, SENSOR * Devices); /*** endheader */ /* START FUNCTION DESCRIPTION ******************************************** BB_Init SYNTAX: void BB_Init() DESCRIPTION: Initialize the Beta-Brite Serial port F RETURN VALUE: None SEE ALSO: END DESCRIPTION **********************************************************/ void BB_Init() { serFopen(BB_BAUD); serFparity(PARAM_EPARITY); serFdatabits(PARAM_7BIT); serFwrFlush(); serFrdFlush(); } cofunc void BB_SendCmd(char * Body, int Length) { serFwrite(BB_HeaderStr, sizeof(BB_HeaderStr) - 1); serFwrite(Body, Length); serFputc(BB_EOT_Char); waitfor (DelayMs(1000)); } cofunc void BB_SendText(char ID, char * Body, char Mode) { serFwrite(BB_HeaderStr, sizeof(BB_HeaderStr) - 1); serFputc('A'); serFputc(ID); serFputc('\x1B'); serFputc(' '); serFputc(Mode); serFputc(' '); serFwrite(Body, strlen(Body)); serFputc(BB_EOT_Char); waitfor (DelayMs(1000)); } cofunc void BB_SendString(char ID, char * Body) { serFwrite(BB_HeaderStr, sizeof(BB_HeaderStr) - 1); serFputc('G'); serFputc(ID); serFwrite(Body, strlen(Body)); serFputc(BB_EOT_Char); waitfor (DelayMs(1000)); } /* START FUNCTION DESCRIPTION ******************************************** BB_Init SYNTAX: void BB_Init() DESCRIPTION: Initialize the Beta-Brite Serial port F RETURN VALUE: None SEE ALSO: END DESCRIPTION **********************************************************/ cofunc void BB_SetMemory(BB_MESSAGE * Messages) { BB_MESSAGE * pMessage ; char Size[5]; // Write the header and Command "E" serFwrite(BB_HeaderStr, sizeof(BB_HeaderStr) - 1); serFputc('E'); serFputc('$'); // Set Memory Configuration // Set the memory usage for each message in array for (pMessage = Messages; pMessage->ID; pMessage++) { serFputc(pMessage->ID); // File Lable serFputc((pMessage->Type == 't')? 'A' : 'B'); // File Type serFputc('L'); // Lock Keyboard sprintf(Size, "%04X", pMessage->Size); serFwrite(Size, 4); // Memory Size serFwrite("0000", 4); } serFputc(BB_EOT_Char); waitfor (DelayMs(1000)); } cofunc void BB_SendTextMessages(BB_MESSAGE * Messages) { BB_MESSAGE * pMessage ; // Send the memory usage for each message in array for (pMessage = Messages; pMessage->ID; pMessage++) { if(pMessage->Type == 't') { wfd BB_SendText(pMessage->ID, pMessage->Format, pMessage->Mode); } } } cofunc void BB_SendStringMessages(BB_MESSAGE * Messages, SENSOR * Devices) { BB_MESSAGE * pMessage ; char Buffer[BB_MAX_LINE]; // Send the memory usage for each message in array for (pMessage = Messages; pMessage->ID; pMessage++) { if(pMessage->Type == 's') { Buffer[0] = BB_SET_COLOR; Buffer[1] = BB_GREEN; if (Devices[pMessage->Device].Rate > 1.0) Buffer[1] = BB_RED; if (Devices[pMessage->Device].Rate < -1.0) Buffer[1] = BB_AMBER; sprintf(Buffer+2, pMessage->Format, Devices[pMessage->Device].Scaled); wfd BB_SendString(pMessage->ID, Buffer); } } } /*** BeginHeader */ #endif /*** EndHeader */