SNIC UART Interface library for Murata Type-YD module

Dependents:   WebSocketServerTest

Fork of SNICInterface_mod by Toyomasa Watarai

Committer:
MACRUM
Date:
Sun Mar 22 14:13:10 2015 +0000
Revision:
50:d390d41d1405
Parent:
47:62ba69ff80d2
Added default constructor and create() method

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 */
MACRUM 50:d390d41d1405 50 C_SNIC_WifiInterface() {};
kishino 12:0254eaccfda2 51 C_SNIC_WifiInterface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200);
kishino 26:f2e1030964e4 52 virtual ~C_SNIC_WifiInterface();
kishino 12:0254eaccfda2 53
MACRUM 50:d390d41d1405 54 /** Create instance.
MACRUM 50:d390d41d1405 55 */
MACRUM 50:d390d41d1405 56 void create(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200);
MACRUM 50:d390d41d1405 57
kishino 12:0254eaccfda2 58 /** Initialize the interface.
kishino 12:0254eaccfda2 59 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 60 */
kishino 12:0254eaccfda2 61 int init();
kishino 12:0254eaccfda2 62
kishino 12:0254eaccfda2 63 /** Get Firmware version string.
kishino 12:0254eaccfda2 64 @param version_p Pointer of FW version string.(null terminated)[output]
kishino 12:0254eaccfda2 65 @return 0:success/other:fail
kishino 12:0254eaccfda2 66 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 67 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 68 */
kishino 12:0254eaccfda2 69 int getFWVersion( unsigned char *version_p );
kishino 12:0254eaccfda2 70
kishino 12:0254eaccfda2 71 /** Connect to AP
kishino 12:0254eaccfda2 72 @param ssid_p Wi-Fi SSID(null terminated)
kishino 12:0254eaccfda2 73 @param ssid_len Wi-Fi SSID length
kishino 12:0254eaccfda2 74 @param sec_type Wi-Fi security type.
kishino 12:0254eaccfda2 75 @param sec_key_len Wi-Fi passphrase or security key length
kishino 12:0254eaccfda2 76 @param sec_key_p Wi-Fi passphrase or security key
kishino 12:0254eaccfda2 77 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 78 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 79 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 80 */
kishino 12:0254eaccfda2 81 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 82
kishino 12:0254eaccfda2 83 /** Disconnect from AP
kishino 12:0254eaccfda2 84 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 85 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 86 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 87 */
kishino 12:0254eaccfda2 88 int disconnect();
kishino 12:0254eaccfda2 89
kishino 12:0254eaccfda2 90 /** Scan AP
kishino 12:0254eaccfda2 91 @param ssid_p Wi-Fi SSID(null terminated)
kishino 12:0254eaccfda2 92 If do not specify SSID, set to NULL.
kishino 12:0254eaccfda2 93 @param bssid_p Wi-Fi BSSID(null terminated)
kishino 12:0254eaccfda2 94 If do not specify SSID, set to NULL.
kishino 12:0254eaccfda2 95 @param result_handler_p Pointer of scan result callback function.
kishino 12:0254eaccfda2 96 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 97 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 98 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 99 Scan results will be notified by asynchronous callback function.
kishino 43:d80bbb12ffe6 100 If there is no continuity data, scan_result will be set NULL..
kishino 12:0254eaccfda2 101 */
kishino 12:0254eaccfda2 102 int scan( const char *ssid_p, unsigned char *bssid_p
kishino 12:0254eaccfda2 103 ,void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) );
kishino 12:0254eaccfda2 104
kishino 12:0254eaccfda2 105 /** Wi-Fi Turn on
kishino 12:0254eaccfda2 106 @param country_p Pointer of country code.
kishino 12:0254eaccfda2 107 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 108 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 109 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 110 */
kishino 12:0254eaccfda2 111 int wifi_on( const char *country_p );
kishino 12:0254eaccfda2 112
kishino 12:0254eaccfda2 113 /** Wi-Fi Turn off
kishino 12:0254eaccfda2 114 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 115 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 116 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 117 */
kishino 12:0254eaccfda2 118 int wifi_off();
kishino 12:0254eaccfda2 119
kishino 12:0254eaccfda2 120 /** Get Wi-Fi RSSI
kishino 12:0254eaccfda2 121 @param rssi_p Pointer of RSSI.[output]
kishino 12:0254eaccfda2 122 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 123 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 124 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 125 */
kishino 12:0254eaccfda2 126 int getRssi( signed char *rssi_p );
kishino 12:0254eaccfda2 127
kishino 12:0254eaccfda2 128 /** Get Wi-Fi status
kishino 12:0254eaccfda2 129 @param status_p Pointer of status structure.[output]
kishino 12:0254eaccfda2 130 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 131 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 132 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 133 */
kishino 12:0254eaccfda2 134 int getWifiStatus( tagWIFI_STATUS_T *status_p);
kishino 12:0254eaccfda2 135
kishino 31:15c22824cc46 136 /** Set IP configuration
kishino 31:15c22824cc46 137 @param is_DHCP true:DHCP false:static IP.
kishino 31:15c22824cc46 138 @param ip_p Pointer of strings of IP address.(null terminate).
kishino 31:15c22824cc46 139 @param mask_p Pointer of strings of Netmask.(null terminate).
kishino 31:15c22824cc46 140 @param gateway_p Pointer of strings of gateway address.(null terminate).
kishino 31:15c22824cc46 141 @return 0 on success, a negative number on failure
kishino 31:15c22824cc46 142 @note This function is blocked until a returns.
kishino 31:15c22824cc46 143 When you use it by UI thread, be careful.
kishino 31:15c22824cc46 144 */
kishino 31:15c22824cc46 145 int setIPConfig( bool is_DHCP, const char *ip_p=NULL, const char *mask_p=NULL, const char *gateway_p=NULL );
kishino 12:0254eaccfda2 146
MACRUM 47:62ba69ff80d2 147 /** Get the IP address of your Ethernet interface
MACRUM 47:62ba69ff80d2 148 * \return a pointer to a string containing the IP address
MACRUM 47:62ba69ff80d2 149 */
MACRUM 47:62ba69ff80d2 150 static char* getIPAddress();
MACRUM 47:62ba69ff80d2 151
kishino 12:0254eaccfda2 152 private:
kishino 12:0254eaccfda2 153 PinName mUART_tx;
kishino 12:0254eaccfda2 154 PinName mUART_rx;
kishino 12:0254eaccfda2 155 PinName mUART_cts;
kishino 12:0254eaccfda2 156 PinName mUART_rts;
kishino 12:0254eaccfda2 157 int mUART_baud;
kishino 12:0254eaccfda2 158 PinName mModuleReset;
kishino 12:0254eaccfda2 159 };
kishino 12:0254eaccfda2 160 #endif /* _YD_WIFIINTERFACE_H_ */