customized SNICInterface

Dependents:   MurataTypeYD_Ping

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Thu May 29 03:23:21 2014 +0000
Revision:
31:15c22824cc46
Parent:
29:6a0ba999597d
Child:
32:ae95309643aa
Created a command of IP address settings.

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