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

Committer:
phsfan
Date:
Wed Jul 01 01:00:31 2015 +0000
Revision:
102:f5bcfb224067
Parent:
101:b330179423c8
fix flow control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phsfan 97:7d9cc95e2ea7 1 /* AbitUSBModem.h */
phsfan 97:7d9cc95e2ea7 2 /* Modified by 2015 phsfan
phsfan 97:7d9cc95e2ea7 3 * for ABIT SMA-01
phsfan 96:b50f5f795684 4 */
phsfan 96:b50f5f795684 5 /* VodafoneUSBModem.h */
phsfan 96:b50f5f795684 6 /* Copyright (C) 2012 mbed.org, MIT License
phsfan 96:b50f5f795684 7 *
phsfan 96:b50f5f795684 8 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
phsfan 96:b50f5f795684 9 * and associated documentation files (the "Software"), to deal in the Software without restriction,
phsfan 96:b50f5f795684 10 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
phsfan 96:b50f5f795684 11 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
phsfan 96:b50f5f795684 12 * furnished to do so, subject to the following conditions:
phsfan 96:b50f5f795684 13 *
phsfan 96:b50f5f795684 14 * The above copyright notice and this permission notice shall be included in all copies or
phsfan 96:b50f5f795684 15 * substantial portions of the Software.
phsfan 96:b50f5f795684 16 *
phsfan 96:b50f5f795684 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
phsfan 96:b50f5f795684 18 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
phsfan 96:b50f5f795684 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
phsfan 96:b50f5f795684 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
phsfan 96:b50f5f795684 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
phsfan 96:b50f5f795684 22 */
phsfan 96:b50f5f795684 23
phsfan 96:b50f5f795684 24 #ifndef _ABITUSBMODEM_H_
phsfan 96:b50f5f795684 25 #define _ABITUSBMODEM_H_
phsfan 96:b50f5f795684 26
phsfan 96:b50f5f795684 27 #include "core/fwk.h"
phsfan 100:dbd92e9515ef 28 #include "mbed.h"
phsfan 96:b50f5f795684 29
phsfan 97:7d9cc95e2ea7 30 #include "at/ATCommandsInterface.h"
phsfan 100:dbd92e9515ef 31 #include "serial/io/IOSerialStream.h"
phsfan 96:b50f5f795684 32 #include "ip/PPPIPInterface.h"
phsfan 97:7d9cc95e2ea7 33 #include "sms/SMSInterface.h"
phsfan 96:b50f5f795684 34
phsfan 102:f5bcfb224067 35 #define DEVICE_SERIAL_FC 1
phsfan 101:b330179423c8 36
phsfan 100:dbd92e9515ef 37 class AbitModemInterface {
phsfan 96:b50f5f795684 38 public:
phsfan 100:dbd92e9515ef 39 AbitModemInterface (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, int baud = 120000);
phsfan 96:b50f5f795684 40
phsfan 96:b50f5f795684 41 /** Open a 3G internet connection
phsfan 96:b50f5f795684 42 @return 0 on success, error code on failure
phsfan 96:b50f5f795684 43 */
phsfan 96:b50f5f795684 44 int connect(const char* user = NULL, const char* password = NULL);
phsfan 96:b50f5f795684 45
phsfan 96:b50f5f795684 46 /** Close the internet connection
phsfan 96:b50f5f795684 47 @return 0 on success, error code on failure
phsfan 96:b50f5f795684 48 */
phsfan 96:b50f5f795684 49 int disconnect();
phsfan 96:b50f5f795684 50
phsfan 97:7d9cc95e2ea7 51 /** Send a SM
phsfan 97:7d9cc95e2ea7 52 @param number The receiver's phone number
phsfan 97:7d9cc95e2ea7 53 @param message The message to send
phsfan 97:7d9cc95e2ea7 54 @return 0 on success, error code on failure
phsfan 97:7d9cc95e2ea7 55 */
phsfan 97:7d9cc95e2ea7 56 int sendSM(const char* number, const char* message);
phsfan 97:7d9cc95e2ea7 57
phsfan 97:7d9cc95e2ea7 58 /** Receive a SM
phsfan 97:7d9cc95e2ea7 59 @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)
phsfan 97:7d9cc95e2ea7 60 @param message Pointer to a buffer to store the the incoming message
phsfan 97:7d9cc95e2ea7 61 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
phsfan 97:7d9cc95e2ea7 62 @return 0 on success, error code on failure
phsfan 97:7d9cc95e2ea7 63 */
phsfan 97:7d9cc95e2ea7 64 int getSM(char* number, char* message, size_t maxLength);
phsfan 97:7d9cc95e2ea7 65
phsfan 96:b50f5f795684 66 /** Get the IP address of a connected device
phsfan 96:b50f5f795684 67 @return A pointer to a string containing the IP address.
phsfan 96:b50f5f795684 68 */
phsfan 96:b50f5f795684 69 char* getIPAddress();
phsfan 96:b50f5f795684 70
phsfan 96:b50f5f795684 71 protected:
phsfan 96:b50f5f795684 72 int init();
phsfan 96:b50f5f795684 73
phsfan 96:b50f5f795684 74 private:
phsfan 100:dbd92e9515ef 75 mbed::RawSerial m_module; //< Interface to USB connected WAN dongle
phsfan 101:b330179423c8 76 #if !DEVICE_SERIAL_FC
phsfan 100:dbd92e9515ef 77 mbed::DigitalIn m_cts;
phsfan 100:dbd92e9515ef 78 mbed::DigitalOut m_rts;
phsfan 101:b330179423c8 79 #endif
phsfan 101:b330179423c8 80 mbed::DigitalInOut m_reset;
phsfan 96:b50f5f795684 81
phsfan 100:dbd92e9515ef 82 IOSerialStream m_pppStream; //< Serial interface to PPP channel on modem
phsfan 96:b50f5f795684 83
phsfan 96:b50f5f795684 84 ATCommandsInterface m_at; //< Interface to AT commands processing
phsfan 96:b50f5f795684 85
phsfan 97:7d9cc95e2ea7 86 SMSInterface m_sms; //< Interface to SMS manager (send/receive etc)
phsfan 97:7d9cc95e2ea7 87
phsfan 96:b50f5f795684 88 PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc)
phsfan 96:b50f5f795684 89
phsfan 100:dbd92e9515ef 90 bool m_moduleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
phsfan 96:b50f5f795684 91 bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
phsfan 97:7d9cc95e2ea7 92 bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
phsfan 96:b50f5f795684 93 bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
phsfan 96:b50f5f795684 94
phsfan 96:b50f5f795684 95 };
phsfan 96:b50f5f795684 96
phsfan 96:b50f5f795684 97 #endif