uses pushing box to write to google spreadsheets

Dependencies:   GSM_PUSHING_BOX_STATE_MACHINE MBed_Adafruit-GPS-Library SDFileSystem mbed

Fork of DCS by DCS_TEAM

Embed: (wiki syntax)

« Back to documentation index

GPRS Class Reference

The GPRS class. More...

#include <GPRS.h>

Inherits Modem.

Inherited by GPRSInterface.

Public Member Functions

 GPRS (PinName tx, PinName rx, int baudRate, const char *apn, const char *userName=NULL, const char *passWord=NULL)
 Constructor.
bool join (void)
 Connect the GPRS module to the network.
bool disconnect (void)
 Disconnect the GPRS module from the network.
bool close (int socket)
 Close a tcp connection.
bool connect (int socket, Protocol ptl, const char *host, int port, int timeout=DEFAULT_TIMEOUT)
 Open a tcp/udp connection with the specified host on the specified port.
bool setProtocol (int socket, Protocol p)
 Set the protocol (UDP or TCP)
void reset ()
 Reset the GPRS module.
bool readable (void)
 Check if GPRS module is readable or not.
int wait_readable (int socket, int wait_time)
 Wait a few time to check if GPRS module is readable or not.
int wait_writeable (int socket, int req_size)
 Wait a few time to check if GPRS module is writeable or not.
bool is_connected (int socket)
 Check if a tcp link is active.
int send (int socket, const char *str, int len)
 Send data to socket.
int recv (int socket, char *buf, int len)
 Read data from socket.
bool gethostbyname (const char *host, uint32_t *ip)
 Convert the host to ip.
bool preInit ()
 Power on Modem.

Static Public Member Functions

static GPRSgetInstance ()
 Get instance of GPRS class.

Protected Member Functions

char readByte (void)
 read one byte from serialModem
int readBuffer (char *buffer, int count, unsigned int timeOut)
 read from Modem module and save to buffer array
void cleanBuffer (char *buffer, int count)
 clean Buffer
void sendCmd (const char *cmd)
 send AT command to Modem module
void sendATTest (void)
 send "AT" to Modem module
bool respCmp (const char *resp, unsigned int len, unsigned int timeout)
 compare the response from GPRS module with a string
int waitForResp (const char *resp, unsigned int timeout, DataType type)
 check Modem module response before time out
int sendCmdAndWaitForResp (const char *data, const char *resp, unsigned timeout, DataType type)
 send AT command to GPRS module and wait for correct response

Detailed Description

The GPRS class.

Definition at line 41 of file GPRS.h.


Constructor & Destructor Documentation

GPRS ( PinName  tx,
PinName  rx,
int  baudRate,
const char *  apn,
const char *  userName = NULL,
const char *  passWord = NULL 
)

Constructor.

Parameters:
txmbed pin to use for tx line of Serial interface
rxmbed pin to use for rx line of Serial interface
baudRateserial communicate baud rate
apnname of the gateway for GPRS to connect to the network
userNameapn's username, usually is NULL
passWordapn's password, usually is NULL

Definition at line 32 of file GPRS.cpp.


Member Function Documentation

void cleanBuffer ( char *  buffer,
int  count 
) [protected, inherited]

clean Buffer

Parameters:
bufferbuffer to clean
countnumber of bytes to clean

Definition at line 147 of file modem.cpp.

bool close ( int  socket )

Close a tcp connection.

Returns:
true if successful

Definition at line 305 of file GPRS.cpp.

bool connect ( int  socket,
Protocol  ptl,
const char *  host,
int  port,
int  timeout = DEFAULT_TIMEOUT 
)

Open a tcp/udp connection with the specified host on the specified port.

Parameters:
socketan endpoint of an inter-process communication flow of GPRS module,for SIM900 module, it is in [0,6]
ptlprotocol for socket, TCP/UDP can be choosen
hosthost (can be either an ip address or a name. If a name is provided, a dns request will be established)
portport
timeoutwait seconds till connected
Returns:
true if successful

Definition at line 242 of file GPRS.cpp.

bool disconnect ( void   )

Disconnect the GPRS module from the network.

Returns:
true if successful

Reimplemented in GPRSInterface.

