gg
Fork of IntegrationCAN-novo by
Diff: CAN_library.cpp
- Revision:
- 5:53d7dbb8503c
- Parent:
- 4:c648a8c57106
diff -r c648a8c57106 -r 53d7dbb8503c CAN_library.cpp --- a/CAN_library.cpp Sun Jun 17 14:59:05 2018 +0000 +++ b/CAN_library.cpp Wed Jun 20 21:27:51 2018 +0000 @@ -6,57 +6,68 @@ extern uint16_t rx_flag; extern uint8_t lvdtref; extern Serial tRF; -extern uint16_t Rpm0, Speed0, Gear0, Water_Temp0, Oil_Temp0, TPS0, Brakes0, Oil_P0, MAP0, Air_Temp0, Lambda0, Volts0, Crank0; -extern uint16_t Rpm, Speed, Gear, Water_Temp, Oil_Temp, TPS, Brakes, Oil_P, MAP, Air_Temp, Lambda, Volts, Crank; +extern uint16_t Rpm0, Speed0, Gear0, Water_Temp0, Oil_Temp0, TPS0, Brakes0, Oil_P0, MAP0, Air_Temp0, Lambda0, Volts0, Crank0, BF_Oil_P0, BR_Oil_P0; +extern uint16_t Rpm, Speed, Gear, Water_Temp, Oil_Temp, TPS, Brakes, Oil_P, MAP, Air_Temp, Lambda, Volts, Crank, BF_Oil_P, BR_Oil_P; extern int FL_LVDT0, FR_LVDT0, RL_LVDT0, RR_LVDT0, FL_LVDT, FR_LVDT, RL_LVDT, RR_LVDT; extern int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref; -int LVDT_Max=150; +int LVDT_Max=1024; void CANMsgReceive(){ // CAN RX Interrupt Function CANMessage tmpMsg; if (can.read(tmpMsg)) { //Detect message - //pc.printf("%x\n",tmpMsg.id); + //pc.printf("%x\n",tmpMsg.id); + //tRF.printf("S%x%x\n",tmpMsg.id,tmpMsg.data); switch(tmpMsg.id){ //Find which DTA message is received case(0x2000): rx_flag|=(1<<0); msgDTA1=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; case(0x2001): rx_flag|=(1<<1); msgDTA2=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); //pc.printf("rx_flag=%x\n",rx_flag); break; case(0x2002): rx_flag|=(1<<2); msgDTA3=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; case(0x2003): rx_flag|=(1<<3); msgDTA4=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; case(0x2004): rx_flag|=(1<<4); msgDTA5=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; case(0x2005): rx_flag|=(1<<5); msgDTA6=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; - case(0x2006): + case(0x1006): rx_flag|=(1<<6); msgLVDTFront=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; - case(0x2007): + case(0x1007): rx_flag|=(1<<7); msgLVDTRear=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; - case(0x2008): + case(0x1008): rx_flag|=(1<<8); msgBrakes=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; - case(0x2009): + case(0x1009): rx_flag|=(1<<9); msgKm=tmpMsg; + //tRF.printf("S%x%x\n", tmpMsg.id, tmpMsg.data); break; }; //pc.printf("rx_flag=%d\n",rx_flag); @@ -186,33 +197,6 @@ FL_LVDT=newData[0]; FR_LVDT0=FR_LVDT; FR_LVDT=newData[1]; - if(!(lvdtref & (1<<3))){ //Check if its the first time LVDT value is received. If yes than store it as Referrent value. - if (FL_LVDT>FL_LVDT_Ref){ - FL_LVDT=(FL_LVDT-FL_LVDT_Ref)*100/(LVDT_Max-FL_LVDT_Ref); - }else{ - FL_LVDT=(FL_LVDT-FL_LVDT_Ref)*100/FL_LVDT_Ref; - }; - //pc.printf("Im in 1\n"); - }else{ - FL_LVDT_Ref=FL_LVDT; - FL_LVDT=0; - lvdtref=lvdtref^(1<<3); - //pc.printf("Ref=%d\n",FL_LVDT_Ref); - }; - //pc.printf("FL_LVDT=%d, FL_LVDT0=%d\n",abs(FL_LVDT),abs(FL_LVDT0)); - //pc.printf("FR_LVDT=%d, FR_LVDT0=%d\n",abs(FR_LVDT),abs(FR_LVDT0)); - - if(!(lvdtref & (1<<2))){ - if (FR_LVDT>FR_LVDT_Ref){ - FR_LVDT=(FR_LVDT-FR_LVDT_Ref)*100/(LVDT_Max-FR_LVDT_Ref); - }else{ - FR_LVDT=(FR_LVDT-FR_LVDT_Ref)*100/FR_LVDT_Ref; - }; - }else{ - FR_LVDT_Ref=FR_LVDT; - FR_LVDT=0; - lvdtref=lvdtref^(1<<2); - }; //printf("FL_Ref=%d, FR_Ref=%d, RL_Ref=%d, RR_Ref=%d\n",FL_LVDT_Dpos,FR_LVDT_Dpos,RL_LVDT_Dpos,RR_LVDT_Dpos); }; @@ -221,35 +205,16 @@ RL_LVDT=newData[0]; RR_LVDT0=RR_LVDT; RR_LVDT=newData[1]; - if(!(lvdtref & (1<<1))){ - if (RL_LVDT>RL_LVDT_Ref){ - RL_LVDT=(RL_LVDT-RL_LVDT_Ref)*100/(LVDT_Max-RL_LVDT_Ref); - }else{ - RL_LVDT=(RL_LVDT-RL_LVDT_Ref)*100/RL_LVDT_Ref; - }; - }else{ - RL_LVDT_Ref=RL_LVDT; - RL_LVDT=0; - lvdtref=lvdtref^(1<<1); - }; - - if(!(lvdtref & (1<<0))){ - if (RR_LVDT>RR_LVDT_Ref){ - RR_LVDT=(RR_LVDT-RR_LVDT_Ref)*100/(LVDT_Max-RR_LVDT_Ref); - }else{ - RR_LVDT=(RR_LVDT-RR_LVDT_Ref)*100/RR_LVDT_Ref; - }; - }else{ - RR_LVDT_Ref=RR_LVDT; - RR_LVDT=0; - lvdtref=lvdtref^(1<<0); - }; - //pc.printf("RL_LVDT=%d, RL_LVDT0=%d\n",abs(RL_LVDT),abs(RL_LVDT0)); + pc.printf("RL_LVDT=%d, RL_LVDT0=%d\n",RL_LVDT,RR_LVDT0); //pc.printf("RR_LVDT=%d, RR_LVDT0=%d\n",abs(RR_LVDT),abs(RR_LVDT0)); }; void UpdateInfoBrakes(uint16_t newData[4]){ //Update values for Brakes message + BF_Oil_P0=BF_Oil_P; + BF_Oil_P=newData[0]; + BR_Oil_P0=BR_Oil_P; + BR_Oil_P=newData[1]; Brakes0=Brakes; - Brakes=newData[0]; + Brakes=newData[2]; }; \ No newline at end of file