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