for CAN communication between mbed
Dependents: EM_Logger EM_Mission
Revision 4:ef1cc9f2945e, committed 2013-08-16
- Comitter:
- YSB
- Date:
- Fri Aug 16 08:24:30 2013 +0000
- Parent:
- 0:89073e0112db
- Commit message:
- 20130816ver
Changed in this revision
myCAN.cpp | Show annotated file Show diff for this revision Revisions of this file |
myCAN.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 89073e0112db -r ef1cc9f2945e myCAN.cpp --- a/myCAN.cpp Sun Jul 21 07:02:45 2013 +0000 +++ b/myCAN.cpp Fri Aug 16 08:24:30 2013 +0000 @@ -44,15 +44,24 @@ { 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); write(CANMessage(GPS_LAT_1,CANdata[GPS_LAT_1])); + wait_ms(5); write(CANMessage(GPS_LAT_2,CANdata[GPS_LAT_2])); + wait_ms(5); write(CANMessage(GPS_LON_1,CANdata[GPS_LON_1])); + wait_ms(5); write(CANMessage(GPS_LON_2,CANdata[GPS_LON_2])); + 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])); + wait_ms(5); } else {} } @@ -65,7 +74,7 @@ } } -void myCAN::make_logger_senddata(char* time,int NoS,char* latitude,char* longitude,int a_z,int temp,int pres) +void myCAN::make_logger_senddata(char* time,int NoS,char* latitude,char* longitude,int roll,int pitch,int temp,int pres) { for(int i=0; i<8; i++) { CANdata[GPS_TIME][i] = time[i]; @@ -86,12 +95,16 @@ 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)((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[GPS_LAT_2][2] = a_z; + CANdata[ADXL345_XYZ][0] = (char)((roll&0xFF00)>>8); + CANdata[ADXL345_XYZ][1] = (char)(roll&0x00FF); + + CANdata[ADXL345_XYZ][2] = (char)((pitch&0xFF00)>>8); + CANdata[ADXL345_XYZ][3] = (char)(pitch&0x00FF); } char* myCAN::get_time(void) @@ -129,39 +142,19 @@ NoS = CANdata[GPS_LAT_2][1]; return NoS; } -float myCAN::get_a_x(void) -{ - return acel[0]; -} -float myCAN::get_a_y(void) -{ - - return acel[1]; -} - -int myCAN::get_a_z(void) -{ - acel[2] = CANdata[GPS_LAT_2][2]; - return acel[2]; +int myCAN::get_roll(void){ + hroll = CANdata[ADXL345_XYZ][0]; + lroll = CANdata[ADXL345_XYZ][1]; + roll = ((((short)(hroll))<<8) & 0xFF00) | (((short)(lroll))&0x00FF); + return roll; } -int myCAN::get_j_x(void) -{ - - return jail[0]; -} - -int myCAN::get_j_y(void) -{ - - return jail[1]; -} - -int myCAN::get_j_z(void) -{ - - return jail[2]; +int myCAN::get_pitch(void){ + hpitch = CANdata[ADXL345_XYZ][2]; + lpitch = CANdata[ADXL345_XYZ][3]; + pitch = ((((short)(hroll))<<8) & 0xFF00) | (((short)(lroll))&0x00FF); + return pitch; } float myCAN::get_temp(void) @@ -174,4 +167,13 @@ { pres = (int)(CANdata[SCP1000_PRES_TEMP][2])<<4+(int)(CANdata[SCP1000_PRES_TEMP][3]); return pres; +} + +void myCAN::make_mission_senddata(int status){ + CANdata[MISSION_STATUS][0] = status; +} + +int myCAN::get_mission_status(void){ + mission_status = CANdata[MISSION_STATUS][0]; + return mission_status; } \ No newline at end of file
diff -r 89073e0112db -r ef1cc9f2945e myCAN.h --- a/myCAN.h Sun Jul 21 07:02:45 2013 +0000 +++ b/myCAN.h Fri Aug 16 08:24:30 2013 +0000 @@ -17,15 +17,13 @@ float get_temp(void); int get_pres(void); - float get_a_x(void); - float get_a_y(void); - int get_a_z(void); - int get_j_x(void); - int get_j_y(void); - int get_j_z(void); + int get_roll(void); + int get_pitch(void); - void make_logger_senddata(char* time,int NoS,char* latitude,char* longitude,int a_z,int temp,int pres); - void make_mission_senddata(void); + int get_mission_status(void); + + void make_logger_senddata(char* time,int NoS,char* latitude,char* longitude,int roll,int pitch,int temp,int pres); + void make_mission_senddata(int status); void send(char user); @@ -39,9 +37,14 @@ char latitude[10]; char longitude[11]; - int acel[3]; - int jail[3]; + int mission_status; + char hroll; + char lroll; + int roll; + char hpitch; + char lpitch; + int pitch; int temp; int pres;