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