Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SNIC-httpclient-example SNIC-ntpclient-example
Fork of SNICInterface by
SNIC/SNICwifi.h@11:c49007d49e52, 2014-03-19 (annotated)
- Committer:
- kishino
- Date:
- Wed Mar 19 01:48:37 2014 +0000
- Revision:
- 11:c49007d49e52
- Parent:
- SNICwifi/SNICwifi.h@10:49ffd373066b
C_SNICwifi was modified to singleton class.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kishino | 8:50d2509479cd | 1 | #ifndef _SNIC_WIFI_H_ |
| kishino | 8:50d2509479cd | 2 | #define _SNIC_WIFI_H_ |
| kishino | 8:50d2509479cd | 3 | |
| kishino | 8:50d2509479cd | 4 | #include "mbed.h" |
| kishino | 8:50d2509479cd | 5 | #include "rtos.h" |
| kishino | 8:50d2509479cd | 6 | #include "RawSerial.h" |
| kishino | 8:50d2509479cd | 7 | |
| kishino | 8:50d2509479cd | 8 | #include "SNICwifiUartCommand.h" |
| kishino | 8:50d2509479cd | 9 | //#include "CBuffer.h" |
| kishino | 8:50d2509479cd | 10 | |
| kishino | 8:50d2509479cd | 11 | namespace murata_wifi |
| kishino | 8:50d2509479cd | 12 | { |
| kishino | 10:49ffd373066b | 13 | #define UART_REQUEST_PAYLOAD_MAX 256 |
| kishino | 8:50d2509479cd | 14 | |
| kishino | 9:a98b45e766c8 | 15 | #define MEMPOOL_BLOCK_SIZE 2048 |
| kishino | 9:a98b45e766c8 | 16 | #define MEMPOOL_PAYLOAD_NUM 1 |
| kishino | 9:a98b45e766c8 | 17 | typedef struct |
| kishino | 9:a98b45e766c8 | 18 | { |
| kishino | 9:a98b45e766c8 | 19 | unsigned char buf[MEMPOOL_BLOCK_SIZE]; |
| kishino | 9:a98b45e766c8 | 20 | }tagMEMPOOL_BLOCK_T; |
| kishino | 9:a98b45e766c8 | 21 | |
| kishino | 11:c49007d49e52 | 22 | /** Wi-Fi security |
| kishino | 11:c49007d49e52 | 23 | */ |
| kishino | 11:c49007d49e52 | 24 | typedef enum SECURITY { |
| kishino | 11:c49007d49e52 | 25 | /** Securiry Open */ |
| kishino | 11:c49007d49e52 | 26 | e_SEC_OPEN = 0x00, |
| kishino | 11:c49007d49e52 | 27 | /** Securiry WEP */ |
| kishino | 11:c49007d49e52 | 28 | e_SEC_WEP = 0x01, |
| kishino | 11:c49007d49e52 | 29 | /** Securiry WPA-PSK(TKIP) */ |
| kishino | 11:c49007d49e52 | 30 | e_SEC_WPA_TKIP = 0x02, |
| kishino | 11:c49007d49e52 | 31 | /** Securiry WPA2-PSK(AES) */ |
| kishino | 11:c49007d49e52 | 32 | e_SEC_WPA2_AES = 0x04, |
| kishino | 11:c49007d49e52 | 33 | /** Securiry WPA2-PSK(TKIP/AES) */ |
| kishino | 11:c49007d49e52 | 34 | e_SEC_WPA2_MIXED = 0x06, |
| kishino | 11:c49007d49e52 | 35 | /** Securiry WPA-PSK(AES) */ |
| kishino | 11:c49007d49e52 | 36 | e_SEC_WPA_AES = 0x07 |
| kishino | 11:c49007d49e52 | 37 | }E_SECURITY; |
| kishino | 11:c49007d49e52 | 38 | |
| kishino | 11:c49007d49e52 | 39 | /** Wi-Fi Network type |
| kishino | 11:c49007d49e52 | 40 | */ |
| kishino | 11:c49007d49e52 | 41 | typedef enum NETWORK_TYPE { |
| kishino | 11:c49007d49e52 | 42 | /** Infrastructure */ |
| kishino | 11:c49007d49e52 | 43 | e_INFRA = 0, |
| kishino | 11:c49007d49e52 | 44 | /** Adhoc */ |
| kishino | 11:c49007d49e52 | 45 | e_ADHOC = 1 |
| kishino | 11:c49007d49e52 | 46 | }E_NETWORK_TYPE; |
| kishino | 11:c49007d49e52 | 47 | |
| kishino | 11:c49007d49e52 | 48 | /** Wi-Fi status |
| kishino | 11:c49007d49e52 | 49 | */ |
| kishino | 11:c49007d49e52 | 50 | typedef enum WIFI_STATUS { |
| kishino | 11:c49007d49e52 | 51 | /** Wi-Fi OFF */ |
| kishino | 11:c49007d49e52 | 52 | e_STATUS_OFF = 0, |
| kishino | 11:c49007d49e52 | 53 | /** No network */ |
| kishino | 11:c49007d49e52 | 54 | e_NO_NETWORK, |
| kishino | 11:c49007d49e52 | 55 | /** Connected to AP (STA mode) */ |
| kishino | 11:c49007d49e52 | 56 | e_STA_JOINED, |
| kishino | 11:c49007d49e52 | 57 | /** Started on AP mode */ |
| kishino | 11:c49007d49e52 | 58 | e_AP_STARTED |
| kishino | 11:c49007d49e52 | 59 | }E_WIFI_STATUS; |
| kishino | 11:c49007d49e52 | 60 | |
| kishino | 11:c49007d49e52 | 61 | /** GEN_FW_VER_GET_REQ Command */ |
| kishino | 11:c49007d49e52 | 62 | typedef struct |
| kishino | 11:c49007d49e52 | 63 | { |
| kishino | 11:c49007d49e52 | 64 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 65 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 66 | }tagGEN_FW_VER_GET_REQ_T; |
| kishino | 11:c49007d49e52 | 67 | |
| kishino | 11:c49007d49e52 | 68 | /** SNIC_INIT_REQ */ |
| kishino | 11:c49007d49e52 | 69 | typedef struct |
| kishino | 11:c49007d49e52 | 70 | { |
| kishino | 11:c49007d49e52 | 71 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 72 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 73 | unsigned short buf_size; |
| kishino | 11:c49007d49e52 | 74 | }tagSNIC_INIT_REQ_T; |
| kishino | 11:c49007d49e52 | 75 | |
| kishino | 11:c49007d49e52 | 76 | /** WIFI_ON_REQ Command */ |
| kishino | 11:c49007d49e52 | 77 | typedef struct |
| kishino | 11:c49007d49e52 | 78 | { |
| kishino | 11:c49007d49e52 | 79 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 80 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 81 | char country[COUNTRYC_CODE_LENTH]; |
| kishino | 11:c49007d49e52 | 82 | }tagWIFI_ON_REQ_T; |
| kishino | 11:c49007d49e52 | 83 | |
| kishino | 11:c49007d49e52 | 84 | /** WIFI_OFF_REQ Command */ |
| kishino | 11:c49007d49e52 | 85 | typedef struct |
| kishino | 11:c49007d49e52 | 86 | { |
| kishino | 11:c49007d49e52 | 87 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 88 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 89 | }tagWIFI_OFF_REQ_T; |
| kishino | 11:c49007d49e52 | 90 | |
| kishino | 11:c49007d49e52 | 91 | /** WIFI_DISCONNECT_REQ Command */ |
| kishino | 11:c49007d49e52 | 92 | typedef struct |
| kishino | 11:c49007d49e52 | 93 | { |
| kishino | 11:c49007d49e52 | 94 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 95 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 96 | }tagWIFI_DISCONNECT_REQ_T; |
| kishino | 11:c49007d49e52 | 97 | |
| kishino | 11:c49007d49e52 | 98 | /** WIFI_GET_STA_RSSI_REQ Command */ |
| kishino | 11:c49007d49e52 | 99 | typedef struct |
| kishino | 11:c49007d49e52 | 100 | { |
| kishino | 11:c49007d49e52 | 101 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 102 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 103 | }tagWIFI_GET_STA_RSSI_REQ_T; |
| kishino | 11:c49007d49e52 | 104 | |
| kishino | 11:c49007d49e52 | 105 | /** WIFI_GET_STATUS_REQ Command */ |
| kishino | 11:c49007d49e52 | 106 | typedef struct |
| kishino | 11:c49007d49e52 | 107 | { |
| kishino | 11:c49007d49e52 | 108 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 109 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 110 | unsigned char interface; |
| kishino | 11:c49007d49e52 | 111 | }tagWIFI_GET_STATUS_REQ_T; |
| kishino | 11:c49007d49e52 | 112 | |
| kishino | 11:c49007d49e52 | 113 | /** WIFI_SCAN_REQ Command */ |
| kishino | 11:c49007d49e52 | 114 | typedef struct |
| kishino | 11:c49007d49e52 | 115 | { |
| kishino | 11:c49007d49e52 | 116 | unsigned char cmd_sid; |
| kishino | 11:c49007d49e52 | 117 | unsigned char seq; |
| kishino | 11:c49007d49e52 | 118 | unsigned char scan_type; |
| kishino | 11:c49007d49e52 | 119 | unsigned char bss_type; |
| kishino | 11:c49007d49e52 | 120 | unsigned char bssid[BSSID_MAC_LENTH]; |
| kishino | 11:c49007d49e52 | 121 | unsigned char chan_list; |
| kishino | 11:c49007d49e52 | 122 | unsigned char ssid[SSID_MAX_LENGTH+1]; |
| kishino | 11:c49007d49e52 | 123 | }tagWIFI_SCAN_REQ_T; |
| kishino | 11:c49007d49e52 | 124 | |
| kishino | 8:50d2509479cd | 125 | /** C_SNICwifi class |
| kishino | 8:50d2509479cd | 126 | */ |
| kishino | 8:50d2509479cd | 127 | class C_SNICwifi |
| kishino | 8:50d2509479cd | 128 | { |
| kishino | 8:50d2509479cd | 129 | |
| kishino | 8:50d2509479cd | 130 | public: |
| kishino | 11:c49007d49e52 | 131 | C_SNICwifiUartCommand mUartCommand; |
| kishino | 8:50d2509479cd | 132 | |
| kishino | 9:a98b45e766c8 | 133 | /** Get buffer for command from memory pool. |
| kishino | 9:a98b45e766c8 | 134 | @return Pointer of buffer |
| kishino | 9:a98b45e766c8 | 135 | */ |
| kishino | 9:a98b45e766c8 | 136 | tagMEMPOOL_BLOCK_T *getAlocCmdBuf(); |
| kishino | 9:a98b45e766c8 | 137 | |
| kishino | 9:a98b45e766c8 | 138 | /** Release buffer to memory pool. |
| kishino | 9:a98b45e766c8 | 139 | @param buf_p Pointer of buffer |
| kishino | 9:a98b45e766c8 | 140 | */ |
| kishino | 9:a98b45e766c8 | 141 | void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ); |
| kishino | 9:a98b45e766c8 | 142 | |
| kishino | 11:c49007d49e52 | 143 | /** Initialize UART |
| kishino | 11:c49007d49e52 | 144 | */ |
| kishino | 11:c49007d49e52 | 145 | int initUart( PinName tx, PinName rx, int baud ); |
| kishino | 11:c49007d49e52 | 146 | |
| kishino | 11:c49007d49e52 | 147 | /** Send data to UART |
| kishino | 11:c49007d49e52 | 148 | @param len Length of send data |
| kishino | 11:c49007d49e52 | 149 | @param data Pointer of send data |
| kishino | 11:c49007d49e52 | 150 | @return 0:success/other:fail |
| kishino | 11:c49007d49e52 | 151 | */ |
| kishino | 11:c49007d49e52 | 152 | int sendUart( unsigned int len, unsigned char *data ); |
| kishino | 11:c49007d49e52 | 153 | |
| kishino | 10:49ffd373066b | 154 | /** Preparation of the UART command |
| kishino | 10:49ffd373066b | 155 | @param cmd_id UART Command ID |
| kishino | 10:49ffd373066b | 156 | @param cmd_sid UART Command SubID |
| kishino | 10:49ffd373066b | 157 | @param req_buf_p Pointer of UART request buffer |
| kishino | 10:49ffd373066b | 158 | @param req_buf_len Length of UART request buffer |
| kishino | 10:49ffd373066b | 159 | @param response_buf_p Pointer of UART response buffer |
| kishino | 10:49ffd373066b | 160 | @param command_p Pointer of UART command[output] |
| kishino | 10:49ffd373066b | 161 | @return Length of UART command. |
| kishino | 10:49ffd373066b | 162 | */ |
| kishino | 10:49ffd373066b | 163 | unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid |
| kishino | 10:49ffd373066b | 164 | , unsigned char *req_buf_p, unsigned int req_buf_len |
| kishino | 10:49ffd373066b | 165 | , unsigned char *response_buf_p, unsigned char *command_p ); |
| kishino | 10:49ffd373066b | 166 | |
| kishino | 11:c49007d49e52 | 167 | /** Get an instance of the C_SNICwifi class. |
| kishino | 11:c49007d49e52 | 168 | @return Instance of the C_SNICwifi class |
| kishino | 11:c49007d49e52 | 169 | @note Please do not create an instance in the default constructor this class. |
| kishino | 11:c49007d49e52 | 170 | Please use this method when you want to get an instance. |
| kishino | 11:c49007d49e52 | 171 | */ |
| kishino | 11:c49007d49e52 | 172 | static C_SNICwifi *getInstance(); |
| kishino | 8:50d2509479cd | 173 | |
| kishino | 11:c49007d49e52 | 174 | protected: |
| kishino | 8:50d2509479cd | 175 | static C_SNICwifi *mInstance_p; |
| kishino | 10:49ffd373066b | 176 | Thread *mUartRecvThread_p; |
| kishino | 11:c49007d49e52 | 177 | RawSerial *mUart_p; |
| kishino | 10:49ffd373066b | 178 | Mutex mUartMutex; |
| kishino | 8:50d2509479cd | 179 | // DigitalInOut mModuleReset; |
| kishino | 11:c49007d49e52 | 180 | |
| kishino | 11:c49007d49e52 | 181 | private: |
| kishino | 11:c49007d49e52 | 182 | /** MemoryPool for payload of UART response */ |
| kishino | 11:c49007d49e52 | 183 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload; |
| kishino | 11:c49007d49e52 | 184 | |
| kishino | 8:50d2509479cd | 185 | /** Constructor |
| kishino | 8:50d2509479cd | 186 | */ |
| kishino | 11:c49007d49e52 | 187 | C_SNICwifi(); |
| kishino | 8:50d2509479cd | 188 | |
| kishino | 8:50d2509479cd | 189 | /** Receiving thread of UART |
| kishino | 8:50d2509479cd | 190 | */ |
| kishino | 8:50d2509479cd | 191 | static void uartRecvThread( void const *args_p ); |
| kishino | 8:50d2509479cd | 192 | }; |
| kishino | 8:50d2509479cd | 193 | } |
| kishino | 8:50d2509479cd | 194 | |
| kishino | 8:50d2509479cd | 195 | #endif |
