Axeda demo software for u-blox C027 (GSM)

Dependencies:   mbed

Committer:
AxedaCorp
Date:
Mon Aug 11 19:07:20 2014 +0000
Revision:
1:ff6d8adaf6b9
Parent:
0:a725e8eab383
Pointed to platform (prod)

Who changed what in which revision?

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