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