works through pushing box to log data to google spreadsheet

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed

Fork of GPR_Interface by DCS_TEAM

Committer:
lawliet
Date:
Tue Feb 25 02:52:48 2014 +0000
Revision:
0:8ccbd963e74d
Child:
1:7298a7950f65
Initial version of GPRS Interface

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
lawliet 0:8ccbd963e74d 26 #include "mbed.h"
lawliet 0:8ccbd963e74d 27
lawliet 0:8ccbd963e74d 28 #define DEFAULT_TIMEOUT 5
lawliet 0:8ccbd963e74d 29
lawliet 0:8ccbd963e74d 30 enum DataType {
lawliet 0:8ccbd963e74d 31 CMD = 0,
lawliet 0:8ccbd963e74d 32 DATA = 1,
lawliet 0:8ccbd963e74d 33 };
lawliet 0:8ccbd963e74d 34
lawliet 0:8ccbd963e74d 35 /** Modem class.
lawliet 0:8ccbd963e74d 36 * Used for Modem communication. attention that Modem module communicate with MCU in serial protocol
lawliet 0:8ccbd963e74d 37 */
lawliet 0:8ccbd963e74d 38 class Modem
lawliet 0:8ccbd963e74d 39 {
lawliet 0:8ccbd963e74d 40
lawliet 0:8ccbd963e74d 41 public:
lawliet 0:8ccbd963e74d 42 /** Create Modem Instance
lawliet 0:8ccbd963e74d 43 * @param tx uart transmit pin to communicate with Modem
lawliet 0:8ccbd963e74d 44 * @param rx uart receive pin to communicate with Modem
lawliet 0:8ccbd963e74d 45 * @param baudRate baud rate of uart communication
lawliet 0:8ccbd963e74d 46 */
lawliet 0:8ccbd963e74d 47 Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) {
lawliet 0:8ccbd963e74d 48 serialModem.baud(baudRate);
lawliet 0:8ccbd963e74d 49 };
lawliet 0:8ccbd963e74d 50
lawliet 0:8ccbd963e74d 51 /** Power on Modem
lawliet 0:8ccbd963e74d 52 */
lawliet 0:8ccbd963e74d 53 void preInit(void);
lawliet 0:8ccbd963e74d 54
lawliet 0:8ccbd963e74d 55 /** check serialModem is readable or not
lawliet 0:8ccbd963e74d 56 * @returns
lawliet 0:8ccbd963e74d 57 * true on readable
lawliet 0:8ccbd963e74d 58 * false on not readable
lawliet 0:8ccbd963e74d 59 */
lawliet 0:8ccbd963e74d 60 bool readable();
lawliet 0:8ccbd963e74d 61
lawliet 0:8ccbd963e74d 62 /** read one byte from serialModem
lawliet 0:8ccbd963e74d 63 * @returns
lawliet 0:8ccbd963e74d 64 * one byte read from serialModem
lawliet 0:8ccbd963e74d 65 */
lawliet 0:8ccbd963e74d 66 char readByte(void);
lawliet 0:8ccbd963e74d 67
lawliet 0:8ccbd963e74d 68 /** read from Modem module and save to buffer array
lawliet 0:8ccbd963e74d 69 * @param buffer buffer array to save what read from Modem module
lawliet 0:8ccbd963e74d 70 * @param count the maximal bytes number read from Modem module
lawliet 0:8ccbd963e74d 71 * @param timeOut time to wait for reading from Modem module
lawliet 0:8ccbd963e74d 72 * @returns
lawliet 0:8ccbd963e74d 73 * 0 on success
lawliet 0:8ccbd963e74d 74 * -1 on error
lawliet 0:8ccbd963e74d 75 */
lawliet 0:8ccbd963e74d 76 int readBuffer(char* buffer,int count, unsigned int timeOut);
lawliet 0:8ccbd963e74d 77
lawliet 0:8ccbd963e74d 78
lawliet 0:8ccbd963e74d 79 /** clean Buffer
lawliet 0:8ccbd963e74d 80 * @param buffer buffer to clean
lawliet 0:8ccbd963e74d 81 * @param count number of bytes to clean
lawliet 0:8ccbd963e74d 82 */
lawliet 0:8ccbd963e74d 83 void cleanBuffer(char* buffer, int count);
lawliet 0:8ccbd963e74d 84
lawliet 0:8ccbd963e74d 85 /** send AT command to Modem module
lawliet 0:8ccbd963e74d 86 * @param cmd command array which will be send to GPRS module
lawliet 0:8ccbd963e74d 87 */
lawliet 0:8ccbd963e74d 88 void sendCmd(const char* cmd);
lawliet 0:8ccbd963e74d 89
lawliet 0:8ccbd963e74d 90 /**send "AT" to Modem module
lawliet 0:8ccbd963e74d 91 */
lawliet 0:8ccbd963e74d 92 void sendATTest(void);
lawliet 0:8ccbd963e74d 93
lawliet 0:8ccbd963e74d 94 /** compare the response from GPRS module with a string
lawliet 0:8ccbd963e74d 95 * @param resp buffer to be compared
lawliet 0:8ccbd963e74d 96 * @param len length that will be compared
lawliet 0:8ccbd963e74d 97 * @param timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 98 */
lawliet 0:8ccbd963e74d 99 bool respCmp(const char *resp, unsigned int len, unsigned int timeout);
lawliet 0:8ccbd963e74d 100
lawliet 0:8ccbd963e74d 101 /** check Modem module response before time out
lawliet 0:8ccbd963e74d 102 * @param *resp correct response which Modem module will return
lawliet 0:8ccbd963e74d 103 * @param *timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 104 * @returns
lawliet 0:8ccbd963e74d 105 * 0 on success
lawliet 0:8ccbd963e74d 106 * -1 on error
lawliet 0:8ccbd963e74d 107 */
lawliet 0:8ccbd963e74d 108 int waitForResp(const char *resp, unsigned int timeout,DataType type);
lawliet 0:8ccbd963e74d 109
lawliet 0:8ccbd963e74d 110 /** send AT command to GPRS module and wait for correct response
lawliet 0:8ccbd963e74d 111 * @param *cmd AT command which will be send to GPRS module
lawliet 0:8ccbd963e74d 112 * @param *resp correct response which GPRS module will return
lawliet 0:8ccbd963e74d 113 * @param *timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 114 * @returns
lawliet 0:8ccbd963e74d 115 * 0 on success
lawliet 0:8ccbd963e74d 116 * -1 on error
lawliet 0:8ccbd963e74d 117 */
lawliet 0:8ccbd963e74d 118 int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
lawliet 0:8ccbd963e74d 119
lawliet 0:8ccbd963e74d 120
lawliet 0:8ccbd963e74d 121 /** used for serial debug, you can specify tx and rx pin and then communicate with GPRS module with common AT commands
lawliet 0:8ccbd963e74d 122 */
lawliet 0:8ccbd963e74d 123 void serialDebug(void);
lawliet 0:8ccbd963e74d 124
lawliet 0:8ccbd963e74d 125 Serial serialModem;
lawliet 0:8ccbd963e74d 126 Timer timeCnt;
lawliet 0:8ccbd963e74d 127
lawliet 0:8ccbd963e74d 128 private:
lawliet 0:8ccbd963e74d 129
lawliet 0:8ccbd963e74d 130 };
lawliet 0:8ccbd963e74d 131
lawliet 0:8ccbd963e74d 132 #endif