Path: blob/master/libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h
9762 views
#pragma once12#include "AP_ESC_Telem_config.h"34#if HAL_WITH_ESC_TELEM56class AP_ESC_Telem;78class AP_ESC_Telem_Backend {9public:1011struct TelemetryData {12int16_t temperature_cdeg; // centi-degrees C, negative values allowed13float voltage; // Volt14float current; // Ampere15float consumption_mah; // milli-Ampere.hours16uint32_t usage_s; // usage seconds17int16_t motor_temp_cdeg; // centi-degrees C, negative values allowed18uint32_t last_update_ms; // last update time in milliseconds, determines whether active19uint16_t types; // telemetry types present20uint16_t count; // number of times updated21#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED22uint16_t edt2_status; // status reported by Extended DShot Telemetry v223uint16_t edt2_stress; // stress reported in dedicated messages by Extended DShot Telemetry v224#endif25#if AP_EXTENDED_ESC_TELEM_ENABLED26uint8_t input_duty; // input duty cycle27uint8_t output_duty; // output duty cycle28uint32_t flags; // Status flags29uint8_t power_percentage; // Percentage of output power30#endif // AP_EXTENDED_ESC_TELEM_ENABLED3132// set to false if no data has been received within the timeout period33bool any_data_valid;3435// return true if the data is stale36bool stale() const volatile;3738// return true if the requested type of data is available and not stale39bool valid(const uint16_t type_mask) const volatile;40};4142struct RpmData {43float rpm; // rpm44float prev_rpm; // previous rpm45float error_rate; // error rate in percent46uint32_t last_update_us; // last update time, greater then 0 means we've gotten data at some point47float update_rate_hz;48bool data_valid; // if this isn't set to true, then the ESC data should be ignored49};5051enum TelemetryType {52TEMPERATURE = 1 << 0,53MOTOR_TEMPERATURE = 1 << 1,54VOLTAGE = 1 << 2,55CURRENT = 1 << 3,56CONSUMPTION = 1 << 4,57USAGE = 1 << 5,58TEMPERATURE_EXTERNAL = 1 << 6,59MOTOR_TEMPERATURE_EXTERNAL = 1 << 7,60#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED61EDT2_STATUS = 1 << 8,62EDT2_STRESS = 1 << 9,63#endif64#if AP_EXTENDED_ESC_TELEM_ENABLED65INPUT_DUTY = 1 << 10,66OUTPUT_DUTY = 1 << 11,67FLAGS = 1 << 12,68POWER_PERCENTAGE = 1 << 13,69#endif // AP_EXTENDED_ESC_TELEM_ENABLED70};717273AP_ESC_Telem_Backend();7475/* Do not allow copies */76CLASS_NO_COPY(AP_ESC_Telem_Backend);7778protected:79// callback to update the rpm in the frontend, should be called by the driver when new data is available80void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate = 0.0f);8182// callback to update the data in the frontend, should be called by the driver when new data is available83void update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask);8485private:86AP_ESC_Telem* _frontend;87};8889#else9091// dummy empty class92class AP_ESC_Telem_Backend {93public:94AP_ESC_Telem_Backend(){};95};9697#endif9899100