Beispiel #1
0
        public async Task <string> Stop()
        {
            var response = "Skipped Stop";

            if (_shouldStopAndStart)
            {
                response = await SendAsync(RemoteCommand.Create("Exe", "Stop", true));
            }

            ResponseLog.Add(response);

            return(response);
        }
Beispiel #2
0
        public async Task <string> SendAsync(RemoteCommand command)
        {
            var cmd = JsonConvert.SerializeObject(command);

            ResponseLog.Add($"Sending Command: {command.Command} {command.Method} {(command.Value == null ? "": $"with value: {command.Value}")}");

            await _client.WriteLine(cmd);

            var response = await _client.ReadAsync(TimeSpan.FromMilliseconds(_config.TimeoutMs));

            LogResults(response);

            return(response);
        }
Beispiel #3
0
        public async Task <SdrState> CurrentState()
        {
            var gainAudioCommand        = RemoteCommand.Create("Get", "AudioGain");
            var detectorTypeCommand     = RemoteCommand.Create("Get", "DetectorType");
            var filterBandwidthCommand  = RemoteCommand.Create("Get", "FilterBandwidth");
            var squelchEnabledCommand   = RemoteCommand.Create("Get", "SquelchEnabled");
            var SquelchThresholdCommand = RemoteCommand.Create("Get", "SquelchThreshold");
            var fmStereoCommand         = RemoteCommand.Create("Get", "FmStereo");
            var frequencyCommand        = RemoteCommand.Create("Get", "Frequency");

            var gainAudioResponse = await SendAsync(gainAudioCommand);

            gainAudioResponse.TryParseJson <RemoteResult>(out var gainAudioValue);

            var detectorTypeResponse = await SendAsync(detectorTypeCommand);

            detectorTypeResponse.TryParseJson <RemoteResult>(out var detectorTypeValue);

            var filterBandwidthResponse = await SendAsync(filterBandwidthCommand);

            filterBandwidthResponse.TryParseJson <RemoteResult>(out var filterBandwidthValue);

            var squelchEnabledResponse = await SendAsync(squelchEnabledCommand);

            squelchEnabledResponse.TryParseJson <RemoteResult>(out var squelchEnabledValue);

            var SquelchThresholdResponse = await SendAsync(SquelchThresholdCommand);

            SquelchThresholdResponse.TryParseJson <RemoteResult>(out var squelchThresholdValue);

            var fmStereoResponse = await SendAsync(fmStereoCommand);

            fmStereoResponse.TryParseJson <RemoteResult>(out var fmStereoValue);

            var frequencyResponse = await SendAsync(frequencyCommand);

            frequencyResponse.TryParseJson <RemoteResult>(out var frequencyValue);

            return(new SdrState {
                AudioGain = gainAudioValue?.Value?.ToString(),
                DetectorType = detectorTypeValue?.Value?.ToString(),
                FilterBandwidth = filterBandwidthValue?.Value?.ToString(),
                SquelchEnabled = squelchEnabledValue?.Value?.ToString(),
                SquelchThreshold = squelchThresholdValue?.Value?.ToString(),
                FmStereo = fmStereoValue?.Value?.ToString(),
                Frequency = frequencyValue?.Value?.ToString()
            });
        }
Beispiel #4
0
        public async Task <SdrRemote> Execute()
        {
            _shouldStopAndStart = await IsPlaying();

            await Stop();

            while (Commands.Count > 0)
            {
                RemoteCommand command = Commands.Dequeue();
                await SendAsync(command);
            }

            await Start();

            return(this);
        }
Beispiel #5
0
        public async Task <bool> IsPlaying()
        {
            var response = await SendAsync(RemoteCommand.Create("Get", nameof(IsPlaying)));

            //SDR may wite back multiple objects from SDR on new lines, so we have to split and find the correct object
            var responses = response.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string str in responses)
            {
                bool isValidObject = str.TryParseJson <RemoteResult>(out var result);
                if (isValidObject && result.Method == nameof(IsPlaying))
                {
                    return(Convert.ToBoolean(result.Value));
                }
            }
            return(false);
        }
Beispiel #6
0
 public SdrRemote AddCommand(RemoteCommand command)
 {
     Commands.Enqueue(command);
     return(this);
 }
Beispiel #7
0
 public Preset AddCommand(RemoteCommand command)
 {
     Commands.Enqueue(command);
     return(this);
 }