Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Diff: utility.cpp
- Revision:
- 78:a383971fe02f
- Parent:
- 77:7c136766466c
- Child:
- 79:68f0dd8d1f19
- Child:
- 81:cf009a64eedd
diff -r 7c136766466c -r a383971fe02f utility.cpp --- 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; }