Skip to content

Commit 3f1baef

Browse files
committed
25 - Printing offset in grouped view
1 parent 4c44377 commit 3f1baef

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ itself has been updated to dotnet 8.0 and is now using the new information
1616
- Introduced timestamp for telegrams [#22](https://github.com/stprograms/SuperSoco485Monitor/issues/22)
1717
- Introduced storing of telegrams with timestamp [#23](https://github.com/stprograms/SuperSoco485Monitor/issues/23)
1818
- Showing offset to previous telegram in time view [#24](https://github.com/stprograms/SuperSoco485Monitor/issues/24)
19+
- Showing offset to previous telegram in grouped view [#25](https://github.com/stprograms/SuperSoco485Monitor/issues/25)
1920

2021
## 1.2.0
2122
### Modified

RS485 Monitor/src/Utils/ConsolePrinter.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ private class TelegramInfo
2121
/// Reference to the telegram
2222
/// </summary>
2323
public BaseTelegram Telegram { get; set; }
24+
/// <summary>
25+
/// Offset to the previous telegram of the same type
26+
/// </summary>
27+
public TimeSpan TimeOffset { get; set; }
2428

2529
/// <summary>
2630
/// Create new telegram info based on the given BaseTelegram
@@ -30,6 +34,7 @@ public TelegramInfo(BaseTelegram t)
3034
{
3135
Count = 1;
3236
Telegram = t;
37+
TimeOffset = TimeSpan.Zero;
3338
}
3439
};
3540

@@ -113,25 +118,21 @@ public ConsolePrinter()
113118
public void PrintTelegram(BaseTelegram tg)
114119
{
115120
// Generate key
116-
UInt16 key = (UInt16)((tg.Source << 8) + tg.Destination);
121+
UInt16 key = tg.Id;
117122

118123
lock (telegrams)
119124
{
120-
121-
if (!telegrams.ContainsKey(key))
125+
if (telegrams.TryGetValue(key, out TelegramInfo? value))
122126
{
123-
// New telegram
124-
telegrams[key] = new TelegramInfo(tg);
127+
// Update existing telegramtype
128+
value.TimeOffset = tg.TimeStamp - value.Telegram.TimeStamp;
129+
value.Telegram = tg;
130+
value.Count++;
125131
}
126132
else
127133
{
128-
// Update telegram
129-
if (!telegrams[key].Telegram.Equals(tg))
130-
{
131-
telegrams[key].Telegram = tg;
132-
}
133-
// UPdate entry
134-
telegrams[key].Count++;
134+
// New telegram type, create new entry
135+
telegrams[key] = new TelegramInfo(tg);
135136
}
136137
}
137138

@@ -195,10 +196,10 @@ private void PrintScreen()
195196
}
196197

197198
// Print the telegrams
198-
foreach (var telegram in telegrams)
199+
foreach (var value in telegrams.Values)
199200
{
200-
BaseTelegram t = telegram.Value.Telegram;
201-
Console.WriteLine($"({telegram.Value.Count:D3}) {t.ToStringDetailed()}");
201+
BaseTelegram t = value.Telegram;
202+
Console.WriteLine($"({value.Count:D3}) [{value.TimeOffset.TotalMilliseconds,5:N0} ms] {t.ToStringDetailed()}");
202203
}
203204
}
204205

@@ -210,19 +211,19 @@ private void PrintScreen()
210211
/// <summary>
211212
/// Clear the screen and print the header
212213
/// </summary>
213-
private void PrintHeader()
214+
private static void PrintHeader()
214215
{
215216
try
216217
{
217218
Console.CursorVisible = false;
218219
Console.Clear();
219-
Console.WriteLine("(Count) Raw Data -> Parsed Data");
220-
Console.WriteLine("-----------------------------------");
220+
Console.WriteLine("(Count) [Offset] Raw Data -> Parsed Data");
221+
Console.WriteLine("----------------------------------------");
221222
}
222223
catch (System.IO.IOException)
223224
{
224225
// VS Code debugger
225226
Console.WriteLine();
226227
}
227228
}
228-
}
229+
}

0 commit comments

Comments
 (0)