Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Dependencies:   GPS_CanSat mbed

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