customized SNICInterface
Fork of NySNICInterface by
SNIC/SNIC_UartCommandManager.h@41:1c1b5ad4d491, 2014-07-15 (annotated)
- Committer:
- kishino
- Date:
- Tue Jul 15 10:13:53 2014 +0000
- Revision:
- 41:1c1b5ad4d491
- Parent:
- 39:a1233ca02edf
Modified the module name of Copyright.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kishino | 39:a1233ca02edf | 1 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
kishino | 41:1c1b5ad4d491 | 2 | * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
kishino | 20:dd736d328de6 | 3 | * |
kishino | 39:a1233ca02edf | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kishino | 39:a1233ca02edf | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kishino | 39:a1233ca02edf | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kishino | 39:a1233ca02edf | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kishino | 39:a1233ca02edf | 8 | * furnished to do so, subject to the following conditions: |
kishino | 20:dd736d328de6 | 9 | * |
kishino | 39:a1233ca02edf | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kishino | 39:a1233ca02edf | 11 | * substantial portions of the Software. |
kishino | 20:dd736d328de6 | 12 | * |
kishino | 39:a1233ca02edf | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kishino | 39:a1233ca02edf | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kishino | 39:a1233ca02edf | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kishino | 39:a1233ca02edf | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kishino | 39:a1233ca02edf | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kishino | 39:a1233ca02edf | 18 | */ |
kishino | 20:dd736d328de6 | 19 | #ifndef _SNIC_UART_COMMAND_MANAGER_H_ |
kishino | 20:dd736d328de6 | 20 | #define _SNIC_UART_COMMAND_MANAGER_H_ |
kishino | 25:67183ed15708 | 21 | #include "MurataObject.h" |
kishino | 20:dd736d328de6 | 22 | #include "mbed.h" |
kishino | 20:dd736d328de6 | 23 | #include "rtos.h" |
kishino | 20:dd736d328de6 | 24 | |
kishino | 20:dd736d328de6 | 25 | /** Max length of SSID */ |
kishino | 20:dd736d328de6 | 26 | #define SSID_MAX_LENGTH 32 |
kishino | 20:dd736d328de6 | 27 | /** Max length of BSSID */ |
kishino | 20:dd736d328de6 | 28 | #define BSSID_MAC_LENTH 6 |
kishino | 20:dd736d328de6 | 29 | /** Length of Country code */ |
kishino | 20:dd736d328de6 | 30 | #define COUNTRYC_CODE_LENTH 2 |
kishino | 20:dd736d328de6 | 31 | |
kishino | 20:dd736d328de6 | 32 | /** Wait signal ID of UART command */ |
kishino | 20:dd736d328de6 | 33 | #define UART_COMMAND_SIGNAL 0x00000001 |
kishino | 20:dd736d328de6 | 34 | /** Timeout of UART command wait(ms)*/ |
kishino | 20:dd736d328de6 | 35 | #define UART_COMMAND_WAIT_TIMEOUT 10000 |
kishino | 20:dd736d328de6 | 36 | |
kishino | 23:4ff2231ff9ba | 37 | /** Scan result structure used by scanresults handler |
kishino | 20:dd736d328de6 | 38 | */ |
kishino | 20:dd736d328de6 | 39 | typedef struct { |
kishino | 20:dd736d328de6 | 40 | bool is_complete; |
kishino | 20:dd736d328de6 | 41 | /** Channel */ |
kishino | 20:dd736d328de6 | 42 | unsigned char channel; |
kishino | 20:dd736d328de6 | 43 | /** RSSI */ |
kishino | 20:dd736d328de6 | 44 | signed char rssi; |
kishino | 20:dd736d328de6 | 45 | /** Security type */ |
kishino | 20:dd736d328de6 | 46 | unsigned char security; |
kishino | 20:dd736d328de6 | 47 | /** BSSID */ |
kishino | 20:dd736d328de6 | 48 | unsigned char bssid[BSSID_MAC_LENTH]; |
kishino | 20:dd736d328de6 | 49 | /** Network type */ |
kishino | 20:dd736d328de6 | 50 | unsigned char network_type; |
kishino | 20:dd736d328de6 | 51 | /** Max data rate */ |
kishino | 20:dd736d328de6 | 52 | unsigned char max_rate; |
kishino | 20:dd736d328de6 | 53 | /** SSID */ |
kishino | 20:dd736d328de6 | 54 | char ssid[SSID_MAX_LENGTH+1]; |
kishino | 20:dd736d328de6 | 55 | }tagSCAN_RESULT_T; |
kishino | 20:dd736d328de6 | 56 | |
kishino | 23:4ff2231ff9ba | 57 | /** Internal class for managing the SNIC UART command. |
kishino | 20:dd736d328de6 | 58 | */ |
kishino | 25:67183ed15708 | 59 | class C_SNIC_UartCommandManager: public C_MurataObject |
kishino | 20:dd736d328de6 | 60 | { |
kishino | 21:dda155fe5048 | 61 | friend class C_SNIC_Core; |
kishino | 21:dda155fe5048 | 62 | friend class C_SNIC_WifiInterface; |
kishino | 21:dda155fe5048 | 63 | friend class TCPSocketConnection; |
kishino | 32:ae95309643aa | 64 | friend class TCPSocketServer; |
kishino | 33:33f1bc919486 | 65 | friend class UDPSocket; |
kishino | 21:dda155fe5048 | 66 | friend class Socket; |
kishino | 21:dda155fe5048 | 67 | |
kishino | 21:dda155fe5048 | 68 | private: |
kishino | 26:f2e1030964e4 | 69 | virtual ~C_SNIC_UartCommandManager(); |
kishino | 26:f2e1030964e4 | 70 | |
kishino | 20:dd736d328de6 | 71 | /** Set Command ID |
kishino | 20:dd736d328de6 | 72 | @param cmd_id Command ID |
kishino | 20:dd736d328de6 | 73 | */ |
kishino | 20:dd736d328de6 | 74 | void setCommandID( unsigned char cmd_id ); |
kishino | 20:dd736d328de6 | 75 | |
kishino | 20:dd736d328de6 | 76 | /** Get Command ID |
kishino | 20:dd736d328de6 | 77 | @return Command ID |
kishino | 20:dd736d328de6 | 78 | */ |
kishino | 20:dd736d328de6 | 79 | unsigned char getCommandID(); |
kishino | 20:dd736d328de6 | 80 | |
kishino | 20:dd736d328de6 | 81 | /** Set Command SubID |
kishino | 20:dd736d328de6 | 82 | @param cmd_sid Command Sub ID |
kishino | 20:dd736d328de6 | 83 | */ |
kishino | 20:dd736d328de6 | 84 | void setCommandSID( unsigned char cmd_sid ); |
kishino | 20:dd736d328de6 | 85 | |
kishino | 20:dd736d328de6 | 86 | /** Get Command SubID |
kishino | 20:dd736d328de6 | 87 | @return Command Sub ID |
kishino | 20:dd736d328de6 | 88 | */ |
kishino | 20:dd736d328de6 | 89 | unsigned char getCommandSID(); |
kishino | 20:dd736d328de6 | 90 | |
kishino | 20:dd736d328de6 | 91 | /** Set Command status |
kishino | 20:dd736d328de6 | 92 | @param status Command status |
kishino | 20:dd736d328de6 | 93 | */ |
kishino | 20:dd736d328de6 | 94 | void setCommandStatus( unsigned char status ); |
kishino | 20:dd736d328de6 | 95 | |
kishino | 20:dd736d328de6 | 96 | /** Get Command status |
kishino | 20:dd736d328de6 | 97 | @return Command status |
kishino | 20:dd736d328de6 | 98 | */ |
kishino | 20:dd736d328de6 | 99 | unsigned char getCommandStatus(); |
kishino | 20:dd736d328de6 | 100 | |
kishino | 20:dd736d328de6 | 101 | /** Set Response buffer |
kishino | 20:dd736d328de6 | 102 | @param buf_p Pointer of response buffer |
kishino | 20:dd736d328de6 | 103 | */ |
kishino | 20:dd736d328de6 | 104 | void setResponseBuf( unsigned char *buf_p ); |
kishino | 20:dd736d328de6 | 105 | |
kishino | 20:dd736d328de6 | 106 | /** Get Response buffer |
kishino | 20:dd736d328de6 | 107 | @return Pointer of response buffer |
kishino | 20:dd736d328de6 | 108 | */ |
kishino | 20:dd736d328de6 | 109 | unsigned char *getResponseBuf(); |
kishino | 20:dd736d328de6 | 110 | |
kishino | 20:dd736d328de6 | 111 | /** Set scan result callback hander |
kishino | 20:dd736d328de6 | 112 | @param handler_p Pointer of callback function |
kishino | 20:dd736d328de6 | 113 | */ |
kishino | 20:dd736d328de6 | 114 | void setScanResultHandler( void (*handler_p)(tagSCAN_RESULT_T *scan_result) ); |
kishino | 20:dd736d328de6 | 115 | |
kishino | 20:dd736d328de6 | 116 | void bufferredPacket( unsigned char *payload_p, int payload_len ); |
kishino | 20:dd736d328de6 | 117 | |
kishino | 33:33f1bc919486 | 118 | void bufferredUDPPacket( unsigned char *payload_p, int payload_len ); |
kishino | 33:33f1bc919486 | 119 | |
kishino | 20:dd736d328de6 | 120 | void scanResultIndicate( unsigned char *payload_p, int payload_len ); |
kishino | 20:dd736d328de6 | 121 | |
kishino | 32:ae95309643aa | 122 | void connectedTCPClient( unsigned char *payload_p, int payload_len ); |
kishino | 33:33f1bc919486 | 123 | |
kishino | 20:dd736d328de6 | 124 | /** Checks in the command which is waiting from Command ID and Sub ID. |
kishino | 20:dd736d328de6 | 125 | @param command_id Command ID |
kishino | 20:dd736d328de6 | 126 | @param payload_p Command payload |
kishino | 20:dd736d328de6 | 127 | @return true: Waiting command / false: Not waiting command |
kishino | 20:dd736d328de6 | 128 | */ |
kishino | 20:dd736d328de6 | 129 | bool isWaitingCommand( unsigned int command_id, unsigned char *payload_p ); |
kishino | 20:dd736d328de6 | 130 | |
kishino | 20:dd736d328de6 | 131 | int wait(); |
kishino | 20:dd736d328de6 | 132 | |
kishino | 20:dd736d328de6 | 133 | int signal(); |
kishino | 20:dd736d328de6 | 134 | |
kishino | 20:dd736d328de6 | 135 | private: |
kishino | 20:dd736d328de6 | 136 | /** Command request thread ID */ |
kishino | 20:dd736d328de6 | 137 | osThreadId mCommandThreadID; |
kishino | 20:dd736d328de6 | 138 | /** Command ID */ |
kishino | 20:dd736d328de6 | 139 | unsigned char mCommandID; |
kishino | 20:dd736d328de6 | 140 | /** Command SubID */ |
kishino | 20:dd736d328de6 | 141 | unsigned char mCommandSID; |
kishino | 20:dd736d328de6 | 142 | /** Status of command response */ |
kishino | 20:dd736d328de6 | 143 | unsigned char mCommandStatus; |
kishino | 20:dd736d328de6 | 144 | /** ResponseData of command response */ |
kishino | 20:dd736d328de6 | 145 | unsigned char *mResponseBuf_p; |
kishino | 20:dd736d328de6 | 146 | /** Scan result handler */ |
kishino | 20:dd736d328de6 | 147 | void (*mScanResultHandler_p)(tagSCAN_RESULT_T *scan_result); |
kishino | 20:dd736d328de6 | 148 | }; |
kishino | 20:dd736d328de6 | 149 | |
kishino | 20:dd736d328de6 | 150 | #endif |