void logException(unsigned int errorCode, const char * pStrError, int takeAction) { // errorcode == 1 means memory error from BodyInit() and ucBSInit() int i; char errorString[160]; if(vCur_1 < V_MIN_SDWRITE_VOLTAGE) { } if (takeAction || LOG_WARNINGS) { strcpy(errorString,"\x0d\x0a" "*** ERROR! (cycle "); //cycle number longToDecimalString(systemCounts.powerUpNumber,(char *)(errorString+strlen(errorString)),4); strcat(errorString," - version " VERSION ")\x0d\x0a*** #"); longToDecimalString((long)errorCode,(char *)(errorString+strlen(errorString)),3); if (takeAction) { strcat(errorString,"-fatal"); stop(); } else strcat(errorString,"-warning"); if (LOG_FILE) { logString(errorString,ASAP); if (pStrError) { LBstrncpy(errorString,pStrError,80); logString(errorString,ASAP); } } else { appendStringToFile(ERROR_LOG_FILE,errorString); if (pStrError) { LBstrncpy(errorString,pStrError,80); appendStringToFile(ERROR_LOG_FILE,errorString); } } } //todo: put a parameter in fct to return instead of reset or USB //maybe a choice of the three RETURN, RESET, USB if (takeAction) { // commenting out code to alert user of error -- just use lights and auto-reset to welcome msg // if (errorCode != 10 && errorCode != 14) // can't access config or system boot // insertSoundFile(ERROR_SOUND_FILE_IDX); // if (errorCode != 14) // LED_GREEN and LED_RED are not assigned without config file for (i=0; i < 5; i++) { setLED(LED_GREEN,FALSE); setLED(LED_RED,TRUE); wait(500); setLED(LED_RED,FALSE); setLED(LED_GREEN,TRUE); wait(500); } if (takeAction == USB_MODE) // can't load config setUSBDevice (TRUE); else if (takeAction == RESET) resetSystem(); else if (takeAction == SHUT_DOWN) setOperationalMode((int)P_SLEEP); } }
bool unitTest() { bool retVal = false; int i; char testString[MAX_LEN]; char *spaceFile = "SpaceUnitTestFile.txt", *tabFile = "TabUnitTestFile.txt", *newLineFile = "NewLineUnitTestFile.txt", *result; //test appending memset(testString, 0, MAX_LEN); for(i = 0; i < MAX_STRINGS; i++){ strcat(testString, "10"); retVal = appendStringToFile(testString, spaceFile, 's'); retVal = appendStringToFile(testString, tabFile, 't'); retVal = appendStringToFile(testString, newLineFile, 'n'); } //test retrieveing memset(testString, 0, MAX_LEN); for(i = 1; i <= MAX_STRINGS; i++){ strcat(testString, "10"); result = getStringAtIndexInFile(i, spaceFile); if(strcmp(result, testString)) retVal = false; MACRO_FREE_RESULT(result); result = getStringAtIndexInFile(i, tabFile); if(strcmp(result, testString)) retVal = false; MACRO_FREE_RESULT(result); result = getStringAtIndexInFile(i, newLineFile); if(strcmp(result, testString)) retVal = false; MACRO_FREE_RESULT(result); } //invalid delimiter getStringAtIndexInFile(1, tabFile); //file not found getStringAtIndexInFile(1, "INVALIDFILE"); //negative index getStringAtIndexInFile(-1, tabFile); //invalid path retVal = !(appendStringToFile("INVALIDFILE", "?.!.*.%", 'n')); return retVal; }
void flushLog(void) { if (idxLogBuffer && LOG_FILE && !SACM_Status()) { appendStringToFile(LOG_FILE,logBuffer); idxLogBuffer = 0; } }
int main( int argc, char *argv[] ) { //Should print out errors and ok = true if unitTest() passes bool ok = unitTest(); if(argc > 1){ if(!strcmp(argv[1], "a") && argc == 5){ appendStringToFile(argv[3], argv[4], argv[2][0]); } else if (!strcmp(argv[1], "g") && argc == 4){ char* str = getStringAtIndexInFile(atoi(argv[2]), argv[3]); if(str){ printf("%s", str); delete str; } } else if(strcmp( argv[1], "g") && strcmp( argv[1], "a")){ printf("You have entered an invald opperation\n"); } else{ printf("You hve not provided the necessary arguments, halting execution\n"); } } else{ printf("Program arguments:\nUse 'a' to append to a file, provide filename and delimiter (s, t, n)\n" "Use 'g' to retrieve from a file, provide index and filename\n" "Exiting...\n"); } return 0; }
int logLongHex(unsigned long data) { char strHex[7]; int ret; longToHexString((long)data, (char *)strHex, 1); //bytesToWrite = convertDoubleToSingleChar(strHex,strHex,TRUE); //ret = write(handle,strHex<<1,bytesToWrite); ret=appendStringToFile((const char *)"data.txt",(char *)strHex); return ret; }
int addCategoryToActiveLists(char * strCategoryCode, char * strMessageList) { char filepath[PATH_LENGTH]; char tempCategoryCode[LIST_ITEM_LENGTH]; int ret; // be sure category is in master-list.txt if (strMessageList) { strcpy(filepath,LISTS_PATH); strcat(filepath,strMessageList); strcat(filepath,"/"); } else cpyListPath(filepath,LIST_MASTER); strcat(filepath,(char *)LIST_MASTER); strcat(filepath,(char *)".txt"); // Only add category entry if doesn't already exist. // Checking for existence without deleting and appending preserves category order. ret = findDeleteStringFromFile((char *)NULL, filepath, strCategoryCode, 0); if (ret == -1) { // not found in file strcpy(tempCategoryCode,strCategoryCode); // since appendStringToFile destroys string ret = appendStringToFile(filepath, tempCategoryCode); } return ret; }