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:
Mon Apr 28 13:01:23 2014 +0000
Revision:
6:464ccda1ebcc
Parent:
1:7298a7950f65
Child:
10:8c55dfcc9a7c
make SerialModel to be public member.

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 6:464ccda1ebcc 50
lawliet 6:464ccda1ebcc 51 Serial serialModem;
lawliet 1:7298a7950f65 52 protected:
lawliet 0:8ccbd963e74d 53 /** Power on Modem
lawliet 0:8ccbd963e74d 54 */
lawliet 0:8ccbd963e74d 55 void preInit(void);
lawliet 0:8ccbd963e74d 56
lawliet 0:8ccbd963e74d 57 /** check serialModem is readable or not
lawliet 0:8ccbd963e74d 58 * @returns
lawliet 0:8ccbd963e74d 59 * true on readable
lawliet 0:8ccbd963e74d 60 * false on not readable
lawliet 0:8ccbd963e74d 61 */
lawliet 0:8ccbd963e74d 62 bool readable();
lawliet 0:8ccbd963e74d 63
lawliet 0:8ccbd963e74d 64 /** read one byte from serialModem
lawliet 0:8ccbd963e74d 65 * @returns
lawliet 0:8ccbd963e74d 66 * one byte read from serialModem
lawliet 0:8ccbd963e74d 67 */
lawliet 0:8ccbd963e74d 68 char readByte(void);
lawliet 0:8ccbd963e74d 69
lawliet 0:8ccbd963e74d 70 /** read from Modem module and save to buffer array
lawliet 0:8ccbd963e74d 71 * @param buffer buffer array to save what read from Modem module
lawliet 0:8ccbd963e74d 72 * @param count the maximal bytes number read from Modem module
lawliet 0:8ccbd963e74d 73 * @param timeOut time to wait for reading from Modem module
lawliet 0:8ccbd963e74d 74 * @returns
lawliet 0:8ccbd963e74d 75 * 0 on success
lawliet 0:8ccbd963e74d 76 * -1 on error
lawliet 0:8ccbd963e74d 77 */
lawliet 0:8ccbd963e74d 78 int readBuffer(char* buffer,int count, unsigned int timeOut);
lawliet 0:8ccbd963e74d 79
lawliet 0:8ccbd963e74d 80
lawliet 0:8ccbd963e74d 81 /** clean Buffer
lawliet 0:8ccbd963e74d 82 * @param buffer buffer to clean
lawliet 0:8ccbd963e74d 83 * @param count number of bytes to clean
lawliet 0:8ccbd963e74d 84 */
lawliet 0:8ccbd963e74d 85 void cleanBuffer(char* buffer, int count);
lawliet 0:8ccbd963e74d 86
lawliet 0:8ccbd963e74d 87 /** send AT command to Modem module
lawliet 0:8ccbd963e74d 88 * @param cmd command array which will be send to GPRS module
lawliet 0:8ccbd963e74d 89 */
lawliet 0:8ccbd963e74d 90 void sendCmd(const char* cmd);
lawliet 0:8ccbd963e74d 91
lawliet 0:8ccbd963e74d 92 /**send "AT" to Modem module
lawliet 0:8ccbd963e74d 93 */
lawliet 0:8ccbd963e74d 94 void sendATTest(void);
lawliet 0:8ccbd963e74d 95
lawliet 0:8ccbd963e74d 96 /** compare the response from GPRS module with a string
lawliet 0:8ccbd963e74d 97 * @param resp buffer to be compared
lawliet 0:8ccbd963e74d 98 * @param len length that will be compared
lawliet 0:8ccbd963e74d 99 * @param timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 100 */
lawliet 0:8ccbd963e74d 101 bool respCmp(const char *resp, unsigned int len, unsigned int timeout);
lawliet 0:8ccbd963e74d 102
lawliet 0:8ccbd963e74d 103 /** check Modem module response before time out
lawliet 0:8ccbd963e74d 104 * @param *resp correct response which Modem module will return
lawliet 0:8ccbd963e74d 105 * @param *timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 106 * @returns
lawliet 0:8ccbd963e74d 107 * 0 on success
lawliet 0:8ccbd963e74d 108 * -1 on error
lawliet 0:8ccbd963e74d 109 */
lawliet 0:8ccbd963e74d 110 int waitForResp(const char *resp, unsigned int timeout,DataType type);
lawliet 0:8ccbd963e74d 111
lawliet 0:8ccbd963e74d 112 /** send AT command to GPRS module and wait for correct response
lawliet 0:8ccbd963e74d 113 * @param *cmd AT command which will be send to GPRS module
lawliet 0:8ccbd963e74d 114 * @param *resp correct response which GPRS module will return
lawliet 0:8ccbd963e74d 115 * @param *timeout waiting seconds till timeout
lawliet 0:8ccbd963e74d 116 * @returns
lawliet 0:8ccbd963e74d 117 * 0 on success
lawliet 0:8ccbd963e74d 118 * -1 on error
lawliet 0:8ccbd963e74d 119 */
lawliet 0:8ccbd963e74d 120 int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
lawliet 0:8ccbd963e74d 121
lawliet 0:8ccbd963e74d 122 Timer timeCnt;
lawliet 0:8ccbd963e74d 123
lawliet 0:8ccbd963e74d 124 private:
lawliet 0:8ccbd963e74d 125
lawliet 0:8ccbd963e74d 126 };
lawliet 0:8ccbd963e74d 127
lawliet 0:8ccbd963e74d 128 #endif