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.
Dependents: SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more
Fork of YDwifiInterface by
YDwifi/YDwifi_uartmsg.cpp@7:e88ccbe0225f, 2014-03-14 (annotated)
- Committer:
- kishino
- Date:
- Fri Mar 14 08:48:12 2014 +0000
- Revision:
- 7:e88ccbe0225f
- Parent:
- 3:9f90024d7fb2
Scan handler interface modify
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 | 7:e88ccbe0225f | 3 | using namespace murata_wifi; |
| kishino | 7:e88ccbe0225f | 4 | |
| kishino | 0:61c402886fbb | 5 | C_YD_UartMsg::C_YD_UartMsg() |
| kishino | 0:61c402886fbb | 6 | { |
| kishino | 0:61c402886fbb | 7 | } |
| kishino | 0:61c402886fbb | 8 | |
| kishino | 0:61c402886fbb | 9 | unsigned short C_YD_UartMsg::makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p ) |
| kishino | 0:61c402886fbb | 10 | { |
| kishino | 0:61c402886fbb | 11 | unsigned short payload_len = 0; |
| kishino | 0:61c402886fbb | 12 | int i; |
| kishino | 0:61c402886fbb | 13 | |
| kishino | 0:61c402886fbb | 14 | for( i = 0; i < cmd_len; i++, payload_p++, payload_len++ ) |
| kishino | 0:61c402886fbb | 15 | { |
| kishino | 0:61c402886fbb | 16 | /* check Escape code */ |
| kishino | 0:61c402886fbb | 17 | if( ( cmd_p[i] == UART_CMD_SOM ) || ( cmd_p[i] == UART_CMD_EOM ) || ( cmd_p[i] == UART_CMD_ESC ) ) |
| kishino | 0:61c402886fbb | 18 | { |
| kishino | 0:61c402886fbb | 19 | /* Add ESC */ |
| kishino | 0:61c402886fbb | 20 | *payload_p = UART_CMD_ESC; |
| kishino | 0:61c402886fbb | 21 | payload_len++; |
| kishino | 0:61c402886fbb | 22 | |
| kishino | 0:61c402886fbb | 23 | payload_p++; |
| kishino | 0:61c402886fbb | 24 | *payload_p = (0x80 | cmd_p[i]); |
| kishino | 0:61c402886fbb | 25 | } |
| kishino | 0:61c402886fbb | 26 | else |
| kishino | 0:61c402886fbb | 27 | { |
| kishino | 0:61c402886fbb | 28 | *payload_p = cmd_p[i]; |
| kishino | 0:61c402886fbb | 29 | } |
| kishino | 0:61c402886fbb | 30 | } |
| kishino | 0:61c402886fbb | 31 | |
| kishino | 0:61c402886fbb | 32 | return payload_len; |
| kishino | 0:61c402886fbb | 33 | } |
| kishino | 0:61c402886fbb | 34 | |
| kishino | 0:61c402886fbb | 35 | unsigned int C_YD_UartMsg::makeRequest( unsigned char cmd_id,unsigned char *payload_p |
| kishino | 0:61c402886fbb | 36 | , unsigned short payload_len, unsigned char *uart_command_p ) |
| kishino | 0:61c402886fbb | 37 | { |
| kishino | 0:61c402886fbb | 38 | unsigned char check_sum = 0; // Check Sum |
| kishino | 0:61c402886fbb | 39 | unsigned int uart_cmd_len = 0; |
| kishino | 0:61c402886fbb | 40 | int i; |
| kishino | 0:61c402886fbb | 41 | |
| kishino | 0:61c402886fbb | 42 | // set SOM |
| kishino | 0:61c402886fbb | 43 | *uart_command_p = UART_CMD_SOM; |
| kishino | 0:61c402886fbb | 44 | uart_command_p++; |
| kishino | 0:61c402886fbb | 45 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 46 | |
| kishino | 0:61c402886fbb | 47 | // set payload length L0 |
| kishino | 0:61c402886fbb | 48 | *uart_command_p = (0x80 | (payload_len & 0x007f)); |
| kishino | 0:61c402886fbb | 49 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 50 | uart_command_p++; |
| kishino | 0:61c402886fbb | 51 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 52 | |
| kishino | 0:61c402886fbb | 53 | // set payload length L1 |
| kishino | 0:61c402886fbb | 54 | *uart_command_p = (0x80 | ( (payload_len >> 7) & 0x003f)); |
| kishino | 0:61c402886fbb | 55 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 56 | uart_command_p++; |
| kishino | 0:61c402886fbb | 57 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 58 | |
| kishino | 0:61c402886fbb | 59 | // set Command ID |
| kishino | 0:61c402886fbb | 60 | *uart_command_p = (0x80 | cmd_id); |
| kishino | 0:61c402886fbb | 61 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 62 | uart_command_p++; |
| kishino | 0:61c402886fbb | 63 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 64 | |
| kishino | 0:61c402886fbb | 65 | // set Payload |
| kishino | 0:61c402886fbb | 66 | for( i = 0; i < payload_len; i++, uart_command_p++, uart_cmd_len++ ) |
| kishino | 0:61c402886fbb | 67 | { |
| kishino | 0:61c402886fbb | 68 | *uart_command_p = payload_p[i]; |
| kishino | 0:61c402886fbb | 69 | check_sum += *uart_command_p; |
| kishino | 0:61c402886fbb | 70 | } |
| kishino | 0:61c402886fbb | 71 | |
| kishino | 0:61c402886fbb | 72 | // set Check sum |
| kishino | 0:61c402886fbb | 73 | *uart_command_p = (0x80 | check_sum); |
| kishino | 0:61c402886fbb | 74 | uart_command_p++; |
| kishino | 0:61c402886fbb | 75 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 76 | |
| kishino | 0:61c402886fbb | 77 | // set EOM |
| kishino | 0:61c402886fbb | 78 | *uart_command_p = UART_CMD_EOM; |
| kishino | 0:61c402886fbb | 79 | uart_cmd_len++; |
| kishino | 0:61c402886fbb | 80 | |
| kishino | 0:61c402886fbb | 81 | return uart_cmd_len; |
| kishino | 0:61c402886fbb | 82 | } |
| kishino | 1:c6e5f49dce5f | 83 | |
| kishino | 2:0ba43344c814 | 84 | unsigned int C_YD_UartMsg::getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p |
| kishino | 1:c6e5f49dce5f | 85 | , unsigned char *command_id_p, unsigned char *payload_p ) |
| kishino | 1:c6e5f49dce5f | 86 | { |
| kishino | 1:c6e5f49dce5f | 87 | unsigned short payload_len = 0; |
| kishino | 1:c6e5f49dce5f | 88 | unsigned int response_len = 0; |
| kishino | 1:c6e5f49dce5f | 89 | unsigned char *buf = NULL; |
| kishino | 1:c6e5f49dce5f | 90 | bool isESC = false; |
| kishino | 1:c6e5f49dce5f | 91 | int i; |
| kishino | 1:c6e5f49dce5f | 92 | |
| kishino | 1:c6e5f49dce5f | 93 | // get payload length |
| kishino | 3:9f90024d7fb2 | 94 | payload_len = ( ( (recvdata_p[1] & ~0x80) & 0xff) | ( ( (recvdata_p[2] & ~0xC0) << 7) & 0xff80) ); |
| kishino | 1:c6e5f49dce5f | 95 | |
| kishino | 1:c6e5f49dce5f | 96 | // get Command ID |
| kishino | 1:c6e5f49dce5f | 97 | *command_id_p = (recvdata_p[3] & ~0x80); |
| kishino | 1:c6e5f49dce5f | 98 | |
| kishino | 1:c6e5f49dce5f | 99 | buf = &recvdata_p[4]; |
| kishino | 1:c6e5f49dce5f | 100 | |
| kishino | 1:c6e5f49dce5f | 101 | // get payload data |
| kishino | 1:c6e5f49dce5f | 102 | for( i = 0; i < payload_len; i++, buf++ ) |
| kishino | 1:c6e5f49dce5f | 103 | { |
| kishino | 1:c6e5f49dce5f | 104 | if( isESC ) |
| kishino | 1:c6e5f49dce5f | 105 | { |
| kishino | 1:c6e5f49dce5f | 106 | *payload_p = (*buf & ~0x80); |
| kishino | 1:c6e5f49dce5f | 107 | payload_p++; |
| kishino | 1:c6e5f49dce5f | 108 | response_len++; |
| kishino | 3:9f90024d7fb2 | 109 | isESC = false; |
| kishino | 1:c6e5f49dce5f | 110 | } |
| kishino | 1:c6e5f49dce5f | 111 | else |
| kishino | 1:c6e5f49dce5f | 112 | { |
| kishino | 1:c6e5f49dce5f | 113 | // Check Escape code |
| kishino | 1:c6e5f49dce5f | 114 | if( *buf == UART_CMD_ESC ) |
| kishino | 1:c6e5f49dce5f | 115 | { |
| kishino | 1:c6e5f49dce5f | 116 | isESC = true; |
| kishino | 1:c6e5f49dce5f | 117 | continue; |
| kishino | 1:c6e5f49dce5f | 118 | } |
| kishino | 1:c6e5f49dce5f | 119 | else |
| kishino | 1:c6e5f49dce5f | 120 | { |
| kishino | 1:c6e5f49dce5f | 121 | *payload_p = *buf; |
| kishino | 1:c6e5f49dce5f | 122 | payload_p++; |
| kishino | 1:c6e5f49dce5f | 123 | response_len++; |
| kishino | 1:c6e5f49dce5f | 124 | } |
| kishino | 1:c6e5f49dce5f | 125 | } |
| kishino | 1:c6e5f49dce5f | 126 | } |
| kishino | 1:c6e5f49dce5f | 127 | |
| kishino | 1:c6e5f49dce5f | 128 | return response_len; |
| kishino | 1:c6e5f49dce5f | 129 | } |

Murata TypeYD