gondola_core/packets.rs
1// This file is part of gaps-online-software and published
2// under the GPLv3 license
3
4pub mod tof_packet_type;
5pub mod tof_packet;
6pub mod telemetry_packet_type;
7pub mod telemetry_packet_header;
8pub mod telemetry_packet;
9pub mod tracker_header;
10pub use tracker_header::TrackerHeader;
11pub mod bfsw_ack_packet;
12pub use bfsw_ack_packet::AckBfsw;
13pub mod gps_packet;
14pub use gps_packet::GPSPacket;
15pub mod pdu_packet;
16pub use pdu_packet::{
17 PduChannel,
18 Pac1934,
19 PduHKPacket,
20};
21
22pub mod tracker_event_echo;
23pub use tracker_event_echo::*;
24
25pub mod tracker_templeak;
26pub use tracker_templeak::*;
27
28pub mod tracker_daqtemp;
29pub use tracker_daqtemp::*;
30
31pub mod tracker_daqhk;
32pub use tracker_daqhk::*;
33
34pub mod magnetometer;
35pub use magnetometer::MagnetoMeter;
36
37
38// public exports to reduce the Matroshka effect a little
39pub use telemetry_packet_type::TelemetryPacketType;
40pub use telemetry_packet::TelemetryPacket;
41pub use telemetry_packet_header::TelemetryPacketHeader;
42pub use tof_packet_type::TofPacketType;
43pub use tof_packet::TofPacket;
44
45use crate::io::serialization::Serialization;
46
47#[cfg(feature="pybindings")]
48use pyo3::prelude::*;
49
50/// Recreate 48bit timestamp from u32 and u16
51#[cfg_attr(feature="pybindings", pyfunction)]
52pub fn make_systime(lower : u32, upper : u16) -> u64 {
53 (upper as u64) << 32 | lower as u64
54}
55
56///// This allows to pack anything in either a TOF or a Telemetry
57///// packet and will help to select what is appropriate
58///// automatically
59//pub trait Packable {
60// const TOF_PACKET_TYPE : TofPacketType = TofPacketType::Unknown;
61// // provide an alternative TofPacketType to retrieve the
62// // packet from without failing
63// const TOF_PACKET_TYPE_ALT : TofPacketType = TofPacketType::Unknown;
64// // for data whihc is only stored in Telemetry packets, they use a
65// // different packet type.
66// const TEL_PACKET_TYPE : TelemetryPacketType = TelemetryPacketType::Unknown;
67// const TEL_PACKET_TYPES_EVENT : [TelemetryPacketType;4] = [
68// TelemetryPacketType::NoGapsTriggerEvent,
69// TelemetryPacketType::BoringEvent,
70// TelemetryPacketType::InterestingEvent,
71// TelemetryPacketType::NoTofDataEvent];
72//}
73
74
75/// Can be wrapped within a TofPacket. To do, we just have
76/// to define a packet type
77pub trait TofPackable {
78 const TOF_PACKET_TYPE : TofPacketType;
79 // provide an alternative TofPacketType to retrieve the
80 // packet from without failing
81 const TOF_PACKET_TYPE_ALT : TofPacketType = TofPacketType::Unknown;
82
83 /// Wrap myself in a TofPacket
84 fn pack(&self) -> TofPacket
85 where Self: Serialization {
86 let mut tp = TofPacket::new();
87 tp.payload = self.to_bytestream();
88 tp.packet_type = Self::TOF_PACKET_TYPE;
89 tp
90 }
91}
92
93/// Can be wrapped within a TofPacket. To do, we just have
94/// to define a packet type
95pub trait TelemetryPackable {
96 /// packet type for any kind of telemetry packet which is NOT an
97 /// event
98 const TEL_PACKET_TYPE : TelemetryPacketType = TelemetryPacketType::Unknown;
99 /// TelemetryEvents can "occupy" several packet types, e.g. GapsTrigger, Boring, etc
100 const TEL_PACKET_TYPES_EVENT : [TelemetryPacketType;4] = [
101 TelemetryPacketType::NoGapsTriggerEvent,
102 TelemetryPacketType::BoringEvent,
103 TelemetryPacketType::InterestingEvent,
104 TelemetryPacketType::NoTofDataEvent];
105
106 ///// Everything which is supposed to be packed in a TelemetryPacket,
107 ///// needs a TelemetryPacketHeader
108 //fn get_telemetry_header(&self) -> TelemetryPacketHeader;
109 //
110 ///// Wrap myself in a TelemetryPacket
111 //fn pack(&self) -> TelemetryPacket
112 // where Self: Serialization {
113 // let mut tp = TelemetryPacket::new();
114 // tp.header = self.get_telemetry_header();
115 // tp.payload = self.to_bytestream();
116 // tp
117 //}
118}
119