1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! `CRadarTargetPositionData` — a single radar/track position snapshot of an
//! aircraft.
use std::marker::PhantomData;
use euroscope_sys::EsHandle;
use crate::utils::cstr;
/// A radar target position snapshot.
///
/// A thin handle over EuroScope's `CRadarTargetPositionData`. It is reached
/// through a `CRadarTarget`, so the underlying pointer is the radar target's;
/// like the other handles it is valid only for the duration of the callback /
/// query block that produced it (`'cb`).
#[derive(Clone, Copy)]
pub struct RadarTargetPosition<'cb> {
raw: EsHandle,
_marker: PhantomData<&'cb ()>,
}
impl RadarTargetPosition<'_> {
pub(crate) fn from_raw(raw: EsHandle) -> Self {
Self {
raw,
_marker: PhantomData,
}
}
/// The raw `CRadarTarget*` this snapshot reads from. Escape hatch for
/// `euroscope-sys` calls not yet wrapped here.
pub(crate) fn as_ptr(&self) -> EsHandle {
self.raw
}
/// Whether the position reference is valid.
pub fn is_valid(&self) -> bool {
// SAFETY: `raw` is the radar-target pointer EuroScope handed us.
unsafe { euroscope_sys::es_rtpos_is_valid(self.raw) }
}
/// Whether the position is a reference to the flight-plan track.
pub fn is_fp_track_position(&self) -> bool {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_is_fp_track_position(self.raw) }
}
/// Seconds elapsed since this position data was received.
pub fn received_time(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_received_time(self.raw) }
}
/// The lat/lon coordinates of the plane.
pub fn position(&self) -> crate::Position {
let mut lat = 0.0_f64;
let mut lon = 0.0_f64;
// SAFETY: `raw` is valid; the out-params are live stack locals.
unsafe {
euroscope_sys::es_rtpos_position(self.raw, &raw mut lat, &raw mut lon);
}
crate::Position::new(lat, lon)
}
/// The squawk sent by the pilot. Borrows EuroScope-owned memory; valid for
/// this callback only.
pub fn squawk(&self) -> &str {
// SAFETY: the SDK returns a borrowed NUL-terminated ANSI string, or
// null (guarded).
unsafe { cstr(euroscope_sys::es_rtpos_squawk(self.raw)) }
}
/// Whether the plane transponder is in C mode.
pub fn transponder_c(&self) -> bool {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_transponder_c(self.raw) }
}
/// Whether the plane transponder is in IDENT mode.
pub fn transponder_i(&self) -> bool {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_transponder_i(self.raw) }
}
/// The true altitude of the plane, in feet.
pub fn pressure_altitude(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_pressure_altitude(self.raw) }
}
/// The altitude calculated using standard pressure, in feet.
pub fn flight_level(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_flight_level(self.raw) }
}
/// The ground speed reported by the pilot client.
pub fn reported_gs(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_reported_gs(self.raw) }
}
/// The heading (not tracking) reported by the pilot client.
pub fn reported_heading(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_reported_heading(self.raw) }
}
/// The reported heading referenced to true north.
pub fn reported_heading_true_north(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_reported_heading_true_north(self.raw) }
}
/// The pitch reported by the pilot client (-180..+180; negative is above
/// horizon).
pub fn reported_pitch(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_reported_pitch(self.raw) }
}
/// The bank reported by the pilot client (-180..+180; negative is right
/// bank).
pub fn reported_bank(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_reported_bank(self.raw) }
}
/// The radar response flags: an OR of the `RADAR_POSITION_*` values
/// (primary, secondary C, secondary S).
pub fn radar_flags(&self) -> i32 {
// SAFETY: see `is_valid`.
unsafe { euroscope_sys::es_rtpos_radar_flags(self.raw) }
}
}