SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html
Dependents: SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more
Fork of YDwifiInterface by
YDwifi/YDwifi_uartmsg.cpp@3:9f90024d7fb2, 2014-03-13 (annotated)
- Committer:
- kishino
- Date:
- Thu Mar 13 01:34:56 2014 +0000
- Revision:
- 3:9f90024d7fb2
- Parent:
- 2:0ba43344c814
- Child:
- 7:e88ccbe0225f
The following API was created.; =>Connect to AP.; =>Disconnect from AP.; =>Scan AP.
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 | } |
| kishino | 1:c6e5f49dce5f | 81 | |
| kishino | 2:0ba43344c814 | 82 | unsigned int C_YD_UartMsg::getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p |
| kishino | 1:c6e5f49dce5f | 83 | , unsigned char *command_id_p, unsigned char *payload_p ) |
| kishino | 1:c6e5f49dce5f | 84 | { |
| kishino | 1:c6e5f49dce5f | 85 | unsigned short payload_len = 0; |
| kishino | 1:c6e5f49dce5f | 86 | unsigned int response_len = 0; |
| kishino | 1:c6e5f49dce5f | 87 | unsigned char *buf = NULL; |
| kishino | 1:c6e5f49dce5f | 88 | bool isESC = false; |
| kishino | 1:c6e5f49dce5f | 89 | int i; |
| kishino | 1:c6e5f49dce5f | 90 | |
| kishino | 1:c6e5f49dce5f | 91 | // get payload length |
| kishino | 3:9f90024d7fb2 | 92 | payload_len = ( ( (recvdata_p[1] & ~0x80) & 0xff) | ( ( (recvdata_p[2] & ~0xC0) << 7) & 0xff80) ); |
| kishino | 1:c6e5f49dce5f | 93 | |
| kishino | 1:c6e5f49dce5f | 94 | // get Command ID |
| kishino | 1:c6e5f49dce5f | 95 | *command_id_p = (recvdata_p[3] & ~0x80); |
| kishino | 1:c6e5f49dce5f | 96 | |
| kishino | 1:c6e5f49dce5f | 97 | buf = &recvdata_p[4]; |
| kishino | 1:c6e5f49dce5f | 98 | |
| kishino | 1:c6e5f49dce5f | 99 | // get payload data |
| kishino | 1:c6e5f49dce5f | 100 | for( i = 0; i < payload_len; i++, buf++ ) |
| kishino | 1:c6e5f49dce5f | 101 | { |
| kishino | 1:c6e5f49dce5f | 102 | if( isESC ) |
| kishino | 1:c6e5f49dce5f | 103 | { |
| kishino | 1:c6e5f49dce5f | 104 | *payload_p = (*buf & ~0x80); |
| kishino | 1:c6e5f49dce5f | 105 | payload_p++; |
| kishino | 1:c6e5f49dce5f | 106 | response_len++; |
| kishino | 3:9f90024d7fb2 | 107 | isESC = false; |
| kishino | 1:c6e5f49dce5f | 108 | } |
| kishino | 1:c6e5f49dce5f | 109 | else |
| kishino | 1:c6e5f49dce5f | 110 | { |
| kishino | 1:c6e5f49dce5f | 111 | // Check Escape code |
| kishino | 1:c6e5f49dce5f | 112 | if( *buf == UART_CMD_ESC ) |
| kishino | 1:c6e5f49dce5f | 113 | { |
| kishino | 1:c6e5f49dce5f | 114 | isESC = true; |
| kishino | 1:c6e5f49dce5f | 115 | continue; |
| kishino | 1:c6e5f49dce5f | 116 | } |
| kishino | 1:c6e5f49dce5f | 117 | else |
| kishino | 1:c6e5f49dce5f | 118 | { |
| kishino | 1:c6e5f49dce5f | 119 | *payload_p = *buf; |
| kishino | 1:c6e5f49dce5f | 120 | payload_p++; |
| kishino | 1:c6e5f49dce5f | 121 | response_len++; |
| kishino | 1:c6e5f49dce5f | 122 | } |
| kishino | 1:c6e5f49dce5f | 123 | } |
| kishino | 1:c6e5f49dce5f | 124 | } |
| kishino | 1:c6e5f49dce5f | 125 | |
| kishino | 1:c6e5f49dce5f | 126 | return response_len; |
| kishino | 1:c6e5f49dce5f | 127 | } |
muRata

Murata TypeYD