euroscope 0.0.1

Safe, idiomatic Rust interface for writing EuroScope plugins
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
//! Rust enums mirroring the EuroScope SDK's integer constant groups
//! (`CONNECTION_TYPE_*`, and — as the API grows — `TAG_*`, `POPUP_*`, the
//! coordination/handoff states, …). Each has a `from_raw` and an `Other`
//! variant for forward-compatibility.
//!
//! A handful of fields the SDK exposes as a single ANSI character (the ICAO
//! wake/type/engine letters, the communication-type code) are modelled the same
//! way, mapping to/from `c_char` with an `Other(c_char)` escape hatch.

use std::ffi::c_char;

/// How EuroScope is connected to the network. Mirrors `CONNECTION_TYPE_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionType {
    /// Not connected.
    None,
    /// Direct connection to the network.
    Direct,
    /// Connection via a proxy.
    ViaProxy,
    /// Connected as a simulator server.
    SimulatorServer,
    /// Playback of a recorded session.
    Playback,
    /// Connected as a simulator client.
    SimulatorClient,
    /// Sweatbox (training) server.
    Sweatbox,
    /// An unrecognized connection code (forward-compatibility).
    Unknown(i32),
}

impl ConnectionType {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Direct,
            2 => Self::ViaProxy,
            3 => Self::SimulatorServer,
            4 => Self::Playback,
            5 => Self::SimulatorClient,
            6 => Self::Sweatbox,
            other => Self::Unknown(other),
        }
    }

    /// Whether EuroScope is connected in any way (i.e. not [`None`](Self::None)).
    pub fn is_connected(self) -> bool {
        self != Self::None
    }
}

/// A flight plan's correlation/coordination state, from `CFlightPlan::GetState`.
/// Mirrors the `FLIGHT_PLAN_STATE_*` values used by `GetState`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FlightPlanState {
    /// Not concerned.
    NonConcerned,
    /// Notified.
    Notified,
    /// Coordinated.
    Coordinated,
    /// Transfer to me initiated.
    TransferToMeInitiated,
    /// Transfer from me initiated.
    TransferFromMeInitiated,
    /// Assumed (tracked by me).
    Assumed,
    /// Redundant.
    Redundant,
    /// An unrecognized state.
    Other(i32),
}

impl FlightPlanState {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::NonConcerned,
            1 => Self::Notified,
            2 => Self::Coordinated,
            3 => Self::TransferToMeInitiated,
            4 => Self::TransferFromMeInitiated,
            5 => Self::Assumed,
            7 => Self::Redundant,
            other => Self::Other(other),
        }
    }
}

/// A flight plan's simulation state, from `CFlightPlan::GetFPState`. Mirrors the
/// `FLIGHT_PLAN_STATE_NOT_STARTED/SIMULATED/TERMINATED` values.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SimulationState {
    /// Not started.
    NotStarted,
    /// Simulated by EuroScope (out of range).
    Simulated,
    /// Terminated.
    Terminated,
    /// An unrecognized state.
    Other(i32),
}

impl SimulationState {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::NotStarted,
            1 => Self::Simulated,
            2 => Self::Terminated,
            other => Self::Other(other),
        }
    }
}

/// Which controller-assigned datum changed, from the `data_type` of
/// [`Plugin::on_controller_assigned_data_update`](crate::Plugin::on_controller_assigned_data_update).
/// Mirrors `CTR_DATA_TYPE_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControllerDataType {
    Squawk,
    FinalAltitude,
    TemporaryAltitude,
    CommunicationType,
    ScratchPadString,
    GroundState,
    ClearanceFlag,
    DepartureSequence,
    Speed,
    Mach,
    Rate,
    Heading,
    DirectTo,
    /// An unrecognized data type.
    Other(i32),
}

impl ControllerDataType {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            1 => Self::Squawk,
            2 => Self::FinalAltitude,
            3 => Self::TemporaryAltitude,
            4 => Self::CommunicationType,
            5 => Self::ScratchPadString,
            6 => Self::GroundState,
            7 => Self::ClearanceFlag,
            8 => Self::DepartureSequence,
            9 => Self::Speed,
            10 => Self::Mach,
            11 => Self::Rate,
            12 => Self::Heading,
            13 => Self::DirectTo,
            other => Self::Other(other),
        }
    }
}

