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 08:07:37 2015 +0000
Revision:
124:65eb7d58f2da
updated toby handling

Who changed what in which revision?

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