Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: X_NUCLEO_IDW01M1v2-lapi-1
Fork of SPWF01SA by
SPWFSA01.h
00001 /* SPWFInterface Example 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SPWFSA01_H 00018 #define SPWFSA01_H 00019 00020 #include "ATParser.h" 00021 00022 /** SPWFSA01Interface class. 00023 This is an interface to a SPWFSA01 module. 00024 */ 00025 class SPWFSA01 00026 { 00027 public: 00028 //Pin PC_8 is wakeup pin, Pin PC_12 reset pin with X-NUCLEO-IDW01M1 00029 SPWFSA01(PinName tx, PinName rx, bool debug=false, 00030 PinName resetPin=PC_12, PinName wakeupPin = PC_8); 00031 00032 /** 00033 * Init the SPWFSA01 00034 * 00035 * @param mode mode in which to startup 00036 * @return true only if SPWFSA01 has started up correctly 00037 */ 00038 bool startup(int mode); 00039 00040 void waitSPWFReady(void); 00041 /** 00042 * Reset SPWFSA01 00043 * 00044 * @return true only if SPWFSA01 resets successfully 00045 */ 00046 bool reset(void); 00047 00048 bool hw_reset(void); 00049 00050 /** 00051 * Enable/Disable DHCP 00052 * 00053 * @param mode mode of DHCP 2-softAP, 1-on, 0-off 00054 * @return true only if SPWFSA01 enables/disables DHCP successfully 00055 */ 00056 bool dhcp(int mode); 00057 00058 /** 00059 * Connect SPWFSA01 to AP 00060 * 00061 * @param ap the name of the AP 00062 * @param passPhrase the password of AP 00063 * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open) 00064 * @param channel the WiFi channel number 00065 * @return true only if SPWFSA01 is connected successfully 00066 */ 00067 bool connect(const char *ap, const char *passPhrase, int securityMode, int channel); 00068 00069 /** 00070 * Disconnect SPWFSA01 from AP 00071 * 00072 * @return true only if SPWFSA01 is disconnected successfully 00073 */ 00074 bool disconnect(void); 00075 00076 00077 /** 00078 * Get the RSSI of the last packet 00079 * 00080 * @return the RSSI (dBm) 00081 */ 00082 int8_t getRSSI(void); 00083 00084 /** 00085 * Get the IP address of SPWFSA01 00086 * 00087 * @return null-teriminated IP address or null if no IP address is assigned 00088 */ 00089 const char *getIPAddress(void); 00090 00091 /** 00092 * Get the MAC address of SPWFSA01 00093 * 00094 * @return null-terminated MAC address or null if no MAC address is assigned 00095 */ 00096 const char *getMACAddress(void); 00097 00098 /** 00099 * Check if SPWFSA01 is conenected 00100 * 00101 * @return true only if the chip has an IP address 00102 */ 00103 bool isConnected(void); 00104 00105 /** 00106 * Open a socketed connection 00107 * 00108 * @param type the type of socket to open "u" (UDP) or "t" (TCP) 00109 * @param id id to get the new socket number, valid 0-7 00110 * @param port port to open connection with 00111 * @param addr the IP address of the destination 00112 * @return true only if socket opened successfully 00113 */ 00114 bool open(const char *type, int* id, const char* addr, int port); 00115 00116 /** 00117 * Sends data to an open socket 00118 * 00119 * @param id id of socket to send to 00120 * @param data data to be sent 00121 * @param amount amount of data to be sent - max 1024 00122 * @return true only if data sent successfully 00123 */ 00124 bool send(int id, const void *data, uint32_t amount); 00125 00126 /** 00127 * Receives data from an open socket 00128 * 00129 * @param id id to receive from 00130 * @param data placeholder for returned information 00131 * @param amount number of bytes to be received 00132 * @return the number of bytes received 00133 */ 00134 int32_t recv(int id, void *data, uint32_t amount); 00135 00136 /** 00137 * Closes a socket 00138 * 00139 * @param id id of socket to close, valid only 0-4 00140 * @return true only if socket is closed successfully 00141 */ 00142 bool close(int id); 00143 00144 /** 00145 * Allows timeout to be changed between commands 00146 * 00147 * @param timeout_ms timeout of the connection 00148 */ 00149 void setTimeout(uint32_t timeout_ms); 00150 00151 /** 00152 * Checks if data is available 00153 */ 00154 bool readable(); 00155 00156 /** 00157 * Checks if data can be written 00158 */ 00159 bool writeable(); 00160 00161 private: 00162 BufferedSerial _serial; 00163 ATParser _parser; 00164 DigitalInOut _wakeup; 00165 DigitalInOut _reset; 00166 00167 char _ip_buffer[16]; 00168 char _mac_buffer[18]; 00169 bool dbg_on; 00170 }; 00171 00172 #endif //SPWFSA01_H
Generated on Tue Jul 19 2022 11:37:49 by
1.7.2
