Temp fork
Fork of GPRSInterface by
Revision 3:acf2ea413e72, committed 2014-02-26
- Comitter:
- lawliet
- Date:
- Wed Feb 26 09:12:46 2014 +0000
- Parent:
- 2:8cb3c0d45988
- Child:
- 4:1142bdd07989
- Commit message:
- version 1.1 (fix some errors)
Changed in this revision
--- a/GPRS/GPRS.cpp Tue Feb 25 06:00:32 2014 +0000 +++ b/GPRS/GPRS.cpp Wed Feb 26 09:12:46 2014 +0000 @@ -142,8 +142,8 @@ bool GPRS::is_connected(int socket) { char cmd[16]; - char resp[64]; - snprintf(cmd,16,"AT+CIPSTAUTS=%d\r\n",socket); + char resp[96]; + snprintf(cmd,16,"AT+CIPSTATUS=%d\r\n",socket); sendCmd(cmd); readBuffer(resp,sizeof(resp),DEFAULT_TIMEOUT); if(NULL != strstr(resp,"CONNECTED")) { @@ -228,15 +228,16 @@ char cmd[32]; char resp[16]; wait(1); - snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d,%d\r\n",socket,len); - if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT,CMD)) { - return false; + if(len > 0){ + snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d,%d\r\n",socket,len); + if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT,CMD)) { + return false; + } + snprintf(resp,sizeof(resp),"%d, SEND OK",socket); + if(0 != sendCmdAndWaitForResp(str,resp,DEFAULT_TIMEOUT,DATA)) { + return -1; + } } - snprintf(resp,sizeof(resp),"%d, SEND OK",socket); - if(0 != sendCmdAndWaitForResp(str,resp,DEFAULT_TIMEOUT,DATA)) { - return -1; - } - return len; }
--- a/Socket/Socket.cpp Tue Feb 25 06:00:32 2014 +0000 +++ b/Socket/Socket.cpp Wed Feb 26 09:12:46 2014 +0000 @@ -29,6 +29,11 @@ } } +void Socket::set_blocking(bool blocking, unsigned int timeout) +{ + //nothing to do for GPRS +} + int Socket::close() { return (gprs->close(_sock_fd)) ? 0 : -1; }
--- a/Socket/Socket.h Tue Feb 25 06:00:32 2014 +0000 +++ b/Socket/Socket.h Wed Feb 26 09:12:46 2014 +0000 @@ -31,6 +31,8 @@ /** Socket */ Socket(); + + void set_blocking(bool blocking, unsigned int timeout=1); /** Close the socket file descriptor */
--- a/Socket/TCPSocketConnection.cpp Tue Feb 25 06:00:32 2014 +0000 +++ b/Socket/TCPSocketConnection.cpp Wed Feb 26 09:12:46 2014 +0000 @@ -22,10 +22,8 @@ #include "TCPSocketConnection.h" -static int size; TCPSocketConnection::TCPSocketConnection() { - size = 0; } int TCPSocketConnection::connect(const char* host, const int port) @@ -67,6 +65,7 @@ int TCPSocketConnection::receive(char* data, int length) { +#if 0 if (size < 0) { return -1; } @@ -80,7 +79,9 @@ length = size; size = -1; } - return gprs->recv(_sock_fd, data, length); +#endif + int size = gprs->wait_readable(_sock_fd, DEFAULT_TIMEOUT); + return gprs->recv(_sock_fd, data, size); } int TCPSocketConnection::receive_all(char* data, int length)