Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:c68d5d7a6e80
- Child:
- 1:bd7f40902a2b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon May 07 15:23:10 2018 +0000
@@ -0,0 +1,194 @@
+#include "mbed.h"
+#include "CAN_IDs.h"
+
+//CAN Identificators
+#define DTA_1 0x2000
+#define DTA_2 0x2001
+#define DTA_3 0x2002
+#define DTA_4 0x2003
+#define DTA_5 0x2004
+#define DTA_6 0x2005
+// This IDs can be changed as they are our own IDs
+#define LVDT_FRONT 0x6
+#define LVDT_REAR 0x7
+#define BRAKES 0x8
+// If we add some other IDs in the vehicle add them here
+
+CAN can1(PB_8, PB_9);
+
+char dta1[8]; //DTA1
+uint16_t Rpm,TPS, Water_Temp, Air_Temp;
+char dta2[8]; //DTA2
+uint16_t MAP, Lambda, Speed, Oil_P;
+char dta3[8]; //DTA3
+uint16_t Oil_Temp,Volts;
+char dta4[8]; //DTA4
+uint16_t Gear;
+char dta6[8];
+uint16_t Crank_Error;
+char lvdtfront[8]; //LVDTFront
+uint16_t FL_LVDT, FR_LVDT;
+char lvdtrear[8]; //LVDTRear
+uint16_t RL_LVDT, RR_LVDT;
+char brakes[8]; //Brakes
+uint16_t Brakes;
+
+int counter;
+
+void send(uint16_t ID, char dta[8]) {
+ if(can1.write(CANMessage((uint16_t)ID,dta, 8))) {
+ counter++;
+ printf("%x\n",ID);
+ printf("Message sent: info1=%x%x, info2=%x%x, info3=%x%x, info4=%x%x, counter=%d\n", dta[1],dta[0],dta[3],dta[2],dta[5],dta[4],dta[7],dta[6],counter);
+ }
+}
+
+int main() {
+ while(1){
+ counter=0;
+ CANMessage msg;
+ for(int k=0;k<150;k++){
+
+ //DTA1 CAN simulation
+ Rpm=k;
+ TPS=k*2;
+ Water_Temp=k*4;
+ Air_Temp=k*6;
+ dta1[0]=(uint8_t)(Rpm & 0x00FF);
+ dta1[1]=(uint8_t)(Rpm>>8);
+ dta1[2]=(uint8_t)(TPS & 0x00FF);
+ dta1[3]=(uint8_t)(TPS>>8);
+ dta1[4]=(uint8_t)(Water_Temp & 0x00FF);
+ dta1[5]=(uint8_t)(Water_Temp>>8);
+ dta1[6]=(uint8_t)(Air_Temp & 0x00FF);
+ dta1[7]=(uint8_t)(Air_Temp>>8);
+ send(DTA_1,dta1);
+
+
+ //DTA2 CAN simulation
+ Speed=k;
+ MAP=k*2;
+ Lambda=k*4;
+ Oil_P=k*6;
+ dta2[0]=(uint8_t)(MAP & 0x00FF);
+ dta2[1]=(uint8_t)(MAP>>8);
+ dta2[2]=(uint8_t)(Lambda & 0x00FF);
+ dta2[3]=(uint8_t)(Lambda>>8);
+ dta2[4]=(uint8_t)(Speed & 0x00FF);
+ dta2[5]=(uint8_t)(Speed>>8);
+ dta2[6]=(uint8_t)(Oil_P & 0x00FF);
+ dta2[7]=(uint8_t)(Oil_P>>8);
+ send(DTA_2,dta2);
+
+ //DTA3 CAN simulation
+ Oil_Temp=k*2;
+ Volts=k*4;
+ dta3[0]=0;
+ dta3[1]=0;
+ dta3[2]=(uint8_t)(Oil_Temp & 0x00FF);
+ dta3[3]=(uint8_t)(Oil_Temp>>8);
+ dta3[4]=(uint8_t)(Volts & 0x00FF);
+ dta3[5]=(uint8_t)(Volts>>8);
+ dta3[6]=0;
+ dta3[7]=0;
+ send(DTA_3,dta3);
+
+ //DTA4 CAN simulation
+ Gear=k/25;
+ dta4[0]=Gear;
+ send(DTA_4,dta4);
+
+ //DTA6 CAN simulation
+ if((k/10)%2){
+ //only for Crank_Error
+ dta6[4]=0xFF;
+ dta6[5]=0xFF;
+ }else{
+ dta6[4]=0;
+ dta6[5]=0;
+ };
+ send(DTA_6,dta6);
+
+ //LVDTFront CAN simulation
+ FL_LVDT=k;
+ FR_LVDT=150-k;
+ lvdtfront[0]=(uint8_t)(FL_LVDT & 0x00FF);
+ lvdtfront[1]=(uint8_t)(FL_LVDT>>8);
+ lvdtfront[2]=(uint8_t)(FR_LVDT & 0x00FF);
+ lvdtfront[3]=(uint8_t)(FR_LVDT>>8);
+ send(LVDT_FRONT,lvdtfront);
+
+ //LVDTRear CAN simulation
+ RL_LVDT=k;
+ RR_LVDT=150-k;
+ lvdtrear[0]=(uint8_t)(RL_LVDT & 0x00FF);
+ lvdtrear[1]=(uint8_t)(RL_LVDT>>8);
+ lvdtrear[2]=(uint8_t)(RR_LVDT & 0x00FF);
+ lvdtrear[3]=(uint8_t)(RR_LVDT>>8);
+ send(LVDT_REAR,lvdtrear);
+
+ //Brakes CAN simulation
+ if((k/10)%2){
+ brakes[0]=0xFF;
+ brakes[1]=0xFF;
+ }else{
+ brakes[0]=0;
+ brakes[1]=0;
+ };
+ send(BRAKES,brakes);
+
+ };
+
+ /*for(int k=150;k>0;k--){
+
+ //DTA1 CAN simulation
+ Rpm=k;
+ TPS=k*2;
+ Water_Temp=k*4;
+ Air_Temp=k*6;
+ dta1[0]=(uint8_t)(Rpm & 0x00FF);
+ dta1[1]=(uint8_t)(Rpm>>8);
+ dta1[2]=(uint8_t)(TPS & 0x00FF);
+ dta1[3]=(uint8_t)(TPS>>8);
+ dta1[4]=(uint8_t)(Water_Temp & 0x00FF);
+ dta1[5]=(uint8_t)(Water_Temp>>8);
+ dta1[6]=(uint8_t)(Air_Temp & 0x00FF);
+ dta1[7]=(uint8_t)(Air_Temp>>8);
+ send(DTA_1,dta1);
+
+ //DTA2 CAN simulation
+ Speed=k;
+ MAP=k*2;
+ Lambda=k*4;
+ Oil_P=k*6;
+ dta2[0]=(uint8_t)(MAP & 0x00FF);
+ dta2[1]=(uint8_t)(MAP>>8);
+ dta2[2]=(uint8_t)(Lambda & 0x00FF);
+ dta2[3]=(uint8_t)(Lambda>>8);
+ dta2[4]=(uint8_t)(Speed & 0x00FF);
+ dta2[5]=(uint8_t)(Speed>>8);
+ dta2[6]=(uint8_t)(Oil_P & 0x00FF);
+ dta2[7]=(uint8_t)(Oil_P>>8);
+ send(DTA_2,dta2);
+
+ //DTA3 CAN simulation
+ Oil_Temp=k*2;
+ Volts=k*4;
+ dta3[0]=0;
+ dta3[1]=0;
+ dta3[2]=(uint8_t)(Oil_Temp & 0x00FF);
+ dta3[3]=(uint8_t)(Oil_Temp>>8);
+ dta3[4]=(uint8_t)(Volts & 0x00FF);
+ dta3[5]=(uint8_t)(Volts>>8);
+ dta3[6]=0;
+ dta3[7]=0;
+ send(DTA_3,dta3);
+
+ //DTA4 CAN simulation
+ Gear=k/25;
+ dta4[0]=Gear;
+ send(DTA_4,dta4);
+
+ };*/
+ };
+};
\ No newline at end of file