2020-09-28 01:31:38 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Frsky_SPort.h"
|
|
|
|
#include <AP_RCTelemetry/AP_RCTelemetry.h>
|
|
|
|
|
2020-09-10 09:55:53 -03:00
|
|
|
#include "AP_Frsky_SPortParser.h"
|
|
|
|
#include "AP_Frsky_MAVlite.h"
|
|
|
|
|
|
|
|
#include "AP_Frsky_Telem.h"
|
|
|
|
|
|
|
|
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
2020-09-24 02:33:06 -03:00
|
|
|
#include "AP_Frsky_MAVlite_SPortToMAVlite.h"
|
|
|
|
#include "AP_Frsky_MAVlite_MAVliteToSPort.h"
|
2020-10-02 02:18:06 -03:00
|
|
|
#include "AP_Frsky_MAVliteMsgHandler.h"
|
|
|
|
|
2020-09-10 09:55:53 -03:00
|
|
|
#define SPORT_TX_PACKET_DUPLICATES 1 // number of duplicates packets we send (fport only)
|
|
|
|
#endif
|
2020-09-28 01:31:38 -03:00
|
|
|
|
2020-09-28 18:53:17 -03:00
|
|
|
class AP_Frsky_SPort_Passthrough : public AP_Frsky_SPort, public AP_RCTelemetry
|
|
|
|
{
|
2020-09-28 01:31:38 -03:00
|
|
|
public:
|
|
|
|
|
2020-09-10 09:55:53 -03:00
|
|
|
AP_Frsky_SPort_Passthrough(AP_HAL::UARTDriver *port, bool use_external_data, AP_Frsky_Parameters *&frsky_parameters) :
|
2020-09-28 01:31:38 -03:00
|
|
|
AP_Frsky_SPort(port),
|
2020-12-20 15:57:08 -04:00
|
|
|
AP_RCTelemetry(WFQ_LAST_ITEM),
|
2020-09-10 09:55:53 -03:00
|
|
|
_use_external_data(use_external_data),
|
|
|
|
_frsky_parameters(frsky_parameters)
|
2020-12-10 05:28:56 -04:00
|
|
|
{
|
|
|
|
singleton = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AP_Frsky_SPort_Passthrough *get_singleton(void) {
|
|
|
|
return singleton;
|
|
|
|
}
|
2020-09-28 01:31:38 -03:00
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
bool init_serial_port() override;
|
|
|
|
|
|
|
|
// passthrough WFQ scheduler
|
|
|
|
bool is_packet_ready(uint8_t idx, bool queue_empty) override;
|
|
|
|
void process_packet(uint8_t idx) override;
|
|
|
|
void adjust_packet_weight(bool queue_empty) override;
|
|
|
|
// setup ready for passthrough operation
|
|
|
|
void setup_wfq_scheduler(void) override;
|
|
|
|
|
|
|
|
bool get_next_msg_chunk(void) override;
|
|
|
|
|
2020-12-10 05:28:56 -04:00
|
|
|
bool get_telem_data(sport_packet_t* packet_array, uint8_t &packet_count, const uint8_t max_size) override;
|
2020-11-18 13:16:15 -04:00
|
|
|
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
2020-09-10 09:55:53 -03:00
|
|
|
bool set_telem_data(const uint8_t frame, const uint16_t appid, const uint32_t data) override;
|
2020-12-10 05:28:56 -04:00
|
|
|
#endif //HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
2020-09-28 01:31:38 -03:00
|
|
|
|
2020-09-28 18:53:17 -03:00
|
|
|
void queue_text_message(MAV_SEVERITY severity, const char *text) override
|
|
|
|
{
|
|
|
|
AP_RCTelemetry::queue_message(severity, text);
|
2020-09-28 01:31:38 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
enum PassthroughPacketType : uint8_t {
|
|
|
|
TEXT = 0, // 0x5000 status text (dynamic)
|
|
|
|
ATTITUDE = 1, // 0x5006 Attitude and range (dynamic)
|
|
|
|
GPS_LAT = 2, // 0x800 GPS lat
|
|
|
|
GPS_LON = 3, // 0x800 GPS lon
|
|
|
|
VEL_YAW = 4, // 0x5005 Vel and Yaw
|
|
|
|
AP_STATUS = 5, // 0x5001 AP status
|
|
|
|
GPS_STATUS = 6, // 0x5002 GPS status
|
|
|
|
HOME = 7, // 0x5004 Home
|
|
|
|
BATT_2 = 8, // 0x5008 Battery 2 status
|
|
|
|
BATT_1 = 9, // 0x5008 Battery 1 status
|
2020-09-10 09:55:53 -03:00
|
|
|
PARAM = 10, // 0x5007 parameters
|
2021-01-29 04:50:59 -04:00
|
|
|
RPM = 11, // 0x500A rpm sensors 1 and 2
|
|
|
|
UDATA = 12, // user data
|
2020-09-10 09:55:53 -03:00
|
|
|
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
2021-01-29 04:50:59 -04:00
|
|
|
MAV = 13, // mavlite
|
2020-09-10 09:55:53 -03:00
|
|
|
#endif //HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
2021-03-07 05:23:02 -04:00
|
|
|
TERRAIN = 14, // 0x500B terrain data
|
2021-06-18 12:59:41 -03:00
|
|
|
WIND = 15, // 0x500C wind data
|
2021-07-06 16:47:35 -03:00
|
|
|
WAYPOINT = 16, // 0x500D waypoint data
|
2020-12-10 05:28:56 -04:00
|
|
|
WFQ_LAST_ITEM // must be last
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void send() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
AP_Frsky_Parameters *&_frsky_parameters;
|
|
|
|
|
|
|
|
enum PassthroughParam : uint8_t {
|
2021-03-05 11:10:02 -04:00
|
|
|
NONE = 0,
|
2020-12-10 05:28:56 -04:00
|
|
|
FRAME_TYPE = 1,
|
|
|
|
BATT_FS_VOLTAGE = 2,
|
|
|
|
BATT_FS_CAPACITY = 3,
|
|
|
|
BATT_CAPACITY_1 = 4,
|
2021-03-05 11:10:02 -04:00
|
|
|
BATT_CAPACITY_2 = 5,
|
2021-03-13 04:52:50 -04:00
|
|
|
TELEMETRY_FEATURES = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
enum PassthroughFeatures : uint8_t {
|
|
|
|
BIDIR = 0,
|
|
|
|
SCRIPTING = 1,
|
2020-09-28 01:31:38 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// methods to convert flight controller data to FrSky SPort Passthrough (OpenTX) format
|
|
|
|
uint32_t calc_param(void);
|
|
|
|
uint32_t calc_batt(uint8_t instance);
|
|
|
|
uint32_t calc_ap_status(void);
|
|
|
|
uint32_t calc_home(void);
|
|
|
|
uint32_t calc_velandyaw(void);
|
|
|
|
uint32_t calc_attiandrng(void);
|
2021-01-29 04:50:59 -04:00
|
|
|
uint32_t calc_rpm(void);
|
2021-03-07 05:23:02 -04:00
|
|
|
uint32_t calc_terrain(void);
|
2021-06-18 12:59:41 -03:00
|
|
|
uint32_t calc_wind(void);
|
2021-07-06 16:47:35 -03:00
|
|
|
uint32_t calc_waypoint(void);
|
2020-09-28 01:31:38 -03:00
|
|
|
|
|
|
|
// use_external_data is set when this library will
|
|
|
|
// be providing data to another transport, such as FPort
|
|
|
|
bool _use_external_data;
|
2020-12-10 05:28:56 -04:00
|
|
|
|
2020-09-28 01:31:38 -03:00
|
|
|
struct {
|
2020-12-10 05:28:56 -04:00
|
|
|
sport_packet_t packet;
|
2020-09-28 01:31:38 -03:00
|
|
|
bool pending;
|
|
|
|
} external_data;
|
|
|
|
|
2020-09-28 18:53:17 -03:00
|
|
|
struct {
|
2020-09-28 01:31:38 -03:00
|
|
|
uint32_t chunk; // a "chunk" (four characters/bytes) at a time of the queued message to be sent
|
|
|
|
uint8_t repeats; // send each message "chunk" 3 times to make sure the entire messsage gets through without getting cut
|
|
|
|
uint8_t char_index; // index of which character to get in the message
|
|
|
|
} _msg_chunk;
|
|
|
|
|
2021-05-05 05:39:05 -03:00
|
|
|
// passthrough default sensor id
|
|
|
|
uint8_t downlink_sensor_id = 0x1B;
|
2020-09-10 09:55:53 -03:00
|
|
|
|
|
|
|
#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL
|
|
|
|
// bidirectional sport telemetry
|
|
|
|
struct {
|
|
|
|
uint8_t uplink_sensor_id = 0x0D;
|
|
|
|
uint8_t downlink1_sensor_id = 0x34;
|
|
|
|
uint8_t downlink2_sensor_id = 0x67;
|
|
|
|
uint8_t tx_packet_duplicates;
|
|
|
|
ObjectBuffer_TS<AP_Frsky_SPort::sport_packet_t> rx_packet_queue{SPORT_PACKET_QUEUE_LENGTH};
|
|
|
|
ObjectBuffer_TS<AP_Frsky_SPort::sport_packet_t> tx_packet_queue{SPORT_PACKET_QUEUE_LENGTH};
|
|
|
|
} _SPort_bidir;
|
|
|
|
|
|
|
|
AP_Frsky_SPortParser _sport_handler;
|
2020-09-24 02:33:06 -03:00
|
|
|
AP_Frsky_MAVlite_SPortToMAVlite sport_to_mavlite;
|
|
|
|
AP_Frsky_MAVlite_MAVliteToSPort mavlite_to_sport;
|
2020-09-10 09:55:53 -03:00
|
|
|
|
|
|
|
void set_sensor_id(AP_Int8 idx, uint8_t &sensor);
|
|
|
|
// tx/rx sport packet processing
|
|
|
|
void queue_rx_packet(const AP_Frsky_SPort::sport_packet_t sp);
|
|
|
|
void process_rx_queue(void);
|
|
|
|
void process_tx_queue(void);
|
|
|
|
|
2020-10-02 02:18:06 -03:00
|
|
|
// create an object to handle incoming mavlite messages; a
|
|
|
|
// callback method is provided to allow the handler to send responses
|
|
|
|
bool send_message(const AP_Frsky_MAVlite_Message &txmsg);
|
|
|
|
AP_Frsky_MAVliteMsgHandler mavlite{FUNCTOR_BIND_MEMBER(&AP_Frsky_SPort_Passthrough::send_message, bool, const AP_Frsky_MAVlite_Message &)};
|
2020-09-10 09:55:53 -03:00
|
|
|
#endif
|
|
|
|
|
2020-09-28 01:31:38 -03:00
|
|
|
void send_sport_frame(uint8_t frame, uint16_t appid, uint32_t data);
|
|
|
|
|
2020-09-10 09:55:53 -03:00
|
|
|
// true if we need to respond to the last polling byte
|
2021-02-01 12:26:28 -04:00
|
|
|
bool is_passthrough_byte(const uint8_t byte) const;
|
2020-09-10 09:55:53 -03:00
|
|
|
|
2020-09-28 01:31:38 -03:00
|
|
|
uint8_t _paramID;
|
|
|
|
|
|
|
|
uint32_t calc_gps_status(void);
|
2020-12-10 05:28:56 -04:00
|
|
|
|
|
|
|
static AP_Frsky_SPort_Passthrough *singleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Frsky_SPort_Passthrough *frsky_passthrough_telem();
|
2020-09-28 01:31:38 -03:00
|
|
|
};
|