Skip to content

Commit f5ac710

Browse files
committed
24 - Timestamp offset in time view
Introduced writing the offset to the previous received telegram in the time view.
1 parent ed00287 commit f5ac710

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ itself has been updated to dotnet 8.0 and is now using the new information
1515
- Introduced software unit tests [#17](https://github.com/stprograms/SuperSoco485Monitor/issues/17)
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)
18+
- Showing offset to previous telegram in time view [#24](https://github.com/stprograms/SuperSoco485Monitor/issues/24)
1819

1920
## 1.2.0
2021
### Modified

RS485 Monitor/src/Utils/LogPrinter.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
using NLog;
22

33
/// <summary>
4-
/// Simple class printing the telegram to the log
4+
/// Simple class printing the telegram to the log.
5+
///
6+
/// It will print the telegrams in the following format:
7+
/// - offset to the last telegram in milliseconds
8+
/// - Raw data of the telegram
9+
/// - Detailed string representation of the telegram
510
/// </summary>
611
public class LogPrinter : IUserVisualizable
712
{
8-
913
/// <summary>
1014
/// class logger
1115
/// </summary>
1216
private static readonly Logger log = LogManager.GetCurrentClassLogger();
17+
/// <summary>
18+
/// Timestamp of the last printed telegram.
19+
///
20+
/// If no telegram was printed yet, it is null.
21+
/// </summary>
22+
private DateTime? lastTelegramTimestamp = null;
1323

1424
/// <summary>
1525
/// Flush output
@@ -25,6 +35,9 @@ public void Flush()
2535
/// <param name="tg"></param>
2636
public void PrintTelegram(BaseTelegram tg)
2737
{
28-
log.Info(tg.ToStringDetailed());
38+
var offset = lastTelegramTimestamp.HasValue ? tg.TimeStamp - lastTelegramTimestamp.Value : TimeSpan.Zero;
39+
lastTelegramTimestamp = tg.TimeStamp;
40+
41+
log.Info($"[{offset.TotalMilliseconds,5:N0} ms] {tg.ToStringDetailed()}");
2942
}
30-
}
43+
}

0 commit comments

Comments
 (0)