SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html
Dependents: SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more
Fork of YDwifiInterface by
SNICwifi/SNICwifi.h@10:49ffd373066b, 2014-03-18 (annotated)
- Committer:
- kishino
- Date:
- Tue Mar 18 02:57:24 2014 +0000
- Revision:
- 10:49ffd373066b
- Parent:
- 9:a98b45e766c8
[Refactoring]Created the common function for the preparation of request command of UART.
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 | 8:50d2509479cd | 22 | /** C_SNICwifi class |
| kishino | 8:50d2509479cd | 23 | */ |
| kishino | 8:50d2509479cd | 24 | class C_SNICwifi |
| kishino | 8:50d2509479cd | 25 | { |
| kishino | 8:50d2509479cd | 26 | |
| kishino | 8:50d2509479cd | 27 | public: |
| kishino | 8:50d2509479cd | 28 | /** Wi-Fi security |
| kishino | 8:50d2509479cd | 29 | */ |
| kishino | 8:50d2509479cd | 30 | typedef enum SECURITY { |
| kishino | 8:50d2509479cd | 31 | /** Securiry Open */ |
| kishino | 8:50d2509479cd | 32 | e_SEC_OPEN = 0x00, |
| kishino | 8:50d2509479cd | 33 | /** Securiry WEP */ |
| kishino | 8:50d2509479cd | 34 | e_SEC_WEP = 0x01, |
| kishino | 8:50d2509479cd | 35 | /** Securiry WPA-PSK(TKIP) */ |
| kishino | 8:50d2509479cd | 36 | e_SEC_WPA_TKIP = 0x02, |
| kishino | 8:50d2509479cd | 37 | /** Securiry WPA2-PSK(AES) */ |
| kishino | 8:50d2509479cd | 38 | e_SEC_WPA2_AES = 0x04, |
| kishino | 8:50d2509479cd | 39 | /** Securiry WPA2-PSK(TKIP/AES) */ |
| kishino | 8:50d2509479cd | 40 | e_SEC_WPA2_MIXED = 0x06, |
| kishino | 8:50d2509479cd | 41 | /** Securiry WPA-PSK(AES) */ |
| kishino | 8:50d2509479cd | 42 | e_SEC_WPA_AES = 0x07 |
| kishino | 8:50d2509479cd | 43 | }E_SECURITY; |
| kishino | 8:50d2509479cd | 44 | |
| kishino | 8:50d2509479cd | 45 | /** Wi-Fi Network type |
| kishino | 8:50d2509479cd | 46 | */ |
| kishino | 8:50d2509479cd | 47 | typedef enum NETWORK_TYPE { |
| kishino | 8:50d2509479cd | 48 | /** Infrastructure */ |
| kishino | 8:50d2509479cd | 49 | e_INFRA = 0, |
| kishino | 8:50d2509479cd | 50 | /** Adhoc */ |
| kishino | 8:50d2509479cd | 51 | e_ADHOC = 1 |
| kishino | 8:50d2509479cd | 52 | }E_NETWORK_TYPE; |
| kishino | 8:50d2509479cd | 53 | |
| kishino | 8:50d2509479cd | 54 | /** Wi-Fi status |
| kishino | 8:50d2509479cd | 55 | */ |
| kishino | 8:50d2509479cd | 56 | typedef enum WIFI_STATUS { |
| kishino | 8:50d2509479cd | 57 | /** Wi-Fi OFF */ |
| kishino | 8:50d2509479cd | 58 | e_STATUS_OFF = 0, |
| kishino | 8:50d2509479cd | 59 | /** No network */ |
| kishino | 8:50d2509479cd | 60 | e_NO_NETWORK, |
| kishino | 8:50d2509479cd | 61 | /** Connected to AP (STA mode) */ |
| kishino | 8:50d2509479cd | 62 | e_STA_JOINED, |
| kishino | 8:50d2509479cd | 63 | /** Started on AP mode */ |
| kishino | 8:50d2509479cd | 64 | e_AP_STARTED |
| kishino | 8:50d2509479cd | 65 | }E_WIFI_STATUS; |
| kishino | 8:50d2509479cd | 66 | |
| kishino | 9:a98b45e766c8 | 67 | /** Get buffer for command from memory pool. |
| kishino | 9:a98b45e766c8 | 68 | @return Pointer of buffer |
| kishino | 9:a98b45e766c8 | 69 | */ |
| kishino | 9:a98b45e766c8 | 70 | tagMEMPOOL_BLOCK_T *getAlocCmdBuf(); |
| kishino | 9:a98b45e766c8 | 71 | |
| kishino | 9:a98b45e766c8 | 72 | /** Release buffer to memory pool. |
| kishino | 9:a98b45e766c8 | 73 | @param buf_p Pointer of buffer |
| kishino | 9:a98b45e766c8 | 74 | */ |
| kishino | 9:a98b45e766c8 | 75 | void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ); |
| kishino | 9:a98b45e766c8 | 76 | |
| kishino | 10:49ffd373066b | 77 | /** Preparation of the UART command |
| kishino | 10:49ffd373066b | 78 | @param cmd_id UART Command ID |
| kishino | 10:49ffd373066b | 79 | @param cmd_sid UART Command SubID |
| kishino | 10:49ffd373066b | 80 | @param req_buf_p Pointer of UART request buffer |
| kishino | 10:49ffd373066b | 81 | @param req_buf_len Length of UART request buffer |
| kishino | 10:49ffd373066b | 82 | @param response_buf_p Pointer of UART response buffer |
| kishino | 10:49ffd373066b | 83 | @param command_p Pointer of UART command[output] |
| kishino | 10:49ffd373066b | 84 | @return Length of UART command. |
| kishino | 10:49ffd373066b | 85 | */ |
| kishino | 10:49ffd373066b | 86 | unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid |
| kishino | 10:49ffd373066b | 87 | , unsigned char *req_buf_p, unsigned int req_buf_len |
| kishino | 10:49ffd373066b | 88 | , unsigned char *response_buf_p, unsigned char *command_p ); |
| kishino | 10:49ffd373066b | 89 | |
| kishino | 8:50d2509479cd | 90 | protected: |
| kishino | 8:50d2509479cd | 91 | /** GEN_FW_VER_GET_REQ Command */ |
| kishino | 8:50d2509479cd | 92 | typedef struct |
| kishino | 8:50d2509479cd | 93 | { |
| kishino | 8:50d2509479cd | 94 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 95 | unsigned char seq; |
| kishino | 8:50d2509479cd | 96 | }tagGEN_FW_VER_GET_REQ_T; |
| kishino | 8:50d2509479cd | 97 | |
| kishino | 8:50d2509479cd | 98 | /** SNIC_INIT_REQ */ |
| kishino | 8:50d2509479cd | 99 | typedef struct |
| kishino | 8:50d2509479cd | 100 | { |
| kishino | 8:50d2509479cd | 101 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 102 | unsigned char seq; |
| kishino | 8:50d2509479cd | 103 | unsigned short buf_size; |
| kishino | 8:50d2509479cd | 104 | }tagSNIC_INIT_REQ_T; |
| kishino | 8:50d2509479cd | 105 | |
| kishino | 8:50d2509479cd | 106 | /** WIFI_ON_REQ Command */ |
| kishino | 8:50d2509479cd | 107 | typedef struct |
| kishino | 8:50d2509479cd | 108 | { |
| kishino | 8:50d2509479cd | 109 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 110 | unsigned char seq; |
| kishino | 8:50d2509479cd | 111 | char country[COUNTRYC_CODE_LENTH]; |
| kishino | 8:50d2509479cd | 112 | }tagWIFI_ON_REQ_T; |
| kishino | 8:50d2509479cd | 113 | |
| kishino | 8:50d2509479cd | 114 | /** WIFI_OFF_REQ Command */ |
| kishino | 8:50d2509479cd | 115 | typedef struct |
| kishino | 8:50d2509479cd | 116 | { |
| kishino | 8:50d2509479cd | 117 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 118 | unsigned char seq; |
| kishino | 8:50d2509479cd | 119 | }tagWIFI_OFF_REQ_T; |
| kishino | 8:50d2509479cd | 120 | |
| kishino | 8:50d2509479cd | 121 | /** WIFI_DISCONNECT_REQ Command */ |
| kishino | 8:50d2509479cd | 122 | typedef struct |
| kishino | 8:50d2509479cd | 123 | { |
| kishino | 8:50d2509479cd | 124 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 125 | unsigned char seq; |
| kishino | 8:50d2509479cd | 126 | }tagWIFI_DISCONNECT_REQ_T; |
| kishino | 8:50d2509479cd | 127 | |
| kishino | 8:50d2509479cd | 128 | /** WIFI_GET_STA_RSSI_REQ Command */ |
| kishino | 8:50d2509479cd | 129 | typedef struct |
| kishino | 8:50d2509479cd | 130 | { |
| kishino | 8:50d2509479cd | 131 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 132 | unsigned char seq; |
| kishino | 8:50d2509479cd | 133 | }tagWIFI_GET_STA_RSSI_REQ_T; |
| kishino | 8:50d2509479cd | 134 | |
| kishino | 8:50d2509479cd | 135 | /** WIFI_GET_STATUS_REQ Command */ |
| kishino | 8:50d2509479cd | 136 | typedef struct |
| kishino | 8:50d2509479cd | 137 | { |
| kishino | 8:50d2509479cd | 138 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 139 | unsigned char seq; |
| kishino | 8:50d2509479cd | 140 | unsigned char interface; |
| kishino | 8:50d2509479cd | 141 | }tagWIFI_GET_STATUS_REQ_T; |
| kishino | 8:50d2509479cd | 142 | |
| kishino | 8:50d2509479cd | 143 | /** WIFI_SCAN_REQ Command */ |
| kishino | 8:50d2509479cd | 144 | typedef struct |
| kishino | 8:50d2509479cd | 145 | { |
| kishino | 8:50d2509479cd | 146 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 147 | unsigned char seq; |
| kishino | 8:50d2509479cd | 148 | unsigned char scan_type; |
| kishino | 8:50d2509479cd | 149 | unsigned char bss_type; |
| kishino | 8:50d2509479cd | 150 | unsigned char bssid[BSSID_MAC_LENTH]; |
| kishino | 8:50d2509479cd | 151 | unsigned char chan_list; |
| kishino | 8:50d2509479cd | 152 | unsigned char ssid[SSID_MAX_LENGTH+1]; |
| kishino | 8:50d2509479cd | 153 | }tagWIFI_SCAN_REQ_T; |
| kishino | 8:50d2509479cd | 154 | |
| kishino | 8:50d2509479cd | 155 | static C_SNICwifi *mInstance_p; |
| kishino | 10:49ffd373066b | 156 | Thread *mUartRecvThread_p; |
| kishino | 10:49ffd373066b | 157 | Mutex mUartMutex; |
| kishino | 8:50d2509479cd | 158 | // DigitalInOut mModuleReset; |
| kishino | 8:50d2509479cd | 159 | C_SNICwifiUartCommand mUartCommand; |
| kishino | 10:49ffd373066b | 160 | RawSerial mUart; |
| kishino | 8:50d2509479cd | 161 | |
| kishino | 8:50d2509479cd | 162 | /** Constructor |
| kishino | 8:50d2509479cd | 163 | * \param tx mbed pin to use for tx line of Serial interface |
| kishino | 8:50d2509479cd | 164 | * \param rx mbed pin to use for rx line of Serial interface |
| kishino | 8:50d2509479cd | 165 | * \param cts mbed pin to use for cts line of Serial interface |
| kishino | 8:50d2509479cd | 166 | * \param rts mbed pin to use for rts line of Serial interface |
| kishino | 8:50d2509479cd | 167 | * \param reset reset pin of the wifi module |
| kishino | 8:50d2509479cd | 168 | * \param alarm alarm pin of the wifi module |
| kishino | 8:50d2509479cd | 169 | * \param baud baud rate of Serial interface |
| kishino | 8:50d2509479cd | 170 | */ |
| kishino | 8:50d2509479cd | 171 | C_SNICwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud); |
| kishino | 8:50d2509479cd | 172 | |
| kishino | 8:50d2509479cd | 173 | /** Initialize UART |
| kishino | 8:50d2509479cd | 174 | */ |
| kishino | 8:50d2509479cd | 175 | int initUart(); |
| kishino | 8:50d2509479cd | 176 | |
| kishino | 8:50d2509479cd | 177 | static C_SNICwifi * getInstance() { |
| kishino | 8:50d2509479cd | 178 | return mInstance_p; |
| kishino | 8:50d2509479cd | 179 | }; |
| kishino | 8:50d2509479cd | 180 | |
| kishino | 8:50d2509479cd | 181 | /** Send data to UART |
| kishino | 8:50d2509479cd | 182 | @param len Length of send data |
| kishino | 8:50d2509479cd | 183 | @param data Pointer of send data |
| kishino | 8:50d2509479cd | 184 | @return 0:success/other:fail |
| kishino | 8:50d2509479cd | 185 | */ |
| kishino | 8:50d2509479cd | 186 | int sendUart( unsigned int len, unsigned char *data ); |
| kishino | 8:50d2509479cd | 187 | |
| kishino | 8:50d2509479cd | 188 | /** Receiving thread of UART |
| kishino | 8:50d2509479cd | 189 | */ |
| kishino | 8:50d2509479cd | 190 | static void uartRecvThread( void const *args_p ); |
| kishino | 9:a98b45e766c8 | 191 | |
| kishino | 9:a98b45e766c8 | 192 | private: |
| kishino | 9:a98b45e766c8 | 193 | /** MemoryPool for payload of UART response */ |
| kishino | 9:a98b45e766c8 | 194 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload; |
| kishino | 9:a98b45e766c8 | 195 | |
| kishino | 8:50d2509479cd | 196 | }; |
| kishino | 8:50d2509479cd | 197 | } |
| kishino | 8:50d2509479cd | 198 | |
| kishino | 8:50d2509479cd | 199 | #endif |
muRata

Murata TypeYD