diff --git a/CHANGELOG.md b/CHANGELOG.md index 964f930..adbacda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ itself has been updated to dotnet 8.0 and is now using the new information - Introduced timestamp for telegrams [#22](https://github.com/stprograms/SuperSoco485Monitor/issues/22) - Introduced storing of telegrams with timestamp [#23](https://github.com/stprograms/SuperSoco485Monitor/issues/23) - Showing offset to previous telegram in time view [#24](https://github.com/stprograms/SuperSoco485Monitor/issues/24) +- Showing offset to previous telegram in grouped view [#25](https://github.com/stprograms/SuperSoco485Monitor/issues/25) ## 1.2.0 ### Modified diff --git a/RS485 Monitor/src/Utils/ConsolePrinter.cs b/RS485 Monitor/src/Utils/ConsolePrinter.cs index 6949fc6..43ec674 100644 --- a/RS485 Monitor/src/Utils/ConsolePrinter.cs +++ b/RS485 Monitor/src/Utils/ConsolePrinter.cs @@ -21,6 +21,10 @@ private class TelegramInfo /// Reference to the telegram /// public BaseTelegram Telegram { get; set; } + /// + /// Offset to the previous telegram of the same type + /// + public TimeSpan TimeOffset { get; set; } /// /// Create new telegram info based on the given BaseTelegram @@ -30,6 +34,7 @@ public TelegramInfo(BaseTelegram t) { Count = 1; Telegram = t; + TimeOffset = TimeSpan.Zero; } }; @@ -113,25 +118,21 @@ public ConsolePrinter() public void PrintTelegram(BaseTelegram tg) { // Generate key - UInt16 key = (UInt16)((tg.Source << 8) + tg.Destination); + UInt16 key = tg.Id; lock (telegrams) { - - if (!telegrams.ContainsKey(key)) + if (telegrams.TryGetValue(key, out TelegramInfo? value)) { - // New telegram - telegrams[key] = new TelegramInfo(tg); + // Update existing telegramtype + value.TimeOffset = tg.TimeStamp - value.Telegram.TimeStamp; + value.Telegram = tg; + value.Count++; } else { - // Update telegram - if (!telegrams[key].Telegram.Equals(tg)) - { - telegrams[key].Telegram = tg; - } - // UPdate entry - telegrams[key].Count++; + // New telegram type, create new entry + telegrams[key] = new TelegramInfo(tg); } } @@ -195,10 +196,10 @@ private void PrintScreen() } // Print the telegrams - foreach (var telegram in telegrams) + foreach (var value in telegrams.Values) { - BaseTelegram t = telegram.Value.Telegram; - Console.WriteLine($"({telegram.Value.Count:D3}) {t.ToStringDetailed()}"); + BaseTelegram t = value.Telegram; + Console.WriteLine($"({value.Count:D3}) [{value.TimeOffset.TotalMilliseconds,5:N0} ms] {t.ToStringDetailed()}"); } } @@ -210,14 +211,14 @@ private void PrintScreen() /// /// Clear the screen and print the header /// - private void PrintHeader() + private static void PrintHeader() { try { Console.CursorVisible = false; Console.Clear(); - Console.WriteLine("(Count) Raw Data -> Parsed Data"); - Console.WriteLine("-----------------------------------"); + Console.WriteLine("(Count) [Offset] Raw Data -> Parsed Data"); + Console.WriteLine("----------------------------------------"); } catch (System.IO.IOException) { @@ -225,4 +226,4 @@ private void PrintHeader() Console.WriteLine(); } } -} \ No newline at end of file +}