1 #ifndef FG_FGCOM_HXX 2 #define FG_FGCOM_HXX 3 4 // fgcom.hxx -- FGCom: Voice communication 5 // 6 // Written by Clement de l'Hamaide, started May 2013. 7 // 8 // This program is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU General Public License as 10 // published by the Free Software Foundation; either version 2 of the 11 // License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, but 14 // WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 // General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License 19 // along with this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 22 #include <simgear/structure/subsystem_mgr.hxx> 23 #include <simgear/props/props.hxx> 24 #include <simgear/math/sg_geodesy.hxx> 25 26 class FGCom : public SGSubsystem, 27 public SGPropertyChangeListener 28 { 29 public: 30 FGCom(); 31 virtual ~FGCom(); 32 33 // Subsystem API. 34 void bind() override; 35 void init() override; 36 void postinit() override; 37 void shutdown() override; 38 void unbind() override; 39 void update(double dt) override; 40 41 // Subsystem identification. staticSubsystemClassId()42 static const char* staticSubsystemClassId() { return "fgcom"; } 43 44 virtual void valueChanged(SGPropertyNode *prop); 45 void iaxTextEvent(struct iaxc_ev_text text); 46 47 private: 48 SGPropertyNode_ptr _ptt_node; // PTT; nonzero int indicating channel number (instrumentation/comm/[channel-1]) 49 SGPropertyNode_ptr _selected_comm_node; // selected channel (fgcom); nonzero channel int indicating channel number (instrumentation/comm/[channel-1]) 50 SGPropertyNode_ptr _commFrequencyNode; // current comm node in use; e.g. /instrumentation/comm[0] 51 SGPropertyNode_ptr _commVolumeNode; // current volume node in use; e.g. /instrumentation/comm[0]/volume 52 SGPropertyNode_ptr _test_node; // sim/fgcom/test 53 SGPropertyNode_ptr _text_node; // sim/fgcom/text 54 SGPropertyNode_ptr _server_node; // sim/fgcom/server 55 SGPropertyNode_ptr _enabled_node; // sim/fgcom/enabled 56 SGPropertyNode_ptr _version_node; // sim/version/flightgear 57 SGPropertyNode_ptr _micBoost_node; // sim/fgcom/mic-boost 58 SGPropertyNode_ptr _callsign_node; // sim/multiplay/callsign 59 SGPropertyNode_ptr _register_node; // sim/fgcom/register/enabled 60 SGPropertyNode_ptr _username_node; // sim/fgcom/register/username 61 SGPropertyNode_ptr _password_node; // sim/fgcom/register/password 62 SGPropertyNode_ptr _micLevel_node; // sim/fgcom/mic-level 63 SGPropertyNode_ptr _silenceThd_node; // sim/fgcom/silence-threshold 64 SGPropertyNode_ptr _speakerLevel_node; // sim/fgcom/speaker-level 65 SGPropertyNode_ptr _deviceID_node[4]; // sim/fgcom/device[n]/id 66 SGPropertyNode_ptr _deviceName_node[4]; // sim/fgcom/device[n]/name 67 SGPropertyNode_ptr _deviceInput_node[4]; // sim/fgcom/device[n]/available-input 68 SGPropertyNode_ptr _deviceOutput_node[4]; // sim/fgcom/device[n]/available-output 69 SGPropertyNode_ptr _selectedInput_node; // sim/fgcom/device-input 70 SGPropertyNode_ptr _selectedOutput_node; // sim/fgcom/device-output 71 SGPropertyNode_ptr _showMessages_node; // sim/fgcom/show-messages 72 SGPropertyNode_ptr _mpTransmitFrequencyNode; // sim/multiplay/comm-transmit-frequency-mhz 73 SGPropertyNode_ptr _mpTransmitPowerNode; // sim/multiplay/comm-transmit-power-norm 74 75 double _maxRange = 0.0; 76 double _minRange = 0.0; 77 double _currentCommFrequency = 0.0; 78 double _currentCallFrequency = 0.0; 79 bool _register = true; 80 bool _enabled = false; 81 bool _initialized = false; 82 int _regId = 0; 83 int _currentCallIdent = -1; 84 //int _callComm1; 85 int _listener_active = 0; 86 std::string _server; 87 std::string _callsign; 88 std::string _username; 89 std::string _password; 90 SGTimeStamp _processingTimer; 91 SGGeod _aptPos; 92 93 std::string computePhoneNumber(const double& freq, const std::string& icao) const; 94 std::string getAirportCode(const double& freq); 95 // SGGeod getAirportPos(const double& freq) const; 96 void setupCommFrequency(int channel = -1); 97 double getCurrentFrequencyKhz() const; 98 double getCurrentCommVolume() const; 99 bool isInRange(const double& freq) const; 100 101 void updateCall(); 102 void connectToCommFrequency(); 103 void testMode(bool testMode); 104 }; 105 106 #endif // of FG_FGCOM_HXX 107 108 109