From 12a9122b5b35a57ced049643030dc87cbd0e67d2 Mon Sep 17 00:00:00 2001 From: Matteo Pignataro <matteo.pignataro@skywarder.eu> Date: Wed, 25 May 2022 16:25:47 +0200 Subject: [PATCH] [GPS] Slight fix about mutex lock --- src/shared/logger/Logger.cpp | 2 +- src/shared/sensors/BME280/BME280.cpp | 2 ++ src/shared/sensors/UBXGPS/UBXGPSSerial.cpp | 7 ++++++- src/tests/sensors/test-ubxgps-serial.cpp | 6 +++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/shared/logger/Logger.cpp b/src/shared/logger/Logger.cpp index 2709fbcc2..e7c882215 100644 --- a/src/shared/logger/Logger.cpp +++ b/src/shared/logger/Logger.cpp @@ -301,7 +301,7 @@ LoggerResult Logger::logImpl(const char* name, const void* data, { if (started == false) { - TRACE("Attempting to log %s but the Logger is not started!\n", name); + // TRACE("Attempting to log %s but the Logger is not started!\n", name); stats.droppedSamples++; // Signal that we are trying to write to a closed log diff --git a/src/shared/sensors/BME280/BME280.cpp b/src/shared/sensors/BME280/BME280.cpp index fe621101c..60b9b4f1a 100644 --- a/src/shared/sensors/BME280/BME280.cpp +++ b/src/shared/sensors/BME280/BME280.cpp @@ -115,6 +115,8 @@ bool BME280::init() return false; } + LOG_DEBUG(logger, "Device configurated correctly!"); + return true; } diff --git a/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp b/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp index 41006faf4..c5dabc4be 100644 --- a/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp +++ b/src/shared/sensors/UBXGPS/UBXGPSSerial.cpp @@ -100,6 +100,8 @@ bool UBXGPSSerial::init() return false; } + this->start(); + return true; } @@ -311,7 +313,8 @@ bool UBXGPSSerial::readUBXFrame(UBXFrame& frame) else { i = 0; - LOG_DEBUG(logger, "Received unexpected byte: {:02x} {:#c}", c, c); + // LOG_DEBUG(logger, "Received unexpected byte: {:02x} {:#c}", c, + // c); } } @@ -405,6 +408,8 @@ void UBXGPSSerial::run() UBXPvtFrame::Payload& pvtP = pvt.getPayload(); + // Lock the mutex + Lock<FastMutex> l(mutex); threadSample.gpsTimestamp = TimestampTimer::getInstance().getTimestamp(); threadSample.latitude = (float)pvtP.lat / 1e7; diff --git a/src/tests/sensors/test-ubxgps-serial.cpp b/src/tests/sensors/test-ubxgps-serial.cpp index 316b049f5..e05dc4632 100644 --- a/src/tests/sensors/test-ubxgps-serial.cpp +++ b/src/tests/sensors/test-ubxgps-serial.cpp @@ -30,7 +30,7 @@ using namespace Boardcore; using namespace miosix; -#define RATE 4 +#define RATE 10 int main() { @@ -43,7 +43,7 @@ int main() tx.alternateFunction(7); // Keep GPS baud rate at default for easier testing - UBXGPSSerial gps(38400, RATE, 2, "gps", 9600); + UBXGPSSerial gps(256000, RATE, 2, "gps", 9600); UBXGPSData dataGPS; printf("Gps allocated\n"); @@ -68,7 +68,7 @@ int main() } // Start the gps thread - gps.start(); + // gps.start(); printf("Gps started\n"); while (true) -- GitLab