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
- Revision:
- 69:6bfdfc002036
- Parent:
- 58:4d06288d75a2
- Child:
- 75:77bd26829dca
--- a/utility.cpp Thu Apr 11 18:52:12 2013 +0000 +++ b/utility.cpp Sun Apr 14 01:21:11 2013 +0000 @@ -9,6 +9,8 @@ userIdle=(++secsNoTouch>userTimeout)?true:false; LPC_RTC->ILR |= (1<<0); // clear interrupt to prepare for next tick=true; + // will use this to generate a logTP() just before the next Message received. + if( (time(NULL) % 60) == 0) ZeroSecTick = true; // gg - at 0-second of each minute } void RTC_Init (void) { @@ -37,7 +39,7 @@ } void logCan (char mType, CANMessage canRXmsg) { - char sTemp[40]; + char sTemp[40]; unsigned short ts = getTimeStamp(); static unsigned char ii = 0, lasti = 0; // indexindex unsigned char changed,i; @@ -46,6 +48,7 @@ signed short packA; static signed short imotorRPM = 0; signed long imWs_x4; + secsNoMsg=0; // reset deadman switch if(logOpen){ if(canRXmsg.id>0) { @@ -105,7 +108,7 @@ //if(i==22) logCP=true; //Turbo3 //if( (i==22) && (yesBattLog) ) logCP=true; // only if enabled gg - Batt Log if(i==22){ - logCP=yesBattLog; // Only log is logging enabled + logCP=yesBattLog; // Only log if logging enabled showCP=true; // Always show } i*=7; @@ -143,17 +146,33 @@ void logTS () { CANMessage tsMsg; unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 + // NOTE: In Mbed, I believe that this is seconds past start of 1970, not 1900 + // but this is good, since seconds past 1970 is what CAN-Do expects. GG - Date Time tsMsg.id=0xfff; tsMsg.len=0xf; - tsMsg.data[0]=secs&0xff; + tsMsg.data[0]=secs&0xff; tsMsg.data[1]=(secs>>8)&0xff; tsMsg.data[2]=(secs>>16)&0xff; - tsMsg.data[3]=secs>>24; - tsMsg.data[4]=0xff; - tsMsg.data[5]=0xff; - tsMsg.data[6]=0xff; + tsMsg.data[3]=(secs>>24)&0xff; + tsMsg.data[4]=0; // 0xff; gg - Date Time + tsMsg.data[5]=0; // 0xff; for CAN-Do + tsMsg.data[6]=0; // 0xff; tsMsg.data[7]=0xff; - logCan(0,tsMsg); + logCan(0,tsMsg); // Date-Time +} + +void logErrMsg (char * errMsg) { + // log CAN-Do 8-character Pseudo Message + CANMessage tsMsg; + tsMsg.id=0xffe; // pseudo Message to CAN-Do log + tsMsg.len=0xf; + int iMsgLen = strlen(errMsg); + // 8 character message compatible with CAN-Do + for(int i=0; i<8; i++){ + tsMsg.data[i]=' '; + if( i < iMsgLen ) tsMsg.data[i]=errMsg[i]; + } + logCan(0,tsMsg); // FFE Comment Message } void sendCPreq() { @@ -162,7 +181,10 @@ can1.monitor(false); // set to active mode can1SleepMode = 0; // enable TX can1.write(CANMessage(0x79b, data, 8)); - logCan(1,CANMessage(0x79b, data, 8)); + + if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus + + logCan(1,CANMessage(0x79b, data, 8)); // Group 2 Request on EV data[0]=0x30; //change to request next line message data[1]=0x01; data[2]=0x00; @@ -180,7 +202,10 @@ can1.monitor(false); // set to active mode can1SleepMode = 0; // enable TX can1.write(CANMessage(0x79b, data, 8)); - logCan(1,CANMessage(0x79b, data, 8)); + + if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus + + logCan(1,CANMessage(0x79b, data, 8)); // Group 4 request on EV data[0]=0x30; //change to request next line message data[1]=0x01; data[2]=0x00; @@ -206,14 +231,20 @@ void recieve1() { CANMessage msg1; can1.read(msg1); - logCan(1, msg1); //EVcan + + if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus + + logCan(1, msg1); // EVcan Message Received led1 = !led1; } void recieve2() { CANMessage msg2; can2.read(msg2); - logCan(2, msg2); //CARcan + + if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus + + logCan(2, msg2); // CARcan Message Received led2 = !led2; } @@ -264,9 +295,9 @@ cfile = fopen("/local/config.txt", "r"); if (cfile==NULL){ // if doesn't exist --> create sprintf(sTemp,"No config file found.\n"); - logMsg(sTemp); + logMsg(sTemp); // no config file sprintf(sTemp,"Calibrating touch screen.\n"); - logMsg(sTemp); + logMsg(sTemp); // 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. @@ -303,10 +334,10 @@ if(ff<3){//If not latest format, save as latest format saveConfig(); sprintf(sTemp,"Config file format updated.\n"); - logMsg(sTemp); + logMsg(sTemp); // config forat updates } sprintf(sTemp,"Config file loaded.\n"); - logMsg(sTemp); + logMsg(sTemp); // config file loaded } }