Murata Type YD Wi-Fi driver
Dependents: easy-connect-type-yd
SNICInterface/SNIC_WifiInterface.h@0:35a2186cf186, 2017-07-12 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Jul 12 10:49:10 2017 +0000
- Revision:
- 0:35a2186cf186
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:35a2186cf186 | 1 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
MACRUM | 0:35a2186cf186 | 2 | * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART. |
MACRUM | 0:35a2186cf186 | 3 | * |
MACRUM | 0:35a2186cf186 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MACRUM | 0:35a2186cf186 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
MACRUM | 0:35a2186cf186 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
MACRUM | 0:35a2186cf186 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
MACRUM | 0:35a2186cf186 | 8 | * furnished to do so, subject to the following conditions: |
MACRUM | 0:35a2186cf186 | 9 | * |
MACRUM | 0:35a2186cf186 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
MACRUM | 0:35a2186cf186 | 11 | * substantial portions of the Software. |
MACRUM | 0:35a2186cf186 | 12 | * |
MACRUM | 0:35a2186cf186 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
MACRUM | 0:35a2186cf186 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
MACRUM | 0:35a2186cf186 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
MACRUM | 0:35a2186cf186 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MACRUM | 0:35a2186cf186 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MACRUM | 0:35a2186cf186 | 18 | */ |
MACRUM | 0:35a2186cf186 | 19 | #ifndef _SNIC_WIFIINTERFACE_H_ |
MACRUM | 0:35a2186cf186 | 20 | #define _SNIC_WIFIINTERFACE_H_ |
MACRUM | 0:35a2186cf186 | 21 | |
MACRUM | 0:35a2186cf186 | 22 | #include "SNICInterface/SNIC/SNIC_Core.h" |
MACRUM | 0:35a2186cf186 | 23 | #include "SNICInterface/SNIC/MurataObject.h" |
MACRUM | 0:35a2186cf186 | 24 | |
MACRUM | 0:35a2186cf186 | 25 | /** Wi-Fi status used by getWifiStatus(). */ |
MACRUM | 0:35a2186cf186 | 26 | typedef struct |
MACRUM | 0:35a2186cf186 | 27 | { |
MACRUM | 0:35a2186cf186 | 28 | /** status */ |
MACRUM | 0:35a2186cf186 | 29 | E_WIFI_STATUS status; |
MACRUM | 0:35a2186cf186 | 30 | /** Mac address */ |
MACRUM | 0:35a2186cf186 | 31 | char mac_address[BSSID_MAC_LENTH]; |
MACRUM | 0:35a2186cf186 | 32 | /** SSID */ |
MACRUM | 0:35a2186cf186 | 33 | char ssid[SSID_MAX_LENGTH+1]; |
MACRUM | 0:35a2186cf186 | 34 | }tagWIFI_STATUS_T; |
MACRUM | 0:35a2186cf186 | 35 | |
MACRUM | 0:35a2186cf186 | 36 | /** Interface class for using SNIC UART. |
MACRUM | 0:35a2186cf186 | 37 | */ |
MACRUM | 0:35a2186cf186 | 38 | class C_SNIC_WifiInterface : public C_MurataObject { |
MACRUM | 0:35a2186cf186 | 39 | |
MACRUM | 0:35a2186cf186 | 40 | public: |
MACRUM | 0:35a2186cf186 | 41 | /** Default constructor |
MACRUM | 0:35a2186cf186 | 42 | */ |
MACRUM | 0:35a2186cf186 | 43 | C_SNIC_WifiInterface() {}; |
MACRUM | 0:35a2186cf186 | 44 | |
MACRUM | 0:35a2186cf186 | 45 | /** Constructor |
MACRUM | 0:35a2186cf186 | 46 | @param tx mbed pin to use for tx line of Serial interface |
MACRUM | 0:35a2186cf186 | 47 | @param rx mbed pin to use for rx line of Serial interface |
MACRUM | 0:35a2186cf186 | 48 | @param cts mbed pin to use for cts line of Serial interface |
MACRUM | 0:35a2186cf186 | 49 | @param rts mbed pin to use for rts line of Serial interface |
MACRUM | 0:35a2186cf186 | 50 | @param reset reset pin of the wifi module |
MACRUM | 0:35a2186cf186 | 51 | @param alarm alarm pin of the wifi module (default: NC) |
MACRUM | 0:35a2186cf186 | 52 | @param baud baud rate of Serial interface (default: 115200) |
MACRUM | 0:35a2186cf186 | 53 | */ |
MACRUM | 0:35a2186cf186 | 54 | C_SNIC_WifiInterface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200); |
MACRUM | 0:35a2186cf186 | 55 | virtual ~C_SNIC_WifiInterface(); |
MACRUM | 0:35a2186cf186 | 56 | |
MACRUM | 0:35a2186cf186 | 57 | /** Create instance. |
MACRUM | 0:35a2186cf186 | 58 | */ |
MACRUM | 0:35a2186cf186 | 59 | void create(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200); |
MACRUM | 0:35a2186cf186 | 60 | |
MACRUM | 0:35a2186cf186 | 61 | /** Initialize the interface. |
MACRUM | 0:35a2186cf186 | 62 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 63 | */ |
MACRUM | 0:35a2186cf186 | 64 | int init(); |
MACRUM | 0:35a2186cf186 | 65 | |
MACRUM | 0:35a2186cf186 | 66 | /** Get Firmware version string. |
MACRUM | 0:35a2186cf186 | 67 | @param version_p Pointer of FW version string.(null terminated)[output] |
MACRUM | 0:35a2186cf186 | 68 | @return 0:success/other:fail |
MACRUM | 0:35a2186cf186 | 69 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 70 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 71 | */ |
MACRUM | 0:35a2186cf186 | 72 | int getFWVersion( unsigned char *version_p, int *length_p); |
MACRUM | 0:35a2186cf186 | 73 | |
MACRUM | 0:35a2186cf186 | 74 | /** Connect to AP |
MACRUM | 0:35a2186cf186 | 75 | @param ssid_p Wi-Fi SSID(null terminated) |
MACRUM | 0:35a2186cf186 | 76 | @param ssid_len Wi-Fi SSID length |
MACRUM | 0:35a2186cf186 | 77 | @param sec_type Wi-Fi security type. |
MACRUM | 0:35a2186cf186 | 78 | @param sec_key_len Wi-Fi passphrase or security key length |
MACRUM | 0:35a2186cf186 | 79 | @param sec_key_p Wi-Fi passphrase or security key |
MACRUM | 0:35a2186cf186 | 80 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 81 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 82 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 83 | */ |
MACRUM | 0:35a2186cf186 | 84 | int connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type, const char *sec_key_p, unsigned char sec_key_len); |
MACRUM | 0:35a2186cf186 | 85 | |
MACRUM | 0:35a2186cf186 | 86 | /** Disconnect from AP |
MACRUM | 0:35a2186cf186 | 87 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 88 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 89 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 90 | */ |
MACRUM | 0:35a2186cf186 | 91 | int disconnect(); |
MACRUM | 0:35a2186cf186 | 92 | |
MACRUM | 0:35a2186cf186 | 93 | /** Scan AP |
MACRUM | 0:35a2186cf186 | 94 | @param ssid_p Wi-Fi SSID(null terminated) |
MACRUM | 0:35a2186cf186 | 95 | If do not specify SSID, set to NULL. |
MACRUM | 0:35a2186cf186 | 96 | @param bssid_p Wi-Fi BSSID(null terminated) |
MACRUM | 0:35a2186cf186 | 97 | If do not specify SSID, set to NULL. |
MACRUM | 0:35a2186cf186 | 98 | @param result_handler_p Pointer of scan result callback function. |
MACRUM | 0:35a2186cf186 | 99 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 100 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 101 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 102 | Scan results will be notified by asynchronous callback function. |
MACRUM | 0:35a2186cf186 | 103 | If there is no continuity data, scan_result will be set NULL.. |
MACRUM | 0:35a2186cf186 | 104 | */ |
MACRUM | 0:35a2186cf186 | 105 | int scan( const char *ssid_p, unsigned char *bssid_p |
MACRUM | 0:35a2186cf186 | 106 | ,void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) ); |
MACRUM | 0:35a2186cf186 | 107 | |
MACRUM | 0:35a2186cf186 | 108 | /** Wi-Fi Turn on |
MACRUM | 0:35a2186cf186 | 109 | @param country_p Pointer of country code. |
MACRUM | 0:35a2186cf186 | 110 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 111 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 112 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 113 | */ |
MACRUM | 0:35a2186cf186 | 114 | int wifi_on( const char *country_p ); |
MACRUM | 0:35a2186cf186 | 115 | |
MACRUM | 0:35a2186cf186 | 116 | /** Wi-Fi Turn off |
MACRUM | 0:35a2186cf186 | 117 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 118 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 119 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 120 | */ |
MACRUM | 0:35a2186cf186 | 121 | int wifi_off(); |
MACRUM | 0:35a2186cf186 | 122 | |
MACRUM | 0:35a2186cf186 | 123 | int wifi_softap_off(); |
MACRUM | 0:35a2186cf186 | 124 | |
MACRUM | 0:35a2186cf186 | 125 | /** Get Wi-Fi RSSI |
MACRUM | 0:35a2186cf186 | 126 | @param rssi_p Pointer of RSSI.[output] |
MACRUM | 0:35a2186cf186 | 127 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 128 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 129 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 130 | */ |
MACRUM | 0:35a2186cf186 | 131 | int getRssi( signed char *rssi_p ); |
MACRUM | 0:35a2186cf186 | 132 | |
MACRUM | 0:35a2186cf186 | 133 | /** Get Wi-Fi status |
MACRUM | 0:35a2186cf186 | 134 | @param status_p Pointer of status structure.[output] |
MACRUM | 0:35a2186cf186 | 135 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 136 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 137 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 138 | */ |
MACRUM | 0:35a2186cf186 | 139 | int getWifiStatus( tagWIFI_STATUS_T *status_p); |
MACRUM | 0:35a2186cf186 | 140 | |
MACRUM | 0:35a2186cf186 | 141 | /** Set IP configuration |
MACRUM | 0:35a2186cf186 | 142 | @param is_DHCP true:DHCP false:static IP. |
MACRUM | 0:35a2186cf186 | 143 | @param ip_p Pointer of strings of IP address.(null terminate). |
MACRUM | 0:35a2186cf186 | 144 | @param mask_p Pointer of strings of Netmask.(null terminate). |
MACRUM | 0:35a2186cf186 | 145 | @param gateway_p Pointer of strings of gateway address.(null terminate). |
MACRUM | 0:35a2186cf186 | 146 | @return 0 on success, a negative number on failure |
MACRUM | 0:35a2186cf186 | 147 | @note This function is blocked until a returns. |
MACRUM | 0:35a2186cf186 | 148 | When you use it by UI thread, be careful. |
MACRUM | 0:35a2186cf186 | 149 | */ |
MACRUM | 0:35a2186cf186 | 150 | int setIPConfig( bool is_DHCP, const char *ip_p=NULL, const char *mask_p=NULL, const char *gateway_p=NULL ); |
MACRUM | 0:35a2186cf186 | 151 | |
MACRUM | 0:35a2186cf186 | 152 | /** Get the IP address of your SNIC interface |
MACRUM | 0:35a2186cf186 | 153 | * \return a pointer to a string containing the IP address |
MACRUM | 0:35a2186cf186 | 154 | */ |
MACRUM | 0:35a2186cf186 | 155 | static char* getIPAddress(); |
MACRUM | 0:35a2186cf186 | 156 | static char* getSubnetAddress(); |
MACRUM | 0:35a2186cf186 | 157 | static char* getGatewayAddress(); |
MACRUM | 0:35a2186cf186 | 158 | |
MACRUM | 0:35a2186cf186 | 159 | int resolveName(const char *name, unsigned char *ipaddr); |
MACRUM | 0:35a2186cf186 | 160 | |
MACRUM | 0:35a2186cf186 | 161 | private: |
MACRUM | 0:35a2186cf186 | 162 | PinName mUART_tx; |
MACRUM | 0:35a2186cf186 | 163 | PinName mUART_rx; |
MACRUM | 0:35a2186cf186 | 164 | PinName mUART_cts; |
MACRUM | 0:35a2186cf186 | 165 | PinName mUART_rts; |
MACRUM | 0:35a2186cf186 | 166 | int mUART_baud; |
MACRUM | 0:35a2186cf186 | 167 | PinName mModuleReset; |
MACRUM | 0:35a2186cf186 | 168 | }; |
MACRUM | 0:35a2186cf186 | 169 | #endif /* _YD_WIFIINTERFACE_H_ */ |