DCS_TEAM / GPRS-server

Fork of GPRSInterface by -deleted-

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     void sendCmdResp(const char*);
00052     void getResp();
00053     void gprs_response();
00054     void store_response();
00055     void wait_for_sms();
00056     //
00057     Serial serialModem;
00058 protected:
00059     /** Power on Modem
00060      */
00061     void preInit(void);
00062 
00063     /** check serialModem is readable or not
00064      *  @returns
00065      *      true on readable
00066      *      false on not readable
00067      */
00068     bool readable();
00069 
00070     /** read one byte from serialModem
00071      *  @returns
00072      *      one byte read from serialModem
00073      */
00074     char readByte(void);
00075 
00076     /** read from Modem module and save to buffer array
00077      *  @param  buffer  buffer array to save what read from Modem module
00078      *  @param  count   the maximal bytes number read from Modem module
00079      *  @param  timeOut time to wait for reading from Modem module
00080      *  @returns
00081      *      0 on success
00082      *      -1 on error
00083      */
00084     int readBuffer(char* buffer,int count, unsigned int timeOut);
00085 
00086 
00087     /** clean Buffer
00088      *  @param buffer   buffer to clean
00089      *  @param count    number of bytes to clean
00090      */
00091     void cleanBuffer(char* buffer, int count);
00092 
00093     /** send AT command to Modem module
00094      *  @param cmd  command array which will be send to GPRS module
00095      */
00096     void sendCmd(const char* cmd);
00097 
00098     /**send "AT" to Modem module
00099      */
00100     void sendATTest(void);
00101 
00102     /** compare the response from GPRS module with a string
00103      *  @param resp buffer to be compared
00104      *  @param len length that will be compared
00105      *  @param timeout  waiting seconds till timeout
00106      */
00107     bool respCmp(const char *resp, unsigned int len, unsigned int timeout);
00108 
00109     /** check Modem module response before time out
00110      *  @param  *resp   correct response which Modem module will return
00111      *  @param  *timeout    waiting seconds till timeout
00112      *  @returns
00113      *      0 on success
00114      *      -1 on error
00115      */
00116     int waitForResp(const char *resp, unsigned int timeout,DataType type);
00117 
00118     /** send AT command to GPRS module and wait for correct response
00119      *  @param  *cmd    AT command which will be send to GPRS module
00120      *  @param  *resp   correct response which GPRS module will return
00121      *  @param  *timeout    waiting seconds till timeout
00122      *  @returns
00123      *      0 on success
00124      *      -1 on error
00125      */
00126     int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
00127 
00128     Timer timeCnt;
00129 
00130 private:
00131 
00132 };
00133 
00134 #endif