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:
DeWayneDennis
Date:
Wed Oct 21 19:41:42 2015 +0000
Revision:
11:045cb766d9a5
Parent:
10:8c55dfcc9a7c
Changed GPR Interface to work with pushingbox

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