Fix macOS Bluetooth state and add RTK debug console
This commit is contained in:
@@ -9,6 +9,7 @@ namespace FieldLogger.ViewModels;
|
||||
public sealed partial class DebugViewModel : ObservableObject
|
||||
{
|
||||
private readonly UmReceiverService _receiver;
|
||||
private readonly MaglinkService _gps;
|
||||
private readonly DeviceConnectionManager _manager;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -46,32 +47,35 @@ public sealed partial class DebugViewModel : ObservableObject
|
||||
{
|
||||
_receiver = receiver;
|
||||
_manager = manager;
|
||||
_gps = manager.Gps;
|
||||
}
|
||||
|
||||
public void OnAppearing()
|
||||
{
|
||||
_receiver.LineReceived += OnLineReceived;
|
||||
_receiver.LineReceived += OnUmLineReceived;
|
||||
_gps.LineReceived += OnGpsLineReceived;
|
||||
UpdateConnectionStatus();
|
||||
}
|
||||
|
||||
public void OnDisappearing()
|
||||
{
|
||||
_receiver.LineReceived -= OnLineReceived;
|
||||
_receiver.LineReceived -= OnUmLineReceived;
|
||||
_gps.LineReceived -= OnGpsLineReceived;
|
||||
}
|
||||
|
||||
private void UpdateConnectionStatus()
|
||||
{
|
||||
IsConnected = _receiver.IsConnected;
|
||||
if (IsConnected)
|
||||
{
|
||||
ConnectionStatus = $"Connected to {_receiver.DeviceName ?? "receiver"}";
|
||||
ConnectionStateColor = "Green";
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectionStatus = "Not connected";
|
||||
ConnectionStateColor = "Gray";
|
||||
}
|
||||
var connections = new List<string>();
|
||||
if (_receiver.IsConnected)
|
||||
connections.Add($"Locator: {_receiver.DeviceName ?? "receiver"}");
|
||||
if (_gps.IsConnected)
|
||||
connections.Add($"RTK: {_gps.DeviceName ?? "receiver"}");
|
||||
|
||||
ConnectionStatus = connections.Count > 0
|
||||
? string.Join(" · ", connections)
|
||||
: "No devices connected";
|
||||
ConnectionStateColor = connections.Count > 0 ? "Green" : "Gray";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -133,16 +137,29 @@ public sealed partial class DebugViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLineReceived(object? sender, string line)
|
||||
private void OnUmLineReceived(object? sender, string line) => AddReceivedLine(line, false);
|
||||
|
||||
private void OnGpsLineReceived(object? sender, string line) => AddReceivedLine(line, true);
|
||||
|
||||
private void AddReceivedLine(string line, bool isGps)
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
var messageType = ClassifyMessage(line);
|
||||
var messageType = isGps ? ClassifyGpsMessage(line) : ClassifyMessage(line);
|
||||
var parsedData = ParseMessage(line, messageType);
|
||||
AddMessage("RX", line, messageType, parsedData);
|
||||
});
|
||||
}
|
||||
|
||||
private static string ClassifyGpsMessage(string line)
|
||||
{
|
||||
if (line.StartsWith("$GNPOS,", StringComparison.Ordinal))
|
||||
return NmeaSentence.VerifyChecksum(line) ? "GNPOS" : "GNPOS (bad checksum)";
|
||||
if (line.StartsWith("$GNDEV,", StringComparison.Ordinal))
|
||||
return NmeaSentence.VerifyChecksum(line) ? "GNDEV" : "GNDEV (bad checksum)";
|
||||
return line.StartsWith('$') ? "NMEA" : "RTK Text";
|
||||
}
|
||||
|
||||
private void AddMessage(string direction, string rawMessage, string type, string? parsedData = null)
|
||||
{
|
||||
var message = new DebugMessage
|
||||
@@ -212,6 +229,19 @@ public sealed partial class DebugViewModel : ObservableObject
|
||||
return $"Mfr={info.Manufacturer}, Model={info.ModelName}, SN={info.SerialNumber}, FW={info.SoftwareVersion}";
|
||||
}
|
||||
}
|
||||
else if (type == "GNPOS")
|
||||
{
|
||||
var fix = GnssFix.TryParse(line);
|
||||
if (fix is not null)
|
||||
return $"{fix.StatusLabel}, {fix.Latitude:F8}, {fix.Longitude:F8}, " +
|
||||
$"H ±{fix.Hrms:F3}m, V ±{fix.Vrms:F3}m, {fix.SatellitesUsed} sats";
|
||||
}
|
||||
else if (type == "GNDEV")
|
||||
{
|
||||
var info = GnssDeviceInfo.TryParse(line);
|
||||
if (info is not null)
|
||||
return $"SN={info.SerialNumber}, PCB={info.PcbVersion}, FW={info.FirmwareVersion}";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -239,6 +269,11 @@ public sealed partial class DebugViewModel : ObservableObject
|
||||
"UMLOG (Button)" => "Blue",
|
||||
"UMLOG (Timed)" => "DodgerBlue",
|
||||
"UMDEV" => "Purple",
|
||||
"GNPOS" => "ForestGreen",
|
||||
"GNDEV" => "DarkViolet",
|
||||
_ when type.Contains("bad checksum", StringComparison.Ordinal) => "Red",
|
||||
"NMEA" => "Teal",
|
||||
"RTK Text" => "DarkOrange",
|
||||
"Command" => "Orange",
|
||||
_ when type.StartsWith("UMLOG") => "Blue",
|
||||
_ => "Gray"
|
||||
|
||||
Reference in New Issue
Block a user