![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Diff: Ublox6.cpp
- Revision:
- 18:3f8a8f6e3cc1
- Parent:
- 16:eb28d0f64a9b
- Child:
- 19:0d1728091519
diff -r 5c2af0904e87 -r 3f8a8f6e3cc1 Ublox6.cpp --- a/Ublox6.cpp Thu Dec 13 23:27:04 2018 +0000 +++ b/Ublox6.cpp Fri Dec 14 00:36:06 2018 +0000 @@ -7,8 +7,10 @@ #define POSLLH_BIT 0x02 #define SOL_BIT 0x04 #define VELNED_BIT 0x08 + #define SYNC1 0xB5 #define SYNC2 0x62 + #define POSLLH_MSG 0x02 #define SBAS_MSG 0x32 #define VELNED_MSG 0x12 @@ -17,6 +19,7 @@ #define DOP_MSG 0x04 #define DGPS_MSG 0x31 #define SVINFO_MSG 0x30 + #define CFG 0x06 #define NAV 0x01 #define MSG 0x01 @@ -26,7 +29,20 @@ #define INT(X) *(int16_t *)(&data[X]) #define UINT(X) *(uint16_t *)(&data[X]) -// TODO 2: abstract LED/status to some kind of pub/sub thing +Ublox6::Ublox6() +{ + // clear flags + _ready = 0; + _available = false; + // clear out structs + tmp.lat = 0; + tmp.lon = 0; + tmp.course = 0; + tmp.speed = 0; + tmp.hdop = 0; + tmp.svcount = 0; + latest = tmp; +} void Ublox6::parse(unsigned char cc) { @@ -98,32 +114,32 @@ case 0x01: // NAV- switch (id) { case POSLLH_MSG: // NAV-POSLLH - _longitude = ((float)LONG(4))/10000000.0; - _latitude = ((float)LONG(8))/10000000.0; + tmp.lon = ((float)LONG(4))/10000000.0; + tmp.lat = ((float)LONG(8))/10000000.0; // vAcc = ULONG(24); // mm // hAcc = ULONG(20); // mm - _available |= POSLLH_BIT; + _ready |= POSLLH_BIT; break; case DOP_MSG: // NAV-DOP //gDOP = ((float) UINT(4))/100.0; //tDOP = ((float) UINT(8))/100.0; //vDOP = ((float) UINT(10))/100.0; - _hdop = ((float) UINT(12))/100.0; - _available |= DOP_BIT; + tmp.hdop = ((float) UINT(12))/100.0; + _ready |= DOP_BIT; break; case SOL_MSG: // NAV-SOL //week = UINT(8); //pDOP = ((float) UINT(44))/ 100.0; //pAcc = ULONG(24); - _sat_count = data[47]; - _available |= SOL_BIT; + tmp.svcount = data[47]; + _ready |= SOL_BIT; break; case VELNED_MSG: // NAV-VELNED - _speed_mps = ULONG(20)/100.0; + tmp.speed = ULONG(20)/100.0; //sAcc = ULONG(28)/100.0; - _course_deg = ((float) LONG(24))/100000.0; + tmp.course = ((float) LONG(24))/100000.0; //cAcc = ((float) LONG(32))/100000.0; - _available |= VELNED_BIT; + _ready |= VELNED_BIT; break; default: break; @@ -145,18 +161,35 @@ default: break; } + + if (_ready == POSLLH_BIT|DOP_BIT|SOL_BIT|VELNED_BIT) { + latest = tmp; + _ready = 0; + _available = true; + } + + return; } +void Ublox6::read(double& lat, double& lon, float& course, float& speed, float& hdop, int& svcount) { + lat = latest.lat; + lon = latest.lon; + course = latest.course; + speed = latest.speed; + hdop = latest.hdop; + svcount = latest.svcount; + + return; +} + + + bool Ublox6::available(void) { - return (_available & (DOP_BIT|POSLLH_BIT|SOL_BIT|VELNED_BIT)); + return _available; } -void Ublox6::reset_available(void) -{ - _available = 0; -} - +/* double Ublox6::latitude(void) { return _latitude; @@ -184,5 +217,6 @@ int Ublox6::sat_count(void) { - return _sat_count; + return _svcount; } +*/