Line data Source code
1 : /*! 2 : * @file VehicleDataManager.cpp 3 : * @brief Implementation of the VehicleDataManager class. 4 : * @version 0.1 5 : * @date 2025-02-12 6 : * @details This file contains the implementation of the VehicleDataManager class, 7 : * which is responsible for handling vehicle data. 8 : * @author Félix LE BIHAN (@Fle-bihh) 9 : * @author Tiago Pereira (@t-pereira06) 10 : * @author Ricardo Melo (@reomelo) 11 : * @author Michel Batista (@MicchelFAB) 12 : * 13 : * @copyright Copyright (c) 2025 14 : */ 15 : 16 : #include "VehicleDataManager.hpp" 17 : #include <QtMath> 18 : 19 : /*! 20 : * @brief Construct a new VehicleDataManager::VehicleDataManager object 21 : * @param parent The parent QObject. 22 : * @details This constructor initializes the VehicleDataManager object. 23 : */ 24 5 : VehicleDataManager::VehicleDataManager(QObject *parent) 25 5 : : QObject(parent) 26 5 : {} 27 : 28 : /*! 29 : * @brief Destroy the VehicleDataManager::VehicleDataManager object 30 : * @details This destructor cleans up the resources used by the VehicleDataManager. 31 : */ 32 10 : VehicleDataManager::~VehicleDataManager() {} 33 : 34 : 35 : /*! 36 : * @brief Handle Rotation Per Minute data. 37 : * @param rawRpm The raw rotation per minute data. 38 : * @details This function processes the RPM data by forwarding it to the 39 : * canDataProcessed signal. 40 : * @see VehicleDataManager::canDataProcessed 41 : */ 42 1 : void VehicleDataManager::handleRpmData(int rawRpm) 43 : { 44 1 : m_rpm = rawRpm; 45 1 : emit canDataProcessed(m_speed, rawRpm); 46 1 : } 47 : 48 : /*! 49 : * @brief Handle Speed data. 50 : * @param rawSpeed The raw speed data. 51 : * @details This function processes the speed data by forwarding it to the 52 : * canDataProcessed signal. The speed data is converted to the current cluster 53 : * metrics (either kilometers or miles). 54 : * @see VehicleDataManager::canDataProcessed 55 : * @see VehicleDataManager::setClusterMetrics 56 : */ 57 1 : void VehicleDataManager::handleSpeedData(float rawSpeed) 58 : { 59 1 : float processedSpeed = rawSpeed; 60 1 : if (m_clusterMetrics == ClusterMetrics::Miles) { 61 0 : processedSpeed *= 0.621371f; 62 : } 63 1 : m_speed = processedSpeed; 64 1 : emit canDataProcessed(processedSpeed, m_rpm); 65 1 : } 66 : 67 : /*! 68 : * @brief Handle mileage data. 69 : * @param mileage The mileage data. 70 : * @details This function processes the mileage data by updating the internal 71 : * mileage value and emitting a mileageUpdated signal if the value has changed. 72 : * @see VehicleDataManager::mileageUpdated 73 : */ 74 2 : void VehicleDataManager::handleMileageUpdate(double mileage) 75 : { 76 2 : if (!qFuzzyCompare(m_mileage, mileage)) { 77 1 : m_mileage = mileage; 78 1 : emit mileageUpdated(m_mileage); 79 : } 80 2 : } 81 : 82 : /*! 83 : * @brief Handle Direction data. 84 : * @param rawDirection The raw direction data. 85 : * @details This function processes the direction data by updating the internal 86 : * direction value and emitting an engineDataProcessed signal if the value has 87 : * changed. 88 : * @see VehicleDataManager::engineDataProcessed 89 : */ 90 2 : void VehicleDataManager::handleDirectionData(CarDirection rawDirection) 91 : { 92 2 : if (m_carDirection != rawDirection) { 93 1 : m_carDirection = rawDirection; 94 1 : emit engineDataProcessed(rawDirection, m_steeringDirection); 95 : } 96 2 : } 97 : 98 : 99 : /*! 100 : * @brief Handle Steering data. 101 : * @param rawAngle The raw steering angle data. 102 : * @details This function processes the steering data by updating the internal 103 : * steering direction value and emitting an engineDataProcessed signal if the 104 : * value has changed. 105 : * @see VehicleDataManager::engineDataProcessed 106 : */ 107 2 : void VehicleDataManager::handleSteeringData(int rawAngle) 108 : { 109 2 : if (m_steeringDirection != rawAngle) { 110 1 : m_steeringDirection = rawAngle; 111 1 : emit engineDataProcessed(m_carDirection, rawAngle); 112 : } 113 2 : }