From 50da8bf404c9008a6b064396bdab07d3c8df18f1 Mon Sep 17 00:00:00 2001 From: Braath Waate Date: Mon, 22 Aug 2022 07:12:34 -0600 Subject: [PATCH 1/3] fix polling intensity --- cpp/src/Driver.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cpp/src/Driver.cpp b/cpp/src/Driver.cpp index 84124da920..23249ed384 100644 --- a/cpp/src/Driver.cpp +++ b/cpp/src/Driver.cpp @@ -4092,7 +4092,7 @@ bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity) notification->SetHomeAndNodeIds(m_homeId, _valueId.GetNodeId()); notification->SetValueId(_valueId); QueueNotification(notification); - Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), m_pollList.size()); + Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x,int=%d)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), pe.m_pollCounter,m_pollList.size()); WriteCache(); return true; } @@ -4282,6 +4282,18 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) while (1) { int32 pollInterval = m_pollInterval; + // If the polling interval is for the whole poll list, calculate the time before the next poll, + // so that all polls can take place within the user-specified interval. + if (!m_bIntervalBetweenPolls) + { + if (pollInterval < 100) + { + Log::Write(LogLevel_Info, "The pollInterval setting is only %d, which appears to be a legacy setting. Multiplying by 1000 to convert to ms.", pollInterval); + pollInterval *= 1000; + } + pollInterval /= (int32) m_pollList.size(); + } + if (m_awakeNodesQueried && !m_pollList.empty()) { @@ -4299,6 +4311,14 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) pe.m_pollCounter--; m_pollList.push_back(pe); m_pollMutex->Unlock(); + // ready for next poll...insert the pollInterval delay + int i32; + i32 = Internal::Platform::Wait::Single(_exitEvent, pollInterval); + if (i32 == 0) + { + // Exit has been called + return; + } continue; } @@ -4314,18 +4334,6 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) m_pollList.push_back(pe); value->Release(); } - // If the polling interval is for the whole poll list, calculate the time before the next poll, - // so that all polls can take place within the user-specified interval. - if (!m_bIntervalBetweenPolls) - { - if (pollInterval < 100) - { - Log::Write(LogLevel_Info, "The pollInterval setting is only %d, which appears to be a legacy setting. Multiplying by 1000 to convert to ms.", pollInterval); - pollInterval *= 1000; - } - pollInterval /= (int32) m_pollList.size(); - } - { Internal::LockGuard LG(m_nodeMutex); // Request the state of the value from the node to which it belongs @@ -4399,7 +4407,7 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) else // poll list is empty or awake nodes haven't been fully queried yet { // don't poll just yet, wait for the pollInterval or exit before re-checking to see if the pollList has elements - int32 i32 = Internal::Platform::Wait::Single(_exitEvent, 500); + int32 i32 = Internal::Platform::Wait::Single(_exitEvent, pollInterval); if (i32 == 0) { // Exit has been called From 68acfa7a2669440da4ff4de43dac9dd6bc9f696a Mon Sep 17 00:00:00 2001 From: Braath Waate Date: Tue, 26 Mar 2024 06:07:03 -0600 Subject: [PATCH 2/3] fix 100% cpu usage, null ptr reference --- cpp/src/Driver.cpp | 9 +++++---- .../command_classes/AssociationCommandConfiguration.cpp | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/src/Driver.cpp b/cpp/src/Driver.cpp index 23249ed384..aede3c5866 100644 --- a/cpp/src/Driver.cpp +++ b/cpp/src/Driver.cpp @@ -4082,9 +4082,8 @@ bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity) // Not in the list, so we add it PollEntry pe; pe.m_id = _valueId; - pe.m_pollCounter = value->GetPollIntensity(); + pe.m_pollCounter = 1; // poll immediately m_pollList.push_back(pe); - value->Release(); m_pollMutex->Unlock(); // send notification to indicate polling is enabled @@ -4092,8 +4091,9 @@ bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity) notification->SetHomeAndNodeIds(m_homeId, _valueId.GetNodeId()); notification->SetValueId(_valueId); QueueNotification(notification); - Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x,int=%d)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), pe.m_pollCounter,m_pollList.size()); + Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x,int=%d)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), value->GetPollIntensity(),m_pollList.size()); WriteCache(); + value->Release(); return true; } @@ -4291,7 +4291,8 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) Log::Write(LogLevel_Info, "The pollInterval setting is only %d, which appears to be a legacy setting. Multiplying by 1000 to convert to ms.", pollInterval); pollInterval *= 1000; } - pollInterval /= (int32) m_pollList.size(); + if (m_pollList.size() != 0) + pollInterval /= (int32) m_pollList.size(); } diff --git a/cpp/src/command_classes/AssociationCommandConfiguration.cpp b/cpp/src/command_classes/AssociationCommandConfiguration.cpp index 576441250b..63ff69f0a7 100644 --- a/cpp/src/command_classes/AssociationCommandConfiguration.cpp +++ b/cpp/src/command_classes/AssociationCommandConfiguration.cpp @@ -182,8 +182,7 @@ namespace OpenZWave if (Node* node = GetNodeUnsafe()) { - Group* group = node->GetGroup(groupIdx); - if ( NULL == group) + if (Group* group = node->GetGroup(groupIdx)) { if (firstReports) { From 9ede05d01e9585396eecaa17f6dc4cd10e5de55a Mon Sep 17 00:00:00 2001 From: Braath Waate Date: Fri, 6 Dec 2024 07:10:54 -0700 Subject: [PATCH 3/3] bug fixes --- cpp/examples/MinOZW/Main.cpp | 3 ++- cpp/src/Driver.cpp | 15 ++++++++------- .../AssociationCommandConfiguration.cpp | 3 +-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cpp/examples/MinOZW/Main.cpp b/cpp/examples/MinOZW/Main.cpp index 07b494f866..fecdcdfe93 100644 --- a/cpp/examples/MinOZW/Main.cpp +++ b/cpp/examples/MinOZW/Main.cpp @@ -318,7 +318,8 @@ int main( int argc, char* argv[] ) #elif WIN32 string port = "\\\\.\\COM6"; #else - string port = "/dev/ttyUSB0"; + // string port = "/dev/ttyUSB0"; + string port = "/dev/ttyACM0"; #endif if ( argc > 1 ) { diff --git a/cpp/src/Driver.cpp b/cpp/src/Driver.cpp index 23249ed384..e4047244cb 100644 --- a/cpp/src/Driver.cpp +++ b/cpp/src/Driver.cpp @@ -4082,9 +4082,8 @@ bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity) // Not in the list, so we add it PollEntry pe; pe.m_id = _valueId; - pe.m_pollCounter = value->GetPollIntensity(); + pe.m_pollCounter = 1; // poll immediately m_pollList.push_back(pe); - value->Release(); m_pollMutex->Unlock(); // send notification to indicate polling is enabled @@ -4092,8 +4091,9 @@ bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity) notification->SetHomeAndNodeIds(m_homeId, _valueId.GetNodeId()); notification->SetValueId(_valueId); QueueNotification(notification); - Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x,int=%d)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), pe.m_pollCounter,m_pollList.size()); + Log::Write(LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x,int=%d)--poll list has %d items", _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), value->GetPollIntensity(),m_pollList.size()); WriteCache(); + value->Release(); return true; } @@ -4291,7 +4291,8 @@ void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent) Log::Write(LogLevel_Info, "The pollInterval setting is only %d, which appears to be a legacy setting. Multiplying by 1000 to convert to ms.", pollInterval); pollInterval *= 1000; } - pollInterval /= (int32) m_pollList.size(); + if (m_pollList.size() != 0) + pollInterval /= (int32) m_pollList.size(); } @@ -6994,7 +6995,7 @@ bool Driver::startConfigDownload(uint16 _manufacturerId, uint16 _productType, ui ss << std::hex << std::setw(4) << std::setfill('0') << _productId << "."; ss << std::hex << std::setw(4) << std::setfill('0') << _productType << "."; ss << std::hex << std::setw(4) << std::setfill('0') << _manufacturerId << ".xml"; - download->url = "http://download.db.openzwave.com/" + ss.str(); + download->url = "https://github.com/OpenZWave/open-zwave/tree/master/config/" + ss.str(); download->filename = configfile; download->operation = Internal::HttpDownload::Config; download->node = node; @@ -7006,7 +7007,7 @@ bool Driver::startConfigDownload(uint16 _manufacturerId, uint16 _productType, ui bool Driver::startMFSDownload(string configfile) { Internal::HttpDownload *download = new Internal::HttpDownload(); - download->url = "http://download.db.openzwave.com/mfs.xml"; + download->url = "https://github.com/OpenZWave/open-zwave/tree/master/config/mfs.xml"; download->filename = configfile; download->operation = Internal::HttpDownload::MFSConfig; download->node = 0; @@ -7018,7 +7019,7 @@ bool Driver::startMFSDownload(string configfile) bool Driver::startDownload(string target, string file) { Internal::HttpDownload *download = new Internal::HttpDownload(); - download->url = "http://download.db.openzwave.com/" + file; + download->url = "https://github.com/OpenZWave/open-zwave/tree/master/config/" + file; download->filename = target; download->operation = Internal::HttpDownload::Image; Log::Write(LogLevel_Info, "Queuing download for %s (Node %d)", download->url.c_str(), download->node); diff --git a/cpp/src/command_classes/AssociationCommandConfiguration.cpp b/cpp/src/command_classes/AssociationCommandConfiguration.cpp index 576441250b..63ff69f0a7 100644 --- a/cpp/src/command_classes/AssociationCommandConfiguration.cpp +++ b/cpp/src/command_classes/AssociationCommandConfiguration.cpp @@ -182,8 +182,7 @@ namespace OpenZWave if (Node* node = GetNodeUnsafe()) { - Group* group = node->GetGroup(groupIdx); - if ( NULL == group) + if (Group* group = node->GetGroup(groupIdx)) { if (firstReports) {