@@ -587,6 +587,7 @@ JshI2CInfo i2cHRM;
587
587
#define PRESSURE_I2C &i2cPressure
588
588
#define HRM_I2C &i2cHRM
589
589
#define GPS_UART EV_SERIAL1
590
+ #define GPS_CASIC 1 // handle decoding of 'CASIC' packets from the GPS
590
591
#define HEARTRATE 1
591
592
592
593
bool pressureBMP280Enabled = false;
@@ -4658,7 +4659,7 @@ bool jswrap_banglejs_idle() {
4658
4659
bool jswrap_banglejs_gps_character (char ch ) {
4659
4660
#ifdef GPS_PIN_RX
4660
4661
// if too many chars, roll over since it's probably because we skipped a newline
4661
- // or messed the message length
4662
+ // or messed up the message length
4662
4663
if (gpsLineLength >= sizeof (gpsLine )) {
4663
4664
#ifdef GPS_UBLOX
4664
4665
if (inComingUbloxProtocol == UBLOX_PROTOCOL_UBX &&
@@ -4689,6 +4690,21 @@ bool jswrap_banglejs_gps_character(char ch) {
4689
4690
}
4690
4691
#endif // GPS_UBLOX
4691
4692
gpsLine [gpsLineLength ++ ] = ch ;
4693
+ #ifdef GPS_CASIC
4694
+ if (gpsLineLength > 2 && gpsLine [0 ]== 0xBA && gpsLine [1 ]== 0xCE ) {
4695
+ if (gpsLineLength < 4 ) return true; // not enough data for length
4696
+ int len = gpsLine [2 ] | (gpsLine [3 ] << 8 );
4697
+ // 4 class, 5 = msg
4698
+ // 4 byte checksum on end
4699
+ if (gpsLineLength >=len + 10 ) { // packet end!
4700
+ memcpy (gpsLastLine , gpsLine , gpsLineLength );
4701
+ gpsLastLineLength = gpsLineLength ;
4702
+ bangleTasks |= JSBT_GPS_DATA_LINE ;
4703
+ gpsClearLine ();
4704
+ }
4705
+ return true;
4706
+ }
4707
+ #endif
4692
4708
if (
4693
4709
#ifdef GPS_UBLOX
4694
4710
inComingUbloxProtocol == UBLOX_PROTOCOL_NMEA &&
@@ -4707,8 +4723,20 @@ bool jswrap_banglejs_gps_character(char ch) {
4707
4723
if (gpsLineLength > 2 && gpsLineLength <= NMEA_MAX_SIZE && gpsLine [gpsLineLength - 2 ] == '\r' ) {
4708
4724
gpsLine [gpsLineLength - 2 ] = 0 ; // just overwriting \r\n
4709
4725
gpsLine [gpsLineLength - 1 ] = 0 ;
4710
- if (nmea_decode (& gpsFix , (char * )gpsLine ))
4726
+ if (nmea_decode (& gpsFix , (char * )gpsLine )) {
4711
4727
bangleTasks |= JSBT_GPS_DATA ;
4728
+ #ifdef BANGLEJS_Q3
4729
+ if (gpsFix .packetCount == 1 ) { // first packet
4730
+ // https://github.com/espruino/Espruino/issues/2354 - on newer Bangle.js, speed/time may not be reported
4731
+ // as there's no RMC packet by default. If we detect this in 1st packet send a command to fix it
4732
+ if ((gpsFix .packetsParsed & NMEA_RMC )== 0 ) {
4733
+ jshTransmitPrintf (GPS_UART ,"$PCAS03,1,0,0,1,1,0,0,0*03\r\n" );
4734
+ }
4735
+ }
4736
+ #endif
4737
+ // reset what packets we think we got
4738
+ gpsFix .packetsParsed = NMEA_NONE ;
4739
+ }
4712
4740
if (bangleTasks & (JSBT_GPS_DATA_PARTIAL |JSBT_GPS_DATA_LINE )) {
4713
4741
// we were already waiting to post data, so lets not overwrite it
4714
4742
bangleTasks |= JSBT_GPS_DATA_OVERFLOW ;
0 commit comments