diff --git a/src/drivers/rc_input/RCInput.cpp b/src/drivers/rc_input/RCInput.cpp index 68bb442c3f..f08d3173f6 100644 --- a/src/drivers/rc_input/RCInput.cpp +++ b/src/drivers/rc_input/RCInput.cpp @@ -654,16 +654,14 @@ void RCInput::Run() _rc_in.input_source = input_rc_s::RC_INPUT_SOURCE_PX4FMU_GHST; fill_rc_in(_raw_rc_count, _raw_rc_values, cycle_timestamp, false, false, 0, ghst_rssi); - // Enable GHST Telemetry only on the Omnibus, because on Pixhawk (-related) boards + // ghst telemetry works on fmu-v5 + // on other Pixhawk (-related) boards it does not work because // we cannot write to the RC UART - // It might work on FMU-v5. Or another option is to use a different UART port -#ifdef CONFIG_ARCH_BOARD_OMNIBUS_F4SD if (!_rc_scan_locked && !_ghst_telemetry) { _ghst_telemetry = new GHSTTelemetry(_rcs_fd); } -#endif /* CONFIG_ARCH_BOARD_OMNIBUS_F4SD */ _rc_scan_locked = true; diff --git a/src/drivers/rc_input/RCInput.hpp b/src/drivers/rc_input/RCInput.hpp index f965aa764b..894367e146 100644 --- a/src/drivers/rc_input/RCInput.hpp +++ b/src/drivers/rc_input/RCInput.hpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -61,7 +61,7 @@ #include #include "crsf_telemetry.h" -#include "ghst_telemetry.h" +#include "ghst_telemetry.hpp" #ifdef HRT_PPM_CHANNEL # include diff --git a/src/drivers/rc_input/ghst_telemetry.cpp b/src/drivers/rc_input/ghst_telemetry.cpp index ab9da12698..e254cb09ab 100644 --- a/src/drivers/rc_input/ghst_telemetry.cpp +++ b/src/drivers/rc_input/ghst_telemetry.cpp @@ -40,8 +40,10 @@ * @author Juraj Ciberlin */ -#include "ghst_telemetry.h" -#include +#include "ghst_telemetry.hpp" +#include + +using time_literals::operator ""_s; GHSTTelemetry::GHSTTelemetry(int uart_fd) : _uart_fd(uart_fd) @@ -50,36 +52,44 @@ GHSTTelemetry::GHSTTelemetry(int uart_fd) : bool GHSTTelemetry::update(const hrt_abstime &now) { - const int update_rate_hz = 10; + bool success = false; - if (now - _last_update <= 1_s / (update_rate_hz * num_data_types)) { - return false; + if ((now - _last_update) > (1_s / (UPDATE_RATE_HZ * NUM_DATA_TYPES))) { + + switch (_next_type) { + case 0U: + success = send_battery_status(); + break; + + default: + success = false; + break; + } + + _last_update = now; + _next_type = (_next_type + 1U) % NUM_DATA_TYPES; } - bool sent = false; - - switch (_next_type) { - case 0: - sent = send_battery_status(); - break; - } - - _last_update = now; - _next_type = (_next_type + 1) % num_data_types; - - return sent; + return success; } bool GHSTTelemetry::send_battery_status() { + bool success = false; + float voltage_in_10mV; + float current_in_10mA; + float fuel_in_10mAh; battery_status_s battery_status; - if (!_battery_status_sub.update(&battery_status)) { - return false; + if (_battery_status_sub.update(&battery_status)) { + voltage_in_10mV = battery_status.voltage_filtered_v * FACTOR_VOLTS_TO_10MV; + current_in_10mA = battery_status.current_filtered_a * FACTOR_AMPS_TO_10MA; + fuel_in_10mAh = battery_status.discharged_mah * FACTOR_MAH_TO_10MAH; + success = ghst_send_telemetry_battery_status(_uart_fd, + static_cast(voltage_in_10mV), + static_cast(current_in_10mA), + static_cast(fuel_in_10mAh)); } - uint16_t voltage = battery_status.voltage_filtered_v * 10; - uint16_t current = battery_status.current_filtered_a * 10; - uint16_t fuel = battery_status.discharged_mah; - return ghst_send_telemetry_battery(_uart_fd, voltage, current, fuel); + return success; } diff --git a/src/drivers/rc_input/ghst_telemetry.h b/src/drivers/rc_input/ghst_telemetry.hpp similarity index 84% rename from src/drivers/rc_input/ghst_telemetry.h rename to src/drivers/rc_input/ghst_telemetry.hpp index 0bbba0e0d5..a996eff876 100644 --- a/src/drivers/rc_input/ghst_telemetry.h +++ b/src/drivers/rc_input/ghst_telemetry.hpp @@ -46,8 +46,6 @@ #include #include -using namespace time_literals; - /** * High-level class that handles sending of GHST telemetry data */ @@ -58,7 +56,7 @@ public: * @param uart_fd file descriptor for the UART to use. It is expected to be configured * already. */ - GHSTTelemetry(int uart_fd); + explicit GHSTTelemetry(int uart_fd); ~GHSTTelemetry() = default; @@ -74,10 +72,16 @@ private: uORB::Subscription _battery_status_sub{ORB_ID(battery_status)}; - hrt_abstime _last_update{0}; - - static constexpr int num_data_types{1}; // number of different telemetry data types - int _next_type{0}; - int _uart_fd; + hrt_abstime _last_update {0U}; + uint32_t _next_type {0U}; + + static constexpr uint32_t NUM_DATA_TYPES {1U}; // number of different telemetry data types + static constexpr uint32_t UPDATE_RATE_HZ {10U}; // update rate [Hz] + + // Factors that should be applied to get correct values + static constexpr float FACTOR_VOLTS_TO_10MV {100.0F}; + static constexpr float FACTOR_AMPS_TO_10MA {100.0F}; + static constexpr float FACTOR_MAH_TO_10MAH {0.1F}; + }; diff --git a/src/lib/rc/common_rc.h b/src/lib/rc/common_rc.h index 54b7f0046e..4a94615045 100644 --- a/src/lib/rc/common_rc.h +++ b/src/lib/rc/common_rc.h @@ -4,8 +4,8 @@ #include #include "crsf.h" -#include "ghst.h" #include "dsm.h" +#include "ghst.hpp" #include "sbus.h" #include "st24.h" #include "sumd.h" diff --git a/src/lib/rc/ghst.cpp b/src/lib/rc/ghst.cpp index 49a8b50570..1ea1bbdbbd 100644 --- a/src/lib/rc/ghst.cpp +++ b/src/lib/rc/ghst.cpp @@ -60,20 +60,19 @@ // TODO: include RSSI dBm to percentage conversion for ghost receiver #include "spektrum_rssi.h" -#include "ghst.h" +#include "ghst.hpp" #include "common_rc.h" #define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define GHST_FRAME_PAYLOAD_SIZE_TELEMETRY (10u) -#define GHST_FRAME_CRC_SIZE (1) -#define GHST_FRAME_TYPE_SIZE (1) -#define GHST_TYPE_DATA_CRC_SIZE (12u) +#define GHST_FRAME_PAYLOAD_SIZE_TELEMETRY (10U) +#define GHST_FRAME_CRC_SIZE (1U) +#define GHST_FRAME_TYPE_SIZE (1U) +#define GHST_TYPE_DATA_CRC_SIZE (12U) #define GHST_MAX_NUM_CHANNELS (16) enum class ghst_parser_state_t : uint8_t { - unsynced = 0, + unsynced = 0U, synced }; @@ -81,7 +80,7 @@ enum class ghst_parser_state_t : uint8_t { static int8_t ghst_rssi = -1; static ghst_frame_t &ghst_frame = rc_decode_buf.ghst_frame; -static uint32_t current_frame_position = 0; +static uint32_t current_frame_position = 0U; static ghst_parser_state_t parser_state = ghst_parser_state_t::unsynced; static uint16_t prev_rc_vals[GHST_MAX_NUM_CHANNELS]; @@ -100,7 +99,7 @@ int ghst_config(int uart_fd) tcgetattr(uart_fd, &t); cfsetspeed(&t, GHST_BAUDRATE); t.c_cflag &= ~(CSTOPB | PARENB); - memset(prev_rc_vals, (int)UINT16_MAX, sizeof(uint16_t) * GHST_MAX_NUM_CHANNELS); + memset(prev_rc_vals, static_cast(UINT16_MAX), sizeof(uint16_t) * GHST_MAX_NUM_CHANNELS); ret_val = tcsetattr(uart_fd, TCSANOW, &t); return ret_val; } @@ -121,51 +120,51 @@ bool ghst_parse(const uint64_t now, const uint8_t *frame, unsigned len, uint16_t memcpy(values, prev_rc_vals, sizeof(uint16_t) * GHST_MAX_NUM_CHANNELS); - while (len > 0) { + while (len > 0U) { // fill in the ghst_buffer, as much as we can - const unsigned current_len = MIN(len, sizeof(ghst_frame_t) - current_frame_position); + const uint32_t current_len = MIN(len, sizeof(ghst_frame_t) - current_frame_position); memcpy(ghst_frame_ptr + current_frame_position, frame, current_len); current_frame_position += current_len; // protection to guarantee parsing progress - if (current_len == 0) { - GHST_DEBUG("========== parser bug: no progress (%i) ===========", len); + if (current_len == 0U) { + GHST_DEBUG("========== parser bug: no progress (%u) ===========", len); - for (unsigned i = 0; i < current_frame_position; ++i) { - GHST_DEBUG("ghst_frame_ptr[%i]: 0x%x", i, (int)ghst_frame_ptr[i]); + for (uint32_t i = 0U; i < current_frame_position; ++i) { + GHST_DEBUG("ghst_frame_ptr[%u]: 0x%x", i, ghst_frame_ptr[i]); } // reset the parser - current_frame_position = 0; + current_frame_position = 0U; parser_state = ghst_parser_state_t::unsynced; - return false; - } + success = false; - len -= current_len; - frame += current_len; + } else { + len -= current_len; + frame += current_len; - if (ghst_parse_buffer(values, rssi, num_values, max_channels)) { - success = true; + if (ghst_parse_buffer(values, rssi, num_values, max_channels)) { + success = true; + } } } - return success; } uint8_t ghst_frame_CRC(const ghst_frame_t &frame) { - uint8_t crc = crc8_dvb_s2(0, frame.type); + uint8_t crc = crc8_dvb_s2(0U, frame.type); - for (int i = 0; i < frame.header.length - GHST_FRAME_CRC_SIZE - GHST_FRAME_TYPE_SIZE; ++i) { + for (uint32_t i = 0U; i < frame.header.length - GHST_FRAME_CRC_SIZE - GHST_FRAME_TYPE_SIZE; ++i) { crc = crc8_dvb_s2(crc, frame.payload[i]); } return crc; } -static uint16_t convert_channel_value(unsigned chan_value) +static uint16_t convert_channel_value(unsigned int chan_value) { /* * RC PWM @@ -173,9 +172,13 @@ static uint16_t convert_channel_value(unsigned chan_value) * mid 992 -> 1500us * max 1811 -> 2012us */ - static constexpr float scale = (2012.f - 988.f) / (1811.f - 172.f); - static constexpr float offset = 988.f - 172.f * scale; - return (scale * chan_value) + offset; + static constexpr float scale = (2012.0F - 988.0F) / (1811.0F - 172.0F); + static constexpr float offset = 988.0F - (172.0F * scale); + float scaled_chan_value = scale * static_cast(chan_value); + float scaled_chan_value_with_offset = scaled_chan_value + offset; + uint16_t converted_chan_value = static_cast(scaled_chan_value_with_offset); + + return converted_chan_value; } static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_values, uint16_t max_channels) @@ -184,16 +187,16 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu if (parser_state == ghst_parser_state_t::unsynced) { // there is no sync yet, try to find an RC packet by searching for a matching frame length and type - for (unsigned i = 1; i < current_frame_position - 1; ++i) { - if ((ghst_frame_ptr[i + 1] >= (uint8_t)ghstFrameType::frameTypeFirst) && - (ghst_frame_ptr[i + 1] <= (uint8_t)ghstFrameType::frameTypeLast)) { + for (uint32_t i = 1U; i < current_frame_position - 1U; ++i) { + if ((ghst_frame_ptr[i + 1U] >= static_cast(ghstFrameType::frameTypeFirst)) && + (ghst_frame_ptr[i + 1U] <= static_cast(ghstFrameType::frameTypeLast))) { if (ghst_frame_ptr[i] == GHST_TYPE_DATA_CRC_SIZE) { parser_state = ghst_parser_state_t::synced; - unsigned frame_offset = i - 1; - GHST_VERBOSE("RC channels found at offset %i", frame_offset); + uint32_t frame_offset = i - 1U; + GHST_VERBOSE("RC channels found at offset %u", frame_offset); // move the rest of the buffer to the beginning - if (frame_offset != 0) { + if (frame_offset != 0U) { memmove(ghst_frame_ptr, ghst_frame_ptr + frame_offset, current_frame_position - frame_offset); current_frame_position -= frame_offset; } @@ -207,7 +210,7 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu if (parser_state != ghst_parser_state_t::synced) { if (current_frame_position >= sizeof(ghst_frame_t)) { // discard most of the data, but keep the last 3 bytes (otherwise we could miss the frame start) - current_frame_position = 3; + current_frame_position = 3U; memcpy(ghst_frame_ptr, ghst_frame_ptr + sizeof(ghst_frame_t) - current_frame_position, current_frame_position); @@ -218,7 +221,7 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu } - if (current_frame_position < 3) { + if (current_frame_position < 3U) { // wait until we have the address, length and type return false; } @@ -227,18 +230,18 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu const unsigned current_frame_length = ghst_frame.header.length + sizeof(ghst_frame_header_t); - if (current_frame_length > sizeof(ghst_frame_t) || current_frame_length < 4) { + if ((current_frame_length > sizeof(ghst_frame_t)) || (current_frame_length < 4U)) { // frame too long or bogus (frame length should be longer than 4, at least 1 address, 1 length, 1 type, 1 data, 1 crc) // discard everything and go into unsynced state - current_frame_position = 0; + current_frame_position = 0U; parser_state = ghst_parser_state_t::unsynced; - GHST_DEBUG("Frame too long/bogus (%i, type=%i) -> unsync", current_frame_length, ghst_frame.type); + GHST_DEBUG("Frame too long/bogus (%u, type=%u) -> unsync", current_frame_length, ghst_frame.type); return false; } if (current_frame_position < current_frame_length) { // we do not have the full frame yet -> wait for more data - GHST_VERBOSE("waiting for more data (%i < %i)", current_frame_position, current_frame_length); + GHST_VERBOSE("waiting for more data (%u < %u)", current_frame_position, current_frame_length); return false; } @@ -246,59 +249,58 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu // now we have the full frame - if ((ghst_frame.type >= (uint8_t)ghstFrameType::frameTypeFirst) && - (ghst_frame.type <= (uint8_t)ghstFrameType::frameTypeLast) && + if ((ghst_frame.type >= static_cast(ghstFrameType::frameTypeFirst)) && + (ghst_frame.type <= static_cast(ghstFrameType::frameTypeLast)) && (ghst_frame.header.length == GHST_TYPE_DATA_CRC_SIZE)) { - const uint8_t crc = ghst_frame.payload[ghst_frame.header.length - 2]; + const uint8_t crc = ghst_frame.payload[ghst_frame.header.length - 2U]; if (crc == ghst_frame_CRC(ghst_frame)) { const ghstPayloadData_t *const rcChannels = (ghstPayloadData_t *)&ghst_frame.payload; *num_values = MIN(max_channels, GHST_MAX_NUM_CHANNELS); // all frames contain data from chan1to4 - if (max_channels > 0) { values[0] = convert_channel_value(rcChannels->chan1to4.chan1 >> 1); } + if (max_channels > 0U) { values[0] = convert_channel_value(rcChannels->chan1to4.chan1 >> 1U); } - if (max_channels > 1) { values[1] = convert_channel_value(rcChannels->chan1to4.chan2 >> 1); } + if (max_channels > 1U) { values[1] = convert_channel_value(rcChannels->chan1to4.chan2 >> 1U); } - if (max_channels > 2) { values[2] = convert_channel_value(rcChannels->chan1to4.chan3 >> 1); } + if (max_channels > 2U) { values[2] = convert_channel_value(rcChannels->chan1to4.chan3 >> 1U); } - if (max_channels > 3) { values[3] = convert_channel_value(rcChannels->chan1to4.chan4 >> 1); } + if (max_channels > 3U) { values[3] = convert_channel_value(rcChannels->chan1to4.chan4 >> 1U); } - if (ghst_frame.type == (uint8_t)ghstFrameType::frameType5to8) { - if (max_channels > 4) { values[4] = convert_channel_value(rcChannels->chanA << 3); } + if (ghst_frame.type == static_cast(ghstFrameType::frameType5to8)) { + if (max_channels > 4U) { values[4] = convert_channel_value(rcChannels->chanA << 3U); } - if (max_channels > 5) { values[5] = convert_channel_value(rcChannels->chanB << 3); } + if (max_channels > 5U) { values[5] = convert_channel_value(rcChannels->chanB << 3U); } - if (max_channels > 6) { values[6] = convert_channel_value(rcChannels->chanC << 3); } + if (max_channels > 6U) { values[6] = convert_channel_value(rcChannels->chanC << 3U); } - if (max_channels > 7) { values[7] = convert_channel_value(rcChannels->chanD << 3); } + if (max_channels > 7U) { values[7] = convert_channel_value(rcChannels->chanD << 3U); } - } else if (ghst_frame.type == (uint8_t)ghstFrameType::frameType9to12) { - if (max_channels > 8) { values[8] = convert_channel_value(rcChannels->chanA << 3); } + } else if (ghst_frame.type == static_cast(ghstFrameType::frameType9to12)) { + if (max_channels > 8U) { values[8] = convert_channel_value(rcChannels->chanA << 3U); } - if (max_channels > 9) { values[9] = convert_channel_value(rcChannels->chanB << 3); } + if (max_channels > 9U) { values[9] = convert_channel_value(rcChannels->chanB << 3U); } - if (max_channels > 10) { values[10] = convert_channel_value(rcChannels->chanC << 3); } + if (max_channels > 10U) { values[10] = convert_channel_value(rcChannels->chanC << 3U); } - if (max_channels > 11) { values[11] = convert_channel_value(rcChannels->chanD << 3); } + if (max_channels > 11U) { values[11] = convert_channel_value(rcChannels->chanD << 3U); } - } else if (ghst_frame.type == (uint8_t)ghstFrameType::frameType13to16) { - if (max_channels > 12) { values[12] = convert_channel_value(rcChannels->chanA << 3); } + } else if (ghst_frame.type == static_cast(ghstFrameType::frameType13to16)) { + if (max_channels > 12U) { values[12] = convert_channel_value(rcChannels->chanA << 3U); } - if (max_channels > 13) { values[13] = convert_channel_value(rcChannels->chanB << 3); } + if (max_channels > 13U) { values[13] = convert_channel_value(rcChannels->chanB << 3U); } - if (max_channels > 14) { values[14] = convert_channel_value(rcChannels->chanC << 3); } + if (max_channels > 14U) { values[14] = convert_channel_value(rcChannels->chanC << 3U); } - if (max_channels > 15) { values[15] = convert_channel_value(rcChannels->chanD << 3); } + if (max_channels > 15U) { values[15] = convert_channel_value(rcChannels->chanD << 3U); } - } else if (ghst_frame.type == (uint8_t)ghstFrameType::frameTypeRssi) { + } else if (ghst_frame.type == static_cast(ghstFrameType::frameTypeRssi)) { const ghstPayloadRssi_t *const rssiValues = (ghstPayloadRssi_t *)&ghst_frame.payload; // TODO: call function for RSSI dBm to percentage conversion for ghost receiver - ghst_rssi = spek_dbm_to_percent(rssiValues->rssidBm); - } + ghst_rssi = spek_dbm_to_percent(static_cast(rssiValues->rssidBm)); - else { - GHST_DEBUG("Frame type: %i", ghst_frame.type); + } else { + GHST_DEBUG("Frame type: %u", ghst_frame.type); } *rssi = ghst_rssi; @@ -314,17 +316,17 @@ static bool ghst_parse_buffer(uint16_t *values, int8_t *rssi, uint16_t *num_valu } } else { - GHST_DEBUG("Got Non-RC frame (len=%i, type=%i)", current_frame_length, ghst_frame.type); + GHST_DEBUG("Got Non-RC frame (len=%u, type=%u)", current_frame_length, ghst_frame.type); } // either reset or move the rest of the buffer if (current_frame_position > current_frame_length) { - GHST_VERBOSE("Moving buffer (%i > %i)", current_frame_position, current_frame_length); + GHST_VERBOSE("Moving buffer (%u > %u)", current_frame_position, current_frame_length); memmove(ghst_frame_ptr, ghst_frame_ptr + current_frame_length, current_frame_position - current_frame_length); current_frame_position -= current_frame_length; } else { - current_frame_position = 0; + current_frame_position = 0U; } return ret; @@ -343,8 +345,8 @@ static inline void write_uint8_t(uint8_t *buf, int &offset, uint8_t value) */ static inline void write_uint16_t(uint8_t *buf, int &offset, uint16_t value) { - buf[offset] = value & 0xff; - buf[offset + 1] = value >> 8; + buf[offset] = value & 0xFFU; + buf[offset + 1] = value >> 8U; offset += 2; } @@ -353,9 +355,9 @@ static inline void write_uint16_t(uint8_t *buf, int &offset, uint16_t value) */ static inline void write_frame_header(uint8_t *buf, int &offset, ghstTelemetryType type, uint8_t payload_size) { - write_uint8_t(buf, offset, (uint8_t)ghstAddress::rxAddress); + write_uint8_t(buf, offset, static_cast(ghstAddress::rxAddress)); write_uint8_t(buf, offset, payload_size + GHST_FRAME_CRC_SIZE + GHST_FRAME_TYPE_SIZE); - write_uint8_t(buf, offset, (uint8_t)type); + write_uint8_t(buf, offset, static_cast(type)); } /** @@ -363,21 +365,31 @@ static inline void write_frame_header(uint8_t *buf, int &offset, ghstTelemetryTy */ static inline void write_frame_crc(uint8_t *buf, int &offset, int buf_size) { - write_uint8_t(buf, offset, crc8_dvb_s2_buf(buf + 2, buf_size - 3)); + write_uint8_t(buf, offset, crc8_dvb_s2_buf(buf + 2U, buf_size - 3)); } -bool ghst_send_telemetry_battery(int uart_fd, uint16_t voltage, uint16_t current, uint16_t fuel) +bool ghst_send_telemetry_battery_status(int uart_fd, uint16_t voltage_in_10mV, + uint16_t current_in_10mA, uint16_t fuel_in_10mAh) { - uint8_t buf[GHST_FRAME_PAYLOAD_SIZE_TELEMETRY + 4u]; // address, frame length, type, crc + bool success; + uint8_t buf[GHST_FRAME_PAYLOAD_SIZE_TELEMETRY + 4U]; // address, frame length, type, crc int offset = 0; write_frame_header(buf, offset, ghstTelemetryType::batteryPack, GHST_FRAME_PAYLOAD_SIZE_TELEMETRY); - write_uint16_t(buf, offset, voltage); - write_uint16_t(buf, offset, current); - write_uint16_t(buf, offset, fuel); - write_uint8_t(buf, offset, 0x00); // empty - write_uint8_t(buf, offset, 0x00); // empty - write_uint8_t(buf, offset, 0x00); // empty - write_uint8_t(buf, offset, 0x00); // empty + write_uint16_t(buf, offset, voltage_in_10mV); + write_uint16_t(buf, offset, current_in_10mA); + write_uint16_t(buf, offset, fuel_in_10mAh); + write_uint8_t(buf, offset, 0x00U); // empty + write_uint8_t(buf, offset, 0x00U); // empty + write_uint8_t(buf, offset, 0x00U); // empty + write_uint8_t(buf, offset, 0x00U); // empty write_frame_crc(buf, offset, sizeof(buf)); - return write(uart_fd, buf, offset) == offset; + + if (write(uart_fd, buf, offset) == offset) { + success = true; + + } else { + success = false; + } + + return success; } diff --git a/src/lib/rc/ghst.h b/src/lib/rc/ghst.hpp similarity index 90% rename from src/lib/rc/ghst.h rename to src/lib/rc/ghst.hpp index c1a7a0c0a0..bba236f9c7 100644 --- a/src/lib/rc/ghst.h +++ b/src/lib/rc/ghst.hpp @@ -68,14 +68,14 @@ enum class ghstTelemetryType { }; struct ghst_frame_header_t { - uint8_t device_address; // device address - uint8_t length; // length + uint8_t device_address; // device address + uint8_t length; // length }; struct ghst_frame_t { ghst_frame_header_t header; // header uint8_t type; // frame type - uint8_t payload[GHST_PAYLOAD_MAX_SIZE + 1]; // payload data including 1 byte CRC at the end + uint8_t payload[GHST_PAYLOAD_MAX_SIZE + 1U]; // payload data including 1 byte CRC at the end }; // Channel data (1-4) @@ -131,11 +131,12 @@ __EXPORT bool ghst_parse(const uint64_t now, const uint8_t *frame, unsigned len, /** * Send telemetry battery information * @param uart_fd UART file descriptor - * @param voltage Voltage [0.1V] - * @param current Current [0.1A] - * @param fuel drawn mAh + * @param voltage_in_10mV Voltage [10 mV] + * @param current_in_10mA Current [10 mA] + * @param fuel_in_10mAh Fuel [10 mAh] * @return true on success */ -__EXPORT bool ghst_send_telemetry_battery(int uart_fd, uint16_t voltage, uint16_t current, uint16_t fuel); +__EXPORT bool ghst_send_telemetry_battery_status(int uart_fd, uint16_t voltage_in_10mV, + uint16_t current_in_10mA, uint16_t fuel_in_10mAh); __END_DECLS diff --git a/src/lib/rc/rc_tests/RCTest.cpp b/src/lib/rc/rc_tests/RCTest.cpp index 0f4d6c86a5..115372eac5 100644 --- a/src/lib/rc/rc_tests/RCTest.cpp +++ b/src/lib/rc/rc_tests/RCTest.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #if defined(CONFIG_ARCH_BOARD_PX4_SITL) #define TEST_DATA_PATH "./test_data/"