From 29b77f5629a4dc1e51aba665e9b84308e3749eee Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 10 Mar 2021 17:28:32 -0500 Subject: [PATCH 1/2] Update CecPortController class to implement IBasicCommunicationWithStreamDebuggingB --- .../Comm and IR/CecPortController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs index 1ab38d89..08358742 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs @@ -11,8 +11,10 @@ using PepperDash.Core; namespace PepperDash.Essentials.Core { - public class CecPortController : Device, IBasicCommunication + public class CecPortController : Device, IBasicCommunicationWithStreamDebugging { + public CommunicationStreamDebugging StreamDebugging { get; private set; } + public event EventHandler BytesReceived; public event EventHandler TextReceived; @@ -23,6 +25,8 @@ namespace PepperDash.Essentials.Core public CecPortController(string key, Func postActivationFunc, EssentialsControlPropertiesConfig config):base(key) { + StreamDebugging = new CommunicationStreamDebugging(key); + AddPostActivationAction(() => { Port = postActivationFunc(config); @@ -57,8 +61,12 @@ namespace PepperDash.Essentials.Core bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); } var textHandler = TextReceived; - if (textHandler != null) - textHandler(this, new GenericCommMethodReceiveTextArgs(s)); + if (textHandler != null) + { + if (StreamDebugging.RxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Recevied: '{0}'", s); + textHandler(this, new GenericCommMethodReceiveTextArgs(s)); + } } #region IBasicCommunication Members @@ -67,6 +75,8 @@ namespace PepperDash.Essentials.Core { if (Port == null) return; + if (StreamDebugging.TxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, text); Port.StreamCec.Send.StringValue = text; } @@ -75,6 +85,8 @@ namespace PepperDash.Essentials.Core if (Port == null) return; var text = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length); + if (StreamDebugging.TxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes)); Port.StreamCec.Send.StringValue = text; } From a583fdb72af98f1a660d31712b4200232a095c63 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 11 Mar 2021 12:25:46 -0500 Subject: [PATCH 2/2] Update StreamDebugging on receive for both CECPortController and ComPortController --- .../Comm and IR/CecPortController.cs | 6 ++++-- .../Comm and IR/ComPortController.cs | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs index 08358742..203c2f1a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CecPortController.cs @@ -54,17 +54,19 @@ namespace PepperDash.Essentials.Core void OnDataReceived(string s) { - var bytesHandler = BytesReceived; + var bytesHandler = BytesReceived; if (bytesHandler != null) { var bytes = Encoding.GetEncoding(28591).GetBytes(s); + if (StreamDebugging.RxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Received: '{0}'", ComTextHelper.GetEscapedText(bytes)); bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); } var textHandler = TextReceived; if (textHandler != null) { if (StreamDebugging.RxStreamDebuggingIsEnabled) - Debug.Console(0, this, "Recevied: '{0}'", s); + Debug.Console(0, this, "Received: '{0}'", s); textHandler(this, new GenericCommMethodReceiveTextArgs(s)); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/ComPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/ComPortController.cs index 75e9ae72..6d454ac5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/ComPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/ComPortController.cs @@ -92,18 +92,20 @@ namespace PepperDash.Essentials.Core void OnDataReceived(string s) { + var bytesHandler = BytesReceived; if (bytesHandler != null) { var bytes = Encoding.GetEncoding(28591).GetBytes(s); + if (StreamDebugging.RxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Received: '{0}'", ComTextHelper.GetEscapedText(bytes)); bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); } var textHandler = TextReceived; if (textHandler != null) { - if (StreamDebugging.RxStreamDebuggingIsEnabled) - Debug.Console(0, this, "Recevied: '{0}'", s); - + if (StreamDebugging.RxStreamDebuggingIsEnabled) + Debug.Console(0, this, "Received: '{0}'", s); textHandler(this, new GenericCommMethodReceiveTextArgs(s)); } }