示例#1
0
        private void Mode1OnLostFocus(object sender, RoutedEventArgs routedEventArgs)
        {
            if (!CanInteract())
            {
                return;
            }

            int mode1 = 0;

            if (int.TryParse(Mode1.Text.Replace(',', '.').Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out mode1))
            {
                TransponderHelper.SetMode1(mode1);
            }
            else
            {
                Mode1.Text = "--";
                TransponderHelper.SetMode1(-1);
            }
        }
示例#2
0
        private void StartUDPCommandListener()
        {
            Task.Factory.StartNew(() =>
            {
                while (!_stop)
                {
                    var localEp = new IPEndPoint(IPAddress.Any, _globalSettings.GetNetworkSetting(GlobalSettingsKeys.CommandListenerUDP));
                    try
                    {
                        _udpCommandListener = new UdpClient(localEp);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn(ex, $"Unable to bind to the UDP Command Listener Socket Port: {localEp.Port}");
                        Thread.Sleep(500);
                    }
                }

                while (!_stop)
                {
                    try
                    {
                        var groupEp = new IPEndPoint(IPAddress.Any, 0);
                        var bytes   = _udpCommandListener.Receive(ref groupEp);

                        //Logger.Info("Recevied Message from UDP COMMAND INTERFACE: "+ Encoding.UTF8.GetString(
                        //          bytes, 0, bytes.Length));
                        var message =
                            JsonConvert.DeserializeObject <UDPInterfaceCommand>(Encoding.UTF8.GetString(
                                                                                    bytes, 0, bytes.Length));

                        if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_DELTA)
                        {
                            RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.FREQUENCY_SET)
                        {
                            RadioHelper.UpdateRadioFrequency(message.Frequency, message.RadioId, false, true);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.ACTIVE_RADIO)
                        {
                            RadioHelper.SelectRadio(message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TOGGLE_GUARD)
                        {
                            RadioHelper.ToggleGuard(message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.GUARD)
                        {
                            RadioHelper.SetGuard(message.RadioId, message.Enabled);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_UP)
                        {
                            RadioHelper.RadioChannelUp(message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.CHANNEL_DOWN)
                        {
                            RadioHelper.RadioChannelDown(message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.SET_VOLUME)
                        {
                            RadioHelper.SetRadioVolume(message.Volume, message.RadioId);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_POWER)
                        {
                            TransponderHelper.SetPower(message.Enabled);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M1_CODE)
                        {
                            TransponderHelper.SetMode1(message.Code);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M3_CODE)
                        {
                            TransponderHelper.SetMode3(message.Code);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_M4)
                        {
                            TransponderHelper.SetMode4(message.Enabled);
                        }
                        else if (message?.Command == UDPInterfaceCommand.UDPCommandType.TRANSPONDER_IDENT)
                        {
                            TransponderHelper.SetIdent(message.Enabled);
                        }
                        else
                        {
                            Logger.Error("Unknown UDP Command!");
                        }
                    }
                    catch (SocketException e)
                    {
                        // SocketException is raised when closing app/disconnecting, ignore so we don't log "irrelevant" exceptions
                        if (!_stop)
                        {
                            Logger.Error(e, "SocketException Handling DCS  Message");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e, "Exception Handling DCS  Message");
                    }
                }

                try
                {
                    _udpCommandListener.Close();
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Exception stoping DCS listener ");
                }
            });
        }