Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions RS485 Monitor/src/Utils/ConsolePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ private class TelegramInfo
/// Reference to the telegram
/// </summary>
public BaseTelegram Telegram { get; set; }
/// <summary>
/// Offset to the previous telegram of the same type
/// </summary>
public TimeSpan TimeOffset { get; set; }

/// <summary>
/// Create new telegram info based on the given BaseTelegram
Expand All @@ -30,6 +34,7 @@ public TelegramInfo(BaseTelegram t)
{
Count = 1;
Telegram = t;
TimeOffset = TimeSpan.Zero;
}
};

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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()}");
}
}

Expand All @@ -210,19 +211,19 @@ private void PrintScreen()
/// <summary>
/// Clear the screen and print the header
/// </summary>
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)
{
// VS Code debugger
Console.WriteLine();
}
}
}
}