Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NySNICInterface by
YDwifi/YDwifi_uartmsg.cpp@0:61c402886fbb, 2014-03-06 (annotated)
- Committer:
- kishino
- Date:
- Thu Mar 06 11:13:00 2014 +0000
- Revision:
- 0:61c402886fbb
- Child:
- 1:c6e5f49dce5f
The common method which creates a UART command request was created.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kishino | 0:61c402886fbb | 1 | #include "YDwifi_uartmsg.h" |
| kishino | 0:61c402886fbb | 2 | |
| kishino | 0:61c402886fbb | 3 | C_YD_UartMsg::C_YD_UartMsg() |
| kishino | 0:61c402886fbb | 4 | { |
| kishino | 0:61c402886fbb | 5 | } |
| kishino | 0:61c402886fbb | 6 | |
| kishino | 0:61c402886fbb | 7 | unsigned short C_YD_UartMsg::makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p ) |
| kishino | 0:61c402886fbb | 8 | { |
| kishino | 0:61c402886fbb | 9 | unsigned short payload_len = 0; |
| kishino | 0:61c402886fbb | 10 | int i; |
| kishino | 0:61c402886fbb | 11 | |
| kishino | 0:61c402886fbb | 12 | for( i = 0; i < cmd_len; i++, payload_p++, payload_len++ ) |
| kishino | 0:61c402886fbb | 13 | { |
| kishino | 0:61c402886fbb | 14 | /* check Escape code */ |
| kishino | 0:61c402886fbb | 15 | if( ( cmd_p[i] == UART_CMD_SOM ) || ( cmd_p[i] == UART_CMD_EOM ) || ( cmd_p[i] == UART_CMD_ESC ) ) |
| kishino | 0:61c402886fbb | 16 | { |
| kishino | 0:61c402886fbb | 17 | /* Add ESC */ |
| kishino | 0:61c402886fbb | 18 | *payload_p = UART_CMD_ESC; |
| kishino | 0:61c402886fbb | 19 | payload_len++; |
| kishino | 0:61c402886fbb | 20 | |
| kishino | 0:61c402886fbb | 21 | payload_p++; |
| kishino | 0:61c402886fbb | 22 | *payload_p = (0x80 | cmd_p[i]); |
| kishino | 0:61c402886fbb | 23 | } |
| kishino | 0:61c402886fbb | 24 | else |
| kishino | 0:61c402886fbb | 25 | { |
| kishino | 0:61c402886fbb | 26 | *payload_p = cmd_p[i]; |
| kishino | 0:61c402886fbb | 27 | } |
| kishino | 0:61c402886fbb | 28 | } |
| kishino | 0:61c402886fbb | 29 | |
| kishino | 0:61c402886fbb | 30 | return payload_len; |
| kishino | 0:61c402886fbb | 31 | } |
| kishino | 0:61c402886fbb | 32 | |
| kishino | 0:61c402886fbb | 33 | unsigned int C_YD_UartMsg::makeRequest( unsigned char cmd_id,unsigned char *payload_p |
| kishino | 0:61c402886fbb | 34 | , unsigned short payload_len, unsigned char *uart_command_p ) |
| kishino | 0:61c402886fbb | 35 | { |
| kishino | 0:61c402886fbb | 36 | unsigned char check_sum = 0; // Check Sum |
| kishino | 0:61c402886fbb | 37 | unsigned int uart_cmd_len = 0; |
| kishino | 0:61c402886fbb | 38 | int i; |
| kishino | 0:61c402886fbb | 39 | |
| kishino | 0:61c402886fbb | 40 | // set SOM |
| kishino | 0:61c402886fbb | 41 | *uart_command_p = UART_CMD_SOM; |
| kishino | 0:61c402886fbb | 42 | uart_command_p++; |
| kishino | 0:61c402886fbb | 43 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 44 | |
| kishino | 0:61c402886fbb | 45 | // set payload length L0 |
| kishino | 0:61c402886fbb | 46 | *uart_command_p = (0x80 | (payload_len & 0x007f)); |
| kishino | 0:61c402886fbb | 47 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 48 | uart_command_p++; |
| kishino | 0:61c402886fbb | 49 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 50 | |
| kishino | 0:61c402886fbb | 51 | // set payload length L1 |
| kishino | 0:61c402886fbb | 52 | *uart_command_p = (0x80 | ( (payload_len >> 7) & 0x003f)); |
| kishino | 0:61c402886fbb | 53 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 54 | uart_command_p++; |
| kishino | 0:61c402886fbb | 55 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 56 | |
| kishino | 0:61c402886fbb | 57 | // set Command ID |
| kishino | 0:61c402886fbb | 58 | *uart_command_p = (0x80 | cmd_id); |
| kishino | 0:61c402886fbb | 59 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 60 | uart_command_p++; |
| kishino | 0:61c402886fbb | 61 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 62 | |
| kishino | 0:61c402886fbb | 63 | // set Payload |
| kishino | 0:61c402886fbb | 64 | for( i = 0; i < payload_len; i++, uart_command_p++, uart_cmd_len++ ) |
| kishino | 0:61c402886fbb | 65 | { |
| kishino | 0:61c402886fbb | 66 | *uart_command_p = payload_p[i]; |
| kishino | 0:61c402886fbb | 67 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 68 | } |
| kishino | 0:61c402886fbb | 69 | |
| kishino | 0:61c402886fbb | 70 | // set Check sum |
| kishino | 0:61c402886fbb | 71 | *uart_command_p = (0x80 | check_sum); |
| kishino | 0:61c402886fbb | 72 | uart_command_p++; |
| kishino | 0:61c402886fbb | 73 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 74 | |
| kishino | 0:61c402886fbb | 75 | // set EOM |
| kishino | 0:61c402886fbb | 76 | *uart_command_p = UART_CMD_EOM; |
| kishino | 0:61c402886fbb | 77 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 78 | |
| kishino | 0:61c402886fbb | 79 | return uart_cmd_len; |
| kishino | 0:61c402886fbb | 80 | } |
