Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Revision 78:a383971fe02f, committed 2013-04-16
- Comitter:
- TickTock
- Date:
- Tue Apr 16 13:01:13 2013 +0000
- Parent:
- 77:7c136766466c
- Child:
- 79:68f0dd8d1f19
- Child:
- 81:cf009a64eedd
- Commit message:
- Moved message request to ticker instead of wait_ms delay to stop buffer overrun caused by wait_ms blocking usb write. Also requests other four frames so raw data can be logged for analysis.
Changed in this revision
--- a/main.cpp Tue Apr 16 03:28:55 2013 +0000 +++ b/main.cpp Tue Apr 16 13:01:13 2013 +0000 @@ -29,6 +29,7 @@ Ticker autoPoll; Ticker playback; +Ticker msgReq; Timer timer; DigitalOut led1(LED1); @@ -50,7 +51,7 @@ // gg - revStr is used in 2 places // gg - and is easy to edit here // gg - added ZeroSecTick and revStr -char revStr[7] = "77"; // gg - fix rev number +char revStr[7] = "78"; bool logEn = false, logOpen = false; bool yesBattLog = false ; // gg - Batt Log @@ -82,7 +83,7 @@ unsigned char displayLoc = 0; unsigned char indexOffset = 1; bool showCP = false; -bool pollCP = false; +//bool pollCP = false; bool logCP = false; //Turbo3 bool repeatPoll = false; bool headlights = false; @@ -101,7 +102,7 @@ bool playbackEn = false; bool playbackOpen = false; //float playbackInt = 0.05; //read messages every 50 ms -float playbackInt = 0.005; //read messages every 50 ms +float playbackInt = 0.005; //read messages every 5 ms bool step = false; char header[5]; char data[8]; @@ -119,6 +120,7 @@ 60*60*24*39.8, 60*60*24*63.1, 60*60*24*100, 60*60*24*158, 60*60*24*251, 60*60*24*365}; // 1 year bool updateDTE = false; unsigned short pointerSep; +unsigned char reqMsgCnt = 99; int main() { char sTemp[40]; @@ -223,6 +225,9 @@ // Read config file readConfig(); + // Start 15ms timer for requests + msgReq.attach(&sendReq,0.015); + // Start monitors can1.monitor(true); // set to snoop mode can2.monitor(true); // set to snoop mode @@ -416,11 +421,11 @@ sMode=0; dMode[whichTouched] = brakeScreen ; // GoTo Brake Screen } else if (dMode[whichTouched]==cpScreen) { - pollCP=true; + reqMsgCnt=0; } else if (dMode[whichTouched]==cpHistScreen) { // gg - hist - pollCP=true; + reqMsgCnt=0; } else if (dMode[whichTouched]==cpBarScreen) { // gg - cpbars - pollCP=true; + reqMsgCnt=0; } else if (dMode[whichTouched]==config1Screen) { mbed_reset(); } else if (dMode[whichTouched]==playbackScreen) { // pause/unpause @@ -491,7 +496,10 @@ case 01: // left col middle row if (dMode[whichTouched]==config1Screen) { logEn = !logEn; - if (!logEn) repeatPoll=false; // disable auto polling, too + if (!logEn) { + repeatPoll=false; // disable auto polling, too + autoPoll.detach(); + } } else if (dMode[whichTouched] == indexScreen) { // gg - index dMode[whichTouched] = cpScreen ; // GoTo CP Data Screen sMode=0; @@ -718,12 +726,12 @@ display=display<1?display+1:0; // toggle display updateDisplay(display); - if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked + /*if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked sendCPreq(); // send cellpair data request. wait_ms(16); sendTreq(); //send temperature request pollCP=false; - } + }*/ if(step){ // playback if(playbackOpen&&playbackEn){
--- a/utility.cpp Tue Apr 16 03:28:55 2013 +0000 +++ b/utility.cpp Tue Apr 16 13:01:13 2013 +0000 @@ -102,30 +102,32 @@ bdi=0x20; sprintf(sTemp,"Getting temperature data\n"); logMsg(sTemp); - }else bdi=0; + }else bdi=0xff; // ignore other messages (for now) lasti=0; } - i=canRXmsg.data[0]&0x0f; //lower nibble of D0 is index - if(lasti>i){ //detect rollover and offset index appropriately - bdi=0x10; - } - lasti=i; //remember the msb to detect rollover next time around - i+=bdi; - //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 if logging enabled - showCP=true; // Always show - } - i*=7; - if(i<0xfa){ // Is there a better way to do this? - battData[i+0]=canRXmsg.data[1]; - battData[i+1]=canRXmsg.data[2]; - battData[i+2]=canRXmsg.data[3]; - battData[i+3]=canRXmsg.data[4]; - battData[i+4]=canRXmsg.data[5]; - battData[i+5]=canRXmsg.data[6]; - battData[i+6]=canRXmsg.data[7]; + if(bdi<0xff){ + i=canRXmsg.data[0]&0x0f; //lower nibble of D0 is index + if(lasti>i){ //detect rollover and offset index appropriately + bdi=0x10; + } + lasti=i; //remember the msb to detect rollover next time around + i+=bdi; + //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 if logging enabled + showCP=true; // Always show + } + i*=7; + if(i<0xfa){ // Is there a better way to do this? + battData[i+0]=canRXmsg.data[1]; + battData[i+1]=canRXmsg.data[2]; + battData[i+2]=canRXmsg.data[3]; + battData[i+3]=canRXmsg.data[4]; + battData[i+4]=canRXmsg.data[5]; + battData[i+5]=canRXmsg.data[6]; + battData[i+6]=canRXmsg.data[7]; + } } }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps packV=((canRXmsg.data[2]<<2)|(canRXmsg.data[3]>>6)); // 1 LSB = 0.5V @@ -181,7 +183,54 @@ logCan(0,tsMsg); // FFE Comment Message } -void sendCPreq() { +void sendReq() { + static char data[8] = {0x02, 0x21, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff}; + if(reqMsgCnt<99){ + switch (reqMsgCnt){ + case 0: + can1.monitor(false); // set to active mode + can1SleepMode = 0; // enable TX + data[0]=0x02; //change to request frame 1 + data[1]=0x21; + data[2]=0x01; + break; + case 6: // frame 1 has 6 lines + can1.monitor(false); // set to active mode + can1SleepMode = 0; // enable TX + data[0]=0x02; //change to request frame 2 (cp data) + data[1]=0x21; + data[2]=0x02; + break; + case 35: // frame 2 has 29 lines + data[0]=0x02; //change to request frame 3 + data[1]=0x21; + data[2]=0x03; + break; + case 40: // frame 3 has 5 lines + data[0]=0x02; //change to request frame 4 (temperature) + data[1]=0x21; + data[2]=0x04; + break; + case 43: // frame 4 has 3 lines + data[0]=0x02; //change to request frame 5 + data[1]=0x21; + data[2]=0x05; + break; + case 54: // frame 5 has 11 lines + reqMsgCnt = 99; + can1SleepMode = 1; // disable TX + can1.monitor(true); // set to snoop mode + default: + data[0]=0x30; //change to request next line message + data[1]=0x01; + data[2]=0x00; + } + can1.write(CANMessage(0x79b, data, 8)); + reqMsgCnt++; + } +} + +/*void sendCPreq() { char i; char data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff}; can1.monitor(false); // set to active mode @@ -225,8 +274,11 @@ void autoPollISR() { //This is the ticker ISR for auto-polling pollCP=true; //Set a flag to do in main loop instead of here -} //since ticker blocks other interrupts +} //since ticker blocks other interrupts*/ +void autoPollISR(){ + reqMsgCnt = 0; //reset message counter +} void playbackISR() { //Used for autoplayback step=true; }
--- a/utility.h Tue Apr 16 03:28:55 2013 +0000 +++ b/utility.h Tue Apr 16 13:01:13 2013 +0000 @@ -29,7 +29,7 @@ extern CANMessage lastMsg[100]; extern CAN can1,can2; extern DigitalOut can1SleepMode,can2SleepMode; -extern bool pollCP; +//extern bool pollCP; extern bool tick; extern bool ZeroSecTick; extern bool headlights; @@ -49,6 +49,7 @@ extern unsigned char skin; extern unsigned char dtePeriod; extern Beep spkr; +extern unsigned char reqMsgCnt; extern "C" { void mbed_reset(); @@ -60,8 +61,9 @@ void logCan (char mType, CANMessage canRXmsg); void logTS (); void logErrMsg (char * errMsg); // gg - messeges - void sendCPreq(); - void sendTreq(); + //void sendCPreq(); + //void sendTreq(); + void sendReq(); void autoPollISR(); void playbackISR(); void recieve1();