for CAN communication between mbed

Dependents:   EM_Logger EM_Mission

Revision:
2:e0e7269bf1f0
Parent:
1:0732a5dec208
diff -r 0732a5dec208 -r e0e7269bf1f0 myCAN.cpp
--- a/myCAN.cpp	Fri Aug 02 10:50:57 2013 +0000
+++ b/myCAN.cpp	Sat Aug 03 09:13:48 2013 +0000
@@ -44,6 +44,7 @@
 {
     if(user == MISSION) {
         write(CANMessage(MISSION_STATUS,CANdata[MISSION_STATUS]));
+        wait_ms(5);
     } else if(user == LOGGER) {
         write(CANMessage(GPS_TIME,CANdata[GPS_TIME]));
         wait_ms(5);
@@ -57,9 +58,7 @@
         wait_ms(5);
         write(CANMessage(SCP1000_PRES_TEMP,CANdata[SCP1000_PRES_TEMP]));
         wait_ms(5);
-        write(CANMessage(ADXL345_XYZ,CANdata[ADXL345_XYZ]));
-        wait_ms(5);
-        write(CANMessage(ITG3200_XYZ,CANdata[ITG3200_XYZ]));
+        write(CANMessage(ANGLE_DATA,CANdata[ANGLE_DATA]));
         wait_ms(5);
     } else {}
 }
@@ -94,13 +93,14 @@
         CANdata[GPS_LON_2][i] = longitude[i+8];
     }
 
-    //CANdata[SCP1000_PRES_TEMP][0]=(char)((temp & 0xF0)>>4);
-    //CANdata[SCP1000_PRES_TEMP][1]=(char)(temp & 0x0F);
-    //CANdata[SCP1000_PRES_TEMP][2]=(char)((pres & 0xF0)>>4);
-    //CANdata[SCP1000_PRES_TEMP][3]=(char)(pres & 0x0F);
+    CANdata[SCP1000_PRES_TEMP][0]=(char)((pres & 0xFF0000)>>16);
+    CANdata[SCP1000_PRES_TEMP][1]=(char)((pres & 0x00FF00)>>8);
+    CANdata[SCP1000_PRES_TEMP][2]=(char)(pres & 0x0000FF);
+    CANdata[SCP1000_PRES_TEMP][3]=(char)((temp & 0xFF00)>>8);
+    CANdata[SCP1000_PRES_TEMP][4]=(char)(temp & 0x00FF);
     
-    CANdata[ADXL345_XYZ][0] = (char)((roll&0xFF00)>>8);
-    CANdata[ADXL345_XYZ][1] = (char)(roll&0x00FF);
+    CANdata[ANGLE_DATA][0] = (char)((roll&0xFF00)>>8);
+    CANdata[ANGLE_DATA][1] = (char)(roll&0x00FF);
 }
 
 char* myCAN::get_time(void)
@@ -140,20 +140,20 @@
 }
 
 int myCAN::get_roll(void){
-    hroll = CANdata[ADXL345_XYZ][0];
-    lroll = CANdata[ADXL345_XYZ][1];
+    hroll = CANdata[ANGLE_DATA][0];
+    lroll = CANdata[ANGLE_DATA][1];
     roll = ((((int)(hroll))<<8) & 0xFF00) | (((int)(lroll))&0x00FF);
     return roll;
 }
 
 float myCAN::get_temp(void)
 {
-    temp = (float)(((int)(CANdata[SCP1000_PRES_TEMP][0])<<4+(int)(CANdata[SCP1000_PRES_TEMP][1]))/20.0);
+    temp = (float)((((int)(CANdata[SCP1000_PRES_TEMP][3]))<<8+(int)(CANdata[SCP1000_PRES_TEMP][4]))/20.0);
     return temp;
 }
 
 int myCAN::get_pres(void)
 {
-    pres = (int)(CANdata[SCP1000_PRES_TEMP][2])<<4+(int)(CANdata[SCP1000_PRES_TEMP][3]);
+    pres = ((int)(CANdata[SCP1000_PRES_TEMP][0]))<<16 + ((int)(CANdata[SCP1000_PRES_TEMP][1]))<<8+(int)(CANdata[SCP1000_PRES_TEMP][8]);
     return pres;
 }
\ No newline at end of file