Customized SNICInterface

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Tue Mar 25 01:42:25 2014 +0000
Revision:
12:0254eaccfda2
Child:
13:53e6471d5753
Refactoring of the class name

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 12:0254eaccfda2 1 #ifndef _SNIC_CORE_H_
kishino 12:0254eaccfda2 2 #define _SNIC_CORE_H_
kishino 12:0254eaccfda2 3
kishino 12:0254eaccfda2 4 #include "mbed.h"
kishino 12:0254eaccfda2 5 #include "rtos.h"
kishino 12:0254eaccfda2 6 #include "RawSerial.h"
kishino 12:0254eaccfda2 7 #include "CBuffer.h"
kishino 12:0254eaccfda2 8
kishino 12:0254eaccfda2 9 #include "SNIC_UartCommandManager.h"
kishino 12:0254eaccfda2 10
kishino 12:0254eaccfda2 11 namespace murata_wifi
kishino 12:0254eaccfda2 12 {
kishino 12:0254eaccfda2 13 #define UART_REQUEST_PAYLOAD_MAX 256
kishino 12:0254eaccfda2 14
kishino 12:0254eaccfda2 15 #define MEMPOOL_BLOCK_SIZE 2048
kishino 12:0254eaccfda2 16 #define MEMPOOL_PAYLOAD_NUM 1
kishino 12:0254eaccfda2 17 typedef struct
kishino 12:0254eaccfda2 18 {
kishino 12:0254eaccfda2 19 unsigned char buf[MEMPOOL_BLOCK_SIZE];
kishino 12:0254eaccfda2 20 }tagMEMPOOL_BLOCK_T;
kishino 12:0254eaccfda2 21
kishino 12:0254eaccfda2 22 #define MAX_SOCKET_ID 5
kishino 12:0254eaccfda2 23
kishino 12:0254eaccfda2 24 /** Connection information
kishino 12:0254eaccfda2 25 */
kishino 12:0254eaccfda2 26 typedef struct {
kishino 12:0254eaccfda2 27 CircBuffer<unsigned char> *recvbuf_p;
kishino 12:0254eaccfda2 28 bool is_connected;
kishino 12:0254eaccfda2 29 bool is_received;
kishino 12:0254eaccfda2 30 }tagCONNECT_INFO_T;
kishino 12:0254eaccfda2 31
kishino 12:0254eaccfda2 32 /** Wi-Fi security
kishino 12:0254eaccfda2 33 */
kishino 12:0254eaccfda2 34 typedef enum SECURITY {
kishino 12:0254eaccfda2 35 /** Securiry Open */
kishino 12:0254eaccfda2 36 e_SEC_OPEN = 0x00,
kishino 12:0254eaccfda2 37 /** Securiry WEP */
kishino 12:0254eaccfda2 38 e_SEC_WEP = 0x01,
kishino 12:0254eaccfda2 39 /** Securiry WPA-PSK(TKIP) */
kishino 12:0254eaccfda2 40 e_SEC_WPA_TKIP = 0x02,
kishino 12:0254eaccfda2 41 /** Securiry WPA2-PSK(AES) */
kishino 12:0254eaccfda2 42 e_SEC_WPA2_AES = 0x04,
kishino 12:0254eaccfda2 43 /** Securiry WPA2-PSK(TKIP/AES) */
kishino 12:0254eaccfda2 44 e_SEC_WPA2_MIXED = 0x06,
kishino 12:0254eaccfda2 45 /** Securiry WPA-PSK(AES) */
kishino 12:0254eaccfda2 46 e_SEC_WPA_AES = 0x07
kishino 12:0254eaccfda2 47 }E_SECURITY;
kishino 12:0254eaccfda2 48
kishino 12:0254eaccfda2 49 /** Wi-Fi Network type
kishino 12:0254eaccfda2 50 */
kishino 12:0254eaccfda2 51 typedef enum NETWORK_TYPE {
kishino 12:0254eaccfda2 52 /** Infrastructure */
kishino 12:0254eaccfda2 53 e_INFRA = 0,
kishino 12:0254eaccfda2 54 /** Adhoc */
kishino 12:0254eaccfda2 55 e_ADHOC = 1
kishino 12:0254eaccfda2 56 }E_NETWORK_TYPE;
kishino 12:0254eaccfda2 57
kishino 12:0254eaccfda2 58 /** Wi-Fi status
kishino 12:0254eaccfda2 59 */
kishino 12:0254eaccfda2 60 typedef enum WIFI_STATUS {
kishino 12:0254eaccfda2 61 /** Wi-Fi OFF */
kishino 12:0254eaccfda2 62 e_STATUS_OFF = 0,
kishino 12:0254eaccfda2 63 /** No network */
kishino 12:0254eaccfda2 64 e_NO_NETWORK,
kishino 12:0254eaccfda2 65 /** Connected to AP (STA mode) */
kishino 12:0254eaccfda2 66 e_STA_JOINED,
kishino 12:0254eaccfda2 67 /** Started on AP mode */
kishino 12:0254eaccfda2 68 e_AP_STARTED
kishino 12:0254eaccfda2 69 }E_WIFI_STATUS;
kishino 12:0254eaccfda2 70
kishino 12:0254eaccfda2 71 /** GEN_FW_VER_GET_REQ Command */
kishino 12:0254eaccfda2 72 typedef struct
kishino 12:0254eaccfda2 73 {
kishino 12:0254eaccfda2 74 unsigned char cmd_sid;
kishino 12:0254eaccfda2 75 unsigned char seq;
kishino 12:0254eaccfda2 76 }tagGEN_FW_VER_GET_REQ_T;
kishino 12:0254eaccfda2 77
kishino 12:0254eaccfda2 78 /** SNIC_INIT_REQ */
kishino 12:0254eaccfda2 79 typedef struct
kishino 12:0254eaccfda2 80 {
kishino 12:0254eaccfda2 81 unsigned char cmd_sid;
kishino 12:0254eaccfda2 82 unsigned char seq;
kishino 12:0254eaccfda2 83 unsigned short buf_size;
kishino 12:0254eaccfda2 84 }tagSNIC_INIT_REQ_T;
kishino 12:0254eaccfda2 85
kishino 12:0254eaccfda2 86 /** SNIC_TCP_CREATE_SOCKET_REQ */
kishino 12:0254eaccfda2 87 typedef struct
kishino 12:0254eaccfda2 88 {
kishino 12:0254eaccfda2 89 unsigned char cmd_sid;
kishino 12:0254eaccfda2 90 unsigned char seq;
kishino 12:0254eaccfda2 91 unsigned char bind;
kishino 12:0254eaccfda2 92 unsigned int local_addr;
kishino 12:0254eaccfda2 93 unsigned short local_port;
kishino 12:0254eaccfda2 94 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
kishino 12:0254eaccfda2 95
kishino 12:0254eaccfda2 96 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
kishino 12:0254eaccfda2 97 typedef struct
kishino 12:0254eaccfda2 98 {
kishino 12:0254eaccfda2 99 unsigned char cmd_sid;
kishino 12:0254eaccfda2 100 unsigned char seq;
kishino 12:0254eaccfda2 101 unsigned char socket_id;
kishino 12:0254eaccfda2 102 unsigned char remote_addr[4];
kishino 12:0254eaccfda2 103 unsigned char remote_port[2];
kishino 12:0254eaccfda2 104 unsigned char recv_bufsize[2];
kishino 12:0254eaccfda2 105 /*
kishino 12:0254eaccfda2 106 unsigned int remote_addr;
kishino 12:0254eaccfda2 107 unsigned short remote_port;
kishino 12:0254eaccfda2 108 unsigned short recv_bufsize;
kishino 12:0254eaccfda2 109 */
kishino 12:0254eaccfda2 110 unsigned char timeout;
kishino 12:0254eaccfda2 111 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
kishino 12:0254eaccfda2 112
kishino 12:0254eaccfda2 113 /** WIFI_ON_REQ Command */
kishino 12:0254eaccfda2 114 typedef struct
kishino 12:0254eaccfda2 115 {
kishino 12:0254eaccfda2 116 unsigned char cmd_sid;
kishino 12:0254eaccfda2 117 unsigned char seq;
kishino 12:0254eaccfda2 118 char country[COUNTRYC_CODE_LENTH];
kishino 12:0254eaccfda2 119 }tagWIFI_ON_REQ_T;
kishino 12:0254eaccfda2 120
kishino 12:0254eaccfda2 121 /** WIFI_OFF_REQ Command */
kishino 12:0254eaccfda2 122 typedef struct
kishino 12:0254eaccfda2 123 {
kishino 12:0254eaccfda2 124 unsigned char cmd_sid;
kishino 12:0254eaccfda2 125 unsigned char seq;
kishino 12:0254eaccfda2 126 }tagWIFI_OFF_REQ_T;
kishino 12:0254eaccfda2 127
kishino 12:0254eaccfda2 128 /** WIFI_DISCONNECT_REQ Command */
kishino 12:0254eaccfda2 129 typedef struct
kishino 12:0254eaccfda2 130 {
kishino 12:0254eaccfda2 131 unsigned char cmd_sid;
kishino 12:0254eaccfda2 132 unsigned char seq;
kishino 12:0254eaccfda2 133 }tagWIFI_DISCONNECT_REQ_T;
kishino 12:0254eaccfda2 134
kishino 12:0254eaccfda2 135 /** WIFI_GET_STA_RSSI_REQ Command */
kishino 12:0254eaccfda2 136 typedef struct
kishino 12:0254eaccfda2 137 {
kishino 12:0254eaccfda2 138 unsigned char cmd_sid;
kishino 12:0254eaccfda2 139 unsigned char seq;
kishino 12:0254eaccfda2 140 }tagWIFI_GET_STA_RSSI_REQ_T;
kishino 12:0254eaccfda2 141
kishino 12:0254eaccfda2 142 /** WIFI_GET_STATUS_REQ Command */
kishino 12:0254eaccfda2 143 typedef struct
kishino 12:0254eaccfda2 144 {
kishino 12:0254eaccfda2 145 unsigned char cmd_sid;
kishino 12:0254eaccfda2 146 unsigned char seq;
kishino 12:0254eaccfda2 147 unsigned char interface;
kishino 12:0254eaccfda2 148 }tagWIFI_GET_STATUS_REQ_T;
kishino 12:0254eaccfda2 149
kishino 12:0254eaccfda2 150 /** WIFI_SCAN_REQ Command */
kishino 12:0254eaccfda2 151 typedef struct
kishino 12:0254eaccfda2 152 {
kishino 12:0254eaccfda2 153 unsigned char cmd_sid;
kishino 12:0254eaccfda2 154 unsigned char seq;
kishino 12:0254eaccfda2 155 unsigned char scan_type;
kishino 12:0254eaccfda2 156 unsigned char bss_type;
kishino 12:0254eaccfda2 157 unsigned char bssid[BSSID_MAC_LENTH];
kishino 12:0254eaccfda2 158 unsigned char chan_list;
kishino 12:0254eaccfda2 159 unsigned char ssid[SSID_MAX_LENGTH+1];
kishino 12:0254eaccfda2 160 }tagWIFI_SCAN_REQ_T;
kishino 12:0254eaccfda2 161
kishino 12:0254eaccfda2 162 /** C_SNIC_Core class
kishino 12:0254eaccfda2 163 */
kishino 12:0254eaccfda2 164 class C_SNIC_Core
kishino 12:0254eaccfda2 165 {
kishino 12:0254eaccfda2 166
kishino 12:0254eaccfda2 167 public:
kishino 12:0254eaccfda2 168 C_SNIC_UartCommandManager mUartCommand;
kishino 12:0254eaccfda2 169
kishino 12:0254eaccfda2 170 /** Get buffer for command from memory pool.
kishino 12:0254eaccfda2 171 @return Pointer of buffer
kishino 12:0254eaccfda2 172 */
kishino 12:0254eaccfda2 173 tagMEMPOOL_BLOCK_T *getAlocCmdBuf();
kishino 12:0254eaccfda2 174
kishino 12:0254eaccfda2 175 /** Release buffer to memory pool.
kishino 12:0254eaccfda2 176 @param buf_p Pointer of buffer
kishino 12:0254eaccfda2 177 */
kishino 12:0254eaccfda2 178 void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 12:0254eaccfda2 179
kishino 12:0254eaccfda2 180 /** Initialize UART
kishino 12:0254eaccfda2 181 */
kishino 12:0254eaccfda2 182 int initUart( PinName tx, PinName rx, int baud );
kishino 12:0254eaccfda2 183
kishino 12:0254eaccfda2 184 /** Send data to UART
kishino 12:0254eaccfda2 185 @param len Length of send data
kishino 12:0254eaccfda2 186 @param data Pointer of send data
kishino 12:0254eaccfda2 187 @return 0:success/other:fail
kishino 12:0254eaccfda2 188 */
kishino 12:0254eaccfda2 189 int sendUart( unsigned int len, unsigned char *data );
kishino 12:0254eaccfda2 190
kishino 12:0254eaccfda2 191 /** Preparation of the UART command
kishino 12:0254eaccfda2 192 @param cmd_id UART Command ID
kishino 12:0254eaccfda2 193 @param cmd_sid UART Command SubID
kishino 12:0254eaccfda2 194 @param req_buf_p Pointer of UART request buffer
kishino 12:0254eaccfda2 195 @param req_buf_len Length of UART request buffer
kishino 12:0254eaccfda2 196 @param response_buf_p Pointer of UART response buffer
kishino 12:0254eaccfda2 197 @param command_p Pointer of UART command[output]
kishino 12:0254eaccfda2 198 @return Length of UART command.
kishino 12:0254eaccfda2 199 */
kishino 12:0254eaccfda2 200 unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
kishino 12:0254eaccfda2 201 , unsigned char *req_buf_p, unsigned int req_buf_len
kishino 12:0254eaccfda2 202 , unsigned char *response_buf_p, unsigned char *command_p );
kishino 12:0254eaccfda2 203
kishino 12:0254eaccfda2 204 /**
kishino 12:0254eaccfda2 205 Get pointer of connection information.
kishino 12:0254eaccfda2 206 @param socket_id Socket ID
kishino 12:0254eaccfda2 207 @return The pointer of connection information
kishino 12:0254eaccfda2 208 */
kishino 12:0254eaccfda2 209 tagCONNECT_INFO_T *getConnectInfo( int socket_id );
kishino 12:0254eaccfda2 210
kishino 12:0254eaccfda2 211 /** Get an instance of the C_SNIC_Core class.
kishino 12:0254eaccfda2 212 @return Instance of the C_SNIC_Core class
kishino 12:0254eaccfda2 213 @note Please do not create an instance in the default constructor this class.
kishino 12:0254eaccfda2 214 Please use this method when you want to get an instance.
kishino 12:0254eaccfda2 215 */
kishino 12:0254eaccfda2 216 static C_SNIC_Core *getInstance();
kishino 12:0254eaccfda2 217
kishino 12:0254eaccfda2 218 protected:
kishino 12:0254eaccfda2 219 static C_SNIC_Core *mInstance_p;
kishino 12:0254eaccfda2 220 Thread *mUartRecvThread_p;
kishino 12:0254eaccfda2 221 RawSerial *mUart_p;
kishino 12:0254eaccfda2 222 Mutex mUartMutex;
kishino 12:0254eaccfda2 223 // DigitalInOut mModuleReset;
kishino 12:0254eaccfda2 224
kishino 12:0254eaccfda2 225 private:
kishino 12:0254eaccfda2 226 /** MemoryPool for payload of UART response */
kishino 12:0254eaccfda2 227 MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload;
kishino 12:0254eaccfda2 228
kishino 12:0254eaccfda2 229 /** Socket buffer */
kishino 12:0254eaccfda2 230 tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1];
kishino 12:0254eaccfda2 231
kishino 12:0254eaccfda2 232 /** Constructor
kishino 12:0254eaccfda2 233 */
kishino 12:0254eaccfda2 234 C_SNIC_Core();
kishino 12:0254eaccfda2 235
kishino 12:0254eaccfda2 236 /** Receiving thread of UART
kishino 12:0254eaccfda2 237 */
kishino 12:0254eaccfda2 238 static void uartRecvThread( void const *args_p );
kishino 12:0254eaccfda2 239 };
kishino 12:0254eaccfda2 240 }
kishino 12:0254eaccfda2 241
kishino 12:0254eaccfda2 242 #endif