![](/media/cache/profiles/aa7fd480bd75d86948e7f7aac11d2704.jpg.50x50_q85.jpg)
support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.
Fork of C027_Support by
GPS.h@31:a0bed6c1e05d, 2014-04-09 (annotated)
- Committer:
- mazgch
- Date:
- Wed Apr 09 11:48:04 2014 +0000
- Revision:
- 31:a0bed6c1e05d
- Parent:
- 24:0e287a85ac9e
- Child:
- 38:e6cab4632d84
restructure the modem APIs make them more robust
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mazgch | 1:f41579f4e2ed | 1 | #pragma once |
mazgch | 1:f41579f4e2ed | 2 | |
mazgch | 2:b6012cd91657 | 3 | #include "mbed.h" |
mazgch | 2:b6012cd91657 | 4 | #include "Pipe.h" |
mazgch | 1:f41579f4e2ed | 5 | #include "SerialPipe.h" |
mazgch | 2:b6012cd91657 | 6 | |
mazgch | 19:2b5d097ca15d | 7 | #ifdef TARGET_UBLOX_C027 |
mazgch | 19:2b5d097ca15d | 8 | // if we detect the C027 platform we will assign the |
mazgch | 19:2b5d097ca15d | 9 | // default pinname and baudrate in the constructor |
mazgch | 19:2b5d097ca15d | 10 | // this helper macro will be used. |
mazgch | 19:2b5d097ca15d | 11 | #define _C027DEFAULT(name) = name |
mazgch | 19:2b5d097ca15d | 12 | #else |
mazgch | 19:2b5d097ca15d | 13 | #define _C027DEFAULT(name) |
mazgch | 19:2b5d097ca15d | 14 | #endif |
mazgch | 9:e7a5959ffae1 | 15 | |
mazgch | 2:b6012cd91657 | 16 | class GPSParser |
mazgch | 2:b6012cd91657 | 17 | { |
mazgch | 2:b6012cd91657 | 18 | public: |
mazgch | 2:b6012cd91657 | 19 | #define WAIT -1 |
mazgch | 2:b6012cd91657 | 20 | #define NOT_FOUND 0 |
mazgch | 2:b6012cd91657 | 21 | |
mazgch | 31:a0bed6c1e05d | 22 | #define UNKNOWN 0x000000 |
mazgch | 2:b6012cd91657 | 23 | #define UBX 0x100000 |
mazgch | 2:b6012cd91657 | 24 | #define NMEA 0x200000 |
mazgch | 2:b6012cd91657 | 25 | #define LENGTH(x) (x & 0x00FFFF) |
mazgch | 2:b6012cd91657 | 26 | #define PROTOCOL(x) (x & 0xFF0000) |
mazgch | 1:f41579f4e2ed | 27 | |
mazgch | 2:b6012cd91657 | 28 | virtual int getMessage(char* buf, int len) = 0; |
mazgch | 4:c959dd4c5fe8 | 29 | virtual int send(const char* buf, int len); |
mazgch | 4:c959dd4c5fe8 | 30 | virtual int sendNmea(const char* buf, int len); |
mazgch | 11:b084552b03fe | 31 | virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0); |
mazgch | 31:a0bed6c1e05d | 32 | void powerOff(void); |
mazgch | 2:b6012cd91657 | 33 | |
mazgch | 2:b6012cd91657 | 34 | static const char* findNmeaItemPos(int ix, const char* start, const char* end); |
mazgch | 2:b6012cd91657 | 35 | static bool getNmeaItem(int ix, char* buf, int len, double& val); |
mazgch | 2:b6012cd91657 | 36 | static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/); |
mazgch | 2:b6012cd91657 | 37 | static bool getNmeaItem(int ix, char* buf, int len, char& val); |
mazgch | 20:535ef78655df | 38 | static bool getNmeaAngle(int ix, char* buf, int len, double& val); |
mazgch | 2:b6012cd91657 | 39 | protected: |
mazgch | 2:b6012cd91657 | 40 | static int _getMessage(Pipe<char>* pipe, char* buf, int len); |
mazgch | 2:b6012cd91657 | 41 | static int _parseNmea(Pipe<char>* pipe, int len); |
mazgch | 2:b6012cd91657 | 42 | static int _parseUbx(Pipe<char>* pipe, int len); |
mazgch | 4:c959dd4c5fe8 | 43 | virtual int _send(const void* buf, int len) = 0; |
mazgch | 2:b6012cd91657 | 44 | static const char toHex[16]; |
mazgch | 2:b6012cd91657 | 45 | }; |
mazgch | 2:b6012cd91657 | 46 | |
mazgch | 9:e7a5959ffae1 | 47 | class GPSSerial : public SerialPipe, public GPSParser |
mazgch | 1:f41579f4e2ed | 48 | { |
mazgch | 1:f41579f4e2ed | 49 | public: |
mazgch | 19:2b5d097ca15d | 50 | GPSSerial(PinName tx _C027DEFAULT( GPSTXD ), |
mazgch | 19:2b5d097ca15d | 51 | PinName rx _C027DEFAULT( GPSRXD ), |
mazgch | 19:2b5d097ca15d | 52 | int baudrate _C027DEFAULT( GPSBAUD ), |
mazgch | 19:2b5d097ca15d | 53 | int rxSize = 256 , |
mazgch | 19:2b5d097ca15d | 54 | int txSize = 128 ); |
mazgch | 2:b6012cd91657 | 55 | virtual int getMessage(char* buf, int len); |
mazgch | 2:b6012cd91657 | 56 | protected: |
mazgch | 4:c959dd4c5fe8 | 57 | virtual int _send(const void* buf, int len); |
mazgch | 1:f41579f4e2ed | 58 | }; |
mazgch | 2:b6012cd91657 | 59 | |
mazgch | 2:b6012cd91657 | 60 | class GPSI2C : public I2C, public GPSParser |
mazgch | 2:b6012cd91657 | 61 | { |
mazgch | 2:b6012cd91657 | 62 | public: |
mazgch | 19:2b5d097ca15d | 63 | GPSI2C(PinName sda _C027DEFAULT( GPSSDA ), |
mazgch | 19:2b5d097ca15d | 64 | PinName scl _C027DEFAULT( GPSSCL ), |
mazgch | 19:2b5d097ca15d | 65 | unsigned char i2cAdr _C027DEFAULT( GPSADR ), |
mazgch | 19:2b5d097ca15d | 66 | int rxSize = 256 ); |
mazgch | 2:b6012cd91657 | 67 | bool detect(void); |
mazgch | 2:b6012cd91657 | 68 | |
mazgch | 2:b6012cd91657 | 69 | virtual int getMessage(char* buf, int len); |
mazgch | 4:c959dd4c5fe8 | 70 | virtual int send(const char* buf, int len); |
mazgch | 3:c7cd4887560d | 71 | virtual int sendNmea(const char* buf, int len); |
mazgch | 11:b084552b03fe | 72 | virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0); |
mazgch | 2:b6012cd91657 | 73 | protected: |
mazgch | 9:e7a5959ffae1 | 74 | bool writeable(void) { return true; } |
mazgch | 9:e7a5959ffae1 | 75 | bool putc(int c) { char ch = c; return send(&ch, 1); } |
mazgch | 4:c959dd4c5fe8 | 76 | virtual int _send(const void* buf, int len); |
mazgch | 3:c7cd4887560d | 77 | int _get(char* buf, int len); // read the NMEA or UBX stream |
mazgch | 3:c7cd4887560d | 78 | |
mazgch | 2:b6012cd91657 | 79 | Pipe<char> _pipe; |
mazgch | 2:b6012cd91657 | 80 | bool found; |
mazgch | 19:2b5d097ca15d | 81 | unsigned char _i2cAdr; |
mazgch | 2:b6012cd91657 | 82 | static const char REGLEN; |
mazgch | 2:b6012cd91657 | 83 | static const char REGSTREAM; |
mazgch | 2:b6012cd91657 | 84 | }; |