Skip to content

Commit

Permalink
crct: fix sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Mar 7, 2024
1 parent 2595071 commit e09c4d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
27 changes: 17 additions & 10 deletions Src/cyphal_application/circuit_status/circuit_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static const uint16_t AVG_SLOPE = 5; ///< avg_slope/(3.3/4096)
#endif

int8_t CircuitStatus::init() {
int8_t CircuitStatus::init() const {
return AdcPeriphery::init();
}

Expand All @@ -40,25 +40,32 @@ void CircuitStatus::process(uint32_t crnt_time_ms) {
}

void CircuitStatus::_update_parameters() {
voltage_5v_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_5V_ID));
voltage_vin_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_VIN_ID));
temperature_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_TEMPERATURE_ID));
uint16_t port_id;

port_id = static_cast<uint16_t>(paramsGetIntegerValue(PARAM_PUB_CRCT_5V_ID));
voltage_5v_pub.setPortId(port_id);

port_id = static_cast<uint16_t>(paramsGetIntegerValue(PARAM_PUB_CRCT_VIN_ID));
voltage_vin_pub.setPortId(port_id);

port_id = static_cast<uint16_t>(paramsGetIntegerValue(PARAM_PUB_CRCT_TEMPERATURE_ID));
temperature_pub.setPortId(port_id);
}

void CircuitStatus::_spin_once() {
if (voltage_5v_publisher.isEnabled()) {
if (voltage_5v_pub.isEnabled()) {
float volt = AdcPeriphery::get(AdcChannel::ADC_5V) * ADC_RAW_TO_5V;
voltage_5v_publisher.publish(uavcan_si_sample_voltage_Scalar_1_0{0, volt});
voltage_5v_pub.publish(uavcan_si_sample_voltage_Scalar_1_0{0, volt});
}

if (voltage_vin_publisher.isEnabled()) {
if (voltage_vin_pub.isEnabled()) {
float volt = AdcPeriphery::get(AdcChannel::ADC_VIN) * ADC_RAW_TO_VIN;
voltage_vin_publisher.publish(uavcan_si_sample_voltage_Scalar_1_0{0, volt});
voltage_vin_pub.publish(uavcan_si_sample_voltage_Scalar_1_0{0, volt});
}

if (temperature_publisher.isEnabled()) {
if (temperature_pub.isEnabled()) {
uint16_t raw_temperature = AdcPeriphery::get(AdcChannel::ADC_TEMPERATURE);
float kelvin = (ADC_REF - raw_temperature) / AVG_SLOPE + TEMP_REF + 273;
temperature_publisher.publish(uavcan_si_sample_temperature_Scalar_1_0{0, kelvin});
temperature_pub.publish(uavcan_si_sample_temperature_Scalar_1_0{0, kelvin});
}
}
18 changes: 11 additions & 7 deletions Src/cyphal_application/circuit_status/circuit_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ class CircuitStatus {
/**
* @brief The constructor must be called only after initialization of Cyphal instance!
*/
explicit CircuitStatus() : voltage_5v_publisher(cyphal::Cyphal::get_instance(), 65535),
voltage_vin_publisher(cyphal::Cyphal::get_instance(), 65535),
temperature_publisher(cyphal::Cyphal::get_instance(), 65535) {};
CircuitStatus() = default;

/**
* @brief This function should be called once in the beginning of the application
* @return >= 0 on success and < 0 on error
*/
int8_t init();
int8_t init() const;

/**
* @brief This function should be called periodically. It should automatically:
Expand All @@ -39,9 +37,15 @@ class CircuitStatus {
void _spin_once();
void _update_parameters();

RaccoonLab::CircuitStatusVoltagePublisher voltage_5v_publisher;
RaccoonLab::CircuitStatusVoltagePublisher voltage_vin_publisher;
RaccoonLab::CircuitStatusTemperaturePublisher temperature_publisher;
RaccoonLab::CircuitStatusVoltagePublisher voltage_5v_pub{
cyphal::Cyphal::get_instance(), 65535};

RaccoonLab::CircuitStatusVoltagePublisher voltage_vin_pub{
cyphal::Cyphal::get_instance(), 65535};

RaccoonLab::CircuitStatusTemperaturePublisher temperature_pub{
cyphal::Cyphal::get_instance(), 65535};

uint32_t _prev_pub_ts_ms = 0;
};

Expand Down

0 comments on commit e09c4d5

Please sign in to comment.