454
Fork of C027_Support by
GPS.h@18:e5697801df29, 2014-03-14 (annotated)
- Committer:
- mazgch
- Date:
- Fri Mar 14 13:07:48 2014 +0000
- Revision:
- 18:e5697801df29
- Parent:
- 13:e2446fcdc246
- Child:
- 19:2b5d097ca15d
- Child:
- 20:535ef78655df
extend Api for GPS and GNSS
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 | #include "C027_PinNames.h" |
mazgch | 2:b6012cd91657 | 7 | |
mazgch | 9:e7a5959ffae1 | 8 | #define RX_SIZE 256 |
mazgch | 9:e7a5959ffae1 | 9 | #define TX_SIZE 128 |
mazgch | 9:e7a5959ffae1 | 10 | |
mazgch | 2:b6012cd91657 | 11 | class GPSParser |
mazgch | 2:b6012cd91657 | 12 | { |
mazgch | 2:b6012cd91657 | 13 | public: |
mazgch | 2:b6012cd91657 | 14 | #define WAIT -1 |
mazgch | 2:b6012cd91657 | 15 | #define NOT_FOUND 0 |
mazgch | 2:b6012cd91657 | 16 | |
mazgch | 2:b6012cd91657 | 17 | #define UBX 0x100000 |
mazgch | 2:b6012cd91657 | 18 | #define NMEA 0x200000 |
mazgch | 2:b6012cd91657 | 19 | #define LENGTH(x) (x & 0x00FFFF) |
mazgch | 2:b6012cd91657 | 20 | #define PROTOCOL(x) (x & 0xFF0000) |
mazgch | 1:f41579f4e2ed | 21 | |
mazgch | 2:b6012cd91657 | 22 | virtual int getMessage(char* buf, int len) = 0; |
mazgch | 4:c959dd4c5fe8 | 23 | virtual int send(const char* buf, int len); |
mazgch | 4:c959dd4c5fe8 | 24 | virtual int sendNmea(const char* buf, int len); |
mazgch | 11:b084552b03fe | 25 | virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0); |
mazgch | 2:b6012cd91657 | 26 | |
mazgch | 2:b6012cd91657 | 27 | static const char* findNmeaItemPos(int ix, const char* start, const char* end); |
mazgch | 2:b6012cd91657 | 28 | static bool getNmeaItem(int ix, char* buf, int len, double& val); |
mazgch | 2:b6012cd91657 | 29 | static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/); |
mazgch | 2:b6012cd91657 | 30 | static bool getNmeaItem(int ix, char* buf, int len, char& val); |
mazgch | 18:e5697801df29 | 31 | static bool getNmeaAngle(int ix, char* buf, int len, double& d); |
mazgch | 2:b6012cd91657 | 32 | protected: |
mazgch | 2:b6012cd91657 | 33 | static int _getMessage(Pipe<char>* pipe, char* buf, int len); |
mazgch | 2:b6012cd91657 | 34 | static int _parseNmea(Pipe<char>* pipe, int len); |
mazgch | 2:b6012cd91657 | 35 | static int _parseUbx(Pipe<char>* pipe, int len); |
mazgch | 4:c959dd4c5fe8 | 36 | virtual int _send(const void* buf, int len) = 0; |
mazgch | 2:b6012cd91657 | 37 | static const char toHex[16]; |
mazgch | 2:b6012cd91657 | 38 | }; |
mazgch | 2:b6012cd91657 | 39 | |
mazgch | 9:e7a5959ffae1 | 40 | class GPSSerial : public SerialPipe, public GPSParser |
mazgch | 1:f41579f4e2ed | 41 | { |
mazgch | 1:f41579f4e2ed | 42 | public: |
mazgch | 9:e7a5959ffae1 | 43 | GPSSerial(PinName tx = GPSTXD, PinName rx = GPSRXD, int baudrate = GPSBAUD, |
mazgch | 9:e7a5959ffae1 | 44 | int rxSize = RX_SIZE, int txSize = TX_SIZE); |
mazgch | 2:b6012cd91657 | 45 | virtual int getMessage(char* buf, int len); |
mazgch | 2:b6012cd91657 | 46 | protected: |
mazgch | 4:c959dd4c5fe8 | 47 | virtual int _send(const void* buf, int len); |
mazgch | 1:f41579f4e2ed | 48 | }; |
mazgch | 2:b6012cd91657 | 49 | |
mazgch | 2:b6012cd91657 | 50 | class GPSI2C : public I2C, public GPSParser |
mazgch | 2:b6012cd91657 | 51 | { |
mazgch | 2:b6012cd91657 | 52 | public: |
mazgch | 9:e7a5959ffae1 | 53 | GPSI2C(PinName sda = GPSSDA, PinName scl = GPSSCL, |
mazgch | 9:e7a5959ffae1 | 54 | int rxSize = RX_SIZE); |
mazgch | 2:b6012cd91657 | 55 | bool detect(void); |
mazgch | 2:b6012cd91657 | 56 | |
mazgch | 2:b6012cd91657 | 57 | virtual int getMessage(char* buf, int len); |
mazgch | 4:c959dd4c5fe8 | 58 | virtual int send(const char* buf, int len); |
mazgch | 3:c7cd4887560d | 59 | virtual int sendNmea(const char* buf, int len); |
mazgch | 11:b084552b03fe | 60 | virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0); |
mazgch | 2:b6012cd91657 | 61 | protected: |
mazgch | 9:e7a5959ffae1 | 62 | bool writeable(void) { return true; } |
mazgch | 9:e7a5959ffae1 | 63 | bool putc(int c) { char ch = c; return send(&ch, 1); } |
mazgch | 4:c959dd4c5fe8 | 64 | virtual int _send(const void* buf, int len); |
mazgch | 3:c7cd4887560d | 65 | int _get(char* buf, int len); // read the NMEA or UBX stream |
mazgch | 3:c7cd4887560d | 66 | |
mazgch | 2:b6012cd91657 | 67 | Pipe<char> _pipe; |
mazgch | 2:b6012cd91657 | 68 | bool found; |
mazgch | 2:b6012cd91657 | 69 | static const char REGLEN; |
mazgch | 2:b6012cd91657 | 70 | static const char REGSTREAM; |
mazgch | 2:b6012cd91657 | 71 | }; |