更新 'src/Network/fgcom.cxx'

This commit is contained in:
zhongjin 2022-11-09 17:00:29 +08:00
parent e834e998ec
commit 3df9fbcda0

View File

@ -47,7 +47,7 @@
#define MAX_RANGE 100.0 #define MAX_RANGE 100.0
#define MIN_RANGE 20.0 #define MIN_RANGE 20.0
#define MIN_GNDTWR_RANGE 0.0 #define MIN_GNDTWR_RANGE 0.0
#define DEFAULT_SERVER "fgcom.jingweiht.com" #define DEFAULT_SERVER "fgcom.flightgear.org"
#define IAX_DELAY 300 // delay between calls in milliseconds #define IAX_DELAY 300 // delay between calls in milliseconds
#define TEST_FREQ 910.00 #define TEST_FREQ 910.00
#define NULL_ICAO "ZZZZ" #define NULL_ICAO "ZZZZ"
@ -326,9 +326,6 @@ void FGCom::postinit()
iaxc_input_level_set( 0.0 ); iaxc_input_level_set( 0.0 );
iaxc_output_level_set(getCurrentCommVolume()); iaxc_output_level_set(getCurrentCommVolume());
SG_LOG(SG_SOUND, SG_INFO, "FGCom: Mute the mic and set speaker at start " << getCurrentCommVolume());
iaxc_millisleep(50); iaxc_millisleep(50);
// Do the first call at start // Do the first call at start
@ -345,8 +342,6 @@ double FGCom::getCurrentCommVolume() const {
if (_commVolumeNode) if (_commVolumeNode)
rv = rv * _commVolumeNode->getFloatValue(); rv = rv * _commVolumeNode->getFloatValue();
//zhongjin
rv = 0.9;
return rv; return rv;
} }
double FGCom::getCurrentFrequencyKhz() const { double FGCom::getCurrentFrequencyKhz() const {
@ -354,9 +349,6 @@ double FGCom::getCurrentFrequencyKhz() const {
} }
void FGCom::setupCommFrequency(int channel) { void FGCom::setupCommFrequency(int channel) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: setupCommFrequency " << channel);
if (channel < 1) { if (channel < 1) {
if (_selected_comm_node != nullptr) { if (_selected_comm_node != nullptr) {
channel = _selected_comm_node->getIntValue(); channel = _selected_comm_node->getIntValue();
@ -366,7 +358,7 @@ void FGCom::setupCommFrequency(int channel) {
if (channel < 1) { if (channel < 1) {
if (_currentCallIdent != -1) { if (_currentCallIdent != -1) {
iaxc_dump_call_number(_currentCallIdent); iaxc_dump_call_number(_currentCallIdent);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: disconnect as channel 0 " << _currentCallIdent); SG_LOG(SG_IO, SG_INFO, "FGCom: disconnect as channel 0 " << _currentCallIdent);
_currentCallIdent = -1; _currentCallIdent = -1;
} }
_currentCommFrequency = 0.0; _currentCommFrequency = 0.0;
@ -397,21 +389,20 @@ void FGCom::setupCommFrequency(int channel) {
} }
} }
} }
SG_LOG(SG_SOUND, SG_INFO, "FGCom: setupCommFrequency node listener failed: channel " << channel); SG_LOG(SG_IO, SG_INFO, "FGCom: setupCommFrequency node listener failed: channel " << channel);
} }
if (_commFrequencyNode) if (_commFrequencyNode)
_commFrequencyNode->removeChangeListener(this); _commFrequencyNode->removeChangeListener(this);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: setupCommFrequency invalid channel " << channel); SG_LOG(SG_IO, SG_INFO, "FGCom: setupCommFrequency invalid channel " << channel);
_currentCommFrequency = 0.0; _currentCommFrequency = 0.0;
} }
void FGCom::connectToCommFrequency() { void FGCom::connectToCommFrequency() {
// ensure that the current comm is still in range // ensure that the current comm is still in range
if ((_currentCallFrequency > 0.0) && !isInRange(_currentCallFrequency)) { if ((_currentCallFrequency > 0.0) && !isInRange(_currentCallFrequency)) {
SG_LOG(SG_SOUND, SG_WARN, "FGCom: call out of range of: " << _currentCallFrequency); SG_LOG(SG_IO, SG_WARN, "FGCom: call out of range of: " << _currentCallFrequency);
_currentCallFrequency = 0.0; _currentCallFrequency = 0.0;
} }
@ -428,7 +419,7 @@ void FGCom::connectToCommFrequency() {
if (_currentCallFrequency != _currentCommFrequency || _currentCallIdent == -1) { if (_currentCallFrequency != _currentCommFrequency || _currentCallIdent == -1) {
if (_currentCallIdent != -1) { if (_currentCallIdent != -1) {
iaxc_dump_call_number(_currentCallIdent); iaxc_dump_call_number(_currentCallIdent);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: dump_call_number " << _currentCallIdent); SG_LOG(SG_IO, SG_INFO, "FGCom: dump_call_number " << _currentCallIdent);
_currentCallIdent = -1; _currentCallIdent = -1;
} }
@ -438,7 +429,7 @@ void FGCom::connectToCommFrequency() {
_processingTimer.stamp(); _processingTimer.stamp();
if (!isInRange(_currentCommFrequency)) { if (!isInRange(_currentCommFrequency)) {
if (_currentCallIdent != -1) { if (_currentCallIdent != -1) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: disconnect call as not in range " << _currentCallIdent); SG_LOG(SG_IO, SG_INFO, "FGCom: disconnect call as not in range " << _currentCallIdent);
if (_currentCallIdent != -1) { if (_currentCallIdent != -1) {
iaxc_dump_call_number(_currentCallIdent); iaxc_dump_call_number(_currentCallIdent);
_currentCallIdent = -1; _currentCallIdent = -1;
@ -449,14 +440,14 @@ void FGCom::connectToCommFrequency() {
if (!num.empty()) { if (!num.empty()) {
_currentCallIdent = iaxc_call(num.c_str()); _currentCallIdent = iaxc_call(num.c_str());
if (_currentCallIdent == -1) if (_currentCallIdent == -1)
SG_LOG(SG_SOUND, SG_DEBUG, "FGCom: cannot call " << num.c_str()); SG_LOG(SG_IO, SG_DEBUG, "FGCom: cannot call " << num.c_str());
else { else {
SG_LOG(SG_SOUND, SG_DEBUG, "FGCom: call established " << num.c_str() << " Freq: " << _currentCommFrequency); SG_LOG(SG_IO, SG_DEBUG, "FGCom: call established " << num.c_str() << " Freq: " << _currentCommFrequency);
_currentCallFrequency = _currentCommFrequency; _currentCallFrequency = _currentCommFrequency;
} }
} }
else else
SG_LOG(SG_SOUND, SG_WARN, "FGCom: frequency " << _currentCommFrequency << " does not map to valid IAX address"); SG_LOG(SG_IO, SG_WARN, "FGCom: frequency " << _currentCommFrequency << " does not map to valid IAX address");
} }
} }
} }
@ -491,8 +482,6 @@ void FGCom::shutdown()
_initialized = false; _initialized = false;
_enabled = false; _enabled = false;
SG_LOG(SG_SOUND, SG_INFO, "FGCom: shutdown" );
iaxc_set_event_callback(NULL); iaxc_set_event_callback(NULL);
iaxc_unregister(_regId); iaxc_unregister(_regId);
iaxc_stop_processing_thread(); iaxc_stop_processing_thread();
@ -529,34 +518,28 @@ void FGCom::valueChanged(SGPropertyNode *prop)
} }
if (prop == _commVolumeNode && _enabled) { if (prop == _commVolumeNode && _enabled) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _commVolumeNode" );
if (_ptt_node->getIntValue()) { if (_ptt_node->getIntValue()) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: ignoring change comm volume as PTT pressed"); SG_LOG(SG_IO, SG_INFO, "FGCom: ignoring change comm volume as PTT pressed");
} }
else else
{ {
iaxc_input_level_set(0.0); iaxc_input_level_set(0.0);
iaxc_output_level_set(getCurrentCommVolume()); iaxc_output_level_set(getCurrentCommVolume());
SG_LOG(SG_SOUND, SG_INFO, "FGCom: change comm volume=" << _commVolumeNode->getFloatValue()); SG_LOG(SG_IO, SG_INFO, "FGCom: change comm volume=" << _commVolumeNode->getFloatValue());
} }
} }
if (prop == _selected_comm_node && _enabled) { if (prop == _selected_comm_node && _enabled) {
setupCommFrequency(); setupCommFrequency();
SG_LOG(SG_SOUND, SG_INFO, "FGCom: change comm frequency (selected node): set to " << _currentCommFrequency); SG_LOG(SG_IO, SG_INFO, "FGCom: change comm frequency (selected node): set to " << _currentCommFrequency);
} }
if (prop == _commFrequencyNode && _enabled) { if (prop == _commFrequencyNode && _enabled) {
setupCommFrequency(); setupCommFrequency();
SG_LOG(SG_SOUND, SG_INFO, "FGCom: change comm frequency (property updated): set to " << _currentCommFrequency); SG_LOG(SG_IO, SG_INFO, "FGCom: change comm frequency (property updated): set to " << _currentCommFrequency);
} }
if (prop == _ptt_node && _enabled) { if (prop == _ptt_node && _enabled) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _ptt_node" );
if (_ptt_node->getIntValue()) { if (_ptt_node->getIntValue()) {
// ensure that we are on the right channel by calling setupCommFrequency // ensure that we are on the right channel by calling setupCommFrequency
setupCommFrequency(); setupCommFrequency();
@ -564,12 +547,12 @@ void FGCom::valueChanged(SGPropertyNode *prop)
iaxc_input_level_set(_micLevel_node->getFloatValue()); //0.0 = min , 1.0 = max iaxc_input_level_set(_micLevel_node->getFloatValue()); //0.0 = min , 1.0 = max
_mpTransmitFrequencyNode->setValue(_currentCallFrequency * 1000000); _mpTransmitFrequencyNode->setValue(_currentCallFrequency * 1000000);
_mpTransmitPowerNode->setValue(1.0); _mpTransmitPowerNode->setValue(1.0);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: PTT active: " << _currentCallFrequency); SG_LOG(SG_IO, SG_INFO, "FGCom: PTT active: " << _currentCallFrequency);
} }
else { else {
iaxc_output_level_set(getCurrentCommVolume()); iaxc_output_level_set(getCurrentCommVolume());
iaxc_input_level_set(0.0); iaxc_input_level_set(0.0);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: PTT release: " << _currentCallFrequency << " vol=" << getCurrentCommVolume()); SG_LOG(SG_IO, SG_INFO, "FGCom: PTT release: " << _currentCallFrequency << " vol=" << getCurrentCommVolume());
_mpTransmitFrequencyNode->setValue(0); _mpTransmitFrequencyNode->setValue(0);
_mpTransmitPowerNode->setValue(0); _mpTransmitPowerNode->setValue(0);
} }
@ -589,9 +572,6 @@ void FGCom::valueChanged(SGPropertyNode *prop)
//FIXME: not implemented in IAX audio driver (audio_openal.c) //FIXME: not implemented in IAX audio driver (audio_openal.c)
if (prop == _micBoost_node && _initialized) { if (prop == _micBoost_node && _initialized) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _micBoost_node" );
int micBoost = prop->getIntValue(); int micBoost = prop->getIntValue();
SG_CLAMP_RANGE<int>( micBoost, 0, 1 ); SG_CLAMP_RANGE<int>( micBoost, 0, 1 );
iaxc_mic_boost_set( micBoost ) ; // 0 = enabled , 1 = disabled iaxc_mic_boost_set( micBoost ) ; // 0 = enabled , 1 = disabled
@ -600,9 +580,6 @@ void FGCom::valueChanged(SGPropertyNode *prop)
//FIXME: not implemented in IAX audio driver (audio_openal.c) //FIXME: not implemented in IAX audio driver (audio_openal.c)
if ((prop == _selectedInput_node || prop == _selectedOutput_node) && _initialized) { if ((prop == _selectedInput_node || prop == _selectedOutput_node) && _initialized) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _selectedInput_node _selectedOutput_node" );
int selectedInput = _selectedInput_node->getIntValue(); int selectedInput = _selectedInput_node->getIntValue();
int selectedOutput = _selectedOutput_node->getIntValue(); int selectedOutput = _selectedOutput_node->getIntValue();
iaxc_audio_devices_set(selectedInput, selectedOutput, 0); iaxc_audio_devices_set(selectedInput, selectedOutput, 0);
@ -615,20 +592,13 @@ void FGCom::valueChanged(SGPropertyNode *prop)
_listener_active++; _listener_active++;
if (prop == _speakerLevel_node && _enabled) { if (prop == _speakerLevel_node && _enabled) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _speakerLevel_node" );
float speakerLevel = prop->getFloatValue(); float speakerLevel = prop->getFloatValue();
SG_CLAMP_RANGE<float>( speakerLevel, 0.0, 1.0 ); SG_CLAMP_RANGE<float>( speakerLevel, 0.0, 1.0 );
_speakerLevel_node->setFloatValue(speakerLevel); _speakerLevel_node->setFloatValue(speakerLevel);
//iaxc_output_level_set(speakerLevel); iaxc_output_level_set(speakerLevel);
SG_LOG(SG_SOUND, SG_INFO, "FGCom: speakerLevel " << speakerLevel );
} }
if (prop == _micLevel_node && _enabled) { if (prop == _micLevel_node && _enabled) {
SG_LOG(SG_SOUND, SG_INFO, "FGCom: prop = _micLevel_node" );
float micLevel = prop->getFloatValue(); float micLevel = prop->getFloatValue();
SG_CLAMP_RANGE<float>( micLevel, 0.0, 1.0 ); SG_CLAMP_RANGE<float>( micLevel, 0.0, 1.0 );
_micLevel_node->setFloatValue(micLevel); _micLevel_node->setFloatValue(micLevel);
@ -653,7 +623,7 @@ void FGCom::testMode(bool testMode)
_currentCallIdent = iaxc_call(num.c_str()); _currentCallIdent = iaxc_call(num.c_str());
} }
if( _currentCallIdent == -1 ) if( _currentCallIdent == -1 )
SG_LOG( SG_SOUND, SG_DEBUG, "FGCom: cannot call " << num.c_str() ); SG_LOG( SG_IO, SG_DEBUG, "FGCom: cannot call " << num.c_str() );
} else { } else {
if( _initialized ) { if( _initialized ) {
iaxc_dump_all_calls(); iaxc_dump_all_calls();