SNIC UART Interface library for Murata Type-YD module

Dependents:   WebSocketServerTest

Fork of SNICInterface_mod by Toyomasa Watarai

Committer:
MACRUM
Date:
Fri Jan 23 09:56:01 2015 +0000
Revision:
47:62ba69ff80d2
Parent:
43:d80bbb12ffe6
Child:
50:d390d41d1405
Added getIPAddress() function

Who changed what in which revision?

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