KDDI Fx0 hackathon
/
MurataTypeYD_Websocket_Sample_full
Websocket_Sample for MurataTypeYD
SNICInterface_mod/SNIC/SNIC_UartMsgUtil.h@1:b5ac0f971f43, 2015-03-12 (annotated)
- Committer:
- komoritan
- Date:
- Thu Mar 12 12:15:46 2015 +0000
- Revision:
- 1:b5ac0f971f43
- Parent:
- 0:14bd24b5a77f
Fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 0:14bd24b5a77f | 1 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
komoritan | 0:14bd24b5a77f | 2 | * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
komoritan | 0:14bd24b5a77f | 3 | * |
komoritan | 0:14bd24b5a77f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
komoritan | 0:14bd24b5a77f | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
komoritan | 0:14bd24b5a77f | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
komoritan | 0:14bd24b5a77f | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
komoritan | 0:14bd24b5a77f | 8 | * furnished to do so, subject to the following conditions: |
komoritan | 0:14bd24b5a77f | 9 | * |
komoritan | 0:14bd24b5a77f | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
komoritan | 0:14bd24b5a77f | 11 | * substantial portions of the Software. |
komoritan | 0:14bd24b5a77f | 12 | * |
komoritan | 0:14bd24b5a77f | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
komoritan | 0:14bd24b5a77f | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
komoritan | 0:14bd24b5a77f | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
komoritan | 0:14bd24b5a77f | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
komoritan | 0:14bd24b5a77f | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
komoritan | 0:14bd24b5a77f | 18 | */ |
komoritan | 0:14bd24b5a77f | 19 | #ifndef _SNIC_WIFI_UART_MSG_UTIL_H_ |
komoritan | 0:14bd24b5a77f | 20 | #define _SNIC_WIFI_UART_MSG_UTILH_ |
komoritan | 0:14bd24b5a77f | 21 | #include "MurataObject.h" |
komoritan | 0:14bd24b5a77f | 22 | #include "mbed.h" |
komoritan | 0:14bd24b5a77f | 23 | #include "rtos.h" |
komoritan | 0:14bd24b5a77f | 24 | #include "RawSerial.h" |
komoritan | 0:14bd24b5a77f | 25 | |
komoritan | 0:14bd24b5a77f | 26 | #define UART_CMD_SOM 0x02 |
komoritan | 0:14bd24b5a77f | 27 | #define UART_CMD_EOM 0x04 |
komoritan | 0:14bd24b5a77f | 28 | #define UART_CMD_ESC 0x10 |
komoritan | 0:14bd24b5a77f | 29 | |
komoritan | 0:14bd24b5a77f | 30 | /* SNIC UART Command ID */ |
komoritan | 0:14bd24b5a77f | 31 | #define UART_CMD_ID_GEN 0x01 //General command |
komoritan | 0:14bd24b5a77f | 32 | #define UART_CMD_ID_SNIC 0x70 //SNIC command |
komoritan | 0:14bd24b5a77f | 33 | #define UART_CMD_ID_WIFI 0x50 //Wi-Fi command |
komoritan | 0:14bd24b5a77f | 34 | |
komoritan | 0:14bd24b5a77f | 35 | /* SNIC UART Subcommand ID */ |
komoritan | 0:14bd24b5a77f | 36 | #define UART_CMD_SID_GEN_PWR_UP_IND 0x00 //Power up indication |
komoritan | 0:14bd24b5a77f | 37 | #define UART_CMD_SID_GEN_FW_VER_GET_REQ 0x08 //Get firmware version string |
komoritan | 0:14bd24b5a77f | 38 | |
komoritan | 0:14bd24b5a77f | 39 | #define UART_CMD_SID_SNIC_INIT_REQ 0x00 // SNIC API initialization |
komoritan | 0:14bd24b5a77f | 40 | #define UART_CMD_SID_SNIC_CLEANUP_REQ 0x01 // SNIC API cleanup |
komoritan | 0:14bd24b5a77f | 41 | #define UART_CMD_SID_SNIC_SEND_FROM_SOCKET_REQ 0x02 // Send from socket |
komoritan | 0:14bd24b5a77f | 42 | #define UART_CMD_SID_SNIC_CLOSE_SOCKET_REQ 0x03 // Close socket |
komoritan | 0:14bd24b5a77f | 43 | #define UART_CMD_SID_SNIC_ SOCKET _PARTIAL_CLOSE_ REQ 0x04 // Socket partial close |
komoritan | 0:14bd24b5a77f | 44 | #define UART_CMD_SID_SNIC_GETSOCKOPT_REQ 0x05 // Get socket option |
komoritan | 0:14bd24b5a77f | 45 | #define UART_CMD_SID_SNIC_SETSOCKOPT_REQ 0x06 // Set socket option |
komoritan | 0:14bd24b5a77f | 46 | #define UART_CMD_SID_SNIC_SOCKET_GETNAME_REQ 0x07 // Get name or peer name |
komoritan | 0:14bd24b5a77f | 47 | #define UART_CMD_SID_SNIC_SEND_ARP_REQ 0x08 // Send ARP request |
komoritan | 0:14bd24b5a77f | 48 | #define UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ 0x09 // Get DHCP info |
komoritan | 0:14bd24b5a77f | 49 | #define UART_CMD_SID_SNIC_RESOLVE_NAME_REQ 0x0A // Resolve a host name to IP address |
komoritan | 0:14bd24b5a77f | 50 | #define UART_CMD_SID_SNIC_IP_CONFIG_REQ 0x0B // Configure DHCP or static IP |
komoritan | 0:14bd24b5a77f | 51 | #define UART_CMD_SID_SNIC_DATA_IND_ACK_CONFIG_REQ 0x0C // ACK configuration for data indications |
komoritan | 0:14bd24b5a77f | 52 | #define UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ 0x10 // Create TCP socket |
komoritan | 0:14bd24b5a77f | 53 | #define UART_CMD_SID_SNIC_TCP_CREATE_CONNECTION_REQ 0x11 // Create TCP connection server |
komoritan | 0:14bd24b5a77f | 54 | #define UART_CMD_SID_SNIC_TCP_CONNECT_TO_SERVER_REQ 0x12 // Connect to TCP server |
komoritan | 0:14bd24b5a77f | 55 | #define UART_CMD_SID_SNIC_UDP_CREATE_SOCKET_REQ 0x13 // Create UDP socket |
komoritan | 0:14bd24b5a77f | 56 | #define UART_CMD_SID_SNIC_UDP_START_RECV_REQ 0x14 // Start UDP receive on socket |
komoritan | 0:14bd24b5a77f | 57 | #define UART_CMD_SID_SNIC_UDP_SIMPLE_SEND_REQ 0x15 // Send UDP packet |
komoritan | 0:14bd24b5a77f | 58 | #define UART_CMD_SID_SNIC_UDP_SEND_FROM_SOCKET_REQ 0x16 // Send UDP packet from socket |
komoritan | 0:14bd24b5a77f | 59 | #define UART_CMD_SID_SNIC_HTTP_REQ 0x17 // Send HTTP request |
komoritan | 0:14bd24b5a77f | 60 | #define UART_CMD_SID_SNIC_HTTP_MORE_REQ 0x18 // Send HTTP more data request |
komoritan | 0:14bd24b5a77f | 61 | #define UART_CMD_SID_SNIC_HTTPS_REQ 0x19 // Send HTTPS request |
komoritan | 0:14bd24b5a77f | 62 | #define UART_CMD_SID_SNIC_TCP_CREATE_ADV_TLS_SOCKET_REQ 0x1A // Create advanced TLS TCP socket |
komoritan | 0:14bd24b5a77f | 63 | #define UART_CMD_SID_SNIC_TCP_CREAET_SIMPLE_TLS_SOCKET_REQ 0x1B // Create simple TLS TCP socket |
komoritan | 0:14bd24b5a77f | 64 | #define UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND 0x20 // Connection status indication |
komoritan | 0:14bd24b5a77f | 65 | #define UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND 0x21 // TCP client socket indication |
komoritan | 0:14bd24b5a77f | 66 | #define UART_CMD_SID_SNIC_CONNECTION_RECV_IND 0x22 // TCP or connected UDP packet received indication |
komoritan | 0:14bd24b5a77f | 67 | #define UART_CMD_SID_SNIC_UDP_RECV_IND 0x23 // UCP packet received indication |
komoritan | 0:14bd24b5a77f | 68 | #define UART_CMD_SID_SNIC_ARP_REPLY_IND 0x24 // ARP reply indication |
komoritan | 0:14bd24b5a77f | 69 | #define UART_CMD_SID_SNIC_HTTP_RSP_IND 0x25 // HTTP response indication |
komoritan | 0:14bd24b5a77f | 70 | |
komoritan | 0:14bd24b5a77f | 71 | #define UART_CMD_SID_WIFI_ON_REQ 0x00 // Turn on Wifi |
komoritan | 0:14bd24b5a77f | 72 | #define UART_CMD_SID_WIFI_OFF_REQ 0x01 // Turn off Wifi |
komoritan | 0:14bd24b5a77f | 73 | #define UART_CMD_SID_WIFI_JOIN_REQ 0x02 // Associate to a network |
komoritan | 0:14bd24b5a77f | 74 | #define UART_CMD_SID_WIFI_DISCONNECT_REQ 0x03 // Disconnect from a network |
komoritan | 0:14bd24b5a77f | 75 | #define UART_CMD_SID_WIFI_GET_STATUS_REQ 0x04 // Get WiFi status |
komoritan | 0:14bd24b5a77f | 76 | #define UART_CMD_SID_WIFI_SCAN_REQ 0x05 // Scan WiFi networks |
komoritan | 0:14bd24b5a77f | 77 | #define UART_CMD_SID_WIFI_GET_STA_RSSI_REQ 0x06 // Get STA signal strength (RSSI) |
komoritan | 0:14bd24b5a77f | 78 | #define UART_CMD_SID_WIFI_AP_CTRL_REQ 0x07 // Soft AP on-off control |
komoritan | 0:14bd24b5a77f | 79 | #define UART_CMD_SID_WIFI_WPS_REQ 0x08 // Start WPS process |
komoritan | 0:14bd24b5a77f | 80 | #define UART_CMD_SID_WIFI_AP_GET_CLIENT_REQ 0x0A // Get clients that are associated to the soft AP. |
komoritan | 0:14bd24b5a77f | 81 | #define UART_CMD_SID_WIFI_NETWORK_STATUS_IND 0x10 // Network status indication |
komoritan | 0:14bd24b5a77f | 82 | #define UART_CMD_SID_WIFI_SCAN_RESULT_IND 0x11 // Scan result indication |
komoritan | 0:14bd24b5a77f | 83 | |
komoritan | 0:14bd24b5a77f | 84 | /* SNIC UART Command response status code */ |
komoritan | 0:14bd24b5a77f | 85 | #define UART_CMD_RES_SNIC_SUCCESS 0x00 |
komoritan | 0:14bd24b5a77f | 86 | #define UART_CMD_RES_SNIC_FAIL 0x01 |
komoritan | 0:14bd24b5a77f | 87 | #define UART_CMD_RES_SNIC_INIT_FAIL 0x02 |
komoritan | 0:14bd24b5a77f | 88 | #define UART_CMD_RES_SNIC_CLEANUP_FAIL 0x03 |
komoritan | 0:14bd24b5a77f | 89 | #define UART_CMD_RES_SNIC_GETADDRINFO_FAIL 0x04 |
komoritan | 0:14bd24b5a77f | 90 | #define UART_CMD_RES_SNIC_CREATE_SOCKET_FAIL 0x05 |
komoritan | 0:14bd24b5a77f | 91 | #define UART_CMD_RES_SNIC_BIND_SOCKET_FAIL 0x06 |
komoritan | 0:14bd24b5a77f | 92 | #define UART_CMD_RES_SNIC_LISTEN_SOCKET_FAIL 0x07 |
komoritan | 0:14bd24b5a77f | 93 | #define UART_CMD_RES_SNIC_ACCEPT_SOCKET_FAIL 0x08 |
komoritan | 0:14bd24b5a77f | 94 | #define UART_CMD_RES_SNIC_PARTIAL_CLOSE_FAIL 0x09 |
komoritan | 0:14bd24b5a77f | 95 | #define UART_CMD_RES_SNIC_SOCKET_PARTIALLY_CLOSED 0x0A |
komoritan | 0:14bd24b5a77f | 96 | #define UART_CMD_RES_SNIC_SOCKET_CLOSED 0x0B |
komoritan | 0:14bd24b5a77f | 97 | #define UART_CMD_RES_SNIC_CLOSE_SOCKET_FAIL 0x0C |
komoritan | 0:14bd24b5a77f | 98 | #define UART_CMD_RES_SNIC_PACKET_TOO_LARGE 0x0D |
komoritan | 0:14bd24b5a77f | 99 | #define UART_CMD_RES_SNIC_SEND_FAIL 0x0E |
komoritan | 0:14bd24b5a77f | 100 | #define UART_CMD_RES_SNIC_CONNECT_TO_SERVER_FAIL 0x0F |
komoritan | 0:14bd24b5a77f | 101 | #define UART_CMD_RES_SNIC_NOT_ENOUGH_MEMORY 0x10 |
komoritan | 0:14bd24b5a77f | 102 | #define UART_CMD_RES_SNIC_TIMEOUT 0x11 |
komoritan | 0:14bd24b5a77f | 103 | #define UART_CMD_RES_SNIC_CONNECTION_UP 0x12 |
komoritan | 0:14bd24b5a77f | 104 | #define UART_CMD_RES_SNIC_GETSOCKOPT_FAIL 0x13 |
komoritan | 0:14bd24b5a77f | 105 | #define UART_CMD_RES_SNIC_SETSOCKOPT_FAIL 0x14 |
komoritan | 0:14bd24b5a77f | 106 | #define UART_CMD_RES_SNIC_INVALID_ARGUMENT 0x15 |
komoritan | 0:14bd24b5a77f | 107 | #define UART_CMD_RES_SNIC_SEND_ARP_FAIL 0x16 |
komoritan | 0:14bd24b5a77f | 108 | #define UART_CMD_RES_SNIC_INVALID_SOCKET 0x17 |
komoritan | 0:14bd24b5a77f | 109 | #define UART_CMD_RES_SNIC_COMMAND_PENDING 0x18 |
komoritan | 0:14bd24b5a77f | 110 | #define UART_CMD_RES_SNIC_SOCKET_NOT_BOUND 0x19 |
komoritan | 0:14bd24b5a77f | 111 | #define UART_CMD_RES_SNIC_SOCKET_NOT_CONNECTED 0x1A |
komoritan | 0:14bd24b5a77f | 112 | #define UART_CMD_RES_SNIC_NO_NETWORK 0x20 |
komoritan | 0:14bd24b5a77f | 113 | #define UART_CMD_RES_SNIC_INIT_NOT_DONE 0x21 |
komoritan | 0:14bd24b5a77f | 114 | #define UART_CMD_RES_SNIC_NET_IF_FAIL 0x22 |
komoritan | 0:14bd24b5a77f | 115 | #define UART_CMD_RES_SNIC_NET_IF_NOT_UP 0x23 |
komoritan | 0:14bd24b5a77f | 116 | #define UART_CMD_RES_SNIC_DHCP_START_FAIL 0x24 |
komoritan | 0:14bd24b5a77f | 117 | |
komoritan | 0:14bd24b5a77f | 118 | #define UART_CMD_RES_WIFI_SUCCESS 0x00 |
komoritan | 0:14bd24b5a77f | 119 | #define UART_CMD_RES_WIFI_ERR_UNKNOWN_COUNTRY 0x01 |
komoritan | 0:14bd24b5a77f | 120 | #define UART_CMD_RES_WIFI_ERR_INIT_FAIL 0x02 |
komoritan | 0:14bd24b5a77f | 121 | #define UART_CMD_RES_WIFI_ERR_ALREADY_JOINED 0x03 |
komoritan | 0:14bd24b5a77f | 122 | #define UART_CMD_RES_WIFI_ERR_AUTH_TYPE 0x04 |
komoritan | 0:14bd24b5a77f | 123 | #define UART_CMD_RES_WIFI_ERR_JOIN_FAIL 0x05 |
komoritan | 0:14bd24b5a77f | 124 | #define UART_CMD_RES_WIFI_ERR_NOT_JOINED 0x06 |
komoritan | 0:14bd24b5a77f | 125 | #define UART_CMD_RES_WIFI_ERR_LEAVE_FAILED 0x07 |
komoritan | 0:14bd24b5a77f | 126 | #define UART_CMD_RES_WIFI_COMMAND_PENDING 0x08 |
komoritan | 0:14bd24b5a77f | 127 | #define UART_CMD_RES_WIFI_WPS_NO_CONFIG 0x09 |
komoritan | 0:14bd24b5a77f | 128 | #define UART_CMD_RES_WIFI_NETWORK_UP 0x10 |
komoritan | 0:14bd24b5a77f | 129 | #define UART_CMD_RES_WIFI_NETWORK_DOWN 0x11 |
komoritan | 0:14bd24b5a77f | 130 | #define UART_CMD_RES_WIFI_FAIL 0xFF |
komoritan | 0:14bd24b5a77f | 131 | |
komoritan | 0:14bd24b5a77f | 132 | /** UART Command sequence number |
komoritan | 0:14bd24b5a77f | 133 | */ |
komoritan | 0:14bd24b5a77f | 134 | static unsigned char mUartRequestSeq; |
komoritan | 0:14bd24b5a77f | 135 | |
komoritan | 0:14bd24b5a77f | 136 | /** Internal utility class used by any other classes. |
komoritan | 0:14bd24b5a77f | 137 | */ |
komoritan | 0:14bd24b5a77f | 138 | class C_SNIC_UartMsgUtil: public C_MurataObject |
komoritan | 0:14bd24b5a77f | 139 | { |
komoritan | 0:14bd24b5a77f | 140 | friend class C_SNIC_Core; |
komoritan | 0:14bd24b5a77f | 141 | friend class C_SNIC_WifiInterface; |
komoritan | 0:14bd24b5a77f | 142 | friend class UDPSocket; |
komoritan | 0:14bd24b5a77f | 143 | friend class TCPSocketConnection; |
komoritan | 0:14bd24b5a77f | 144 | friend class Socket; |
komoritan | 0:14bd24b5a77f | 145 | |
komoritan | 0:14bd24b5a77f | 146 | private: |
komoritan | 0:14bd24b5a77f | 147 | C_SNIC_UartMsgUtil(); |
komoritan | 0:14bd24b5a77f | 148 | virtual ~C_SNIC_UartMsgUtil(); |
komoritan | 0:14bd24b5a77f | 149 | |
komoritan | 0:14bd24b5a77f | 150 | /** Make SNIC UART command. |
komoritan | 0:14bd24b5a77f | 151 | @param cmd_id Command ID |
komoritan | 0:14bd24b5a77f | 152 | @param payload_p Payload pointer |
komoritan | 0:14bd24b5a77f | 153 | @param uart_command_p UART Command pointer [output] |
komoritan | 0:14bd24b5a77f | 154 | @return UART Command length |
komoritan | 0:14bd24b5a77f | 155 | */ |
komoritan | 0:14bd24b5a77f | 156 | static unsigned int makeRequest( unsigned char cmd_id, unsigned char *payload_p, unsigned short payload_len, unsigned char *uart_command_p ); |
komoritan | 0:14bd24b5a77f | 157 | |
komoritan | 0:14bd24b5a77f | 158 | |
komoritan | 0:14bd24b5a77f | 159 | /** Get uart command from receive data. |
komoritan | 0:14bd24b5a77f | 160 | @param recvdata_len Receive data length |
komoritan | 0:14bd24b5a77f | 161 | @param recvdata_p Pointer of received data from UART |
komoritan | 0:14bd24b5a77f | 162 | @param command_id_p Pointer of command ID[output] |
komoritan | 0:14bd24b5a77f | 163 | @param payload_p Pointer of payload[output] |
komoritan | 0:14bd24b5a77f | 164 | @return Payload length |
komoritan | 0:14bd24b5a77f | 165 | */ |
komoritan | 0:14bd24b5a77f | 166 | static unsigned int getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p |
komoritan | 0:14bd24b5a77f | 167 | , unsigned char *command_id_p, unsigned char *payload_p ); |
komoritan | 0:14bd24b5a77f | 168 | |
komoritan | 0:14bd24b5a77f | 169 | /** Convert a string to number of ip address. |
komoritan | 0:14bd24b5a77f | 170 | @param recvdata_p Pointer of string of IP address |
komoritan | 0:14bd24b5a77f | 171 | @return Number of ip address |
komoritan | 0:14bd24b5a77f | 172 | */ |
komoritan | 0:14bd24b5a77f | 173 | static int addrToInteger( const char *addr_p ); |
komoritan | 0:14bd24b5a77f | 174 | |
komoritan | 0:14bd24b5a77f | 175 | /** Convert a integer to byte array of ip address. |
komoritan | 0:14bd24b5a77f | 176 | @param recvdata_p Pointer of string of IP address |
komoritan | 0:14bd24b5a77f | 177 | @return Number of ip address |
komoritan | 0:14bd24b5a77f | 178 | */ |
komoritan | 0:14bd24b5a77f | 179 | static void convertIntToByteAdday( int addr, char *addr_array_p ); |
komoritan | 0:14bd24b5a77f | 180 | |
komoritan | 0:14bd24b5a77f | 181 | protected: |
komoritan | 0:14bd24b5a77f | 182 | |
komoritan | 0:14bd24b5a77f | 183 | }; |
komoritan | 0:14bd24b5a77f | 184 | |
komoritan | 0:14bd24b5a77f | 185 | #endif /* _YD_WIFI_UART_MSG_H_ */ |