PHS module APM-002 library. see: https://developer.mbed.org/users/phsfan/notebook/abitusbmodem/

Dependencies:   Socket lwip-sys lwip

Fork of AbitUSBModem by phs fan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AbitModemInterface.h Source File

AbitModemInterface.h

00001 /* AbitUSBModem.h */
00002 /* Modified by 2015 phsfan
00003  *  for ABIT SMA-01
00004  */
00005 /* VodafoneUSBModem.h */
00006 /* Copyright (C) 2012 mbed.org, MIT License
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00009  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00010  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00011  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in all copies or
00015  * substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00018  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00019  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00020  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022  */
00023 
00024 #ifndef _ABITUSBMODEM_H_
00025 #define _ABITUSBMODEM_H_
00026 
00027 #include "core/fwk.h"
00028 #include "mbed.h"
00029 
00030 #include "at/ATCommandsInterface.h"
00031 #include "serial/io/IOSerialStream.h"
00032 #include "ip/PPPIPInterface.h"
00033 #include "sms/SMSInterface.h"
00034 
00035 #define DEVICE_SERIAL_FC 1
00036 
00037 class AbitModemInterface {
00038 public:
00039   AbitModemInterface (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, int baud = 120000);
00040 
00041   /** Open a 3G internet connection
00042       @return 0 on success, error code on failure
00043   */
00044   int connect(const char* user = NULL, const char* password = NULL);
00045 
00046   /** Close the internet connection
00047      @return 0 on success, error code on failure
00048   */
00049   int disconnect();
00050 
00051   /** Send a SM
00052      @param number The receiver's phone number
00053      @param message The message to send
00054      @return 0 on success, error code on failure
00055    */
00056   int sendSM(const char* number, const char* message);
00057 
00058   /** Receive a SM
00059      @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char)
00060      @param message Pointer to a buffer to store the the incoming message
00061      @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
00062      @return 0 on success, error code on failure
00063    */
00064   int getSM(char* number, char* message, size_t maxLength);
00065 
00066   /** Get the IP address of a connected device
00067       @return A pointer to a string containing the IP address.
00068   */
00069   char* getIPAddress();
00070 
00071 protected:
00072   int init();
00073 
00074 private:
00075   mbed::RawSerial m_module;          //< Interface to USB connected WAN dongle
00076 #if !DEVICE_SERIAL_FC
00077   mbed::DigitalIn m_cts;
00078   mbed::DigitalOut m_rts;
00079 #endif
00080   mbed::DigitalInOut m_reset;
00081 
00082   IOSerialStream m_pppStream; //< Serial interface to PPP channel on modem
00083 
00084   ATCommandsInterface m_at;    //< Interface to AT commands processing
00085 
00086   SMSInterface m_sms;          //< Interface to SMS manager (send/receive etc)
00087 
00088   PPPIPInterface m_ppp;        //< Interface to PPP conection manager (IP assignment etc)
00089 
00090   bool m_moduleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
00091   bool m_ipInit;          //< Has PPIPInterface object (m_ppp) been initialised? true/false
00092   bool m_smsInit;         //< Has SMSInterface object (m_sms) been initialised? true/false
00093   bool m_atOpen;          //< Is the interface to the ATCommandsInterface open? true/false
00094 
00095 };
00096 
00097 #endif