support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.

Committer:
mazgch
Date:
Thu Aug 20 13:47:29 2015 +0000
Revision:
125:25a292afbac6
Parent:
124:65eb7d58f2da
Child:
126:bfbb9e19f6e0
- moved from individual modules to module series ; - added workarounds for TOBY-L2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 17:296d94a006b4 1 #pragma once
mazgch 17:296d94a006b4 2
mazgch 17:296d94a006b4 3 #include "mbed.h"
mazgch 21:c4d64830bf02 4 #include <stdarg.h>
mazgch 21:c4d64830bf02 5
mazgch 18:e5697801df29 6 #include "Pipe.h"
mazgch 18:e5697801df29 7 #include "SerialPipe.h"
mazgch 17:296d94a006b4 8
mazgch 123:66cef6353b13 9 #if 0//def TARGET_UBLOX_C027
mazgch 75:ce6e12067d0c 10 #define MDM_IF(onboard,shield) onboard
mazgch 19:2b5d097ca15d 11 #else
mazgch 75:ce6e12067d0c 12 #define MDM_IF(onboard,shield) shield
mazgch 19:2b5d097ca15d 13 #endif
mazgch 18:e5697801df29 14
mazgch 74:208e3e32d263 15 //! include debug capabilty on more powerful targets with a dedicated debug port
mazgch 74:208e3e32d263 16 #if defined(TARGET_LPC1768) || defined(TARGET_LPC4088) || defined(TARGET_K64F)
mazgch 74:208e3e32d263 17 #define MDM_DEBUG
mazgch 74:208e3e32d263 18 #endif
mazgch 74:208e3e32d263 19
mazgch 38:e6cab4632d84 20 /** basic modem parser class
mazgch 38:e6cab4632d84 21 */
mazgch 18:e5697801df29 22 class MDMParser
mazgch 18:e5697801df29 23 {
mazgch 18:e5697801df29 24 public:
mazgch 31:a0bed6c1e05d 25 //! Constructor
mazgch 76:f7c3dd568dae 26 MDMParser(void);
mazgch 44:9d12223b78ff 27 //! get static instance
mazgch 44:9d12223b78ff 28 static MDMParser* getInstance() { return inst; };
mazgch 31:a0bed6c1e05d 29
mazgch 31:a0bed6c1e05d 30 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 31 // Types
mazgch 31:a0bed6c1e05d 32 // ----------------------------------------------------------------
mazgch 38:e6cab4632d84 33 //! MT Device Types
mazgch 123:66cef6353b13 34 typedef enum { DEV_UNKNOWN,
mazgch 125:25a292afbac6 35 DEV_SARA_G35, DEV_LISA_U2, DEV_LISA_C2,
mazgch 125:25a292afbac6 36 DEV_SARA_U2, DEV_LEON_G2, DEV_TOBY_L2, DEV_MPCI_L2 } Dev;
mazgch 38:e6cab4632d84 37 //! SIM Status
mazgch 75:ce6e12067d0c 38 typedef enum { SIM_UNKNOWN, SIM_MISSING, SIM_PIN, SIM_READY } Sim;
mazgch 38:e6cab4632d84 39 //! SIM Status
mazgch 76:f7c3dd568dae 40 typedef enum { LPM_DISABLED, LPM_ENABLED, LPM_ACTIVE } Lpm;
mazgch 38:e6cab4632d84 41 //! Device status
mazgch 33:fb8fb5021b09 42 typedef struct {
mazgch 34:3b3b7807c0c3 43 Dev dev; //!< Device Type
mazgch 35:9275215a3a5b 44 Lpm lpm; //!< Power Saving
mazgch 34:3b3b7807c0c3 45 Sim sim; //!< SIM Card Status
mazgch 34:3b3b7807c0c3 46 char ccid[20+1]; //!< Integrated Circuit Card ID
mazgch 34:3b3b7807c0c3 47 char imsi[15+1]; //!< International Mobile Station Identity
mazgch 34:3b3b7807c0c3 48 char imei[15+1]; //!< International Mobile Equipment Identity
mazgch 34:3b3b7807c0c3 49 char meid[18+1]; //!< Mobile Equipment IDentifier
mazgch 34:3b3b7807c0c3 50 char manu[16]; //!< Manufacturer (u-blox)
mazgch 34:3b3b7807c0c3 51 char model[16]; //!< Model Name (LISA-U200, LISA-C200 or SARA-G350)
mazgch 34:3b3b7807c0c3 52 char ver[16]; //!< Software Version
mazgch 38:e6cab4632d84 53 } DevStatus;
mazgch 38:e6cab4632d84 54 //! Registration Status
mazgch 38:e6cab4632d84 55 typedef enum { REG_UNKNOWN, REG_DENIED, REG_NONE, REG_HOME, REG_ROAMING } Reg;
mazgch 38:e6cab4632d84 56 //! Access Technology
mazgch 123:66cef6353b13 57 typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA, ACT_LTE } AcT;
mazgch 38:e6cab4632d84 58 //! Network Status
mazgch 33:fb8fb5021b09 59 typedef struct {
mazgch 79:291df065e345 60 Reg csd; //!< CSD Registration Status (Circuit Switched Data)
mazgch 79:291df065e345 61 Reg psd; //!< PSD Registration status (Packet Switched Data)
mazgch 123:66cef6353b13 62 Reg eps; //!< EPS Registration status
mazgch 34:3b3b7807c0c3 63 AcT act; //!< Access Technology
mazgch 121:8da935c2c08c 64 int rssi; //!< Received Signal Strength Indication (in dBm, range -113..-51)
mazgch 54:7ba8e4c218e2 65 int ber; //!< Bit Error Rate (BER), see 3GPP TS 45.008 [20] subclause 8.2.4
mazgch 34:3b3b7807c0c3 66 char opr[16+1]; //!< Operator Name
mazgch 34:3b3b7807c0c3 67 char num[32]; //!< Mobile Directory Number
mazgch 54:7ba8e4c218e2 68 unsigned short lac; //!< location area code in hexadecimal format (2 bytes in hex)
mazgch 54:7ba8e4c218e2 69 unsigned int ci; //!< Cell ID in hexadecimal format (2 to 4 bytes in hex)
mazgch 38:e6cab4632d84 70 } NetStatus;
mazgch 38:e6cab4632d84 71 //! An IP v4 address
mazgch 38:e6cab4632d84 72 typedef uint32_t IP;
mazgch 33:fb8fb5021b09 73 #define NOIP ((MDMParser::IP)0) //!< No IP address
mazgch 31:a0bed6c1e05d 74 // ip number formating and conversion
mazgch 31:a0bed6c1e05d 75 #define IPSTR "%d.%d.%d.%d"
mazgch 31:a0bed6c1e05d 76 #define IPNUM(ip) ((ip)>>24)&0xff, \
mazgch 31:a0bed6c1e05d 77 ((ip)>>16)&0xff, \
mazgch 31:a0bed6c1e05d 78 ((ip)>> 8)&0xff, \
mazgch 31:a0bed6c1e05d 79 ((ip)>> 0)&0xff
mazgch 31:a0bed6c1e05d 80 #define IPADR(a,b,c,d) ((((IP)(a))<<24) | \
mazgch 31:a0bed6c1e05d 81 (((IP)(b))<<16) | \
mazgch 31:a0bed6c1e05d 82 (((IP)(c))<< 8) | \
mazgch 31:a0bed6c1e05d 83 (((IP)(d))<< 0))
mazgch 31:a0bed6c1e05d 84
mazgch 31:a0bed6c1e05d 85
mazgch 31:a0bed6c1e05d 86 // ----------------------------------------------------------------
mazgch 57:869bd35f44cc 87 // Device
mazgch 31:a0bed6c1e05d 88 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 89
mazgch 80:34985b4d821e 90 typedef enum { AUTH_NONE, AUTH_PAP, AUTH_CHAP, AUTH_DETECT } Auth;
mazgch 80:34985b4d821e 91
mazgch 57:869bd35f44cc 92 /** Combined Init, checkNetStatus, join suitable for simple applications
mazgch 57:869bd35f44cc 93 \param simpin a optional pin of the SIM card
mazgch 57:869bd35f44cc 94 \param apn the of the network provider e.g. "internet" or "apn.provider.com"
mazgch 57:869bd35f44cc 95 \param username is the user name text string for the authentication phase
mazgch 57:869bd35f44cc 96 \param password is the password text string for the authentication phase
mazgch 80:34985b4d821e 97 \param auth is the authentication mode (CHAP,PAP,NONE or DETECT)
mazgch 57:869bd35f44cc 98 \return true if successful, false otherwise
mazgch 57:869bd35f44cc 99 */
mazgch 94:d697fe11f3e5 100 bool connect(const char* simpin = NULL,
mazgch 94:d697fe11f3e5 101 const char* apn = NULL, const char* username = NULL,
mazgch 94:d697fe11f3e5 102 const char* password = NULL, Auth auth = AUTH_DETECT,
mazgch 75:ce6e12067d0c 103 PinName pn MDM_IF( = MDMPWRON, = D4));
mazgch 57:869bd35f44cc 104
mazgch 31:a0bed6c1e05d 105 /** register (Attach) the MT to the GPRS service.
mazgch 57:869bd35f44cc 106 \param simpin a optional pin of the SIM card
mazgch 31:a0bed6c1e05d 107 \param status an optional struture to with device information
mazgch 31:a0bed6c1e05d 108 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 109 */
mazgch 123:66cef6353b13 110 virtual bool init(const char* simpin = NULL, DevStatus* status = NULL,
mazgch 75:ce6e12067d0c 111 PinName pn MDM_IF( = MDMPWRON, = D4));
mazgch 123:66cef6353b13 112
mazgch 120:0e718a4ea25e 113 /** get the current device status
mazgch 120:0e718a4ea25e 114 \param strocture holding the device information.
mazgch 120:0e718a4ea25e 115 */
mazgch 123:66cef6353b13 116 void getDevStatus(MDMParser::DevStatus* dev) { memcpy(dev, &_dev, sizeof(DevStatus)); }
mazgch 75:ce6e12067d0c 117
mazgch 75:ce6e12067d0c 118 /** register to the network
mazgch 75:ce6e12067d0c 119 \param status an optional structure to with network information
mazgch 75:ce6e12067d0c 120 \param timeout_ms -1 blocking, else non blocking timeout in ms
mazgch 75:ce6e12067d0c 121 \return true if successful and connected to network, false otherwise
mazgch 75:ce6e12067d0c 122 */
mazgch 75:ce6e12067d0c 123 bool registerNet(NetStatus* status = NULL, int timeout_ms = 180000);
mazgch 31:a0bed6c1e05d 124
mazgch 31:a0bed6c1e05d 125 /** check if the network is available
mazgch 31:a0bed6c1e05d 126 \param status an optional structure to with network information
mazgch 31:a0bed6c1e05d 127 \return true if successful and connected to network, false otherwise
mazgch 31:a0bed6c1e05d 128 */
mazgch 31:a0bed6c1e05d 129 bool checkNetStatus(NetStatus* status = NULL);
mazgch 31:a0bed6c1e05d 130
mazgch 31:a0bed6c1e05d 131 /** Power off the MT, This function has to be called prior to
mazgch 31:a0bed6c1e05d 132 switching off the supply.
mazgch 31:a0bed6c1e05d 133 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 134 */
mazgch 31:a0bed6c1e05d 135 bool powerOff(void);
mazgch 31:a0bed6c1e05d 136
mazgch 31:a0bed6c1e05d 137 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 138 // Data Connection (GPRS)
mazgch 31:a0bed6c1e05d 139 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 140
mazgch 31:a0bed6c1e05d 141 /** register (Attach) the MT to the GPRS service.
mazgch 31:a0bed6c1e05d 142 \param apn the of the network provider e.g. "internet" or "apn.provider.com"
mazgch 57:869bd35f44cc 143 \param username is the user name text string for the authentication phase
mazgch 31:a0bed6c1e05d 144 \param password is the password text string for the authentication phase
mazgch 80:34985b4d821e 145 \param auth is the authentication mode (CHAP,PAP,NONE or DETECT)
mazgch 31:a0bed6c1e05d 146 \return the ip that is assigned
mazgch 31:a0bed6c1e05d 147 */
mazgch 79:291df065e345 148 MDMParser::IP join(const char* apn = NULL, const char* username = NULL,
mazgch 79:291df065e345 149 const char* password = NULL, Auth auth = AUTH_DETECT);
mazgch 31:a0bed6c1e05d 150
mazgch 31:a0bed6c1e05d 151 /** deregister (detach) the MT from the GPRS service.
mazgch 31:a0bed6c1e05d 152 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 153 */
mazgch 31:a0bed6c1e05d 154 bool disconnect(void);
mazgch 31:a0bed6c1e05d 155
mazgch 31:a0bed6c1e05d 156 /** Translates a domain name to an IP address
mazgch 31:a0bed6c1e05d 157 \param host the domain name to translate e.g. "u-blox.com"
mazgch 31:a0bed6c1e05d 158 \return the IP if successful, 0 otherwise
mazgch 31:a0bed6c1e05d 159 */
mazgch 31:a0bed6c1e05d 160 MDMParser::IP gethostbyname(const char* host);
mazgch 31:a0bed6c1e05d 161
mazgch 120:0e718a4ea25e 162 /** get the current assigned IP address
mazgch 120:0e718a4ea25e 163 \return the ip that is assigned
mazgch 120:0e718a4ea25e 164 */
mazgch 123:66cef6353b13 165 MDMParser::IP getIpAddress(void) { return _ip; }
mazgch 123:66cef6353b13 166
mazgch 31:a0bed6c1e05d 167 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 168 // Sockets
mazgch 31:a0bed6c1e05d 169 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 170
mazgch 31:a0bed6c1e05d 171 //! Type of IP protocol
mazgch 31:a0bed6c1e05d 172 typedef enum { IPPROTO_TCP, IPPROTO_UDP } IpProtocol;
mazgch 31:a0bed6c1e05d 173
mazgch 31:a0bed6c1e05d 174 //! Socket error return codes
mazgch 31:a0bed6c1e05d 175 #define SOCKET_ERROR -1
mazgch 31:a0bed6c1e05d 176
mazgch 63:42cb563a25bc 177 /** Create a socket for a ip protocol (and optionaly bind)
mazgch 31:a0bed6c1e05d 178 \param ipproto the protocol (UDP or TCP)
mazgch 63:42cb563a25bc 179 \param port in case of UDP, this optional port where it is bind
mazgch 31:a0bed6c1e05d 180 \return the socket handle if successful or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 181 */
mazgch 63:42cb563a25bc 182 int socketSocket(IpProtocol ipproto, int port = -1);
mazgch 31:a0bed6c1e05d 183
mazgch 31:a0bed6c1e05d 184 /** make a socket connection
mazgch 31:a0bed6c1e05d 185 \param socket the socket handle
mazgch 31:a0bed6c1e05d 186 \param host the domain name to connect e.g. "u-blox.com"
mazgch 31:a0bed6c1e05d 187 \param port the port to connect
mazgch 31:a0bed6c1e05d 188 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 189 */
mazgch 31:a0bed6c1e05d 190 bool socketConnect(int socket, const char* host, int port);
mazgch 31:a0bed6c1e05d 191
mazgch 44:9d12223b78ff 192 /** make a socket connection
mazgch 44:9d12223b78ff 193 \param socket the socket handle
mazgch 44:9d12223b78ff 194 \return true if connected, false otherwise
mazgch 44:9d12223b78ff 195 */
mazgch 44:9d12223b78ff 196 bool socketIsConnected(int socket);
mazgch 44:9d12223b78ff 197
mazgch 44:9d12223b78ff 198 /** Get the number of bytes pending for reading for this socket
mazgch 44:9d12223b78ff 199 \param socket the socket handle
mazgch 44:9d12223b78ff 200 \param timeout_ms -1 blocking, else non blocking timeout in ms
mazgch 44:9d12223b78ff 201 \return 0 if successful or SOCKET_ERROR on failure
mazgch 44:9d12223b78ff 202 */
mazgch 66:69072b3c5bca 203 bool socketSetBlocking(int socket, int timeout_ms);
mazgch 44:9d12223b78ff 204
mazgch 31:a0bed6c1e05d 205 /** Write socket data
mazgch 31:a0bed6c1e05d 206 \param socket the socket handle
mazgch 31:a0bed6c1e05d 207 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 208 \param len the size of the buffer to write
mazgch 31:a0bed6c1e05d 209 \return the size written or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 210 */
mazgch 31:a0bed6c1e05d 211 int socketSend(int socket, const char * buf, int len);
mazgch 31:a0bed6c1e05d 212
mazgch 31:a0bed6c1e05d 213 /** Write socket data to a IP
mazgch 31:a0bed6c1e05d 214 \param socket the socket handle
mazgch 31:a0bed6c1e05d 215 \param ip the ip to send to
mazgch 31:a0bed6c1e05d 216 \param port the port to send to
mazgch 31:a0bed6c1e05d 217 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 218 \param len the size of the buffer to write
mazgch 31:a0bed6c1e05d 219 \return the size written or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 220 */
mazgch 31:a0bed6c1e05d 221 int socketSendTo(int socket, IP ip, int port, const char * buf, int len);
mazgch 31:a0bed6c1e05d 222
mazgch 31:a0bed6c1e05d 223 /** Get the number of bytes pending for reading for this socket
mazgch 31:a0bed6c1e05d 224 \param socket the socket handle
mazgch 31:a0bed6c1e05d 225 \return the number of bytes pending or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 226 */
mazgch 31:a0bed6c1e05d 227 int socketReadable(int socket);
mazgch 31:a0bed6c1e05d 228
mazgch 31:a0bed6c1e05d 229 /** Read this socket
mazgch 31:a0bed6c1e05d 230 \param socket the socket handle
mazgch 31:a0bed6c1e05d 231 \param buf the buffer to read into
mazgch 31:a0bed6c1e05d 232 \param len the size of the buffer to read into
mazgch 31:a0bed6c1e05d 233 \return the number of bytes read or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 234 */
mazgch 31:a0bed6c1e05d 235 int socketRecv(int socket, char* buf, int len);
mazgch 31:a0bed6c1e05d 236
mazgch 31:a0bed6c1e05d 237 /** Read from this socket
mazgch 31:a0bed6c1e05d 238 \param socket the socket handle
mazgch 63:42cb563a25bc 239 \param ip the ip of host where the data originates from
mazgch 63:42cb563a25bc 240 \param port the port where the data originates from
mazgch 31:a0bed6c1e05d 241 \param buf the buffer to read into
mazgch 31:a0bed6c1e05d 242 \param len the size of the buffer to read into
mazgch 31:a0bed6c1e05d 243 \return the number of bytes read or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 244 */
mazgch 63:42cb563a25bc 245 int socketRecvFrom(int socket, IP* ip, int* port, char* buf, int len);
mazgch 31:a0bed6c1e05d 246
mazgch 31:a0bed6c1e05d 247 /** Close a connectied socket (that was connected with #socketConnect)
mazgch 31:a0bed6c1e05d 248 \param socket the socket handle
mazgch 31:a0bed6c1e05d 249 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 250 */
mazgch 31:a0bed6c1e05d 251 bool socketClose(int socket);
mazgch 31:a0bed6c1e05d 252
mazgch 31:a0bed6c1e05d 253 /** Free the socket (that was allocated before by #socketSocket)
mazgch 31:a0bed6c1e05d 254 \param socket the socket handle
mazgch 31:a0bed6c1e05d 255 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 256 */
mazgch 31:a0bed6c1e05d 257 bool socketFree(int socket);
mazgch 31:a0bed6c1e05d 258
mazgch 31:a0bed6c1e05d 259 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 260 // SMS Short Message Service
mazgch 31:a0bed6c1e05d 261 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 262
mazgch 31:a0bed6c1e05d 263 /** count the number of sms in the device and optionally return a
mazgch 31:a0bed6c1e05d 264 list with indexes from the storage locations in the device.
mazgch 31:a0bed6c1e05d 265 \param stat what type of messages you can use use
mazgch 31:a0bed6c1e05d 266 "REC UNREAD", "REC READ", "STO UNSENT", "STO SENT", "ALL"
mazgch 31:a0bed6c1e05d 267 \param ix list where to save the storage positions
mazgch 31:a0bed6c1e05d 268 \param num number of elements in the list
mazgch 31:a0bed6c1e05d 269 \return the number of messages, this can be bigger than num, -1 on failure
mazgch 31:a0bed6c1e05d 270 */
mazgch 31:a0bed6c1e05d 271 int smsList(const char* stat = "ALL", int* ix = NULL, int num = 0);
mazgch 31:a0bed6c1e05d 272
mazgch 31:a0bed6c1e05d 273 /** Read a Message from a storage position
mazgch 31:a0bed6c1e05d 274 \param ix the storage position to read
mazgch 31:a0bed6c1e05d 275 \param num the originator address (~16 chars)
mazgch 31:a0bed6c1e05d 276 \param buf a buffer where to save the sm
mazgch 31:a0bed6c1e05d 277 \param len the length of the sm
mazgch 31:a0bed6c1e05d 278 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 279 */
mazgch 31:a0bed6c1e05d 280 bool smsRead(int ix, char* num, char* buf, int len);
mazgch 31:a0bed6c1e05d 281
mazgch 31:a0bed6c1e05d 282 /** Send a message to a recipient
mazgch 31:a0bed6c1e05d 283 \param ix the storage position to delete
mazgch 31:a0bed6c1e05d 284 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 285 */
mazgch 31:a0bed6c1e05d 286 bool smsDelete(int ix);
mazgch 31:a0bed6c1e05d 287
mazgch 31:a0bed6c1e05d 288 /** Send a message to a recipient
mazgch 31:a0bed6c1e05d 289 \param num the phone number of the recipient
mazgch 31:a0bed6c1e05d 290 \param buf the content of the message to sent
mazgch 31:a0bed6c1e05d 291 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 292 */
mazgch 31:a0bed6c1e05d 293 bool smsSend(const char* num, const char* buf);
mazgch 31:a0bed6c1e05d 294
mazgch 31:a0bed6c1e05d 295 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 296 // USSD Unstructured Supplementary Service Data
mazgch 31:a0bed6c1e05d 297 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 298
mazgch 31:a0bed6c1e05d 299 /** Read a Message from a storage position
mazgch 31:a0bed6c1e05d 300 \param cmd the ussd command to send e.g "*#06#"
mazgch 31:a0bed6c1e05d 301 \param buf a buffer where to save the reply
mazgch 31:a0bed6c1e05d 302 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 303 */
mazgch 31:a0bed6c1e05d 304 bool ussdCommand(const char* cmd, char* buf);
mazgch 31:a0bed6c1e05d 305
mazgch 38:e6cab4632d84 306 // ----------------------------------------------------------------
mazgch 80:34985b4d821e 307 // FILE
mazgch 80:34985b4d821e 308 // ----------------------------------------------------------------
mazgch 80:34985b4d821e 309
mazgch 80:34985b4d821e 310 /** Delete a file in the local file system
mazgch 80:34985b4d821e 311 \param filename the name of the file
mazgch 80:34985b4d821e 312 \return true if successful, false otherwise
mazgch 80:34985b4d821e 313 */
mazgch 80:34985b4d821e 314 bool delFile(const char* filename);
mazgch 80:34985b4d821e 315
mazgch 80:34985b4d821e 316 /** Write some data to a file in the local file system
mazgch 80:34985b4d821e 317 \param filename the name of the file
mazgch 80:34985b4d821e 318 \param buf the data to write
mazgch 80:34985b4d821e 319 \param len the size of the data to write
mazgch 80:34985b4d821e 320 \return the number of bytes written
mazgch 80:34985b4d821e 321 */
mazgch 80:34985b4d821e 322 int writeFile(const char* filename, const char* buf, int len);
mazgch 80:34985b4d821e 323
mazgch 80:34985b4d821e 324 /** REad a file from the local file system
mazgch 80:34985b4d821e 325 \param filename the name of the file
mazgch 80:34985b4d821e 326 \param buf a buffer to hold the data
mazgch 80:34985b4d821e 327 \param len the size to read
mazgch 80:34985b4d821e 328 \return the number of bytes read
mazgch 80:34985b4d821e 329 */
mazgch 80:34985b4d821e 330 int readFile(const char* filename, char* buf, int len);
mazgch 80:34985b4d821e 331
mazgch 80:34985b4d821e 332 // ----------------------------------------------------------------
mazgch 74:208e3e32d263 333 // DEBUG/DUMP status to standard out (printf)
mazgch 54:7ba8e4c218e2 334 // ----------------------------------------------------------------
mazgch 54:7ba8e4c218e2 335
mazgch 74:208e3e32d263 336 /*! Set the debug level
mazgch 117:74e4e0109a9e 337 \param level -1 = OFF, 0 = ERROR, 1 = INFO(default), 2 = TRACE, 3 = ATCMD,TEST
mazgch 74:208e3e32d263 338 \return true if successful, false not possible
mazgch 74:208e3e32d263 339 */
mazgch 74:208e3e32d263 340 bool setDebug(int level);
mazgch 74:208e3e32d263 341
mazgch 73:2b32e0a21df2 342 //! helper type for DPRINT
mazgch 73:2b32e0a21df2 343 typedef int (*_DPRINT)(void* param, char const * format, ...);
mazgch 73:2b32e0a21df2 344
mazgch 73:2b32e0a21df2 345 //! helper to declate templates and void versions
mazgch 73:2b32e0a21df2 346 #define _DUMP_TEMPLATE(func, type, arg) \
mazgch 73:2b32e0a21df2 347 template<class T> \
mazgch 73:2b32e0a21df2 348 inline void func(type arg, \
mazgch 73:2b32e0a21df2 349 int (*dprint)( T* param, char const * format, ...), \
mazgch 73:2b32e0a21df2 350 T* param) { func(arg, (_DPRINT)dprint, (void*)param); } \
mazgch 73:2b32e0a21df2 351 static void func(type arg, \
mazgch 73:2b32e0a21df2 352 _DPRINT dprint = (_DPRINT)fprintf, \
mazgch 73:2b32e0a21df2 353 void* param = (void*)stdout);
mazgch 74:208e3e32d263 354
mazgch 54:7ba8e4c218e2 355 /** dump the device status to stdout using printf
mazgch 54:7ba8e4c218e2 356 \param status the status to convert to textual form,
mazgch 54:7ba8e4c218e2 357 unavailable fields are ommited (not printed)
mazgch 73:2b32e0a21df2 358 \param dprint a function pointer
mazgch 73:2b32e0a21df2 359 \param param the irst argument passed to dprint
mazgch 54:7ba8e4c218e2 360 */
mazgch 73:2b32e0a21df2 361 _DUMP_TEMPLATE(dumpDevStatus, MDMParser::DevStatus*, status)
mazgch 54:7ba8e4c218e2 362
mazgch 54:7ba8e4c218e2 363 /** dump the network status to stdout using printf
mazgch 54:7ba8e4c218e2 364 \param status the status to convert to textual form,
mazgch 54:7ba8e4c218e2 365 unavailable fields are ommited (not printed)
mazgch 73:2b32e0a21df2 366 \param dprint a function pointer
mazgch 73:2b32e0a21df2 367 \param param the irst argument passed to dprint
mazgch 54:7ba8e4c218e2 368 */
mazgch 73:2b32e0a21df2 369 _DUMP_TEMPLATE(dumpNetStatus, MDMParser::NetStatus*, status)
mazgch 73:2b32e0a21df2 370
mazgch 54:7ba8e4c218e2 371 /** dump the ip address to stdout using printf
mazgch 54:7ba8e4c218e2 372 \param ip the ip to convert to textual form,
mazgch 54:7ba8e4c218e2 373 unavailable fields are ommited (not printed)
mazgch 73:2b32e0a21df2 374 \param dprint a function pointer
mazgch 73:2b32e0a21df2 375 \param param the irst argument passed to dprint
mazgch 54:7ba8e4c218e2 376 */
mazgch 73:2b32e0a21df2 377 _DUMP_TEMPLATE(dumpIp, MDMParser::IP, ip)
mazgch 73:2b32e0a21df2 378
mazgch 54:7ba8e4c218e2 379 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 380 // Parseing
mazgch 31:a0bed6c1e05d 381 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 382
mazgch 51:e7b81c31baec 383 enum {
mazgch 51:e7b81c31baec 384 // waitFinalResp Responses
mazgch 52:8071747a7cb3 385 NOT_FOUND = 0,
mazgch 52:8071747a7cb3 386 WAIT = -1, // TIMEOUT
mazgch 52:8071747a7cb3 387 RESP_OK = -2,
mazgch 52:8071747a7cb3 388 RESP_ERROR = -3,
mazgch 52:8071747a7cb3 389 RESP_PROMPT = -4,
mazgch 31:a0bed6c1e05d 390
mazgch 51:e7b81c31baec 391 // getLine Responses
mazgch 51:e7b81c31baec 392 #define LENGTH(x) (x & 0x00FFFF) //!< extract/mask the length
mazgch 51:e7b81c31baec 393 #define TYPE(x) (x & 0xFF0000) //!< extract/mask the type
mazgch 51:e7b81c31baec 394
mazgch 51:e7b81c31baec 395 TYPE_UNKNOWN = 0x000000,
mazgch 51:e7b81c31baec 396 TYPE_OK = 0x110000,
mazgch 51:e7b81c31baec 397 TYPE_ERROR = 0x120000,
mazgch 51:e7b81c31baec 398 TYPE_RING = 0x210000,
mazgch 51:e7b81c31baec 399 TYPE_CONNECT = 0x220000,
mazgch 51:e7b81c31baec 400 TYPE_NOCARRIER = 0x230000,
mazgch 51:e7b81c31baec 401 TYPE_NODIALTONE = 0x240000,
mazgch 51:e7b81c31baec 402 TYPE_BUSY = 0x250000,
mazgch 51:e7b81c31baec 403 TYPE_NOANSWER = 0x260000,
mazgch 51:e7b81c31baec 404 TYPE_PROMPT = 0x300000,
mazgch 51:e7b81c31baec 405 TYPE_PLUS = 0x400000,
mazgch 66:69072b3c5bca 406 TYPE_TEXT = 0x500000,
mazgch 66:69072b3c5bca 407
mazgch 66:69072b3c5bca 408 // special timout constant
mazgch 66:69072b3c5bca 409 TIMEOUT_BLOCKING = -1
mazgch 51:e7b81c31baec 410 };
mazgch 31:a0bed6c1e05d 411
mazgch 31:a0bed6c1e05d 412 /** Get a line from the physical interface. This function need
mazgch 31:a0bed6c1e05d 413 to be implemented in a inherited class. Usually just calls
mazgch 31:a0bed6c1e05d 414 #_getLine on the rx buffer pipe.
mazgch 31:a0bed6c1e05d 415
mazgch 31:a0bed6c1e05d 416 \param buf the buffer to store it
mazgch 31:a0bed6c1e05d 417 \param buf size of the buffer
mazgch 31:a0bed6c1e05d 418 \return type and length if something was found,
mazgch 31:a0bed6c1e05d 419 WAIT if not enough data is available
mazgch 31:a0bed6c1e05d 420 NOT_FOUND if nothing was found
mazgch 31:a0bed6c1e05d 421 */
mazgch 31:a0bed6c1e05d 422 virtual int getLine(char* buf, int len) = 0;
mazgch 28:4d9509e3b1cf 423
mazgch 101:edfeb8af206e 424 /* clear the pending input data
mazgch 101:edfeb8af206e 425 */
mazgch 101:edfeb8af206e 426 virtual void purge(void) = 0;
mazgch 101:edfeb8af206e 427
mazgch 31:a0bed6c1e05d 428 /** Write data to the device
mazgch 31:a0bed6c1e05d 429 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 430 \param buf size of the buffer to write
mazgch 31:a0bed6c1e05d 431 \return bytes written
mazgch 31:a0bed6c1e05d 432 */
mazgch 31:a0bed6c1e05d 433 virtual int send(const char* buf, int len);
mazgch 21:c4d64830bf02 434
mazgch 31:a0bed6c1e05d 435 /** Write formated date to the physical interface (printf style)
mazgch 31:a0bed6c1e05d 436 \param fmt the format string
mazgch 31:a0bed6c1e05d 437 \param .. variable arguments to be formated
mazgch 31:a0bed6c1e05d 438 \return bytes written
mazgch 31:a0bed6c1e05d 439 */
mazgch 21:c4d64830bf02 440 int sendFormated(const char* format, ...);
mazgch 26:07be5faf8925 441
mazgch 31:a0bed6c1e05d 442 /** callback function for #waitFinalResp with void* as argument
mazgch 31:a0bed6c1e05d 443 \param type the #getLine response
mazgch 31:a0bed6c1e05d 444 \param buf the parsed line
mazgch 31:a0bed6c1e05d 445 \param len the size of the parsed line
mazgch 31:a0bed6c1e05d 446 \param param the optional argument passed to #waitFinalResp
mazgch 31:a0bed6c1e05d 447 \return WAIT if processing should continue,
mazgch 31:a0bed6c1e05d 448 any other value aborts #waitFinalResp and this retunr value retuned
mazgch 31:a0bed6c1e05d 449 */
mazgch 26:07be5faf8925 450 typedef int (*_CALLBACKPTR)(int type, const char* buf, int len, void* param);
mazgch 31:a0bed6c1e05d 451
mazgch 31:a0bed6c1e05d 452 /** Wait for a final respons
mazgch 31:a0bed6c1e05d 453 \param cb the optional callback function
mazgch 31:a0bed6c1e05d 454 \param param the optional callback function parameter
mazgch 58:e38a2e942fbb 455 \param timeout_ms the timeout to wait (See Estimated command
mazgch 58:e38a2e942fbb 456 response time of AT manual)
mazgch 31:a0bed6c1e05d 457 */
mazgch 31:a0bed6c1e05d 458 int waitFinalResp(_CALLBACKPTR cb = NULL,
mazgch 26:07be5faf8925 459 void* param = NULL,
mazgch 58:e38a2e942fbb 460 int timeout_ms = 10000);
mazgch 31:a0bed6c1e05d 461
mazgch 31:a0bed6c1e05d 462 /** template version of #waitFinalResp when using callbacks,
mazgch 31:a0bed6c1e05d 463 This template will allow the compiler to do type cheking but
mazgch 31:a0bed6c1e05d 464 internally symply casts the arguments and call the (void*)
mazgch 31:a0bed6c1e05d 465 version of #waitFinalResp.
mazgch 31:a0bed6c1e05d 466 \sa waitFinalResp
mazgch 31:a0bed6c1e05d 467 */
mazgch 26:07be5faf8925 468 template<class T>
mazgch 73:2b32e0a21df2 469 inline int waitFinalResp(int (*cb)(int type, const char* buf, int len, T* param),
mazgch 73:2b32e0a21df2 470 T* param,
mazgch 73:2b32e0a21df2 471 int timeout_ms = 10000)
mazgch 26:07be5faf8925 472 {
mazgch 26:07be5faf8925 473 return waitFinalResp((_CALLBACKPTR)cb, (void*)param, timeout_ms);
mazgch 26:07be5faf8925 474 }
mazgch 31:a0bed6c1e05d 475
mazgch 18:e5697801df29 476 protected:
mazgch 31:a0bed6c1e05d 477 /** Write bytes to the physical interface. This function should be
mazgch 31:a0bed6c1e05d 478 implemented in a inherited class.
mazgch 31:a0bed6c1e05d 479 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 480 \param buf size of the buffer to write
mazgch 31:a0bed6c1e05d 481 \return bytes written
mazgch 31:a0bed6c1e05d 482 */
mazgch 18:e5697801df29 483 virtual int _send(const void* buf, int len) = 0;
mazgch 31:a0bed6c1e05d 484
mazgch 31:a0bed6c1e05d 485 /** Helper: Parse a line from the receiving buffered pipe
mazgch 31:a0bed6c1e05d 486 \param pipe the receiving buffer pipe
mazgch 31:a0bed6c1e05d 487 \param buf the parsed line
mazgch 31:a0bed6c1e05d 488 \param len the size of the parsed line
mazgch 31:a0bed6c1e05d 489 \return type and length if something was found,
mazgch 31:a0bed6c1e05d 490 WAIT if not enough data is available
mazgch 31:a0bed6c1e05d 491 NOT_FOUND if nothing was found
mazgch 31:a0bed6c1e05d 492 */
mazgch 31:a0bed6c1e05d 493 static int _getLine(Pipe<char>* pipe, char* buffer, int length);
mazgch 31:a0bed6c1e05d 494
mazgch 31:a0bed6c1e05d 495 /** Helper: Parse a match from the pipe
mazgch 31:a0bed6c1e05d 496 \param pipe the buffered pipe
mazgch 31:a0bed6c1e05d 497 \param number of bytes to parse at maximum,
mazgch 31:a0bed6c1e05d 498 \param sta the starting string, NULL if none
mazgch 31:a0bed6c1e05d 499 \param end the terminating string, NULL if none
mazgch 31:a0bed6c1e05d 500 \return size of parsed match
mazgch 31:a0bed6c1e05d 501 */
mazgch 31:a0bed6c1e05d 502 static int _parseMatch(Pipe<char>* pipe, int len, const char* sta, const char* end);
mazgch 31:a0bed6c1e05d 503
mazgch 31:a0bed6c1e05d 504 /** Helper: Parse a match from the pipe
mazgch 31:a0bed6c1e05d 505 \param pipe the buffered pipe
mazgch 31:a0bed6c1e05d 506 \param number of bytes to parse at maximum,
mazgch 31:a0bed6c1e05d 507 \param fmt the formating string (%d any number, %c any char of last %d len)
mazgch 31:a0bed6c1e05d 508 \return size of parsed match
mazgch 31:a0bed6c1e05d 509 */
mazgch 31:a0bed6c1e05d 510 static int _parseFormated(Pipe<char>* pipe, int len, const char* fmt);
mazgch 31:a0bed6c1e05d 511
mazgch 35:9275215a3a5b 512 protected:
mazgch 95:8282dbbe1492 513 // for rtos over riding by useing Rtos<MDMxx>
mazgch 95:8282dbbe1492 514 /** override in a rtos system, you us the wait function of a Thread
mazgch 95:8282dbbe1492 515 \param ms the number of milliseconds to wait
mazgch 95:8282dbbe1492 516 */
mazgch 95:8282dbbe1492 517 virtual void wait_ms(int ms) { if (ms) ::wait_ms(ms); }
mazgch 95:8282dbbe1492 518 //! override the lock in a rtos system
mazgch 95:8282dbbe1492 519 virtual void lock(void) { }
mazgch 95:8282dbbe1492 520 //! override the unlock in a rtos system
mazgch 95:8282dbbe1492 521 virtual void unlock(void) { }
mazgch 95:8282dbbe1492 522 protected:
mazgch 31:a0bed6c1e05d 523 // parsing callbacks for different AT commands and their parameter arguments
mazgch 31:a0bed6c1e05d 524 static int _cbString(int type, const char* buf, int len, char* str);
mazgch 31:a0bed6c1e05d 525 static int _cbInt(int type, const char* buf, int len, int* val);
mazgch 31:a0bed6c1e05d 526 // device
mazgch 32:8f12ac182bbb 527 static int _cbATI(int type, const char* buf, int len, Dev* dev);
mazgch 31:a0bed6c1e05d 528 static int _cbCPIN(int type, const char* buf, int len, Sim* sim);
mazgch 31:a0bed6c1e05d 529 static int _cbCCID(int type, const char* buf, int len, char* ccid);
mazgch 31:a0bed6c1e05d 530 // network
mazgch 54:7ba8e4c218e2 531 static int _cbCSQ(int type, const char* buf, int len, NetStatus* status);
mazgch 31:a0bed6c1e05d 532 static int _cbCOPS(int type, const char* buf, int len, NetStatus* status);
mazgch 31:a0bed6c1e05d 533 static int _cbCNUM(int type, const char* buf, int len, char* num);
mazgch 81:3966a5c17037 534 static int _cbUACTIND(int type, const char* buf, int len, int* i);
mazgch 84:a05edb010176 535 static int _cbUDOPN(int type, const char* buf, int len, char* mccmnc);
mazgch 31:a0bed6c1e05d 536 // sockets
mazgch 32:8f12ac182bbb 537 static int _cbCMIP(int type, const char* buf, int len, IP* ip);
mazgch 31:a0bed6c1e05d 538 static int _cbUPSND(int type, const char* buf, int len, int* act);
mazgch 31:a0bed6c1e05d 539 static int _cbUPSND(int type, const char* buf, int len, IP* ip);
mazgch 21:c4d64830bf02 540 static int _cbUDNSRN(int type, const char* buf, int len, IP* ip);
mazgch 103:197fa7920ad8 541 static int _cbUSOCR(int type, const char* buf, int len, int* handle);
mazgch 21:c4d64830bf02 542 static int _cbUSORD(int type, const char* buf, int len, char* out);
mazgch 21:c4d64830bf02 543 typedef struct { char* buf; IP ip; int port; } USORFparam;
mazgch 21:c4d64830bf02 544 static int _cbUSORF(int type, const char* buf, int len, USORFparam* param);
mazgch 21:c4d64830bf02 545 typedef struct { char* buf; char* num; } CMGRparam;
mazgch 21:c4d64830bf02 546 static int _cbCUSD(int type, const char* buf, int len, char* buf);
mazgch 31:a0bed6c1e05d 547 // sms
mazgch 31:a0bed6c1e05d 548 typedef struct { int* ix; int num; } CMGLparam;
mazgch 31:a0bed6c1e05d 549 static int _cbCMGL(int type, const char* buf, int len, CMGLparam* param);
mazgch 21:c4d64830bf02 550 static int _cbCMGR(int type, const char* buf, int len, CMGRparam* param);
mazgch 80:34985b4d821e 551 // file
mazgch 80:34985b4d821e 552 typedef struct { const char* filename; char* buf; int sz; int len; } URDFILEparam;
mazgch 115:d8d94b73c725 553 static int _cbUDELFILE(int type, const char* buf, int len, void*);
mazgch 80:34985b4d821e 554 static int _cbURDFILE(int type, const char* buf, int len, URDFILEparam* param);
mazgch 38:e6cab4632d84 555 // variables
mazgch 31:a0bed6c1e05d 556 DevStatus _dev; //!< collected device information
mazgch 31:a0bed6c1e05d 557 NetStatus _net; //!< collected network information
mazgch 31:a0bed6c1e05d 558 IP _ip; //!< assigned ip address
mazgch 31:a0bed6c1e05d 559 // management struture for sockets
mazgch 103:197fa7920ad8 560 typedef struct { int handle; int timeout_ms; volatile bool connected; volatile int pending; } SockCtrl;
mazgch 103:197fa7920ad8 561 // LISA-C has 6 TCP and 6 UDP sockets
mazgch 103:197fa7920ad8 562 // LISA-U and SARA-G have 7 sockets
mazgch 103:197fa7920ad8 563 SockCtrl _sockets[12];
mazgch 103:197fa7920ad8 564 int _findSocket(int handle = SOCKET_ERROR/* = CREATE*/);
mazgch 44:9d12223b78ff 565 static MDMParser* inst;
mazgch 76:f7c3dd568dae 566 bool _init;
mazgch 74:208e3e32d263 567 #ifdef TARGET_UBLOX_C027
mazgch 74:208e3e32d263 568 bool _onboard;
mazgch 74:208e3e32d263 569 #endif
mazgch 74:208e3e32d263 570 #ifdef MDM_DEBUG
mazgch 74:208e3e32d263 571 int _debugLevel;
mazgch 74:208e3e32d263 572 Timer _debugTime;
mazgch 117:74e4e0109a9e 573 void _debugPrint(int level, const char* color, const char* format, ...);
mazgch 74:208e3e32d263 574 #endif
mazgch 18:e5697801df29 575 };
mazgch 18:e5697801df29 576
mazgch 18:e5697801df29 577 // -----------------------------------------------------------------------
mazgch 18:e5697801df29 578
mazgch 38:e6cab4632d84 579 /** modem class which uses a serial port
mazgch 38:e6cab4632d84 580 as physical interface.
mazgch 38:e6cab4632d84 581 */
mazgch 18:e5697801df29 582 class MDMSerial : public SerialPipe, public MDMParser
mazgch 17:296d94a006b4 583 {
mazgch 17:296d94a006b4 584 public:
mazgch 38:e6cab4632d84 585 /** Constructor
mazgch 38:e6cab4632d84 586
mazgch 38:e6cab4632d84 587 \param tx is the serial ports transmit pin (modem to CPU)
mazgch 38:e6cab4632d84 588 \param rx is the serial ports receive pin (CPU to modem)
mazgch 38:e6cab4632d84 589 \param baudrate the baudrate of the modem use 115200
mazgch 38:e6cab4632d84 590 \param rts is the serial ports ready to send pin (CPU to modem)
mazgch 38:e6cab4632d84 591 this pin is optional
mazgch 38:e6cab4632d84 592 \param cts is the serial ports clear to send pin (modem to CPU)
mazgch 38:e6cab4632d84 593 this pin is optional, but required for power saving to be enabled
mazgch 38:e6cab4632d84 594 \param rxSize the size of the serial rx buffer
mazgch 38:e6cab4632d84 595 \param txSize the size of the serial tx buffer
mazgch 38:e6cab4632d84 596 */
mazgch 75:ce6e12067d0c 597 MDMSerial(PinName tx MDM_IF( = MDMTXD, = D1 ),
mazgch 75:ce6e12067d0c 598 PinName rx MDM_IF( = MDMRXD, = D0 ),
mazgch 75:ce6e12067d0c 599 int baudrate MDM_IF( = MDMBAUD, = 115200 ),
mazgch 35:9275215a3a5b 600 #if DEVICE_SERIAL_FC
mazgch 75:ce6e12067d0c 601 PinName rts MDM_IF( = MDMRTS, = NC /* D2 resistor R62 on shield not mounted */ ),
mazgch 75:ce6e12067d0c 602 PinName cts MDM_IF( = MDMCTS, = NC /* D3 resistor R63 on shield not mounted */ ),
mazgch 35:9275215a3a5b 603 #endif
mazgch 19:2b5d097ca15d 604 int rxSize = 256 ,
mazgch 21:c4d64830bf02 605 int txSize = 128 );
mazgch 76:f7c3dd568dae 606 //! Destructor
mazgch 93:2b5478693c20 607 virtual ~MDMSerial(void);
mazgch 123:66cef6353b13 608
mazgch 38:e6cab4632d84 609 /** Get a line from the physical interface.
mazgch 38:e6cab4632d84 610 \param buf the buffer to store it
mazgch 38:e6cab4632d84 611 \param buf size of the buffer
mazgch 38:e6cab4632d84 612 \return type and length if something was found,
mazgch 38:e6cab4632d84 613 WAIT if not enough data is available
mazgch 38:e6cab4632d84 614 NOT_FOUND if nothing was found
mazgch 38:e6cab4632d84 615 */
mazgch 18:e5697801df29 616 virtual int getLine(char* buffer, int length);
mazgch 101:edfeb8af206e 617
mazgch 101:edfeb8af206e 618 /* clear the pending input data */
mazgch 101:edfeb8af206e 619 virtual void purge(void)
mazgch 101:edfeb8af206e 620 {
mazgch 101:edfeb8af206e 621 while (readable())
mazgch 101:edfeb8af206e 622 getc();
mazgch 101:edfeb8af206e 623 }
mazgch 18:e5697801df29 624 protected:
mazgch 38:e6cab4632d84 625 /** Write bytes to the physical interface.
mazgch 38:e6cab4632d84 626 \param buf the buffer to write
mazgch 38:e6cab4632d84 627 \param buf size of the buffer to write
mazgch 38:e6cab4632d84 628 \return bytes written
mazgch 38:e6cab4632d84 629 */
mazgch 18:e5697801df29 630 virtual int _send(const void* buf, int len);
mazgch 17:296d94a006b4 631 };
mazgch 18:e5697801df29 632
mazgch 18:e5697801df29 633 // -----------------------------------------------------------------------
mazgch 18:e5697801df29 634
mazgch 38:e6cab4632d84 635 //#define HAVE_MDMUSB
mazgch 18:e5697801df29 636 #ifdef HAVE_MDMUSB
mazgch 18:e5697801df29 637 class MDMUsb : /*public UsbSerial,*/ public MDMParser
mazgch 18:e5697801df29 638 {
mazgch 18:e5697801df29 639 public:
mazgch 76:f7c3dd568dae 640 //! Constructor
mazgch 18:e5697801df29 641 MDMUsb(void);
mazgch 76:f7c3dd568dae 642 //! Destructor
mazgch 93:2b5478693c20 643 virtual ~MDMUsb(void);
mazgch 18:e5697801df29 644 virtual int getLine(char* buffer, int length);
mazgch 101:edfeb8af206e 645 virtual void purge(void) { }
mazgch 18:e5697801df29 646 protected:
mazgch 18:e5697801df29 647 virtual int _send(const void* buf, int len);
mazgch 18:e5697801df29 648 };
mazgch 18:e5697801df29 649 #endif
mazgch 18:e5697801df29 650
mazgch 95:8282dbbe1492 651 // -----------------------------------------------------------------------
mazgch 18:e5697801df29 652
mazgch 95:8282dbbe1492 653 #ifdef RTOS_H
mazgch 95:8282dbbe1492 654 /** Use this template to override the lock and wait functions of the
mazgch 95:8282dbbe1492 655 modem driver in a Rtos system. For example declare it the modem
mazgch 95:8282dbbe1492 656 object as MDMRtos<MDMSerial> instead of MDMSerial.
mazgch 95:8282dbbe1492 657 */
mazgch 95:8282dbbe1492 658 template <class T>
mazgch 95:8282dbbe1492 659 class MDMRtos : public T
mazgch 95:8282dbbe1492 660 {
mazgch 95:8282dbbe1492 661 protected:
mazgch 95:8282dbbe1492 662 //! we assume that the modem runs in a thread so we yield when waiting
mazgch 95:8282dbbe1492 663 virtual void wait_ms(int ms) {
mazgch 95:8282dbbe1492 664 if (ms) Thread::wait(ms);
mazgch 95:8282dbbe1492 665 else Thread::yield();
mazgch 95:8282dbbe1492 666 }
mazgch 95:8282dbbe1492 667 //! lock a mutex when accessing the modem
mazgch 95:8282dbbe1492 668 virtual void lock(void) { _mtx.lock(); }
mazgch 95:8282dbbe1492 669 //! unlock the modem when done accessing it
mazgch 95:8282dbbe1492 670 virtual void unlock(void) { _mtx.unlock(); }
mazgch 95:8282dbbe1492 671 // the mutex resource
mazgch 95:8282dbbe1492 672 Mutex _mtx;
mazgch 95:8282dbbe1492 673 };
mazgch 95:8282dbbe1492 674 #endif