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 wei zou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers modem.h Source File

modem.h

00001 /*
00002   modem.h
00003   2014 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet zou(lawliet.zou@gmail.com)
00006   2014-2-24
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 #ifndef __MODEM_H__
00024 #define __MODEM_H__
00025 
00026 #if defined(TARGET_LPC11UXX) || defined (TARGET_LPC176X)
00027 #include "BufferedSerial.h"
00028 #define INTERFACE_BASE      BufferedSerial
00029 #else
00030 #include "mbed.h"
00031 #define INTERFACE_BASE      Serial
00032 #endif
00033 
00034 #define DEFAULT_TIMEOUT_MS      30000
00035 
00036 
00037 /** Modem class.
00038  *  Used for Modem communication. attention that Modem module communicate with MCU in serial protocol
00039  */
00040 class Modem : public INTERFACE_BASE
00041 {
00042 
00043 public:
00044     /** Create Modem Instance
00045      *  @param tx   uart transmit pin to communicate with Modem
00046      *  @param rx   uart receive pin to communicate with Modem
00047      */
00048     Modem(PinName tx, PinName rx) : INTERFACE_BASE(tx, rx) {
00049         baud(115200);
00050     };
00051 
00052 protected:
00053     /** Read a line
00054      * @param buf   the buffer to store a line
00055      * @param len   size of the buffer
00056      * @param timeout   wait time (ms)
00057      * @return -1 if timeout, length of the line if otherwise
00058      */
00059     int readline(char *buf, int len, uint32_t timeout = DEFAULT_TIMEOUT_MS);
00060 
00061     int command(const char* format, ...);
00062 
00063     int match(const char *resp, uint32_t timeout = DEFAULT_TIMEOUT_MS);
00064 
00065     void flush();
00066     uint8_t read();
00067 
00068 private:
00069     Timer timer;
00070 };
00071 
00072 #endif