34rtyujk
Fork of WizFi310Interface_Legacy by
Revision 2:4ec2fd843038, committed 2017-11-27
- Comitter:
- ajeet3004
- Date:
- Mon Nov 27 05:28:45 2017 +0000
- Parent:
- 1:e08ea0ee2788
- Commit message:
- werty
Changed in this revision
--- a/Socket/Socket.cpp Tue May 02 00:31:36 2017 +0000 +++ b/Socket/Socket.cpp Mon Nov 27 05:28:45 2017 +0000 @@ -27,16 +27,18 @@ #include <cstring> Socket::Socket() { + _wizfi310 = NULL; _wizfi310 = WizFi310::getInstance(); if (_wizfi310 == NULL) error("Socket constructor error: no WizFi250 instance available!\r\n"); _blocking = true; - _timeout = 1500; + _timeout = 2500; _server = false; _cid = -1; _port = 0; + printf("Socket done\n"); } void Socket::set_blocking(bool blocking, unsigned int timeout) {
--- a/Socket/TCPSocketConnection.cpp Tue May 02 00:31:36 2017 +0000 +++ b/Socket/TCPSocketConnection.cpp Mon Nov 27 05:28:45 2017 +0000 @@ -28,6 +28,8 @@ TCPSocketConnection::TCPSocketConnection() {} + + int TCPSocketConnection::connect(const char* host, const int port) { if (set_address(host, port) != 0) return -1; @@ -40,10 +42,10 @@ } bool TCPSocketConnection::is_connected(void) -{ +{ printf("_cid: %d\n", _cid); bool _is_connected = _wizfi310->isConnected(_cid); if(!_is_connected) _cid = -1; - + printf(" is_connected: %d\n",_is_connected); return _is_connected; } @@ -99,7 +101,7 @@ } if(time >= _timeout) { - //WIZ_DBG("receive timeout"); + WIZ_DBG("receive timeout"); return 0; } } @@ -141,7 +143,7 @@ if( _wizfi310->cmdSMGMT(cid) ) return; if( !_wizfi310->getRemote(_cid, &ip, &port)) - { + { set_address(ip, port); } }
--- a/Socket/TCPSocketConnection.h Tue May 02 00:31:36 2017 +0000 +++ b/Socket/TCPSocketConnection.h Mon Nov 27 05:28:45 2017 +0000 @@ -80,6 +80,7 @@ int receive_all(char* data, int length); void acceptCID (int cid); + }; #endif
--- a/Socket/TCPSocketServer.h Tue May 02 00:31:36 2017 +0000 +++ b/Socket/TCPSocketServer.h Mon Nov 27 05:28:45 2017 +0000 @@ -54,6 +54,7 @@ \param connection A TCPSocketConnection instance that will handle the incoming connection. \return 0 on success, -1 on failure. */ + int accept(TCPSocketConnection& connection); };
--- a/WizFi310/CBuffer.h Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310/CBuffer.h Mon Nov 27 05:28:45 2017 +0000 @@ -53,7 +53,23 @@ read = 0; write = 0; } + void getdata(int a) { + + int i=0; + while(i<a) + { + data[i]=buf[i]; + i++; + } +printf("\n data is %s\n", data); + + //strcpy(data,buf); + + +memset(buf,'\0',sizeof(buf)); +memset(data,'\0',sizeof(data)); + } uint32_t available() { return (write >= read) ? write - read : size - read + write; @@ -73,6 +89,7 @@ volatile uint32_t read; uint32_t size; T * buf; + char data[]; }; #endif
--- a/WizFi310/WizFi310.h Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310/WizFi310.h Mon Nov 27 05:28:45 2017 +0000 @@ -106,6 +106,7 @@ RES_FDNS, RES_SMGMT, RES_WSTATUS, + RES_SCON, }; @@ -143,6 +144,7 @@ int cmdWJOIN (); int cmdWLEAVE (); int cmdWSTATUS (); + int cmdSCON (); int cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode = "0"); int cmdSCON ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort = 0, const char *dataMode = "0"); int cmdSSEND ( const char *data, int cid, int sendSize, const char *remoteIp = NULL, int remotePort = 0, int Timeout = 2000 ); @@ -327,6 +329,8 @@ //daniel for mqtt char rcvd_mqtt_topic[128]; + + bool test(void); };
--- a/WizFi310/WizFi310_at.cpp Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310/WizFi310_at.cpp Mon Nov 27 05:28:45 2017 +0000 @@ -166,7 +166,7 @@ int WizFi310::cmdWANT(AntennaMode mode) { char cmd[CFG_CMD_SIZE]; - sprintf(cmd, "AT+WANT=%d",mode); + sprintf(cmd, "AT+WANT=%d",mode); return sendCommand(cmd); } @@ -215,7 +215,7 @@ if( cmdWSTATUS() ) return -1; - WIZ_INFO("WizFi310 is successfully join to AP"); + //WIZ_INFO("WizFi310 is successfully join to AP"); return 0; } @@ -347,3 +347,14 @@ resp = sendCommand("AT+SMGMT=?", RES_SMGMT); return resp; } + + +int WizFi310::cmdSCON() +{ + int resp; + + resp = sendCommand("AT+SCON=?", RES_SCON,1500); + printf("Response: %d \n", resp); + return resp; +} +
--- a/WizFi310/WizFi310_sock.cpp Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310/WizFi310_sock.cpp Mon Nov 27 05:28:45 2017 +0000 @@ -77,6 +77,8 @@ _con[cid].protocol = proto; _con[cid].type = TYPE_CLIENT; _con[cid].func = func; + printf("TYPE : %d\n",_con[cid].type); + return cid; } @@ -213,9 +215,12 @@ int WizFi310::readable (int cid) { if (!isConnected(cid)) return -1; - if(_con[cid].buf == NULL) return -1; - return _con[cid].buf->available(); + +int a=_con[cid].buf->available(); +//printf(" return value:%d\n",a); + _con[cid].buf->getdata(a); +return _con[cid].buf->available(); } bool WizFi310::isConnected (int cid) @@ -246,3 +251,6 @@ *port = _con[cid].port; return 0; } + + +
--- a/WizFi310Interface.cpp Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310Interface.cpp Mon Nov 27 05:28:45 2017 +0000 @@ -64,6 +64,8 @@ return cmdWLEAVE(); } + + char* WizFi310Interface::getMACAddress() { return _state.mac; @@ -84,4 +86,30 @@ return cmdWANT(mode); } + +int WizFi310Interface::tcpclient() +{ + +TCPSocketConnection TCPconnection; + +char *p="192.168.200.1"; // ip of TCP server +int a=TCPconnection.connect(p,5000); // Port of TCP Server + + +if(TCPconnection.is_connected()) + { + char *data="Welcome"; + printf("The data is %s\n",data); + int size=strlen(data); + + int b=TCPconnection.send(data,size); + if(b!=-1) + printf("Data send successfuly\n"); + else + printf("Data sending falied\n"); + } + return 0; + } //char* getNetworkMask(); + +
--- a/WizFi310Interface.h Tue May 02 00:31:36 2017 +0000 +++ b/WizFi310Interface.h Mon Nov 27 05:28:45 2017 +0000 @@ -27,8 +27,10 @@ #define WIZFI310INTERFACE_H_ #include "WizFi310.h" +#include "TCPSocketConnection.h" -class WizFi310Interface : public WizFi310{ + +class WizFi310Interface : public WizFi310,public TCPSocketConnection{ public: WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200); @@ -37,14 +39,13 @@ int init(const char* ip, const char* mask, const char* gateway, const char* name = NULL); int connect(Security sec, const char* ssid, const char* phrase, WiFiMode mode = WM_STATION); int disconnect(); + int tcpclient(); char* getMACAddress(); char* getIPAddress(); char* getGateway(); char* getNetworkMask(); - int setAntMode(AntennaMode mode); - };