From 55a65946466c1448e9754aa34276e661d75f3648 Mon Sep 17 00:00:00 2001 From: fastium Date: Sat, 4 Jan 2025 16:41:02 +0100 Subject: [PATCH] ADD preparation for tests --- common/sensor_device.cpp | 42 ++++++++++++++++++++++++----------- common/sensor_device.hpp | 2 +- common/speedometer.cpp | 4 +--- common/speedometer.hpp | 1 + multi_tasking/bike_system.cpp | 12 ++++++++++ multi_tasking/bike_system.hpp | 12 +++++++++- 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/common/sensor_device.cpp b/common/sensor_device.cpp index 4aa7ef2..69d3344 100644 --- a/common/sensor_device.cpp +++ b/common/sensor_device.cpp @@ -1,21 +1,37 @@ +// Copyright 2022 Haute école d'ingénierie et d'architecture de Fribourg +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/**************************************************************************** + * @file speedometer_device.cpp + * @author Serge Ayer + * + * @brief WheelCounterDevice implementation (static scheduling) + * + * @date 2023-08-20 + * @version 1.0.0 + ***************************************************************************/ + #include "sensor_device.hpp" namespace bike_computer { -SensorDevice::SensorDevice() : _hdc1000(I2C_SDA, I2C_SCL, STMOD_11) -{} +SensorDevice::SensorDevice() : _hdc1000(I2C_SDA, I2C_SCL, STMOD_11) {} -bool SensorDevice::init() { - return this->_hdc1000.probe(); -} +bool SensorDevice::init() { return this->_hdc1000.probe(); } -float SensorDevice::readTemperature(void) { - return this->_hdc1000.getTemperature(); -} +float SensorDevice::readTemperature(void) { return this->_hdc1000.getTemperature(); } -float SensorDevice::readHumidity(void) { - return this->_hdc1000.getHumidity(); -} - -} // bike_computer +float SensorDevice::readHumidity(void) { return this->_hdc1000.getHumidity(); } +} // namespace bike_computer diff --git a/common/sensor_device.hpp b/common/sensor_device.hpp index d6ead2c..37bc1f1 100644 --- a/common/sensor_device.hpp +++ b/common/sensor_device.hpp @@ -46,4 +46,4 @@ class SensorDevice { advembsof::HDC1000 _hdc1000; }; -} // namespace bike_computer \ No newline at end of file +} // namespace bike_computer diff --git a/common/speedometer.cpp b/common/speedometer.cpp index 4296b10..7d05312 100644 --- a/common/speedometer.cpp +++ b/common/speedometer.cpp @@ -80,7 +80,6 @@ float Speedometer::getDistance() { } void Speedometer::reset() { - // TODO : done this->_totalDistanceMutex.lock(); this->_totalDistance = 0.0f; this->_totalDistanceMutex.unlock(); @@ -96,6 +95,7 @@ float Speedometer::getTraySize() const { return kTraySize; } std::chrono::milliseconds Speedometer::getCurrentPedalRotationTime() const { return _pedalRotationTime; } +void Speedometer::setOnResetCallback(mbed::Callback cb) { _cbOnReset = cb; } #endif // defined(MBED_TEST_MODE) @@ -107,7 +107,6 @@ void Speedometer::computeSpeed() { // = 6.99m If you ride at 80 pedal turns / min, you run a distance of 6.99 * 80 / min // ~= 560 m / min = 33.6 km/h - // TODO : done // Distance run with one pedal turn = tray size / rear gear size * circumference of // the wheel constexpr float ms_in_hour = static_cast(3600 * 1000); @@ -129,7 +128,6 @@ void Speedometer::computeDistance() { // ~= 560 m / min = 33.6 km/h. We then multiply the speed by the time for getting the // distance traveled. - // TODO : done Speedometer::computeSpeed(); // compute distance diff --git a/common/speedometer.hpp b/common/speedometer.hpp index d821093..559eafc 100644 --- a/common/speedometer.hpp +++ b/common/speedometer.hpp @@ -55,6 +55,7 @@ class Speedometer { float getTraySize() const; std::chrono::milliseconds getCurrentPedalRotationTime() const; void setOnResetCallback(mbed::Callback cb); + mbed::Callback _cbOnReset; #endif // defined(MBED_TEST_MODE) private: diff --git a/multi_tasking/bike_system.cpp b/multi_tasking/bike_system.cpp index 037b0b7..01ba9f5 100644 --- a/multi_tasking/bike_system.cpp +++ b/multi_tasking/bike_system.cpp @@ -87,6 +87,14 @@ BikeSystem::BikeSystem() #if defined(MBED_TEST_MODE) const advembsof::TaskLogger& BikeSystem::getTaskLogger() { return _taskLogger; } + +bike_computer::Speedometer& Bike_system::getSpeedometer() { + _mutexSpeedometer.lock(); + bike_computer::Speedometer& speedometer = _speedometer; + _mutexSpeedometer.unlock(); + return speedometer; +} + #endif // defined(MBED_TEST_MODE) void BikeSystem::init() { @@ -162,10 +170,12 @@ void BikeSystem::onReset() { // ISR thread functions void BikeSystem::resetTask() { +#ifndef(MBED_TEST_MODE) auto taskStartTime = _timer.elapsed_time(); std::chrono::microseconds responseTime = _timer.elapsed_time() - _resetTime; tr_info("Reset task: response time is %" PRIu64 " usecs", responseTime.count()); +#endif // ENTER CRITICAL SECTION _mutexSpeedometer.lock(); @@ -173,8 +183,10 @@ void BikeSystem::resetTask() { _mutexSpeedometer.unlock(); // END CRITICAL SECTION +#ifndef(MBED_TEST_MODE) _taskLogger.logPeriodAndExecutionTime( _timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime); +#endif } // Speed distance thread functions diff --git a/multi_tasking/bike_system.hpp b/multi_tasking/bike_system.hpp index 001a224..68d2789 100644 --- a/multi_tasking/bike_system.hpp +++ b/multi_tasking/bike_system.hpp @@ -58,6 +58,7 @@ class BikeSystem { #if defined(MBED_TEST_MODE) const advembsof::TaskLogger& getTaskLogger(); + bike_computer::Speedometer& getSpeedometer(); #endif // defined(MBED_TEST_MODE) private: @@ -69,8 +70,17 @@ class BikeSystem { void displayTask(); void cpuTask(); - // ISR Thread +// ISR Thread +#if defined(MBED_TEST_MODE) + + public: +#endif void onReset(); +#if defined(MBED_TEST_MODE) + + private: +#endif + void resetTask(); // gear Thread