Dual CANbus monitor and instrumentation cluster
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Diff: utility.cpp
- Revision:
- 81:cf009a64eedd
- Parent:
- 80:24f1793171e7
- Parent:
- 78:a383971fe02f
- Child:
- 83:52b1f330a62d
--- a/utility.cpp Tue Apr 16 21:13:59 2013 +0000 +++ b/utility.cpp Tue Apr 16 21:49:13 2013 +0000 @@ -235,41 +235,45 @@ bdi=0x20; // index 0 - 2 from SeqNum 20 - 22 sprintf(sTemp,"Getting temperature data\n"); logMsg(sTemp); - }else bdi=0; // strange, BUG? the same as Group 2 - + //}else bdi=0; // strange, BUG? the same as Group 2 + }else bdi=0xff; // ignore other messages (for now) + lasti=0; } - // handle this response - i=canRXmsg.data[0]&0x0f; // lower nibble of D0 is index, 0 to F - if(lasti>i){ //detect rollover to 20 (index 0) and offset index appropriately - bdi=0x10; // adding 10 to the index for CPs - } - lasti=i; //remember the index nibble to detect rollover next time around - i+=bdi; // 0 to F then 10 through about 1C for CPs - // 20 through 22 for the Temperatures (Group 4) + + if(bdi<0xff){ + // handle just the recognized response + i=canRXmsg.data[0]&0x0f; // lower nibble of D0 is index, 0 to F + if(lasti>i){ //detect rollover to 20 (index 0) and offset index appropriately + bdi=0x10; // adding 10 to the index for CPs + } + lasti=i; //remember the index nibble to detect rollover next time around + i+=bdi; // 0 to F then 10 through about 1C for CPs + // 20 through 22 for the Temperatures (Group 4) - //-------------- - // detect last response from the Temperature series. - //if(i==22) logCP=true; //Turbo3 - //if( (i==22) && (yesBattLog) ) logCP=true; // only if enabled gg - Batt Log - if(i==22){ - // is the last response from Temperatures - logCP=yesBattLog; // Only log if logging enabled - showCP=true; // Always show - } + //-------------- + // detect last response from the Temperature series. + //if(i==22) logCP=true; //Turbo3 + //if( (i==22) && (yesBattLog) ) logCP=true; // only if enabled gg - Batt Log + if(i==22){ + // is the last response from Temperatures + logCP=yesBattLog; // Only log if logging enabled + showCP=true; // Always show + } - // storing 7 bytes of data from each response (after the SeqNum) - i*=7; - if(i<0xfa){ // Is there a better way to do this? - // for CP data the base is 0, at i is (i*7)+6 and the last is 28*7+6 - // for Temp data, base is 32*7, at i is (i*7)+6 and the last is 34*7+6 - 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]; + // storing 7 bytes of data from each response (after the SeqNum) + i*=7; + if(i<0xfa){ // Is there a better way to do this? + // for CP data the base is 0, at i is (i*7)+6 and the last is 28*7+6 + // for Temp data, base is 32*7, at i is (i*7)+6 and the last is 34*7+6 + 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]; + } } //---------------------- @@ -286,30 +290,8 @@ mWs_x4 += imWs_x4; // total mWs_x4 numWsamples++; } -//------------------------- -#if 0 - }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps - packV=((canRXmsg.data[2]<<2)|(canRXmsg.data[3]>>6)); // 1 LSB = 0.5V - packA=((canRXmsg.data[0]<<3)|(canRXmsg.data[1]>>5)); // 1 LSB = 0.5A - if(packA>0x03ff){ - packA|=0xf800;//extend sign; - } - imWs_x4 = packV; // Volts*milliSeconds*2 - imWs_x4 *= -packA; // milliWattseconds*4 - if (!((imotorRPM<2)&&(imWs_x4<0))){ //Ignore if charging from wall - mWs_x4 += imWs_x4; // total mWs_x4 - numWsamples++; - } - }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed - imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); - if(imotorRPM<0){ // take absolute value - imotorRPM=-imotorRPM; - } - motorRPM+=imotorRPM; - numSsamples++; - } -#endif -//------------------------- + + //------------------------- }else if((mType==1)&&(canRXmsg.id==0x1da)){ // EV bus // Motor Speed imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); @@ -356,7 +338,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 @@ -400,8 +429,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; }