Interface the adf and transponder to the electrical system.
This commit is contained in:
parent
3fdcbbd6ce
commit
a7fb46bcb2
2 changed files with 98 additions and 80 deletions
src/Network
|
@ -398,11 +398,14 @@ bool FGATC610x::open() {
|
||||||
dme_kt = fgGetNode( "/radios/dme/speed-kt", true );
|
dme_kt = fgGetNode( "/radios/dme/speed-kt", true );
|
||||||
dme_nm = fgGetNode( "/radios/dme/distance-nm", true );
|
dme_nm = fgGetNode( "/radios/dme/distance-nm", true );
|
||||||
|
|
||||||
|
adf_bus_power = fgGetNode( "/systems/electrical/outputs/adf", true );
|
||||||
dme_bus_power = fgGetNode( "/systems/electrical/outputs/dme", true );
|
dme_bus_power = fgGetNode( "/systems/electrical/outputs/dme", true );
|
||||||
navcom1_bus_power = fgGetNode( "/systems/electrical/outputs/navcomm[0]",
|
navcom1_bus_power = fgGetNode( "/systems/electrical/outputs/navcom[0]",
|
||||||
true );
|
true );
|
||||||
navcom2_bus_power = fgGetNode( "/systems/electrical/outputs/navcomm[1]",
|
navcom2_bus_power = fgGetNode( "/systems/electrical/outputs/navcom[1]",
|
||||||
true );
|
true );
|
||||||
|
xpdr_bus_power = fgGetNode( "/systems/electrical/outputs/transponder",
|
||||||
|
true );
|
||||||
|
|
||||||
navcom1_power_btn = fgGetNode( "/radios/comm[0]/inputs/power-btn", true );
|
navcom1_power_btn = fgGetNode( "/radios/comm[0]/inputs/power-btn", true );
|
||||||
navcom2_power_btn = fgGetNode( "/radios/comm[1]/inputs/power-btn", true );
|
navcom2_power_btn = fgGetNode( "/radios/comm[1]/inputs/power-btn", true );
|
||||||
|
@ -423,7 +426,7 @@ bool FGATC610x::open() {
|
||||||
nav2_stby_freq
|
nav2_stby_freq
|
||||||
= fgGetNode( "/radios/nav[1]/frequencies/standby-mhz", true );
|
= fgGetNode( "/radios/nav[1]/frequencies/standby-mhz", true );
|
||||||
|
|
||||||
adf_power = fgGetNode( "/radios/kr-87/inputs/power-btn", true );
|
adf_power_btn = fgGetNode( "/radios/kr-87/inputs/power-btn", true );
|
||||||
adf_vol = fgGetNode( "/radios/kr-87/inputs/volume", true );
|
adf_vol = fgGetNode( "/radios/kr-87/inputs/volume", true );
|
||||||
adf_adf_btn = fgGetNode( "/radios/kr-87/inputs/adf-btn", true );
|
adf_adf_btn = fgGetNode( "/radios/kr-87/inputs/adf-btn", true );
|
||||||
adf_bfo_btn = fgGetNode( "/radios/kr-87/inputs/bfo-btn", true );
|
adf_bfo_btn = fgGetNode( "/radios/kr-87/inputs/bfo-btn", true );
|
||||||
|
@ -944,13 +947,14 @@ bool FGATC610x::do_radio_switches() {
|
||||||
coarse_freq + fine_freq / 20.0);
|
coarse_freq + fine_freq / 20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( adf_power->getBoolValue() ) {
|
// ADF Tuner
|
||||||
// ADF Tuner
|
|
||||||
int adf_tuner_fine = ((radio_switch_data[21] >> 4) & 0x0f) - 1;
|
int adf_tuner_fine = ((radio_switch_data[21] >> 4) & 0x0f) - 1;
|
||||||
int adf_tuner_coarse = (radio_switch_data[21] & 0x0f) - 1;
|
int adf_tuner_coarse = (radio_switch_data[21] & 0x0f) - 1;
|
||||||
static int last_adf_tuner_fine = adf_tuner_fine;
|
static int last_adf_tuner_fine = adf_tuner_fine;
|
||||||
static int last_adf_tuner_coarse = adf_tuner_coarse;
|
static int last_adf_tuner_coarse = adf_tuner_coarse;
|
||||||
|
|
||||||
|
if ( adf_has_power() ) {
|
||||||
// cout << "adf_stby_mode = " << adf_stby_mode->getIntValue() << endl;
|
// cout << "adf_stby_mode = " << adf_stby_mode->getIntValue() << endl;
|
||||||
if ( adf_count_mode->getIntValue() == 2 ) {
|
if ( adf_count_mode->getIntValue() == 2 ) {
|
||||||
// tune count down timer
|
// tune count down timer
|
||||||
|
@ -1005,9 +1009,6 @@ bool FGATC610x::do_radio_switches() {
|
||||||
if ( value > 1799 ) { value -= 1600; }
|
if ( value > 1799 ) { value -= 1600; }
|
||||||
}
|
}
|
||||||
|
|
||||||
last_adf_tuner_fine = adf_tuner_fine;
|
|
||||||
last_adf_tuner_coarse = adf_tuner_coarse;
|
|
||||||
|
|
||||||
if ( adf_count_mode->getIntValue() == 2 ) {
|
if ( adf_count_mode->getIntValue() == 2 ) {
|
||||||
fgSetFloat( "/radios/kr-87/outputs/elapsed-timer", value );
|
fgSetFloat( "/radios/kr-87/outputs/elapsed-timer", value );
|
||||||
} else {
|
} else {
|
||||||
|
@ -1018,6 +1019,9 @@ bool FGATC610x::do_radio_switches() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
last_adf_tuner_fine = adf_tuner_fine;
|
||||||
|
last_adf_tuner_coarse = adf_tuner_coarse;
|
||||||
|
|
||||||
|
|
||||||
// ADF buttons
|
// ADF buttons
|
||||||
fgSetInt( "/radios/kr-87/inputs/adf-btn",
|
fgSetInt( "/radios/kr-87/inputs/adf-btn",
|
||||||
|
@ -1042,13 +1046,13 @@ bool FGATC610x::do_radio_switches() {
|
||||||
// Transponder Tuner
|
// Transponder Tuner
|
||||||
int i;
|
int i;
|
||||||
int digit_tuner[4];
|
int digit_tuner[4];
|
||||||
|
|
||||||
digit_tuner[0] = radio_switch_data[25] & 0x0f;
|
digit_tuner[0] = radio_switch_data[25] & 0x0f;
|
||||||
digit_tuner[1] = ( radio_switch_data[25] >> 4 ) & 0x0f;
|
digit_tuner[1] = ( radio_switch_data[25] >> 4 ) & 0x0f;
|
||||||
digit_tuner[2] = radio_switch_data[29] & 0x0f;
|
digit_tuner[2] = radio_switch_data[29] & 0x0f;
|
||||||
digit_tuner[3] = ( radio_switch_data[29] >> 4 ) & 0x0f;
|
digit_tuner[3] = ( radio_switch_data[29] >> 4 ) & 0x0f;
|
||||||
static bool first_time = true;
|
|
||||||
static int last_digit_tuner[4];
|
static int last_digit_tuner[4];
|
||||||
|
static bool first_time = true;
|
||||||
if ( first_time ) {
|
if ( first_time ) {
|
||||||
first_time = false;
|
first_time = false;
|
||||||
for ( i = 0; i < 4; ++i ) {
|
for ( i = 0; i < 4; ++i ) {
|
||||||
|
@ -1056,40 +1060,44 @@ bool FGATC610x::do_radio_switches() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int id_code = xpdr_id_code->getIntValue();
|
if ( xpdr_has_power() ) {
|
||||||
int digit[4];
|
int id_code = xpdr_id_code->getIntValue();
|
||||||
int place = 1000;
|
int digit[4];
|
||||||
for ( i = 0; i < 4; ++i ) {
|
int place = 1000;
|
||||||
digit[i] = id_code / place;
|
for ( i = 0; i < 4; ++i ) {
|
||||||
id_code -= digit[i] * place;
|
digit[i] = id_code / place;
|
||||||
place /= 10;
|
id_code -= digit[i] * place;
|
||||||
}
|
place /= 10;
|
||||||
|
|
||||||
for ( i = 0; i < 4; ++i ) {
|
|
||||||
if ( digit_tuner[i] != last_digit_tuner[i] ) {
|
|
||||||
diff = digit_tuner[i] - last_digit_tuner[i];
|
|
||||||
if ( abs(diff) > 4 ) {
|
|
||||||
// roll over
|
|
||||||
if ( digit_tuner[i] < last_digit_tuner[i] ) {
|
|
||||||
// going up
|
|
||||||
diff = 15 - last_digit_tuner[i] + digit_tuner[i];
|
|
||||||
} else {
|
|
||||||
// going down
|
|
||||||
diff = digit_tuner[i] - 15 - last_digit_tuner[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
digit[i] += diff;
|
|
||||||
}
|
}
|
||||||
while ( digit[i] >= 8 ) { digit[i] -= 8; }
|
|
||||||
while ( digit[i] < 0 ) { digit[i] += 8; }
|
for ( i = 0; i < 4; ++i ) {
|
||||||
|
if ( digit_tuner[i] != last_digit_tuner[i] ) {
|
||||||
|
diff = digit_tuner[i] - last_digit_tuner[i];
|
||||||
|
if ( abs(diff) > 4 ) {
|
||||||
|
// roll over
|
||||||
|
if ( digit_tuner[i] < last_digit_tuner[i] ) {
|
||||||
|
// going up
|
||||||
|
diff = 15 - last_digit_tuner[i] + digit_tuner[i];
|
||||||
|
} else {
|
||||||
|
// going down
|
||||||
|
diff = digit_tuner[i] - 15 - last_digit_tuner[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
digit[i] += diff;
|
||||||
|
}
|
||||||
|
while ( digit[i] >= 8 ) { digit[i] -= 8; }
|
||||||
|
while ( digit[i] < 0 ) { digit[i] += 8; }
|
||||||
|
}
|
||||||
|
|
||||||
|
fgSetInt( "/radios/kt-70/inputs/digit1", digit[0] );
|
||||||
|
fgSetInt( "/radios/kt-70/inputs/digit2", digit[1] );
|
||||||
|
fgSetInt( "/radios/kt-70/inputs/digit3", digit[2] );
|
||||||
|
fgSetInt( "/radios/kt-70/inputs/digit4", digit[3] );
|
||||||
|
}
|
||||||
|
for ( i = 0; i < 4; ++i ) {
|
||||||
last_digit_tuner[i] = digit_tuner[i];
|
last_digit_tuner[i] = digit_tuner[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
fgSetInt( "/radios/kt-70/inputs/digit1", digit[0] );
|
|
||||||
fgSetInt( "/radios/kt-70/inputs/digit2", digit[1] );
|
|
||||||
fgSetInt( "/radios/kt-70/inputs/digit3", digit[2] );
|
|
||||||
fgSetInt( "/radios/kt-70/inputs/digit4", digit[3] );
|
|
||||||
|
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
for ( i = 0; i < 5; ++i ) {
|
for ( i = 0; i < 5; ++i ) {
|
||||||
if ( radio_switch_data[27] >> i & 0x01 ) {
|
if ( radio_switch_data[27] >> i & 0x01 ) {
|
||||||
|
@ -1307,7 +1315,7 @@ bool FGATC610x::do_radio_display() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ADF standby frequency / timer
|
// ADF standby frequency / timer
|
||||||
if ( adf_power->getBoolValue() ) {
|
if ( adf_has_power() ) {
|
||||||
if ( adf_stby_mode->getIntValue() == 0 ) {
|
if ( adf_stby_mode->getIntValue() == 0 ) {
|
||||||
// frequency
|
// frequency
|
||||||
float adf_stby = adf_stby_freq->getFloatValue();
|
float adf_stby = adf_stby_freq->getFloatValue();
|
||||||
|
@ -1388,40 +1396,42 @@ bool FGATC610x::do_radio_display() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transponder code and flight level
|
// Transponder code and flight level
|
||||||
if ( xpdr_func_knob->getIntValue() == 2 ) {
|
if ( xpdr_has_power() ) {
|
||||||
// test mode
|
if ( xpdr_func_knob->getIntValue() == 2 ) {
|
||||||
radio_display_data[36] = 8 << 4 | 8;
|
// test mode
|
||||||
radio_display_data[37] = 8 << 4 | 8;
|
radio_display_data[36] = 8 << 4 | 8;
|
||||||
radio_display_data[38] = 0xff;
|
radio_display_data[37] = 8 << 4 | 8;
|
||||||
radio_display_data[39] = 8 << 4 | 0x0f;
|
radio_display_data[38] = 0xff;
|
||||||
radio_display_data[40] = 8 << 4 | 8;
|
radio_display_data[39] = 8 << 4 | 0x0f;
|
||||||
} else if ( xpdr_func_knob->getIntValue() > 0 ) {
|
radio_display_data[40] = 8 << 4 | 8;
|
||||||
// other on modes
|
|
||||||
int id_code = xpdr_id_code->getIntValue();
|
|
||||||
int place = 1000;
|
|
||||||
for ( i = 0; i < 4; ++i ) {
|
|
||||||
digits[i] = id_code / place;
|
|
||||||
id_code -= digits[i] * place;
|
|
||||||
place /= 10;
|
|
||||||
}
|
|
||||||
radio_display_data[36] = digits[2] << 4 | digits[3];
|
|
||||||
radio_display_data[37] = digits[0] << 4 | digits[1];
|
|
||||||
radio_display_data[38] = 0xff;
|
|
||||||
|
|
||||||
if ( xpdr_func_knob->getIntValue() == 3 ||
|
|
||||||
xpdr_func_knob->getIntValue() == 5 )
|
|
||||||
{
|
|
||||||
// do flight level display
|
|
||||||
snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
|
|
||||||
for ( i = 0; i < 6; ++i ) {
|
|
||||||
digits[i] -= '0';
|
|
||||||
}
|
|
||||||
radio_display_data[39] = digits[2] << 4 | 0x0f;
|
|
||||||
radio_display_data[40] = digits[0] << 4 | digits[1];
|
|
||||||
} else {
|
} else {
|
||||||
// blank flight level display
|
// other on modes
|
||||||
radio_display_data[39] = 0xff;
|
int id_code = xpdr_id_code->getIntValue();
|
||||||
radio_display_data[40] = 0xff;
|
int place = 1000;
|
||||||
|
for ( i = 0; i < 4; ++i ) {
|
||||||
|
digits[i] = id_code / place;
|
||||||
|
id_code -= digits[i] * place;
|
||||||
|
place /= 10;
|
||||||
|
}
|
||||||
|
radio_display_data[36] = digits[2] << 4 | digits[3];
|
||||||
|
radio_display_data[37] = digits[0] << 4 | digits[1];
|
||||||
|
radio_display_data[38] = 0xff;
|
||||||
|
|
||||||
|
if ( xpdr_func_knob->getIntValue() == 3 ||
|
||||||
|
xpdr_func_knob->getIntValue() == 5 )
|
||||||
|
{
|
||||||
|
// do flight level display
|
||||||
|
snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
|
||||||
|
for ( i = 0; i < 6; ++i ) {
|
||||||
|
digits[i] -= '0';
|
||||||
|
}
|
||||||
|
radio_display_data[39] = digits[2] << 4 | 0x0f;
|
||||||
|
radio_display_data[40] = digits[0] << 4 | digits[1];
|
||||||
|
} else {
|
||||||
|
// blank flight level display
|
||||||
|
radio_display_data[39] = 0xff;
|
||||||
|
radio_display_data[40] = 0xff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// off
|
// off
|
||||||
|
|
|
@ -71,7 +71,7 @@ class FGATC610x : public FGProtocol {
|
||||||
|
|
||||||
float compass_position;
|
float compass_position;
|
||||||
|
|
||||||
SGPropertyNode *dme_bus_power;
|
SGPropertyNode *adf_bus_power, *dme_bus_power, *xpdr_bus_power;
|
||||||
SGPropertyNode *navcom1_bus_power, *navcom2_bus_power;
|
SGPropertyNode *navcom1_bus_power, *navcom2_bus_power;
|
||||||
|
|
||||||
SGPropertyNode *mag_compass;
|
SGPropertyNode *mag_compass;
|
||||||
|
@ -82,7 +82,7 @@ class FGATC610x : public FGProtocol {
|
||||||
SGPropertyNode *nav1_freq, *nav1_stby_freq;
|
SGPropertyNode *nav1_freq, *nav1_stby_freq;
|
||||||
SGPropertyNode *nav2_freq, *nav2_stby_freq;
|
SGPropertyNode *nav2_freq, *nav2_stby_freq;
|
||||||
SGPropertyNode *adf_adf_btn, *adf_bfo_btn;
|
SGPropertyNode *adf_adf_btn, *adf_bfo_btn;
|
||||||
SGPropertyNode *adf_power, *adf_vol;
|
SGPropertyNode *adf_power_btn, *adf_vol;
|
||||||
SGPropertyNode *adf_freq, *adf_stby_freq;
|
SGPropertyNode *adf_freq, *adf_stby_freq;
|
||||||
SGPropertyNode *adf_stby_mode, *adf_timer_mode;
|
SGPropertyNode *adf_stby_mode, *adf_timer_mode;
|
||||||
SGPropertyNode *adf_count_mode, *adf_flight_timer, *adf_elapsed_timer;
|
SGPropertyNode *adf_count_mode, *adf_flight_timer, *adf_elapsed_timer;
|
||||||
|
@ -115,6 +115,10 @@ class FGATC610x : public FGProtocol {
|
||||||
bool do_switches();
|
bool do_switches();
|
||||||
|
|
||||||
// convenience
|
// convenience
|
||||||
|
inline bool adf_has_power() const {
|
||||||
|
return (adf_bus_power->getDoubleValue() > 1.0)
|
||||||
|
&& adf_power_btn->getBoolValue();
|
||||||
|
}
|
||||||
inline bool dme_has_power() const {
|
inline bool dme_has_power() const {
|
||||||
return (dme_bus_power->getDoubleValue() > 1.0)
|
return (dme_bus_power->getDoubleValue() > 1.0)
|
||||||
&& dme_switch;
|
&& dme_switch;
|
||||||
|
@ -127,6 +131,10 @@ class FGATC610x : public FGProtocol {
|
||||||
return (navcom2_bus_power->getDoubleValue() > 1.0)
|
return (navcom2_bus_power->getDoubleValue() > 1.0)
|
||||||
&& navcom2_power_btn->getBoolValue();
|
&& navcom2_power_btn->getBoolValue();
|
||||||
}
|
}
|
||||||
|
inline bool xpdr_has_power() const {
|
||||||
|
return (xpdr_bus_power->getDoubleValue() > 1.0)
|
||||||
|
&& (xpdr_func_knob->getIntValue() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue