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 @@ -15,6 +15,7 @@ itself has been updated to dotnet 8.0 and is now using the new information
- Introduced software unit tests [#17](https://github.com/stprograms/SuperSoco485Monitor/issues/17)
- 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)

## 1.2.0
### Modified
Expand Down
21 changes: 17 additions & 4 deletions RS485 Monitor/src/Utils/LogPrinter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
using NLog;

/// <summary>
/// Simple class printing the telegram to the log
/// Simple class printing the telegram to the log.
///
/// It will print the telegrams in the following format:
/// - offset to the last telegram in milliseconds
/// - Raw data of the telegram
/// - Detailed string representation of the telegram
/// </summary>
public class LogPrinter : IUserVisualizable
{

/// <summary>
/// class logger
/// </summary>
private static readonly Logger log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Timestamp of the last printed telegram.
///
/// If no telegram was printed yet, it is null.
/// </summary>
private DateTime? lastTelegramTimestamp = null;

/// <summary>
/// Flush output
Expand All @@ -25,6 +35,9 @@ public void Flush()
/// <param name="tg"></param>
public void PrintTelegram(BaseTelegram tg)
{
log.Info(tg.ToStringDetailed());
var offset = lastTelegramTimestamp.HasValue ? tg.TimeStamp - lastTelegramTimestamp.Value : TimeSpan.Zero;
lastTelegramTimestamp = tg.TimeStamp;

log.Info($"[{offset.TotalMilliseconds,5:N0} ms] {tg.ToStringDetailed()}");
}
}
}