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