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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use crate::ffi;
pub trait Unit {
fn as_raw_unit() -> ffi::RawUnit;
}
#[macro_export]
macro_rules! gauge_unit {
($ty:ident: $name:literal; $description:literal) => {
#[doc = $description]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct $ty;
impl $ty {
const UNIT_NAME: &'static str = concat!($name, "\0");
}
impl $crate::Unit for $ty {
#[inline]
fn as_raw_unit() -> $crate::ffi::RawUnit {
static RAW_UNIT_VALUE: $crate::once_cell::Lazy<$crate::ffi::RawUnit> = $crate::once_cell::Lazy::new(|| unsafe {
$crate::ffi::RawUnit::from_units_enum_str($ty::UNIT_NAME)
});
*RAW_UNIT_VALUE
}
}
};
}
pub trait AircraftVariable {
type Unit: Unit;
fn as_raw_aircraft_variable() -> ffi::RawAircraftVariable;
}
#[macro_export]
macro_rules! aircraft_variable {
($ty:ident ( $unit:ty ): $name:literal ; $description:literal) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct $ty;
impl $ty {
const VARIABLE_NAME: &'static str = concat!($name, "\0");
}
impl $crate::AircraftVariable for $ty {
type Unit = $unit;
#[inline]
fn as_raw_aircraft_variable() -> $crate::ffi::RawAircraftVariable {
static RAW_UNIT_VALUE: $crate::once_cell::Lazy<$crate::ffi::RawAircraftVariable> =
$crate::once_cell::Lazy::new(|| unsafe {
$crate::ffi::RawAircraftVariable::from_aircraft_variable_enum_str(
$ty::VARIABLE_NAME,
)
});
*RAW_UNIT_VALUE
}
}
};
}
#[macro_export]
macro_rules! indexed_aircraft_variable {
($ty:ident ( $unit:ty ): $name:literal; $description:literal) => {
$crate::aircraft_variable!($ty($unit): $name; $description);
impl $ty {
#[inline]
fn read_raw_by_index(index: u32) -> f64 {
$crate::ffi::RawAircraftVariable::read(<Self as $crate::AircraftVariable>::as_raw_aircraft_variable(), <<Self as $crate::AircraftVariable>::Unit as $crate::Unit>::as_raw_unit(), index)
}
}
};
}
#[macro_export]
macro_rules! unindexed_aircraft_variable {
($ty:ident ( $unit:ty ): $name:literal; $description:literal) => {
$crate::aircraft_variable!($ty($unit): $name; $description);
impl $ty {
#[inline]
fn read_raw() -> f64 {
$crate::ffi::RawAircraftVariable::read(<Self as $crate::AircraftVariable>::as_raw_aircraft_variable(), <<Self as $crate::AircraftVariable>::Unit as $crate::Unit>::as_raw_unit(), 0)
}
}
};
}
pub trait NamedVariable {
type Value: Into<f64> + From<f64>;
fn as_raw_named_variable() -> ffi::RawNamedVariable;
}
#[macro_export]
macro_rules! named_variable {
($ty:ident ($val:ty): $name:literal; $description:literal) => {
#[doc = $description]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct $ty;
impl $ty {
const VARIABLE_NAME: &'static str = concat!($name, "\0");
#[inline]
fn set_raw(value: <Self as $crate::NamedVariable>::Value)
{
$crate::ffi::RawNamedVariable::set(<Self as $crate::NamedVariable>::as_raw_named_variable(), value.into())
}
#[inline]
fn read_raw() -> <Self as $crate::NamedVariable>::Value
{
$crate::ffi::RawNamedVariable::get(<Self as $crate::NamedVariable>::as_raw_named_variable()).into()
}
}
impl $crate::NamedVariable for $ty {
type Value = $val;
#[inline]
fn as_raw_named_variable() -> $crate::ffi::RawNamedVariable {
static RAW_UNIT_VALUE: $crate::once_cell::Lazy<$crate::ffi::RawNamedVariable> = $crate::once_cell::Lazy::new(|| unsafe {
$crate::ffi::RawNamedVariable::register_new($ty::VARIABLE_NAME)
});
*RAW_UNIT_VALUE
}
}
};
}