| 1 | /* |
| 2 | * SPDX-License-Identifier: CC0-1.0 |
| 3 | * |
| 4 | * adf.hxx - automatic direction finder. |
| 5 | * Written by David Megginson, started 2003. |
| 6 | * Last modified by Eric van den Berg, 24 Nov 2012 |
| 7 | * |
| 8 | * This file is in the Public Domain and comes with no warranty. |
| 9 | */ |
| 10 | |
| 11 | #pragma once |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | #include <Instrumentation/AbstractInstrument.hxx> |
| 16 | #include <simgear/math/SGMath.hxx> |
| 17 | |
| 18 | class SGSampleGroup; |
| 19 | |
| 20 | /** |
| 21 | * Model an ADF radio. |
| 22 | * |
| 23 | * Input properties: |
| 24 | * |
| 25 | * /position/longitude-deg |
| 26 | * /position/latitude-deg |
| 27 | * /position/altitude-ft |
| 28 | * /orientation/heading-deg |
| 29 | * /systems/electrical/outputs/adf |
| 30 | * /instrumentation/adf/serviceable |
| 31 | * /instrumentation/adf/error-deg |
| 32 | * /instrumentation/adf/frequencies/selected-khz |
| 33 | * /instrumentation/adf/mode |
| 34 | * /instrumentation/adf/ident-audible |
| 35 | * /instrumentation/adf/volume-norm |
| 36 | * |
| 37 | * Output properties: |
| 38 | * |
| 39 | * /instrumentation/adf/in-range |
| 40 | * /instrumentation/adf/indicated-bearing-deg |
| 41 | * /instrumentation/adf/ident |
| 42 | */ |
| 43 | class ADF : public AbstractInstrument |
| 44 | { |
| 45 | public: |
| 46 | ADF ( SGPropertyNode *node ); |
| 47 | virtual ~ADF (); |
| 48 | |
| 49 | // Subsystem API. |
| 50 | void init() override; |
| 51 | void update(double delta_time_sec) override; |
| 52 | |
| 53 | // Subsystem identification. |
| 54 | static const char* staticSubsystemClassId() { return "adf"; } |
| 55 | |
| 56 | private: |
| 57 | void set_bearing (double delta_time_sec, double bearing); |
| 58 | |
| 59 | void search (double frequency, const SGGeod& pos); |
| 60 | |
| 61 | SGPropertyNode_ptr _heading_node; |
| 62 | SGPropertyNode_ptr _error_node; |
| 63 | SGPropertyNode_ptr _frequency_node; |
| 64 | SGPropertyNode_ptr _mode_node; |
| 65 | |
| 66 | SGPropertyNode_ptr _in_range_node; |
| 67 | SGPropertyNode_ptr _bearing_node; |
| 68 | SGPropertyNode_ptr _ident_node; |
| 69 | SGPropertyNode_ptr _ident_audible_node; |
| 70 | SGPropertyNode_ptr _volume_node; |
| 71 | |
| 72 | double _time_before_search_sec; |
| 73 | |
| 74 | int _last_frequency_khz; |
| 75 | bool _transmitter_valid; |
| 76 | std::string _last_ident; |
| 77 | SGGeod _transmitter_pos; |
| 78 | SGVec3d _transmitter_cart; |
| 79 | double _transmitter_range_nm; |
| 80 | |
| 81 | int _ident_count; |
| 82 | time_t _last_ident_time; |
| 83 | float _last_volume; |
| 84 | std::string _adf_ident; |
| 85 | |
| 86 | SGSharedPtr<SGSampleGroup> _sgr; |
| 87 | }; |