Own fork of C027_Support

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of C027_Support by u-blox

Committer:
mazgch
Date:
Fri Apr 11 16:30:54 2014 +0000
Revision:
38:e6cab4632d84
Parent:
31:a0bed6c1e05d
Child:
39:9b4b9433e220
more docu

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 38:e6cab4632d84 16 /** basic gps parser class
mazgch 38:e6cab4632d84 17 */
mazgch 2:b6012cd91657 18 class GPSParser
mazgch 2:b6012cd91657 19 {
mazgch 2:b6012cd91657 20 public:
mazgch 2:b6012cd91657 21 #define WAIT -1
mazgch 2:b6012cd91657 22 #define NOT_FOUND 0
mazgch 2:b6012cd91657 23
mazgch 31:a0bed6c1e05d 24 #define UNKNOWN 0x000000
mazgch 2:b6012cd91657 25 #define UBX 0x100000
mazgch 2:b6012cd91657 26 #define NMEA 0x200000
mazgch 2:b6012cd91657 27 #define LENGTH(x) (x & 0x00FFFF)
mazgch 2:b6012cd91657 28 #define PROTOCOL(x) (x & 0xFF0000)
mazgch 1:f41579f4e2ed 29
mazgch 2:b6012cd91657 30 virtual int getMessage(char* buf, int len) = 0;
mazgch 4:c959dd4c5fe8 31 virtual int send(const char* buf, int len);
mazgch 4:c959dd4c5fe8 32 virtual int sendNmea(const char* buf, int len);
mazgch 11:b084552b03fe 33 virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0);
mazgch 31:a0bed6c1e05d 34 void powerOff(void);
mazgch 2:b6012cd91657 35
mazgch 2:b6012cd91657 36 static const char* findNmeaItemPos(int ix, const char* start, const char* end);
mazgch 2:b6012cd91657 37 static bool getNmeaItem(int ix, char* buf, int len, double& val);
mazgch 2:b6012cd91657 38 static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
mazgch 2:b6012cd91657 39 static bool getNmeaItem(int ix, char* buf, int len, char& val);
mazgch 20:535ef78655df 40 static bool getNmeaAngle(int ix, char* buf, int len, double& val);
mazgch 2:b6012cd91657 41 protected:
mazgch 2:b6012cd91657 42 static int _getMessage(Pipe<char>* pipe, char* buf, int len);
mazgch 2:b6012cd91657 43 static int _parseNmea(Pipe<char>* pipe, int len);
mazgch 2:b6012cd91657 44 static int _parseUbx(Pipe<char>* pipe, int len);
mazgch 4:c959dd4c5fe8 45 virtual int _send(const void* buf, int len) = 0;
mazgch 2:b6012cd91657 46 static const char toHex[16];
mazgch 2:b6012cd91657 47 };
mazgch 2:b6012cd91657 48
mazgch 38:e6cab4632d84 49 /** gps class which uses a serial port
mazgch 38:e6cab4632d84 50 as physical interface.
mazgch 38:e6cab4632d84 51 */
mazgch 9:e7a5959ffae1 52 class GPSSerial : public SerialPipe, public GPSParser
mazgch 1:f41579f4e2ed 53 {
mazgch 1:f41579f4e2ed 54 public:
mazgch 38:e6cab4632d84 55 /** Constructor
mazgch 38:e6cab4632d84 56 \param tx is the serial ports transmit pin (gps to CPU)
mazgch 38:e6cab4632d84 57 \param rx is the serial ports receive pin (CPU to gps)
mazgch 38:e6cab4632d84 58 \param baudrate the baudrate of the gps use 9600
mazgch 38:e6cab4632d84 59 \param rxSize the size of the serial rx buffer
mazgch 38:e6cab4632d84 60 \param txSize the size of the serial tx buffer
mazgch 38:e6cab4632d84 61 */
mazgch 19:2b5d097ca15d 62 GPSSerial(PinName tx _C027DEFAULT( GPSTXD ),
mazgch 19:2b5d097ca15d 63 PinName rx _C027DEFAULT( GPSRXD ),
mazgch 19:2b5d097ca15d 64 int baudrate _C027DEFAULT( GPSBAUD ),
mazgch 19:2b5d097ca15d 65 int rxSize = 256 ,
mazgch 19:2b5d097ca15d 66 int txSize = 128 );
mazgch 38:e6cab4632d84 67 /** Get a line from the physical interface.
mazgch 38:e6cab4632d84 68 \param buf the buffer to store it
mazgch 38:e6cab4632d84 69 \param len size of the buffer
mazgch 38:e6cab4632d84 70 \return type and length if something was found,
mazgch 38:e6cab4632d84 71 WAIT if not enough data is available
mazgch 38:e6cab4632d84 72 NOT_FOUND if nothing was found
mazgch 38:e6cab4632d84 73 */
mazgch 2:b6012cd91657 74 virtual int getMessage(char* buf, int len);
mazgch 2:b6012cd91657 75 protected:
mazgch 38:e6cab4632d84 76 /** Write bytes to the physical interface.
mazgch 38:e6cab4632d84 77 \param buf the buffer to write
mazgch 38:e6cab4632d84 78 \param len size of the buffer to write
mazgch 38:e6cab4632d84 79 \return bytes written
mazgch 38:e6cab4632d84 80 */
mazgch 4:c959dd4c5fe8 81 virtual int _send(const void* buf, int len);
mazgch 1:f41579f4e2ed 82 };
mazgch 2:b6012cd91657 83
mazgch 38:e6cab4632d84 84 /** gps class which uses a i2c as physical interface.
mazgch 38:e6cab4632d84 85 */
mazgch 2:b6012cd91657 86 class GPSI2C : public I2C, public GPSParser
mazgch 2:b6012cd91657 87 {
mazgch 2:b6012cd91657 88 public:
mazgch 38:e6cab4632d84 89 /** Constructor
mazgch 38:e6cab4632d84 90 \param sda is the I2C SDA pin (between CPU and GPS)
mazgch 38:e6cab4632d84 91 \param scl is the I2C SCL pin (CPU to GPS)
mazgch 38:e6cab4632d84 92 \param adr the I2C address of the GPS set to (66<<1)
mazgch 38:e6cab4632d84 93 \param rxSize the size of the serial rx buffer
mazgch 38:e6cab4632d84 94 */
mazgch 19:2b5d097ca15d 95 GPSI2C(PinName sda _C027DEFAULT( GPSSDA ),
mazgch 19:2b5d097ca15d 96 PinName scl _C027DEFAULT( GPSSCL ),
mazgch 19:2b5d097ca15d 97 unsigned char i2cAdr _C027DEFAULT( GPSADR ),
mazgch 19:2b5d097ca15d 98 int rxSize = 256 );
mazgch 38:e6cab4632d84 99 /** helper function to probe the i2c device
mazgch 38:e6cab4632d84 100 \return true if successfully detected the gps.
mazgch 38:e6cab4632d84 101 */
mazgch 2:b6012cd91657 102 bool detect(void);
mazgch 2:b6012cd91657 103
mazgch 38:e6cab4632d84 104 /** Get a line from the physical interface.
mazgch 38:e6cab4632d84 105 \param buf the buffer to store it
mazgch 38:e6cab4632d84 106 \param len size of the buffer
mazgch 38:e6cab4632d84 107 \return type and length if something was found,
mazgch 38:e6cab4632d84 108 WAIT if not enough data is available
mazgch 38:e6cab4632d84 109 NOT_FOUND if nothing was found
mazgch 38:e6cab4632d84 110 */
mazgch 2:b6012cd91657 111 virtual int getMessage(char* buf, int len);
mazgch 38:e6cab4632d84 112
mazgch 38:e6cab4632d84 113 /** send a buffer
mazgch 38:e6cab4632d84 114 \param buf the buffer to write
mazgch 38:e6cab4632d84 115 \param len size of the buffer to write
mazgch 38:e6cab4632d84 116 \return bytes written
mazgch 38:e6cab4632d84 117 */
mazgch 4:c959dd4c5fe8 118 virtual int send(const char* buf, int len);
mazgch 38:e6cab4632d84 119
mazgch 38:e6cab4632d84 120 /** send a NMEA message, this function just takes the
mazgch 38:e6cab4632d84 121 payload and calculates and adds checksum. ($ and *XX\r\n will be added)
mazgch 38:e6cab4632d84 122 \param buf the message payload to write
mazgch 38:e6cab4632d84 123 \param len size of the message payload to write
mazgch 38:e6cab4632d84 124 \return total bytes written
mazgch 38:e6cab4632d84 125 */
mazgch 3:c7cd4887560d 126 virtual int sendNmea(const char* buf, int len);
mazgch 38:e6cab4632d84 127
mazgch 38:e6cab4632d84 128 /** send a UBX message, this function just takes the
mazgch 38:e6cab4632d84 129 payload and calculates and adds checksum.
mazgch 38:e6cab4632d84 130 \param cls the UBX class id
mazgch 38:e6cab4632d84 131 \param id the UBX message id
mazgch 38:e6cab4632d84 132 \param buf the message payload to write
mazgch 38:e6cab4632d84 133 \param len size of the message payload to write
mazgch 38:e6cab4632d84 134 \return total bytes written
mazgch 38:e6cab4632d84 135 */
mazgch 11:b084552b03fe 136 virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf = NULL, int len = 0);
mazgch 2:b6012cd91657 137 protected:
mazgch 38:e6cab4632d84 138 /** check if the port is writeable (like SerialPipe)
mazgch 38:e6cab4632d84 139 \return true if writeable
mazgch 38:e6cab4632d84 140 */
mazgch 9:e7a5959ffae1 141 bool writeable(void) { return true; }
mazgch 38:e6cab4632d84 142 /** Write a character (like SerialPipe)
mazgch 38:e6cab4632d84 143 \param c the character to write
mazgch 38:e6cab4632d84 144 \return true if succesffully written
mazgch 38:e6cab4632d84 145 */
mazgch 9:e7a5959ffae1 146 bool putc(int c) { char ch = c; return send(&ch, 1); }
mazgch 38:e6cab4632d84 147 /** Write bytes to the physical interface.
mazgch 38:e6cab4632d84 148 \param buf the buffer to write
mazgch 38:e6cab4632d84 149 \param len size of the buffer to write
mazgch 38:e6cab4632d84 150 \return bytes written
mazgch 38:e6cab4632d84 151 */
mazgch 4:c959dd4c5fe8 152 virtual int _send(const void* buf, int len);
mazgch 38:e6cab4632d84 153 /** read bytes from the physical interface.
mazgch 38:e6cab4632d84 154 \param buf the buffer to read into
mazgch 38:e6cab4632d84 155 \param len size of the read buffer
mazgch 38:e6cab4632d84 156 \return bytes read
mazgch 38:e6cab4632d84 157 */
mazgch 38:e6cab4632d84 158 int _get(char* buf, int len);
mazgch 3:c7cd4887560d 159
mazgch 38:e6cab4632d84 160 Pipe<char> _pipe; //!< the rx pipe
mazgch 38:e6cab4632d84 161 bool found; //!< flag if device is detected.
mazgch 38:e6cab4632d84 162 unsigned char _i2cAdr; //!< the i2c address
mazgch 38:e6cab4632d84 163 static const char REGLEN; //!< the length i2c register address
mazgch 38:e6cab4632d84 164 static const char REGSTREAM;//!< the stream i2c register address
mazgch 2:b6012cd91657 165 };