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:
- 121:553faf139a20
- Parent:
- 120:041edeec08f5
- Child:
- 122:138a40892a4c
--- a/utility.cpp Mon Jul 08 02:08:08 2013 +0000 +++ b/utility.cpp Thu Jul 11 05:29:18 2013 +0000 @@ -208,35 +208,41 @@ if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data? Need to store all responses if(canRXmsg.data[0]<0x20){ if(canRXmsg.data[3]==1){//Group 1 data - bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22) + bdi=BatDataBaseG1; // index offset for Group 1 data if(debugMode){ 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) + bdi=BatDataBaseG2; // index offset for CP data if(debugMode){ 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) + bdi=BatDataBaseG3; // index offset for Group 3 data if(debugMode){ 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) + bdi=BatDataBaseG4; // index offset for Temperature data if(debugMode){ 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) + bdi=BatDataBaseG5; // index offset for Group 5 data if(debugMode){ printMsg(" Getting Group 5 data\n"); } + }else if(canRXmsg.data[3]==6){//Group 6 data = shunt data + bdi=BatDataBaseG6; // index offset for Group 6 data + if(debugMode){ + printMsg(" Getting Group 6 data\n"); + } + }else bdi=0xff; // ignore other messages (for now) lasti=0; } @@ -249,12 +255,23 @@ lasti=i; //remember the msb to detect rollover next time around i+=bdi; //------- - if(i==BatDataBaseG5){ // Last of Temperature data was loaded last time + //------- + i*=7; + if(i+6 < BatDataBufMax) { + 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(i==(BatDataBaseG6+3)*7){ // All data loaded logCP=yesBattLog; // Only log if logging enabled showCP=true; // Always show + + // Find hottest temperature by finding smallest ADC value // 2013 models only have three sensors - // Or =25+(467-ADC)/9.33 (C) - // Find hottest temperature by finding smallest ADC value k=battData[(BatDataBaseG4*7)+3]*0x100+battData[(BatDataBaseG4*7)+4]; j=battData[(BatDataBaseG4*7)+6]*0x100+battData[(BatDataBaseG4*7)+7]; if(j<k)k=j; @@ -272,20 +289,18 @@ maxTemp*=(temp_C[ii-1]-temp_C[ii]); maxTemp+=temp_C[ii]; + // Get state of health SOH_x100=battData[(BatDataBaseG1*7)+29]*0x100+battData[(BatDataBaseG1*7)+30]; Ah_x10000=battData[(BatDataBaseG1*7)+36]*0x10000+battData[(BatDataBaseG1*7)+37]*0x100+battData[(BatDataBaseG1*7)+38]; SOC_x10000=battData[(BatDataBaseG1*7)+32]*0x10000+battData[(BatDataBaseG1*7)+33]*0x100+battData[(BatDataBaseG1*7)+34]; - } - //------- - i*=7; - if(i+6 < BatDataBufMax) { - 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]; + + // Save shunt data + for(j=0; j<24; j++){ + shunt[j*4+0]=battData[BatDataBaseG6*7+j+3]&0x08; + shunt[j*4+1]=battData[BatDataBaseG6*7+j+3]&0x04; + shunt[j*4+2]=battData[BatDataBaseG6*7+j+3]&0x02; + shunt[j*4+3]=battData[BatDataBaseG6*7+j+3]&0x01; + } } } }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps @@ -295,22 +310,34 @@ packA_x2|=0xf800;//extend sign; } packA_x2 -= 1; //Slight correction to value required (unique to my Leaf?) + if (-packA_x2<Imin){ + Imin=-packA_x2; + } else if (-packA_x2>Imax){ + Imax=-packA_x2; + } imWs_x4 = packV_x2; // Volts*milliSeconds*2 imWs_x4 *= -packA_x2; // milliWattseconds*4 mWs_x4 += imWs_x4; // total mWs_x4 - float temp = packV_x2-Resr*packA_x2; + float temp; + temp = Resr; + temp *= (float) -packA_x2; + temp += (float) packV_x2; if(temp>curRmax){ curRmax=temp; } else if(temp<curRmin){ curRmin=temp; } - temp = packV_x2-(Resr-0.001)*packA_x2; + temp = Resr-0.001; + temp *= (float) -packA_x2; + temp += (float) packV_x2; if(temp>redRmax){ redRmax=temp; } else if(temp<redRmin){ redRmin=temp; } - temp = packV_x2-(Resr+0.001)*packA_x2; + temp = Resr+0.001; + temp *= (float) -packA_x2; + temp += (float) packV_x2; if(temp>incRmax){ incRmax=temp; } else if(temp<incRmin){ @@ -392,7 +419,12 @@ data[1]=0x21; data[2]=0x05; break; - case BatDataBaseG6: // group 5 has 11 frames + case BatDataBaseG6: // group 4 has 3 frames + data[0]=0x02; //change to request group 5 + data[1]=0x21; + data[2]=0x06; + break; + case BatDataBaseG7: // group 5 has 11 frames reqMsgCnt = 99; can1SleepMode = VP230Sleep; // disable TX can1.monitor(true); // set to snoop mode