/*** Beginheader */ #ifndef __AIT_GEN_LIB #define __AIT_GEN_LIB #define SEC_PER_MIN 60 #define SEC_PER_HOUR 3600 #define CONVERT_LED 0 #define WEB_CONNECT_LED 1 #define WEB_FORM 2 #define PWR_PULSE 3 typedef unsigned char BYTE; #define ElementsIn(arr) (sizeof(arr)/sizeof((arr)[0])) #define SWRITE_BUFFER if(State->offset < State->length) \ { State->offset += sock_fastwrite(&State->s, State->buffer + (int)State->offset, \ (int)State->length - (int)State->offset); \ } else { State->offset = 0; State->length = 0; State->buffer[0] = 0; } #define SSEND(text) (strcat(State->buffer, (text))) #define SSET_LENGTH State->length = strlen(State->buffer); \ State->offset = 0; static char TimeText[16]; static char DateText[16]; static char StartTimeText[16]; static char StartDateText[16]; /*** Endheader */ /* START LIBRARY DESCRIPTION ********************************************* AIT_GENERAL.LIB Copyright (c) 2003, Adaptive Internet Technologies DESCRIPTION: AIT General purpose utilities SUPPORT LIBS: REVISION HISTORY: 1.1 12/04/03 Original Issue END DESCRIPTION **********************************************************/ //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--// /*** BeginHeader AIT_EflushRx, AIT_htob, AIT_PrintTime, AIT_GetDay, AIT_getTime24 */ const char HEX[17] = "0123456789ABCDEF" ; cofunc int AIT_EflushRx(int Wait, int Show); BYTE AIT_htob(char HexC); void AIT_PrintTime(unsigned long thetime); int AIT_GetDay(); int AIT_GetTime24(); /*** EndHeader */ /* START _FUNCTION DESCRIPTION ******************************************** AIT_EflushRx SYNTAX: cofunc int AIT_EflushRx(int Wait, int Show) DESCRIPTION: Waits for pending TX chars to send and then flushes all Response characters PARAMETER1: Period to wait (mS) for incoming charaters before aborting PARAMETER2: Flag to display Rx Characters. 1= Show, 0=NoShow RETURN VALUE: Total characters flushed from RX buffer SEE ALSO: END DESCRIPTION **********************************************************/ cofunc int AIT_EflushRx(int Wait, int Show) { char Buffer[64]; int Total; int C; // Wait for the TX buffer to be empty and the First RX char to turn up waitfor(serEwrFree() == EOUTBUFSIZE); waitfor(serEpeek() != -1 ); // Read all chars until no chars for "Wait Time" if (Show) puts("Echo: "); Total = 0; while((C=serEread(Buffer, 63, Wait)) > 0) { Buffer[C] = 0 ; Total += C ; if (Show) puts(Buffer); } if (Show) puts("\n"); return (Total); } /* START _FUNCTION DESCRIPTION ******************************************** AIT_htob SYNTAX: BYTE AIT_htob(char HexC) DESCRIPTION: Converts a single Hex Char to a BYTE val 0-15 PARAMETER1: Character to convert (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) RETURN VALUE: Numeric value of Hex Char (0-15) SEE ALSO: END DESCRIPTION **********************************************************/ BYTE AIT_htob(char HexC) { char * Loc; HexC = (char)toupper(HexC); if ((Loc = strchr(HEX, HexC)) == NULL) return (0) ; else return (BYTE)(Loc - HEX) ; } void AIT_PrintTime(unsigned long thetime) { struct tm thetm; mktm(&thetm, thetime); printf("%02d/%02d/%04d %02d:%02d:%02d\n", thetm.tm_mon, thetm.tm_mday, 1900+thetm.tm_year, thetm.tm_hour, thetm.tm_min, thetm.tm_sec); } int AIT_GetDay() { struct tm thetm; mktm(&thetm, read_rtc()); return (thetm.tm_mday); } int AIT_GetTime24() { struct tm thetm; mktm(&thetm, read_rtc()); return ((thetm.tm_hour * 100) + thetm.tm_min); } /*** BeginHeader */ #endif /*** EndHeader */