@@ -587,6 +587,7 @@ JshI2CInfo i2cHRM;
587587#define PRESSURE_I2C &i2cPressure
588588#define HRM_I2C &i2cHRM
589589#define GPS_UART EV_SERIAL1
590+ #define GPS_CASIC 1 // handle decoding of 'CASIC' packets from the GPS
590591#define HEARTRATE 1
591592
592593bool pressureBMP280Enabled = false;
@@ -4658,7 +4659,7 @@ bool jswrap_banglejs_idle() {
46584659bool jswrap_banglejs_gps_character (char ch ) {
46594660#ifdef GPS_PIN_RX
46604661 // 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
46624663 if (gpsLineLength >= sizeof (gpsLine )) {
46634664#ifdef GPS_UBLOX
46644665 if (inComingUbloxProtocol == UBLOX_PROTOCOL_UBX &&
@@ -4689,6 +4690,21 @@ bool jswrap_banglejs_gps_character(char ch) {
46894690 }
46904691#endif // GPS_UBLOX
46914692 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
46924708 if (
46934709#ifdef GPS_UBLOX
46944710 inComingUbloxProtocol == UBLOX_PROTOCOL_NMEA &&
@@ -4707,8 +4723,20 @@ bool jswrap_banglejs_gps_character(char ch) {
47074723 if (gpsLineLength > 2 && gpsLineLength <= NMEA_MAX_SIZE && gpsLine [gpsLineLength - 2 ] == '\r' ) {
47084724 gpsLine [gpsLineLength - 2 ] = 0 ; // just overwriting \r\n
47094725 gpsLine [gpsLineLength - 1 ] = 0 ;
4710- if (nmea_decode (& gpsFix , (char * )gpsLine ))
4726+ if (nmea_decode (& gpsFix , (char * )gpsLine )) {
47114727 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+ }
47124740 if (bangleTasks & (JSBT_GPS_DATA_PARTIAL |JSBT_GPS_DATA_LINE )) {
47134741 // we were already waiting to post data, so lets not overwrite it
47144742 bangleTasks |= JSBT_GPS_DATA_OVERFLOW ;
0 commit comments