Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: utility.cpp
- Branch:
- Metric
- Revision:
- 116:5cd72bae7c12
- Parent:
- 115:549410af477d
- Child:
- 117:49883c779a74
--- a/utility.cpp Thu Jul 04 00:09:28 2013 +0000 +++ b/utility.cpp Thu Jul 04 05:27:15 2013 +0000 @@ -83,9 +83,6 @@ // overlay the last message with a "Lost0002" comment writeBuffer[tempWritePointer][0]=0; - // leave the ts of the overlaid message - //writeBuffer[tempWritePointer][1]=(ts&0xff00)>>8; // Time Stamp (2 bytes_ - //writeBuffer[tempWritePointer][2]=(ts&0x00ff); // force the MsgID to an Event Message writeBuffer[tempWritePointer][3]=0xfe; // MsgID, low byte writeBuffer[tempWritePointer][4]=0xff; // Len nibble, and MsgID high nibble @@ -165,12 +162,11 @@ for(i=5;i<13;i++){ // Is there a better way to do this? (writeBuffer[localWritePointer][5]=canRXmsg.data?) writeBuffer[localWritePointer][i]=canRXmsg.data[i-5]; } - if (writePointer==readPointer) { - // Just caught up to read pointer - sprintf(sTemp,"Write buffer overrun.\n"); - printMsg(sTemp); // write buffer overrun - spkr.beep(500,0.25); - } + //if (localWritePointer==readPointer) { //Just caught up to read pointer + // printMsg("Write buffer overrun.\n"); + // spkr.beep(500,0.125); + //} + swInt=1; // trigger buffer dump } } @@ -185,8 +181,7 @@ // the ii array is full, more than 100 MsgIDs found if(ii==99) { ii++; // step to 100 to log only one error - sprintf(sTemp,"MsgID buffer overrun.\n"); - printMsg(sTemp); // write buffer overrun + printMsg("MsgID buffer overrun.\n"); // write buffer overrun } } } @@ -212,36 +207,31 @@ if(canRXmsg.data[3]==1){//Group 1 data bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22) if(debugMode){ - sprintf(sTemp," Getting Group 1 data\n"); - printMsg(sTemp); + printMsg(" Getting Group 1 data\n"); } }else if(canRXmsg.data[3]==2){//Group 2 = cellpair data bdi=BatDataBaseG2; // index offset for CP data (uses 00 - 1C) if(debugMode){ - sprintf(sTemp," Getting cell pair data\n"); - printMsg(sTemp); + printMsg(" Getting cell pair data\n"); } }else if(canRXmsg.data[3]==3){//Group 3 data bdi=BatDataBaseG3; // index offset for Group 3 data (uses 20 - 22) if(debugMode){ - sprintf(sTemp," Getting Group 3 data\n"); - printMsg(sTemp); + printMsg(" Getting Group 3 data\n"); } }else if(canRXmsg.data[3]==4){//Group 4 = temperature data bdi=BatDataBaseG4; // index offset for Temperature data (uses 20 - 22) if(debugMode){ - sprintf(sTemp," Getting temperature data\n"); - printMsg(sTemp); + printMsg(" Getting temperature data\n"); } }else if(canRXmsg.data[3]==5){//Group 5 data bdi=BatDataBaseG5; // index offset for Group 5 data (uses 20 - 22) if(debugMode){ - sprintf(sTemp," Getting Group 5 data\n"); - printMsg(sTemp); + printMsg(" Getting Group 5 data\n"); } }else bdi=0xff; // ignore other messages (for now) @@ -400,9 +390,6 @@ } void autoPollISR(){ - //char sTemp[40]; // just for debug - //sprintf(sTemp,"Requesting cp data\n"); // just for debug - //printMsg(sTemp); // just for debug reqMsgCnt = 0; //reset message counter msgReq.attach(&sendReq,0.015); } @@ -483,13 +470,10 @@ void readConfig(){ FILE *cfile; int ff; - char sTemp[40]; cfile = fopen("/local/config.txt", "r"); if (cfile==NULL){ // if doesn't exist --> create - sprintf(sTemp,"No config file found.\n"); - printMsg(sTemp); // no config file - sprintf(sTemp,"Calibrating touch screen.\n"); - printMsg(sTemp); // calibrating + printMsg("No config file found.\n"); // no config file + printMsg("Calibrating touch screen.\n"); // calibrating //tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);// bypass calibration using my values tt.calibrate(); // run touchscreen calibration routine // NOTE: calibrates screen 1 first, then screen 0. @@ -537,11 +521,9 @@ fclose(cfile); if(ff<4){//If not latest format, save as latest format saveConfig(); - sprintf(sTemp,"Config file format updated.\n"); - printMsg(sTemp); // config forat updates + printMsg("Config file format updated.\n"); // config forat updates } - sprintf(sTemp,"Config file loaded.\n"); - printMsg(sTemp); // config file loaded + printMsg("Config file loaded.\n"); // config file loaded } } @@ -813,3 +795,32 @@ } return(usbEn); } + +void dumpBuffer(void){ + int localWritePointer=writePointer; + //NVIC_DisableIRQ(EINT0_IRQn); + //NVIC_DisableIRQ(EINT1_IRQn); + //NVIC_DisableIRQ(EINT2_IRQn); + //NVIC_DisableIRQ(EINT3_IRQn); + while (readPointer != localWritePointer) { + FRESULT efr=f_write(&efile,&writeBuffer[readPointer][0],13,&bytesRW); + if (efr != FR_OK) { + logOpen = false; + printMsg("Failed to append log file.\n"); // failed to append + spkr.beep(3000,0.25); + spkr.beep(1500,0.25); + spkr.beep(750,0.25); + spkr.beep(375,0.25); + logEn=false; + } + if(++readPointer >= maxBufLen){ + readPointer=0; + led4 = !led4; + } + } + swInt=0; + //NVIC_EnableIRQ(EINT0_IRQn); + //NVIC_EnableIRQ(EINT1_IRQn); + //NVIC_EnableIRQ(EINT2_IRQn); + //NVIC_EnableIRQ(EINT3_IRQn); +} \ No newline at end of file