works through pushing box to log data to google spreadsheet

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed

Fork of GPR_Interface by DCS_TEAM

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 #include "mbed.h"
00027 #include "SDFileSystem.h"
00028 #define DEFAULT_TIMEOUT 5
00029 
00030 enum DataType {
00031     CMD     = 0,
00032     DATA    = 1,
00033 };
00034 
00035 /** Modem class.
00036  *  Used for Modem communication. attention that Modem module communicate with MCU in serial protocol
00037  */
00038 class Modem
00039 {
00040 
00041 public:
00042     /** Create Modem Instance
00043      *  @param tx   uart transmit pin to communicate with Modem
00044      *  @param rx   uart receive pin to communicate with Modem
00045      *  @param baudRate baud rate of uart communication
00046      */
00047     Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) {
00048         serialModem.baud(baudRate);
00049     };
00050     // added by Noah Milam
00051     char IPAdd[100];
00052     void sendCmdResp(const char*);
00053     void getResp();
00054     void gprs_response();
00055     void storeResp();
00056     void wait_for_sms();
00057     void get_message();
00058     char* get_server_IP();
00059     //
00060     Serial serialModem;
00061 protected:
00062     /** Power on Modem
00063      */
00064     void preInit(void);
00065 
00066     /** check serialModem is readable or not
00067      *  @returns
00068      *      true on readable
00069      *      false on not readable
00070      */
00071     bool readable();
00072 
00073     /** read one byte from serialModem
00074      *  @returns
00075      *      one byte read from serialModem
00076      */
00077     char readByte(void);
00078 
00079     /** read from Modem module and save to buffer array
00080      *  @param  buffer  buffer array to save what read from Modem module
00081      *  @param  count   the maximal bytes number read from Modem module
00082      *  @param  timeOut time to wait for reading from Modem module
00083      *  @returns
00084      *      0 on success
00085      *      -1 on error
00086      */
00087     int readBuffer(char* buffer,int count, unsigned int timeOut);
00088 
00089 
00090     /** clean Buffer
00091      *  @param buffer   buffer to clean
00092      *  @param count    number of bytes to clean
00093      */
00094     void cleanBuffer(char* buffer, int count);
00095 
00096     /** send AT command to Modem module
00097      *  @param cmd  command array which will be send to GPRS module
00098      */
00099     void sendCmd(const char* cmd);
00100 
00101     /**send "AT" to Modem module
00102      */
00103     void sendATTest(void);
00104 
00105     /** compare the response from GPRS module with a string
00106      *  @param resp buffer to be compared
00107      *  @param len length that will be compared
00108      *  @param timeout  waiting seconds till timeout
00109      */
00110     bool respCmp(const char *resp, unsigned int len, unsigned int timeout);
00111 
00112     /** check Modem module response before time out
00113      *  @param  *resp   correct response which Modem module will return
00114      *  @param  *timeout    waiting seconds till timeout
00115      *  @returns
00116      *      0 on success
00117      *      -1 on error
00118      */
00119     int waitForResp(const char *resp, unsigned int timeout,DataType type);
00120 
00121     /** send AT command to GPRS module and wait for correct response
00122      *  @param  *cmd    AT command which will be send to GPRS module
00123      *  @param  *resp   correct response which GPRS module will return
00124      *  @param  *timeout    waiting seconds till timeout
00125      *  @returns
00126      *      0 on success
00127      *      -1 on error
00128      */
00129     int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
00130 
00131     Timer timeCnt;
00132 
00133 private:
00134 
00135 };
00136 
00137 #endif