From adc2e9e3701fca6b353140b863e17d909e20eb99 Mon Sep 17 00:00:00 2001 From: Muralidaran Balaji Date: Sat, 8 Mar 2025 20:07:03 +0530 Subject: [PATCH] Add Timestamp to BaseTelegram and clean up TelegramParser Added a Timestamp property to the BaseTelegram class to store the creation or processing time of the telegram. Updated the TelegramArgs constructor in TelegramParser.cs to set this Timestamp to the current date and time (DateTime.Now) when a new TelegramArgs instance is created. Removed an unnecessary space in the TelegramParser class before the type check for the telegram. --- RS485 Monitor/src/TelegramParser.cs | 3 ++- RS485 Monitor/src/Telegrams/BaseTelegram.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/RS485 Monitor/src/TelegramParser.cs b/RS485 Monitor/src/TelegramParser.cs index ac4ea5d..470b9c3 100644 --- a/RS485 Monitor/src/TelegramParser.cs +++ b/RS485 Monitor/src/TelegramParser.cs @@ -38,6 +38,7 @@ public class TelegramArgs : EventArgs public TelegramArgs(BaseTelegram t) { Telegram = t; + Telegram.Timestamp = DateTime.Now; } } @@ -200,7 +201,7 @@ private void FinishBlock() } // Check if we can convert - if ( tg.Type == BaseTelegram.TelegramType.READ_RESPONSE) + if (tg.Type == BaseTelegram.TelegramType.READ_RESPONSE) { if (tg.Source == 0xAA && tg.Destination == 0x5A && tg.PDU.Length == 10) { diff --git a/RS485 Monitor/src/Telegrams/BaseTelegram.cs b/RS485 Monitor/src/Telegrams/BaseTelegram.cs index 6b5beb5..f8b3011 100644 --- a/RS485 Monitor/src/Telegrams/BaseTelegram.cs +++ b/RS485 Monitor/src/Telegrams/BaseTelegram.cs @@ -57,6 +57,11 @@ public enum TelegramType /// public TelegramType Type { get => (TelegramType)Start; } + /// + /// Timestamp of the telegram + /// + public DateTime Timestamp { get; set; } + #endregion #region Constants