A class for using MU2.
Dependents: EM_Mission FM_integration_copy FM_integration_off FM_integration
Diff: MU2Class.cpp
- Revision:
- 4:a7d413a2889d
- Parent:
- 2:2297b491e452
diff -r 9f98138ed0c4 -r a7d413a2889d MU2Class.cpp --- a/MU2Class.cpp Wed Jul 10 04:11:56 2013 +0000 +++ b/MU2Class.cpp Sat Jul 13 11:16:09 2013 +0000 @@ -1,33 +1,29 @@ #include "MU2Class.h" #include "mbed.h" -//#include <stdlib.h> MU2Class::MU2Class(PinName tx,PinName rx){ _tx=tx; _rx=rx; } +/*MU2Class::MU2Class(PinName tx,PinName rx) : Serial(tx,rx){ +}*/ + uint8_t MU2Class::Store_Str(char data_str[], int index, char Message[]){ uint8_t j=0; while(Message[j]!='\0'&&Message[j]!='^') data_str[index++]=Message[j++];//store char in message into data_str and returns the last index. return index; } -/*uint8_t MU2Class::Store_Int(int data_int[], int index, int Message[]){ - uint8_t j=0; - while(Message[j]!='\0'&&Message[j]!='^') data_int[index++]=Message[j++];//store char in message into data_str and returns the last index. - return index; -}*/ - void MU2Class::send(char Send_Message[]){ Serial MyMu2(_tx,_rx); - Serial pc(USBTX,USBRX); + //Serial pc(USBTX,USBRX); int i=4, str_length=0,send_index=0; char send_data[255]; MyMu2.baud(19200); - pc.baud(19200); + //pc.baud(19200); send_index=0;//initializing the variant. send_index=Store_Str(send_data, send_index, "@DT00^");//this variant is the last index of the string.The reason why char "^" here is that for the case of the data size 10,20,A0 or something . Store_Str copies the string of its last variant into its first variant . @@ -35,10 +31,11 @@ while(Send_Message[str_length]!='\0'){ send_data[send_index++]=Send_Message[str_length++];//storing the string we wanna send into the send_data until null terminater appers. } - send_data[send_index++]='\r';//insert carrige return at the last of send_data. - send_data[send_index++]='\n'; + //send_data[send_index++]='\r';//insert carrige return at the last of send_data. + //send_data[send_index++]='\n'; + send_data[send_index++]='\0'; - //str_length-=2; //the code block below is for making data size proper. + str_length-=2; //the code block below is for making data size proper. for(i=4; i>2; i--){ if(str_length%16<10){ @@ -60,48 +57,4 @@ MyMu2.putc(send_data[j]); pc.putc(send_data[j]); //for debugging.Comment out when U use this in practice. }*/ -} - -/*void MU2Class::send(int Send_Message[]){ - Serial MyMu2(_tx,_rx); - Serial pc(USBTX,USBRX); - - int i=4, int_length=0,send_index=0; - char send_data[255]; - - MyMu2.baud(19200); - pc.baud(19200); - - send_index=0;//initializing the variant. - send_index=Store_Str(send_data, send_index, "@DT00^");//this variant is the last index of the string.The reason why char "^" here is that for the case of the data size 10,20,A0 or something . Store_Str copies the string of its last variant into its first variant . - - while(Send_Message[int_length]!='\0'){ - //send_data[send_index++]=Send_Message[int_length++];//storing the string we wanna send into the send_data until null terminater appers. - //itoa(Send_Message[int_length++],send_data[send_index++],10); - - } - send_data[send_index++]='\r';//insert carrige return at the last of send_data. - send_data[send_index++]='\n'; - - //str_length-=2; //the code block below is for making data size proper. - - for(i=4; i>2; i--){ - if(int_length%16<10){ - send_data[i]='0'+int_length%16; - }else{ - switch(int_length%16){ - case 10:send_data[i]='A'; break; - case 11:send_data[i]='B'; break; - case 12:send_data[i]='C'; break; - case 13:send_data[i]='D'; break; - case 14:send_data[i]='E'; break; - case 15:send_data[i]='F'; break; - } - } - int_length/=16; - } - for(int j=0;j<=send_index;j++){ - MyMu2.putc(send_data[j]); - pc.putc(send_data[j]); //for debugging.Comment out when U use this in practice. - } -}*/ \ No newline at end of file +} \ No newline at end of file