From dd17ff151c3e1aa51ee8130837322d00216fa09c Mon Sep 17 00:00:00 2001 From: Emilio Corigliano <emilio.corigliano@skywarder.eu> Date: Mon, 26 Feb 2024 23:49:23 +0100 Subject: [PATCH] [HIL] Fixed namespace issues, formatting in HILSensor print, cppcheck issues and turned printf in TRACEs --- src/shared/hil/HIL.h | 4 +-- src/shared/hil/HILPhasesManager.h | 10 +++--- src/shared/sensors/HILSensors/HILSensor.h | 4 +-- src/tests/hil/HILSimulationConfig.h | 41 ++++++++++++----------- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/shared/hil/HIL.h b/src/shared/hil/HIL.h index e9ba8b49b..0680517fb 100644 --- a/src/shared/hil/HIL.h +++ b/src/shared/hil/HIL.h @@ -101,7 +101,7 @@ public: LOG_INFO(logger, "Waiting for simulation to start..."); while (!hilPhasesManager->isSimulationRunning()) { - Thread::sleep(updatePeriod); + miosix::Thread::sleep(updatePeriod); } } @@ -118,7 +118,7 @@ private: { hilTransceiver->setActuatorData(updateActuatorData()); } - Thread::sleep(updatePeriod); + miosix::Thread::sleep(updatePeriod); } } diff --git a/src/shared/hil/HILPhasesManager.h b/src/shared/hil/HILPhasesManager.h index 0131f20d8..29827f0a1 100644 --- a/src/shared/hil/HILPhasesManager.h +++ b/src/shared/hil/HILPhasesManager.h @@ -23,6 +23,7 @@ #pragma once #include <algorithms/AirBrakes/TrajectoryPoint.h> +#include <diagnostic/PrintLogger.h> #include <drivers/timer/TimestampTimer.h> #include <events/Event.h> #include <events/EventHandler.h> @@ -30,6 +31,7 @@ #include <iostream> #include <map> +#include <utils/Debug.h> #include <utils/ModuleManager/ModuleManager.hpp> typedef std::function<void()> TCallback; @@ -48,9 +50,9 @@ struct Outcomes void print(uint64_t t_start) const { - printf("@time : %f [sec]\n", (double)(t - t_start) / 1000000); - printf("@altitude : %f [m]\n", z); - printf("@velocity : %f [m/s]\n\n", vz); + TRACE("@time : %f [sec]\n", (double)(t - t_start) / 1000000); + TRACE("@altitude : %f [m]\n", z); + TRACE("@velocity : %f [m/s]\n\n", vz); } }; @@ -151,6 +153,6 @@ protected: std::map<FlightPhases, bool> flagsFlightPhases; std::map<FlightPhases, bool> prev_flagsFlightPhases; - std::map<FlightPhases, vector<TCallback>> callbacks; + std::map<FlightPhases, std::vector<TCallback>> callbacks; std::map<FlightPhases, Outcomes> outcomes; }; diff --git a/src/shared/sensors/HILSensors/HILSensor.h b/src/shared/sensors/HILSensors/HILSensor.h index ce2bfc264..f7b246e45 100644 --- a/src/shared/sensors/HILSensors/HILSensor.h +++ b/src/shared/sensors/HILSensors/HILSensor.h @@ -111,7 +111,7 @@ protected: if (sampleCounter >= N_DATA) { this->lastError = Boardcore::SensorErrors::NO_NEW_DATA; - LOG_WARN(logger, "%s: No new data", typeid(this).name()); + LOG_WARN(logger, "{}: No new data", typeid(this).name()); } else if (this->lastError != Boardcore::SensorErrors::NO_NEW_DATA) { @@ -121,7 +121,7 @@ protected: else { this->lastError = Boardcore::SensorErrors::NOT_INIT; - LOG_WARN(logger, "%s is not initialized", typeid(this).name()); + LOG_WARN(logger, "{} is not initialized", typeid(this).name()); } return this->lastSample; diff --git a/src/tests/hil/HILSimulationConfig.h b/src/tests/hil/HILSimulationConfig.h index 3c71184a3..82b66451e 100644 --- a/src/tests/hil/HILSimulationConfig.h +++ b/src/tests/hil/HILSimulationConfig.h @@ -48,7 +48,7 @@ namespace HILConfig struct SensorConfig : public Boardcore::SensorInfo { - SensorConfig(const std::string s, const uint32_t period) + SensorConfig(const std::string& s, const uint32_t period) : Boardcore::SensorInfo{s, period, []() {}, true} { } @@ -126,7 +126,7 @@ struct FlagsHIL void print() { - printf( + TRACE( "flag_flight: %f\n" "flag_ascent: %f\n" "flag_burning: %f\n" @@ -157,7 +157,7 @@ struct ADAStateHIL void print() { - printf( + TRACE( "mslAltitude: %+.3f\n" "aglAltitude: %+.3f\n" "verticalSpeed: %+.3f\n" @@ -197,7 +197,7 @@ struct NASStateHIL void print() { - printf( + TRACE( "n: %+.3f\n" "e: %+.3f\n" "d: %+.3f\n" @@ -222,7 +222,7 @@ struct AirBrakesStateHIL AirBrakesStateHIL() : updating(0) {} - void print() { printf("updating: %+.3f\n", updating); } + void print() { TRACE("updating: %+.3f\n", updating); } }; /** @@ -245,7 +245,7 @@ struct MEAStateHIL void print() { - printf( + TRACE( "correctedPressure: %+.3f\n" "estimatedMass: %+.3f\n" "estimatedApogee: %+.3f\n" @@ -278,7 +278,7 @@ struct ActuatorsStateHIL void print() { - printf( + TRACE( "airbrakes: %f perc\n" "expulsion: %f perc\n" "mainValve: %f perc\n" @@ -376,7 +376,7 @@ class MainHILPhasesManager : public HILPhasesManager<MainFlightPhases, SimulatorData, ActuatorData> { public: - MainHILPhasesManager( + explicit MainHILPhasesManager( std::function<Boardcore::TimedTrajectoryPoint()> getCurrentPosition) : HILPhasesManager<MainFlightPhases, SimulatorData, ActuatorData>( getCurrentPosition) @@ -443,33 +443,33 @@ public: void printOutcomes() { - printf("OUTCOMES: (times dt from liftoff)\n\n"); - printf("Simulation time: %.3f [sec]\n\n", + TRACE("OUTCOMES: (times dt from liftoff)\n\n"); + TRACE("Simulation time: %.3f [sec]\n\n", (double)(t_stop - t_start) / 1000000.0f); - printf("Motor stopped burning (simulation flag): \n"); + TRACE("Motor stopped burning (simulation flag): \n"); outcomes[MainFlightPhases::SIM_BURNING].print(t_liftoff); - printf("Airbrakes exit shadowmode: \n"); + TRACE("Airbrakes exit shadowmode: \n"); outcomes[MainFlightPhases::AEROBRAKES].print(t_liftoff); - printf("Apogee: \n"); + TRACE("Apogee: \n"); outcomes[MainFlightPhases::APOGEE].print(t_liftoff); - printf("Parachute 1: \n"); + TRACE("Parachute 1: \n"); outcomes[MainFlightPhases::PARA1].print(t_liftoff); - printf("Parachute 2: \n"); + TRACE("Parachute 2: \n"); outcomes[MainFlightPhases::PARA2].print(t_liftoff); - printf("Simulation Stopped: \n"); + TRACE("Simulation Stopped: \n"); outcomes[MainFlightPhases::SIMULATION_STOPPED].print(t_liftoff); // auto cpuMeter = Boardcore::CpuMeter::getCpuStats(); - // printf("max cpu usage: %+.3f\n", cpuMeter.maxValue); - // printf("avg cpu usage: %+.3f\n", cpuMeter.mean); - // printf("min free heap: %+.3lu\n", cpuMeter.minFreeHeap); - // printf("max free stack:%+.3lu\n", cpuMeter.minFreeStack); + // TRACE("max cpu usage: %+.3f\n", cpuMeter.maxValue); + // TRACE("avg cpu usage: %+.3f\n", cpuMeter.mean); + // TRACE("min free heap: %+.3lu\n", cpuMeter.minFreeHeap); + // TRACE("max free stack:%+.3lu\n", cpuMeter.minFreeStack); } private: @@ -480,6 +480,7 @@ private: TRACE("%d invalid event\n", e); /* calling the callbacks subscribed to the changed flags */ + // cppcheck-suppress unsignedLessThanZero for (unsigned int i = 0; i < changed_flags.size(); i++) { std::vector<TCallback> callbacksToCall = -- GitLab