C027_Support library plus AT Comand for dialing.

Fork of C027_Support_New by irsan julfikar

Committer:
irsanjul
Date:
Sun Oct 11 09:56:57 2015 +0000
Revision:
121:3e1d84b2d34c
Parent:
120:353754a2bcd9
C027_Support library from mbed plus AT Command for dialing

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