Esempio n. 1
0
 private void IdentButtonOnClick(object sender, RoutedEventArgs e)
 {
     if (TransponderHelper.ToggleIdent())
     {
         RepaintTransponderStatus();
     }
 }
Esempio n. 2
0
 private void Mode4ButtonOnClick(object sender, RoutedEventArgs e)
 {
     if (TransponderHelper.Mode4Toggle())
     {
         RepaintTransponderStatus();
     }
 }
Esempio n. 3
0
        private bool CanInteract()
        {
            var trans = TransponderHelper.GetTransponder();

            if ((trans == null) || trans.control != Common.DCSState.Transponder.IFFControlMode.OVERLAY)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        private void TransponderPowerClick(object sender, MouseButtonEventArgs e)
        {
            if (!CanInteract())
            {
                return;
            }

            if (TransponderHelper.TogglePower())
            {
                RepaintTransponderStatus();
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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 ");
                }
            });
        }
Esempio n. 7
0
        public void StartDetectPtt(DetectPttCallback callback)
        {
            _detectPtt = true;
            //detect the state of all current buttons
            var pttInputThread = new Thread(() =>
            {
                while (_detectPtt)
                {
                    var bindStates = GenerateBindStateList();

                    for (var i = 0; i < bindStates.Count; i++)
                    {
                        //contains main binding and optional modifier binding + states of each
                        var bindState = bindStates[i];

                        bindState.MainDeviceState = GetButtonState(bindState.MainDevice);

                        if (bindState.ModifierDevice != null)
                        {
                            bindState.ModifierState = GetButtonState(bindState.ModifierDevice);

                            bindState.IsActive = bindState.MainDeviceState && bindState.ModifierState;
                        }
                        else
                        {
                            bindState.IsActive = bindState.MainDeviceState;
                        }

                        //now check this is the best binding and no previous ones are better
                        //Means you can have better binds like PTT  = Space and Radio 1 is Space +1 - holding space +1 will actually trigger radio 1 not PTT
                        if (bindState.IsActive)
                        {
                            for (int j = 0; j < i; j++)
                            {
                                //check previous bindings
                                var previousBind = bindStates[j];

                                if (!previousBind.IsActive)
                                {
                                    continue;
                                }

                                if (previousBind.ModifierDevice == null && bindState.ModifierDevice != null)
                                {
                                    //set previous bind to off if previous bind Main == main or modifier of bindstate
                                    if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        previousBind.IsActive = false;
                                        break;
                                    }
                                    if (previousBind.MainDevice.IsSameBind(bindState.ModifierDevice))
                                    {
                                        previousBind.IsActive = false;
                                        break;
                                    }
                                }
                                else if (previousBind.ModifierDevice != null && bindState.ModifierDevice == null)
                                {
                                    if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        bindState.IsActive = false;
                                        break;
                                    }
                                    if (previousBind.ModifierDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        bindState.IsActive = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    callback(bindStates);
                    //handle overlay

                    foreach (var bindState in bindStates)
                    {
                        if (bindState.IsActive && bindState.MainDevice.InputBind == InputBinding.OverlayToggle)
                        {
                            //run on main
                            Application.Current.Dispatcher.Invoke(
                                () => { _toggleOverlayCallback(false); });
                            break;
                        }
                        else if ((int)bindState.MainDevice.InputBind >= (int)InputBinding.Up100 &&
                                 (int)bindState.MainDevice.InputBind <= (int)InputBinding.RadioVolumeDown)
                        {
                            if (bindState.MainDevice.InputBind == _lastActiveBinding && !bindState.IsActive)
                            {
                                //Assign to a totally different binding to mark as unassign
                                _lastActiveBinding = InputBinding.ModifierIntercom;
                            }

                            //key repeat
                            if (bindState.IsActive && (bindState.MainDevice.InputBind != _lastActiveBinding))
                            {
                                _lastActiveBinding = bindState.MainDevice.InputBind;

                                var dcsPlayerRadioInfo = ClientStateSingleton.Instance.DcsPlayerRadioInfo;

                                if (dcsPlayerRadioInfo != null && dcsPlayerRadioInfo.IsCurrent())
                                {
                                    switch (bindState.MainDevice.InputBind)
                                    {
                                    case InputBinding.Up100:
                                        RadioHelper.UpdateRadioFrequency(100, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up10:
                                        RadioHelper.UpdateRadioFrequency(10, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up1:
                                        RadioHelper.UpdateRadioFrequency(1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up01:
                                        RadioHelper.UpdateRadioFrequency(0.1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up001:
                                        RadioHelper.UpdateRadioFrequency(0.01, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up0001:
                                        RadioHelper.UpdateRadioFrequency(0.001, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down100:
                                        RadioHelper.UpdateRadioFrequency(-100, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down10:
                                        RadioHelper.UpdateRadioFrequency(-10, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down1:
                                        RadioHelper.UpdateRadioFrequency(-1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down01:
                                        RadioHelper.UpdateRadioFrequency(-0.1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down001:
                                        RadioHelper.UpdateRadioFrequency(-0.01, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down0001:
                                        RadioHelper.UpdateRadioFrequency(-0.001, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.ToggleGuard:
                                        RadioHelper.ToggleGuard(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.ToggleEncryption:
                                        RadioHelper.ToggleEncryption(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.NextRadio:
                                        RadioHelper.SelectNextRadio();
                                        break;

                                    case InputBinding.PreviousRadio:
                                        RadioHelper.SelectPreviousRadio();
                                        break;

                                    case InputBinding.EncryptionKeyIncrease:
                                        RadioHelper.IncreaseEncryptionKey(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.EncryptionKeyDecrease:
                                        RadioHelper.DecreaseEncryptionKey(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.RadioChannelUp:
                                        RadioHelper.RadioChannelUp(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.RadioChannelDown:
                                        RadioHelper.RadioChannelDown(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.TransponderIDENT:
                                        TransponderHelper.ToggleIdent();
                                        break;

                                    case InputBinding.RadioVolumeUp:
                                        RadioHelper.RadioVolumeUp(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.RadioVolumeDown:
                                        RadioHelper.RadioVolumeDown(dcsPlayerRadioInfo.selected);
                                        break;


                                    default:
                                        break;
                                    }
                                }


                                break;
                            }
                        }
                    }

                    Thread.Sleep(40);
                }
            });

            pttInputThread.Start();
        }