diff --git a/Common/Source/Comm/LKFlarm.cpp b/Common/Source/Comm/LKFlarm.cpp index 58ffa9ac3..5296e269a 100755 --- a/Common/Source/Comm/LKFlarm.cpp +++ b/Common/Source/Comm/LKFlarm.cpp @@ -251,6 +251,8 @@ BOOL NMEAParser::PFLAV(const char *String, char **params, size_t nparams, NMEA_I */ if(nparams > 3) { + ScopeLock lock(CritSec_FlightData); + pGPS->FLARM_HW_Version = strtod(params[1], nullptr); pGPS->FLARM_SW_Version = strtod(params[2], nullptr); @@ -365,6 +367,8 @@ BOOL NMEAParser::PFLAU(const char *String, char **params, size_t nparams, NMEA_I return FALSE; } + ScopeLock lock(CritSec_FlightData); + setFlarmAvailable(pGPS); pGPS->FLARM_RX = strtoul(params[0], nullptr, 10); // number of received FLARM devices @@ -574,6 +578,8 @@ BOOL NMEAParser::PFLAA(const char *String, char **params, size_t nparams, NMEA_I return FALSE; } + ScopeLock lock(CritSec_FlightData); + setFlarmAvailable(pGPS); // 5 id, 6 digit hex diff --git a/Common/Source/Comm/Parser.cpp b/Common/Source/Comm/Parser.cpp index df8347f1e..bb3d1392b 100755 --- a/Common/Source/Comm/Parser.cpp +++ b/Common/Source/Comm/Parser.cpp @@ -232,27 +232,21 @@ BOOL NMEAParser::ParseNMEAString_Internal(DeviceDescriptor_t& d, const char* Str std::string_view token = params[0] + 2; // Proprietary String if (token == "TAS1"sv) { - ScopeLock lock(CritSec_FlightData); return PTAS1(d, &String[7], params + 1, n_params - 1, pGPS); } if (token == "FLAV"sv) { - ScopeLock lock(CritSec_FlightData); return PFLAV(&String[7], params + 1, n_params - 1, pGPS); } if (token == "FLAA"sv) { - ScopeLock lock(CritSec_FlightData); return PFLAA(&String[7], params + 1, n_params - 1, pGPS); } if (token == "FLAU"sv) { - ScopeLock lock(CritSec_FlightData); return PFLAU(&String[7], params + 1, n_params - 1, pGPS); } if (token == "GRMZ"sv) { - ScopeLock lock(CritSec_FlightData); return RMZ(d, &String[7], params + 1, n_params - 1, pGPS); } if (token == "LKAS"sv) { - ScopeLock lock(CritSec_FlightData); return PLKAS(&String[7], params + 1, n_params - 1, pGPS); } return FALSE; @@ -262,39 +256,32 @@ BOOL NMEAParser::ParseNMEAString_Internal(DeviceDescriptor_t& d, const char* Str // GNSS String std::string_view token = params[0] + 3; if (token == "GSA"sv) { - ScopeLock lock(CritSec_FlightData); return GSA(&String[7], params + 1, n_params - 1, pGPS); } if (token == "GLL"sv) { /* - ScopeLock lock(CritSec_FlightData); return GLL(&String[7], params + 1, n_params-1, pGPS); */ return FALSE; } if (token == "RMB"sv) { /* - ScopeLock lock(CritSec_FlightData); return RMB(&String[7], params + 1, n_params-1, pGPS); */ return FALSE; } if (token == "RMC"sv) { - ScopeLock lock(CritSec_FlightData); return RMC(&String[7], params + 1, n_params - 1, pGPS); } if (token == "GGA"sv) { - ScopeLock lock(CritSec_FlightData); return GGA(&String[7], params + 1, n_params - 1, pGPS); } if (token == "VTG"sv) { - ScopeLock lock(CritSec_FlightData); return VTG(&String[7], params + 1, n_params - 1, pGPS); } } if (std::string_view(params[0] + 1) == "HCHDG"sv) { - ScopeLock lock(CritSec_FlightData); return HCHDG(&String[7], params + 1, n_params - 1, pGPS); } @@ -428,6 +415,8 @@ BOOL NMEAParser::GLL(const char* String, char** params, size_t nparams, NMEA_INF if (!activeGPS) return TRUE; + ScopeLock lock(CritSec_FlightData); + pGPS->NAVWarning = !gpsValid; // use valid time with invalid fix @@ -482,6 +471,9 @@ BOOL NMEAParser::VTG(const char* String, char** params, size_t nparams, NMEA_INF // if no valid fix, we dont get speed either! if (gpsValid) { double speed = StrToDouble(params[4], NULL); + + ScopeLock lock(CritSec_FlightData); + pGPS->Speed = Units::From(unKnots, speed); if (ISCAR) { @@ -524,6 +516,7 @@ BOOL NMEAParser::RMC(const char* String, char** params, size_t nparams, NMEA_INF double ps = GM130BarPressure(); double Altitude = (1 - pow(fabs(ps / QNH), 0.190284)) * 44307.69; + ScopeLock lock(CritSec_FlightData); UpdateBaroSource(pGPS, nullptr, Altitude); } @@ -532,12 +525,8 @@ BOOL NMEAParser::RMC(const char* String, char** params, size_t nparams, NMEA_INF double ps = Royaltek3200_GetPressure(); double Altitude = (1 - pow(fabs(ps / QNH), 0.190284)) * 44307.69; + ScopeLock lock(CritSec_FlightData); UpdateBaroSource(pGPS, nullptr, Altitude); - - #if 0 - pGPS->TemperatureAvailable=true; - pGPS->OutsideAirTemperature = Royaltek3200_GetTemperature(); - #endif } } @@ -553,6 +542,8 @@ BOOL NMEAParser::RMC(const char* String, char** params, size_t nparams, NMEA_INF speed = StrToDouble(params[6], NULL); } + ScopeLock lock(CritSec_FlightData); + pGPS->NAVWarning = !gpsValid; // say we are updated every time we get this, @@ -733,6 +724,9 @@ BOOL NMEAParser::GGA(const char* String, char** params, size_t nparams, NMEA_INF if(gpsValid && (nSatellites == 0)) { nSatellites = -1; // unknown count but valid fix ! } + + ScopeLock lock(CritSec_FlightData); + pGPS->SatellitesUsed = nSatellites; // 091208 pGPS->NAVWarning = !gpsValid; // 091208 @@ -833,8 +827,6 @@ BOOL NMEAParser::GGA(const char* String, char** params, size_t nparams, NMEA_INF // LK8000 IAS , in m/s*10 example: 346 for 34.6 m/s which is = 124.56 km/h BOOL NMEAParser::PLKAS(const char* String, char** params, size_t nparams, NMEA_INFO *pGPS) { - (void)pGPS; - if(nparams < 1) { TESTBENCH_DO_ONLY(10,StartupStore(_T(". NMEAParser invalid PLKAS sentence, nparams=%u%s"),(unsigned)nparams,NEWLINE)); // max index used is 0... @@ -842,6 +834,8 @@ BOOL NMEAParser::PLKAS(const char* String, char** params, size_t nparams, NMEA_I } double vias=StrToDouble(params[0],NULL)/10.0; + + ScopeLock lock(CritSec_FlightData); if (vias > 1) { double qne_altitude = QNHAltitudeToQNEAltitude(pGPS->Altitude); pGPS->TrueAirspeed = TrueAirSpeed(vias, qne_altitude); @@ -859,8 +853,6 @@ BOOL NMEAParser::PLKAS(const char* String, char** params, size_t nparams, NMEA_I BOOL NMEAParser::RMZ(DeviceDescriptor_t& d, const char* String, char **params, size_t nparams, NMEA_INFO *pGPS) { - (void)pGPS; - if(nparams < 2) { TESTBENCH_DO_ONLY(10,StartupStore(_T(". NMEAParser invalid RMZ sentence, nparams=%u%s"),(unsigned)nparams,NEWLINE)); // max index used is 1... @@ -877,6 +869,8 @@ BOOL NMEAParser::RMZ(DeviceDescriptor_t& d, const char* String, char **params, s LastRMZHB = LKHearthBeats; double Altitude = ParseAltitude(params[0], params[1]); + + ScopeLock lock(CritSec_FlightData); UpdateBaroSource(pGPS, &d, QNEAltitudeToQNHAltitude(Altitude)); return FALSE; @@ -892,6 +886,8 @@ BOOL NMEAParser::PTAS1(DeviceDescriptor_t& d, const char* String, char **params, return FALSE; } + ScopeLock lock(CritSec_FlightData); + if(*params[0] != _T('\0')) { const double wnet = Units::From(unKnots, (StrToDouble(params[0],NULL) - 200.0) / 10); UpdateVarioSource(*pGPS, d, wnet); @@ -923,14 +919,13 @@ BOOL NMEAParser::HCHDG(const char* String, char** params, size_t nparams, NMEA_I return FALSE; } - (void)pGPS; - double mag=0; - mag=StrToDouble(params[0],NULL); + double mag = StrToDouble(params[0],NULL); if (mag>=0 && mag<=360) { + ScopeLock lock(CritSec_FlightData); pGPS->MagneticHeading=mag; pGPS->MagneticHeadingAvailable=TRUE; } - return FALSE; + return TRUE; }