Imitator CAN mreze

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
formulas
Date:
Thu Feb 07 11:18:30 2019 +0000
Parent:
0:c68d5d7a6e80
Commit message:
Imitator CAN mreze;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon May 07 15:23:10 2018 +0000
+++ b/main.cpp	Thu Feb 07 11:18:30 2019 +0000
@@ -12,10 +12,13 @@
 #define LVDT_FRONT  0x6
 #define LVDT_REAR   0x7
 #define BRAKES  0x8
+#define DISTANCE_ID 0x9
 // If we add some other IDs in the vehicle add them here
 
 CAN can1(PB_8, PB_9);
-
+Serial pc(USBTX, USBRX);
+AnalogIn speed_value(A0);
+int speed;
 char dta1[8];                               //DTA1
 uint16_t Rpm,TPS, Water_Temp, Air_Temp;
 char dta2[8];                               //DTA2                    
@@ -31,7 +34,9 @@
 char lvdtrear[8];                           //LVDTRear                                             
 uint16_t RL_LVDT, RR_LVDT;                                 
 char brakes[8];                             //Brakes                                             
-uint16_t Brakes;                                           
+uint16_t Brakes;
+char distance[8];
+uint32_t Distance;                                  
 
 int counter;
 
@@ -40,15 +45,45 @@
         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);
+    }else{
+        printf("Shit\n");
     } 
-}
+};
 
 int main() {
+    
+    CANMessage msg;
+    Distance=(uint32_t)2000;
+    distance[0]=(uint8_t)(Distance & 0x000000FF);
+    distance[1]=(uint8_t)((Distance & 0x0000FF00)>>8);
+    distance[2]=(uint8_t)((Distance & 0x00FF0000)>>16);
+    distance[3]=(uint8_t)((Distance & 0xFF000000)>>24);
+    distance[4]=0;
+    distance[5]=0;
+    distance[6]=0;
+    distance[7]=0;
+    //pc.printf("distance=%d\n",Distance);   
+    send(DISTANCE_ID,distance);
+    
     while(1){
         counter=0;
-        CANMessage msg;
-        for(int k=0;k<150;k++){
-            
+        speed=(int)(speed_value.read()*150);
+        //speed=123;
+        dta2[0]=0;
+        dta2[1]=0;
+        dta2[2]=0;
+        dta2[3]=0;
+        dta2[4]=(uint8_t)(speed & 0x00FF);
+        dta2[5]=(uint8_t)(speed>>8);
+        dta2[6]=0;
+        dta2[7]=0;
+        pc.printf("speed=%d\n",speed);   
+        send(DTA_2,dta2);
+        
+    
+        /* for(int k=0;k<150;k++){
+           
+           
             //DTA1 CAN simulation
             Rpm=k;
             TPS=k*2;
@@ -137,7 +172,7 @@
             };
             send(BRAKES,brakes);
             
-        };
+        };*/
         
         /*for(int k=150;k>0;k--){