Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sns susptemp #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sensors/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ void Main::checkTemperature()
}
}

void Main::checkSuspensionTemperature()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've defined this but you aren't calling it anywhere yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs to be defined in main.hpp

{
Temperature_susp_->run(); // not a thread

const auto temperature_susp = temperature_susp_->getData(); // *C
if (temperature_susp > 85) {
log_.info("Suspension Temperature (%u) exceeds maximum value (%d)", temperature_susp, 85);
auto sensors_data = data_.getSensorsData();
sensors_data.module_status = data::ModuleStatus::kCriticalFailure;
data_.setSensorsData(sensors_data);
}
}

void Main::checkAmbientPressure()
{
ambient_pressure_->run(); // not a thread
Expand Down
36 changes: 36 additions & 0 deletions src/sensors/temperature_amb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "temperature.hpp"

#include <stdio.h>

#include <utils/system.hpp>

namespace hyped::sensors {

Temperature::Temperature(const uint8_t pin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AmbientTemperature as class name and ambient_temperature.cpp for file name is probably better

: pin_(pin),
log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ambient Temperature"

{
}

void Temperature::run()
{
uint16_t raw_value = pin_.read();
log_.debug("raw value: %d", raw_value);
temperature_data_.temperature = scaleData(raw_value);
log_.debug("scaled value: %d", temperature_data_.temperature);
temperature_data_.operational = true;
}

int8_t Temperature::scaleData(const uint8_t raw_value)
{
// convert to degrees C
double temp = static_cast<double>(raw_value) / 4095;
temp = (temp * 175) - 50;
return static_cast<int8_t>(temp);
}

uint8_t Temperature::getData() const
{
return temperature_data_.temperature;
}
} // namespace hyped::sensors
55 changes: 55 additions & 0 deletions src/sensors/temperature_amb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include "interface.hpp"

#include <cstdint>

#include <data/data.hpp>
#include <utils/io/adc.hpp>
#include <utils/logger.hpp>
namespace hyped::sensors {

class Temperature : public ITemperature {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AmbientTemperature

ambient_temperature.hpp

public:
/**
* @brief Construct a new Temperature object
*
* @param pin for specific ADC pin
*/
Temperature(const uint8_t pin);
~Temperature() {}

/**
* @brief
*
* @return int to set to data struct in sensors main
*/
uint8_t getData() const override;

/**
* @brief one interation of checking sensors
*/
void run() override;

private:
/**
* @brief scale raw digital data to output in degrees C
*
* @param raw_value input voltage
* @return int representation of temperature
*/
static int8_t scaleData(uint8_t raw_value);

/**
* @brief ADC pin
*/
utils::io::ADC pin_;
utils::Logger log_;

/**
* @brief int from data structs
*/
data::TemperatureData temperature_data_;
};

} // namespace hyped::sensors
36 changes: 36 additions & 0 deletions src/sensors/temperature_susp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "temperature.hpp"

#include <stdio.h>

#include <utils/system.hpp>

namespace hyped::sensors {

Temperature_susp::Temperature_susp(const uint8_t pin)
Copy link
Contributor

@kshxtij kshxtij Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BrakeAndSuspenionTemperature for class?

brake_and_suspension_temperature.cpp for file?

Open to ideas on this, but the current naming isn't ideal

: pin_(pin),
log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Brakes and Suspension Temperature"

{
}

void Temperature_susp::run()
{
uint16_t raw_value = pin_.read();
log_.debug("raw value: %d", raw_value);
temperature_susp_data_.temperature_susp = scaleData(raw_value);
log_.debug("scaled value: %d", temperature_susp_data_.temperature_susp);
temperature_susp_data_.operational = true;
}

int8_t Temperature_susp::scaleData(const uint8_t raw_value)
{
// convert to degrees C
double temp = static_cast<double>(raw_value) / 4095;
temp = ((temp * 175) - 50)/(4*20*0.001);
return static_cast<int8_t>(temp);
}

uint8_t Temperature_susp::getData() const
{
return temperature_data_.temperature;
}
} // namespace hyped::sensors
55 changes: 55 additions & 0 deletions src/sensors/temperature_susp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include "interface.hpp"

#include <cstdint>

#include <data/data.hpp>
#include <utils/io/adc.hpp>
#include <utils/logger.hpp>
namespace hyped::sensors {

class Temperature_susp : public ITemperature_susp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITemperature_susp isn't defined anywhere + define the interface within the header instead of interface.hpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also same naming comment from the other file applies here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both types of temperature managers could be using the same interface ITemperature. Then it would make sense to have files temperature.cpp and temperature.hpp that contain the interface and both classes, AmbientTemperature and BrakeAndSuspsenionTemperature.

public:
/**
* @brief Construct a new Temperature_susp object
*
* @param pin for specific ADC pin
*/
Temperature_susp(const uint8_t pin);
~Temperature_susp() {}

/**
* @brief
*
* @return int to set to data struct in sensors main
*/
uint8_t getData() const override;

/**
* @brief one interation of checking sensors
*/
void run() override;

private:
/**
* @brief scale raw digital data to output in degrees C
*
* @param raw_value input voltage
* @return int representation of temperature_susp
*/
static int8_t scaleData(uint8_t raw_value);

/**
* @brief ADC pin
*/
utils::io::ADC pin_;
utils::Logger log_;

/**
* @brief int from data structs
*/
data::Temperature_suspData temperature_susp_data_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably just keep data::TemperatureData and even then you'd need to define it within data

};

} // namespace hyped::sensors