C027_SupportTest_xively_locationで使用しているC027用ライブラリ

Fork of C027_Support by u-blox

下記のプログラムC027_SupportTest_xively_locationで使用しているC027用ライブラリです。

Import programC027_SupportTest_xively_location

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

オリジナルのライブラリは下記を参照してください。

Import libraryC027_Support

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.

Committer:
mazgch
Date:
Wed Apr 09 13:51:26 2014 +0000
Revision:
33:fb8fb5021b09
Parent:
32:8f12ac182bbb
Child:
34:3b3b7807c0c3
fix parsing in C200 case

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 19:2b5d097ca15d 9 #ifdef TARGET_UBLOX_C027
mazgch 19:2b5d097ca15d 10 // if we detect the C027 platform we will assign the
mazgch 19:2b5d097ca15d 11 // default pinname and baudrate in the constructor
mazgch 19:2b5d097ca15d 12 // this helper macro will be used.
mazgch 19:2b5d097ca15d 13 #define _C027DEFAULT(name) = name
mazgch 19:2b5d097ca15d 14 #else
mazgch 19:2b5d097ca15d 15 #define _C027DEFAULT(name)
mazgch 19:2b5d097ca15d 16 #endif
mazgch 18:e5697801df29 17
mazgch 18:e5697801df29 18 class MDMParser
mazgch 18:e5697801df29 19 {
mazgch 18:e5697801df29 20 public:
mazgch 31:a0bed6c1e05d 21 //! Constructor
mazgch 31:a0bed6c1e05d 22 MDMParser(void);
mazgch 31:a0bed6c1e05d 23
mazgch 31:a0bed6c1e05d 24 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 25 // Types
mazgch 31:a0bed6c1e05d 26 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 27
mazgch 33:fb8fb5021b09 28 typedef enum { DEV_UNKNOWN, DEV_SARA_G350, DEV_LISA_U200, DEV_LISA_C200 } Dev; //!< MT Device Types
mazgch 33:fb8fb5021b09 29 typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; //!< SIM Status
mazgch 33:fb8fb5021b09 30 typedef struct {
mazgch 33:fb8fb5021b09 31 Dev dev; //!< Device Type
mazgch 33:fb8fb5021b09 32 Sim sim; //!< SIM Card Status
mazgch 33:fb8fb5021b09 33 char ccid[20]; //!< Integrated Circuit Card ID
mazgch 33:fb8fb5021b09 34 char imsi[16]; //!< International Mobile Station Identity
mazgch 33:fb8fb5021b09 35 char imei[16]; //!< International Mobile Equipment Identity
mazgch 33:fb8fb5021b09 36 char meid[20]; //!< Mobile Equipment IDentifier
mazgch 33:fb8fb5021b09 37 char manu[16]; //!< Manufacturer
mazgch 33:fb8fb5021b09 38 char model[16]; //!< Model Name LISA-U200, LISA-C200 or SARA-G350
mazgch 33:fb8fb5021b09 39 char ver[16]; //!< Software Version
mazgch 33:fb8fb5021b09 40 } DevStatus; //!< Device status
mazgch 33:fb8fb5021b09 41 typedef enum { REG_UNKNOWN, REG_DENIED, REG_NONE, REG_HOME, REG_ROAMING } Reg; //!< Registration Status
mazgch 33:fb8fb5021b09 42 typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA } AcT; //!< Access Technology
mazgch 33:fb8fb5021b09 43 typedef struct {
mazgch 33:fb8fb5021b09 44 Reg reg; //!< Registration Status
mazgch 33:fb8fb5021b09 45 AcT act; //!< Access Technology
mazgch 33:fb8fb5021b09 46 int rssi; //!< Received Signal Strength Indication (in dBm, range -113..-53)
mazgch 33:fb8fb5021b09 47 char opr[17]; //!< Operator Name
mazgch 33:fb8fb5021b09 48 char num[20]; //!< Mobile Directory Number
mazgch 33:fb8fb5021b09 49 } NetStatus; //!< Network Status
mazgch 33:fb8fb5021b09 50 typedef uint32_t IP; //!< An IP address
mazgch 33:fb8fb5021b09 51 #define NOIP ((MDMParser::IP)0) //!< No IP address
mazgch 31:a0bed6c1e05d 52 // ip number formating and conversion
mazgch 31:a0bed6c1e05d 53 #define IPSTR "%d.%d.%d.%d"
mazgch 31:a0bed6c1e05d 54 #define IPNUM(ip) ((ip)>>24)&0xff, \
mazgch 31:a0bed6c1e05d 55 ((ip)>>16)&0xff, \
mazgch 31:a0bed6c1e05d 56 ((ip)>> 8)&0xff, \
mazgch 31:a0bed6c1e05d 57 ((ip)>> 0)&0xff
mazgch 31:a0bed6c1e05d 58 #define IPADR(a,b,c,d) ((((IP)(a))<<24) | \
mazgch 31:a0bed6c1e05d 59 (((IP)(b))<<16) | \
mazgch 31:a0bed6c1e05d 60 (((IP)(c))<< 8) | \
mazgch 31:a0bed6c1e05d 61 (((IP)(d))<< 0))
mazgch 31:a0bed6c1e05d 62
mazgch 31:a0bed6c1e05d 63
mazgch 31:a0bed6c1e05d 64 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 65 // Data Connection (GPRS)
mazgch 31:a0bed6c1e05d 66 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 67
mazgch 31:a0bed6c1e05d 68 /** register (Attach) the MT to the GPRS service.
mazgch 31:a0bed6c1e05d 69 \param pin a optional pin of the SIM card
mazgch 31:a0bed6c1e05d 70 \param status an optional struture to with device information
mazgch 31:a0bed6c1e05d 71 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 72 */
mazgch 31:a0bed6c1e05d 73 bool init(const char* pin = NULL, DevStatus* status = NULL);
mazgch 31:a0bed6c1e05d 74
mazgch 31:a0bed6c1e05d 75 /** check if the network is available
mazgch 31:a0bed6c1e05d 76 \param status an optional structure to with network information
mazgch 31:a0bed6c1e05d 77 \return true if successful and connected to network, false otherwise
mazgch 31:a0bed6c1e05d 78 */
mazgch 31:a0bed6c1e05d 79 bool checkNetStatus(NetStatus* status = NULL);
mazgch 31:a0bed6c1e05d 80
mazgch 31:a0bed6c1e05d 81 /** Power off the MT, This function has to be called prior to
mazgch 31:a0bed6c1e05d 82 switching off the supply.
mazgch 31:a0bed6c1e05d 83 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 84 */
mazgch 31:a0bed6c1e05d 85 bool powerOff(void);
mazgch 31:a0bed6c1e05d 86
mazgch 31:a0bed6c1e05d 87 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 88 // Data Connection (GPRS)
mazgch 31:a0bed6c1e05d 89 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 90
mazgch 31:a0bed6c1e05d 91 /** register (Attach) the MT to the GPRS service.
mazgch 31:a0bed6c1e05d 92 \param apn the of the network provider e.g. "internet" or "apn.provider.com"
mazgch 31:a0bed6c1e05d 93 \param user is the user name text string for the authentication phase
mazgch 31:a0bed6c1e05d 94 \param password is the password text string for the authentication phase
mazgch 31:a0bed6c1e05d 95 \return the ip that is assigned
mazgch 31:a0bed6c1e05d 96 */
mazgch 31:a0bed6c1e05d 97 MDMParser::IP join(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
mazgch 31:a0bed6c1e05d 98
mazgch 31:a0bed6c1e05d 99 /** deregister (detach) the MT from the GPRS service.
mazgch 31:a0bed6c1e05d 100 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 101 */
mazgch 31:a0bed6c1e05d 102 bool disconnect(void);
mazgch 31:a0bed6c1e05d 103
mazgch 31:a0bed6c1e05d 104 /** Translates a domain name to an IP address
mazgch 31:a0bed6c1e05d 105 \param host the domain name to translate e.g. "u-blox.com"
mazgch 31:a0bed6c1e05d 106 \return the IP if successful, 0 otherwise
mazgch 31:a0bed6c1e05d 107 */
mazgch 31:a0bed6c1e05d 108 MDMParser::IP gethostbyname(const char* host);
mazgch 31:a0bed6c1e05d 109
mazgch 31:a0bed6c1e05d 110 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 111 // Sockets
mazgch 31:a0bed6c1e05d 112 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 113
mazgch 31:a0bed6c1e05d 114 //! Type of IP protocol
mazgch 31:a0bed6c1e05d 115 typedef enum { IPPROTO_TCP, IPPROTO_UDP } IpProtocol;
mazgch 31:a0bed6c1e05d 116
mazgch 31:a0bed6c1e05d 117 //! Socket error return codes
mazgch 31:a0bed6c1e05d 118 #define SOCKET_ERROR -1
mazgch 31:a0bed6c1e05d 119
mazgch 31:a0bed6c1e05d 120 /** Create a socket for a ip protocol
mazgch 31:a0bed6c1e05d 121 \param ipproto the protocol (UDP or TCP)
mazgch 31:a0bed6c1e05d 122 \return the socket handle if successful or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 123 */
mazgch 31:a0bed6c1e05d 124 int socketSocket(IpProtocol ipproto);
mazgch 31:a0bed6c1e05d 125
mazgch 31:a0bed6c1e05d 126 /** make a socket connection
mazgch 31:a0bed6c1e05d 127 \param socket the socket handle
mazgch 31:a0bed6c1e05d 128 \param host the domain name to connect e.g. "u-blox.com"
mazgch 31:a0bed6c1e05d 129 \param port the port to connect
mazgch 31:a0bed6c1e05d 130 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 131 */
mazgch 31:a0bed6c1e05d 132 bool socketConnect(int socket, const char* host, int port);
mazgch 31:a0bed6c1e05d 133
mazgch 31:a0bed6c1e05d 134 /** Write socket data
mazgch 31:a0bed6c1e05d 135 \param socket the socket handle
mazgch 31:a0bed6c1e05d 136 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 137 \param len the size of the buffer to write
mazgch 31:a0bed6c1e05d 138 \return the size written or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 139 */
mazgch 31:a0bed6c1e05d 140 int socketSend(int socket, const char * buf, int len);
mazgch 31:a0bed6c1e05d 141
mazgch 31:a0bed6c1e05d 142 /** Write socket data to a IP
mazgch 31:a0bed6c1e05d 143 \param socket the socket handle
mazgch 31:a0bed6c1e05d 144 \param ip the ip to send to
mazgch 31:a0bed6c1e05d 145 \param port the port to send to
mazgch 31:a0bed6c1e05d 146 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 147 \param len the size of the buffer to write
mazgch 31:a0bed6c1e05d 148 \return the size written or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 149 */
mazgch 31:a0bed6c1e05d 150 int socketSendTo(int socket, IP ip, int port, const char * buf, int len);
mazgch 31:a0bed6c1e05d 151
mazgch 31:a0bed6c1e05d 152 /** Get the number of bytes pending for reading for this socket
mazgch 31:a0bed6c1e05d 153 \param socket the socket handle
mazgch 31:a0bed6c1e05d 154 \return the number of bytes pending or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 155 */
mazgch 31:a0bed6c1e05d 156 int socketReadable(int socket);
mazgch 31:a0bed6c1e05d 157
mazgch 31:a0bed6c1e05d 158 /** Read this socket
mazgch 31:a0bed6c1e05d 159 \param socket the socket handle
mazgch 31:a0bed6c1e05d 160 \param buf the buffer to read into
mazgch 31:a0bed6c1e05d 161 \param len the size of the buffer to read into
mazgch 31:a0bed6c1e05d 162 \return the number of bytes read or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 163 */
mazgch 31:a0bed6c1e05d 164 int socketRecv(int socket, char* buf, int len);
mazgch 31:a0bed6c1e05d 165
mazgch 31:a0bed6c1e05d 166 /** Read from this socket
mazgch 31:a0bed6c1e05d 167 \param socket the socket handle
mazgch 31:a0bed6c1e05d 168 \param buf the buffer to read into
mazgch 31:a0bed6c1e05d 169 \param len the size of the buffer to read into
mazgch 31:a0bed6c1e05d 170 \param ip the ip of host where the data originates from
mazgch 31:a0bed6c1e05d 171 \return the number of bytes read or SOCKET_ERROR on failure
mazgch 31:a0bed6c1e05d 172 */
mazgch 31:a0bed6c1e05d 173 int socketRecvFrom(int socket, char* buf, int len, IP* ip);
mazgch 31:a0bed6c1e05d 174
mazgch 31:a0bed6c1e05d 175 /** Close a connectied socket (that was connected with #socketConnect)
mazgch 31:a0bed6c1e05d 176 \param socket the socket handle
mazgch 31:a0bed6c1e05d 177 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 178 */
mazgch 31:a0bed6c1e05d 179 bool socketClose(int socket);
mazgch 31:a0bed6c1e05d 180
mazgch 31:a0bed6c1e05d 181 /** Free the socket (that was allocated before by #socketSocket)
mazgch 31:a0bed6c1e05d 182 \param socket the socket handle
mazgch 31:a0bed6c1e05d 183 \return true if successfully, false otherwise
mazgch 31:a0bed6c1e05d 184 */
mazgch 31:a0bed6c1e05d 185 bool socketFree(int socket);
mazgch 31:a0bed6c1e05d 186
mazgch 31:a0bed6c1e05d 187 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 188 // SMS Short Message Service
mazgch 31:a0bed6c1e05d 189 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 190
mazgch 31:a0bed6c1e05d 191 /** count the number of sms in the device and optionally return a
mazgch 31:a0bed6c1e05d 192 list with indexes from the storage locations in the device.
mazgch 31:a0bed6c1e05d 193 \param stat what type of messages you can use use
mazgch 31:a0bed6c1e05d 194 "REC UNREAD", "REC READ", "STO UNSENT", "STO SENT", "ALL"
mazgch 31:a0bed6c1e05d 195 \param ix list where to save the storage positions
mazgch 31:a0bed6c1e05d 196 \param num number of elements in the list
mazgch 31:a0bed6c1e05d 197 \return the number of messages, this can be bigger than num, -1 on failure
mazgch 31:a0bed6c1e05d 198 */
mazgch 31:a0bed6c1e05d 199 int smsList(const char* stat = "ALL", int* ix = NULL, int num = 0);
mazgch 31:a0bed6c1e05d 200
mazgch 31:a0bed6c1e05d 201 /** Read a Message from a storage position
mazgch 31:a0bed6c1e05d 202 \param ix the storage position to read
mazgch 31:a0bed6c1e05d 203 \param num the originator address (~16 chars)
mazgch 31:a0bed6c1e05d 204 \param buf a buffer where to save the sm
mazgch 31:a0bed6c1e05d 205 \param len the length of the sm
mazgch 31:a0bed6c1e05d 206 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 207 */
mazgch 31:a0bed6c1e05d 208 bool smsRead(int ix, char* num, char* buf, int len);
mazgch 31:a0bed6c1e05d 209
mazgch 31:a0bed6c1e05d 210 /** Send a message to a recipient
mazgch 31:a0bed6c1e05d 211 \param ix the storage position to delete
mazgch 31:a0bed6c1e05d 212 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 213 */
mazgch 31:a0bed6c1e05d 214 bool smsDelete(int ix);
mazgch 31:a0bed6c1e05d 215
mazgch 31:a0bed6c1e05d 216 /** Send a message to a recipient
mazgch 31:a0bed6c1e05d 217 \param num the phone number of the recipient
mazgch 31:a0bed6c1e05d 218 \param buf the content of the message to sent
mazgch 31:a0bed6c1e05d 219 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 220 */
mazgch 31:a0bed6c1e05d 221 bool smsSend(const char* num, const char* buf);
mazgch 31:a0bed6c1e05d 222
mazgch 31:a0bed6c1e05d 223 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 224 // USSD Unstructured Supplementary Service Data
mazgch 31:a0bed6c1e05d 225 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 226
mazgch 31:a0bed6c1e05d 227 /** Read a Message from a storage position
mazgch 31:a0bed6c1e05d 228 \param cmd the ussd command to send e.g "*#06#"
mazgch 31:a0bed6c1e05d 229 \param buf a buffer where to save the reply
mazgch 31:a0bed6c1e05d 230 \return true if successful, false otherwise
mazgch 31:a0bed6c1e05d 231 */
mazgch 31:a0bed6c1e05d 232 bool ussdCommand(const char* cmd, char* buf);
mazgch 31:a0bed6c1e05d 233
mazgch 31:a0bed6c1e05d 234 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 235 // Parseing
mazgch 31:a0bed6c1e05d 236 // ----------------------------------------------------------------
mazgch 31:a0bed6c1e05d 237
mazgch 31:a0bed6c1e05d 238 // waitFinalResp Responses
mazgch 21:c4d64830bf02 239 #define NOT_FOUND 0
mazgch 21:c4d64830bf02 240 #define WAIT -1 // TIMEOUT
mazgch 21:c4d64830bf02 241 #define OK -2
mazgch 21:c4d64830bf02 242 #define ERROR -3
mazgch 21:c4d64830bf02 243 #define PROMPT -4
mazgch 31:a0bed6c1e05d 244
mazgch 21:c4d64830bf02 245 // getLine Responses
mazgch 21:c4d64830bf02 246 #define LENGTH(x) (x & 0x00FFFF)
mazgch 21:c4d64830bf02 247 #define TYPE(x) (x & 0xFF0000)
mazgch 21:c4d64830bf02 248 #define TYPE_UNKNOWN 0x000000
mazgch 21:c4d64830bf02 249 #define TYPE_OK 0x110000
mazgch 21:c4d64830bf02 250 #define TYPE_ERROR 0x120000
mazgch 21:c4d64830bf02 251 #define TYPE_RING 0x210000
mazgch 21:c4d64830bf02 252 #define TYPE_CONNECT 0x220000
mazgch 21:c4d64830bf02 253 #define TYPE_NOCARRIER 0x230000
mazgch 21:c4d64830bf02 254 #define TYPE_NODIALTONE 0x240000
mazgch 21:c4d64830bf02 255 #define TYPE_BUSY 0x250000
mazgch 21:c4d64830bf02 256 #define TYPE_NOANSWER 0x260000
mazgch 21:c4d64830bf02 257 #define TYPE_PROMPT 0x300000
mazgch 21:c4d64830bf02 258 #define TYPE_PLUS 0x400000
mazgch 31:a0bed6c1e05d 259
mazgch 31:a0bed6c1e05d 260 /** Get a line from the physical interface. This function need
mazgch 31:a0bed6c1e05d 261 to be implemented in a inherited class. Usually just calls
mazgch 31:a0bed6c1e05d 262 #_getLine on the rx buffer pipe.
mazgch 31:a0bed6c1e05d 263
mazgch 31:a0bed6c1e05d 264 \param buf the buffer to store it
mazgch 31:a0bed6c1e05d 265 \param buf size of the buffer
mazgch 31:a0bed6c1e05d 266 \return type and length if something was found,
mazgch 31:a0bed6c1e05d 267 WAIT if not enough data is available
mazgch 31:a0bed6c1e05d 268 NOT_FOUND if nothing was found
mazgch 31:a0bed6c1e05d 269 */
mazgch 31:a0bed6c1e05d 270 virtual int getLine(char* buf, int len) = 0;
mazgch 28:4d9509e3b1cf 271
mazgch 31:a0bed6c1e05d 272 /** Write data to the device
mazgch 31:a0bed6c1e05d 273 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 274 \param buf size of the buffer to write
mazgch 31:a0bed6c1e05d 275 \return bytes written
mazgch 31:a0bed6c1e05d 276 */
mazgch 31:a0bed6c1e05d 277 virtual int send(const char* buf, int len);
mazgch 21:c4d64830bf02 278
mazgch 31:a0bed6c1e05d 279 /** Write formated date to the physical interface (printf style)
mazgch 31:a0bed6c1e05d 280 \param fmt the format string
mazgch 31:a0bed6c1e05d 281 \param .. variable arguments to be formated
mazgch 31:a0bed6c1e05d 282 \return bytes written
mazgch 31:a0bed6c1e05d 283 */
mazgch 21:c4d64830bf02 284 int sendFormated(const char* format, ...);
mazgch 26:07be5faf8925 285
mazgch 31:a0bed6c1e05d 286 /** callback function for #waitFinalResp with void* as argument
mazgch 31:a0bed6c1e05d 287 \param type the #getLine response
mazgch 31:a0bed6c1e05d 288 \param buf the parsed line
mazgch 31:a0bed6c1e05d 289 \param len the size of the parsed line
mazgch 31:a0bed6c1e05d 290 \param param the optional argument passed to #waitFinalResp
mazgch 31:a0bed6c1e05d 291 \return WAIT if processing should continue,
mazgch 31:a0bed6c1e05d 292 any other value aborts #waitFinalResp and this retunr value retuned
mazgch 31:a0bed6c1e05d 293 */
mazgch 26:07be5faf8925 294 typedef int (*_CALLBACKPTR)(int type, const char* buf, int len, void* param);
mazgch 31:a0bed6c1e05d 295
mazgch 31:a0bed6c1e05d 296 /** Wait for a final respons
mazgch 31:a0bed6c1e05d 297 \param cb the optional callback function
mazgch 31:a0bed6c1e05d 298 \param param the optional callback function parameter
mazgch 31:a0bed6c1e05d 299 \param timeout_ms the timeout to wait
mazgch 31:a0bed6c1e05d 300 */
mazgch 31:a0bed6c1e05d 301 int waitFinalResp(_CALLBACKPTR cb = NULL,
mazgch 26:07be5faf8925 302 void* param = NULL,
mazgch 26:07be5faf8925 303 int timeout_ms = 5000);
mazgch 31:a0bed6c1e05d 304
mazgch 31:a0bed6c1e05d 305 /** template version of #waitFinalResp when using callbacks,
mazgch 31:a0bed6c1e05d 306 This template will allow the compiler to do type cheking but
mazgch 31:a0bed6c1e05d 307 internally symply casts the arguments and call the (void*)
mazgch 31:a0bed6c1e05d 308 version of #waitFinalResp.
mazgch 31:a0bed6c1e05d 309 \sa waitFinalResp
mazgch 31:a0bed6c1e05d 310 */
mazgch 26:07be5faf8925 311 template<class T>
mazgch 26:07be5faf8925 312 int waitFinalResp(int (*cb)(int type, const char* buf, int len,
mazgch 26:07be5faf8925 313 T* param),
mazgch 26:07be5faf8925 314 T* param, int timeout_ms = 5000)
mazgch 26:07be5faf8925 315 {
mazgch 26:07be5faf8925 316 return waitFinalResp((_CALLBACKPTR)cb, (void*)param, timeout_ms);
mazgch 26:07be5faf8925 317 }
mazgch 31:a0bed6c1e05d 318
mazgch 18:e5697801df29 319 protected:
mazgch 31:a0bed6c1e05d 320 /** Write bytes to the physical interface. This function should be
mazgch 31:a0bed6c1e05d 321 implemented in a inherited class.
mazgch 31:a0bed6c1e05d 322 \param buf the buffer to write
mazgch 31:a0bed6c1e05d 323 \param buf size of the buffer to write
mazgch 31:a0bed6c1e05d 324 \return bytes written
mazgch 31:a0bed6c1e05d 325 */
mazgch 18:e5697801df29 326 virtual int _send(const void* buf, int len) = 0;
mazgch 31:a0bed6c1e05d 327
mazgch 31:a0bed6c1e05d 328 /** Helper: Parse a line from the receiving buffered pipe
mazgch 31:a0bed6c1e05d 329 \param pipe the receiving buffer pipe
mazgch 31:a0bed6c1e05d 330 \param buf the parsed line
mazgch 31:a0bed6c1e05d 331 \param len the size of the parsed line
mazgch 31:a0bed6c1e05d 332 \return type and length if something was found,
mazgch 31:a0bed6c1e05d 333 WAIT if not enough data is available
mazgch 31:a0bed6c1e05d 334 NOT_FOUND if nothing was found
mazgch 31:a0bed6c1e05d 335 */
mazgch 31:a0bed6c1e05d 336 static int _getLine(Pipe<char>* pipe, char* buffer, int length);
mazgch 31:a0bed6c1e05d 337
mazgch 31:a0bed6c1e05d 338 /** Helper: Parse a match from the pipe
mazgch 31:a0bed6c1e05d 339 \param pipe the buffered pipe
mazgch 31:a0bed6c1e05d 340 \param number of bytes to parse at maximum,
mazgch 31:a0bed6c1e05d 341 \param sta the starting string, NULL if none
mazgch 31:a0bed6c1e05d 342 \param end the terminating string, NULL if none
mazgch 31:a0bed6c1e05d 343 \return size of parsed match
mazgch 31:a0bed6c1e05d 344 */
mazgch 31:a0bed6c1e05d 345 static int _parseMatch(Pipe<char>* pipe, int len, const char* sta, const char* end);
mazgch 31:a0bed6c1e05d 346
mazgch 31:a0bed6c1e05d 347 /** Helper: Parse a match from the pipe
mazgch 31:a0bed6c1e05d 348 \param pipe the buffered pipe
mazgch 31:a0bed6c1e05d 349 \param number of bytes to parse at maximum,
mazgch 31:a0bed6c1e05d 350 \param fmt the formating string (%d any number, %c any char of last %d len)
mazgch 31:a0bed6c1e05d 351 \return size of parsed match
mazgch 31:a0bed6c1e05d 352 */
mazgch 31:a0bed6c1e05d 353 static int _parseFormated(Pipe<char>* pipe, int len, const char* fmt);
mazgch 31:a0bed6c1e05d 354
mazgch 21:c4d64830bf02 355 private:
mazgch 31:a0bed6c1e05d 356 // parsing callbacks for different AT commands and their parameter arguments
mazgch 31:a0bed6c1e05d 357 static int _cbString(int type, const char* buf, int len, char* str);
mazgch 31:a0bed6c1e05d 358 static int _cbInt(int type, const char* buf, int len, int* val);
mazgch 31:a0bed6c1e05d 359 // device
mazgch 32:8f12ac182bbb 360 static int _cbATI(int type, const char* buf, int len, Dev* dev);
mazgch 31:a0bed6c1e05d 361 static int _cbCPIN(int type, const char* buf, int len, Sim* sim);
mazgch 31:a0bed6c1e05d 362 static int _cbCCID(int type, const char* buf, int len, char* ccid);
mazgch 31:a0bed6c1e05d 363 // network
mazgch 31:a0bed6c1e05d 364 static int _cbCSQ(int type, const char* buf, int len, int* rssi);
mazgch 31:a0bed6c1e05d 365 static int _cbCOPS(int type, const char* buf, int len, NetStatus* status);
mazgch 31:a0bed6c1e05d 366 static int _cbCNUM(int type, const char* buf, int len, char* num);
mazgch 31:a0bed6c1e05d 367 static int _cbCGATT(int type, const char* buf, int len, int* state);
mazgch 31:a0bed6c1e05d 368 // sockets
mazgch 32:8f12ac182bbb 369 static int _cbCMIP(int type, const char* buf, int len, IP* ip);
mazgch 31:a0bed6c1e05d 370 static int _cbUPSND(int type, const char* buf, int len, int* act);
mazgch 31:a0bed6c1e05d 371 static int _cbUPSND(int type, const char* buf, int len, IP* ip);
mazgch 21:c4d64830bf02 372 static int _cbUDNSRN(int type, const char* buf, int len, IP* ip);
mazgch 21:c4d64830bf02 373 static int _cbUSOCR(int type, const char* buf, int len, int* socket);
mazgch 21:c4d64830bf02 374 static int _cbUSORD(int type, const char* buf, int len, char* out);
mazgch 21:c4d64830bf02 375 typedef struct { char* buf; IP ip; int port; } USORFparam;
mazgch 21:c4d64830bf02 376 static int _cbUSORF(int type, const char* buf, int len, USORFparam* param);
mazgch 21:c4d64830bf02 377 typedef struct { char* buf; char* num; } CMGRparam;
mazgch 21:c4d64830bf02 378 static int _cbCUSD(int type, const char* buf, int len, char* buf);
mazgch 31:a0bed6c1e05d 379 // sms
mazgch 31:a0bed6c1e05d 380 typedef struct { int* ix; int num; } CMGLparam;
mazgch 31:a0bed6c1e05d 381 static int _cbCMGL(int type, const char* buf, int len, CMGLparam* param);
mazgch 21:c4d64830bf02 382 static int _cbCMGR(int type, const char* buf, int len, CMGRparam* param);
mazgch 31:a0bed6c1e05d 383 //
mazgch 31:a0bed6c1e05d 384 DevStatus _dev; //!< collected device information
mazgch 31:a0bed6c1e05d 385 NetStatus _net; //!< collected network information
mazgch 31:a0bed6c1e05d 386 IP _ip; //!< assigned ip address
mazgch 31:a0bed6c1e05d 387 // management struture for sockets
mazgch 21:c4d64830bf02 388 typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;
mazgch 21:c4d64830bf02 389 typedef struct { SockState state; int pending; } SockCtrl;
mazgch 21:c4d64830bf02 390 SockCtrl _sockets[16];
mazgch 18:e5697801df29 391 };
mazgch 18:e5697801df29 392
mazgch 18:e5697801df29 393 // -----------------------------------------------------------------------
mazgch 18:e5697801df29 394
mazgch 18:e5697801df29 395 class MDMSerial : public SerialPipe, public MDMParser
mazgch 17:296d94a006b4 396 {
mazgch 17:296d94a006b4 397 public:
mazgch 19:2b5d097ca15d 398 MDMSerial(PinName tx _C027DEFAULT(MDMTXD),
mazgch 19:2b5d097ca15d 399 PinName rx _C027DEFAULT(MDMRXD),
mazgch 19:2b5d097ca15d 400 int baudrate _C027DEFAULT(MDMBAUD),
mazgch 19:2b5d097ca15d 401 #if DEVICE_SERIAL_FC
mazgch 19:2b5d097ca15d 402 PinName rts _C027DEFAULT(MDMRTS),
mazgch 19:2b5d097ca15d 403 PinName cts _C027DEFAULT(MDMCTS),
mazgch 19:2b5d097ca15d 404 #endif
mazgch 19:2b5d097ca15d 405 int rxSize = 256 ,
mazgch 21:c4d64830bf02 406 int txSize = 128 );
mazgch 18:e5697801df29 407 virtual int getLine(char* buffer, int length);
mazgch 18:e5697801df29 408 protected:
mazgch 18:e5697801df29 409 virtual int _send(const void* buf, int len);
mazgch 17:296d94a006b4 410 };
mazgch 18:e5697801df29 411
mazgch 18:e5697801df29 412 // -----------------------------------------------------------------------
mazgch 18:e5697801df29 413
mazgch 18:e5697801df29 414 #define HAVE_MDMUSB
mazgch 18:e5697801df29 415 #ifdef HAVE_MDMUSB
mazgch 18:e5697801df29 416 class MDMUsb : /*public UsbSerial,*/ public MDMParser
mazgch 18:e5697801df29 417 {
mazgch 18:e5697801df29 418 public:
mazgch 18:e5697801df29 419 MDMUsb(void);
mazgch 18:e5697801df29 420 virtual int getLine(char* buffer, int length);
mazgch 18:e5697801df29 421 protected:
mazgch 18:e5697801df29 422 virtual int _send(const void* buf, int len);
mazgch 18:e5697801df29 423 };
mazgch 18:e5697801df29 424 #endif
mazgch 18:e5697801df29 425
mazgch 18:e5697801df29 426