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