customized SNICInterface

Dependents:   MurataTypeYD_Ping

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Mon Jun 09 08:28:07 2014 +0000
Revision:
34:8c3527b8f44e
Parent:
33:33f1bc919486
Child:
36:f33fcf5975ab
[Refactoring] ; Changed how to define of buffer for TCP socket.; About setting IP address, changed to using common function for convert to binary array from decimal.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 20:dd736d328de6 1 /******************* Murata Manufacturing Co.,Ltd. 2014 *****************
kishino 20:dd736d328de6 2 *
kishino 20:dd736d328de6 3 * Filename: SNIC_UartMsgUtil.h
kishino 20:dd736d328de6 4 *
kishino 20:dd736d328de6 5 * Purpose: This module has define of function for utilities
kishino 20:dd736d328de6 6 * of SNIC UART Command.
kishino 20:dd736d328de6 7 *
kishino 20:dd736d328de6 8 * $Author: kishino $
kishino 20:dd736d328de6 9 *
kishino 20:dd736d328de6 10 * $Date: 2014/03/26 $
kishino 20:dd736d328de6 11 *
kishino 20:dd736d328de6 12 * $Revision: 0.0.0.1 $
kishino 20:dd736d328de6 13 * ***********************************************************************/
kishino 20:dd736d328de6 14 #ifndef _SNIC_WIFI_UART_MSG_UTIL_H_
kishino 20:dd736d328de6 15 #define _SNIC_WIFI_UART_MSG_UTILH_
kishino 25:67183ed15708 16 #include "MurataObject.h"
kishino 20:dd736d328de6 17 #include "mbed.h"
kishino 20:dd736d328de6 18 #include "rtos.h"
kishino 20:dd736d328de6 19 #include "RawSerial.h"
kishino 20:dd736d328de6 20
kishino 20:dd736d328de6 21 #define UART_CMD_SOM 0x02
kishino 20:dd736d328de6 22 #define UART_CMD_EOM 0x04
kishino 20:dd736d328de6 23 #define UART_CMD_ESC 0x10
kishino 20:dd736d328de6 24
kishino 20:dd736d328de6 25 /* SNIC UART Command ID */
kishino 20:dd736d328de6 26 #define UART_CMD_ID_GEN 0x01 //General command
kishino 20:dd736d328de6 27 #define UART_CMD_ID_SNIC 0x70 //SNIC command
kishino 20:dd736d328de6 28 #define UART_CMD_ID_WIFI 0x50 //Wi-Fi command
kishino 20:dd736d328de6 29
kishino 20:dd736d328de6 30 /* SNIC UART Subcommand ID */
kishino 20:dd736d328de6 31 #define UART_CMD_SID_GEN_PWR_UP_IND 0x00 //Power up indication
kishino 20:dd736d328de6 32 #define UART_CMD_SID_GEN_FW_VER_GET_REQ 0x08 //Get firmware version string
kishino 20:dd736d328de6 33
kishino 20:dd736d328de6 34 #define UART_CMD_SID_SNIC_INIT_REQ 0x00 // SNIC API initialization
kishino 20:dd736d328de6 35 #define UART_CMD_SID_SNIC_CLEANUP_REQ 0x01 // SNIC API cleanup
kishino 20:dd736d328de6 36 #define UART_CMD_SID_SNIC_SEND_FROM_SOCKET_REQ 0x02 // Send from socket
kishino 20:dd736d328de6 37 #define UART_CMD_SID_SNIC_CLOSE_SOCKET_REQ 0x03 // Close socket
kishino 20:dd736d328de6 38 #define UART_CMD_SID_SNIC_ SOCKET _PARTIAL_CLOSE_ REQ 0x04 // Socket partial close
kishino 20:dd736d328de6 39 #define UART_CMD_SID_SNIC_GETSOCKOPT_REQ 0x05 // Get socket option
kishino 20:dd736d328de6 40 #define UART_CMD_SID_SNIC_SETSOCKOPT_REQ 0x06 // Set socket option
kishino 20:dd736d328de6 41 #define UART_CMD_SID_SNIC_SOCKET_GETNAME_REQ 0x07 // Get name or peer name
kishino 20:dd736d328de6 42 #define UART_CMD_SID_SNIC_SEND_ARP_REQ 0x08 // Send ARP request
kishino 20:dd736d328de6 43 #define UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ 0x09 // Get DHCP info
kishino 20:dd736d328de6 44 #define UART_CMD_SID_SNIC_RESOLVE_NAME_REQ 0x0A // Resolve a host name to IP address
kishino 20:dd736d328de6 45 #define UART_CMD_SID_SNIC_IP_CONFIG_REQ 0x0B // Configure DHCP or static IP
kishino 20:dd736d328de6 46 #define UART_CMD_SID_SNIC_DATA_IND_ACK_CONFIG_REQ 0x0C // ACK configuration for data indications
kishino 20:dd736d328de6 47 #define UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ 0x10 // Create TCP socket
kishino 20:dd736d328de6 48 #define UART_CMD_SID_SNIC_TCP_CREATE_CONNECTION_REQ 0x11 // Create TCP connection server
kishino 20:dd736d328de6 49 #define UART_CMD_SID_SNIC_TCP_CONNECT_TO_SERVER_REQ 0x12 // Connect to TCP server
kishino 20:dd736d328de6 50 #define UART_CMD_SID_SNIC_UDP_CREATE_SOCKET_REQ 0x13 // Create UDP socket
kishino 20:dd736d328de6 51 #define UART_CMD_SID_SNIC_UDP_START_RECV_REQ 0x14 // Start UDP receive on socket
kishino 20:dd736d328de6 52 #define UART_CMD_SID_SNIC_UDP_SIMPLE_SEND_REQ 0x15 // Send UDP packet
kishino 20:dd736d328de6 53 #define UART_CMD_SID_SNIC_UDP_SEND_ FROM_SOCKET_REQ 0x16 // Send UDP packet from socket
kishino 20:dd736d328de6 54 #define UART_CMD_SID_SNIC_HTTP_REQ 0x17 // Send HTTP request
kishino 20:dd736d328de6 55 #define UART_CMD_SID_SNIC_HTTP_MORE_REQ 0x18 // Send HTTP more data request
kishino 20:dd736d328de6 56 #define UART_CMD_SID_SNIC_HTTPS_REQ 0x19 // Send HTTPS request
kishino 20:dd736d328de6 57 #define UART_CMD_SID_SNIC_TCP_CREATE_ADV_TLS_SOCKET_REQ 0x1A // Create advanced TLS TCP socket
kishino 20:dd736d328de6 58 #define UART_CMD_SID_SNIC_TCP_CREAET_SIMPLE_TLS_SOCKET_REQ 0x1B // Create simple TLS TCP socket
kishino 20:dd736d328de6 59 #define UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND 0x20 // Connection status indication
kishino 20:dd736d328de6 60 #define UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND 0x21 // TCP client socket indication
kishino 20:dd736d328de6 61 #define UART_CMD_SID_SNIC_CONNECTION_RECV_IND 0x22 // TCP or connected UDP packet received indication
kishino 20:dd736d328de6 62 #define UART_CMD_SID_SNIC_UDP_RECV_IND 0x23 // UCP packet received indication
kishino 20:dd736d328de6 63 #define UART_CMD_SID_SNIC_ARP_REPLY_IND 0x24 // ARP reply indication
kishino 20:dd736d328de6 64 #define UART_CMD_SID_SNIC_HTTP_RSP_IND 0x25 // HTTP response indication
kishino 20:dd736d328de6 65
kishino 20:dd736d328de6 66 #define UART_CMD_SID_WIFI_ON_REQ 0x00 // Turn on Wifi
kishino 20:dd736d328de6 67 #define UART_CMD_SID_WIFI_OFF_REQ 0x01 // Turn off Wifi
kishino 20:dd736d328de6 68 #define UART_CMD_SID_WIFI_JOIN_REQ 0x02 // Associate to a network
kishino 20:dd736d328de6 69 #define UART_CMD_SID_WIFI_DISCONNECT_REQ 0x03 // Disconnect from a network
kishino 20:dd736d328de6 70 #define UART_CMD_SID_WIFI_GET_STATUS_REQ 0x04 // Get WiFi status
kishino 20:dd736d328de6 71 #define UART_CMD_SID_WIFI_SCAN_REQ 0x05 // Scan WiFi networks
kishino 20:dd736d328de6 72 #define UART_CMD_SID_WIFI_GET_STA_RSSI_REQ 0x06 // Get STA signal strength (RSSI)
kishino 20:dd736d328de6 73 #define UART_CMD_SID_WIFI_AP_CTRL_REQ 0x07 // Soft AP on-off control
kishino 20:dd736d328de6 74 #define UART_CMD_SID_WIFI_WPS_REQ 0x08 // Start WPS process
kishino 20:dd736d328de6 75 #define UART_CMD_SID_WIFI_AP_GET_CLIENT_REQ 0x0A // Get clients that are associated to the soft AP.
kishino 20:dd736d328de6 76 #define UART_CMD_SID_WIFI_NETWORK_STATUS_IND 0x10 // Network status indication
kishino 20:dd736d328de6 77 #define UART_CMD_SID_WIFI_SCAN_RESULT_IND 0x11 // Scan result indication
kishino 20:dd736d328de6 78
kishino 20:dd736d328de6 79 /* SNIC UART Command response status code */
kishino 20:dd736d328de6 80 #define UART_CMD_RES_SNIC_SUCCESS 0x00
kishino 20:dd736d328de6 81 #define UART_CMD_RES_SNIC_FAIL 0x01
kishino 20:dd736d328de6 82 #define UART_CMD_RES_SNIC_INIT_FAIL 0x02
kishino 20:dd736d328de6 83 #define UART_CMD_RES_SNIC_CLEANUP_FAIL 0x03
kishino 20:dd736d328de6 84 #define UART_CMD_RES_SNIC_GETADDRINFO_FAIL 0x04
kishino 20:dd736d328de6 85 #define UART_CMD_RES_SNIC_CREATE_SOCKET_FAIL 0x05
kishino 20:dd736d328de6 86 #define UART_CMD_RES_SNIC_BIND_SOCKET_FAIL 0x06
kishino 20:dd736d328de6 87 #define UART_CMD_RES_SNIC_LISTEN_SOCKET_FAIL 0x07
kishino 20:dd736d328de6 88 #define UART_CMD_RES_SNIC_ACCEPT_SOCKET_FAIL 0x08
kishino 20:dd736d328de6 89 #define UART_CMD_RES_SNIC_PARTIAL_CLOSE_FAIL 0x09
kishino 20:dd736d328de6 90 #define UART_CMD_RES_SNIC_SOCKET_PARTIALLY_CLOSED 0x0A
kishino 20:dd736d328de6 91 #define UART_CMD_RES_SNIC_SOCKET_CLOSED 0x0B
kishino 20:dd736d328de6 92 #define UART_CMD_RES_SNIC_CLOSE_SOCKET_FAIL 0x0C
kishino 20:dd736d328de6 93 #define UART_CMD_RES_SNIC_PACKET_TOO_LARGE 0x0D
kishino 20:dd736d328de6 94 #define UART_CMD_RES_SNIC_SEND_FAIL 0x0E
kishino 20:dd736d328de6 95 #define UART_CMD_RES_SNIC_CONNECT_TO_SERVER_FAIL 0x0F
kishino 20:dd736d328de6 96 #define UART_CMD_RES_SNIC_NOT_ENOUGH_MEMORY 0x10
kishino 20:dd736d328de6 97 #define UART_CMD_RES_SNIC_TIMEOUT 0x11
kishino 20:dd736d328de6 98 #define UART_CMD_RES_SNIC_CONNECTION_UP 0x12
kishino 20:dd736d328de6 99 #define UART_CMD_RES_SNIC_GETSOCKOPT_FAIL 0x13
kishino 20:dd736d328de6 100 #define UART_CMD_RES_SNIC_SETSOCKOPT_FAIL 0x14
kishino 20:dd736d328de6 101 #define UART_CMD_RES_SNIC_INVALID_ARGUMENT 0x15
kishino 20:dd736d328de6 102 #define UART_CMD_RES_SNIC_SEND_ARP_FAIL 0x16
kishino 20:dd736d328de6 103 #define UART_CMD_RES_SNIC_INVALID_SOCKET 0x17
kishino 20:dd736d328de6 104 #define UART_CMD_RES_SNIC_COMMAND_PENDING 0x18
kishino 20:dd736d328de6 105 #define UART_CMD_RES_SNIC_SOCKET_NOT_BOUND 0x19
kishino 20:dd736d328de6 106 #define UART_CMD_RES_SNIC_SOCKET_NOT_CONNECTED 0x1A
kishino 20:dd736d328de6 107 #define UART_CMD_RES_SNIC_NO_NETWORK 0x20
kishino 20:dd736d328de6 108 #define UART_CMD_RES_SNIC_INIT_NOT_DONE 0x21
kishino 20:dd736d328de6 109 #define UART_CMD_RES_SNIC_NET_IF_FAIL 0x22
kishino 20:dd736d328de6 110 #define UART_CMD_RES_SNIC_NET_IF_NOT_UP 0x23
kishino 20:dd736d328de6 111 #define UART_CMD_RES_SNIC_DHCP_START_FAIL 0x24
kishino 20:dd736d328de6 112
kishino 20:dd736d328de6 113 #define UART_CMD_RES_WIFI_SUCCESS 0x00
kishino 20:dd736d328de6 114 #define UART_CMD_RES_WIFI_ERR_UNKNOWN_COUNTRY 0x01
kishino 20:dd736d328de6 115 #define UART_CMD_RES_WIFI_ERR_INIT_FAIL 0x02
kishino 20:dd736d328de6 116 #define UART_CMD_RES_WIFI_ERR_ALREADY_JOINED 0x03
kishino 20:dd736d328de6 117 #define UART_CMD_RES_WIFI_ERR_AUTH_TYPE 0x04
kishino 20:dd736d328de6 118 #define UART_CMD_RES_WIFI_ERR_JOIN_FAIL 0x05
kishino 20:dd736d328de6 119 #define UART_CMD_RES_WIFI_ERR_NOT_JOINED 0x06
kishino 20:dd736d328de6 120 #define UART_CMD_RES_WIFI_ERR_LEAVE_FAILED 0x07
kishino 20:dd736d328de6 121 #define UART_CMD_RES_WIFI_COMMAND_PENDING 0x08
kishino 20:dd736d328de6 122 #define UART_CMD_RES_WIFI_WPS_NO_CONFIG 0x09
kishino 20:dd736d328de6 123 #define UART_CMD_RES_WIFI_NETWORK_UP 0x10
kishino 20:dd736d328de6 124 #define UART_CMD_RES_WIFI_NETWORK_DOWN 0x11
kishino 20:dd736d328de6 125 #define UART_CMD_RES_WIFI_FAIL 0xFF
kishino 20:dd736d328de6 126
kishino 20:dd736d328de6 127 /** UART Command sequence number
kishino 20:dd736d328de6 128 */
kishino 20:dd736d328de6 129 static unsigned char mUartRequestSeq;
kishino 20:dd736d328de6 130
kishino 23:4ff2231ff9ba 131 /** Internal utility class used by any other classes.
kishino 20:dd736d328de6 132 */
kishino 25:67183ed15708 133 class C_SNIC_UartMsgUtil: public C_MurataObject
kishino 20:dd736d328de6 134 {
kishino 21:dda155fe5048 135 friend class C_SNIC_Core;
kishino 31:15c22824cc46 136 friend class C_SNIC_WifiInterface;
kishino 33:33f1bc919486 137 friend class UDPSocket;
kishino 34:8c3527b8f44e 138 friend class TCPSocketConnection;
kishino 34:8c3527b8f44e 139 friend class Socket;
kishino 21:dda155fe5048 140
kishino 21:dda155fe5048 141 private:
kishino 20:dd736d328de6 142 C_SNIC_UartMsgUtil();
kishino 26:f2e1030964e4 143 virtual ~C_SNIC_UartMsgUtil();
kishino 20:dd736d328de6 144
kishino 20:dd736d328de6 145 /** Make SNIC UART command payload.
kishino 20:dd736d328de6 146 @param cmd_len Command length
kishino 20:dd736d328de6 147 @param cmd_p Command pointer
kishino 20:dd736d328de6 148 @param payload_p Payload pointer[output]
kishino 20:dd736d328de6 149 @return payload length
kishino 20:dd736d328de6 150 */
kishino 20:dd736d328de6 151 static unsigned short makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p );
kishino 20:dd736d328de6 152
kishino 20:dd736d328de6 153 /** Make SNIC UART command.
kishino 20:dd736d328de6 154 @param cmd_id Command ID
kishino 20:dd736d328de6 155 @param payload_p Payload pointer
kishino 20:dd736d328de6 156 @param uart_command_p UART Command pointer [output]
kishino 20:dd736d328de6 157 @return UART Command length
kishino 20:dd736d328de6 158 */
kishino 20:dd736d328de6 159 static unsigned int makeRequest( unsigned char cmd_id, unsigned char *payload_p, unsigned short payload_len, unsigned char *uart_command_p );
kishino 20:dd736d328de6 160
kishino 20:dd736d328de6 161
kishino 20:dd736d328de6 162 /** Get uart command from receive data.
kishino 20:dd736d328de6 163 @param recvdata_len Receive data length
kishino 20:dd736d328de6 164 @param recvdata_p Pointer of received data from UART
kishino 20:dd736d328de6 165 @param command_id_p Pointer of command ID[output]
kishino 20:dd736d328de6 166 @param payload_p Pointer of payload[output]
kishino 20:dd736d328de6 167 @return Payload length
kishino 20:dd736d328de6 168 */
kishino 20:dd736d328de6 169 static unsigned int getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p
kishino 20:dd736d328de6 170 , unsigned char *command_id_p, unsigned char *payload_p );
kishino 31:15c22824cc46 171
kishino 31:15c22824cc46 172 /** Convert a string to number of ip address.
kishino 31:15c22824cc46 173 @param recvdata_p Pointer of string of IP address
kishino 31:15c22824cc46 174 @return Number of ip address
kishino 31:15c22824cc46 175 */
kishino 31:15c22824cc46 176 static int addrToInteger( const char *addr_p );
kishino 31:15c22824cc46 177
kishino 31:15c22824cc46 178 /** Convert a integer to byte array of ip address.
kishino 31:15c22824cc46 179 @param recvdata_p Pointer of string of IP address
kishino 31:15c22824cc46 180 @return Number of ip address
kishino 31:15c22824cc46 181 */
kishino 31:15c22824cc46 182 static void convertIntToByteAdday( int addr, char *addr_array_p );
kishino 31:15c22824cc46 183
kishino 20:dd736d328de6 184 protected:
kishino 20:dd736d328de6 185
kishino 20:dd736d328de6 186 };
kishino 29:6a0ba999597d 187
kishino 33:33f1bc919486 188 #endif /* _YD_WIFI_UART_MSG_H_ */