Add a bunch of APNs
Fork of C027_Support by
MDM.h@28:4d9509e3b1cf, 2014-04-08 (annotated)
- Committer:
- mazgch
- Date:
- Tue Apr 08 14:11:03 2014 +0000
- Revision:
- 28:4d9509e3b1cf
- Parent:
- 26:07be5faf8925
- Child:
- 29:53d346010624
collect more information
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 | 19:2b5d097ca15d | 10 | // if we detect the C027 platform we will assign the |
mazgch | 19:2b5d097ca15d | 11 | // default pinname and baudrate in the constructor |
mazgch | 19:2b5d097ca15d | 12 | // this helper macro will be used. |
mazgch | 19:2b5d097ca15d | 13 | #define _C027DEFAULT(name) = name |
mazgch | 19:2b5d097ca15d | 14 | #else |
mazgch | 19:2b5d097ca15d | 15 | #define _C027DEFAULT(name) |
mazgch | 19:2b5d097ca15d | 16 | #endif |
mazgch | 18:e5697801df29 | 17 | |
mazgch | 18:e5697801df29 | 18 | class MDMParser |
mazgch | 18:e5697801df29 | 19 | { |
mazgch | 18:e5697801df29 | 20 | public: |
mazgch | 21:c4d64830bf02 | 21 | // waitFinalResp Responses |
mazgch | 21:c4d64830bf02 | 22 | #define NOT_FOUND 0 |
mazgch | 21:c4d64830bf02 | 23 | #define WAIT -1 // TIMEOUT |
mazgch | 21:c4d64830bf02 | 24 | #define OK -2 |
mazgch | 21:c4d64830bf02 | 25 | #define ERROR -3 |
mazgch | 21:c4d64830bf02 | 26 | #define PROMPT -4 |
mazgch | 21:c4d64830bf02 | 27 | // getLine Responses |
mazgch | 21:c4d64830bf02 | 28 | #define LENGTH(x) (x & 0x00FFFF) |
mazgch | 21:c4d64830bf02 | 29 | #define TYPE(x) (x & 0xFF0000) |
mazgch | 21:c4d64830bf02 | 30 | #define TYPE_UNKNOWN 0x000000 |
mazgch | 21:c4d64830bf02 | 31 | #define TYPE_OK 0x110000 |
mazgch | 21:c4d64830bf02 | 32 | #define TYPE_ERROR 0x120000 |
mazgch | 21:c4d64830bf02 | 33 | #define TYPE_RING 0x210000 |
mazgch | 21:c4d64830bf02 | 34 | #define TYPE_CONNECT 0x220000 |
mazgch | 21:c4d64830bf02 | 35 | #define TYPE_NOCARRIER 0x230000 |
mazgch | 21:c4d64830bf02 | 36 | #define TYPE_NODIALTONE 0x240000 |
mazgch | 21:c4d64830bf02 | 37 | #define TYPE_BUSY 0x250000 |
mazgch | 21:c4d64830bf02 | 38 | #define TYPE_NOANSWER 0x260000 |
mazgch | 21:c4d64830bf02 | 39 | #define TYPE_PROMPT 0x300000 |
mazgch | 21:c4d64830bf02 | 40 | #define TYPE_PLUS 0x400000 |
mazgch | 21:c4d64830bf02 | 41 | // Socket Return Codes |
mazgch | 21:c4d64830bf02 | 42 | #define SOCKET_ERROR -1 |
mazgch | 21:c4d64830bf02 | 43 | #define SOCKET_OK 0 |
mazgch | 22:29322c22577e | 44 | typedef uint32_t IP; |
mazgch | 28:4d9509e3b1cf | 45 | |
mazgch | 28:4d9509e3b1cf | 46 | typedef enum { MODEL_UNKNOWN, MODEL_SARA_G350, MODEL_LISA_U200, MODEL_LISA_C200 } Model; |
mazgch | 28:4d9509e3b1cf | 47 | typedef enum { SIM_UNKNOWN, SIM_PIN, SIM_READY } Sim; |
mazgch | 28:4d9509e3b1cf | 48 | typedef struct { Model model; Sim sim; const char* imsi; const char* imei; const char* ccid; } DevStatus; |
mazgch | 25:4045d02e44f1 | 49 | typedef enum { NET_UNKNOWN, NET_DENIED, NET_NONE, NET_HOME, NET_ROAMING } Net; |
mazgch | 25:4045d02e44f1 | 50 | typedef enum { ACT_UNKNOWN, ACT_GSM, ACT_EDGE, ACT_UTRAN, ACT_CDMA } AcT; |
mazgch | 28:4d9509e3b1cf | 51 | typedef struct { const char* num; const char* opr; int rssi; Net net; AcT act; } NetStatus; |
mazgch | 21:c4d64830bf02 | 52 | |
mazgch | 21:c4d64830bf02 | 53 | MDMParser(void); |
mazgch | 18:e5697801df29 | 54 | |
mazgch | 21:c4d64830bf02 | 55 | // interaction with AT command interface |
mazgch | 18:e5697801df29 | 56 | virtual int getLine(char* buf, int len) = 0; |
mazgch | 18:e5697801df29 | 57 | virtual int send(const char* buf, int len); |
mazgch | 21:c4d64830bf02 | 58 | int sendFormated(const char* format, ...); |
mazgch | 26:07be5faf8925 | 59 | |
mazgch | 26:07be5faf8925 | 60 | typedef int (*_CALLBACKPTR)(int type, const char* buf, int len, void* param); |
mazgch | 26:07be5faf8925 | 61 | int waitFinalResp(_CALLBACKPTR = NULL, |
mazgch | 26:07be5faf8925 | 62 | void* param = NULL, |
mazgch | 26:07be5faf8925 | 63 | int timeout_ms = 5000); |
mazgch | 26:07be5faf8925 | 64 | template<class T> |
mazgch | 26:07be5faf8925 | 65 | int waitFinalResp(int (*cb)(int type, const char* buf, int len, |
mazgch | 26:07be5faf8925 | 66 | T* param), |
mazgch | 26:07be5faf8925 | 67 | T* param, int timeout_ms = 5000) |
mazgch | 26:07be5faf8925 | 68 | { |
mazgch | 26:07be5faf8925 | 69 | return waitFinalResp((_CALLBACKPTR)cb, (void*)param, timeout_ms); |
mazgch | 26:07be5faf8925 | 70 | } |
mazgch | 21:c4d64830bf02 | 71 | // network |
mazgch | 28:4d9509e3b1cf | 72 | bool init(const char* pin = NULL, DevStatus* status = NULL); |
mazgch | 28:4d9509e3b1cf | 73 | bool checkNetStatus(NetStatus* status = NULL); |
mazgch | 21:c4d64830bf02 | 74 | bool powerOff(void); |
mazgch | 21:c4d64830bf02 | 75 | // internet connection |
mazgch | 28:4d9509e3b1cf | 76 | bool join(const char* apn = NULL, const char* user = NULL, const char* password = NULL); |
mazgch | 21:c4d64830bf02 | 77 | bool disconnect(void); |
mazgch | 21:c4d64830bf02 | 78 | bool gethostbyname(const char* host, IP* ip); |
mazgch | 23:05a1aeeb5fd9 | 79 | // socket interface |
mazgch | 21:c4d64830bf02 | 80 | typedef enum { IPPROTO_TCP, IPPROTO_UDP } IpProtocol; |
mazgch | 21:c4d64830bf02 | 81 | int socketSocket(IpProtocol ipproto); |
mazgch | 21:c4d64830bf02 | 82 | bool socketConnect(int socket, const char * host, int port); |
mazgch | 21:c4d64830bf02 | 83 | int socketSend(int socket, const char * buf, int len); |
mazgch | 21:c4d64830bf02 | 84 | int socketSendTo(int socket, IP ip, int port, const char * buf, int len); |
mazgch | 21:c4d64830bf02 | 85 | int socketReadable(int socket); |
mazgch | 21:c4d64830bf02 | 86 | int socketRecv(int socket, char* buf, int len); |
mazgch | 21:c4d64830bf02 | 87 | int socketRecvFrom(int socket, char* buf, int len, IP* ip); |
mazgch | 21:c4d64830bf02 | 88 | bool socketClose(int socket); |
mazgch | 21:c4d64830bf02 | 89 | bool socketFree(int socket); |
mazgch | 21:c4d64830bf02 | 90 | // sms |
mazgch | 21:c4d64830bf02 | 91 | bool smsSend(const char* num, const char* buf); |
mazgch | 21:c4d64830bf02 | 92 | bool smsDelete(int ix); |
mazgch | 21:c4d64830bf02 | 93 | bool smsRead(int ix, char* num, char* buf, int len); |
mazgch | 21:c4d64830bf02 | 94 | // ussd |
mazgch | 21:c4d64830bf02 | 95 | int ussdCommand(const char* cmd, char* buf, int len); |
mazgch | 18:e5697801df29 | 96 | protected: |
mazgch | 18:e5697801df29 | 97 | static int _getLine(Pipe<char>* pipe, char* buffer, int length); |
mazgch | 21:c4d64830bf02 | 98 | static int _parseMatch(Pipe<char>* pipe, int len, const char* sta, const char* end); |
mazgch | 21:c4d64830bf02 | 99 | static int _parseFormated(Pipe<char>* pipe, int len, const char* fmt); |
mazgch | 18:e5697801df29 | 100 | virtual int _send(const void* buf, int len) = 0; |
mazgch | 21:c4d64830bf02 | 101 | private: |
mazgch | 21:c4d64830bf02 | 102 | static int _cbATI(int type, const char* buf, int len, Model* model); |
mazgch | 26:07be5faf8925 | 103 | static int _cbCIMI(int type, const char* buf, int len, char* imsi); |
mazgch | 21:c4d64830bf02 | 104 | static int _cbUDNSRN(int type, const char* buf, int len, IP* ip); |
mazgch | 21:c4d64830bf02 | 105 | static int _cbUSOCR(int type, const char* buf, int len, int* socket); |
mazgch | 21:c4d64830bf02 | 106 | static int _cbUSORD(int type, const char* buf, int len, char* out); |
mazgch | 21:c4d64830bf02 | 107 | typedef struct { char* buf; IP ip; int port; } USORFparam; |
mazgch | 21:c4d64830bf02 | 108 | static int _cbUSORF(int type, const char* buf, int len, USORFparam* param); |
mazgch | 21:c4d64830bf02 | 109 | typedef struct { char* buf; char* num; } CMGRparam; |
mazgch | 21:c4d64830bf02 | 110 | static int _cbCUSD(int type, const char* buf, int len, char* buf); |
mazgch | 21:c4d64830bf02 | 111 | static int _cbCMGR(int type, const char* buf, int len, CMGRparam* param); |
mazgch | 26:07be5faf8925 | 112 | static int _cbCGSN(int type, const char* buf, int len, char* imei); |
mazgch | 26:07be5faf8925 | 113 | static int _cbGSN(int type, const char* buf, int len, char* imei); |
mazgch | 26:07be5faf8925 | 114 | static int _cbCCID(int type, const char* buf, int len, char* ccid); |
mazgch | 21:c4d64830bf02 | 115 | static IP strToIp(const char* str); |
mazgch | 21:c4d64830bf02 | 116 | IP _ip; |
mazgch | 21:c4d64830bf02 | 117 | Model _model; |
mazgch | 21:c4d64830bf02 | 118 | Sim _sim; |
mazgch | 21:c4d64830bf02 | 119 | Net _net; |
mazgch | 25:4045d02e44f1 | 120 | AcT _act; |
mazgch | 23:05a1aeeb5fd9 | 121 | char _num[32]; |
mazgch | 25:4045d02e44f1 | 122 | char _opr[32]; |
mazgch | 21:c4d64830bf02 | 123 | int _rssi; |
mazgch | 26:07be5faf8925 | 124 | char _imsi[32]; |
mazgch | 26:07be5faf8925 | 125 | char _imei[32]; |
mazgch | 26:07be5faf8925 | 126 | char _ccid[32]; |
mazgch | 21:c4d64830bf02 | 127 | private: |
mazgch | 21:c4d64830bf02 | 128 | typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState; |
mazgch | 21:c4d64830bf02 | 129 | typedef struct { SockState state; int pending; } SockCtrl; |
mazgch | 21:c4d64830bf02 | 130 | SockCtrl _sockets[16]; |
mazgch | 18:e5697801df29 | 131 | }; |
mazgch | 18:e5697801df29 | 132 | |
mazgch | 18:e5697801df29 | 133 | // ----------------------------------------------------------------------- |
mazgch | 18:e5697801df29 | 134 | |
mazgch | 18:e5697801df29 | 135 | class MDMSerial : public SerialPipe, public MDMParser |
mazgch | 17:296d94a006b4 | 136 | { |
mazgch | 17:296d94a006b4 | 137 | public: |
mazgch | 19:2b5d097ca15d | 138 | MDMSerial(PinName tx _C027DEFAULT(MDMTXD), |
mazgch | 19:2b5d097ca15d | 139 | PinName rx _C027DEFAULT(MDMRXD), |
mazgch | 19:2b5d097ca15d | 140 | int baudrate _C027DEFAULT(MDMBAUD), |
mazgch | 19:2b5d097ca15d | 141 | #if DEVICE_SERIAL_FC |
mazgch | 19:2b5d097ca15d | 142 | PinName rts _C027DEFAULT(MDMRTS), |
mazgch | 19:2b5d097ca15d | 143 | PinName cts _C027DEFAULT(MDMCTS), |
mazgch | 19:2b5d097ca15d | 144 | #endif |
mazgch | 19:2b5d097ca15d | 145 | int rxSize = 256 , |
mazgch | 21:c4d64830bf02 | 146 | int txSize = 128 ); |
mazgch | 18:e5697801df29 | 147 | virtual int getLine(char* buffer, int length); |
mazgch | 18:e5697801df29 | 148 | protected: |
mazgch | 18:e5697801df29 | 149 | virtual int _send(const void* buf, int len); |
mazgch | 17:296d94a006b4 | 150 | }; |
mazgch | 18:e5697801df29 | 151 | |
mazgch | 18:e5697801df29 | 152 | // ----------------------------------------------------------------------- |
mazgch | 18:e5697801df29 | 153 | |
mazgch | 18:e5697801df29 | 154 | #define HAVE_MDMUSB |
mazgch | 18:e5697801df29 | 155 | #ifdef HAVE_MDMUSB |
mazgch | 18:e5697801df29 | 156 | class MDMUsb : /*public UsbSerial,*/ public MDMParser |
mazgch | 18:e5697801df29 | 157 | { |
mazgch | 18:e5697801df29 | 158 | public: |
mazgch | 18:e5697801df29 | 159 | MDMUsb(void); |
mazgch | 18:e5697801df29 | 160 | virtual int getLine(char* buffer, int length); |
mazgch | 18:e5697801df29 | 161 | protected: |
mazgch | 18:e5697801df29 | 162 | virtual int _send(const void* buf, int len); |
mazgch | 18:e5697801df29 | 163 | }; |
mazgch | 18:e5697801df29 | 164 | #endif |
mazgch | 18:e5697801df29 | 165 | |
mazgch | 18:e5697801df29 | 166 |