A class for using MU2.
Dependents: EM_Mission FM_integration_copy FM_integration_off FM_integration
MU2Class.cpp@4:a7d413a2889d, 2013-07-13 (annotated)
- Committer:
- ATKINZ117
- Date:
- Sat Jul 13 11:16:09 2013 +0000
- Revision:
- 4:a7d413a2889d
- Parent:
- 2:2297b491e452
checked can send GPS data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ATKINZ117 | 0:6c7ba361f738 | 1 | #include "MU2Class.h" |
ATKINZ117 | 0:6c7ba361f738 | 2 | #include "mbed.h" |
ATKINZ117 | 0:6c7ba361f738 | 3 | |
ATKINZ117 | 0:6c7ba361f738 | 4 | MU2Class::MU2Class(PinName tx,PinName rx){ |
ATKINZ117 | 0:6c7ba361f738 | 5 | _tx=tx; |
ATKINZ117 | 0:6c7ba361f738 | 6 | _rx=rx; |
ATKINZ117 | 0:6c7ba361f738 | 7 | } |
ATKINZ117 | 0:6c7ba361f738 | 8 | |
ATKINZ117 | 4:a7d413a2889d | 9 | /*MU2Class::MU2Class(PinName tx,PinName rx) : Serial(tx,rx){ |
ATKINZ117 | 4:a7d413a2889d | 10 | }*/ |
ATKINZ117 | 4:a7d413a2889d | 11 | |
ATKINZ117 | 0:6c7ba361f738 | 12 | uint8_t MU2Class::Store_Str(char data_str[], int index, char Message[]){ |
ATKINZ117 | 0:6c7ba361f738 | 13 | uint8_t j=0; |
ATKINZ117 | 0:6c7ba361f738 | 14 | while(Message[j]!='\0'&&Message[j]!='^') data_str[index++]=Message[j++];//store char in message into data_str and returns the last index. |
ATKINZ117 | 0:6c7ba361f738 | 15 | return index; |
ATKINZ117 | 0:6c7ba361f738 | 16 | } |
ATKINZ117 | 0:6c7ba361f738 | 17 | |
ATKINZ117 | 1:c60752b4acb9 | 18 | void MU2Class::send(char Send_Message[]){ |
ATKINZ117 | 0:6c7ba361f738 | 19 | Serial MyMu2(_tx,_rx); |
ATKINZ117 | 4:a7d413a2889d | 20 | //Serial pc(USBTX,USBRX); |
ATKINZ117 | 0:6c7ba361f738 | 21 | |
ATKINZ117 | 0:6c7ba361f738 | 22 | int i=4, str_length=0,send_index=0; |
ATKINZ117 | 0:6c7ba361f738 | 23 | char send_data[255]; |
ATKINZ117 | 0:6c7ba361f738 | 24 | |
ATKINZ117 | 0:6c7ba361f738 | 25 | MyMu2.baud(19200); |
ATKINZ117 | 4:a7d413a2889d | 26 | //pc.baud(19200); |
ATKINZ117 | 0:6c7ba361f738 | 27 | |
ATKINZ117 | 0:6c7ba361f738 | 28 | send_index=0;//initializing the variant. |
ATKINZ117 | 0:6c7ba361f738 | 29 | 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 . |
ATKINZ117 | 0:6c7ba361f738 | 30 | |
ATKINZ117 | 0:6c7ba361f738 | 31 | while(Send_Message[str_length]!='\0'){ |
ATKINZ117 | 0:6c7ba361f738 | 32 | send_data[send_index++]=Send_Message[str_length++];//storing the string we wanna send into the send_data until null terminater appers. |
ATKINZ117 | 0:6c7ba361f738 | 33 | } |
ATKINZ117 | 4:a7d413a2889d | 34 | //send_data[send_index++]='\r';//insert carrige return at the last of send_data. |
ATKINZ117 | 4:a7d413a2889d | 35 | //send_data[send_index++]='\n'; |
ATKINZ117 | 4:a7d413a2889d | 36 | send_data[send_index++]='\0'; |
ATKINZ117 | 0:6c7ba361f738 | 37 | |
ATKINZ117 | 4:a7d413a2889d | 38 | str_length-=2; //the code block below is for making data size proper. |
ATKINZ117 | 0:6c7ba361f738 | 39 | |
ATKINZ117 | 0:6c7ba361f738 | 40 | for(i=4; i>2; i--){ |
ATKINZ117 | 0:6c7ba361f738 | 41 | if(str_length%16<10){ |
ATKINZ117 | 0:6c7ba361f738 | 42 | send_data[i]='0'+str_length%16; |
ATKINZ117 | 0:6c7ba361f738 | 43 | }else{ |
ATKINZ117 | 0:6c7ba361f738 | 44 | switch(str_length%16){ |
ATKINZ117 | 0:6c7ba361f738 | 45 | case 10:send_data[i]='A'; break; |
ATKINZ117 | 0:6c7ba361f738 | 46 | case 11:send_data[i]='B'; break; |
ATKINZ117 | 0:6c7ba361f738 | 47 | case 12:send_data[i]='C'; break; |
ATKINZ117 | 0:6c7ba361f738 | 48 | case 13:send_data[i]='D'; break; |
ATKINZ117 | 0:6c7ba361f738 | 49 | case 14:send_data[i]='E'; break; |
ATKINZ117 | 0:6c7ba361f738 | 50 | case 15:send_data[i]='F'; break; |
ATKINZ117 | 0:6c7ba361f738 | 51 | } |
ATKINZ117 | 0:6c7ba361f738 | 52 | } |
ATKINZ117 | 0:6c7ba361f738 | 53 | str_length/=16; |
ATKINZ117 | 0:6c7ba361f738 | 54 | } |
ATKINZ117 | 2:2297b491e452 | 55 | MyMu2.printf(send_data); |
ATKINZ117 | 2:2297b491e452 | 56 | /*for(int j=0;j<=send_index;j++){ |
ATKINZ117 | 2:2297b491e452 | 57 | MyMu2.putc(send_data[j]); |
ATKINZ117 | 2:2297b491e452 | 58 | pc.putc(send_data[j]); //for debugging.Comment out when U use this in practice. |
ATKINZ117 | 2:2297b491e452 | 59 | }*/ |
ATKINZ117 | 4:a7d413a2889d | 60 | } |