+/*
+ * Listener callback. Maintains channel input properties,
+ * searches new channel frequency, updates _channel and
+ * _frequency and sets boolean _new_frequency appropriately.
+ */
+void
+TACAN::valueChanged(SGPropertyNode *prop)
+{
+ if (_listener_active)
+ return;
+ _listener_active++;
+
+ int index = prop->getIndex();
+ string channel = _channel;
+
+ if (index) { // channel digit or X/Y input
+ int c;
+ if (isdigit(c = _channel_in1_node->getStringValue()[0]))
+ channel[0] = c;
+ if (isdigit(c = _channel_in2_node->getStringValue()[0]))
+ channel[1] = c;
+ if (isdigit(c = _channel_in3_node->getStringValue()[0]))
+ channel[2] = c;
+ c = _channel_in4_node->getStringValue()[0];
+ if (c == 'X' || c == 'Y')
+ channel[3] = c;
+
+ } else { // channel number input
+ unsigned int f = prop->getIntValue();
+ if (f >= 1 && f <= 126) {
+ channel[0] = '0' + (f / 100) % 10;
+ channel[1] = '0' + (f / 10) % 10;
+ channel[2] = '0' + f % 10;
+ }
+ }
+
+ if (channel != _channel) {
+ SG_LOG(SG_INSTR, SG_DEBUG, "new channel " << channel);
+
+ // write back result
+ _channel_in0_node->setIntValue((channel[0] - '0') * 100
+ + (channel[1] - '0') * 10 + (channel[2] - '0'));
+ char s[2] = "0";
+ s[0] = channel[0], _channel_in1_node->setStringValue(s);
+ s[0] = channel[1], _channel_in2_node->setStringValue(s);
+ s[0] = channel[2], _channel_in3_node->setStringValue(s);
+ s[0] = channel[3], _channel_in4_node->setStringValue(s);
+
+ // search channel frequency
+ double freq = searchChannel(channel);
+ if (freq != _frequency_mhz) {
+ SG_LOG(SG_INSTR, SG_DEBUG, "new frequency " << freq);
+ _frequency_node->setDoubleValue(freq);
+ _frequency_mhz = freq;
+ _new_frequency = true;
+ }
+
+ _channel = channel;
+ _time_before_search_sec = 0;
+ }
+
+ _listener_active--;
+}
+