/// A point/altitude coordination state, from the `Get*CoordinationState`
/// getters. Mirrors `COORDINATION_STATE_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CoordinationState {
    None,
    RequestedByMe,
    RequestedByOther,
    Accepted,
    Refused,
    ManualAccepted,
    /// An unrecognized state.
    Other(i32),
}

impl CoordinationState {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            1 => Self::None,
            2 => Self::RequestedByMe,
            3 => Self::RequestedByOther,
            4 => Self::Accepted,
            5 => Self::Refused,
            6 => Self::ManualAccepted,
            other => Self::Other(other),
        }
    }
}

/// What data is available for a tag item, from the `tag_data` of
/// [`Plugin::on_get_tag_item`](crate::Plugin::on_get_tag_item). Mirrors
/// `TAG_DATA_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TagData {
    /// Only uncorrelated radar data.
    UncorrelatedRadar,
    /// Flight-plan track data.
    FlightPlanTrack,
    /// Correlated radar + flight plan.
    Correlated,
    /// An unrecognized value.
    Other(i32),
}

impl TagData {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            1 => Self::UncorrelatedRadar,
            2 => Self::FlightPlanTrack,
            3 => Self::Correlated,
            other => Self::Other(other),
        }
    }
}

/// A built-in tag colour, set via [`TagItem::set_color`](crate::TagItem::set_color).
///
/// Mirrors `TAG_COLOR_*`. Use [`Rgb`](Self::Rgb)/[`Default`](Self::Default) with
/// [`TagItem::set_rgb`](crate::TagItem::set_rgb) for a custom colour.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TagColor {
    /// Default colour.
    Default,
    /// Use the RGB set via `set_rgb`.
    Rgb,
    NonConcerned,
    Notified,
    Assumed,
    TransferToMeInitiated,
    Redundant,
    Information,
    OngoingRequestFromMe,
    OngoingRequestToMe,
    OngoingRequestAccepted,
    OngoingRequestRefused,
    Emergency,
    /// A raw colour code not covered above.
    Other(i32),
}

impl TagColor {
    pub(crate) fn to_raw(self) -> i32 {
        match self {
            Self::Default => 0,
            Self::Rgb => 1,
            Self::NonConcerned => 2,
            Self::Notified => 3,
            Self::Assumed => 4,
            Self::TransferToMeInitiated => 5,
            Self::Redundant => 6,
            Self::Information => 7,
            Self::OngoingRequestFromMe => 8,
            Self::OngoingRequestToMe => 9,
            Self::OngoingRequestAccepted => 10,
            Self::OngoingRequestRefused => 11,
            Self::Emergency => 12,
            Self::Other(v) => v,
        }
    }
}

/// A mouse button, from the screen-object `RadarScreen` callbacks. Mirrors
/// `BUTTON_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseButton {
    Left,
    Middle,
    Right,
    /// An unrecognized button code.
    Other(i32),
}

impl MouseButton {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            1 => Self::Left,
            2 => Self::Middle,
            3 => Self::Right,
            other => Self::Other(other),
        }
    }
}

/// Classification of an extracted-route airway segment. Mirrors `AIRWAY_CLASS_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AirwayClass {
    Valid,
    DirectionError,
    Unconnected,
    NoDataDirect,
    /// An unrecognized class.
    Other(i32),
}

impl AirwayClass {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::Valid,
            1 => Self::DirectionError,
            2 => Self::Unconnected,
            3 => Self::NoDataDirect,
            other => Self::Other(other),
        }
    }
}

/// The drawing phase passed to
/// [`RadarScreen::on_refresh`](crate::RadarScreen::on_refresh). Mirrors
/// `REFRESH_PHASE_*`. `OnRefresh` is called once per phase each repaint.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RefreshPhase {
    /// Background bitmap (map content).
    BackBitmap,
    /// Before TAGs are drawn.
    BeforeTags,
    /// After TAGs, before lists.
    AfterTags,
    /// After everything (before the chat area).
    AfterLists,
    /// An unrecognized phase (forward-compatibility).
    Other(i32),
}

impl RefreshPhase {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::BackBitmap,
            1 => Self::BeforeTags,
            2 => Self::AfterTags,
            3 => Self::AfterLists,
            other => Self::Other(other),
        }
    }
}

/// A sector-file element category, used to filter
/// [`Context::sector_file_elements`](crate::Context::sector_file_elements).
/// Mirrors `SECTOR_ELEMENT_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SectorElementType {
    Info,
    Vor,
    Ndb,
    Airport,
    Runway,
    Fix,
    Star,
    Sid,
    LowAirway,
    HighAirway,
    HighArtc,
    Artc,
    LowArtc,
    Geo,
    FreeText,
    Airspace,
    Position,
    SidsStars,
    Radars,
    Regions,
    /// All element types (`SECTOR_ELEMENT_ALL`).
    All,
    /// An unrecognized element type.
    Other(i32),
}

impl SectorElementType {
    pub(crate) fn to_raw(self) -> i32 {
        match self {
            Self::Info => 0,
            Self::Vor => 1,
            Self::Ndb => 2,
            Self::Airport => 3,
            Self::Runway => 4,
            Self::Fix => 5,
            Self::Star => 6,
            Self::Sid => 7,
            Self::LowAirway => 8,
            Self::HighAirway => 9,
            Self::HighArtc => 10,
            Self::Artc => 11,
            Self::LowArtc => 12,
            Self::Geo => 13,
            Self::FreeText => 14,
            Self::Airspace => 15,
            Self::Position => 16,
            Self::SidsStars => 17,
            Self::Radars => 18,
            Self::Regions => 19,
            Self::All => -1,
            Self::Other(v) => v,
        }
    }
}

/// Checkbox state of a popup-list element. Mirrors `POPUP_ELEMENT_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PopupCheck {
    /// Show an unchecked checkbox.
    Unchecked,
    /// Show a checked checkbox.
    Checked,
    /// No checkbox at all.
    NoCheckbox,
}

impl PopupCheck {
    pub(crate) fn to_raw(self) -> i32 {
        match self {
            Self::Unchecked => 0,
            Self::Checked => 1,
            Self::NoCheckbox => 2,
        }
    }
}

/// A controller's network (VATSIM) rating, from `CController::GetRating`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControllerRating {
    /// No/unknown rating.
    Unknown,
    /// Observer.
    Observer,
    /// Student 1 (Tower Trainee).
    S1,
    /// Student 2 (Tower Controller).
    S2,
    /// Senior Student (Approach Controller).
    S3,
    /// Enroute Controller.
    C1,
    /// C2 (reserved / unused on VATSIM).
    C2,
    /// Senior Controller.
    C3,
    /// Instructor.
    I1,
    /// I2 (reserved / unused on VATSIM).
    I2,
    /// Senior Instructor.
    I3,
    /// Supervisor.
    Supervisor,
    /// Administrator.
    Administrator,
    /// An unrecognized rating id (forward-compatibility).
    Other(i32),
}

impl ControllerRating {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::Unknown,
            1 => Self::Observer,
            2 => Self::S1,
            3 => Self::S2,
            4 => Self::S3,
            5 => Self::C1,
            6 => Self::C2,
            7 => Self::C3,
            8 => Self::I1,
            9 => Self::I2,
            10 => Self::I3,
            11 => Self::Supervisor,
            12 => Self::Administrator,
            other => Self::Other(other),
        }
    }

    /// Short label, e.g. `"S3"`. Empty for [`Unknown`](Self::Unknown) and
    /// unrecognized ratings.
    pub fn label(self) -> &'static str {
        match self {
            Self::Unknown | Self::Other(_) => "",
            Self::Observer => "OBS",
            Self::S1 => "S1",
            Self::S2 => "S2",
            Self::S3 => "S3",
            Self::C1 => "C1",
            Self::C2 => "C2",
            Self::C3 => "C3",
            Self::I1 => "I1",
            Self::I2 => "I2",
            Self::I3 => "I3",
            Self::Supervisor => "SUP",
            Self::Administrator => "ADM",
        }
    }
}

/// The kind of position a controller occupies, from `CController::GetFacility`.
///
/// Reflects *how you are connected*, independent of [`ControllerRating`]: an
/// `S3` connected as an observer has facility [`Observer`](Self::Observer).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Facility {
    /// Observer — not controlling a position.
    Observer,
    /// Flight Service Station.
    FlightService,
    /// Clearance Delivery.
    Delivery,
    /// Ground.
    Ground,
    /// Tower.
    Tower,
    /// Approach / Departure.
    Approach,
    /// Center / Enroute.
    Center,
    /// An unrecognized facility id (forward-compatibility).
    Other(i32),
}

impl Facility {
    pub(crate) fn from_raw(value: i32) -> Self {
        match value {
            0 => Self::Observer,
            1 => Self::FlightService,
            2 => Self::Delivery,
            3 => Self::Ground,
            4 => Self::Tower,
            5 => Self::Approach,
            6 => Self::Center,
            other => Self::Other(other),
        }
    }

    /// Whether this is an observer position (not controlling).
    pub fn is_observer(self) -> bool {
        matches!(self, Self::Observer)
    }
}

/// The voice/text communication capability of a flight plan.
///
/// A controller can assign it, and a flight plan carries it. Mirrors the single
/// character used by `GetCommunicationType`/`SetCommunicationType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommunicationType {
    /// Unassigned (`'\0'`).
    Unassigned,
    /// Full voice (`'V'`).
    Voice,
    /// Receive voice only, transmit by text (`'R'`).
    ReceiveOnly,
    /// Text only (`'T'`).
    TextOnly,
    /// An unrecognized code (forward-compatibility).
    Other(c_char),
}

impl CommunicationType {
    pub(crate) fn from_raw(value: c_char) -> Self {
        match value.cast_unsigned() {
            0 => Self::Unassigned,
            b'V' => Self::Voice,
            b'R' => Self::ReceiveOnly,
            b'T' => Self::TextOnly,
            other => Self::Other(other.cast_signed()),
        }
    }

    pub(crate) fn to_raw(self) -> c_char {
        let byte: u8 = match self {
            Self::Unassigned => 0,
            Self::Voice => b'V',
            Self::ReceiveOnly => b'R',
            Self::TextOnly => b'T',
            Self::Other(c) => c.cast_unsigned(),
        };
        byte.cast_signed()
    }
}

/// The ICAO wake turbulence category of an aircraft, from
/// `CFlightPlanData::GetAircraftWtc`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WakeCategory {
    /// Unknown (`'?'` or unset).
    Unknown,
    /// Light (`'L'`).
    Light,
    /// Medium (`'M'`).
    Medium,
    /// Heavy (`'H'`).
    Heavy,
    /// Super heavy (`'J'`).
    Super,
    /// An unrecognized code (forward-compatibility).
    Other(c_char),
}

impl WakeCategory {
    pub(crate) fn from_raw(value: c_char) -> Self {
        match value.cast_unsigned() {
            0 | b'?' => Self::Unknown,
            b'L' => Self::Light,
            b'M' => Self::Medium,
            b'H' => Self::Heavy,
            b'J' => Self::Super,
            other => Self::Other(other.cast_signed()),
        }
    }
}

/// The airframe category of an aircraft, from
/// `CFlightPlanData::GetAircraftType` (the ICAO single-letter type).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AircraftCategory {
    /// Unknown (`'?'` or unset).
    Unknown,
    /// Landplane (`'L'`).
    Landplane,
    /// Seaplane (`'S'`).
    Seaplane,
    /// Amphibian (`'A'`).
    Amphibian,
    /// Helicopter (`'H'`).
    Helicopter,
    /// Gyrocopter (`'G'`).
    Gyrocopter,
    /// Tilt-wing (`'T'`).
    TiltWing,
    /// An unrecognized code (forward-compatibility).
    Other(c_char),
}

impl AircraftCategory {
    pub(crate) fn from_raw(value: c_char) -> Self {
        match value.cast_unsigned() {
            0 | b'?' => Self::Unknown,
            b'L' => Self::Landplane,
            b'S' => Self::Seaplane,
            b'A' => Self::Amphibian,
            b'H' => Self::Helicopter,
            b'G' => Self::Gyrocopter,
            b'T' => Self::TiltWing,
            other => Self::Other(other.cast_signed()),
        }
    }
}

/// The engine type of an aircraft, from `CFlightPlanData::GetEngineType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EngineType {
    /// Unknown (`'?'` or unset).
    Unknown,
    /// Piston (`'P'`).
    Piston,
    /// Turboprop / turboshaft (`'T'`).
    Turboprop,
    /// Jet (`'J'`).
    Jet,
    /// Electric (`'E'`).
    Electric,
    /// An unrecognized code (forward-compatibility).
    Other(c_char),
}

impl EngineType {
    pub(crate) fn from_raw(value: c_char) -> Self {
        match value.cast_unsigned() {
            0 | b'?' => Self::Unknown,
            b'P' => Self::Piston,
            b'T' => Self::Turboprop,
            b'J' => Self::Jet,
            b'E' => Self::Electric,
            other => Self::Other(other.cast_signed()),
        }
    }
}

/// The navigation/equipment capability of an aircraft, from
/// `CFlightPlanData::GetCapibilities`.
///
/// This is the classic single-letter equipment suffix; the variants spell out
/// the DME / transponder / RNAV combination each letter encodes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NavCapability {
    /// Unknown (`'?'` or unset).
    Unknown,
    /// `'T'` — no DME, transponder without mode A+C.
    NoDmeTransponderNoModeC,
    /// `'X'` — no DME, no transponder.
    NoDmeNoTransponder,
    /// `'U'` — no DME, transponder with mode A+C.
    NoDmeTransponderModeC,
    /// `'D'` — DME, no transponder.
    DmeNoTransponder,
    /// `'B'` — DME, transponder without mode A+C.
    DmeTransponderNoModeC,
    /// `'A'` — DME, transponder with mode A+C.
    DmeTransponderModeC,
    /// `'M'` — TACAN only, no transponder.
    TacanNoTransponder,
    /// `'N'` — TACAN only, transponder without mode A+C.
    TacanTransponderNoModeC,
    /// `'P'` — TACAN only, transponder with mode A+C.
    TacanTransponderModeC,
    /// `'Y'` — simple RNAV, no transponder.
    SimpleRnavNoTransponder,
    /// `'C'` — simple RNAV, transponder without mode A+C.
    SimpleRnavTransponderNoModeC,
    /// `'I'` — simple RNAV, transponder with mode A+C.
    SimpleRnavTransponderModeC,
    /// `'E'` — advanced RNAV with dual FMS.
    AdvancedRnavDualFms,
    /// `'F'` — advanced RNAV with single FMS.
    AdvancedRnavSingleFms,
    /// `'G'` — advanced RNAV with GPS or GNSS.
    AdvancedRnavGnss,
    /// `'R'` — advanced RNAV with RNP capability.
    AdvancedRnavRnp,
    /// `'W'` — advanced RNAV with RVSM capability.
    AdvancedRnavRvsm,
    /// `'Q'` — advanced RNAV with RNP and RVSM.
    AdvancedRnavRnpRvsm,
    /// An unrecognized code (forward-compatibility).
    Other(c_char),
}

impl NavCapability {
    pub(crate) fn from_raw(value: c_char) -> Self {
        match value.cast_unsigned() {
            0 | b'?' => Self::Unknown,
            b'T' => Self::NoDmeTransponderNoModeC,
            b'X' => Self::NoDmeNoTransponder,
            b'U' => Self::NoDmeTransponderModeC,
            b'D' => Self::DmeNoTransponder,
            b'B' => Self::DmeTransponderNoModeC,
            b'A' => Self::DmeTransponderModeC,
            b'M' => Self::TacanNoTransponder,
            b'N' => Self::TacanTransponderNoModeC,
            b'P' => Self::TacanTransponderModeC,
            b'Y' => Self::SimpleRnavNoTransponder,
            b'C' => Self::SimpleRnavTransponderNoModeC,
            b'I' => Self::SimpleRnavTransponderModeC,
            b'E' => Self::AdvancedRnavDualFms,
            b'F' => Self::AdvancedRnavSingleFms,
            b'G' => Self::AdvancedRnavGnss,
            b'R' => Self::AdvancedRnavRnp,
            b'W' => Self::AdvancedRnavRvsm,
            b'Q' => Self::AdvancedRnavRnpRvsm,
            other => Self::Other(other.cast_signed()),
        }
    }
}