Matthew Marino
/
MBED_CAN_Telemetry
telemetry node
Revision 1:69a8c8a7cf1d, committed 2019-04-01
- Comitter:
- LukeMar
- Date:
- Mon Apr 01 04:24:18 2019 +0000
- Parent:
- 0:8128714922a1
- Commit message:
- 4/1/19
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8128714922a1 -r 69a8c8a7cf1d main.cpp --- a/main.cpp Sun Mar 17 01:01:21 2019 +0000 +++ b/main.cpp Mon Apr 01 04:24:18 2019 +0000 @@ -6,14 +6,14 @@ #define RUDDER_ID 1 //Address of this CAN device #define BNO_ID 2 //Address of Control CAN device -#define TELE_ID 3 -#define RC_ID 4 +#define TELE_ID 3 +#define RC_ID 4 Serial pc(USBTX, USBRX); //tx, and rx for tera term DigitalOut led1(LED1); //heartbeat DigitalOut led2(LED2); //CAN read activity DigitalOut led3(LED3); //CAN write activity - +DigitalOut led4(LED4); CAN can(p30,p29); //CAN interface @@ -23,65 +23,198 @@ float RC_out; char datastr[20]; CANMessage msg_read; +float ff = 1.0; -float CanValue(){ - strcpy(datastr, (char*)msg_read.data+1); - float value = strtod(datastr,NULL); - return value; -} +float data; //telemetry data transmition -void alive(void){ - led1 = !led1; - if(led1) - pulse.attach(&alive, .2); // the address of the function to be attached (flip) and the interval (2 seconds) - else - pulse.attach(&alive, 1.3); // the address of the function to be attached (flip) and the interval (2 seconds) +float CanValue() +{ + strcpy(datastr, (char*)msg_read.data+1); + float value = strtod(datastr,NULL); + return value; } -void Bno_Read(){ - - while(can.read(msg_read)){ //if message is available, read into msg - if(msg_read.id == BNO_ID){ //if its the BNO ID - if(msg_read.data[0] == 's' || msg_read.data[0] == 'S'){ - led2 = !led2; - BNOangle = CanValue(); - pc.printf("BNO: %.1f\n",BNOangle); - }//if the first letter was an 's', it is a servo command - } //was the message to this device? - }//while a CAN message has been read - //return datastr; +//void alive(void) +//{ +// led1 = !led1; +// if(led1) +// pulse.attach(&alive, .2); // the address of the function to be attached (flip) and the interval (2 seconds) +// else +// pulse.attach(&alive, 1.3); // the address of the function to be attached (flip) and the interval (2 seconds) +//} +void Time_Read(); +void Lat_Read(); +void Long_Read(); +void Bno_Read(); +void Rudder_Read(); +void Mast_Read(); + + +int main() +{ + + Thread::wait(200); + + // pulse.attach(&alive, 2.0); // the address of the function to be attached (alive) and the interval (2 seconds) + can.frequency(500000); + pc.baud(115200); + + pc.printf("%s\r\n", __FILE__); + + while(1) { + //while(msg_read.data[0] != 'm' || msg_read.data[0] != 'M') {Thread::wait(ff);} + //Time_Read(); + + //while(msg_read.data[0] != 'm' || msg_read.data[0] != 'M') {Thread::wait(ff);} + //Lat_Read(); + + //while(msg_read.data[0] != 'm' || msg_read.data[0] != 'M') {Thread::wait(ff);} + //Long_Read(); -} -void RC_Read(){ - - while(can.read(msg_read)){ //if message is available, read into msg - if(msg_read.id == RC_ID){ //if its the BNO ID - if(msg_read.data[0] == 'r' || msg_read.data[0] == 'R'){ - led3 = !led3; - RC_out = CanValue(); - pc.printf("RC: %.1f\n",RC_out); - }//if the first letter was an 's', it is a servo command - } //was the message to this device? - }//while a CAN message has been read - //return datastr; + //while(msg_read.data[0] != 'b' || msg_read.data[0] != 'B') {Thread::wait(ff);} + Bno_Read(); + + //while(msg_read.data[0] != 'r' || msg_read.data[0] != 'R') {Thread::wait(ff);} + Rudder_Read(); + + //while(msg_read.data[0] != 'm' || msg_read.data[0] != 'M') {Thread::wait(ff);} + Mast_Read(); + + } + + +}//main + + +void Bno_Read() +{ + + while(can.read(msg_read)) { //if message is available, read into msg + + if(msg_read.id == BNO_ID) { //if its the BNO ID + + if(msg_read.data[0] == 'b' || msg_read.data[0] == 'B') { + + led1 = !led1; + BNOangle = CanValue(); + //data = BNOangle; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("BNO: %.1f", BNOangle); //data); + + }//if the first letter was an 's', it is a servo command + } //was the message to this device? + + }//while a CAN message has been read + //return datastr; } -int main() { - - Thread::wait(200); - - pulse.attach(&alive, 2.0); // the address of the function to be attached (alive) and the interval (2 seconds) - can.frequency(500000); - pc.baud(115200); - - pc.printf("%s\r\n", __FILE__); - - while(1){ - Bno_Read(); - RC_Read(); - - } - - -}//main \ No newline at end of file +void Lat_Read() +{ + + while(can.read(msg_read)) { //if message is available, read into msg + + if(msg_read.id == BNO_ID) { //if its the BNO ID + + if(msg_read.data[0] == 'L' || msg_read.data[0] == 'l') { + + //led2 = !led2; + BNOangle = CanValue(); + //data = BNOangle; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("Lat: %.1f", BNOangle); //data); + //Thread::wait(ff); + }//if the first letter was an 's', it is a servo command + } //was the message to this device? + }//while a CAN message has been read + //return datastr; + +} + +void Long_Read() +{ + + while(can.read(msg_read)) { //if message is available, read into msg + + //if(msg_read.id == BNO_ID) { //if its the BNO ID + + if(msg_read.data[0] == 'O' || msg_read.data[0] == 'o') { + + //led2 = !led2; + BNOangle = CanValue(); + //data = BNOangle; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("Long: %.1f", BNOangle); //data); + //Thread::wait(ff); + }//if the first letter was an 's', it is a servo command + //} //was the message to this device? + }//while a CAN message has been read + //return datastr; + +} + +void Time_Read() +{ + float time; + while(can.read(msg_read)) { //if message is available, read into msg + + //if(msg_read.id == BNO_ID) { //if its the BNO ID + + if(msg_read.data[0] == 't' || msg_read.data[0] == 'T') { + + led2 = !led2; + time = CanValue(); + //data = BNOangle; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("Time: %.1f", time); //data); + //Thread::wait(ff); + }//if the first letter was an 's', it is a servo command + // } //was the message to this device? + }//while a CAN message has been read + //return datastr; + +} + +void Rudder_Read() +{ + + while(can.read(msg_read)) { //if message is available, read into msg + //if(msg_read.id == RC_ID) { //if its the BNO ID + if(msg_read.data[0] == 'r' || msg_read.data[0] == 'R') { + led3 = !led3; + RC_out = CanValue(); //I know this is redundant but i use + //data = RC_out; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("Rudder: %.1f", RC_out); //data); + //Thread::wait(ff); + }//if the first letter was an 's', it is a servo command + // } //was the message to this device? + }//while a CAN message has been read + //return datastr; + +} + +void Mast_Read() +{ + + while(can.read(msg_read)) { //if message is available, read into msg + // if(msg_read.id == RC_ID) { //if its the BNO ID + if(msg_read.data[0] == 'm' || msg_read.data[0] == 'M') { + led4 = !led4; + RC_out = CanValue(); //I know this is redundant but i use + //data = RC_out; //a similar form of the code everywhere + //myFloat.m_float = data; + //data = myFloat.m_float; // get the float back from the union + pc.printf("Mast: %.1f\n", RC_out); //data); + //Thread::wait(ff); + }//if the first letter was an 's', it is a servo command + //} //was the message to this device? + }//while a CAN message has been read + //return datastr; + +} \ No newline at end of file