LCOV - code coverage report
Current view: top level - AP_RCTelemetry - AP_Spektrum_Telem.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 2 2 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             : */
      15             : #pragma once
      16             : 
      17             : #include "AP_RCTelemetry_config.h"
      18             : 
      19             : #if HAL_SPEKTRUM_TELEM_ENABLED
      20             : 
      21             : #include <AP_HAL/utility/RingBuffer.h>
      22             : #include "AP_RCTelemetry.h"
      23             : 
      24             : #define UINT8 uint8_t
      25             : #define UINT16 uint16_t
      26             : #define UINT32 uint32_t
      27             : #define UINT64 uint64_t
      28             : #define INT8 int8_t
      29             : #define INT16 int16_t
      30             : #define INT32 int32_t
      31             : extern "C" {
      32             : #include "spektrumTelemetrySensors.h"
      33             : }
      34             : #undef UINT8
      35             : #undef UINT16
      36             : #undef UINT32
      37             : #undef UINT64
      38             : #undef INT8
      39             : #undef INT16
      40             : #undef INT32
      41             : 
      42             : class AP_Spektrum_Telem : public AP_RCTelemetry {
      43             : public:
      44             :     AP_Spektrum_Telem();
      45             :     ~AP_Spektrum_Telem() override;
      46             : 
      47             :     /* Do not allow copies */
      48             :     CLASS_NO_COPY(AP_Spektrum_Telem);
      49             : 
      50             :     // init - perform required initialisation
      51             :     virtual bool init() override;
      52             : 
      53      262928 :     static AP_Spektrum_Telem *get_singleton(void) {
      54      262928 :         return singleton;
      55             :     }
      56             : 
      57             :     // get next telemetry data for external consumers of SPort data
      58             :     static bool get_telem_data(uint8_t* data);
      59             : 
      60             : private:
      61             : 
      62             :     enum SensorType {
      63             :         QOS,
      64             :         RPM,
      65             :         TEXT,
      66             :         ATTITUDE,
      67             :         GPS_LOC,
      68             :         ESC,
      69             :         ALTITUDE,
      70             :         AIRSPEED,
      71             :         GPS_STATUS,
      72             :         VOLTAGE,
      73             :         AMPS,
      74             :         MAH,
      75             :         TEMP,
      76             :         NUM_SENSORS
      77             :     };
      78             : 
      79             :     struct MessageChunk
      80             :     {
      81             :         uint8_t chunk[13]; // a "chunk" (13 characters/bytes) at a time of the queued message to be sent
      82             :         uint8_t linenumber;
      83             :         uint8_t char_index; // index of which character to get in the message
      84             :         uint8_t repeats;
      85             :     } _msg_chunk;
      86             : 
      87             :     float _max_speed = 0.0f;
      88             :     float _max_alt = 0.0f;
      89             : 
      90             :     // passthrough WFQ scheduler
      91             :     // Text Generator
      92             :     bool get_next_msg_chunk(void) override;
      93             :     bool repeat_msg_chunk(void);
      94             :     void send_msg_chunk(const MessageChunk& message);
      95             :     bool is_packet_ready(uint8_t idx, bool queue_empty) override;
      96             :     void process_packet(uint8_t idx) override;
      97             :     void adjust_packet_weight(bool queue_empty) override;
      98             :     // RxV + flight log data
      99             :     void calc_qos();
     100             :     // High-Voltage sensor
     101             :     void calc_batt_volts(uint8_t instance);
     102             :     // Temperature Sensor
     103             :     void calc_temperature(uint8_t instance);
     104             :     // Amps
     105             :     void calc_batt_amps(uint8_t instance);
     106             :     // Flight Battery Capacity (Dual)
     107             :     void calc_batt_mah();
     108             :     // Altitude (Eagle Tree Sensor)
     109             :     void calc_altitude();
     110             :     // Air Speed (Eagle Tree Sensor)
     111             :     void calc_airspeed();
     112             :     // Attitude and Magnetic Compass
     113             :     void calc_attandmag();
     114             :     // GPS Location Data (Eagle Tree)
     115             :     void calc_gps_location();
     116             :     // GPS Status (Eagle Tree)
     117             :     void calc_gps_status();
     118             :     // Electronic Speed Control
     119             :     void calc_esc();
     120             :     // RPM sensor
     121             :     void calc_rpm();
     122             : 
     123             :      // setup ready for passthrough operation
     124             :     void setup_wfq_scheduler(void) override;
     125             : 
     126             :      // get next telemetry data for external consumers of SPort data (internal function)
     127             :     bool _get_telem_data(uint8_t* data);
     128             : 
     129             :     // all Spektrum telemtry packets are big-endian!
     130             :     PACKED UN_TELEMETRY _telem;
     131             :     bool _telem_pending;
     132             : 
     133             :     static AP_Spektrum_Telem *singleton;
     134             : };
     135             : 
     136             : namespace AP {
     137             :     AP_Spektrum_Telem *spektrum_telem();
     138             : };
     139             : 
     140             : #endif

Generated by: LCOV version 1.14