88using Meshtastic . Extensions ;
99using Meshtastic . Protobufs ;
1010using QRCoder ;
11- using Spectre . Console ;
1211using System . Diagnostics . CodeAnalysis ;
13- using System . Linq ;
1412
1513namespace Meshtastic . Display ;
1614
@@ -38,41 +36,55 @@ public void Print()
3836 grid . AddRow ( PrintConfig ( container . LocalConfig , "[bold]Config[/]" ) ,
3937 PrintConfig ( container . LocalModuleConfig , "[bold]Module Config[/]" ) ) ;
4038 AnsiConsole . Write ( grid ) ;
41- AnsiConsole . Write ( PrintNodeInfos ( container . Nodes ) ) ;
39+ AnsiConsole . Write ( PrintNodeInfos ( ) ) ;
4240 }
4341 }
4442
45- public Tree PrintNodeInfos ( List < NodeInfo > nodeInfos )
43+ public Tree PrintNodeInfos ( )
4644 {
4745 var root = new Tree ( "[bold]Nodes[/]" )
4846 {
4947 Style = new Style ( StyleResources . MESHTASTIC_GREEN )
5048 } ;
51- root . AddNode ( PrintNodesTable ( nodeInfos ) ) ;
49+ root . AddNode ( PrintNodesTable ( ) ) ;
5250 return root ;
5351 }
5452
55- private Table PrintNodesTable ( List < NodeInfo > nodeInfos )
53+ public Table PrintNodesTable ( bool compactTable = false )
5654 {
5755 var table = new Table ( ) ;
5856 table . Expand ( ) ;
57+ table . Border ( TableBorder . Rounded ) ;
5958 table . BorderColor ( StyleResources . MESHTASTIC_GREEN ) ;
60- table . RoundedBorder ( ) ;
61- table . AddColumns ( "ID#" , "Name" , "Latitude" , "Longitude" ,
62- "Battery" , "Air Util" ,
63- "Ch. Util" , "SNR" , "Last Heard" ) ;
59+ table . Centered ( ) ;
60+ if ( compactTable )
61+ table . AddColumns ( "Name" , "Latitude" , "Longitude" , "Battery" , "SNR" , "Last Heard" ) ;
62+ else
63+ table . AddColumns ( "ID#" , "Name" , "Latitude" , "Longitude" , "Battery" , "Air Util" , "Ch. Util" , "SNR" , "Last Heard" ) ;
6464
65- foreach ( var node in nodeInfos )
65+ foreach ( var node in container . Nodes )
6666 {
67- table . AddRow ( node . Num . ToString ( ) ,
68- container . GetNodeDisplayName ( node . Num ) ,
69- ( node . Position ? . LatitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
70- ( node . Position ? . LongitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
71- $ "{ node . DeviceMetrics ? . BatteryLevel } %",
72- $ "{ node . DeviceMetrics ? . AirUtilTx . ToString ( "N2" ) } %" ?? String . Empty ,
73- $ "{ node . DeviceMetrics ? . ChannelUtilization . ToString ( "N2" ) } %" ?? String . Empty ,
74- node . Snr . ToString ( ) ,
75- DisplayRelativeTime ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) . AddSeconds ( node . LastHeard ) ) ) ;
67+ if ( compactTable )
68+ {
69+ table . AddRow ( container . GetNodeDisplayName ( node . Num ) ,
70+ ( node . Position ? . LatitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
71+ ( node . Position ? . LongitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
72+ $ "{ node . DeviceMetrics ? . BatteryLevel } %",
73+ node . Snr . ToString ( ) ,
74+ DisplayRelativeTime ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) . AddSeconds ( node . LastHeard ) ) ) ;
75+ }
76+ else
77+ {
78+ table . AddRow ( node . Num . ToString ( ) ,
79+ container . GetNodeDisplayName ( node . Num ) ,
80+ ( node . Position ? . LatitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
81+ ( node . Position ? . LongitudeI * 1e-7 ?? 0 ) . ToString ( "N6" ) ?? String . Empty ,
82+ $ "{ node . DeviceMetrics ? . BatteryLevel } %",
83+ $ "{ node . DeviceMetrics ? . AirUtilTx . ToString ( "N2" ) } %" ?? String . Empty ,
84+ $ "{ node . DeviceMetrics ? . ChannelUtilization . ToString ( "N2" ) } %" ?? String . Empty ,
85+ node . Snr . ToString ( ) ,
86+ DisplayRelativeTime ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) . AddSeconds ( node . LastHeard ) ) ) ;
87+ }
7688 }
7789 return table ;
7890 }
@@ -292,19 +304,22 @@ public void PrintRoute(RepeatedField<uint> route)
292304 }
293305 public BarChart PrintTrafficChart ( )
294306 {
307+ var myInfo = container . Nodes . FirstOrDefault ( n => n . Num == container . MyNodeInfo . MyNodeNum ) ;
308+ var airTimeStats = myInfo != null ? $ "(Ch. Util { myInfo . DeviceMetrics . ChannelUtilization : N2} % / Airtime { myInfo . DeviceMetrics . AirUtilTx : N2} %)" : String . Empty ;
309+
295310 return new BarChart ( )
296- . Label ( "[green bold underline]Mesh traffic by port [/]" )
311+ . Label ( $ "[green bold underline]Mesh traffic by Port { airTimeStats } [/]")
297312 . CenterLabel ( )
298313 . AddItem ( "Admin" , GetMessageCountByPortNum ( PortNum . AdminApp ) , Color . Red )
299314 . AddItem ( "Text" , GetMessageCountByPortNum ( PortNum . TextMessageApp ) + GetMessageCountByPortNum ( PortNum . TextMessageCompressedApp ) , Color . Yellow )
300315 . AddItem ( "Position" , GetMessageCountByPortNum ( PortNum . PositionApp ) , Color . Green )
301316 . AddItem ( "Waypoint" , GetMessageCountByPortNum ( PortNum . WaypointApp ) , Color . Pink1 )
302317 . AddItem ( "NodeInfo" , GetMessageCountByPortNum ( PortNum . NodeinfoApp ) , Color . White )
303- . AddItem ( "Telemetry" , GetMessageCountByPortNum ( PortNum . TelemetryApp ) , Color . Blue ) ;
318+ . AddItem ( "Telemetry" , GetMessageCountByPortNum ( PortNum . TelemetryApp , ignoreLocal : true ) , Color . Blue ) ;
304319 }
305320
306- private int GetMessageCountByPortNum ( PortNum portNum )
321+ private int GetMessageCountByPortNum ( PortNum portNum , bool ignoreLocal = false )
307322 {
308- return container . FromRadioMessageLog . Count ( fr => fr . Packet ? . Decoded ? . Portnum == portNum ) ;
323+ return container . FromRadioMessageLog . Count ( fr => fr . Packet ? . Decoded ? . Portnum == portNum && ( ! ignoreLocal || fr . Packet ? . From == container . MyNodeInfo . MyNodeNum ) ) ;
309324 }
310325}
0 commit comments