* add C027_Support fork

Fork of C027_Support by u-blox

Committer:
mazgch
Date:
Tue Apr 08 11:15:33 2014 +0000
Revision:
24:0e287a85ac9e
Parent:
19:2b5d097ca15d
Parent:
20:535ef78655df
Child:
31:a0bed6c1e05d
merged branches

Who changed what in which revision?

UserRevisionLine numberNew 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 2:b6012cd91657 22 #define UBX 0x100000
mazgch 2:b6012cd91657 23 #define NMEA 0x200000
mazgch 2:b6012cd91657 24 #define LENGTH(x) (x & 0x00FFFF)
mazgch 2:b6012cd91657 25 #define PROTOCOL(x) (x & 0xFF0000)
mazgch 1:f41579f4e2ed 26
mazgch 2:b6012cd91657 27 virtual int getMessage(char* buf, int len) = 0;
mazgch 4:c959dd4c5fe8 28 virtual int send(const char* buf, int len);
mazgch 4:c959dd4c5fe8 29 virtual int sendNmea(const char* buf, int len);
mazgch 11:b084552b03fe 30 virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0);
mazgch 2:b6012cd91657 31
mazgch 2:b6012cd91657 32 static const char* findNmeaItemPos(int ix, const char* start, const char* end);
mazgch 2:b6012cd91657 33 static bool getNmeaItem(int ix, char* buf, int len, double& val);
mazgch 2:b6012cd91657 34 static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
mazgch 2:b6012cd91657 35 static bool getNmeaItem(int ix, char* buf, int len, char& val);
mazgch 20:535ef78655df 36 static bool getNmeaAngle(int ix, char* buf, int len, double& val);
mazgch 2:b6012cd91657 37 protected:
mazgch 2:b6012cd91657 38 static int _getMessage(Pipe<char>* pipe, char* buf, int len);
mazgch 2:b6012cd91657 39 static int _parseNmea(Pipe<char>* pipe, int len);
mazgch 2:b6012cd91657 40 static int _parseUbx(Pipe<char>* pipe, int len);
mazgch 4:c959dd4c5fe8 41 virtual int _send(const void* buf, int len) = 0;
mazgch 2:b6012cd91657 42 static const char toHex[16];
mazgch 2:b6012cd91657 43 };
mazgch 2:b6012cd91657 44
mazgch 9:e7a5959ffae1 45 class GPSSerial : public SerialPipe, public GPSParser
mazgch 1:f41579f4e2ed 46 {
mazgch 1:f41579f4e2ed 47 public:
mazgch 19:2b5d097ca15d 48 GPSSerial(PinName tx _C027DEFAULT( GPSTXD ),
mazgch 19:2b5d097ca15d 49 PinName rx _C027DEFAULT( GPSRXD ),
mazgch 19:2b5d097ca15d 50 int baudrate _C027DEFAULT( GPSBAUD ),
mazgch 19:2b5d097ca15d 51 int rxSize = 256 ,
mazgch 19:2b5d097ca15d 52 int txSize = 128 );
mazgch 2:b6012cd91657 53 virtual int getMessage(char* buf, int len);
mazgch 2:b6012cd91657 54 protected:
mazgch 4:c959dd4c5fe8 55 virtual int _send(const void* buf, int len);
mazgch 1:f41579f4e2ed 56 };
mazgch 2:b6012cd91657 57
mazgch 2:b6012cd91657 58 class GPSI2C : public I2C, public GPSParser
mazgch 2:b6012cd91657 59 {
mazgch 2:b6012cd91657 60 public:
mazgch 19:2b5d097ca15d 61 GPSI2C(PinName sda _C027DEFAULT( GPSSDA ),
mazgch 19:2b5d097ca15d 62 PinName scl _C027DEFAULT( GPSSCL ),
mazgch 19:2b5d097ca15d 63 unsigned char i2cAdr _C027DEFAULT( GPSADR ),
mazgch 19:2b5d097ca15d 64 int rxSize = 256 );
mazgch 2:b6012cd91657 65 bool detect(void);
mazgch 2:b6012cd91657 66
mazgch 2:b6012cd91657 67 virtual int getMessage(char* buf, int len);
mazgch 4:c959dd4c5fe8 68 virtual int send(const char* buf, int len);
mazgch 3:c7cd4887560d 69 virtual int sendNmea(const char* buf, int len);
mazgch 11:b084552b03fe 70 virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0);
mazgch 2:b6012cd91657 71 protected:
mazgch 9:e7a5959ffae1 72 bool writeable(void) { return true; }
mazgch 9:e7a5959ffae1 73 bool putc(int c) { char ch = c; return send(&ch, 1); }
mazgch 4:c959dd4c5fe8 74 virtual int _send(const void* buf, int len);
mazgch 3:c7cd4887560d 75 int _get(char* buf, int len); // read the NMEA or UBX stream
mazgch 3:c7cd4887560d 76
mazgch 2:b6012cd91657 77 Pipe<char> _pipe;
mazgch 2:b6012cd91657 78 bool found;
mazgch 19:2b5d097ca15d 79 unsigned char _i2cAdr;
mazgch 2:b6012cd91657 80 static const char REGLEN;
mazgch 2:b6012cd91657 81 static const char REGSTREAM;
mazgch 2:b6012cd91657 82 };