customized SNICInterface

Dependents:   MurataTypeYD_Ping

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Fri May 30 08:30:40 2014 +0000
Revision:
32:ae95309643aa
Parent:
31:15c22824cc46
Child:
33:33f1bc919486
Implemented  a API of TCP server.

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_Core.h
kishino 20:dd736d328de6 4 *
kishino 20:dd736d328de6 5 * Purpose: This module has define of internal common function for API.
kishino 20:dd736d328de6 6 *
kishino 20:dd736d328de6 7 * $Author: kishino $
kishino 20:dd736d328de6 8 *
kishino 20:dd736d328de6 9 * $Date: 2014/03/26 $
kishino 20:dd736d328de6 10 *
kishino 20:dd736d328de6 11 * $Revision: 0.0.0.1 $
kishino 20:dd736d328de6 12 * ***********************************************************************/
kishino 20:dd736d328de6 13 #ifndef _SNIC_CORE_H_
kishino 20:dd736d328de6 14 #define _SNIC_CORE_H_
kishino 20:dd736d328de6 15
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 #include "CBuffer.h"
kishino 20:dd736d328de6 21
kishino 20:dd736d328de6 22 #include "SNIC_UartCommandManager.h"
kishino 20:dd736d328de6 23
kishino 29:6a0ba999597d 24 #define UART_REQUEST_PAYLOAD_MAX 1024
kishino 20:dd736d328de6 25
kishino 20:dd736d328de6 26 #define MEMPOOL_BLOCK_SIZE 2048
kishino 20:dd736d328de6 27 #define MEMPOOL_PAYLOAD_NUM 1
kishino 20:dd736d328de6 28 #define MAX_SOCKET_ID 5
kishino 20:dd736d328de6 29
kishino 29:6a0ba999597d 30 #define MEMPOOL_UART_RECV_NUM 2
kishino 32:ae95309643aa 31 #define SNIC_UART_RECVBUF_SIZE 2048
kishino 29:6a0ba999597d 32
kishino 20:dd736d328de6 33 /** Wi-Fi security
kishino 20:dd736d328de6 34 */
kishino 20:dd736d328de6 35 typedef enum SECURITY {
kishino 20:dd736d328de6 36 /** Securiry Open */
kishino 20:dd736d328de6 37 e_SEC_OPEN = 0x00,
kishino 20:dd736d328de6 38 /** Securiry WEP */
kishino 20:dd736d328de6 39 e_SEC_WEP = 0x01,
kishino 20:dd736d328de6 40 /** Securiry WPA-PSK(TKIP) */
kishino 20:dd736d328de6 41 e_SEC_WPA_TKIP = 0x02,
kishino 20:dd736d328de6 42 /** Securiry WPA2-PSK(AES) */
kishino 20:dd736d328de6 43 e_SEC_WPA2_AES = 0x04,
kishino 20:dd736d328de6 44 /** Securiry WPA2-PSK(TKIP/AES) */
kishino 20:dd736d328de6 45 e_SEC_WPA2_MIXED = 0x06,
kishino 20:dd736d328de6 46 /** Securiry WPA-PSK(AES) */
kishino 20:dd736d328de6 47 e_SEC_WPA_AES = 0x07
kishino 20:dd736d328de6 48 }E_SECURITY;
kishino 20:dd736d328de6 49
kishino 20:dd736d328de6 50 /** Wi-Fi status
kishino 20:dd736d328de6 51 */
kishino 20:dd736d328de6 52 typedef enum WIFI_STATUS {
kishino 20:dd736d328de6 53 /** Wi-Fi OFF */
kishino 20:dd736d328de6 54 e_STATUS_OFF = 0,
kishino 20:dd736d328de6 55 /** No network */
kishino 20:dd736d328de6 56 e_NO_NETWORK,
kishino 20:dd736d328de6 57 /** Connected to AP (STA mode) */
kishino 20:dd736d328de6 58 e_STA_JOINED,
kishino 20:dd736d328de6 59 /** Started on AP mode */
kishino 20:dd736d328de6 60 e_AP_STARTED
kishino 20:dd736d328de6 61 }E_WIFI_STATUS;
kishino 20:dd736d328de6 62
kishino 29:6a0ba999597d 63 /** Memorypool
kishino 29:6a0ba999597d 64 */
kishino 29:6a0ba999597d 65 typedef struct
kishino 29:6a0ba999597d 66 {
kishino 29:6a0ba999597d 67 unsigned int size;
kishino 29:6a0ba999597d 68 unsigned char buf[MEMPOOL_BLOCK_SIZE];
kishino 29:6a0ba999597d 69 }tagMEMPOOL_BLOCK_T;
kishino 29:6a0ba999597d 70
kishino 23:4ff2231ff9ba 71 /** Internal class used by any other classes. This class is singleton.
kishino 20:dd736d328de6 72 */
kishino 25:67183ed15708 73 class C_SNIC_Core: public C_MurataObject
kishino 20:dd736d328de6 74 {
kishino 21:dda155fe5048 75 friend class C_SNIC_UartCommandManager;
kishino 21:dda155fe5048 76 friend class C_SNIC_WifiInterface;
kishino 21:dda155fe5048 77 friend class TCPSocketConnection;
kishino 21:dda155fe5048 78 friend class Socket;
kishino 32:ae95309643aa 79 friend class TCPSocketServer;
kishino 21:dda155fe5048 80
kishino 21:dda155fe5048 81 private:
kishino 22:a9ec0cad4f84 82 /** Wi-Fi Network type
kishino 22:a9ec0cad4f84 83 */
kishino 22:a9ec0cad4f84 84 typedef enum NETWORK_TYPE {
kishino 22:a9ec0cad4f84 85 /** Infrastructure */
kishino 22:a9ec0cad4f84 86 e_INFRA = 0,
kishino 22:a9ec0cad4f84 87 /** Adhoc */
kishino 22:a9ec0cad4f84 88 e_ADHOC = 1
kishino 22:a9ec0cad4f84 89 }E_NETWORK_TYPE;
kishino 22:a9ec0cad4f84 90
kishino 22:a9ec0cad4f84 91 /** Connection information
kishino 22:a9ec0cad4f84 92 */
kishino 22:a9ec0cad4f84 93 typedef struct {
kishino 29:6a0ba999597d 94 CircBuffer<char> *recvbuf_p;
kishino 22:a9ec0cad4f84 95 bool is_connected;
kishino 22:a9ec0cad4f84 96 bool is_received;
kishino 32:ae95309643aa 97 int parent_socket;
kishino 32:ae95309643aa 98 bool is_accept;
kishino 22:a9ec0cad4f84 99 }tagCONNECT_INFO_T;
kishino 22:a9ec0cad4f84 100
kishino 22:a9ec0cad4f84 101 /** GEN_FW_VER_GET_REQ Command */
kishino 22:a9ec0cad4f84 102 typedef struct
kishino 22:a9ec0cad4f84 103 {
kishino 22:a9ec0cad4f84 104 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 105 unsigned char seq;
kishino 22:a9ec0cad4f84 106 }tagGEN_FW_VER_GET_REQ_T;
kishino 22:a9ec0cad4f84 107
kishino 22:a9ec0cad4f84 108 /** SNIC_INIT_REQ */
kishino 22:a9ec0cad4f84 109 typedef struct
kishino 22:a9ec0cad4f84 110 {
kishino 28:b796031f6519 111 unsigned char cmd_sid;
kishino 28:b796031f6519 112 unsigned char seq;
kishino 28:b796031f6519 113 unsigned char buf_size[2];
kishino 22:a9ec0cad4f84 114 }tagSNIC_INIT_REQ_T;
kishino 22:a9ec0cad4f84 115
kishino 31:15c22824cc46 116 /** SNIC_IP_CONFIG_REQ */
kishino 31:15c22824cc46 117 typedef struct
kishino 31:15c22824cc46 118 {
kishino 31:15c22824cc46 119 unsigned char cmd_sid;
kishino 31:15c22824cc46 120 unsigned char seq;
kishino 31:15c22824cc46 121 unsigned char interface;
kishino 31:15c22824cc46 122 unsigned char dhcp;
kishino 31:15c22824cc46 123 }tagSNIC_IP_CONFIG_REQ_DHCP_T;
kishino 31:15c22824cc46 124
kishino 31:15c22824cc46 125 /** SNIC_IP_CONFIG_REQ */
kishino 31:15c22824cc46 126 typedef struct
kishino 31:15c22824cc46 127 {
kishino 31:15c22824cc46 128 unsigned char cmd_sid;
kishino 31:15c22824cc46 129 unsigned char seq;
kishino 31:15c22824cc46 130 unsigned char interface;
kishino 31:15c22824cc46 131 unsigned char dhcp;
kishino 31:15c22824cc46 132 unsigned char ip_addr[4];
kishino 31:15c22824cc46 133 unsigned char netmask[4];
kishino 31:15c22824cc46 134 unsigned char gateway[4];
kishino 31:15c22824cc46 135 }tagSNIC_IP_CONFIG_REQ_STATIC_T;
kishino 31:15c22824cc46 136
kishino 22:a9ec0cad4f84 137 /** SNIC_TCP_CREATE_SOCKET_REQ */
kishino 22:a9ec0cad4f84 138 typedef struct
kishino 22:a9ec0cad4f84 139 {
kishino 22:a9ec0cad4f84 140 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 141 unsigned char seq;
kishino 22:a9ec0cad4f84 142 unsigned char bind;
kishino 22:a9ec0cad4f84 143 unsigned char local_addr[4];
kishino 22:a9ec0cad4f84 144 unsigned char local_port[2];
kishino 22:a9ec0cad4f84 145 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
kishino 27:dcc4f34448f0 146
kishino 27:dcc4f34448f0 147 /** SNIC_CLOSE_SOCKET_REQ */
kishino 27:dcc4f34448f0 148 typedef struct
kishino 27:dcc4f34448f0 149 {
kishino 27:dcc4f34448f0 150 unsigned char cmd_sid;
kishino 27:dcc4f34448f0 151 unsigned char seq;
kishino 27:dcc4f34448f0 152 unsigned char socket_id;
kishino 27:dcc4f34448f0 153 }tagSNIC_CLOSE_SOCKET_REQ_T;
kishino 22:a9ec0cad4f84 154
kishino 22:a9ec0cad4f84 155 /** SNIC_TCP_SEND_FROM_SOCKET_REQ */
kishino 22:a9ec0cad4f84 156 typedef struct
kishino 22:a9ec0cad4f84 157 {
kishino 22:a9ec0cad4f84 158 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 159 unsigned char seq;
kishino 22:a9ec0cad4f84 160 unsigned char socket_id;
kishino 22:a9ec0cad4f84 161 unsigned char option;
kishino 22:a9ec0cad4f84 162 unsigned char payload_len[2];
kishino 22:a9ec0cad4f84 163 }tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T;
kishino 22:a9ec0cad4f84 164
kishino 32:ae95309643aa 165 /** SNIC_TCP_CREATE_CONNECTION_REQ */
kishino 32:ae95309643aa 166 typedef struct
kishino 32:ae95309643aa 167 {
kishino 32:ae95309643aa 168 unsigned char cmd_sid;
kishino 32:ae95309643aa 169 unsigned char seq;
kishino 32:ae95309643aa 170 unsigned char socket_id;
kishino 32:ae95309643aa 171 unsigned char recv_bufsize[2];
kishino 32:ae95309643aa 172 unsigned char max_client;
kishino 32:ae95309643aa 173 }tagSNIC_TCP_CREATE_CONNECTION_REQ_T;
kishino 32:ae95309643aa 174
kishino 22:a9ec0cad4f84 175 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
kishino 22:a9ec0cad4f84 176 typedef struct
kishino 22:a9ec0cad4f84 177 {
kishino 22:a9ec0cad4f84 178 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 179 unsigned char seq;
kishino 22:a9ec0cad4f84 180 unsigned char socket_id;
kishino 22:a9ec0cad4f84 181 unsigned char remote_addr[4];
kishino 22:a9ec0cad4f84 182 unsigned char remote_port[2];
kishino 22:a9ec0cad4f84 183 unsigned char recv_bufsize[2];
kishino 22:a9ec0cad4f84 184 unsigned char timeout;
kishino 22:a9ec0cad4f84 185 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
kishino 22:a9ec0cad4f84 186
kishino 32:ae95309643aa 187 /** SNIC_GET_DHCP_INFO_REQ */
kishino 32:ae95309643aa 188 typedef struct
kishino 32:ae95309643aa 189 {
kishino 32:ae95309643aa 190 unsigned char cmd_sid;
kishino 32:ae95309643aa 191 unsigned char seq;
kishino 32:ae95309643aa 192 unsigned char interface;
kishino 32:ae95309643aa 193 }tagSNIC_GET_DHCP_INFO_REQ_T;
kishino 32:ae95309643aa 194
kishino 22:a9ec0cad4f84 195 /** WIFI_ON_REQ Command */
kishino 22:a9ec0cad4f84 196 typedef struct
kishino 22:a9ec0cad4f84 197 {
kishino 22:a9ec0cad4f84 198 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 199 unsigned char seq;
kishino 22:a9ec0cad4f84 200 char country[COUNTRYC_CODE_LENTH];
kishino 22:a9ec0cad4f84 201 }tagWIFI_ON_REQ_T;
kishino 22:a9ec0cad4f84 202
kishino 22:a9ec0cad4f84 203 /** WIFI_OFF_REQ Command */
kishino 22:a9ec0cad4f84 204 typedef struct
kishino 22:a9ec0cad4f84 205 {
kishino 22:a9ec0cad4f84 206 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 207 unsigned char seq;
kishino 22:a9ec0cad4f84 208 }tagWIFI_OFF_REQ_T;
kishino 22:a9ec0cad4f84 209
kishino 22:a9ec0cad4f84 210 /** WIFI_DISCONNECT_REQ Command */
kishino 22:a9ec0cad4f84 211 typedef struct
kishino 22:a9ec0cad4f84 212 {
kishino 22:a9ec0cad4f84 213 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 214 unsigned char seq;
kishino 22:a9ec0cad4f84 215 }tagWIFI_DISCONNECT_REQ_T;
kishino 22:a9ec0cad4f84 216
kishino 22:a9ec0cad4f84 217 /** WIFI_GET_STA_RSSI_REQ Command */
kishino 22:a9ec0cad4f84 218 typedef struct
kishino 22:a9ec0cad4f84 219 {
kishino 22:a9ec0cad4f84 220 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 221 unsigned char seq;
kishino 22:a9ec0cad4f84 222 }tagWIFI_GET_STA_RSSI_REQ_T;
kishino 22:a9ec0cad4f84 223
kishino 22:a9ec0cad4f84 224 /** WIFI_SCAN_REQ Command */
kishino 22:a9ec0cad4f84 225 typedef struct
kishino 22:a9ec0cad4f84 226 {
kishino 22:a9ec0cad4f84 227 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 228 unsigned char seq;
kishino 22:a9ec0cad4f84 229 unsigned char scan_type;
kishino 22:a9ec0cad4f84 230 unsigned char bss_type;
kishino 22:a9ec0cad4f84 231 unsigned char bssid[BSSID_MAC_LENTH];
kishino 22:a9ec0cad4f84 232 unsigned char chan_list;
kishino 22:a9ec0cad4f84 233 unsigned char ssid[SSID_MAX_LENGTH+1];
kishino 22:a9ec0cad4f84 234 }tagWIFI_SCAN_REQ_T;
kishino 22:a9ec0cad4f84 235
kishino 29:6a0ba999597d 236 /** WIFI_GET_STATUS_REQ Command */
kishino 29:6a0ba999597d 237 typedef struct
kishino 29:6a0ba999597d 238 {
kishino 29:6a0ba999597d 239 unsigned char cmd_sid;
kishino 29:6a0ba999597d 240 unsigned char seq;
kishino 29:6a0ba999597d 241 unsigned char interface;
kishino 29:6a0ba999597d 242 }tagWIFI_GET_STATUS_REQ_T;
kishino 29:6a0ba999597d 243
kishino 20:dd736d328de6 244 /** Get buffer for command from memory pool.
kishino 20:dd736d328de6 245 @return Pointer of buffer
kishino 20:dd736d328de6 246 */
kishino 29:6a0ba999597d 247 tagMEMPOOL_BLOCK_T *allocCmdBuf();
kishino 20:dd736d328de6 248
kishino 20:dd736d328de6 249 /** Release buffer to memory pool.
kishino 20:dd736d328de6 250 @param buf_p Pointer of buffer
kishino 20:dd736d328de6 251 */
kishino 20:dd736d328de6 252 void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 20:dd736d328de6 253
kishino 29:6a0ba999597d 254 /** Get buffer for command from memory pool.
kishino 29:6a0ba999597d 255 @return Pointer of buffer
kishino 29:6a0ba999597d 256 */
kishino 29:6a0ba999597d 257 tagMEMPOOL_BLOCK_T *allocUartRcvBuf();
kishino 29:6a0ba999597d 258
kishino 29:6a0ba999597d 259 /** Release buffer to memory pool.
kishino 29:6a0ba999597d 260 @param buf_p Pointer of buffer
kishino 29:6a0ba999597d 261 */
kishino 29:6a0ba999597d 262 void freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 29:6a0ba999597d 263
kishino 29:6a0ba999597d 264 /** Module Reset
kishino 29:6a0ba999597d 265 */
kishino 29:6a0ba999597d 266 int resetModule( PinName reset );
kishino 29:6a0ba999597d 267
kishino 29:6a0ba999597d 268 /** Initialize UART
kishino 20:dd736d328de6 269 */
kishino 20:dd736d328de6 270 int initUart( PinName tx, PinName rx, int baud );
kishino 20:dd736d328de6 271
kishino 20:dd736d328de6 272 /** Send data to UART
kishino 20:dd736d328de6 273 @param len Length of send data
kishino 20:dd736d328de6 274 @param data Pointer of send data
kishino 20:dd736d328de6 275 @return 0:success/other:fail
kishino 20:dd736d328de6 276 */
kishino 20:dd736d328de6 277 int sendUart( unsigned int len, unsigned char *data );
kishino 20:dd736d328de6 278
kishino 20:dd736d328de6 279 /** Preparation of the UART command
kishino 20:dd736d328de6 280 @param cmd_id UART Command ID
kishino 20:dd736d328de6 281 @param cmd_sid UART Command SubID
kishino 20:dd736d328de6 282 @param req_buf_p Pointer of UART request buffer
kishino 20:dd736d328de6 283 @param req_buf_len Length of UART request buffer
kishino 20:dd736d328de6 284 @param response_buf_p Pointer of UART response buffer
kishino 20:dd736d328de6 285 @param command_p Pointer of UART command[output]
kishino 20:dd736d328de6 286 @return Length of UART command.
kishino 20:dd736d328de6 287 */
kishino 20:dd736d328de6 288 unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
kishino 20:dd736d328de6 289 , unsigned char *req_buf_p, unsigned int req_buf_len
kishino 20:dd736d328de6 290 , unsigned char *response_buf_p, unsigned char *command_p );
kishino 20:dd736d328de6 291
kishino 20:dd736d328de6 292 /**
kishino 20:dd736d328de6 293 Get pointer of connection information.
kishino 20:dd736d328de6 294 @param socket_id Socket ID
kishino 20:dd736d328de6 295 @return The pointer of connection information
kishino 20:dd736d328de6 296 */
kishino 22:a9ec0cad4f84 297 C_SNIC_Core::tagCONNECT_INFO_T *getConnectInfo( int socket_id );
kishino 20:dd736d328de6 298
kishino 20:dd736d328de6 299 /**
kishino 20:dd736d328de6 300 Get pointer of the instance of C_SNIC_UartCommandManager.
kishino 20:dd736d328de6 301 @return The pointer of the instance of C_SNIC_UartCommandManager.
kishino 20:dd736d328de6 302 */
kishino 20:dd736d328de6 303 C_SNIC_UartCommandManager *getUartCommand();
kishino 20:dd736d328de6 304
kishino 29:6a0ba999597d 305 unsigned char *getCommandBuf();
kishino 29:6a0ba999597d 306
kishino 20:dd736d328de6 307 /** Get an instance of the C_SNIC_Core class.
kishino 20:dd736d328de6 308 @return Instance of the C_SNIC_Core class
kishino 20:dd736d328de6 309 @note Please do not create an instance in the default constructor this class.
kishino 20:dd736d328de6 310 Please use this method when you want to get an instance.
kishino 20:dd736d328de6 311 */
kishino 20:dd736d328de6 312 static C_SNIC_Core *getInstance();
kishino 20:dd736d328de6 313
kishino 20:dd736d328de6 314 private:
kishino 20:dd736d328de6 315 static C_SNIC_Core *mInstance_p;
kishino 20:dd736d328de6 316 Thread *mUartRecvThread_p;
kishino 29:6a0ba999597d 317 Thread *mUartRecvDispatchThread_p;
kishino 20:dd736d328de6 318 RawSerial *mUart_p;
kishino 20:dd736d328de6 319 Mutex mUartMutex;
kishino 29:6a0ba999597d 320
kishino 20:dd736d328de6 321 // DigitalInOut mModuleReset;
kishino 20:dd736d328de6 322 C_SNIC_UartCommandManager *mUartCommand_p;
kishino 29:6a0ba999597d 323
kishino 29:6a0ba999597d 324 CircBuffer<char> *mUartRecvBuf_p; // UART RecvBuffer
kishino 29:6a0ba999597d 325
kishino 20:dd736d328de6 326 /** Socket buffer */
kishino 20:dd736d328de6 327 tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1];
kishino 20:dd736d328de6 328
kishino 20:dd736d328de6 329 /** Constructor
kishino 20:dd736d328de6 330 */
kishino 20:dd736d328de6 331 C_SNIC_Core();
kishino 20:dd736d328de6 332
kishino 26:f2e1030964e4 333 virtual ~C_SNIC_Core();
kishino 29:6a0ba999597d 334
kishino 29:6a0ba999597d 335 static void uartRecvCallback( void );
kishino 20:dd736d328de6 336 /** Receiving thread of UART
kishino 20:dd736d328de6 337 */
kishino 29:6a0ba999597d 338 static void uartRecvDispatchThread( void const *args_p );
kishino 20:dd736d328de6 339 };
kishino 20:dd736d328de6 340
kishino 20:dd736d328de6 341 #endif