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@9:a98b45e766c8, 2014-03-18 (annotated)
- Committer:
- kishino
- Date:
- Tue Mar 18 01:13:52 2014 +0000
- Revision:
- 9:a98b45e766c8
- Parent:
- 8:50d2509479cd
- Child:
- 10:49ffd373066b
[Refactoring]Updated that function for get buffer from memorypool.
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 | 8:50d2509479cd | 13 | |
| kishino | 9:a98b45e766c8 | 14 | #define MEMPOOL_BLOCK_SIZE 2048 |
| kishino | 9:a98b45e766c8 | 15 | #define MEMPOOL_PAYLOAD_NUM 1 |
| kishino | 9:a98b45e766c8 | 16 | typedef struct |
| kishino | 9:a98b45e766c8 | 17 | { |
| kishino | 9:a98b45e766c8 | 18 | unsigned char buf[MEMPOOL_BLOCK_SIZE]; |
| kishino | 9:a98b45e766c8 | 19 | }tagMEMPOOL_BLOCK_T; |
| kishino | 9:a98b45e766c8 | 20 | |
| kishino | 8:50d2509479cd | 21 | /** C_SNICwifi class |
| kishino | 8:50d2509479cd | 22 | */ |
| kishino | 8:50d2509479cd | 23 | class C_SNICwifi |
| kishino | 8:50d2509479cd | 24 | { |
| kishino | 8:50d2509479cd | 25 | |
| kishino | 8:50d2509479cd | 26 | public: |
| kishino | 8:50d2509479cd | 27 | /** Wi-Fi security |
| kishino | 8:50d2509479cd | 28 | */ |
| kishino | 8:50d2509479cd | 29 | typedef enum SECURITY { |
| kishino | 8:50d2509479cd | 30 | /** Securiry Open */ |
| kishino | 8:50d2509479cd | 31 | e_SEC_OPEN = 0x00, |
| kishino | 8:50d2509479cd | 32 | /** Securiry WEP */ |
| kishino | 8:50d2509479cd | 33 | e_SEC_WEP = 0x01, |
| kishino | 8:50d2509479cd | 34 | /** Securiry WPA-PSK(TKIP) */ |
| kishino | 8:50d2509479cd | 35 | e_SEC_WPA_TKIP = 0x02, |
| kishino | 8:50d2509479cd | 36 | /** Securiry WPA2-PSK(AES) */ |
| kishino | 8:50d2509479cd | 37 | e_SEC_WPA2_AES = 0x04, |
| kishino | 8:50d2509479cd | 38 | /** Securiry WPA2-PSK(TKIP/AES) */ |
| kishino | 8:50d2509479cd | 39 | e_SEC_WPA2_MIXED = 0x06, |
| kishino | 8:50d2509479cd | 40 | /** Securiry WPA-PSK(AES) */ |
| kishino | 8:50d2509479cd | 41 | e_SEC_WPA_AES = 0x07 |
| kishino | 8:50d2509479cd | 42 | }E_SECURITY; |
| kishino | 8:50d2509479cd | 43 | |
| kishino | 8:50d2509479cd | 44 | /** Wi-Fi Network type |
| kishino | 8:50d2509479cd | 45 | */ |
| kishino | 8:50d2509479cd | 46 | typedef enum NETWORK_TYPE { |
| kishino | 8:50d2509479cd | 47 | /** Infrastructure */ |
| kishino | 8:50d2509479cd | 48 | e_INFRA = 0, |
| kishino | 8:50d2509479cd | 49 | /** Adhoc */ |
| kishino | 8:50d2509479cd | 50 | e_ADHOC = 1 |
| kishino | 8:50d2509479cd | 51 | }E_NETWORK_TYPE; |
| kishino | 8:50d2509479cd | 52 | |
| kishino | 8:50d2509479cd | 53 | /** Wi-Fi status |
| kishino | 8:50d2509479cd | 54 | */ |
| kishino | 8:50d2509479cd | 55 | typedef enum WIFI_STATUS { |
| kishino | 8:50d2509479cd | 56 | /** Wi-Fi OFF */ |
| kishino | 8:50d2509479cd | 57 | e_STATUS_OFF = 0, |
| kishino | 8:50d2509479cd | 58 | /** No network */ |
| kishino | 8:50d2509479cd | 59 | e_NO_NETWORK, |
| kishino | 8:50d2509479cd | 60 | /** Connected to AP (STA mode) */ |
| kishino | 8:50d2509479cd | 61 | e_STA_JOINED, |
| kishino | 8:50d2509479cd | 62 | /** Started on AP mode */ |
| kishino | 8:50d2509479cd | 63 | e_AP_STARTED |
| kishino | 8:50d2509479cd | 64 | }E_WIFI_STATUS; |
| kishino | 8:50d2509479cd | 65 | |
| kishino | 9:a98b45e766c8 | 66 | /** Get buffer for command from memory pool. |
| kishino | 9:a98b45e766c8 | 67 | @return Pointer of buffer |
| kishino | 9:a98b45e766c8 | 68 | */ |
| kishino | 9:a98b45e766c8 | 69 | tagMEMPOOL_BLOCK_T *getAlocCmdBuf(); |
| kishino | 9:a98b45e766c8 | 70 | |
| kishino | 9:a98b45e766c8 | 71 | /** Release buffer to memory pool. |
| kishino | 9:a98b45e766c8 | 72 | @param buf_p Pointer of buffer |
| kishino | 9:a98b45e766c8 | 73 | */ |
| kishino | 9:a98b45e766c8 | 74 | void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ); |
| kishino | 9:a98b45e766c8 | 75 | |
| kishino | 8:50d2509479cd | 76 | protected: |
| kishino | 8:50d2509479cd | 77 | /** GEN_FW_VER_GET_REQ Command */ |
| kishino | 8:50d2509479cd | 78 | typedef struct |
| kishino | 8:50d2509479cd | 79 | { |
| kishino | 8:50d2509479cd | 80 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 81 | unsigned char seq; |
| kishino | 8:50d2509479cd | 82 | }tagGEN_FW_VER_GET_REQ_T; |
| kishino | 8:50d2509479cd | 83 | |
| kishino | 8:50d2509479cd | 84 | /** SNIC_INIT_REQ */ |
| kishino | 8:50d2509479cd | 85 | typedef struct |
| kishino | 8:50d2509479cd | 86 | { |
| kishino | 8:50d2509479cd | 87 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 88 | unsigned char seq; |
| kishino | 8:50d2509479cd | 89 | unsigned short buf_size; |
| kishino | 8:50d2509479cd | 90 | }tagSNIC_INIT_REQ_T; |
| kishino | 8:50d2509479cd | 91 | |
| kishino | 8:50d2509479cd | 92 | /** WIFI_ON_REQ Command */ |
| kishino | 8:50d2509479cd | 93 | typedef struct |
| kishino | 8:50d2509479cd | 94 | { |
| kishino | 8:50d2509479cd | 95 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 96 | unsigned char seq; |
| kishino | 8:50d2509479cd | 97 | char country[COUNTRYC_CODE_LENTH]; |
| kishino | 8:50d2509479cd | 98 | }tagWIFI_ON_REQ_T; |
| kishino | 8:50d2509479cd | 99 | |
| kishino | 8:50d2509479cd | 100 | /** WIFI_OFF_REQ Command */ |
| kishino | 8:50d2509479cd | 101 | typedef struct |
| kishino | 8:50d2509479cd | 102 | { |
| kishino | 8:50d2509479cd | 103 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 104 | unsigned char seq; |
| kishino | 8:50d2509479cd | 105 | }tagWIFI_OFF_REQ_T; |
| kishino | 8:50d2509479cd | 106 | |
| kishino | 8:50d2509479cd | 107 | /** WIFI_DISCONNECT_REQ Command */ |
| kishino | 8:50d2509479cd | 108 | typedef struct |
| kishino | 8:50d2509479cd | 109 | { |
| kishino | 8:50d2509479cd | 110 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 111 | unsigned char seq; |
| kishino | 8:50d2509479cd | 112 | }tagWIFI_DISCONNECT_REQ_T; |
| kishino | 8:50d2509479cd | 113 | |
| kishino | 8:50d2509479cd | 114 | /** WIFI_GET_STA_RSSI_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_GET_STA_RSSI_REQ_T; |
| kishino | 8:50d2509479cd | 120 | |
| kishino | 8:50d2509479cd | 121 | /** WIFI_GET_STATUS_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 | unsigned char interface; |
| kishino | 8:50d2509479cd | 127 | }tagWIFI_GET_STATUS_REQ_T; |
| kishino | 8:50d2509479cd | 128 | |
| kishino | 8:50d2509479cd | 129 | /** WIFI_SCAN_REQ Command */ |
| kishino | 8:50d2509479cd | 130 | typedef struct |
| kishino | 8:50d2509479cd | 131 | { |
| kishino | 8:50d2509479cd | 132 | unsigned char cmd_sid; |
| kishino | 8:50d2509479cd | 133 | unsigned char seq; |
| kishino | 8:50d2509479cd | 134 | unsigned char scan_type; |
| kishino | 8:50d2509479cd | 135 | unsigned char bss_type; |
| kishino | 8:50d2509479cd | 136 | unsigned char bssid[BSSID_MAC_LENTH]; |
| kishino | 8:50d2509479cd | 137 | unsigned char chan_list; |
| kishino | 8:50d2509479cd | 138 | unsigned char ssid[SSID_MAX_LENGTH+1]; |
| kishino | 8:50d2509479cd | 139 | }tagWIFI_SCAN_REQ_T; |
| kishino | 8:50d2509479cd | 140 | |
| kishino | 8:50d2509479cd | 141 | static C_SNICwifi *mInstance_p; |
| kishino | 8:50d2509479cd | 142 | Thread *mUartRecvThread_p; |
| kishino | 8:50d2509479cd | 143 | Mutex mUartMutex; |
| kishino | 8:50d2509479cd | 144 | // DigitalInOut mModuleReset; |
| kishino | 8:50d2509479cd | 145 | C_SNICwifiUartCommand mUartCommand; |
| kishino | 8:50d2509479cd | 146 | RawSerial mUart; |
| kishino | 8:50d2509479cd | 147 | |
| kishino | 8:50d2509479cd | 148 | /** Constructor |
| kishino | 8:50d2509479cd | 149 | * \param tx mbed pin to use for tx line of Serial interface |
| kishino | 8:50d2509479cd | 150 | * \param rx mbed pin to use for rx line of Serial interface |
| kishino | 8:50d2509479cd | 151 | * \param cts mbed pin to use for cts line of Serial interface |
| kishino | 8:50d2509479cd | 152 | * \param rts mbed pin to use for rts line of Serial interface |
| kishino | 8:50d2509479cd | 153 | * \param reset reset pin of the wifi module |
| kishino | 8:50d2509479cd | 154 | * \param alarm alarm pin of the wifi module |
| kishino | 8:50d2509479cd | 155 | * \param baud baud rate of Serial interface |
| kishino | 8:50d2509479cd | 156 | */ |
| kishino | 8:50d2509479cd | 157 | C_SNICwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud); |
| kishino | 8:50d2509479cd | 158 | |
| kishino | 8:50d2509479cd | 159 | /** Initialize UART |
| kishino | 8:50d2509479cd | 160 | */ |
| kishino | 8:50d2509479cd | 161 | int initUart(); |
| kishino | 8:50d2509479cd | 162 | |
| kishino | 8:50d2509479cd | 163 | static C_SNICwifi * getInstance() { |
| kishino | 8:50d2509479cd | 164 | return mInstance_p; |
| kishino | 8:50d2509479cd | 165 | }; |
| kishino | 8:50d2509479cd | 166 | |
| kishino | 8:50d2509479cd | 167 | /** Send data to UART |
| kishino | 8:50d2509479cd | 168 | @param len Length of send data |
| kishino | 8:50d2509479cd | 169 | @param data Pointer of send data |
| kishino | 8:50d2509479cd | 170 | @return 0:success/other:fail |
| kishino | 8:50d2509479cd | 171 | */ |
| kishino | 8:50d2509479cd | 172 | int sendUart( unsigned int len, unsigned char *data ); |
| kishino | 8:50d2509479cd | 173 | |
| kishino | 8:50d2509479cd | 174 | /** Receiving thread of UART |
| kishino | 8:50d2509479cd | 175 | */ |
| kishino | 8:50d2509479cd | 176 | static void uartRecvThread( void const *args_p ); |
| kishino | 9:a98b45e766c8 | 177 | |
| kishino | 9:a98b45e766c8 | 178 | private: |
| kishino | 9:a98b45e766c8 | 179 | /** MemoryPool for payload of UART response */ |
| kishino | 9:a98b45e766c8 | 180 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload; |
| kishino | 9:a98b45e766c8 | 181 | |
| kishino | 8:50d2509479cd | 182 | }; |
| kishino | 8:50d2509479cd | 183 | } |
| kishino | 8:50d2509479cd | 184 | |
| kishino | 8:50d2509479cd | 185 | #endif |
muRata

Murata TypeYD