From 278d7850c768e06446e3c8bccf98b5f881163002 Mon Sep 17 00:00:00 2001 From: marco <49691247+marcoSchr@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:51:41 +0200 Subject: [PATCH] M17: add data structures for GNSS and extended callsign metadata. --- .../include/protocols/M17/M17Datatypes.hpp | 92 +++++++++++++++++-- openrtx/src/rtx/OpMode_M17.cpp | 6 +- 2 files changed, 88 insertions(+), 10 deletions(-) diff --git a/openrtx/include/protocols/M17/M17Datatypes.hpp b/openrtx/include/protocols/M17/M17Datatypes.hpp index c2a424fd..b5b59fa9 100644 --- a/openrtx/include/protocols/M17/M17Datatypes.hpp +++ b/openrtx/include/protocols/M17/M17Datatypes.hpp @@ -32,12 +32,91 @@ namespace M17 { using call_t = std::array< uint8_t, 6 >; // Data type for encoded callsign -using meta_t = std::array< uint8_t, 14 >; // Data type for LSF metadata field using payload_t = std::array< uint8_t, 16 >; // Data type for frame payload field using lich_t = std::array< uint8_t, 12 >; // Data type for Golay(24,12) encoded LICH data using frame_t = std::array< uint8_t, 48 >; // Data type for a full M17 data frame, including sync word using syncw_t = std::array< uint8_t, 2 >; // Data type for a sync word +enum M17DataMode +{ + M17_DATAMODE_PACKET = 0, + M17_DATAMODE_STREAM = 1 +}; + +enum M17DataType +{ + M17_DATATYPE_DATA = 1, + M17_DATATYPE_VOICE = 2, + M17_DATATYPE_VOICE_DATA = 3 +}; + +enum M17EncyptionType +{ + M17_ENCRYPTION_NONE = 0, + M17_ENCRYPTION_AES = 1, + M17_ENCRYPTION_SCRAMBLER = 2, + M17_ENCRYPTION_OTHER = 3, +}; + +enum M17MetaType +{ + M17_META_TEXT = 0, + M17_META_GNSS = 1, + M17_META_EXTD_CALLSIGN = 2, +}; + +enum M17ScramblingType +{ + M17_SCRAMBLING_8BIT = 0, + M17_SCRAMBLING_16BIT = 1, + M17_SCRAMBLING_24BIT = 2, +}; + + +/** + * Data structure for M17 GNSS metadata field. + */ +typedef struct __attribute__((packed)) +{ + uint8_t data_src; //< Data source + uint8_t station_type; //< Station type + uint8_t lat_deg; //< Latitude, whole number + uint16_t lat_dec; //< Latitude, decimal part multiplied by 65535 + uint8_t lon_deg; //< Longitude, whole number + uint16_t lon_dec; //< Longitude, decimal part multiplied by 65535 + uint8_t lat_sign : 1; //< Latitude N/S: 0 = north, 1 = south + uint8_t lon_sign : 1; //< Longitude E/W: 0 = east, 1 = west + uint8_t alt_valid : 1; //< Altitude data valid + uint8_t spd_valid : 1; //< Speed data valid + uint8_t _unused : 4; + uint16_t altitude; //< Altitude above sea level in feet + 1500 + uint16_t bearing; //< Bearing in degrees, whole number + uint8_t speed; //< Speed in mph, whole number +} +gnssData_t; + +/** + * Data structure for M17 extended callsign metadata field. + */ +typedef struct __attribute__((packed)) +{ + call_t call1; + call_t call2; + uint16_t _unused; +} +extdCall_t; + +/** + * Data structure for M17 LSF metadata field. + */ +typedef union +{ + extdCall_t extended_call_sign; + gnssData_t gnss_data; + uint8_t raw_data[14]; +} +meta_t; + /** * This structure provides bit field definitions for the "TYPE" field * contained in an M17 Link Setup Frame. @@ -46,19 +125,18 @@ typedef union { struct __attribute__((packed)) { - uint16_t stream : 1; //< Packet/stream indicator: 0 = packet, 1 = stream + uint16_t dataMode : 1; //< Packet/stream indicator: 0 = packet, 1 = stream uint16_t dataType : 2; //< Data type indicator uint16_t encType : 2; //< Encryption type uint16_t encSubType : 2; //< Encryption subtype uint16_t CAN : 4; //< Channel Access Number - uint16_t : 4; //< Reserved, padding to 16 bit - } - fields; + uint16_t : 5; //< Reserved, padding to 16 bit + } fields; uint16_t value; } streamType_t; -} // namespace M17 +} // namespace M17 -#endif // M17_DATATYPES_H +#endif // M17_DATATYPES_H diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 6bde9d6c..e2fcd3ba 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -224,9 +224,9 @@ void OpMode_M17::txState(rtxStatus_t *const status) if(!dst.empty()) lsf.setDestination(dst); streamType_t type; - type.fields.stream = 1; // Stream - type.fields.dataType = 2; // Voice data - type.fields.CAN = status->can; // Channel access number + type.fields.dataMode = M17_DATAMODE_STREAM; // Stream + type.fields.dataType = M17_DATATYPE_VOICE; // Voice data + type.fields.CAN = status->can; // Channel access number lsf.setType(type); lsf.updateCrc();