From 1c96176a5657465e5157f414955660d90f5adec1 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Thu, 24 Sep 2020 21:46:08 -0700 Subject: [PATCH] Improve multi-band handling of SNRs --- src/SampleApp.WinDesktop/SatelliteSnr.xaml | 19 +----------- src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs | 31 ++++++++++++++----- .../SatelliteView.xaml.cs | 17 ++++++++-- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml b/src/SampleApp.WinDesktop/SatelliteSnr.xaml index 37ed6cc..5d40ff3 100644 --- a/src/SampleApp.WinDesktop/SatelliteSnr.xaml +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml @@ -57,24 +57,7 @@ VerticalAlignment="Bottom"> - - - - - - - - - - - - - - - - - - + diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs index 24f93e4..5a1e761 100644 --- a/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs @@ -41,8 +41,24 @@ namespace SampleApp.WinDesktop private void UpdateSatellites() { - satellites.ItemsSource = messages.Values.SelectMany(g => g.SVs).OrderBy(s=>s.GnssSignalId).OrderBy(s => s.Id).OrderByDescending(s => s.TalkerId); - } + //satellites.ItemsSource = messages.Values.SelectMany(g => g.SVs).OrderBy(s=>s.GnssSignalId).OrderBy(s => s.Id).OrderByDescending(s => s.TalkerId); + var sats = messages.Values.SelectMany(g => g.SVs).GroupBy(s => s.TalkerId.ToString() + s.Id); + var infos = sats.Select(s => new SatelliteInfo() + { + Id = s.First().Id, + TalkerId = s.First().TalkerId, + SNRs = new Dictionary(s.Select(s => new KeyValuePair(s.GnssSignalId, s.SignalToNoiseRatio)), null) + }); + satellites.ItemsSource = infos; + } + + public struct SatelliteInfo + { + public int Id; + public Talker TalkerId; + public Dictionary SNRs; + public int SignalToNoiseRatio => SNRs.Max(s=>s.Value); + } internal static string SignalIdToName(char signalId, Talker talkerId) { @@ -139,7 +155,7 @@ namespace SampleApp.WinDesktop { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if(value is SatelliteVehicle sv) + if(value is SatelliteSnr.SatelliteInfo sv) { if (parameter as string == "Name") { @@ -156,10 +172,11 @@ namespace SampleApp.WinDesktop name = "NavIC IRNSS"; else name = sv.TalkerId.ToString(); - var signalName = SatelliteSnr.SignalIdToName(sv.GnssSignalId, sv.TalkerId); - if (!string.IsNullOrEmpty(signalName)) - name += " (" + signalName + ")"; - return name; + var snrs = string.Join("\n", sv.SNRs.Select(snr => SatelliteSnr.SignalIdToName(snr.Key, sv.TalkerId) + ": " + snr.Value + "dB")); + if (!string.IsNullOrEmpty(snrs)) + name += $"\n{snrs}"; + + return name; } else return Math.Max(10, sv.SignalToNoiseRatio * 2); diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs index 7803d2f..450ddcf 100644 --- a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; @@ -98,10 +99,22 @@ namespace SampleApp.WinDesktop { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + Talker? talker = null; + int snr = 0; if (value is SatelliteVehicle sv) { - byte alpha = (byte)(sv.SignalToNoiseRatio <= 0 ? 80 : 255); - switch (sv.TalkerId) + talker = sv.TalkerId; + snr = sv.SignalToNoiseRatio; + } + else if (value is SatelliteSnr.SatelliteInfo info) + { + talker = info.TalkerId; + snr = info.SignalToNoiseRatio; + } + if(talker != null) + { + byte alpha = (byte)(snr <= 0 ? 80 : 255); + switch (talker) { case Talker.GlobalPositioningSystem: return Color.FromArgb(alpha, 255, 0, 0); case Talker.GalileoPositioningSystem: return Color.FromArgb(alpha, 0, 255, 0);