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

Committer:
yihui
Date:
Fri Apr 03 09:51:13 2015 +0000
Revision:
14:3c6454f033ac
Parent:
13:379ce1d51b88
bugfix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:8ccbd963e74d 1 /*
lawliet 0:8ccbd963e74d 2 modem.h
lawliet 0:8ccbd963e74d 3 2014 Copyright (c) Seeed Technology Inc. All right reserved.
lawliet 0:8ccbd963e74d 4
lawliet 0:8ccbd963e74d 5 Author:lawliet zou(lawliet.zou@gmail.com)
lawliet 0:8ccbd963e74d 6 2014-2-24
lawliet 0:8ccbd963e74d 7
lawliet 0:8ccbd963e74d 8 This library is free software; you can redistribute it and/or
lawliet 0:8ccbd963e74d 9 modify it under the terms of the GNU Lesser General Public
lawliet 0:8ccbd963e74d 10 License as published by the Free Software Foundation; either
lawliet 0:8ccbd963e74d 11 version 2.1 of the License, or (at your option) any later version.
lawliet 0:8ccbd963e74d 12
lawliet 0:8ccbd963e74d 13 This library is distributed in the hope that it will be useful,
lawliet 0:8ccbd963e74d 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
lawliet 0:8ccbd963e74d 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
lawliet 0:8ccbd963e74d 16 Lesser General Public License for more details.
lawliet 0:8ccbd963e74d 17
lawliet 0:8ccbd963e74d 18 You should have received a copy of the GNU Lesser General Public
lawliet 0:8ccbd963e74d 19 License along with this library; if not, write to the Free Software
lawliet 0:8ccbd963e74d 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
lawliet 0:8ccbd963e74d 21 */
lawliet 0:8ccbd963e74d 22
lawliet 0:8ccbd963e74d 23 #ifndef __MODEM_H__
lawliet 0:8ccbd963e74d 24 #define __MODEM_H__
lawliet 0:8ccbd963e74d 25
Yihui Xiong 13:379ce1d51b88 26 #if defined(TARGET_LPC11UXX) || defined (TARGET_LPC176X)
Yihui Xiong 13:379ce1d51b88 27 #include "BufferedSerial.h"
Yihui Xiong 13:379ce1d51b88 28 #define INTERFACE_BASE BufferedSerial
yihui 12:47488369a980 29 #else
Yihui Xiong 13:379ce1d51b88 30 #include "mbed.h"
Yihui Xiong 13:379ce1d51b88 31 #define INTERFACE_BASE Serial
yihui 12:47488369a980 32 #endif
lawliet 0:8ccbd963e74d 33
Yihui Xiong 13:379ce1d51b88 34 #define DEFAULT_TIMEOUT_MS 30000
lawliet 0:8ccbd963e74d 35
lawliet 0:8ccbd963e74d 36
lawliet 0:8ccbd963e74d 37 /** Modem class.
lawliet 0:8ccbd963e74d 38 * Used for Modem communication. attention that Modem module communicate with MCU in serial protocol
lawliet 0:8ccbd963e74d 39 */
Yihui Xiong 13:379ce1d51b88 40 class Modem : public INTERFACE_BASE
lawliet 0:8ccbd963e74d 41 {
lawliet 0:8ccbd963e74d 42
lawliet 0:8ccbd963e74d 43 public:
lawliet 0:8ccbd963e74d 44 /** Create Modem Instance
lawliet 0:8ccbd963e74d 45 * @param tx uart transmit pin to communicate with Modem
lawliet 0:8ccbd963e74d 46 * @param rx uart receive pin to communicate with Modem
lawliet 0:8ccbd963e74d 47 */
Yihui Xiong 13:379ce1d51b88 48 Modem(PinName tx, PinName rx) : INTERFACE_BASE(tx, rx) {
Yihui Xiong 13:379ce1d51b88 49 baud(115200);
lawliet 0:8ccbd963e74d 50 };
Yihui Xiong 13:379ce1d51b88 51
lawliet 1:7298a7950f65 52 protected:
Yihui Xiong 13:379ce1d51b88 53 /** Read a line
Yihui Xiong 13:379ce1d51b88 54 * @param buf the buffer to store a line
Yihui Xiong 13:379ce1d51b88 55 * @param len size of the buffer
Yihui Xiong 13:379ce1d51b88 56 * @param timeout wait time (ms)
Yihui Xiong 13:379ce1d51b88 57 * @return -1 if timeout, length of the line if otherwise
Yihui Xiong 13:379ce1d51b88 58 */
Yihui Xiong 13:379ce1d51b88 59 int readline(char *buf, int len, uint32_t timeout = DEFAULT_TIMEOUT_MS);
Yihui Xiong 13:379ce1d51b88 60
Yihui Xiong 13:379ce1d51b88 61 int command(const char* format, ...);
Yihui Xiong 13:379ce1d51b88 62
Yihui Xiong 13:379ce1d51b88 63 int match(const char *resp, uint32_t timeout = DEFAULT_TIMEOUT_MS);
Yihui Xiong 13:379ce1d51b88 64
Yihui Xiong 13:379ce1d51b88 65 void flush();
Yihui Xiong 13:379ce1d51b88 66 uint8_t read();
Yihui Xiong 13:379ce1d51b88 67
Yihui Xiong 13:379ce1d51b88 68 private:
Yihui Xiong 13:379ce1d51b88 69 Timer timer;
lawliet 0:8ccbd963e74d 70 };
lawliet 0:8ccbd963e74d 71
lawliet 0:8ccbd963e74d 72 #endif