Skip to content

Commit 1f72045

Browse files
committed
WIP live dashboard continued
1 parent a32fb40 commit 1f72045

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

Meshtastic.Cli/CommandHandlers/LiveCommandHandler.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override async Task OnCompleted(FromRadio packet, DeviceStateContainer co
2424
{
2525
var layout = new Layout("Root")
2626
.SplitColumns(
27-
new Layout("Left"),
27+
new Layout("Messages"),
2828
new Layout("Right")
2929
.SplitRows(
3030
new Layout("Nodes"),
@@ -33,15 +33,24 @@ public override async Task OnCompleted(FromRadio packet, DeviceStateContainer co
3333
await AnsiConsole.Live(layout)
3434
.StartAsync(async ctx =>
3535
{
36+
var printer = new ProtobufPrinter(container, OutputFormat);
37+
UpdateDashboard(layout, printer);
38+
3639
await Connection.ReadFromRadio((fromRadio, container) =>
3740
{
38-
var printer = new ProtobufPrinter(container, OutputFormat);
39-
layout["Nodes"].Update(printer.PrintNodesTable(compactTable: true));
40-
layout["Traffic"].Update(printer.PrintTrafficChart());
41-
ctx.Refresh();
41+
printer = new ProtobufPrinter(container, OutputFormat);
42+
UpdateDashboard(layout, printer);
4243

44+
ctx.Refresh();
4345
return Task.FromResult(false);
4446
});
4547
});
4648
}
49+
50+
private static void UpdateDashboard(Layout layout, ProtobufPrinter printer)
51+
{
52+
layout["Nodes"].Update(printer.PrintNodesTable(compactTable: true));
53+
layout["Traffic"].Update(printer.PrintTrafficChart());
54+
layout["Messages"].Update(printer.PrintMessagesPanel());
55+
}
4756
}

Meshtastic.Cli/Display/ProtobufPrinter.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Meshtastic.Extensions;
99
using Meshtastic.Protobufs;
1010
using QRCoder;
11+
using Spectre.Console.Rendering;
1112
using System.Diagnostics.CodeAnalysis;
1213

1314
namespace Meshtastic.Display;
@@ -66,7 +67,7 @@ public Table PrintNodesTable(bool compactTable = false)
6667
{
6768
if (compactTable)
6869
{
69-
table.AddRow(container.GetNodeDisplayName(node.Num),
70+
table.AddRow(container.GetNodeDisplayName(node.Num, hideNodeNum: true),
7071
(node.Position?.LatitudeI * 1e-7 ?? 0).ToString("N6") ?? String.Empty,
7172
(node.Position?.LongitudeI * 1e-7 ?? 0).ToString("N6") ?? String.Empty,
7273
$"{node.DeviceMetrics?.BatteryLevel}%",
@@ -318,6 +319,43 @@ public BarChart PrintTrafficChart()
318319
.AddItem("Telemetry", GetMessageCountByPortNum(PortNum.TelemetryApp, ignoreLocal: true), Color.Blue);
319320
}
320321

322+
public Panel PrintMessagesPanel()
323+
{
324+
var texts = container.FromRadioMessageLog
325+
.Where(fr => fr.Packet?.Decoded?.Portnum == PortNum.TextMessageApp || fr.Packet?.Decoded?.Portnum == PortNum.TextMessageCompressedApp)
326+
.Select(fr => new
327+
{
328+
from = $"[green bold underline]{container.GetNodeDisplayName(fr.Packet.From, hideNodeNum: true)}[/]",
329+
message = fr.Packet?.Decoded?.Payload.ToStringUtf8()
330+
})
331+
.SelectMany(text =>
332+
{
333+
return new List<IRenderable>() {
334+
new Rule(text.from),
335+
new Text(text.message!)
336+
};
337+
});
338+
339+
340+
if (!texts.Any())
341+
{
342+
return new Panel("Messages")
343+
{
344+
Expand = true,
345+
BorderStyle = new Style(StyleResources.MESHTASTIC_GREEN)
346+
};
347+
}
348+
349+
var messages = new Rows(texts);
350+
var panel = new Panel(messages)
351+
{
352+
Header = new PanelHeader("Messages"),
353+
Expand = true,
354+
BorderStyle = new Style(StyleResources.MESHTASTIC_GREEN)
355+
};
356+
return panel;
357+
}
358+
321359
private int GetMessageCountByPortNum(PortNum portNum, bool ignoreLocal = false)
322360
{
323361
return container.FromRadioMessageLog.Count(fr => fr.Packet?.Decoded?.Portnum == portNum && (!ignoreLocal || fr.Packet?.From == container.MyNodeInfo.MyNodeNum));

Meshtastic/Data/DeviceStateContainer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public uint GetHopLimitOrDefault()
7979
return (uint)(this.LocalConfig.Lora.HopLimit > 0 ? this.LocalConfig.Lora.HopLimit : 3);
8080
}
8181

82-
public string GetNodeDisplayName(uint nodeNum, bool shortName = false)
82+
public string GetNodeDisplayName(uint nodeNum, bool shortName = false, bool hideNodeNum = false)
8383
{
8484
var node = this.Nodes.Find(n => n.Num == nodeNum);
8585
if (node == null)
@@ -88,6 +88,9 @@ public string GetNodeDisplayName(uint nodeNum, bool shortName = false)
8888
if (shortName)
8989
return node.User.ShortName;
9090

91+
if (hideNodeNum)
92+
return $"{node.User.LongName} ({node.User.ShortName})";
93+
9194
return $"{node.User.LongName} ({node.User.ShortName}) - {node.Num}";
9295
}
9396
}

0 commit comments

Comments
 (0)