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.
Fork of WizFi310Interface_Legacy by
WizFi310.h
00001 /* 00002 * Copyright (C) 2013 gsfan, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 /* Copyright (C) 2014 Wiznet, MIT License 00020 * port to the Wiznet Module WizFi250 00021 */ 00022 /* Copyright (C) 2017 Wiznet, MIT License 00023 * port to the Wiznet Module WizFi310 00024 */ 00025 00026 #ifndef WIZFI310_H_ 00027 #define WIZFI310_H_ 00028 00029 #include "WizFi310_conf.h" 00030 00031 #include "mbed.h" 00032 #include "RawSerial.h" 00033 #include "Serial.h" 00034 #include "CBuffer.h" 00035 #include <ctype.h> 00036 #include <stdlib.h> 00037 #include <string> 00038 00039 using namespace std; 00040 00041 #define BUF_SIZE 1600 00042 00043 //Debug is disabled by default 00044 #if 1 00045 #define WIZ_DBG(x, ...) std::printf("[WizFi310: DBG]" x "\r\n", ##__VA_ARGS__); 00046 #define WIZ_WARN(x, ...) std::printf("[WizFi310: WARN]" x "\r\n", ##__VA_ARGS__); 00047 #define WIZ_ERR(x, ...) std::printf("[WizFi310: ERR]" x "\r\n", ##__VA_ARGS__); 00048 #define WIZ_INFO(x, ...) std::printf("[WizFi310: INFO]" x "\r\n", ##__VA_ARGS__); 00049 #else 00050 #define WIZ_DBG(x, ...) 00051 #define WIZ_WARN(x, ...) 00052 #define WIZ_ERR(x, ...) 00053 #define WIZ_INFO(x, ...) 00054 #endif 00055 00056 00057 class WizFi310 00058 { 00059 public: 00060 00061 enum AntennaMode{ 00062 PCB = 0, 00063 UFL = 1, 00064 AUTO = 3, 00065 }; 00066 00067 enum WiFiMode { 00068 WM_STATION = 0, 00069 WM_AP = 1, 00070 }; 00071 00072 /** Wi-Fi security 00073 */ 00074 enum Security { 00075 // kaizen need to change 00076 SEC_AUTO = 0, 00077 SEC_OPEN = 1, 00078 SEC_WEP = 2, 00079 SEC_WPA_TKIP = 3, 00080 SEC_WPA_AES = 4, 00081 SEC_WPA2_AES = 5, 00082 SEC_WPA2_TKIP = 6, 00083 SEC_WPA2_MIXED = 7, 00084 }; 00085 00086 /** TCP/IP protocol 00087 */ 00088 enum Protocol { 00089 PROTO_UDP = 0, 00090 PROTO_TCP = 1, 00091 }; 00092 00093 /** Client/Server 00094 */ 00095 enum Type { 00096 TYPE_CLIENT = 0, 00097 TYPE_SERVER = 1, 00098 }; 00099 00100 enum Response { 00101 RES_NULL, 00102 RES_MACADDRESS, 00103 RES_WJOIN, 00104 RES_CONNECT, 00105 RES_SSEND, 00106 RES_FDNS, 00107 RES_SMGMT, 00108 RES_WSTATUS, 00109 RES_SCON, 00110 00111 }; 00112 00113 enum Mode { 00114 MODE_COMMAND, 00115 MODE_CMDRESP, 00116 MODE_DATA_RX, 00117 MODE_DATA_RXUDP, 00118 MODE_DATA_RXUDP_BULK, 00119 }; 00120 00121 enum Status { 00122 STAT_NONE, 00123 STAT_READY, 00124 STAT_STANDBY, 00125 STAT_WAKEUP, 00126 STAT_DEEPSLEEP, 00127 }; 00128 00129 00130 WizFi310 (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200); 00131 00132 // --------- WizFi250_at.cpp --------- 00133 void clearFlags (); 00134 int sendCommand (const char * cmd, Response res = RES_NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT, int opt = 1); 00135 00136 int cmdAT (); 00137 int cmdMECHO (bool flg); 00138 int cmdUSET (int baud, char *flow); 00139 int cmdMMAC (const char *mac = NULL); 00140 int cmdWSET (WiFiMode mode, const char *ssid, const char *bssid = NULL, int channel = 1); 00141 int cmdWANT (AntennaMode mode); 00142 int cmdWNET (bool is_dhcp); 00143 int cmdWSEC (WiFiMode mode, const char *key, const char *sec = NULL); 00144 int cmdWJOIN (); 00145 int cmdWLEAVE (); 00146 int cmdWSTATUS (); 00147 int cmdSCON (); 00148 int cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode = "0"); 00149 int cmdSCON ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort = 0, const char *dataMode = "0"); 00150 int cmdSSEND ( const char *data, int cid, int sendSize, const char *remoteIp = NULL, int remotePort = 0, int Timeout = 2000 ); 00151 int cmdCLOSE ( int cid ); 00152 int cmdFDNS (const char *host); 00153 int cmdSMGMT ( int cid ); 00154 00155 00156 static WizFi310 * getInstance() { 00157 return _inst; 00158 }; 00159 00160 00161 // --------- WizFi2550_sock.cpp --------- 00162 int getHostByName (const char * host, char *ip); 00163 int open (Protocol proto, const char *ip, int remotePort, int localPort = 0, void(*func)(int) = NULL); 00164 int listen (Protocol proto, int port, void(*func)(int)=NULL); 00165 int close (int cid); 00166 void initCon (int cid, bool connected); 00167 int send (int cid, const char *buf, int len); 00168 int sendto (int cid, const char *buf, int len, const char *ip, int port); 00169 int recv (int cid, char *buf, int len); 00170 int recvfrom (int cid, char *buf, int len, char *ip, int *port); 00171 int readable (int cid); 00172 bool isConnected (int cid); 00173 int accept (int cid); 00174 int getRemote (int cid, char **ip, int *port); 00175 00176 00177 protected: 00178 static WizFi310 * _inst; 00179 00180 00181 // Serial _wizfi 00182 RawSerial _wizfi; 00183 int _baud; 00184 DigitalIn *_cts; 00185 DigitalOut *_rts; 00186 int _flow; 00187 00188 DigitalInOut _reset; 00189 00190 struct STATE { 00191 WiFiMode wm; 00192 00193 Security sec; 00194 char ssid[35]; 00195 char pass[66]; 00196 char ip[16]; 00197 char netmask[16]; 00198 char gateway[16]; 00199 char nameserver[16]; 00200 char mac[18]; 00201 char resolv[16]; 00202 char name[32]; 00203 int rssi; 00204 bool dhcp; 00205 time_t time; 00206 00207 bool initialized; 00208 bool associated; 00209 volatile Mode mode; 00210 volatile Status status; 00211 bool escape; 00212 volatile bool ok, failure; 00213 volatile Response res; 00214 int cid; 00215 int n; 00216 CircBuffer<char> *buf; 00217 char dbgRespBuf[BUF_SIZE]; 00218 //char dummyBuf[BUF_SIZE]; 00219 } _state; 00220 00221 00222 public: 00223 struct CONNECTION { 00224 Protocol protocol; 00225 Type type; 00226 bool connected; 00227 char ip[16]; 00228 int port; 00229 int send_length; 00230 int recv_length; 00231 CircBuffer<char> *buf; 00232 volatile bool received; 00233 volatile int parent; 00234 volatile bool accept; 00235 void(*func)(int); 00236 } _con[8]; 00237 00238 // --------- WizFi310.cpp --------- 00239 00240 int join(WiFiMode mode); 00241 bool isAssociated(); 00242 00243 //int limitedap (); 00244 //int dissociate (); 00245 /* 00246 int disconnect () { 00247 return dissociate(); 00248 } 00249 */ 00250 00251 Status getStatus (); 00252 00253 int setMacAddress (const char *mac); 00254 int getMacAddress (char *mac); 00255 int setAddress (const char *name = NULL); 00256 int setAddress (const char *ip, const char *netmask, const char *gateway, const char *dns = NULL, const char *name = NULL); 00257 int getAddress (char *ip, char *netmask, char *gateway); 00258 int setSsid (const char *ssid); 00259 int setSec (Security sec, const char *phrase); 00260 00261 const char* getIPAddress (void); 00262 const char* getMACAddress (void); 00263 00264 // --------- WizFi250_msg.cpp --------- 00265 void recvData ( char c ); 00266 int parseMessage (); 00267 void msgOk (const char *buf); 00268 void msgError (const char *buf); 00269 void msgConnect (const char *buf); 00270 void msgDisconnect (const char *buf); 00271 void msgListen (const char *buf); 00272 //daniel 00273 void msgMQTTConnect (const char *buf); 00274 void msgMQTTDisconnect (const char *buf); 00275 00276 void resMacAddress (const char *buf); 00277 void resWJOIN (const char *buf); 00278 void resConnect (const char *buf); 00279 void resSSEND (const char *buf); 00280 void resFDNS (const char *buf); 00281 void resSMGMT (const char *buf); 00282 void resWSTATUS (const char *buf); 00283 00284 00285 // --------- WizFi250_hal.cpp --------- 00286 void setReset (bool flg); 00287 void isrUart (); 00288 int getUart (); 00289 void putUart (char c); 00290 void setRts (bool flg); 00291 int lockUart (int ms); 00292 void unlockUart (); 00293 void initUart (PinName cts, PinName rts, PinName alarm, int baud); 00294 00295 00296 // --------- WizFi2550_util.cpp --------- 00297 int x2i (char c); 00298 int i2x (int i); 00299 00300 // --------- WizFi250_ifc.cpp (For NetworkSocketAPI) --------- 00301 /** 00302 * Startup the WizFi310 00303 * 00304 * @return true only if WizFi310 was setup correctly 00305 */ 00306 bool startup(void); 00307 00308 /** 00309 * Reset WizFi310 00310 * 00311 * @return true only if WizFi310 resets successfully 00312 */ 00313 bool reset(void); 00314 00315 /** 00316 * Disconnect WizFi310 from AP 00317 * 00318 * @return true only if WizFi310 is disconnected successfully 00319 */ 00320 bool disconnect(void); 00321 00322 /** 00323 * Check if WizFi310 is conenected 00324 * 00325 * @return true only if the chip has an IP address 00326 */ 00327 bool isConnected(void); 00328 00329 00330 //daniel for mqtt 00331 char rcvd_mqtt_topic[128]; 00332 00333 bool test(void); 00334 00335 }; 00336 00337 #endif /* WIZFI250_H_ */
Generated on Thu Jul 14 2022 15:18:32 by
1.7.2
