DCS_TEAM / GPRS-server

Fork of GPRSInterface by -deleted-

Files at this revision

API Documentation at this revision

Comitter:
lawliet
Date:
Tue Feb 25 05:56:19 2014 +0000
Parent:
0:8ccbd963e74d
Child:
2:8cb3c0d45988
Commit message:
version 1.0(update some code)

Changed in this revision

GPRS/GPRS.h Show annotated file Show diff for this revision Revisions of this file
GPRS/modem/modem.h Show annotated file Show diff for this revision Revisions of this file
Socket/Endpoint.cpp Show diff for this revision Revisions of this file
Socket/Endpoint.h Show diff for this revision Revisions of this file
Socket/Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/Socket.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.h Show annotated file Show diff for this revision Revisions of this file
--- a/GPRS/GPRS.h	Tue Feb 25 02:52:48 2014 +0000
+++ b/GPRS/GPRS.h	Tue Feb 25 05:56:19 2014 +0000
@@ -49,6 +49,12 @@
      */
     GPRS(PinName tx, PinName rx, int baudRate, const char* apn, const char* userName = NULL, const char *passWord = NULL);
 
+    /** get instance of GPRS class
+     */
+    static GPRS* getInstance() {
+        return inst;
+    };
+
     /**	Connect the GPRS module to the network.
      * 	@return true if connected, false otherwise
      */
@@ -58,6 +64,11 @@
      * 	@returns true if successful
      */
     bool disconnect(void);
+    
+    /** Close a tcp connection
+     * 	@returns true if successful
+     */
+    bool close(int socket);
 
     /** Open a tcp/udp connection with the specified host on the specified port
      * 	@param socket an endpoint of an inter-process communication flow of GPRS module,for SIM900 module, it is in [0,6]
@@ -102,11 +113,6 @@
      */
     bool is_connected(int socket);
 
-    /** Close a tcp connection
-     * 	@returns true if successful
-     */
-    bool close(int socket);
-
     /** send data to socket
      *	@param socket socket
      *	@param str string to be sent
@@ -130,12 +136,6 @@
      */
     bool gethostbyname(const char* host, uint32_t* ip);
 
-    /** get instance of GPRS class
-     */
-    static GPRS* getInstance() {
-        return inst;
-    };
-
     int new_socket();
     uint16_t new_port();
     uint32_t _ip;
--- a/GPRS/modem/modem.h	Tue Feb 25 02:52:48 2014 +0000
+++ b/GPRS/modem/modem.h	Tue Feb 25 05:56:19 2014 +0000
@@ -47,7 +47,8 @@
     Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) {
         serialModem.baud(baudRate);
     };
-
+    
+protected:
     /** Power on Modem
      */
     void preInit(void);
@@ -117,11 +118,6 @@
      */
     int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
 
-
-    /** used for serial debug, you can specify tx and rx pin and then communicate with GPRS module with common AT commands
-     */
-    void serialDebug(void);
-
     Serial serialModem;
     Timer timeCnt;
 
--- a/Socket/Endpoint.cpp	Tue Feb 25 02:52:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*
-  Endpoint.cpp
-  2014 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Author:lawliet zou(lawliet.zou@gmail.com)
-  2014-2-24
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#include "Socket/Socket.h"
-#include "Socket/Endpoint.h"
-
-Endpoint::Endpoint()
-{
-    reset_address();
-}
-Endpoint::~Endpoint() {}
-
-void Endpoint::reset_address(void)
-{
-    _ipAddress[0] = '\0';
-    _port = 0;
-}
-
-int Endpoint::set_address(const char* host, const int port)
-{
-    //Resolve DNS address or populate hard-coded IP address
-    GPRS* gprs = GPRS::getInstance();
-    if (gprs == NULL) {
-        return -1;
-    }
-    uint32_t addr;
-    if (!gprs->gethostbyname(host, &addr)) {
-        return -1;
-    }
-    snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
-    _port = port;
-    return 0;
-}
-
-char* Endpoint::get_address()
-{
-    return _ipAddress;
-}
-
-int Endpoint::get_port()
-{
-    return _port;
-}
--- a/Socket/Endpoint.h	Tue Feb 25 02:52:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
-  Endpoint.h
-  2014 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Author:lawliet zou(lawliet.zou@gmail.com)
-  2014-2-24
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#ifndef ENDPOINT_H
-#define ENDPOINT_H
-
-#include "GPRS.h"
-
-class UDPSocket;
-
-/**
-IP Endpoint (address, port)
-*/
-class Endpoint {
-    friend class UDPSocket;
-
-public:
-    /** IP Endpoint (address, port)
-     */
-    Endpoint(void);
-    
-    ~Endpoint(void);
-    
-    /** Reset the address of this endpoint
-     */
-    void reset_address(void);
-    
-    /** Set the address of this endpoint
-    \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS).
-    \param port The endpoint port
-    \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS).
-     */
-    int  set_address(const char* host, const int port);
-    
-    /** Get the IP address of this endpoint
-    \return The IP address of this endpoint.
-     */
-    char* get_address(void);
-    
-    /** Get the port of this endpoint
-    \return The port of this endpoint
-     */
-    int get_port(void);
-
-protected:
-    char _ipAddress[16];
-    int _port;
-};
-
-#endif
--- a/Socket/Socket.cpp	Tue Feb 25 02:52:48 2014 +0000
+++ b/Socket/Socket.cpp	Tue Feb 25 05:56:19 2014 +0000
@@ -22,22 +22,17 @@
  
 #include "Socket.h"
 
-Socket::Socket() : _sock_fd(-1),_blocking(true), _timeout(1500) {
+Socket::Socket() : _sock_fd(-1) {
     gprs = GPRS::getInstance();
     if (gprs == NULL) {
-        error("Socket constructor error: no WIZ8820io instance available!\r\n");
+        error("Socket constructor error: no GPRS instance available!\r\n");
     }       
 }
 
-void Socket::set_blocking(bool blocking, unsigned int timeout) {
-    _blocking = blocking;
-    _timeout = timeout;
-}
-
 int Socket::close() {
     return (gprs->close(_sock_fd)) ? 0 : -1;
 }
 
 Socket::~Socket() {
-    close(); //Don't want to leak
+    close();
 }
--- a/Socket/Socket.h	Tue Feb 25 02:52:48 2014 +0000
+++ b/Socket/Socket.h	Tue Feb 25 05:56:19 2014 +0000
@@ -31,14 +31,7 @@
     /** Socket
      */
     Socket();
-    
-    /** Set blocking or non-blocking mode of the socket and a timeout on
-        blocking socket operations
-    \param blocking  true for blocking mode, false for non-blocking mode.
-    \param timeout   timeout in ms [Default: (1500)ms].
-    */
-    void set_blocking(bool blocking, unsigned int timeout=1500);
-    
+        
     /** Close the socket file descriptor
      */
     int close();
@@ -47,8 +40,6 @@
     
 protected:
     int _sock_fd;
-    bool _blocking;
-    int _timeout;
     GPRS* gprs;
 };
 
--- a/Socket/TCPSocketConnection.h	Tue Feb 25 02:52:48 2014 +0000
+++ b/Socket/TCPSocketConnection.h	Tue Feb 25 05:56:19 2014 +0000
@@ -24,12 +24,10 @@
 #define TCPSOCKET_H
 
 #include "Socket.h"
-#include "Endpoint.h"
 
-/**
-TCP socket connection
-*/
-class TCPSocketConnection: public Socket, public Endpoint
+/** TCP socket connection
+ */
+class TCPSocketConnection: public Socket
 {
     friend class TCPSocketServer;