From e8f773b2e648fe35d430451f4f68afc5ea067632 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Fri, 16 Dec 2022 11:15:58 -0500 Subject: [PATCH 1/4] Fix: removed references to pullup resistors in versiport digital outputs --- .../Outputs/GenericVersiportOutputDevice.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs index 197a5b19..77037845 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs @@ -42,16 +42,17 @@ namespace PepperDash.Essentials.Core.CrestronIO OutputPort = postActivationFunc(config); OutputPort.Register(); - - OutputPort.SetVersiportConfiguration(eVersiportConfiguration.DigitalOutput); - if (config.DisablePullUpResistor) - OutputPort.DisablePullUpResistor = true; + if (!OutputPort.SupportsDigitalOutput) + { + Debug.Console(0, this, "Device does not support configuration as a Digital Output"); + return; + } OutputPort.VersiportChange += OutputPort_VersiportChange; - Debug.Console(1, this, "Created GenericVersiportDigitalInputDevice on port '{0}'. DisablePullUpResistor: '{1}'", config.PortNumber, OutputPort.DisablePullUpResistor); + Debug.Console(1, this, "Created GenericVersiportDigitalOutputDevice on port '{0}'.", config.PortNumber); }); From b0637288e9c353e0264a2ec958b884ed6e4825b5 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 21 Dec 2022 12:21:01 -0700 Subject: [PATCH 2/4] refactor: move logic for updating directory to method --- .../VideoCodec/ZoomRoom/ZoomRoom.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs index aade5c0d..b5eba9c5 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs @@ -1382,22 +1382,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom JsonConvert.PopulateObject(responseObj.ToString(), Status.Phonebook); - var directoryResults = - zStatus.Phonebook.ConvertZoomContactsToGeneric(Status.Phonebook.Contacts); - - if (!PhonebookSyncState.InitialSyncComplete) - { - PhonebookSyncState.InitialPhonebookFoldersReceived(); - PhonebookSyncState.PhonebookRootEntriesReceived(); - PhonebookSyncState.SetPhonebookHasFolders(true); - PhonebookSyncState.SetNumberOfContacts(Status.Phonebook.Contacts.Count); - } - - directoryResults.ResultsFolderId = "root"; - - DirectoryRoot = directoryResults; - - CurrentDirectoryResult = directoryResults; + UpdateDirectory(); break; } @@ -2252,6 +2237,26 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom } } + private void UpdateDirectory() + { + var directoryResults = + zStatus.Phonebook.ConvertZoomContactsToGeneric(Status.Phonebook.Contacts); + + if (!PhonebookSyncState.InitialSyncComplete) + { + PhonebookSyncState.InitialPhonebookFoldersReceived(); + PhonebookSyncState.PhonebookRootEntriesReceived(); + PhonebookSyncState.SetPhonebookHasFolders(true); + PhonebookSyncState.SetNumberOfContacts(Status.Phonebook.Contacts.Count); + } + + directoryResults.ResultsFolderId = "root"; + + DirectoryRoot = directoryResults; + + CurrentDirectoryResult = directoryResults; + } + /// /// Will return true if the host is myself (this zoom room) /// From decc8ed3a52bfe2e4d0130cc74d40ffe18dad30c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 22 Dec 2022 08:52:58 -0700 Subject: [PATCH 3/4] refactor: update queue error handling On some occasions, a ThreadAbortException was being caught on shutdown and causing exceptions to be printed needlessly. Messaging has also been updated to remove personal pronouns. --- .../Queues/GenericQueue.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index 9080435e..d4fe1af3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -1,5 +1,6 @@ using System; using Crestron.SimplSharp; +using Crestron.SimplSharp.Reflection; using Crestron.SimplSharpPro.CrestronThread; using PepperDash.Core; @@ -187,9 +188,20 @@ namespace PepperDash.Essentials.Core.Queues if (_delayEnabled) Thread.Sleep(_delayTime); } + catch (System.Threading.ThreadAbortException) + { + //swallowing this exception, as it should only happen on shut down + } catch (Exception ex) { - Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}\r{1}\r{2}", ex.Message, ex.InnerException, ex.StackTrace); + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue: {1}:{0}", ex.Message, ex); + Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException != null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "---\r\n{0}", ex.InnerException.Message); + Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.InnerException.StackTrace); + } } } else _waitHandle.Wait(); @@ -202,7 +214,7 @@ namespace PepperDash.Essentials.Core.Queues { if (Disposed) { - Debug.Console(1, this, "I've been disposed so you can't enqueue any messages. Are you trying to dispatch a message while the program is stopping?"); + Debug.Console(1, this, "Queue has been disposed. Enqueuing messages not allowed while program is stopping."); return; } @@ -446,7 +458,14 @@ namespace PepperDash_Essentials_Core.Queues } catch (Exception ex) { - Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}\r{1}\r{2}", ex.Message, ex.InnerException, ex.StackTrace); + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}", ex.Message); + Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException != null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}", ex.InnerException.Message); + Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.InnerException.StackTrace); + } } } else _waitHandle.Wait(); From d03581fea86aef5fc59fc338ffd67d42bc0bba4b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 22 Dec 2022 08:54:24 -0700 Subject: [PATCH 4/4] fix: change contact message handling On some occasions when the Zoom Room restarted and Essentials did not, the directory could be requested while the Zoom Room had no contacts yet, as it hadn't received them from Zoom Cloud. This caused the directory to be empty, even though there may be valid contacts. Now, Essentials uses the Added Contact and Updated Contact methods to fire the directory changed event, allowing for directory updates to be propogated as necessary. --- .../VideoCodec/ZoomRoom/ZoomRoom.cs | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs index b5eba9c5..1a70b2af 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs @@ -59,6 +59,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom private CameraBase _selectedCamera; private string _lastDialedMeetingNumber; + private CTimer contactsDebounceTimer; + private readonly ZoomRoomPropertiesConfig _props; @@ -1511,36 +1513,37 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom { case "phonebook": { + zStatus.Contact contact = new zStatus.Contact(); + if (responseObj["Updated Contact"] != null) - { - var updatedContact = - JsonConvert.DeserializeObject( - responseObj["Updated Contact"].ToString()); - - var existingContact = - Status.Phonebook.Contacts.FirstOrDefault(c => c.Jid.Equals(updatedContact.Jid)); - - if (existingContact != null) - { - // Update existing contact - JsonConvert.PopulateObject(responseObj["Updated Contact"].ToString(), - existingContact); - } + { + contact = responseObj["Updated Contact"].ToObject(); } else if (responseObj["Added Contact"] != null) { - var jToken = responseObj["Updated Contact"]; - if (jToken != null) - { - var newContact = - JsonConvert.DeserializeObject( - jToken.ToString()); - - // Add a new contact - Status.Phonebook.Contacts.Add(newContact); - } + contact = responseObj["Added Contact"].ToObject(); } + var existingContactIndex = Status.Phonebook.Contacts.FindIndex(c => c.Jid.Equals(contact.Jid)); + + if (existingContactIndex > 0) + { + Status.Phonebook.Contacts[existingContactIndex] = contact; + } + else + { + Status.Phonebook.Contacts.Add(contact); + } + + if(contactsDebounceTimer == null) + { + contactsDebounceTimer = new CTimer(o => UpdateDirectory(), 2000); + } + else + { + contactsDebounceTimer.Reset(); + } + break; } case "bookingslistresult": @@ -2239,8 +2242,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom private void UpdateDirectory() { - var directoryResults = - zStatus.Phonebook.ConvertZoomContactsToGeneric(Status.Phonebook.Contacts); + Debug.Console(2, this, "Updating directory"); + var directoryResults = zStatus.Phonebook.ConvertZoomContactsToGeneric(Status.Phonebook.Contacts); if (!PhonebookSyncState.InitialSyncComplete) { @@ -2255,6 +2258,22 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom DirectoryRoot = directoryResults; CurrentDirectoryResult = directoryResults; + + // + if (contactsDebounceTimer != null) + { + ClearContactDebounceTimer(); + } + } + + private void ClearContactDebounceTimer() + { + Debug.Console(2, this, "Clearing Timer"); + if (!contactsDebounceTimer.Disposed && contactsDebounceTimer != null) + { + contactsDebounceTimer.Dispose(); + contactsDebounceTimer = null; + } } ///