Definition at line 278 of file GPRS.cpp.

bool gethostbyname ( const char *  host,
uint32_t *  ip 
)

Convert the host to ip.

Parameters:
hosthost ip string, ex. 10.11.12.13
iplong int ip address, ex. 0x11223344
Returns:
true if successful

Definition at line 266 of file GPRS.cpp.

static GPRS* getInstance (  ) [static]

Get instance of GPRS class.

Definition at line 57 of file GPRS.h.

bool is_connected ( int  socket )

Check if a tcp link is active.

Returns:
true if successful

Definition at line 284 of file GPRS.cpp.

bool join ( void   )

Connect the GPRS module to the network.

Returns:
true if connected, false otherwise

Definition at line 120 of file GPRS.cpp.

bool preInit (  )

Power on Modem.

Reimplemented from Modem.

Definition at line 41 of file GPRS.cpp.

bool readable ( void   )

Check if GPRS module is readable or not.

Returns:
true if readable

Reimplemented from Modem.

Definition at line 325 of file GPRS.cpp.

int readBuffer ( char *  buffer,
int  count,
unsigned int  timeOut 
) [protected, inherited]

read from Modem module and save to buffer array

Parameters:
bufferbuffer array to save what read from Modem module
countthe maximal bytes number read from Modem module
timeOuttime to wait for reading from Modem module
Returns:
0 on success -1 on error

Definition at line 127 of file modem.cpp.

char readByte ( void   ) [protected, inherited]

read one byte from serialModem

Returns:
one byte read from serialModem

Definition at line 117 of file modem.cpp.

int recv ( int  socket,
char *  buf,
int  len 
)

Read data from socket.

Parameters:
socketsocket
bufbuffer that will store the data read from socket
lenstring length need to read from socket
Returns:
bytes that actually read

Definition at line 383 of file GPRS.cpp.

void reset (  )

Reset the GPRS module.

Definition at line 301 of file GPRS.cpp.

bool respCmp ( const char *  resp,
unsigned int  len,
unsigned int  timeout 
) [protected, inherited]

compare the response from GPRS module with a string

Parameters:
respbuffer to be compared
lenlength that will be compared
timeoutwaiting seconds till timeout

Definition at line 190 of file modem.cpp.

int send ( int  socket,
const char *  str,
int  len 
)

Send data to socket.

Parameters:
socketsocket
strstring to be sent
lenstring length
Returns:
return bytes that actually been send

Definition at line 363 of file GPRS.cpp.

void sendATTest ( void   ) [protected, inherited]

send "AT" to Modem module

Definition at line 185 of file modem.cpp.

void sendCmd ( const char *  cmd ) [protected, inherited]

send AT command to Modem module

Parameters:
cmdcommand array which will be send to GPRS module

Definition at line 154 of file modem.cpp.

int sendCmdAndWaitForResp ( const char *  data,
const char *  resp,
unsigned  timeout,
DataType  type 
) [protected, inherited]

send AT command to GPRS module and wait for correct response

Parameters:
*cmdAT command which will be send to GPRS module
*respcorrect response which GPRS module will return
*timeoutwaiting seconds till timeout
Returns:
0 on success -1 on error

Definition at line 244 of file modem.cpp.

bool setProtocol ( int  socket,
Protocol  p 
)

Set the protocol (UDP or TCP)

Parameters:
socketsocket
pprotocol
Returns:
true if successful

Definition at line 233 of file GPRS.cpp.

int wait_readable ( int  socket,
int  wait_time 
)

Wait a few time to check if GPRS module is readable or not.

Parameters:
socketsocket
wait_timetime of waiting

Definition at line 330 of file GPRS.cpp.

int wait_writeable ( int  socket,
int  req_size 
)

Wait a few time to check if GPRS module is writeable or not.

Parameters:
socketsocket
wait_timetime of waiting

Definition at line 355 of file GPRS.cpp.

int waitForResp ( const char *  resp,
unsigned int  timeout,
DataType  type 
) [protected, inherited]

check Modem module response before time out

Parameters:
*respcorrect response which Modem module will return
*timeoutwaiting seconds till timeout
Returns:
0 on success -1 on error

Definition at line 213 of file modem.cpp.