Websocket_Sample for MurataTypeYD

Dependencies:   mbed picojson

Committer:
komoritan
Date:
Thu Mar 12 12:14:38 2015 +0000
Revision:
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_UART_COMMAND_MANAGER_H_
komoritan 0:14bd24b5a77f 20 #define _SNIC_UART_COMMAND_MANAGER_H_
komoritan 0:14bd24b5a77f 21 #include "MurataObject.h"
komoritan 0:14bd24b5a77f 22 #include "mbed.h"
komoritan 0:14bd24b5a77f 23 #include "rtos.h"
komoritan 0:14bd24b5a77f 24
komoritan 0:14bd24b5a77f 25 /** Max length of SSID */
komoritan 0:14bd24b5a77f 26 #define SSID_MAX_LENGTH 32
komoritan 0:14bd24b5a77f 27 /** Max length of BSSID */
komoritan 0:14bd24b5a77f 28 #define BSSID_MAC_LENTH 6
komoritan 0:14bd24b5a77f 29 /** Length of Country code */
komoritan 0:14bd24b5a77f 30 #define COUNTRYC_CODE_LENTH 2
komoritan 0:14bd24b5a77f 31
komoritan 0:14bd24b5a77f 32 /** Wait signal ID of UART command */
komoritan 0:14bd24b5a77f 33 #define UART_COMMAND_SIGNAL 0x00000001
komoritan 0:14bd24b5a77f 34 /** Timeout of UART command wait(ms)*/
komoritan 0:14bd24b5a77f 35 #define UART_COMMAND_WAIT_TIMEOUT 10000
komoritan 0:14bd24b5a77f 36
komoritan 0:14bd24b5a77f 37 /** Scan result structure used by scanresults handler
komoritan 0:14bd24b5a77f 38 */
komoritan 0:14bd24b5a77f 39 typedef struct {
komoritan 0:14bd24b5a77f 40 bool is_complete;
komoritan 0:14bd24b5a77f 41 /** Channel */
komoritan 0:14bd24b5a77f 42 unsigned char channel;
komoritan 0:14bd24b5a77f 43 /** RSSI */
komoritan 0:14bd24b5a77f 44 signed char rssi;
komoritan 0:14bd24b5a77f 45 /** Security type */
komoritan 0:14bd24b5a77f 46 unsigned char security;
komoritan 0:14bd24b5a77f 47 /** BSSID */
komoritan 0:14bd24b5a77f 48 unsigned char bssid[BSSID_MAC_LENTH];
komoritan 0:14bd24b5a77f 49 /** Network type */
komoritan 0:14bd24b5a77f 50 unsigned char network_type;
komoritan 0:14bd24b5a77f 51 /** Max data rate */
komoritan 0:14bd24b5a77f 52 unsigned char max_rate;
komoritan 0:14bd24b5a77f 53 /** SSID */
komoritan 0:14bd24b5a77f 54 char ssid[SSID_MAX_LENGTH+1];
komoritan 0:14bd24b5a77f 55 }tagSCAN_RESULT_T;
komoritan 0:14bd24b5a77f 56
komoritan 0:14bd24b5a77f 57 /** Internal class for managing the SNIC UART command.
komoritan 0:14bd24b5a77f 58 */
komoritan 0:14bd24b5a77f 59 class C_SNIC_UartCommandManager: public C_MurataObject
komoritan 0:14bd24b5a77f 60 {
komoritan 0:14bd24b5a77f 61 friend class C_SNIC_Core;
komoritan 0:14bd24b5a77f 62 friend class C_SNIC_WifiInterface;
komoritan 0:14bd24b5a77f 63 friend class TCPSocketConnection;
komoritan 0:14bd24b5a77f 64 friend class TCPSocketServer;
komoritan 0:14bd24b5a77f 65 friend class UDPSocket;
komoritan 0:14bd24b5a77f 66 friend class Socket;
komoritan 0:14bd24b5a77f 67
komoritan 0:14bd24b5a77f 68 private:
komoritan 0:14bd24b5a77f 69 virtual ~C_SNIC_UartCommandManager();
komoritan 0:14bd24b5a77f 70
komoritan 0:14bd24b5a77f 71 /** Set Command ID
komoritan 0:14bd24b5a77f 72 @param cmd_id Command ID
komoritan 0:14bd24b5a77f 73 */
komoritan 0:14bd24b5a77f 74 void setCommandID( unsigned char cmd_id );
komoritan 0:14bd24b5a77f 75
komoritan 0:14bd24b5a77f 76 /** Get Command ID
komoritan 0:14bd24b5a77f 77 @return Command ID
komoritan 0:14bd24b5a77f 78 */
komoritan 0:14bd24b5a77f 79 unsigned char getCommandID();
komoritan 0:14bd24b5a77f 80
komoritan 0:14bd24b5a77f 81 /** Set Command SubID
komoritan 0:14bd24b5a77f 82 @param cmd_sid Command Sub ID
komoritan 0:14bd24b5a77f 83 */
komoritan 0:14bd24b5a77f 84 void setCommandSID( unsigned char cmd_sid );
komoritan 0:14bd24b5a77f 85
komoritan 0:14bd24b5a77f 86 /** Get Command SubID
komoritan 0:14bd24b5a77f 87 @return Command Sub ID
komoritan 0:14bd24b5a77f 88 */
komoritan 0:14bd24b5a77f 89 unsigned char getCommandSID();
komoritan 0:14bd24b5a77f 90
komoritan 0:14bd24b5a77f 91 /** Set Command status
komoritan 0:14bd24b5a77f 92 @param status Command status
komoritan 0:14bd24b5a77f 93 */
komoritan 0:14bd24b5a77f 94 void setCommandStatus( unsigned char status );
komoritan 0:14bd24b5a77f 95
komoritan 0:14bd24b5a77f 96 /** Get Command status
komoritan 0:14bd24b5a77f 97 @return Command status
komoritan 0:14bd24b5a77f 98 */
komoritan 0:14bd24b5a77f 99 unsigned char getCommandStatus();
komoritan 0:14bd24b5a77f 100
komoritan 0:14bd24b5a77f 101 /** Set Response buffer
komoritan 0:14bd24b5a77f 102 @param buf_p Pointer of response buffer
komoritan 0:14bd24b5a77f 103 */
komoritan 0:14bd24b5a77f 104 void setResponseBuf( unsigned char *buf_p );
komoritan 0:14bd24b5a77f 105
komoritan 0:14bd24b5a77f 106 /** Get Response buffer
komoritan 0:14bd24b5a77f 107 @return Pointer of response buffer
komoritan 0:14bd24b5a77f 108 */
komoritan 0:14bd24b5a77f 109 unsigned char *getResponseBuf();
komoritan 0:14bd24b5a77f 110
komoritan 0:14bd24b5a77f 111 /** Set scan result callback hander
komoritan 0:14bd24b5a77f 112 @param handler_p Pointer of callback function
komoritan 0:14bd24b5a77f 113 */
komoritan 0:14bd24b5a77f 114 void setScanResultHandler( void (*handler_p)(tagSCAN_RESULT_T *scan_result) );
komoritan 0:14bd24b5a77f 115
komoritan 0:14bd24b5a77f 116 void bufferredPacket( unsigned char *payload_p, int payload_len );
komoritan 0:14bd24b5a77f 117
komoritan 0:14bd24b5a77f 118 void bufferredUDPPacket( unsigned char *payload_p, int payload_len );
komoritan 0:14bd24b5a77f 119
komoritan 0:14bd24b5a77f 120 void scanResultIndicate( unsigned char *payload_p, int payload_len );
komoritan 0:14bd24b5a77f 121
komoritan 0:14bd24b5a77f 122 void connectedTCPClient( unsigned char *payload_p, int payload_len );
komoritan 0:14bd24b5a77f 123
komoritan 0:14bd24b5a77f 124 /** Checks in the command which is waiting from Command ID and Sub ID.
komoritan 0:14bd24b5a77f 125 @param command_id Command ID
komoritan 0:14bd24b5a77f 126 @param payload_p Command payload
komoritan 0:14bd24b5a77f 127 @return true: Waiting command / false: Not waiting command
komoritan 0:14bd24b5a77f 128 */
komoritan 0:14bd24b5a77f 129 bool isWaitingCommand( unsigned int command_id, unsigned char *payload_p );
komoritan 0:14bd24b5a77f 130
komoritan 0:14bd24b5a77f 131 int wait();
komoritan 0:14bd24b5a77f 132
komoritan 0:14bd24b5a77f 133 int signal();
komoritan 0:14bd24b5a77f 134
komoritan 0:14bd24b5a77f 135 private:
komoritan 0:14bd24b5a77f 136 /** Command request thread ID */
komoritan 0:14bd24b5a77f 137 osThreadId mCommandThreadID;
komoritan 0:14bd24b5a77f 138 /** Command ID */
komoritan 0:14bd24b5a77f 139 unsigned char mCommandID;
komoritan 0:14bd24b5a77f 140 /** Command SubID */
komoritan 0:14bd24b5a77f 141 unsigned char mCommandSID;
komoritan 0:14bd24b5a77f 142 /** Status of command response */
komoritan 0:14bd24b5a77f 143 unsigned char mCommandStatus;
komoritan 0:14bd24b5a77f 144 /** ResponseData of command response */
komoritan 0:14bd24b5a77f 145 unsigned char *mResponseBuf_p;
komoritan 0:14bd24b5a77f 146 /** Scan result handler */
komoritan 0:14bd24b5a77f 147 void (*mScanResultHandler_p)(tagSCAN_RESULT_T *scan_result);
komoritan 0:14bd24b5a77f 148 };
komoritan 0:14bd24b5a77f 149
komoritan 0:14bd24b5a77f 150 #endif