@@ -31,14 +31,63 @@ const String Gps::INF_SEVERITY_STRING[] = {
31
31
String (" TST" ), String (" DBG" )
32
32
};
33
33
34
+ bool Gps::is_neo6 () const {
35
+ if (String (hwString).substring (0 ,4 ) == String (" 0004" )) {
36
+ return true ;
37
+ }
38
+ return false ;
39
+ }
40
+
41
+ bool Gps::is_neo8 () const {
42
+ if (String (hwString).substring (0 ,4 ) == String (" 0008" )) {
43
+ return true ;
44
+ }
45
+ return false ;
46
+ }
47
+
48
+ bool Gps::is_neo10 () const {
49
+ if (String (hwString).substring (0 ,4 ) == String (" 000A" )) {
50
+ return true ;
51
+ }
52
+ return false ;
53
+ }
54
+
55
+ String Gps::hw () const {
56
+ if (is_neo6 ()){
57
+ return " Neo6" ;
58
+ }
59
+ if (is_neo8 ()){
60
+ return " Neo8" ;
61
+ }
62
+ if (is_neo10 ()) {
63
+ return " NeoA" ;
64
+ }
65
+ return " Neo" + String (hwString).substring (3 ,4 );
66
+ }
67
+
34
68
void Gps::begin () {
35
69
setBaud ();
36
70
softResetGps ();
37
71
if (mGpsNeedsConfigUpdate ) {
38
72
configureGpsModule ();
39
73
}
40
- enableAlpIfDataIsAvailable ();
41
74
pollStatistics ();
75
+ if ((!is_neo6 ()) || (!SD.exists (AID_INI_DATA_FILE_NAME))) {
76
+ // we're on a non-6 neo and avoid AID_INI because is deprecated
77
+ // or we're on a neo6 but last boot we didn't get far enough to receive fresh
78
+ // ALP_INI data after initializing
79
+ // so restart GPS for good measure.
80
+ if (is_neo6 ()) log_i (" We found no AID_INI on with neo6 on boot - coldstart gps in case its in a state where it doesn't get fixes" );
81
+ if (!is_neo6 ()) log_i (" Coldstart because we found that newer neos profit from that." );
82
+
83
+ coldStartGps ();
84
+ }
85
+ pollStatistics ();
86
+
87
+ if (is_neo6 ()) {
88
+ enableAlpIfDataIsAvailable ();
89
+ }
90
+
42
91
if (mLastTimeTimeSet == 0 ) {
43
92
#ifdef UBX_M10
44
93
setMessageInterval (UBX_CFG_KEY_ID::CFG_MSGOUT_UBX_NAV_TIMEGPS_UART1, 1 );
@@ -293,7 +342,6 @@ void Gps::softResetGps() {
293
342
log_i (" Soft-RESET GPS!" );
294
343
handle ();
295
344
const uint8_t UBX_CFG_RST[] = {0x00 , 0x00 , 0x02 , 0x00 }; // WARM START
296
- // const uint8_t UBX_CFG_RST[] = {0xFF, 0xFF, 0x02, 0x00}; // Cold START
297
345
// we had the case where the reset took several seconds
298
346
// see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309
299
347
// Newer firmware (like M10 and likely also M8) will not ack this
@@ -304,6 +352,20 @@ void Gps::softResetGps() {
304
352
log_i (" Soft-RESET GPS! Done" );
305
353
}
306
354
355
+ void Gps::coldStartGps () {
356
+ log_i (" Cold-Start GPS!" );
357
+ handle ();
358
+ const uint8_t UBX_CFG_RST[] = {0xFF , 0xFF , 0x00 , 0x00 };
359
+ // we had the case where the reset took several seconds
360
+ // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309
361
+ // Newer firmware (like M10 and likely also M8) will not ack this
362
+ // message so we do not wait for the ACK
363
+ sendUbx (UBX_MSG::CFG_RST, UBX_CFG_RST, 4 );
364
+ waitForData (3000 );
365
+ handle ();
366
+ log_i (" Cold Start GPS! Done" );
367
+ }
368
+
307
369
/* There had been changes for the satellites used for SBAS
308
370
* in europe since the firmware of our GPS module was built
309
371
* we configure the module to use the 2 satellites that are
@@ -344,11 +406,15 @@ void Gps::enableAlpIfDataIsAvailable() {
344
406
/* Poll or refresh one time statistics, also spends some time
345
407
* to collect the results.
346
408
*/
409
+
347
410
void Gps::pollStatistics () {
348
- handle ();
349
- sendUbx (UBX_MSG::AID_ALP);
350
411
handle ();
351
412
sendUbx (UBX_MSG::MON_VER);
413
+ handle (20 );
414
+ if (is_neo6 ()){
415
+ // AID_ALP is a neo6-only thing
416
+ sendUbx (UBX_MSG::AID_ALP);
417
+ }
352
418
handle ();
353
419
sendUbx (UBX_MSG::MON_HW);
354
420
handle ();
@@ -777,21 +843,35 @@ int32_t Gps::getMessagesWithFailedCrcCount() const {
777
843
}
778
844
779
845
void Gps::showWaitStatus (DisplayDevice const * display) const {
846
+ static bool clear = false ;
847
+ if (!is_neo6 () && !clear) {
848
+ obsDisplay->clear ();
849
+ clear = true ;
850
+ }
780
851
String satellitesString[2 ];
781
852
if (mValidMessagesReceived == 0 ) { // could not get any valid char from GPS module
782
853
satellitesString[0 ] = " OFF?" ;
783
854
} else if (mLastTimeTimeSet == 0 ) {
784
- satellitesString[0 ] = String (mCurrentGpsRecord .mSatellitesUsed ) + " sats SN:" + String (mLastNoiseLevel );
855
+ satellitesString[0 ] = " aGain:" + String (mLastGain );
856
+ satellitesString[1 ] = String (mCurrentGpsRecord .mSatellitesUsed ) + " sats SN:" + String (mLastNoiseLevel );
785
857
} else {
786
- satellitesString[0 ] = " GPS " + TimeUtils::timeToString ();
858
+ satellitesString[0 ] = String ( hw ()). substring ( 1 ) + TimeUtils::timeToString ();
787
859
satellitesString[1 ] = String (mCurrentGpsRecord .mSatellitesUsed ) + " sats SN:" + String (mLastNoiseLevel );
788
860
}
861
+ obsDisplay->showTextOnGrid (2 , display->currentLine () - 1 , satellitesString[0 ]);
862
+ obsDisplay->showTextOnGrid (2 , display->currentLine (), satellitesString[1 ]);
863
+ if (!is_neo6 ()){
864
+ obsDisplay->showTextOnGrid (0 , 1 , String (hw ())+" GPS" );
865
+ obsDisplay->showTextOnGrid (2 , 1 , " HDOP: " + getHdopAsString () + " D" );
789
866
790
- if (satellitesString[1 ].isEmpty ()) {
791
- obsDisplay->showTextOnGrid (2 , display->currentLine (), satellitesString[0 ]);
792
- } else {
793
- obsDisplay->showTextOnGrid (2 , display->currentLine () - 1 , satellitesString[0 ]);
794
- obsDisplay->showTextOnGrid (2 , display->currentLine (), satellitesString[1 ]);
867
+ obsDisplay->showTextOnGrid (0 , 2 , " Jam: " + String (mLastJamInd ));
868
+ obsDisplay->showTextOnGrid (2 , 2 , " Msgs: " + String (mValidMessagesReceived ));
869
+ obsDisplay->showTextOnGrid (2 , 3 , " Fix: " + String (mCurrentGpsRecord .mFixStatus ) + " D" );
870
+ obsDisplay->showTextOnGrid (0 , 3 , " lat,lon:" );
871
+
872
+
873
+ obsDisplay->showTextOnGrid (0 , 4 , String (mCurrentGpsRecord .mLatitude ));
874
+ obsDisplay->showTextOnGrid (0 , 5 , String (mCurrentGpsRecord .mLongitude ));
795
875
}
796
876
}
797
877
@@ -1098,12 +1178,40 @@ void Gps::parseUbxMessage() {
1098
1178
String (mGpsBuffer .monVer .swVersion ).c_str (),
1099
1179
String (mGpsBuffer .monVer .hwVersion ).c_str (),
1100
1180
mGpsBuffer .ubxHeader .length );
1181
+ for (int i = 0 ; i < sizeof (hwString) && i < sizeof (mGpsBuffer .monVer .hwVersion ) ; i++) {
1182
+ hwString[i]=mGpsBuffer .monVer .hwVersion [i];
1183
+ }
1101
1184
}
1102
1185
break ;
1103
1186
case (uint16_t ) UBX_MSG::MON_HW: {
1104
- log_v (" MON-HW Antenna Status %d, noise level %d" , mGpsBuffer .monHw .aStatus ,
1105
- mGpsBuffer .monHw .noisePerMs );
1106
- mLastNoiseLevel = mGpsBuffer .monHw .noisePerMs ;
1187
+ const char * aStatus;
1188
+ if (is_neo6 ()) {
1189
+ switch (mGpsBuffer .monHw .aStatus ) {
1190
+ case mGpsBuffer .monHw .INIT : aStatus = " init" ; break ;
1191
+ case mGpsBuffer .monHw .DONTKNOW : aStatus = " ?" ; break ;
1192
+ case mGpsBuffer .monHw .OK : aStatus = " ok" ; break ;
1193
+ case mGpsBuffer .monHw .SHORT : aStatus = " short" ; break ;
1194
+ case mGpsBuffer .monHw .OPEN : aStatus = " open" ; break ;
1195
+ default : aStatus = " invalid" ;
1196
+ }
1197
+ log_d (" MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d" , mGpsBuffer .monHw .aStatus , aStatus, mGpsBuffer .monHw .aPower , mGpsBuffer .monHw .agcCnt , mGpsBuffer .monHw .noisePerMs );
1198
+ mLastNoiseLevel = mGpsBuffer .monHw .noisePerMs ;
1199
+ mLastGain = mGpsBuffer .monHw .agcCnt ;
1200
+ mLastJamInd = mGpsBuffer .monHw .jamInd ;
1201
+ } else {
1202
+ switch (mGpsBuffer .monHwNew .aStatus ) {
1203
+ case mGpsBuffer .monHwNew .INIT : aStatus = " init" ; break ;
1204
+ case mGpsBuffer .monHwNew .DONTKNOW : aStatus = " ?" ; break ;
1205
+ case mGpsBuffer .monHwNew .OK : aStatus = " ok" ; break ;
1206
+ case mGpsBuffer .monHwNew .SHORT : aStatus = " short" ; break ;
1207
+ case mGpsBuffer .monHwNew .OPEN : aStatus = " open" ; break ;
1208
+ default : aStatus = " invalid" ;
1209
+ }
1210
+ log_d (" MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d" , mGpsBuffer .monHwNew .aStatus , aStatus, mGpsBuffer .monHwNew .aPower , mGpsBuffer .monHwNew .agcCnt , mGpsBuffer .monHwNew .noisePerMs );
1211
+ mLastNoiseLevel = mGpsBuffer .monHwNew .noisePerMs ;
1212
+ mLastGain = mGpsBuffer .monHwNew .agcCnt ;
1213
+ mLastJamInd = mGpsBuffer .monHwNew .jamInd ;
1214
+ }
1107
1215
}
1108
1216
break ;
1109
1217
case (uint16_t ) UBX_MSG::NAV_STATUS: {
@@ -1113,7 +1221,7 @@ void Gps::parseUbxMessage() {
1113
1221
mGpsUptime = mGpsBuffer .navStatus .msss ;
1114
1222
if (mGpsBuffer .navStatus .ttff != 0 ) {
1115
1223
addStatisticsMessage (" TimeToFix: " + String (mGpsBuffer .navStatus .ttff ) + " ms" );
1116
- } else if (!mAidIniSent ) {
1224
+ } else if (!mAidIniSent and is_neo6 () ) {
1117
1225
mAidIniSent = true ;
1118
1226
aidIni ();
1119
1227
}
@@ -1130,7 +1238,7 @@ void Gps::parseUbxMessage() {
1130
1238
}
1131
1239
break ;
1132
1240
case (uint16_t ) UBX_MSG::NAV_SOL: {
1133
- log_v (" SOL: iTOW: %u, gpsFix: %d, flags: %02x, numSV: %d, pDop: %04d." ,
1241
+ log_d (" SOL: iTOW: %u, gpsFix: %d, flags: %02x, numSV: %d, pDop: %04d." ,
1134
1242
mGpsBuffer .navSol .iTow , mGpsBuffer .navSol .gpsFix , mGpsBuffer .navSol .flags ,
1135
1243
mGpsBuffer .navSol .numSv , mGpsBuffer .navSol .pDop );
1136
1244
if (mGpsBuffer .navSol .flags & 4 ) { // WKNSET
@@ -1148,15 +1256,15 @@ void Gps::parseUbxMessage() {
1148
1256
}
1149
1257
break ;
1150
1258
case (uint16_t ) UBX_MSG::NAV_PVT: {
1151
- log_v (" PVT: iTOW: %u, fixType: %d, flags: %02x, numSV: %d, pDop: %04d." ,
1259
+ log_d (" PVT: iTOW: %u, fixType: %d, flags: %02x, numSV: %d, pDop: %04d." ,
1152
1260
mGpsBuffer .navPvt .iTow , mGpsBuffer .navPvt .fixType , mGpsBuffer .navPvt .flags ,
1153
1261
mGpsBuffer .navPvt .numSV , mGpsBuffer .navPvt .pDOP );
1154
1262
prepareGpsData (mGpsBuffer .navPvt .iTow , mMessageStarted );
1155
1263
mIncomingGpsRecord .setInfo (mGpsBuffer .navPvt .numSV , mGpsBuffer .navPvt .fixType , mGpsBuffer .navPvt .flags );
1156
1264
}
1157
1265
break ;
1158
1266
case (uint16_t ) UBX_MSG::NAV_VELNED: {
1159
- log_v (" VELNED: iTOW: %u, speed: %d cm/s, gSpeed: %d cm/s, heading: %d,"
1267
+ log_d (" VELNED: iTOW: %u, speed: %d cm/s, gSpeed: %d cm/s, heading: %d,"
1160
1268
" speedAcc: %d, cAcc: %d" ,
1161
1269
mGpsBuffer .navVelned .iTow , mGpsBuffer .navVelned .speed , mGpsBuffer .navVelned .gSpeed ,
1162
1270
mGpsBuffer .navVelned .heading , mGpsBuffer .navVelned .sAcc , mGpsBuffer .navVelned .cAcc );
@@ -1289,7 +1397,7 @@ void Gps::parseUbxMessage() {
1289
1397
log_d (" CFG_GNSS" );
1290
1398
break ;
1291
1399
default :
1292
- log_e (" Got UBX_MESSAGE! Id: 0x%04x Len %d iTOW %d" , mGpsBuffer .ubxHeader .ubxMsgId ,
1400
+ log_e (" Got unparsed UBX_MESSAGE! Id: 0x%04x Len %d iTOW %d" , mGpsBuffer .ubxHeader .ubxMsgId ,
1293
1401
mGpsBuffer .ubxHeader .length , mGpsBuffer .navStatus .iTow );
1294
1402
}
1295
1403
}
@@ -1314,10 +1422,10 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin
1314
1422
mIncomingGpsRecord .setWeek (mLastGpsWeek );
1315
1423
}
1316
1424
if ((message.valid & 0x03 ) == 0x03 // WEEK && TOW
1317
- && delayMs < 250
1425
+ && delayMs < 1000
1318
1426
&& message.tAcc < (20 * 1000 * 1000 /* 20ms */ )
1319
- && (mLastTimeTimeSet == 0
1320
- || (mLastTimeTimeSet + (2 * 60 * 1000 /* 2 minutes */ )) < receivedMs)) {
1427
+ && (( mLastTimeTimeSet == 0 )
1428
+ || (( mLastTimeTimeSet + (2 * 60 * 1000 /* 2 minutes */ )) < receivedMs) )) {
1321
1429
String oldTime = TimeUtils::dateTimeToString ();
1322
1430
TimeUtils::setClockByGps (message.iTow , message.fTow , message.week );
1323
1431
String newTime = TimeUtils::dateTimeToString ();
@@ -1328,10 +1436,12 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin
1328
1436
+ " ms. tAcc:" + String (message.tAcc ) + " ns" );
1329
1437
}
1330
1438
if (mLastTimeTimeSet == 0 ) {
1331
- mLastTimeTimeSet = receivedMs;
1332
- // This triggers another NAV-TIMEGPS message!
1439
+ if (delayMs < 100 ) { // keep mLastTimeTimeSet at 0 unless reasonable delayMs
1440
+ mLastTimeTimeSet = receivedMs;
1441
+ }
1442
+ // This triggers another NAV-TIMEGPS message! more often until good time is received
1333
1443
#ifdef UBX_M6
1334
- setMessageInterval (UBX_MSG::NAV_TIMEGPS, 240 , false ); // every 4 minutes
1444
+ setMessageInterval (UBX_MSG::NAV_TIMEGPS, (delayMs> 100 ) ? 5 : 240 , false ); // every 4 minutes
1335
1445
#endif
1336
1446
#ifdef UBX_M10
1337
1447
setMessageInterval (UBX_CFG_KEY_ID::CFG_MSGOUT_UBX_NAV_TIMEGPS_UART1, 240 , false ); // every 4 minutes
@@ -1411,6 +1521,14 @@ uint16_t Gps::getLastNoiseLevel() const {
1411
1521
return mLastNoiseLevel ;
1412
1522
}
1413
1523
1524
+ uint16_t Gps::getLastAntennaGain () const {
1525
+ return mLastGain ;
1526
+ }
1527
+
1528
+ uint8_t Gps::getLastJamInd () const {
1529
+ return mLastJamInd ;
1530
+ }
1531
+
1414
1532
uint32_t Gps::getBaudRate () {
1415
1533
return mSerial .baudRate ();
1416
1534
}
0 commit comments