a library to use GPRS like ethernet or wifi, which makes it possible to connect to the internet with your GPRS module
Dependencies: BufferedSerial
Dependents: ThinkSpeak_Test roam_v1 roam_v2 finalv3
Fork of GPRSInterface by
Diff: GPRS/GPRS.h
- Revision:
- 13:379ce1d51b88
- Parent:
- 1:7298a7950f65
--- a/GPRS/GPRS.h Tue Mar 10 03:11:38 2015 +0000 +++ b/GPRS/GPRS.h Fri Apr 03 15:44:04 2015 +0800 @@ -27,7 +27,7 @@ #include "modem.h" #define DEFAULT_WAIT_RESP_TIMEOUT 500 -#define MAX_SOCK_NUM 7 //(0~6) +#define MAX_SOCK_NUM 7 // (0~6) enum Protocol { CLOSED = 0, @@ -47,7 +47,7 @@ * @param userName apn's username, usually is NULL * @param passWord apn's password, usually is NULL */ - GPRS(PinName tx, PinName rx, int baudRate, const char* apn, const char* userName = NULL, const char *passWord = NULL); + GPRS(PinName tx, PinName rx, const char* apn, const char* userName = NULL, const char *passWord = NULL); /** get instance of GPRS class */ @@ -75,10 +75,10 @@ * @param ptl protocol for socket, TCP/UDP can be choosen * @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established) * @param port port - * @param timeout wait seconds till connected + * @param timeout wait time (ms) * @returns true if successful */ - bool connect(int socket, Protocol ptl, const char * host, int port, int timeout = DEFAULT_TIMEOUT); + bool connect(int socket, Protocol ptl, const char * host, int port, int timeout = DEFAULT_TIMEOUT_MS); /** Set the protocol (UDP or TCP) * @param socket socket @@ -91,11 +91,6 @@ */ void reset(); - /** check if GPRS module is readable or not - * @returns true if readable - */ - bool readable(void); - /** wait a few time to check if GPRS module is readable or not * @param socket socket * @param wait_time time of waiting @@ -119,7 +114,7 @@ * @param len string length * @returns return bytes that actually been send */ - int send(int socket, const char * str, int len); + int sock_send(int socket, const char * str, int len); /** read data from socket * @param socket socket @@ -127,7 +122,7 @@ * @param len string length need to read from socket * @returns bytes that actually read */ - int recv(int socket, char* buf, int len); + int sock_recv(int socket, char* buf, int len); /** convert the host to ip * @param host host ip string, ex. 10.11.12.13 @@ -138,18 +133,18 @@ int new_socket(); uint16_t new_port(); - uint32_t _ip; + uint32_t _ip; + protected: - - bool preInit(); - bool checkSIMStatus(void); - uint32_t str_to_ip(const char* str); static GPRS* inst; int socketID; const char* _apn; const char* _userName; - const char* _passWord; + const char* _passWord; + bool connected; + uint8_t recv_buf[32]; // for + uint8_t recv_bytes; }; #endif