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