Websocket_Sample for MurataTypeYD

Dependencies:   mbed picojson

Committer:
komoritan
Date:
Thu Mar 12 12:15:46 2015 +0000
Revision:
1:b5ac0f971f43
Parent:
0:14bd24b5a77f
Fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 0:14bd24b5a77f 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
komoritan 0:14bd24b5a77f 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART.
komoritan 0:14bd24b5a77f 3 *
komoritan 0:14bd24b5a77f 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
komoritan 0:14bd24b5a77f 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
komoritan 0:14bd24b5a77f 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
komoritan 0:14bd24b5a77f 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
komoritan 0:14bd24b5a77f 8 * furnished to do so, subject to the following conditions:
komoritan 0:14bd24b5a77f 9 *
komoritan 0:14bd24b5a77f 10 * The above copyright notice and this permission notice shall be included in all copies or
komoritan 0:14bd24b5a77f 11 * substantial portions of the Software.
komoritan 0:14bd24b5a77f 12 *
komoritan 0:14bd24b5a77f 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
komoritan 0:14bd24b5a77f 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
komoritan 0:14bd24b5a77f 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
komoritan 0:14bd24b5a77f 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
komoritan 0:14bd24b5a77f 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
komoritan 0:14bd24b5a77f 18 */
komoritan 0:14bd24b5a77f 19 #ifndef _SNIC_CORE_H_
komoritan 0:14bd24b5a77f 20 #define _SNIC_CORE_H_
komoritan 0:14bd24b5a77f 21
komoritan 0:14bd24b5a77f 22 #include "MurataObject.h"
komoritan 0:14bd24b5a77f 23 #include "mbed.h"
komoritan 0:14bd24b5a77f 24 #include "rtos.h"
komoritan 0:14bd24b5a77f 25 #include "RawSerial.h"
komoritan 0:14bd24b5a77f 26 #include "CBuffer.h"
komoritan 0:14bd24b5a77f 27
komoritan 0:14bd24b5a77f 28 #include "SNIC_UartCommandManager.h"
komoritan 0:14bd24b5a77f 29
komoritan 0:14bd24b5a77f 30 #define UART_REQUEST_PAYLOAD_MAX 2048
komoritan 0:14bd24b5a77f 31
komoritan 0:14bd24b5a77f 32 #define MEMPOOL_BLOCK_SIZE 2048
komoritan 0:14bd24b5a77f 33 #define MEMPOOL_PAYLOAD_NUM 1
komoritan 0:14bd24b5a77f 34 #define MAX_SOCKET_ID 5
komoritan 0:14bd24b5a77f 35
komoritan 0:14bd24b5a77f 36 #define MEMPOOL_UART_RECV_NUM 6
komoritan 0:14bd24b5a77f 37 #define SNIC_UART_RECVBUF_SIZE 2048
komoritan 0:14bd24b5a77f 38
komoritan 0:14bd24b5a77f 39 /** Wi-Fi security
komoritan 0:14bd24b5a77f 40 */
komoritan 0:14bd24b5a77f 41 typedef enum SECURITY {
komoritan 0:14bd24b5a77f 42 /** Securiry Open */
komoritan 0:14bd24b5a77f 43 e_SEC_OPEN = 0x00,
komoritan 0:14bd24b5a77f 44 /** Securiry WEP */
komoritan 0:14bd24b5a77f 45 e_SEC_WEP = 0x01,
komoritan 0:14bd24b5a77f 46 /** Securiry WPA-PSK(TKIP) */
komoritan 0:14bd24b5a77f 47 e_SEC_WPA_TKIP = 0x02,
komoritan 0:14bd24b5a77f 48 /** Securiry WPA2-PSK(AES) */
komoritan 0:14bd24b5a77f 49 e_SEC_WPA2_AES = 0x04,
komoritan 0:14bd24b5a77f 50 /** Securiry WPA2-PSK(TKIP/AES) */
komoritan 0:14bd24b5a77f 51 e_SEC_WPA2_MIXED = 0x06,
komoritan 0:14bd24b5a77f 52 /** Securiry WPA-PSK(AES) */
komoritan 0:14bd24b5a77f 53 e_SEC_WPA_AES = 0x07
komoritan 0:14bd24b5a77f 54 }E_SECURITY;
komoritan 0:14bd24b5a77f 55
komoritan 0:14bd24b5a77f 56 /** Wi-Fi status
komoritan 0:14bd24b5a77f 57 */
komoritan 0:14bd24b5a77f 58 typedef enum WIFI_STATUS {
komoritan 0:14bd24b5a77f 59 /** Wi-Fi OFF */
komoritan 0:14bd24b5a77f 60 e_STATUS_OFF = 0,
komoritan 0:14bd24b5a77f 61 /** No network */
komoritan 0:14bd24b5a77f 62 e_NO_NETWORK,
komoritan 0:14bd24b5a77f 63 /** Connected to AP (STA mode) */
komoritan 0:14bd24b5a77f 64 e_STA_JOINED,
komoritan 0:14bd24b5a77f 65 /** Started on AP mode */
komoritan 0:14bd24b5a77f 66 e_AP_STARTED
komoritan 0:14bd24b5a77f 67 }E_WIFI_STATUS;
komoritan 0:14bd24b5a77f 68
komoritan 0:14bd24b5a77f 69 /** Memorypool
komoritan 0:14bd24b5a77f 70 */
komoritan 0:14bd24b5a77f 71 typedef struct
komoritan 0:14bd24b5a77f 72 {
komoritan 0:14bd24b5a77f 73 unsigned int size;
komoritan 0:14bd24b5a77f 74 unsigned int demand_size;
komoritan 0:14bd24b5a77f 75 unsigned char buf[MEMPOOL_BLOCK_SIZE];
komoritan 0:14bd24b5a77f 76 }tagMEMPOOL_BLOCK_T;
komoritan 0:14bd24b5a77f 77
komoritan 0:14bd24b5a77f 78 /** Internal class used by any other classes. This class is singleton.
komoritan 0:14bd24b5a77f 79 */
komoritan 0:14bd24b5a77f 80 class C_SNIC_Core: public C_MurataObject
komoritan 0:14bd24b5a77f 81 {
komoritan 0:14bd24b5a77f 82 friend class C_SNIC_UartCommandManager;
komoritan 0:14bd24b5a77f 83 friend class C_SNIC_WifiInterface;
komoritan 0:14bd24b5a77f 84 friend class TCPSocketConnection;
komoritan 0:14bd24b5a77f 85 friend class TCPSocketServer;
komoritan 0:14bd24b5a77f 86 friend class UDPSocket;
komoritan 0:14bd24b5a77f 87 friend class Socket;
komoritan 0:14bd24b5a77f 88
komoritan 0:14bd24b5a77f 89 private:
komoritan 0:14bd24b5a77f 90 /** Wi-Fi Network type
komoritan 0:14bd24b5a77f 91 */
komoritan 0:14bd24b5a77f 92 typedef enum NETWORK_TYPE {
komoritan 0:14bd24b5a77f 93 /** Infrastructure */
komoritan 0:14bd24b5a77f 94 e_INFRA = 0,
komoritan 0:14bd24b5a77f 95 /** Adhoc */
komoritan 0:14bd24b5a77f 96 e_ADHOC = 1
komoritan 0:14bd24b5a77f 97 }E_NETWORK_TYPE;
komoritan 0:14bd24b5a77f 98
komoritan 0:14bd24b5a77f 99 /** Connection information
komoritan 0:14bd24b5a77f 100 */
komoritan 0:14bd24b5a77f 101 typedef struct {
komoritan 0:14bd24b5a77f 102 CircBuffer<char> *recvbuf_p;
komoritan 0:14bd24b5a77f 103 bool is_connected;
komoritan 0:14bd24b5a77f 104 bool is_received;
komoritan 0:14bd24b5a77f 105 bool is_receive_complete;
komoritan 0:14bd24b5a77f 106 int parent_socket;
komoritan 0:14bd24b5a77f 107 int from_ip;
komoritan 0:14bd24b5a77f 108 short from_port;
komoritan 0:14bd24b5a77f 109 bool is_accept;
komoritan 0:14bd24b5a77f 110 Mutex mutex;
komoritan 0:14bd24b5a77f 111 }tagCONNECT_INFO_T;
komoritan 0:14bd24b5a77f 112
komoritan 0:14bd24b5a77f 113 /** UDP Recv information
komoritan 0:14bd24b5a77f 114 */
komoritan 0:14bd24b5a77f 115 typedef struct {
komoritan 0:14bd24b5a77f 116 CircBuffer<char> *recvbuf_p;
komoritan 0:14bd24b5a77f 117 int from_ip;
komoritan 0:14bd24b5a77f 118 short from_port;
komoritan 0:14bd24b5a77f 119 int parent_socket;
komoritan 0:14bd24b5a77f 120 bool is_received;
komoritan 0:14bd24b5a77f 121 Mutex mutex;
komoritan 0:14bd24b5a77f 122 }tagUDP_RECVINFO_T;
komoritan 0:14bd24b5a77f 123
komoritan 0:14bd24b5a77f 124 /** GEN_FW_VER_GET_REQ Command */
komoritan 0:14bd24b5a77f 125 typedef struct
komoritan 0:14bd24b5a77f 126 {
komoritan 0:14bd24b5a77f 127 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 128 unsigned char seq;
komoritan 0:14bd24b5a77f 129 }tagGEN_FW_VER_GET_REQ_T;
komoritan 0:14bd24b5a77f 130
komoritan 0:14bd24b5a77f 131 /** SNIC_INIT_REQ */
komoritan 0:14bd24b5a77f 132 typedef struct
komoritan 0:14bd24b5a77f 133 {
komoritan 0:14bd24b5a77f 134 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 135 unsigned char seq;
komoritan 0:14bd24b5a77f 136 unsigned char buf_size[2];
komoritan 0:14bd24b5a77f 137 }tagSNIC_INIT_REQ_T;
komoritan 0:14bd24b5a77f 138
komoritan 0:14bd24b5a77f 139 /** SNIC_IP_CONFIG_REQ */
komoritan 0:14bd24b5a77f 140 typedef struct
komoritan 0:14bd24b5a77f 141 {
komoritan 0:14bd24b5a77f 142 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 143 unsigned char seq;
komoritan 0:14bd24b5a77f 144 unsigned char interface;
komoritan 0:14bd24b5a77f 145 unsigned char dhcp;
komoritan 0:14bd24b5a77f 146 }tagSNIC_IP_CONFIG_REQ_DHCP_T;
komoritan 0:14bd24b5a77f 147
komoritan 0:14bd24b5a77f 148 /** SNIC_IP_CONFIG_REQ */
komoritan 0:14bd24b5a77f 149 typedef struct
komoritan 0:14bd24b5a77f 150 {
komoritan 0:14bd24b5a77f 151 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 152 unsigned char seq;
komoritan 0:14bd24b5a77f 153 unsigned char interface;
komoritan 0:14bd24b5a77f 154 unsigned char dhcp;
komoritan 0:14bd24b5a77f 155 unsigned char ip_addr[4];
komoritan 0:14bd24b5a77f 156 unsigned char netmask[4];
komoritan 0:14bd24b5a77f 157 unsigned char gateway[4];
komoritan 0:14bd24b5a77f 158 }tagSNIC_IP_CONFIG_REQ_STATIC_T;
komoritan 0:14bd24b5a77f 159
komoritan 0:14bd24b5a77f 160 /** SNIC_TCP_CREATE_SOCKET_REQ */
komoritan 0:14bd24b5a77f 161 typedef struct
komoritan 0:14bd24b5a77f 162 {
komoritan 0:14bd24b5a77f 163 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 164 unsigned char seq;
komoritan 0:14bd24b5a77f 165 unsigned char bind;
komoritan 0:14bd24b5a77f 166 unsigned char local_addr[4];
komoritan 0:14bd24b5a77f 167 unsigned char local_port[2];
komoritan 0:14bd24b5a77f 168 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
komoritan 0:14bd24b5a77f 169
komoritan 0:14bd24b5a77f 170 /** SNIC_CLOSE_SOCKET_REQ */
komoritan 0:14bd24b5a77f 171 typedef struct
komoritan 0:14bd24b5a77f 172 {
komoritan 0:14bd24b5a77f 173 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 174 unsigned char seq;
komoritan 0:14bd24b5a77f 175 unsigned char socket_id;
komoritan 0:14bd24b5a77f 176 }tagSNIC_CLOSE_SOCKET_REQ_T;
komoritan 0:14bd24b5a77f 177
komoritan 0:14bd24b5a77f 178 /** SNIC_TCP_SEND_FROM_SOCKET_REQ */
komoritan 0:14bd24b5a77f 179 typedef struct
komoritan 0:14bd24b5a77f 180 {
komoritan 0:14bd24b5a77f 181 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 182 unsigned char seq;
komoritan 0:14bd24b5a77f 183 unsigned char socket_id;
komoritan 0:14bd24b5a77f 184 unsigned char option;
komoritan 0:14bd24b5a77f 185 unsigned char payload_len[2];
komoritan 0:14bd24b5a77f 186 }tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T;
komoritan 0:14bd24b5a77f 187
komoritan 0:14bd24b5a77f 188 /** SNIC_TCP_CREATE_CONNECTION_REQ */
komoritan 0:14bd24b5a77f 189 typedef struct
komoritan 0:14bd24b5a77f 190 {
komoritan 0:14bd24b5a77f 191 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 192 unsigned char seq;
komoritan 0:14bd24b5a77f 193 unsigned char socket_id;
komoritan 0:14bd24b5a77f 194 unsigned char recv_bufsize[2];
komoritan 0:14bd24b5a77f 195 unsigned char max_client;
komoritan 0:14bd24b5a77f 196 }tagSNIC_TCP_CREATE_CONNECTION_REQ_T;
komoritan 0:14bd24b5a77f 197
komoritan 0:14bd24b5a77f 198 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
komoritan 0:14bd24b5a77f 199 typedef struct
komoritan 0:14bd24b5a77f 200 {
komoritan 0:14bd24b5a77f 201 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 202 unsigned char seq;
komoritan 0:14bd24b5a77f 203 unsigned char socket_id;
komoritan 0:14bd24b5a77f 204 unsigned char remote_addr[4];
komoritan 0:14bd24b5a77f 205 unsigned char remote_port[2];
komoritan 0:14bd24b5a77f 206 unsigned char recv_bufsize[2];
komoritan 0:14bd24b5a77f 207 unsigned char timeout;
komoritan 0:14bd24b5a77f 208 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
komoritan 0:14bd24b5a77f 209
komoritan 0:14bd24b5a77f 210 /** SNIC_UDP_SIMPLE_SEND_REQ */
komoritan 0:14bd24b5a77f 211 typedef struct
komoritan 0:14bd24b5a77f 212 {
komoritan 0:14bd24b5a77f 213 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 214 unsigned char seq;
komoritan 0:14bd24b5a77f 215 unsigned char remote_ip[4];
komoritan 0:14bd24b5a77f 216 unsigned char remote_port[2];
komoritan 0:14bd24b5a77f 217 unsigned char payload_len[2];
komoritan 0:14bd24b5a77f 218 }tagSNIC_UDP_SIMPLE_SEND_REQ_T;
komoritan 0:14bd24b5a77f 219
komoritan 0:14bd24b5a77f 220 /** SNIC_UDP_CREATE_SOCKET_REQ */
komoritan 0:14bd24b5a77f 221 typedef struct
komoritan 0:14bd24b5a77f 222 {
komoritan 0:14bd24b5a77f 223 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 224 unsigned char seq;
komoritan 0:14bd24b5a77f 225 unsigned char bind;
komoritan 0:14bd24b5a77f 226 unsigned char local_addr[4];
komoritan 0:14bd24b5a77f 227 unsigned char local_port[2];
komoritan 0:14bd24b5a77f 228 }tagSNIC_UDP_CREATE_SOCKET_REQ_T;
komoritan 0:14bd24b5a77f 229
komoritan 0:14bd24b5a77f 230 /** SNIC_UDP_CREATE_SOCKET_REQ */
komoritan 0:14bd24b5a77f 231 typedef struct
komoritan 0:14bd24b5a77f 232 {
komoritan 0:14bd24b5a77f 233 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 234 unsigned char seq;
komoritan 0:14bd24b5a77f 235 unsigned char bind;
komoritan 0:14bd24b5a77f 236 }tagSNIC_UDP_CREATE_SOCKET_REQ_CLIENT_T;
komoritan 0:14bd24b5a77f 237
komoritan 0:14bd24b5a77f 238 /** SNIC_UDP_SEND_FROM_SOCKET_REQ */
komoritan 0:14bd24b5a77f 239 typedef struct
komoritan 0:14bd24b5a77f 240 {
komoritan 0:14bd24b5a77f 241 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 242 unsigned char seq;
komoritan 0:14bd24b5a77f 243 unsigned char remote_ip[4];
komoritan 0:14bd24b5a77f 244 unsigned char remote_port[2];
komoritan 0:14bd24b5a77f 245 unsigned char socket_id;
komoritan 0:14bd24b5a77f 246 unsigned char connection_mode;
komoritan 0:14bd24b5a77f 247 unsigned char payload_len[2];
komoritan 0:14bd24b5a77f 248 }tagSNIC_UDP_SEND_FROM_SOCKET_REQ_T;
komoritan 0:14bd24b5a77f 249
komoritan 0:14bd24b5a77f 250 /** SNIC_UDP_START_RECV_REQ */
komoritan 0:14bd24b5a77f 251 typedef struct
komoritan 0:14bd24b5a77f 252 {
komoritan 0:14bd24b5a77f 253 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 254 unsigned char seq;
komoritan 0:14bd24b5a77f 255 unsigned char socket_id;
komoritan 0:14bd24b5a77f 256 unsigned char recv_bufsize[2];
komoritan 0:14bd24b5a77f 257 }tagSNIC_UDP_START_RECV_REQ_T;
komoritan 0:14bd24b5a77f 258
komoritan 0:14bd24b5a77f 259 /** SNIC_GET_DHCP_INFO_REQ */
komoritan 0:14bd24b5a77f 260 typedef struct
komoritan 0:14bd24b5a77f 261 {
komoritan 0:14bd24b5a77f 262 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 263 unsigned char seq;
komoritan 0:14bd24b5a77f 264 unsigned char interface;
komoritan 0:14bd24b5a77f 265 }tagSNIC_GET_DHCP_INFO_REQ_T;
komoritan 0:14bd24b5a77f 266
komoritan 0:14bd24b5a77f 267 /** WIFI_ON_REQ Command */
komoritan 0:14bd24b5a77f 268 typedef struct
komoritan 0:14bd24b5a77f 269 {
komoritan 0:14bd24b5a77f 270 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 271 unsigned char seq;
komoritan 0:14bd24b5a77f 272 char country[COUNTRYC_CODE_LENTH];
komoritan 0:14bd24b5a77f 273 }tagWIFI_ON_REQ_T;
komoritan 0:14bd24b5a77f 274
komoritan 0:14bd24b5a77f 275 /** WIFI_OFF_REQ Command */
komoritan 0:14bd24b5a77f 276 typedef struct
komoritan 0:14bd24b5a77f 277 {
komoritan 0:14bd24b5a77f 278 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 279 unsigned char seq;
komoritan 0:14bd24b5a77f 280 }tagWIFI_OFF_REQ_T;
komoritan 0:14bd24b5a77f 281
komoritan 0:14bd24b5a77f 282 /** WIFI_DISCONNECT_REQ Command */
komoritan 0:14bd24b5a77f 283 typedef struct
komoritan 0:14bd24b5a77f 284 {
komoritan 0:14bd24b5a77f 285 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 286 unsigned char seq;
komoritan 0:14bd24b5a77f 287 }tagWIFI_DISCONNECT_REQ_T;
komoritan 0:14bd24b5a77f 288
komoritan 0:14bd24b5a77f 289 /** WIFI_GET_STA_RSSI_REQ Command */
komoritan 0:14bd24b5a77f 290 typedef struct
komoritan 0:14bd24b5a77f 291 {
komoritan 0:14bd24b5a77f 292 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 293 unsigned char seq;
komoritan 0:14bd24b5a77f 294 }tagWIFI_GET_STA_RSSI_REQ_T;
komoritan 0:14bd24b5a77f 295
komoritan 0:14bd24b5a77f 296 /** WIFI_SCAN_REQ Command */
komoritan 0:14bd24b5a77f 297 typedef struct
komoritan 0:14bd24b5a77f 298 {
komoritan 0:14bd24b5a77f 299 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 300 unsigned char seq;
komoritan 0:14bd24b5a77f 301 unsigned char scan_type;
komoritan 0:14bd24b5a77f 302 unsigned char bss_type;
komoritan 0:14bd24b5a77f 303 unsigned char bssid[BSSID_MAC_LENTH];
komoritan 0:14bd24b5a77f 304 unsigned char chan_list;
komoritan 0:14bd24b5a77f 305 unsigned char ssid[SSID_MAX_LENGTH+1];
komoritan 0:14bd24b5a77f 306 }tagWIFI_SCAN_REQ_T;
komoritan 0:14bd24b5a77f 307
komoritan 0:14bd24b5a77f 308 /** WIFI_GET_STATUS_REQ Command */
komoritan 0:14bd24b5a77f 309 typedef struct
komoritan 0:14bd24b5a77f 310 {
komoritan 0:14bd24b5a77f 311 unsigned char cmd_sid;
komoritan 0:14bd24b5a77f 312 unsigned char seq;
komoritan 0:14bd24b5a77f 313 unsigned char interface;
komoritan 0:14bd24b5a77f 314 }tagWIFI_GET_STATUS_REQ_T;
komoritan 0:14bd24b5a77f 315
komoritan 0:14bd24b5a77f 316 /** Get buffer for command from memory pool.
komoritan 0:14bd24b5a77f 317 @return Pointer of buffer
komoritan 0:14bd24b5a77f 318 */
komoritan 0:14bd24b5a77f 319 tagMEMPOOL_BLOCK_T *allocCmdBuf();
komoritan 0:14bd24b5a77f 320
komoritan 0:14bd24b5a77f 321 /** Release buffer to memory pool.
komoritan 0:14bd24b5a77f 322 @param buf_p Pointer of buffer
komoritan 0:14bd24b5a77f 323 */
komoritan 0:14bd24b5a77f 324 void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p );
komoritan 0:14bd24b5a77f 325
komoritan 0:14bd24b5a77f 326 /** Get buffer for command from memory pool.
komoritan 0:14bd24b5a77f 327 @return Pointer of buffer
komoritan 0:14bd24b5a77f 328 */
komoritan 0:14bd24b5a77f 329 tagMEMPOOL_BLOCK_T *allocUartRcvBuf();
komoritan 0:14bd24b5a77f 330
komoritan 0:14bd24b5a77f 331 /** Release buffer to memory pool.
komoritan 0:14bd24b5a77f 332 @param buf_p Pointer of buffer
komoritan 0:14bd24b5a77f 333 */
komoritan 0:14bd24b5a77f 334 void freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p );
komoritan 0:14bd24b5a77f 335
komoritan 0:14bd24b5a77f 336 /** Module Reset
komoritan 0:14bd24b5a77f 337 */
komoritan 0:14bd24b5a77f 338 int resetModule( PinName reset );
komoritan 0:14bd24b5a77f 339
komoritan 0:14bd24b5a77f 340 /** Initialize UART
komoritan 0:14bd24b5a77f 341 */
komoritan 0:14bd24b5a77f 342 int initUart( PinName tx, PinName rx, int baud );
komoritan 0:14bd24b5a77f 343
komoritan 0:14bd24b5a77f 344 /** Send data to UART
komoritan 0:14bd24b5a77f 345 @param len Length of send data
komoritan 0:14bd24b5a77f 346 @param data Pointer of send data
komoritan 0:14bd24b5a77f 347 @return 0:success/other:fail
komoritan 0:14bd24b5a77f 348 */
komoritan 0:14bd24b5a77f 349 int sendUart( unsigned int len, unsigned char *data );
komoritan 0:14bd24b5a77f 350
komoritan 0:14bd24b5a77f 351 /** Preparation of the UART command
komoritan 0:14bd24b5a77f 352 @param cmd_id UART Command ID
komoritan 0:14bd24b5a77f 353 @param cmd_sid UART Command SubID
komoritan 0:14bd24b5a77f 354 @param req_buf_p Pointer of UART request buffer
komoritan 0:14bd24b5a77f 355 @param req_buf_len Length of UART request buffer
komoritan 0:14bd24b5a77f 356 @param response_buf_p Pointer of UART response buffer
komoritan 0:14bd24b5a77f 357 @param command_p Pointer of UART command[output]
komoritan 0:14bd24b5a77f 358 @return Length of UART command.
komoritan 0:14bd24b5a77f 359 */
komoritan 0:14bd24b5a77f 360 unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
komoritan 0:14bd24b5a77f 361 , unsigned char *req_buf_p, unsigned int req_buf_len
komoritan 0:14bd24b5a77f 362 , unsigned char *response_buf_p, unsigned char *command_p );
komoritan 0:14bd24b5a77f 363
komoritan 0:14bd24b5a77f 364 /**
komoritan 0:14bd24b5a77f 365 Get pointer of connection information.
komoritan 0:14bd24b5a77f 366 @param socket_id Socket ID
komoritan 0:14bd24b5a77f 367 @return The pointer of connection information
komoritan 0:14bd24b5a77f 368 */
komoritan 0:14bd24b5a77f 369 C_SNIC_Core::tagCONNECT_INFO_T *getConnectInfo( int socket_id );
komoritan 0:14bd24b5a77f 370
komoritan 0:14bd24b5a77f 371 /**
komoritan 0:14bd24b5a77f 372 Get pointer of UDP Recv information.
komoritan 0:14bd24b5a77f 373 @param socket_id Socket ID
komoritan 0:14bd24b5a77f 374 @return The pointer of UDP Recv information
komoritan 0:14bd24b5a77f 375 */
komoritan 0:14bd24b5a77f 376 C_SNIC_Core::tagUDP_RECVINFO_T *getUdpRecvInfo( int socket_id );
komoritan 0:14bd24b5a77f 377
komoritan 0:14bd24b5a77f 378 /**
komoritan 0:14bd24b5a77f 379 Get pointer of the instance of C_SNIC_UartCommandManager.
komoritan 0:14bd24b5a77f 380 @return The pointer of the instance of C_SNIC_UartCommandManager.
komoritan 0:14bd24b5a77f 381 */
komoritan 0:14bd24b5a77f 382 C_SNIC_UartCommandManager *getUartCommand();
komoritan 0:14bd24b5a77f 383
komoritan 0:14bd24b5a77f 384 unsigned char *getCommandBuf();
komoritan 0:14bd24b5a77f 385
komoritan 0:14bd24b5a77f 386 /** Get an instance of the C_SNIC_Core class.
komoritan 0:14bd24b5a77f 387 @return Instance of the C_SNIC_Core class
komoritan 0:14bd24b5a77f 388 @note Please do not create an instance in the default constructor this class.
komoritan 0:14bd24b5a77f 389 Please use this method when you want to get an instance.
komoritan 0:14bd24b5a77f 390 */
komoritan 0:14bd24b5a77f 391 static C_SNIC_Core *getInstance();
komoritan 0:14bd24b5a77f 392
komoritan 0:14bd24b5a77f 393 /** Mutex lock of API calls
komoritan 0:14bd24b5a77f 394 */
komoritan 0:14bd24b5a77f 395 void lockAPI( void );
komoritan 0:14bd24b5a77f 396
komoritan 0:14bd24b5a77f 397 /** Mutex unlock of API calls
komoritan 0:14bd24b5a77f 398 */
komoritan 0:14bd24b5a77f 399 void unlockAPI( void );
komoritan 0:14bd24b5a77f 400
komoritan 0:14bd24b5a77f 401 private:
komoritan 0:14bd24b5a77f 402 static C_SNIC_Core *mInstance_p;
komoritan 0:14bd24b5a77f 403 Thread *mUartRecvThread_p;
komoritan 0:14bd24b5a77f 404 Thread *mUartRecvDispatchThread_p;
komoritan 0:14bd24b5a77f 405 RawSerial *mUart_p;
komoritan 0:14bd24b5a77f 406 Mutex mUartMutex;
komoritan 0:14bd24b5a77f 407 Mutex mAPIMutex;
komoritan 0:14bd24b5a77f 408
komoritan 0:14bd24b5a77f 409 // DigitalInOut mModuleReset;
komoritan 0:14bd24b5a77f 410 C_SNIC_UartCommandManager *mUartCommand_p;
komoritan 0:14bd24b5a77f 411
komoritan 0:14bd24b5a77f 412 CircBuffer<char> *mUartRecvBuf_p; // UART RecvBuffer
komoritan 0:14bd24b5a77f 413
komoritan 0:14bd24b5a77f 414 /** Socket buffer */
komoritan 0:14bd24b5a77f 415 tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1];
komoritan 0:14bd24b5a77f 416
komoritan 0:14bd24b5a77f 417 /** UDP Information */
komoritan 0:14bd24b5a77f 418 tagUDP_RECVINFO_T mUdpRecvInfo[MAX_SOCKET_ID+1];
komoritan 0:14bd24b5a77f 419
komoritan 0:14bd24b5a77f 420 /** Constructor
komoritan 0:14bd24b5a77f 421 */
komoritan 0:14bd24b5a77f 422 C_SNIC_Core();
komoritan 0:14bd24b5a77f 423
komoritan 0:14bd24b5a77f 424 virtual ~C_SNIC_Core();
komoritan 0:14bd24b5a77f 425
komoritan 0:14bd24b5a77f 426 static void uartRecvCallback( void );
komoritan 0:14bd24b5a77f 427 /** Receiving thread of UART
komoritan 0:14bd24b5a77f 428 */
komoritan 0:14bd24b5a77f 429 static void uartRecvDispatchThread( void const *args_p );
komoritan 0:14bd24b5a77f 430 };
komoritan 0:14bd24b5a77f 431
komoritan 0:14bd24b5a77f 432 #endif