Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_ADSB/AP_ADSB_Sagetech.h
Views: 1798
#pragma once12/*3This program is free software: you can redistribute it and/or modify4it under the terms of the GNU General Public License as published by5the Free Software Foundation, either version 3 of the License, or6(at your option) any later version.78This program is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11GNU General Public License for more details.1213You should have received a copy of the GNU General Public License14along with this program. If not, see <http://www.gnu.org/licenses/>.15*/1617#include "AP_ADSB_Backend.h"1819#if HAL_ADSB_SAGETECH_ENABLED20class AP_ADSB_Sagetech : public AP_ADSB_Backend {21public:22using AP_ADSB_Backend::AP_ADSB_Backend;2324// init - performs any required initialisation for this instance25bool init() override;2627// update - should be called periodically28void update() override;2930// static detection function31static bool detect();3233private:3435static const uint32_t PAYLOAD_XP_MAX_SIZE = 52;3637enum class SystemStateBits {38Error_Transponder = (1U<<0),39Altitidue_Source = (1U<<1),40Error_GPS = (1U<<2),41Error_ICAO = (1U<<3),42Error_Over_Temperature = (1U<<4),43Error_Extended_Squitter = (1U<<5),44Mode_Transponder = (3U<<6), // 2 bit status:45};4647enum class Transponder_Type {48Mode_C = 0x00,49Mode_S_ADSB_OUT = 0x01,50Mode_S_ADSB_OUT_and_IN = 0x02,51Unknown = 0xFF,52};5354enum class MsgType_XP {55INVALID = 0,56Installation_Set = 0x01,57Preflight_Set = 0x02,58Operating_Set = 0x03,59GPS_Set = 0x04,60Request = 0x05,6162ACK = 0x80,63Installation_Response = 0x81,64Preflight_Response = 0x82,65Status_Response = 0x83,66ADSB_StateVector_Report = 0x91,67ADSB_ModeStatus_Report = 0x92,68TISB_StateVector_Report = 0x93,69TISB_ModeStatus_Report = 0x94,70TISB_CorasePos_Report = 0x95,71TISB_ADSB_Mgr_Report = 0x96,72};7374enum class ParseState {75WaitingFor_Start,76WaitingFor_AssmAddr,77WaitingFor_MsgType,78WaitingFor_MsgId,79WaitingFor_PayloadLen,80WaitingFor_PayloadContents,81WaitingFor_ChecksumFletcher,82WaitingFor_Checksum,83WaitingFor_End,84};8586struct Packet_XP {87const uint8_t start = 0xA5;88const uint8_t assemAddr = 0x01;89MsgType_XP type;90uint8_t id;91uint8_t payload_length;92uint8_t payload[PAYLOAD_XP_MAX_SIZE];93uint8_t checksumFletcher;94uint8_t checksum;95const uint8_t end = 0x5A;96};9798struct {99ParseState state;100uint8_t index;101Packet_XP packet;102} message_in;103104// compute Sum and FletcherSum values105uint16_t checksum_generate_XP(Packet_XP &msg) const;106bool checksum_verify_XP(Packet_XP &msg) const;107void checksum_assign_XP(Packet_XP &msg);108109110// handling inbound byte and process it in the state machine111bool parse_byte_XP(const uint8_t data);112113// handle inbound packet114void handle_packet_XP(const Packet_XP &msg);115116// send message to serial port117void send_msg(Packet_XP &msg);118119// handle inbound msgs120void handle_adsb_in_msg(const Packet_XP &msg);121void handle_ack(const Packet_XP &msg);122123// send messages to transceiver124void send_msg_Installation();125void send_msg_PreFlight();126void send_msg_Operating();127void send_msg_GPS();128129// send packet by type130void send_packet(const MsgType_XP type);131132// send msg to request a packet by type133void request_packet(const MsgType_XP type);134135// timers for each out-bound packet136uint32_t last_packet_initialize_ms;137uint32_t last_packet_PreFlight_ms;138uint32_t last_packet_GPS_ms;139uint32_t last_packet_Operating_ms;140141// cached variables to compare against params so we can send msg on param change.142uint16_t last_operating_squawk;143int32_t last_operating_alt;144uint8_t last_operating_rf_select;145146// track status changes in acks147uint8_t last_ack_transponder_mode;148Transponder_Type transponder_type = Transponder_Type::Unknown;149};150#endif // HAL_ADSB_SAGETECH_ENABLED151152153154