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.

Fork of C027_Support by u-blox

Committer:
msinig
Date:
Thu Nov 26 09:42:01 2015 +0000
Revision:
133:57b208dd96fb
Parent:
132:de505da3aadf
Child:
134:2fbd5723e063
Added CellLocate API

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