// Compilation export flags
#if (defined _WINDOWS || defined WIN32 || defined _MSC_VER) && (!defined MINGW && !defined __MINGW32__ && !defined __MINGW64__)
+// As discussd here https://github.com/OpenZWave/open-zwave/pull/1835
+// Disable certain MSVC warnings here (instead of applying the pragma throughout the code as was done in the past).
+// Application and DLL should be built with same compiler and settings anyway.
+// See https://stackoverflow.com/questions/5661738/how-can-i-use-standard-library-stl-classes-in-my-dll-interface-or-abi
# if defined OPENZWAVE_MAKEDLL // Create the dynamic library.
# define OPENZWAVE_EXPORT __declspec(dllexport)
+ __pragma(warning(disable: 4251)) __pragma(warning(disable: 4275))
# elif defined OPENZWAVE_USEDLL // Use the dynamic library
# define OPENZWAVE_EXPORT __declspec(dllimport)
+ __pragma(warning(disable: 4251)) __pragma(warning(disable: 4275))
# else // Create/Use the static library
# define OPENZWAVE_EXPORT
# endif
-// Disable export warnings
-# define OPENZWAVE_EXPORT_WARNINGS_OFF __pragma( warning(push) )\
- __pragma( warning(disable: 4251) ) \
- __pragma( warning(disable: 4275) )
-# define OPENZWAVE_EXPORT_WARNINGS_ON __pragma( warning(pop) )
#else
# define OPENZWAVE_EXPORT
-# define OPENZWAVE_EXPORT_WARNINGS_OFF
-# define OPENZWAVE_EXPORT_WARNINGS_ON
#endif
#ifdef __GNUC__
@@ -62,7 +61,6 @@
#define DEPRECATED
#endif
-
#ifdef _MSC_VER
#define OPENZWAVE_DEPRECATED_WARNINGS_OFF __pragma( warning(push) )\
__pragma( warning(disable: 4996) )
@@ -77,38 +75,37 @@
#define OPENZWAVE_DEPRECATED_WARNINGS_ON _Pragma ( "GCC diagnostic pop" )
#endif
-
-
#ifdef NULL
#undef NULL
#endif
#define NULL 0
// Basic types
-typedef signed char int8;
-typedef unsigned char uint8;
+typedef signed char int8;
+typedef unsigned char uint8;
-typedef signed short int16;
-typedef unsigned short uint16;
+typedef signed short int16;
+typedef unsigned short uint16;
-typedef signed int int32;
-typedef unsigned int uint32;
+typedef signed int int32;
+typedef unsigned int uint32;
#ifdef _MSC_VER
-typedef signed __int64 int64;
-typedef unsigned __int64 uint64;
+typedef signed __int64 int64;
+typedef unsigned __int64 uint64;
#endif
#ifdef __GNUC__
-typedef signed long long int64;
-typedef unsigned long long uint64;
+typedef signed long long int64;
+typedef unsigned long long uint64;
#endif
-typedef float float32;
-typedef double float64;
+typedef float float32;
+typedef double float64;
-typedef struct ozwversion {
- uint32_t _v; /* major << 16 | minor */
+typedef struct ozwversion
+{
+ uint32_t _v; /* major << 16 | minor */
} ozwversion;
/**
@@ -116,7 +113,8 @@ typedef struct ozwversion {
* \param v: the version number to obtain the major number from
* \return the Major Version Number
*/
-static inline uint16_t version_major(struct ozwversion v) {
+static inline uint16_t version_major(struct ozwversion v)
+{
return (v._v & 0xFFFF0000) >> 16;
}
@@ -125,7 +123,8 @@ static inline uint16_t version_major(struct ozwversion v) {
* \param v: the version number to obtain the minor number from
* \return the Minor Version Number
*/
-static inline uint16_t version_minor(const struct ozwversion &v) {
+static inline uint16_t version_minor(const struct ozwversion &v)
+{
return v._v & 0xFFFF;
}
@@ -138,7 +137,7 @@ static inline uint16_t version_minor(const struct ozwversion &v) {
static inline struct ozwversion version(uint16_t major, uint16_t minor)
{
struct ozwversion v;
- v._v = (uint32_t)(major << 16) | (uint32_t)minor;
+ v._v = (uint32_t) (major << 16) | (uint32_t) minor;
return v;
}
@@ -157,7 +156,7 @@ static inline struct ozwversion version(uint16_t major, uint16_t minor)
*/
static inline int version_cmp(struct ozwversion a, struct ozwversion b)
{
- return (a._v == b._v) ? 0 : (a._v > b._v) ? 1 : - 1;
+ return (a._v == b._v) ? 0 : (a._v > b._v) ? 1 : -1;
}
#include "OZWException.h"
@@ -166,28 +165,27 @@ static inline int version_cmp(struct ozwversion a, struct ozwversion b)
#else
# define __MYFUNCTION__ __FILE__
#endif
-// Exceptions : define OPENZWAVE_ENABLE_EXCEPTIONS in compiler flags to enable exceptions instead of exit function
-#ifdef OPENZWAVE_ENABLE_EXCEPTIONS
# define OZW_FATAL_ERROR(exitCode, msg) Log::Write( LogLevel_Error,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
throw OZWException(__MYFUNCTION__, __LINE__, exitCode, msg)
# define OZW_ERROR(exitCode, msg) Log::Write( LogLevel_Warning,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
throw OZWException(__MYFUNCTION__, __LINE__, exitCode, msg)
-#else
-
-# define OZW_FATAL_ERROR(exitCode, msg) Log::Write( LogLevel_Error,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
- std::cerr << "Error: "<< std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1) << ":" << __LINE__ << " - " << msg << std::endl; exit(exitCode)
-# define OZW_ERROR(exitCode, msg) Log::Write( LogLevel_Warning,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg);
-
-#endif
-
// Declare the OpenZWave namespace
-namespace std {}
+namespace std
+{
+}
namespace OpenZWave
{
// Include the STL namespace
using namespace std;
+ namespace Internal
+ {
+ namespace CC
+ {
+
+ }
+ }
}
// Modifications for Microsoft compilers
@@ -202,11 +200,9 @@ namespace OpenZWave
#define snprintf sprintf_s
#define strcasecmp _stricmp
#define sscanf sscanf_s
-#define strncpy strncpy_s
+#define strncpy(x, y, z) strncpy_s(x, sizeof(x), y, sizeof(x)-1)
#define strncat strncat_s
-
-
#endif
// Modifications for MiNGW32 compiler
@@ -222,7 +218,6 @@ namespace OpenZWave
#define fopen_s fopen
-
#endif
//#define MAX_TRIES 3 // Retry sends up to 3 times
@@ -334,7 +329,6 @@ namespace OpenZWave
#define FUNC_ID_PROPRIETARY_D 0xFD
#define FUNC_ID_PROPRIETARY_E 0xFE
-
#define ADD_NODE_ANY 0x01
#define ADD_NODE_CONTROLLER 0x02
#define ADD_NODE_SLAVE 0x03
@@ -453,14 +447,14 @@ namespace OpenZWave
/* RouteScheme Definitions */
typedef enum TXSTATUS_ROUTING_SCHEME
{
- ROUTINGSCHEME_IDLE = 0,
- ROUTINGSCHEME_DIRECT = 1,
- ROUTINGSCHEME_CACHED_ROUTE_SR = 2,
- ROUTINGSCHEME_CACHED_ROUTE = 3,
- ROUTINGSCHEME_CACHED_ROUTE_NLWR = 4,
- ROUTINGSCHEME_ROUTE = 5,
- ROUTINGSCHEME_RESORT_DIRECT = 6,
- ROUTINGSCHEME_RESORT_EXPLORE = 7
+ ROUTINGSCHEME_IDLE = 0,
+ ROUTINGSCHEME_DIRECT = 1,
+ ROUTINGSCHEME_CACHED_ROUTE_SR = 2,
+ ROUTINGSCHEME_CACHED_ROUTE = 3,
+ ROUTINGSCHEME_CACHED_ROUTE_NLWR = 4,
+ ROUTINGSCHEME_ROUTE = 5,
+ ROUTINGSCHEME_RESORT_DIRECT = 6,
+ ROUTINGSCHEME_RESORT_EXPLORE = 7
} TXSTATUS_ROUTING_SCHEME;
/* RouteSpeed Definitions */
@@ -472,5 +466,4 @@ typedef enum TXSTATUS_ROUTE_SPEED
ROUTE_SPEED_100K = 3,
} TXSTATUS_ROUTE_SPEED;
-
#endif // _Defs_H
diff --git a/cpp/src/DoxygenMain.h b/cpp/src/DoxygenMain.h
index ad6119686e..98602a3a91 100644
--- a/cpp/src/DoxygenMain.h
+++ b/cpp/src/DoxygenMain.h
@@ -1,4 +1,3 @@
-
/**
* \mainpage OpenZWave
* \section Introduction Introduction to OpenZWave
@@ -7,29 +6,12 @@
* applications, without requiring any in depth knowledge of the Z-Wave
* protocol.
*
- * The Majority of the Z-Wave Protocol has been released into the public domain
- * on Sept, 2016. Prior to Sept, 2016, OpenZWave had reverse engineered the
- * protocol to allow applications to be created to interact with Z-Wave devices.
- * There is now ongoing work to update OpenZWave to be compliant with the Z-Wave
- * Specifications that are now released at http://zwavepublic.com
- *
- * There is one part of the protocol that has not been released into the Public
- * Domain, namely, the "SerialAPI" protocol that specifies how to talk to
- * a USB Stick via a Serial COM Port. This portion of OpenZWave will continue to
- * be reverse engineered if needed in the future.
- *
- * The goal of the project is to make a positive contribution to the Z-Wave
- * community by creating a library that supports as much of the Z-Wave
- * specification as possible, and that can be used as a "black-box"
- * solution by anyone wanting to add Z-Wave to their application.
- *
- * @image html zwalliance_250x100.jpg
- *
OpenZWave is a affiliate member of the Z-Wave Alliance (http://zwavealliance.org/)
-
+ * For more information about the OpenZWave project: see README.md in the
+ * root of the OpenZWave repository.
* \section ZWave Z-Wave Concepts
* Z-Wave is a proprietary wireless communications protocol employing mesh
* networking technology. A mesh network allows low power devices to
- * communicate over long ranges, and around radio blackspots by passing
+ * communicate over long ranges, and around radio black spots by passing
* messages from one node to another. It is important to note that not all
* Z-Wave devices are active all the time, especially those that are battery
* powered. These nodes cannot take part in the forwarding of messages
@@ -37,10 +19,10 @@
*
* Each Z-Wave device is known as "Node" in the network. A Z-Wave network
* can contain up to 232 nodes. If more devices are required, then
- * multiple networks need to be set up using separate Z-Wave controller.
+ * multiple networks need to be set up using separate Z-Wave controllers.
* OpenZWave supports multiple controllers, but on its own does not bridge
- * the networks allowing a device on one to directly control a device on
- * another. This functionality would have to be supplied by the application.
+ * the networks, allowing a device on one to directly control a device on
+ * another. This functionality would have to be supplied by the application.
*
* Z-Wave nodes can be divided into two types: Controllers and Slaves. The
* controllers are usually in the form of hand-held remote controls, or PC
@@ -49,7 +31,6 @@
* Replication
* Command Classes
* Values
-
*
* \section Library The OpenZWave Library
* \subsection Overview Overview
@@ -93,7 +74,7 @@
* to be reliable. Do not rely on receiving a response to any request.
*
* - A Z-Wave network may change at any time. The application's notification
- * callback handler must deal woth all notifications, and any representation
+ * callback handler must deal with all notifications, and any representation
* of the state of the Z-Wave network held by the application must be
* modified to match. User interfaces should be built dynamically from the
* information reported in the notification callbacks, and must be able to cope
@@ -112,23 +93,11 @@
*
* \section Licensing Licensing
- * OpenZWave is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, either version 3 of the License,
- * or (at your option) any later version.
- *
- * OpenZWave is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with OpenZWave. If not, see .
+ * See README.md in the root of the OpenZWave project.
*
* \section Support Support
- * Assistance with all OpenZWave issues can be obtained by posting a message
- * to the OpenZWave Google Group (http://groups.google.com/group/openzwave)
+ * See README.md in the root of the OpenZWave project.
*
*/
diff --git a/cpp/src/Driver.cpp b/cpp/src/Driver.cpp
index 5b001f4e5b..cf720813d4 100644
--- a/cpp/src/Driver.cpp
+++ b/cpp/src/Driver.cpp
@@ -67,7 +67,6 @@
#include "tinyxml.h"
-
#include "Utils.h"
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# include
@@ -89,12 +88,11 @@ using namespace OpenZWave;
// 01: 12-31-2010 - Introduced config version numbering due to ValueID format change.
// 02: 01-12-2011 - Command class m_afterMark sense corrected, and attribute named to match.
// 03: 08-04-2011 - Changed command class instance handling for non-sequential MultiChannel endpoints.
-//
-uint32 const c_configVersion = 3;
+// 04: 12-07-2019 - Changed Interview Order
+uint32 const c_configVersion = 4;
static char const* c_libraryTypeNames[] =
-{
- "Unknown", // library type 0
+{ "Unknown", // library type 0
"Static Controller", // library type 1
"Controller", // library type 2
"Enhanced Slave", // library type 3
@@ -103,161 +101,63 @@ static char const* c_libraryTypeNames[] =
"Routing Slave", // library type 6
"Bridge Controller", // library type 7
"Device Under Test" // library type 8
-};
+ };
static char const* c_controllerCommandNames[] =
-{
- "None",
- "Add Device",
- "Create New Primary",
- "Receive Configuration",
- "Remove Device",
- "Remove Failed Node",
- "Has Node Failed",
- "Replace Failed Node",
- "Transfer Primary Role",
- "Request Network Update",
- "Request Node Neighbor Update",
- "Assign Return Route",
- "Delete All Return Routes",
- "Send Node Information",
- "Replication Send",
- "Create Button",
- "Delete Button"
-};
+{ "None", "Add Device", "Create New Primary", "Receive Configuration", "Remove Device", "Remove Failed Node", "Has Node Failed", "Replace Failed Node", "Transfer Primary Role", "Request Network Update", "Request Node Neighbor Update", "Assign Return Route", "Delete All Return Routes", "Send Node Information", "Replication Send", "Create Button", "Delete Button" };
static char const* c_sendQueueNames[] =
-{
- "Command",
- "NoOp",
- "Controller",
- "WakeUp",
- "Send",
- "Query",
- "Poll"
-};
-
+{ "Command", "NoOp", "Controller", "WakeUp", "Send", "Query", "Poll" };
//-----------------------------------------------------------------------------
//
// Constructor
//-----------------------------------------------------------------------------
-Driver::Driver
-(
- string const& _controllerPath,
- ControllerInterface const& _interface
-):
-m_driverThread( new Thread( "driver" ) ),
-m_dns ( new DNSThread(this) ),
-m_dnsThread ( new Thread( "dns" ) ),
-m_initMutex(new Mutex()),
-m_exit( false ),
-m_init( false ),
-m_awakeNodesQueried( false ),
-m_allNodesQueried( false ),
-m_notifytransactions( false ),
-m_timer ( new TimerThread( this ) ),
-m_timerThread ( new Thread( "timer" ) ),
-m_controllerInterfaceType( _interface ),
-m_controllerPath( _controllerPath ),
-m_controller( NULL ),
-m_homeId( 0 ),
-m_libraryVersion( "" ),
-m_libraryTypeName( "" ),
-m_libraryType( 0 ),
-m_manufacturerId( 0 ),
-m_productType( 0 ),
-m_productId ( 0 ),
-m_initVersion( 0 ),
-m_initCaps( 0 ),
-m_controllerCaps( 0 ),
-m_Controller_nodeId ( 0 ),
-m_nodeMutex( new Mutex() ),
-m_controllerReplication( NULL ),
-m_transmitOptions( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_EXPLORE ),
-m_waitingForAck( false ),
-m_expectedCallbackId( 0 ),
-m_expectedReply( 0 ),
-m_expectedCommandClassId( 0 ),
-m_expectedNodeId( 0 ),
-m_pollThread( new Thread( "poll" ) ),
-m_pollMutex( new Mutex() ),
-m_pollInterval( 0 ),
-m_bIntervalBetweenPolls( false ), // if set to true (via SetPollInterval), the pollInterval will be interspersed between each poll (so a much smaller m_pollInterval like 100, 500, or 1,000 may be appropriate)
-m_currentControllerCommand( NULL ),
-m_SUCNodeId( 0 ),
-m_controllerResetEvent( NULL ),
-m_sendMutex( new Mutex() ),
-m_currentMsg( NULL ),
-m_virtualNeighborsReceived( false ),
-m_notificationsEvent( new Event() ),
-m_SOFCnt( 0 ),
-m_ACKWaiting( 0 ),
-m_readAborts( 0 ),
-m_badChecksum( 0 ),
-m_readCnt( 0 ),
-m_writeCnt( 0 ),
-m_CANCnt( 0 ),
-m_NAKCnt( 0 ),
-m_ACKCnt( 0 ),
-m_OOFCnt( 0 ),
-m_dropped( 0 ),
-m_retries( 0 ),
-m_callbacks( 0 ),
-m_badroutes( 0 ),
-m_noack( 0 ),
-m_netbusy( 0 ),
-m_notidle( 0 ),
-m_txverified( 0 ),
-m_nondelivery( 0 ),
-m_routedbusy( 0 ),
-m_broadcastReadCnt( 0 ),
-m_broadcastWriteCnt( 0 ),
-AuthKey( 0 ),
-EncryptKey( 0 ),
-m_nonceReportSent( 0 ),
-m_nonceReportSentAttempt( 0 ),
-m_queueMsgEvent (new Event() ),
-m_eventMutex (new Mutex() )
+Driver::Driver(string const& _controllerPath, ControllerInterface const& _interface) :
+ m_driverThread(new Internal::Platform::Thread("driver")), m_dns(new Internal::DNSThread(this)), m_dnsThread(new Internal::Platform::Thread("dns")), m_initMutex(new Internal::Platform::Mutex()), m_exit(false), m_init(false), m_awakeNodesQueried(false), m_allNodesQueried(false), m_notifytransactions(false), m_timer(new Internal::TimerThread(this)), m_timerThread(new Internal::Platform::Thread("timer")), m_controllerInterfaceType(_interface), m_controllerPath(_controllerPath), m_controller(
+ NULL), m_homeId(0), m_libraryVersion(""), m_libraryTypeName(""), m_libraryType(0), m_manufacturerId(0), m_productType(0), m_productId(0), m_initVersion(0), m_initCaps(0), m_controllerCaps(0), m_Controller_nodeId(0), m_nodeMutex(new Internal::Platform::Mutex()), m_controllerReplication( NULL), m_transmitOptions( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_EXPLORE), m_waitingForAck(false), m_expectedCallbackId(0), m_expectedReply(0), m_expectedCommandClassId(
+ 0), m_expectedNodeId(0), m_pollThread(new Internal::Platform::Thread("poll")), m_pollMutex(new Internal::Platform::Mutex()), m_pollInterval(0), m_bIntervalBetweenPolls(false), // if set to true (via SetPollInterval), the pollInterval will be interspersed between each poll (so a much smaller m_pollInterval like 100, 500, or 1,000 may be appropriate)
+ m_currentControllerCommand( NULL), m_SUCNodeId(0), m_controllerResetEvent( NULL), m_sendMutex(new Internal::Platform::Mutex()), m_currentMsg( NULL), m_virtualNeighborsReceived(false), m_notificationsEvent(new Internal::Platform::Event()), m_SOFCnt(0), m_ACKWaiting(0), m_readAborts(0), m_badChecksum(0), m_readCnt(0), m_writeCnt(0), m_CANCnt(0), m_NAKCnt(0), m_ACKCnt(0), m_OOFCnt(0), m_dropped(0), m_retries(0), m_callbacks(0), m_badroutes(0), m_noack(0), m_netbusy(0), m_notidle(0), m_txverified(
+ 0), m_nondelivery(0), m_routedbusy(0), m_broadcastReadCnt(0), m_broadcastWriteCnt(0), AuthKey(0), EncryptKey(0), m_nonceReportSent(0), m_nonceReportSentAttempt(0), m_queueMsgEvent(new Internal::Platform::Event()), m_eventMutex(new Internal::Platform::Mutex())
{
// set a timestamp to indicate when this driver started
- TimeStamp m_startTime;
+ Internal::Platform::TimeStamp m_startTime;
// Create the message queue events
- for( int32 i=0; iSetSignalThreshold( 1 );
+ m_controller->SetSignalThreshold(1);
- Options::Get()->GetOptionAsBool( "NotifyTransactions", &m_notifytransactions );
- Options::Get()->GetOptionAsInt( "PollInterval", &m_pollInterval );
- Options::Get()->GetOptionAsBool( "IntervalBetweenPolls", &m_bIntervalBetweenPolls );
+ Options::Get()->GetOptionAsBool("NotifyTransactions", &m_notifytransactions);
+ Options::Get()->GetOptionAsInt("PollInterval", &m_pollInterval);
+ Options::Get()->GetOptionAsBool("IntervalBetweenPolls", &m_bIntervalBetweenPolls);
- m_httpClient = new HttpClient(this);
+ m_httpClient = new Internal::HttpClient(this);
- m_mfs = ManufacturerSpecificDB::Create();
+ m_mfs = Internal::ManufacturerSpecificDB::Create();
CheckMFSConfigRevision();
@@ -267,29 +167,26 @@ m_eventMutex (new Mutex() )
//
// Destructor
//-----------------------------------------------------------------------------
-Driver::~Driver
-(
-)
+Driver::~Driver()
{
/* Signal that we are going away... so at least Apps know... */
- Notification* notification = new Notification( Notification::Type_DriverRemoved );
- notification->SetHomeAndNodeIds( m_homeId, 0 );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_DriverRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, 0);
+ QueueNotification(notification);
NotifyWatchers();
-
// append final driver stats output to the log file
LogDriverStatistics();
// Save the driver config before deleting anything else
bool save;
- if( Options::Get()->GetOptionAsBool( "SaveConfiguration", &save) )
+ if (Options::Get()->GetOptionAsBool("SaveConfiguration", &save))
{
- if( save )
+ if (save)
{
WriteCache();
- Scene::WriteXML( "zwscene.xml" );
+ Internal::Scene::WriteXML("zwscene.xml");
}
}
@@ -310,9 +207,9 @@ Driver::~Driver
m_driverThread->Stop();
m_driverThread->Release();
- m_timerThread->Stop();
- m_timerThread->Release();
- delete m_timer;
+ m_timerThread->Stop();
+ m_timerThread->Release();
+ delete m_timer;
m_sendMutex->Release();
@@ -321,23 +218,23 @@ Driver::~Driver
m_initMutex->Release();
- if( m_currentMsg != NULL )
+ if (m_currentMsg != NULL)
{
RemoveCurrentMsg();
}
// Clear the node data
{
- LockGuard LG(m_nodeMutex);
- for( int i=0; i<256; ++i )
+ Internal::LockGuard LG(m_nodeMutex);
+ for (int i = 0; i < 256; ++i)
{
- if( GetNodeUnsafe( i ) )
+ if (GetNodeUnsafe(i))
{
delete m_nodes[i];
m_nodes[i] = NULL;
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, i );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, i);
+ QueueNotification(notification);
}
}
}
@@ -345,16 +242,16 @@ Driver::~Driver
m_pollMutex->Release();
// Clear the send Queue
- for( int32 i=0; iGetOptionAsBool( "NotifyOnDriverUnload", ¬ify) )
+ if (Options::Get()->GetOptionAsBool("NotifyOnDriverUnload", ¬ify))
{
- if( notify )
+ if (notify)
{
NotifyWatchers();
}
}
+ list::iterator nit = m_notifications.begin();
+ while (nit != m_notifications.end())
+ {
+ Notification* notification = m_notifications.front();
+ m_notifications.pop_front();
+ delete notification;
+ nit = m_notifications.begin();
+ }
+
if (m_controllerReplication)
delete m_controllerReplication;
m_notificationsEvent->Release();
m_nodeMutex->Release();
+ m_queueMsgEvent->Release();
+ m_eventMutex->Release();
delete this->AuthKey;
delete this->EncryptKey;
delete this->m_httpClient;
@@ -394,30 +302,24 @@ Driver::~Driver
//
// Start the driver thread
//-----------------------------------------------------------------------------
-void Driver::Start
-(
-)
+void Driver::Start()
{
// Start the thread that will handle communications with the Z-Wave network
- m_driverThread->Start( Driver::DriverThreadEntryPoint, this );
- m_dnsThread->Start ( DNSThread::DNSThreadEntryPoint, m_dns);
- m_timerThread->Start( TimerThread::TimerThreadEntryPoint, m_timer );
+ m_driverThread->Start(Driver::DriverThreadEntryPoint, this);
+ m_dnsThread->Start(Internal::DNSThread::DNSThreadEntryPoint, m_dns);
+ m_timerThread->Start(Internal::TimerThread::TimerThreadEntryPoint, m_timer);
}
//-----------------------------------------------------------------------------
//
// Entry point of the thread for creating and managing the worker threads
//-----------------------------------------------------------------------------
-void Driver::DriverThreadEntryPoint
-(
- Event* _exitEvent,
- void* _context
-)
+void Driver::DriverThreadEntryPoint(Internal::Platform::Event* _exitEvent, void* _context)
{
- Driver* driver = (Driver*)_context;
- if( driver )
+ Driver* driver = (Driver*) _context;
+ if (driver)
{
- driver->DriverThreadProc( _exitEvent );
+ driver->DriverThreadProc(_exitEvent);
}
}
@@ -425,24 +327,22 @@ void Driver::DriverThreadEntryPoint
//
// Create and manage the worker threads
//-----------------------------------------------------------------------------
-void Driver::DriverThreadProc
-(
- Event* _exitEvent
-)
+void Driver::DriverThreadProc(Internal::Platform::Event* _exitEvent)
{
#define WAITOBJECTCOUNT 11
uint32 attempts = 0;
bool mfsisReady = false;
- while( true )
+ while (true)
{
- if( Init( attempts ) )
+ if (Init(attempts))
{
// Driver has been initialised
- Wait* waitObjects[WAITOBJECTCOUNT];
+ Internal::Platform::Wait* waitObjects[WAITOBJECTCOUNT];
waitObjects[0] = _exitEvent; // Thread must exit.
waitObjects[1] = m_notificationsEvent; // Notifications waiting to be sent.
- waitObjects[2] = m_queueMsgEvent; ; // a DNS and HTTP Event
+ waitObjects[2] = m_queueMsgEvent;
+ ; // a DNS and HTTP Event
waitObjects[3] = m_controller; // Controller has received data.
waitObjects[4] = m_queueEvent[MsgQueue_Command]; // A controller command is in progress.
waitObjects[5] = m_queueEvent[MsgQueue_NoOp]; // Send device probes and diagnostics messages
@@ -452,32 +352,34 @@ void Driver::DriverThreadProc
waitObjects[9] = m_queueEvent[MsgQueue_Query]; // Node queries are pending.
waitObjects[10] = m_queueEvent[MsgQueue_Poll]; // Poll request is waiting.
- TimeStamp retryTimeStamp;
+ Internal::Platform::TimeStamp retryTimeStamp;
int retryTimeout = RETRY_TIMEOUT;
- Options::Get()->GetOptionAsInt( "RetryTimeout", &retryTimeout );
+ Options::Get()->GetOptionAsInt("RetryTimeout", &retryTimeout);
//retryTimeout = RETRY_TIMEOUT * 10;
- while( true )
+ while (true)
{
- Log::Write( LogLevel_StreamDetail, " Top of DriverThreadProc loop." );
+ Log::Write(LogLevel_StreamDetail, " Top of DriverThreadProc loop.");
uint32 count = WAITOBJECTCOUNT;
- int32 timeout = Wait::Timeout_Infinite;
+ int32 timeout = Internal::Platform::Wait::Timeout_Infinite;
// if the ManufacturerDB class is setting up, we can't do anything yet
- if (mfsisReady == false) {
- count=3;
+ if (mfsisReady == false)
+ {
+ count = 3;
// If we're waiting for a message to complete, we can only
// handle incoming data, notifications, DNS/HTTP and exit events.
- } else if( m_waitingForAck || m_expectedCallbackId || m_expectedReply )
+ }
+ else if (m_waitingForAck || m_expectedCallbackId || m_expectedReply)
{
count = 4;
timeout = m_waitingForAck ? ACK_TIMEOUT : retryTimeStamp.TimeRemaining();
- if( timeout < 0 )
+ if (timeout < 0)
{
timeout = 0;
}
}
- else if( m_currentControllerCommand != NULL )
+ else if (m_currentControllerCommand != NULL)
{
count = 7;
}
@@ -487,63 +389,64 @@ void Driver::DriverThreadProc
}
// Wait for something to do
- int32 res = Wait::Multiple( waitObjects, count, timeout );
+ int32 res = Internal::Platform::Wait::Multiple(waitObjects, count, timeout);
- switch( res )
- {
- case -1:
+ switch (res)
{
- // Wait has timed out - time to resend
- if( m_currentMsg != NULL )
+ case -1:
{
- Notification* notification = new Notification( Notification::Type_Notification );
- notification->SetHomeAndNodeIds( m_homeId, m_currentMsg->GetTargetNodeId() );
- notification->SetNotification( Notification::Code_Timeout );
- QueueNotification( notification );
+ // Wait has timed out - time to resend
+ if (m_currentMsg != NULL)
+ {
+ Notification* notification = new Notification(Notification::Type_Notification);
+ notification->SetHomeAndNodeIds(m_homeId, m_currentMsg->GetTargetNodeId());
+ notification->SetNotification(Notification::Code_Timeout);
+ QueueNotification(notification);
+ }
+ if (WriteMsg("Wait Timeout"))
+ {
+ retryTimeStamp.SetTime(retryTimeout);
+ }
+ break;
}
- if( WriteMsg( "Wait Timeout" ) )
+ case 0:
{
- retryTimeStamp.SetTime( retryTimeout );
+ // Exit has been signalled
+ return;
}
- break;
- }
- case 0:
- {
- // Exit has been signalled
- return;
- }
- case 1:
- {
- // Notifications are waiting to be sent
- NotifyWatchers();
- break;
- }
- case 2:
- {
- // a DNS or HTTP Event has occurred
- ProcessEventMsg();
- if (mfsisReady == false && m_mfs->isReady()) {
- Notification* notification = new Notification( Notification::Type_ManufacturerSpecificDBReady );
- QueueNotification( notification );
- mfsisReady = true;
+ case 1:
+ {
+ // Notifications are waiting to be sent
+ NotifyWatchers();
+ break;
}
- break;
- }
- case 3:
- {
- // Data has been received
- ReadMsg();
- break;
- }
- default:
- {
- // All the other events are sending message queue items
- if( WriteNextMsg( (MsgQueue)(res-4) ) )
+ case 2:
{
- retryTimeStamp.SetTime( retryTimeout );
+ // a DNS or HTTP Event has occurred
+ ProcessEventMsg();
+ if (mfsisReady == false && m_mfs->isReady())
+ {
+ Notification* notification = new Notification(Notification::Type_ManufacturerSpecificDBReady);
+ QueueNotification(notification);
+ mfsisReady = true;
+ }
+ break;
+ }
+ case 3:
+ {
+ // Data has been received
+ ReadMsg();
+ break;
+ }
+ default:
+ {
+ // All the other events are sending message queue items
+ if (WriteNextMsg((MsgQueue) (res - 4)))
+ {
+ retryTimeStamp.SetTime(retryTimeout);
+ }
+ break;
}
- break;
- }
}
}
}
@@ -551,18 +454,18 @@ void Driver::DriverThreadProc
++attempts;
uint32 maxAttempts = 0;
- Options::Get()->GetOptionAsInt("DriverMaxAttempts", (int32 *)&maxAttempts);
- if( maxAttempts && (attempts >= maxAttempts) )
+ Options::Get()->GetOptionAsInt("DriverMaxAttempts", (int32 *) &maxAttempts);
+ if (maxAttempts && (attempts >= maxAttempts))
{
Manager::Get()->Manager::SetDriverReady(this, false);
NotifyWatchers();
break;
}
- if( attempts < 25 )
+ if (attempts < 25)
{
// Retry every 5 seconds for the first two minutes
- if( Wait::Single( _exitEvent, 5000 ) == 0 )
+ if (Internal::Platform::Wait::Single(_exitEvent, 5000) == 0)
{
// Exit signalled.
return;
@@ -571,7 +474,7 @@ void Driver::DriverThreadProc
else
{
// Retry every 30 seconds after that
- if( Wait::Single( _exitEvent, 30000 ) == 0 )
+ if (Internal::Platform::Wait::Single(_exitEvent, 30000) == 0)
{
// Exit signalled.
return;
@@ -580,15 +483,11 @@ void Driver::DriverThreadProc
}
}
-
//-----------------------------------------------------------------------------
//
// Initialize the controller
//-----------------------------------------------------------------------------
-bool Driver::Init
-(
- uint32 _attempts
-)
+bool Driver::Init(uint32 _attempts)
{
m_initMutex->Lock();
@@ -602,24 +501,24 @@ bool Driver::Init
m_waitingForAck = false;
// Open the controller
- Log::Write( LogLevel_Info, " Opening controller %s", m_controllerPath.c_str() );
+ Log::Write(LogLevel_Info, " Opening controller %s", m_controllerPath.c_str());
- if( !m_controller->Open( m_controllerPath ) )
+ if (!m_controller->Open(m_controllerPath))
{
- Log::Write( LogLevel_Warning, "WARNING: Failed to init the controller (attempt %d)", _attempts );
+ Log::Write(LogLevel_Warning, "WARNING: Failed to init the controller (attempt %d)", _attempts);
m_initMutex->Unlock();
return false;
}
// Controller opened successfully, so we need to start all the worker threads
- m_pollThread->Start( Driver::PollThreadEntryPoint, this );
+ m_pollThread->Start(Driver::PollThreadEntryPoint, this);
// Send a NAK to the ZWave device
uint8 nak = NAK;
- m_controller->Write( &nak, 1 );
+ m_controller->Write(&nak, 1);
// Get/set ZWave controller information in its preferred initialization order
- m_controller->PlayInitSequence( this );
+ m_controller->PlayInitSequence(this);
//If we ever want promiscuous mode uncomment this code.
//Msg* msg = new Msg( "FUNC_ID_ZW_SET_PROMISCUOUS_MODE", 0xff, REQUEST, FUNC_ID_ZW_SET_PROMISCUOUS_MODE, false, false );
@@ -636,34 +535,31 @@ bool Driver::Init
//
// Clean up any messages to a node
//-----------------------------------------------------------------------------
-void Driver::RemoveQueues
-(
- uint8 const _nodeId
-)
+void Driver::RemoveQueues(uint8 const _nodeId)
{
- if( m_currentMsg != NULL && m_currentMsg->GetTargetNodeId() == _nodeId )
+ if (m_currentMsg != NULL && m_currentMsg->GetTargetNodeId() == _nodeId)
{
RemoveCurrentMsg();
}
// Clear the send Queue
- for( int32 i=0; i::iterator it = m_msgQueue[i].begin();
- while( it != m_msgQueue[i].end() )
+ while (it != m_msgQueue[i].end())
{
bool remove = false;
MsgQueueItem const& item = *it;
- if( MsgQueueCmd_SendMsg == item.m_command && _nodeId == item.m_msg->GetTargetNodeId() )
+ if (MsgQueueCmd_SendMsg == item.m_command && _nodeId == item.m_msg->GetTargetNodeId())
{
delete item.m_msg;
remove = true;
}
- else if( MsgQueueCmd_QueryStageComplete == item.m_command && _nodeId == item.m_nodeId )
+ else if (MsgQueueCmd_QueryStageComplete == item.m_command && _nodeId == item.m_nodeId)
{
remove = true;
}
- else if( MsgQueueCmd_Controller == item.m_command && _nodeId == item.m_cci->m_controllerCommandNode && m_currentControllerCommand != item.m_cci )
+ else if (MsgQueueCmd_Controller == item.m_command && _nodeId == item.m_cci->m_controllerCommandNode && m_currentControllerCommand != item.m_cci)
{
delete item.m_cci;
remove = true;
@@ -672,16 +568,16 @@ void Driver::RemoveQueues
{
remove = true;
}
- if( remove )
+ if (remove)
{
- it = m_msgQueue[i].erase( it );
+ it = m_msgQueue[i].erase(it);
}
else
{
++it;
}
}
- if( m_msgQueue[i].empty() )
+ if (m_msgQueue[i].empty())
{
m_queueEvent[i]->Reset();
}
@@ -696,121 +592,125 @@ void Driver::RemoveQueues
//
// Read our configuration from an XML document
//-----------------------------------------------------------------------------
-bool Driver::ReadCache
-(
-)
+bool Driver::ReadCache()
{
char str[32];
int32 intVal;
// Load the XML document that contains the driver configuration
string userPath;
- Options::Get()->GetOptionAsString( "UserPath", &userPath );
+ Options::Get()->GetOptionAsString("UserPath", &userPath);
- snprintf( str, sizeof(str), "ozwcache_0x%08x.xml", m_homeId );
- string filename = userPath + string(str);
+ snprintf(str, sizeof(str), "ozwcache_0x%08x.xml", m_homeId);
+ string filename = userPath + string(str);
TiXmlDocument doc;
- if( !doc.LoadFile( filename.c_str(), TIXML_ENCODING_UTF8 ) )
+ if (!doc.LoadFile(filename.c_str(), TIXML_ENCODING_UTF8))
{
return false;
}
- doc.SetUserData((void *)filename.c_str());
+ doc.SetUserData((void *) filename.c_str());
TiXmlElement const* driverElement = doc.RootElement();
+ char const *xmlns = driverElement->Attribute("xmlns");
+ if (strcmp(xmlns, "https://github.com/OpenZWave/open-zwave"))
+ {
+ Log::Write(LogLevel_Warning, "Invalid XML Namespace. Ignoring %s", filename.c_str());
+ return false;
+ }
+
// Version
- if( TIXML_SUCCESS != driverElement->QueryIntAttribute( "version", &intVal ) || (uint32)intVal != c_configVersion )
+ if (TIXML_SUCCESS != driverElement->QueryIntAttribute("version", &intVal) || (uint32) intVal != c_configVersion)
{
- Log::Write( LogLevel_Warning, "WARNING: Driver::ReadCache - %s is from an older version of OpenZWave and cannot be loaded.", filename.c_str() );
+ Log::Write(LogLevel_Warning, "WARNING: Driver::ReadCache - %s is from an older version of OpenZWave and cannot be loaded.", filename.c_str());
return false;
}
// Capabilities
- if( TIXML_SUCCESS == driverElement->QueryIntAttribute( "revision", &intVal ) )
+ if (TIXML_SUCCESS == driverElement->QueryIntAttribute("revision", &intVal))
{
m_mfs->setLatestRevision(intVal);
}
-
// Home ID
- char const* homeIdStr = driverElement->Attribute( "home_id" );
- if( homeIdStr )
+ char const* homeIdStr = driverElement->Attribute("home_id");
+ if (homeIdStr)
{
char* p;
- uint32 homeId = (uint32)strtoul( homeIdStr, &p, 0 );
+ uint32 homeId = (uint32) strtoul(homeIdStr, &p, 0);
- if( homeId != m_homeId )
+ if (homeId != m_homeId)
{
- Log::Write( LogLevel_Warning, "WARNING: Driver::ReadCache - Home ID in file %s is incorrect", filename.c_str() );
+ Log::Write(LogLevel_Warning, "WARNING: Driver::ReadCache - Home ID in file %s is incorrect", filename.c_str());
return false;
}
}
else
{
- Log::Write( LogLevel_Warning, "WARNING: Driver::ReadCache - Home ID is missing from file %s", filename.c_str() );
+ Log::Write(LogLevel_Warning, "WARNING: Driver::ReadCache - Home ID is missing from file %s", filename.c_str());
return false;
}
// Node ID
- if( TIXML_SUCCESS == driverElement->QueryIntAttribute( "node_id", &intVal ) )
+ if (TIXML_SUCCESS == driverElement->QueryIntAttribute("node_id", &intVal))
{
- if( (uint8)intVal != m_Controller_nodeId )
+ if ((uint8) intVal != m_Controller_nodeId)
{
- Log::Write( LogLevel_Warning, "WARNING: Driver::ReadCache - Controller Node ID in file %s is incorrect", filename.c_str() );
+ Log::Write(LogLevel_Warning, "WARNING: Driver::ReadCache - Controller Node ID in file %s is incorrect", filename.c_str());
return false;
}
}
else
{
- Log::Write( LogLevel_Warning, "WARNING: Driver::ReadCache - Node ID is missing from file %s", filename.c_str() );
+ Log::Write(LogLevel_Warning, "WARNING: Driver::ReadCache - Node ID is missing from file %s", filename.c_str());
return false;
}
// Capabilities
- if( TIXML_SUCCESS == driverElement->QueryIntAttribute( "api_capabilities", &intVal ) )
+ if (TIXML_SUCCESS == driverElement->QueryIntAttribute("api_capabilities", &intVal))
{
- m_initCaps = (uint8)intVal;
+ m_initCaps = (uint8) intVal;
}
- if( TIXML_SUCCESS == driverElement->QueryIntAttribute( "controller_capabilities", &intVal ) )
+ if (TIXML_SUCCESS == driverElement->QueryIntAttribute("controller_capabilities", &intVal))
{
- m_controllerCaps = (uint8)intVal;
+ m_controllerCaps = (uint8) intVal;
}
// Poll Interval
- if( TIXML_SUCCESS == driverElement->QueryIntAttribute( "poll_interval", &intVal ) )
+ if (TIXML_SUCCESS == driverElement->QueryIntAttribute("poll_interval", &intVal))
{
m_pollInterval = intVal;
}
// Poll Interval--between polls or period for polling the entire pollList?
- char const* cstr = driverElement->Attribute( "poll_interval_between" );
- if( cstr )
+ char const* cstr = driverElement->Attribute("poll_interval_between");
+ if (cstr)
{
- m_bIntervalBetweenPolls = !strcmp( cstr, "true" );
+ m_bIntervalBetweenPolls = !strcmp(cstr, "true");
}
// Read the nodes
- LockGuard LG(m_nodeMutex);
+ Internal::LockGuard LG(m_nodeMutex);
TiXmlElement const* nodeElement = driverElement->FirstChildElement();
- while( nodeElement )
+ while (nodeElement)
{
char const* str = nodeElement->Value();
- if( str && !strcmp( str, "Node" ) )
+ if (str && !strcmp(str, "Node"))
{
// Get the node Id from the XML
- if( TIXML_SUCCESS == nodeElement->QueryIntAttribute( "id", &intVal ) )
+ if (TIXML_SUCCESS == nodeElement->QueryIntAttribute("id", &intVal))
{
- uint8 nodeId = (uint8)intVal;
- Node* node = new Node( m_homeId, nodeId );
+ uint8 nodeId = (uint8) intVal;
+ Node* node = new Node(m_homeId, nodeId);
m_nodes[nodeId] = node;
- Notification* notification = new Notification( Notification::Type_NodeAdded );
- notification->SetHomeAndNodeIds( m_homeId, nodeId );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_NodeAdded);
+ notification->SetHomeAndNodeIds(m_homeId, nodeId);
+ QueueNotification(notification);
// Read the rest of the node configuration from the XML
- node->ReadXML( nodeElement );
+ node->ReadXML(nodeElement);
}
}
@@ -820,16 +720,16 @@ bool Driver::ReadCache
LG.Unlock();
// restore the previous state (for now, polling) for the nodes/values just retrieved
- for( int i=0; i<256; i++ )
+ for (int i = 0; i < 256; i++)
{
- if( m_nodes[i] != NULL )
+ if (m_nodes[i] != NULL)
{
- ValueStore* vs = m_nodes[i]->m_values;
- for( ValueStore::Iterator it = vs->Begin(); it != vs->End(); ++it )
+ Internal::VC::ValueStore* vs = m_nodes[i]->m_values;
+ for (Internal::VC::ValueStore::Iterator it = vs->Begin(); it != vs->End(); ++it)
{
- Value* value = it->second;
- if( value->m_pollIntensity != 0 )
- EnablePoll( value->GetID(), value->m_pollIntensity );
+ Internal::VC::Value* value = it->second;
+ if (value->m_pollIntensity != 0)
+ EnablePoll(value->GetID(), value->m_pollIntensity);
}
}
}
@@ -841,73 +741,75 @@ bool Driver::ReadCache
//
// Write ourselves to an XML document
//-----------------------------------------------------------------------------
-void Driver::WriteCache
-(
-)
+void Driver::WriteCache()
{
char str[32];
- if (!m_homeId) {
- Log::Write( LogLevel_Warning, "WARNING: Tried to write driver config with no home ID set");
+ if (!m_homeId)
+ {
+ Log::Write(LogLevel_Warning, "WARNING: Tried to write driver config with no home ID set");
return;
}
Log::Write(LogLevel_Info, "Saving Cache");
// Create a new XML document to contain the driver configuration
TiXmlDocument doc;
- TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "" );
- TiXmlElement* driverElement = new TiXmlElement( "Driver" );
- doc.LinkEndChild( decl );
- doc.LinkEndChild( driverElement );
+ TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "utf-8", "");
+ TiXmlElement* driverElement = new TiXmlElement("Driver");
+ doc.LinkEndChild(decl);
+ doc.LinkEndChild(driverElement);
- driverElement->SetAttribute( "xmlns", "https://github.com/OpenZWave/open-zwave" );
+ driverElement->SetAttribute("xmlns", "https://github.com/OpenZWave/open-zwave");
- snprintf( str, sizeof(str), "%d", c_configVersion );
- driverElement->SetAttribute( "version", str );
+ snprintf(str, sizeof(str), "%d", c_configVersion);
+ driverElement->SetAttribute("version", str);
- snprintf( str, sizeof(str), "%d", GetManufacturerSpecificDB()->getRevision());
- driverElement->SetAttribute( "revision", str);
+ snprintf(str, sizeof(str), "%d", GetManufacturerSpecificDB()->getRevision());
+ driverElement->SetAttribute("revision", str);
- snprintf( str, sizeof(str), "0x%.8x", m_homeId );
- driverElement->SetAttribute( "home_id", str );
+ snprintf(str, sizeof(str), "0x%.8x", m_homeId);
+ driverElement->SetAttribute("home_id", str);
- snprintf( str, sizeof(str), "%d", m_Controller_nodeId );
- driverElement->SetAttribute( "node_id", str );
+ snprintf(str, sizeof(str), "%d", m_Controller_nodeId);
+ driverElement->SetAttribute("node_id", str);
- snprintf( str, sizeof(str), "%d", m_initCaps );
- driverElement->SetAttribute( "api_capabilities", str );
+ snprintf(str, sizeof(str), "%d", m_initCaps);
+ driverElement->SetAttribute("api_capabilities", str);
- snprintf( str, sizeof(str), "%d", m_controllerCaps );
- driverElement->SetAttribute( "controller_capabilities", str );
+ snprintf(str, sizeof(str), "%d", m_controllerCaps);
+ driverElement->SetAttribute("controller_capabilities", str);
- snprintf( str, sizeof(str), "%d", m_pollInterval );
- driverElement->SetAttribute( "poll_interval", str );
+ snprintf(str, sizeof(str), "%d", m_pollInterval);
+ driverElement->SetAttribute("poll_interval", str);
- snprintf( str, sizeof(str), "%s", m_bIntervalBetweenPolls ? "true" : "false" );
- driverElement->SetAttribute( "poll_interval_between", str );
+ snprintf(str, sizeof(str), "%s", m_bIntervalBetweenPolls ? "true" : "false");
+ driverElement->SetAttribute("poll_interval_between", str);
{
- LockGuard LG(m_nodeMutex);
+ Internal::LockGuard LG(m_nodeMutex);
- for( int i=0; i<256; ++i )
+ for (int i = 0; i < 256; ++i)
{
- if( m_nodes[i] )
+ if (m_nodes[i])
{
- if (m_nodes[i]->GetCurrentQueryStage() == Node::QueryStage_Complete) {
- m_nodes[i]->WriteXML( driverElement );
- Log::Write(LogLevel_Info, i, "Cache Save for Node %d as its QueryStage_Complete", i);
- } else {
- Log::Write(LogLevel_Info, i, "Skipping Cache Save for Node %d as its not QueryStage_Complete", i);
+ if (m_nodes[i]->GetCurrentQueryStage() >= Node::QueryStage_CacheLoad)
+ {
+ m_nodes[i]->WriteXML(driverElement);
+ Log::Write(LogLevel_Info, i, "Cache Save for Node %d as its QueryStage_CacheLoad", i);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, i, "Skipping Cache Save for Node %d as its not past QueryStage_CacheLoad", i);
}
}
}
}
string userPath;
- Options::Get()->GetOptionAsString( "UserPath", &userPath );
+ Options::Get()->GetOptionAsString("UserPath", &userPath);
- snprintf( str, sizeof(str), "ozwcache_0x%08x.xml", m_homeId );
- string filename = userPath + string(str);
+ snprintf(str, sizeof(str), "ozwcache_0x%08x.xml", m_homeId);
+ string filename = userPath + string(str);
- doc.SaveFile( filename.c_str() );
+ doc.SaveFile(filename.c_str());
}
//-----------------------------------------------------------------------------
@@ -919,12 +821,9 @@ void Driver::WriteCache
// Returns a pointer to the requested node without locking.
// Only to be used by main thread code.
//-----------------------------------------------------------------------------
-Node* Driver::GetNodeUnsafe
-(
- uint8 _nodeId
-)
+Node* Driver::GetNodeUnsafe(uint8 _nodeId)
{
- if( Node* node = m_nodes[_nodeId] )
+ if (Node* node = m_nodes[_nodeId])
{
return node;
}
@@ -935,16 +834,14 @@ Node* Driver::GetNodeUnsafe
//
// Locks the nodes and returns a pointer to the requested one
//-----------------------------------------------------------------------------
-Node* Driver::GetNode
-(
- uint8 _nodeId
-)
+Node* Driver::GetNode(uint8 _nodeId)
{
- if (m_nodeMutex->IsSignalled()) {
+ if (m_nodeMutex->IsSignalled())
+ {
Log::Write(LogLevel_Error, _nodeId, "Driver Thread is Not Locked during Call to GetNode");
return NULL;
}
- if( Node* node = m_nodes[_nodeId] )
+ if (Node* node = m_nodes[_nodeId])
{
return node;
}
@@ -960,11 +857,7 @@ Node* Driver::GetNode
//
// Queue an item on the query queue that indicates a stage is complete
//-----------------------------------------------------------------------------
-void Driver::SendQueryStageComplete
-(
- uint8 const _nodeId,
- Node::QueryStage const _stage
-)
+void Driver::SendQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage)
{
MsgQueueItem item;
item.m_command = MsgQueueCmd_QueryStageComplete;
@@ -972,28 +865,28 @@ void Driver::SendQueryStageComplete
item.m_queryStage = _stage;
item.m_retry = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- if( !node->IsListeningDevice() )
+ if (!node->IsListeningDevice())
{
- if( WakeUp* wakeUp = static_cast( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) )
+ if (Internal::CC::WakeUp* wakeUp = static_cast(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
{
- if( !wakeUp->IsAwake() )
+ if (!wakeUp->IsAwake())
{
// If the message is for a sleeping node, we queue it in the node itself.
- Log::Write( LogLevel_Info, "" );
- Log::Write( LogLevel_Detail, node->GetNodeId(), "Queuing (%s) Query Stage Complete (%s)", c_sendQueueNames[MsgQueue_WakeUp], node->GetQueryStageName( _stage ).c_str() );
- wakeUp->QueueMsg( item );
+ Log::Write(LogLevel_Info, "");
+ Log::Write(LogLevel_Detail, node->GetNodeId(), "Queuing (%s) Query Stage Complete (%s)", c_sendQueueNames[MsgQueue_WakeUp], node->GetQueryStageName(_stage).c_str());
+ wakeUp->QueueMsg(item);
return;
}
}
}
// Non-sleeping node
- Log::Write( LogLevel_Detail, node->GetNodeId(), "Queuing (%s) Query Stage Complete (%s)", c_sendQueueNames[MsgQueue_Query], node->GetQueryStageName( _stage ).c_str() );
+ Log::Write(LogLevel_Detail, node->GetNodeId(), "Queuing (%s) Query Stage Complete (%s)", c_sendQueueNames[MsgQueue_Query], node->GetQueryStageName(_stage).c_str());
m_sendMutex->Lock();
- m_msgQueue[MsgQueue_Query].push_back( item );
+ m_msgQueue[MsgQueue_Query].push_back(item);
m_queueEvent[MsgQueue_Query]->Set();
m_sendMutex->Unlock();
@@ -1004,11 +897,7 @@ void Driver::SendQueryStageComplete
//
// Request the current stage will be repeated
//-----------------------------------------------------------------------------
-void Driver::RetryQueryStageComplete
-(
- uint8 const _nodeId,
- Node::QueryStage const _stage
-)
+void Driver::RetryQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage)
{
MsgQueueItem item;
item.m_command = MsgQueueCmd_QueryStageComplete;
@@ -1017,9 +906,9 @@ void Driver::RetryQueryStageComplete
m_sendMutex->Lock();
- for( list::iterator it = m_msgQueue[MsgQueue_Query].begin(); it != m_msgQueue[MsgQueue_Query].end(); ++it )
+ for (list::iterator it = m_msgQueue[MsgQueue_Query].begin(); it != m_msgQueue[MsgQueue_Query].end(); ++it)
{
- if( *it == item )
+ if (*it == item)
{
(*it).m_retry = true;
break;
@@ -1032,11 +921,7 @@ void Driver::RetryQueryStageComplete
//
// Queue a message to be sent to the Z-Wave PC Interface
//-----------------------------------------------------------------------------
-void Driver::SendMsg
-(
- Msg* _msg,
- MsgQueue const _queue
-)
+void Driver::SendMsg(Internal::Msg* _msg, MsgQueue const _queue)
{
MsgQueueItem item;
@@ -1046,52 +931,52 @@ void Driver::SendMsg
_msg->SetHomeId(m_homeId);
_msg->Finalize();
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode(_msg->GetTargetNodeId()) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_msg->GetTargetNodeId()))
{
/* if the node Supports the Security Class - check if this message is meant to be encapsulated */
- if ( node->GetCommandClass(Security::StaticGetCommandClassId()) )
+ if (node->GetCommandClass(Internal::CC::Security::StaticGetCommandClassId()))
{
- CommandClass *cc = node->GetCommandClass(_msg->GetSendingCommandClass());
- if ( (cc) && (cc->IsSecured()) )
+ Internal::CC::CommandClass *cc = node->GetCommandClass(_msg->GetSendingCommandClass());
+ if ((cc) && (cc->IsSecured()))
{
- Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Setting Encryption Flag on Message For Command Class %s", cc->GetCommandClassName().c_str());
+ Log::Write(LogLevel_Detail, GetNodeNumber(_msg), "Setting Encryption Flag on Message For Command Class %s", cc->GetCommandClassName().c_str());
item.m_msg->setEncrypted();
}
}
// If the message is for a sleeping node, we queue it in the node itself.
- if( !node->IsListeningDevice() )
+ if (!node->IsListeningDevice())
{
- if( WakeUp* wakeUp = static_cast( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) )
+ if (Internal::CC::WakeUp* wakeUp = static_cast(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
{
- if( !wakeUp->IsAwake() )
+ if (!wakeUp->IsAwake())
{
- Log::Write( LogLevel_Detail, "" );
+ Log::Write(LogLevel_Detail, "");
// Handle saving multi-step controller commands
- if( m_currentControllerCommand != NULL )
+ if (m_currentControllerCommand != NULL)
{
- Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_Controller], c_controllerCommandNames[m_currentControllerCommand->m_controllerCommand] );
+ Log::Write(LogLevel_Detail, GetNodeNumber(_msg), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_Controller], c_controllerCommandNames[m_currentControllerCommand->m_controllerCommand]);
delete _msg;
item.m_command = MsgQueueCmd_Controller;
- item.m_cci = new ControllerCommandItem( *m_currentControllerCommand );
+ item.m_cci = new ControllerCommandItem(*m_currentControllerCommand);
item.m_msg = NULL;
- UpdateControllerState( ControllerState_Sleeping );
+ UpdateControllerState(ControllerState_Sleeping);
}
else
{
- Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_WakeUp], _msg->GetAsString().c_str() );
+ Log::Write(LogLevel_Detail, GetNodeNumber(_msg), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_WakeUp], _msg->GetAsString().c_str());
}
- wakeUp->QueueMsg( item );
+ wakeUp->QueueMsg(item);
return;
}
}
}
}
}
- Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[_queue], _msg->GetAsString().c_str() );
+ Log::Write(LogLevel_Detail, GetNodeNumber(_msg), "Queuing (%s) %s", c_sendQueueNames[_queue], _msg->GetAsString().c_str());
m_sendMutex->Lock();
- m_msgQueue[_queue].push_back( item );
+ m_msgQueue[_queue].push_back(item);
m_queueEvent[_queue]->Set();
m_sendMutex->Unlock();
}
@@ -1100,101 +985,99 @@ void Driver::SendMsg
//
// Transmit a queued message to the Z-Wave controller
//-----------------------------------------------------------------------------
-bool Driver::WriteNextMsg
-(
- MsgQueue const _queue
-)
+bool Driver::WriteNextMsg(MsgQueue const _queue)
{
// There are messages to send, so get the one at the front of the queue
m_sendMutex->Lock();
MsgQueueItem item = m_msgQueue[_queue].front();
- if( MsgQueueCmd_SendMsg == item.m_command )
+ if (MsgQueueCmd_SendMsg == item.m_command)
{
// Send a message
m_currentMsg = item.m_msg;
m_currentMsgQueueSource = _queue;
m_msgQueue[_queue].pop_front();
- if( m_msgQueue[_queue].empty() )
+ if (m_msgQueue[_queue].empty())
{
m_queueEvent[_queue]->Reset();
}
- if (m_nonceReportSent > 0) {
+ if (m_nonceReportSent > 0)
+ {
MsgQueueItem item_new;
item_new.m_command = MsgQueueCmd_SendMsg;
item_new.m_nodeId = item.m_msg->GetTargetNodeId();
item_new.m_retry = item.m_retry;
- item_new.m_msg = new Msg(*item.m_msg);
+ item_new.m_msg = new Internal::Msg(*item.m_msg);
m_msgQueue[_queue].push_front(item_new);
m_queueEvent[_queue]->Set();
}
m_sendMutex->Unlock();
- return WriteMsg( "WriteNextMsg" );
+ return WriteMsg("WriteNextMsg");
}
- else if( MsgQueueCmd_QueryStageComplete == item.m_command )
+ else if (MsgQueueCmd_QueryStageComplete == item.m_command)
{
// Move to the next query stage
m_currentMsg = NULL;
Node::QueryStage stage = item.m_queryStage;
m_msgQueue[_queue].pop_front();
- if( m_msgQueue[_queue].empty() )
+ if (m_msgQueue[_queue].empty())
{
m_queueEvent[_queue]->Reset();
}
m_sendMutex->Unlock();
- Node* node = GetNodeUnsafe( item.m_nodeId );
- if( node != NULL )
+ Node* node = GetNodeUnsafe(item.m_nodeId);
+ if (node != NULL)
{
- Log::Write( LogLevel_Detail, node->GetNodeId(), "Query Stage Complete (%s)", node->GetQueryStageName( stage ).c_str() );
- if( !item.m_retry )
+ Log::Write(LogLevel_Detail, node->GetNodeId(), "Query Stage Complete (%s)", node->GetQueryStageName(stage).c_str());
+ if (!item.m_retry)
{
- node->QueryStageComplete( stage );
+ node->QueryStageComplete(stage);
}
node->AdvanceQueries();
return true;
}
}
- else if( MsgQueueCmd_Controller == item.m_command )
+ else if (MsgQueueCmd_Controller == item.m_command)
{
// Run a multi-step controller command
m_currentControllerCommand = item.m_cci;
m_sendMutex->Unlock();
// Figure out if done with command
- if ( m_currentControllerCommand->m_controllerCommandDone )
+ if (m_currentControllerCommand->m_controllerCommandDone)
{
m_sendMutex->Lock();
m_msgQueue[_queue].pop_front();
- if( m_msgQueue[_queue].empty() )
+ if (m_msgQueue[_queue].empty())
{
m_queueEvent[_queue]->Reset();
}
m_sendMutex->Unlock();
- if( m_currentControllerCommand->m_controllerCallback )
+ if (m_currentControllerCommand->m_controllerCallback)
{
- m_currentControllerCommand->m_controllerCallback( m_currentControllerCommand->m_controllerState, m_currentControllerCommand->m_controllerReturnError, m_currentControllerCommand->m_controllerCallbackContext );
+ m_currentControllerCommand->m_controllerCallback(m_currentControllerCommand->m_controllerState, m_currentControllerCommand->m_controllerReturnError, m_currentControllerCommand->m_controllerCallbackContext);
}
m_sendMutex->Lock();
delete m_currentControllerCommand;
m_currentControllerCommand = NULL;
m_sendMutex->Unlock();
}
- else if( m_currentControllerCommand->m_controllerState == ControllerState_Normal )
+ else if (m_currentControllerCommand->m_controllerState == ControllerState_Normal)
{
DoControllerCommand();
}
- else if( m_currentControllerCommand->m_controllerStateChanged )
+ else if (m_currentControllerCommand->m_controllerStateChanged)
{
- if( m_currentControllerCommand->m_controllerCallback )
+ if (m_currentControllerCommand->m_controllerCallback)
{
- m_currentControllerCommand->m_controllerCallback( m_currentControllerCommand->m_controllerState, m_currentControllerCommand->m_controllerReturnError, m_currentControllerCommand->m_controllerCallbackContext );
+ m_currentControllerCommand->m_controllerCallback(m_currentControllerCommand->m_controllerState, m_currentControllerCommand->m_controllerReturnError, m_currentControllerCommand->m_controllerCallbackContext);
}
m_currentControllerCommand->m_controllerStateChanged = false;
}
else
{
- Log::Write( LogLevel_Info, "WriteNextMsg Controller nothing to do" );
+ Log::Write(LogLevel_Info, "WriteNextMsg Controller nothing to do");
m_sendMutex->Lock();
m_queueEvent[_queue]->Reset();
m_sendMutex->Unlock();
@@ -1204,7 +1087,7 @@ bool Driver::WriteNextMsg
else if (MsgQueueCmd_ReloadNode == item.m_command)
{
m_msgQueue[_queue].pop_front();
- if( m_msgQueue[_queue].empty() )
+ if (m_msgQueue[_queue].empty())
{
m_queueEvent[_queue]->Reset();
}
@@ -1214,8 +1097,7 @@ bool Driver::WriteNextMsg
/* this will reload the Node, ignoring any cache that exists etc */
ReloadNode(item.m_nodeId);
return true;
-}
-
+ }
return false;
}
@@ -1224,14 +1106,11 @@ bool Driver::WriteNextMsg
//
// Transmit the current message to the Z-Wave controller
//-----------------------------------------------------------------------------
-bool Driver::WriteMsg
-(
- string const &msg
-)
+bool Driver::WriteMsg(string const &msg)
{
- if( !m_currentMsg )
+ if (!m_currentMsg)
{
- Log::Write( LogLevel_Detail, GetNodeNumber( m_currentMsg ), "WriteMsg %s m_currentMsg=%08x", msg.c_str(), m_currentMsg );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), "WriteMsg %s m_currentMsg=%08x", msg.c_str(), m_currentMsg);
// We try not to hang when this happenes
m_expectedCallbackId = 0;
m_expectedCommandClassId = 0;
@@ -1246,31 +1125,35 @@ bool Driver::WriteMsg
*/
uint8 attempts;
uint8 nodeId;
- if (m_nonceReportSent > 0) {
+ if (m_nonceReportSent > 0)
+ {
attempts = m_nonceReportSentAttempt++;
nodeId = m_nonceReportSent;
- } else {
+ }
+ else
+ {
attempts = m_currentMsg->GetSendAttempts();
nodeId = m_currentMsg->GetTargetNodeId();
}
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( nodeId );
- if( attempts >= m_currentMsg->GetMaxSendAttempts() ||
- (node != NULL && !node->IsNodeAlive() && !m_currentMsg->IsNoOperation() ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(nodeId);
+ if (attempts >= m_currentMsg->GetMaxSendAttempts() || (node != NULL && !node->IsNodeAlive() && !m_currentMsg->IsNoOperation()))
{
- if( node != NULL && !node->IsNodeAlive() )
+ if (node != NULL && !node->IsNodeAlive())
{
- Log::Write( LogLevel_Error, nodeId, "ERROR: Dropping command because node is presumed dead" );
+ Log::Write(LogLevel_Error, nodeId, "ERROR: Dropping command because node is presumed dead");
}
else
{
// That's it - already tried to send GetMaxSendAttempt() times.
- Log::Write( LogLevel_Error, nodeId, "ERROR: Dropping command, expected response not received after %d attempt(s)", m_currentMsg->GetMaxSendAttempts() );
+ Log::Write(LogLevel_Error, nodeId, "ERROR: Dropping command, expected response not received after %d attempt(s). Command: \"%s\"",
+ m_currentMsg->GetMaxSendAttempts(),
+ m_currentMsg->GetAsString().c_str());
}
- if( m_currentControllerCommand != NULL )
+ if (m_currentControllerCommand != NULL)
{
/* its a ControllerCommand that is failed */
- UpdateControllerState( ControllerState_Error, ControllerError_Failed);
+ UpdateControllerState(ControllerState_Error, ControllerError_Failed);
}
@@ -1279,7 +1162,7 @@ bool Driver::WriteMsg
return false;
}
- if (( attempts != 0) && (m_nonceReportSent == 0))
+ if ((attempts != 0) && (m_nonceReportSent == 0))
{
// this is not the first attempt, so increment the callback id before sending
m_currentMsg->UpdateCallbackId();
@@ -1290,11 +1173,15 @@ bool Driver::WriteMsg
*
*/
- if (m_nonceReportSent == 0) {
- if (m_currentMsg->isEncrypted() && !m_currentMsg->isNonceRecieved()) {
- m_currentMsg->SetSendAttempts( ++attempts );
- } else if (!m_currentMsg->isEncrypted() ) {
- m_currentMsg->SetSendAttempts( ++attempts );
+ if (m_nonceReportSent == 0)
+ {
+ if (m_currentMsg->isEncrypted() && !m_currentMsg->isNonceRecieved())
+ {
+ m_currentMsg->SetSendAttempts(++attempts);
+ }
+ else if (!m_currentMsg->isEncrypted())
+ {
+ m_currentMsg->SetSendAttempts(++attempts);
}
m_expectedCallbackId = m_currentMsg->GetCallbackId();
m_expectedCommandClassId = m_currentMsg->GetExpectedCommandClassId();
@@ -1303,33 +1190,41 @@ bool Driver::WriteMsg
m_waitingForAck = true;
}
string attemptsstr = "";
- if( attempts > 1 )
+ if (attempts > 1)
{
char buf[15];
- snprintf( buf, sizeof(buf), "Attempt %d, ", attempts );
+ snprintf(buf, sizeof(buf), "Attempt %d, ", attempts);
attemptsstr = buf;
m_retries++;
- if( node != NULL )
+ if (node != NULL)
{
node->m_retries++;
}
}
- Log::Write( LogLevel_Detail, "" );
+ Log::Write(LogLevel_Detail, "");
- if (m_nonceReportSent > 0) {
+ if (m_nonceReportSent > 0 && node != NULL)
+ {
/* send a new NONCE report */
SendNonceKey(m_nonceReportSent, node->GenerateNonceKey());
- } else if (m_currentMsg->isEncrypted()) {
- if (m_currentMsg->isNonceRecieved()) {
- Log::Write( LogLevel_Info, nodeId, "Processing (%s) Encrypted message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x) - %s", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply, m_currentMsg->GetAsString().c_str() );
+ }
+ else if (m_currentMsg->isEncrypted())
+ {
+ if (m_currentMsg->isNonceRecieved())
+ {
+ Log::Write(LogLevel_Info, nodeId, "Processing (%s) Encrypted message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x) - %s", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply, m_currentMsg->GetAsString().c_str());
SendEncryptedMessage();
- } else {
- Log::Write( LogLevel_Info, nodeId, "Processing (%s) Nonce Request message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x)", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, nodeId, "Processing (%s) Nonce Request message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x)", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply);
SendNonceRequest(m_currentMsg->GetLogText());
}
- } else {
- Log::Write( LogLevel_Info, nodeId, "Sending (%s) message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x) - %s", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply, m_currentMsg->GetAsString().c_str() );
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, nodeId, "Sending (%s) message (%sCallback ID=0x%.2x, Expected Reply=0x%.2x) - %s", c_sendQueueNames[m_currentMsgQueueSource], attemptsstr.c_str(), m_expectedCallbackId, m_expectedReply, m_currentMsg->GetAsString().c_str());
uint32 bytesWritten = m_controller->Write(m_currentMsg->GetBuffer(), m_currentMsg->GetLength());
if (bytesWritten == 0)
@@ -1348,20 +1243,20 @@ bool Driver::WriteMsg
}
m_writeCnt++;
- if( nodeId == 0xff )
+ if (nodeId == 0xff)
{
m_broadcastWriteCnt++; // not accurate since library uses 0xff for the controller too
}
else
{
- if( node != NULL )
+ if (node != NULL)
{
node->m_sentCnt++;
node->m_sentTS.SetTime();
- if( m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER )
+ if (m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER)
{
- CommandClass *cc = node->GetCommandClass(m_expectedCommandClassId);
- if( cc != NULL )
+ Internal::CC::CommandClass *cc = node->GetCommandClass(m_expectedCommandClassId);
+ if (cc != NULL)
{
cc->SentCntIncr();
}
@@ -1375,12 +1270,10 @@ bool Driver::WriteMsg
//
// Delete the current message
//-----------------------------------------------------------------------------
-void Driver::RemoveCurrentMsg
-(
-)
+void Driver::RemoveCurrentMsg()
{
- Log::Write( LogLevel_Detail, GetNodeNumber( m_currentMsg ), "Removing current message" );
- if( m_currentMsg != NULL)
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), "Removing current message");
+ if (m_currentMsg != NULL)
{
delete m_currentMsg;
m_currentMsg = NULL;
@@ -1399,54 +1292,50 @@ void Driver::RemoveCurrentMsg
//
// Move messages for a sleeping device to its wake-up queue
//-----------------------------------------------------------------------------
-bool Driver::MoveMessagesToWakeUpQueue
-(
- uint8 const _targetNodeId,
- bool const _move
-)
+bool Driver::MoveMessagesToWakeUpQueue(uint8 const _targetNodeId, bool const _move)
{
// If the target node is one that goes to sleep, transfer
// all messages for it to its Wake-Up queue.
- if( Node* node = GetNodeUnsafe(_targetNodeId) )
+ if (Node* node = GetNodeUnsafe(_targetNodeId))
{
- if( !node->IsListeningDevice() && !node->IsFrequentListeningDevice() && _targetNodeId != m_Controller_nodeId )
+ if (!node->IsListeningDevice() && !node->IsFrequentListeningDevice() && _targetNodeId != m_Controller_nodeId)
{
- if( WakeUp* wakeUp = static_cast( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) )
+ if (Internal::CC::WakeUp* wakeUp = static_cast(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
{
// Mark the node as asleep
- wakeUp->SetAwake( false );
+ wakeUp->SetAwake(false);
// If we need to save the messages
- if( _move )
+ if (_move)
{
// Move all messages for this node to the wake-up queue
m_sendMutex->Lock();
// See if we are working on a controller command
- if( m_currentControllerCommand )
+ if (m_currentControllerCommand)
{
// Don't save controller message as it will be recreated
RemoveCurrentMsg();
}
// Then try the current message first
- if( m_currentMsg )
+ if (m_currentMsg)
{
- if( _targetNodeId == m_currentMsg->GetTargetNodeId() )
+ if (_targetNodeId == m_currentMsg->GetTargetNodeId())
{
// This message is for the unresponsive node
// We do not move any "Wake Up No More Information"
// commands or NoOperations to the pending queue.
- if( !m_currentMsg->IsWakeUpNoMoreInformationCommand() && !m_currentMsg->IsNoOperation() )
+ if (!m_currentMsg->IsWakeUpNoMoreInformationCommand() && !m_currentMsg->IsNoOperation())
{
- Log::Write( LogLevel_Info, _targetNodeId, "Node not responding - moving message to Wake-Up queue: %s", m_currentMsg->GetAsString().c_str() );
+ Log::Write(LogLevel_Info, _targetNodeId, "Node not responding - moving message to Wake-Up queue: %s", m_currentMsg->GetAsString().c_str());
/* reset the sendAttempts */
m_currentMsg->SetSendAttempts(0);
MsgQueueItem item;
item.m_command = MsgQueueCmd_SendMsg;
item.m_msg = m_currentMsg;
- wakeUp->QueueMsg( item );
+ wakeUp->QueueMsg(item);
}
else
{
@@ -1463,26 +1352,26 @@ bool Driver::MoveMessagesToWakeUpQueue
}
// Now the message queues
- for( int i=0; i::iterator it = m_msgQueue[i].begin();
- while( it != m_msgQueue[i].end() )
+ while (it != m_msgQueue[i].end())
{
bool remove = false;
MsgQueueItem const& item = *it;
- if( MsgQueueCmd_SendMsg == item.m_command )
+ if (MsgQueueCmd_SendMsg == item.m_command)
{
- if( _targetNodeId == item.m_msg->GetTargetNodeId() )
+ if (_targetNodeId == item.m_msg->GetTargetNodeId())
{
// This message is for the unresponsive node
// We do not move any "Wake Up No More Information"
// commands or NoOperations to the pending queue.
- if( !item.m_msg->IsWakeUpNoMoreInformationCommand() && !item.m_msg->IsNoOperation() )
+ if (!item.m_msg->IsWakeUpNoMoreInformationCommand() && !item.m_msg->IsNoOperation())
{
- Log::Write( LogLevel_Info, item.m_msg->GetTargetNodeId(), "Node not responding - moving message to Wake-Up queue: %s", item.m_msg->GetAsString().c_str() );
+ Log::Write(LogLevel_Info, item.m_msg->GetTargetNodeId(), "Node not responding - moving message to Wake-Up queue: %s", item.m_msg->GetAsString().c_str());
/* reset any SendAttempts */
item.m_msg->SetSendAttempts(0);
- wakeUp->QueueMsg( item );
+ wakeUp->QueueMsg(item);
}
else
{
@@ -1491,30 +1380,30 @@ bool Driver::MoveMessagesToWakeUpQueue
remove = true;
}
}
- if( MsgQueueCmd_QueryStageComplete == item.m_command )
+ if (MsgQueueCmd_QueryStageComplete == item.m_command)
{
- if( _targetNodeId == item.m_nodeId )
+ if (_targetNodeId == item.m_nodeId)
{
- Log::Write( LogLevel_Info, _targetNodeId, "Node not responding - moving QueryStageComplete command to Wake-Up queue" );
+ Log::Write(LogLevel_Info, _targetNodeId, "Node not responding - moving QueryStageComplete command to Wake-Up queue");
- wakeUp->QueueMsg( item );
+ wakeUp->QueueMsg(item);
remove = true;
}
}
- if( MsgQueueCmd_Controller == item.m_command )
+ if (MsgQueueCmd_Controller == item.m_command)
{
- if( _targetNodeId == item.m_cci->m_controllerCommandNode )
+ if (_targetNodeId == item.m_cci->m_controllerCommandNode)
{
- Log::Write( LogLevel_Info, _targetNodeId, "Node not responding - moving controller command to Wake-Up queue: %s", c_controllerCommandNames[item.m_cci->m_controllerCommand] );
+ Log::Write(LogLevel_Info, _targetNodeId, "Node not responding - moving controller command to Wake-Up queue: %s", c_controllerCommandNames[item.m_cci->m_controllerCommand]);
- wakeUp->QueueMsg( item );
+ wakeUp->QueueMsg(item);
remove = true;
}
}
- if( remove )
+ if (remove)
{
- it = m_msgQueue[i].erase( it );
+ it = m_msgQueue[i].erase(it);
}
else
{
@@ -1523,21 +1412,21 @@ bool Driver::MoveMessagesToWakeUpQueue
}
// If the queue is now empty, we need to clear its event
- if( m_msgQueue[i].empty() )
+ if (m_msgQueue[i].empty())
{
m_queueEvent[i]->Reset();
}
}
- if( m_currentControllerCommand )
+ if (m_currentControllerCommand)
{
// Put command back on queue so it will be cleaned up
- UpdateControllerState( ControllerState_Sleeping );
+ UpdateControllerState(ControllerState_Sleeping);
MsgQueueItem item;
item.m_command = MsgQueueCmd_Controller;
- item.m_cci = new ControllerCommandItem( *m_currentControllerCommand );
+ item.m_cci = new ControllerCommandItem(*m_currentControllerCommand);
m_currentControllerCommand = item.m_cci;
- m_msgQueue[MsgQueue_Controller].push_back( item );
+ m_msgQueue[MsgQueue_Controller].push_back(item);
m_queueEvent[MsgQueue_Controller]->Set();
}
@@ -1559,55 +1448,50 @@ bool Driver::MoveMessagesToWakeUpQueue
// For messages that return a ZW_SEND_DATA response, process the results here
// If it is a non-listeing (sleeping) node return true.
//-----------------------------------------------------------------------------
-bool Driver::HandleErrorResponse
-(
- uint8 const _error,
- uint8 const _nodeId,
- char const* _funcStr,
- bool _sleepCheck // = 0
-)
+bool Driver::HandleErrorResponse(uint8 const _error, uint8 const _nodeId, char const* _funcStr, bool _sleepCheck // = 0
+ )
{
// Only called with a ZW_SEND_DATA error response. We count and output the message here.
- if( _error == TRANSMIT_COMPLETE_NOROUTE )
+ if (_error == TRANSMIT_COMPLETE_NOROUTE)
{
m_badroutes++;
- Log::Write( LogLevel_Info, _nodeId, "ERROR: %s failed. No route available.", _funcStr );
+ Log::Write(LogLevel_Info, _nodeId, "ERROR: %s failed. No route available.", _funcStr);
}
- else if( _error == TRANSMIT_COMPLETE_NO_ACK )
+ else if (_error == TRANSMIT_COMPLETE_NO_ACK)
{
m_noack++;
- Log::Write( LogLevel_Info, _nodeId, "WARNING: %s failed. No ACK received - device may be asleep.", _funcStr );
- if( m_currentMsg )
+ Log::Write(LogLevel_Info, _nodeId, "WARNING: %s failed. No ACK received - device may be asleep.", _funcStr);
+ if (m_currentMsg)
{
// In case the failure is due to the target being a sleeping node, we
// first try to move its pending messages to its wake-up queue.
- if( MoveMessagesToWakeUpQueue( m_currentMsg->GetTargetNodeId(), _sleepCheck ) )
+ if (MoveMessagesToWakeUpQueue(m_currentMsg->GetTargetNodeId(), _sleepCheck))
{
return true;
}
- Log::Write( LogLevel_Warning, _nodeId, "WARNING: Device is not a sleeping node." );
+ Log::Write(LogLevel_Warning, _nodeId, "WARNING: Device is not a sleeping node.");
}
}
- else if( _error == TRANSMIT_COMPLETE_FAIL )
+ else if (_error == TRANSMIT_COMPLETE_FAIL)
{
m_netbusy++;
- Log::Write( LogLevel_Info, _nodeId, "ERROR: %s failed. Network is busy.", _funcStr );
+ Log::Write(LogLevel_Info, _nodeId, "ERROR: %s failed. Network is busy.", _funcStr);
}
- else if( _error == TRANSMIT_COMPLETE_NOT_IDLE )
+ else if (_error == TRANSMIT_COMPLETE_NOT_IDLE)
{
m_notidle++;
- Log::Write( LogLevel_Info, _nodeId, "ERROR: %s failed. Network is busy.", _funcStr );
+ Log::Write(LogLevel_Info, _nodeId, "ERROR: %s failed. Network is busy.", _funcStr);
}
- else if ( _error == TRANSMIT_COMPLETE_VERIFIED )
+ else if (_error == TRANSMIT_COMPLETE_VERIFIED)
{
m_txverified++;
- Log::Write( LogLevel_Info, _nodeId, "ERROR: %s failed. Transmit Verified.", _funcStr );
+ Log::Write(LogLevel_Info, _nodeId, "ERROR: %s failed. Transmit Verified.", _funcStr);
}
- if( Node* node = GetNodeUnsafe( _nodeId ) )
+ if (Node* node = GetNodeUnsafe(_nodeId))
{
- if( ++node->m_errors >= 3 )
+ if (++node->m_errors >= 3)
{
- node->SetNodeAlive( false );
+ node->SetNodeAlive(false);
}
}
return false;
@@ -1617,32 +1501,30 @@ bool Driver::HandleErrorResponse
//
// Identify controller (as opposed to node) commands...especially blocking ones
//-----------------------------------------------------------------------------
-void Driver::CheckCompletedNodeQueries
-(
-)
+void Driver::CheckCompletedNodeQueries()
{
- Log::Write( LogLevel_Warning, "CheckCompletedNodeQueries m_allNodesQueried=%d m_awakeNodesQueried=%d", m_allNodesQueried, m_awakeNodesQueried );
- if( !m_allNodesQueried )
+ Log::Write(LogLevel_Warning, "CheckCompletedNodeQueries m_allNodesQueried=%d m_awakeNodesQueried=%d", m_allNodesQueried, m_awakeNodesQueried);
+ if (!m_allNodesQueried)
{
bool all = true;
bool sleepingOnly = true;
bool deadFound = false;
{
- LockGuard LG(m_nodeMutex);
- for( int i=0; i<256; ++i )
+ Internal::LockGuard LG(m_nodeMutex);
+ for (int i = 0; i < 256; ++i)
{
- if( m_nodes[i] )
+ if (m_nodes[i])
{
- if ( m_nodes[i]->GetCurrentQueryStage() != Node::QueryStage_Complete )
+ if (m_nodes[i]->GetCurrentQueryStage() != Node::QueryStage_Complete)
{
- if( !m_nodes[i]->IsNodeAlive() )
+ if (!m_nodes[i]->IsNodeAlive())
{
deadFound = true;
continue;
}
all = false;
- if( m_nodes[i]->IsListeningDevice() )
+ if (m_nodes[i]->IsListeningDevice())
{
sleepingOnly = false;
}
@@ -1651,37 +1533,37 @@ void Driver::CheckCompletedNodeQueries
}
}
- Log::Write( LogLevel_Warning, "CheckCompletedNodeQueries all=%d, deadFound=%d sleepingOnly=%d", all, deadFound, sleepingOnly );
- if( all )
+ Log::Write(LogLevel_Warning, "CheckCompletedNodeQueries all=%d, deadFound=%d sleepingOnly=%d", all, deadFound, sleepingOnly);
+ if (all)
{
- if( deadFound )
+ if (deadFound)
{
// only dead nodes left to query
- Log::Write( LogLevel_Info, " Node query processing complete except for dead nodes." );
- Notification* notification = new Notification( Notification::Type_AllNodesQueriedSomeDead );
- notification->SetHomeAndNodeIds( m_homeId, 0xff );
- QueueNotification( notification );
+ Log::Write(LogLevel_Info, " Node query processing complete except for dead nodes.");
+ Notification* notification = new Notification(Notification::Type_AllNodesQueriedSomeDead);
+ notification->SetHomeAndNodeIds(m_homeId, 0xff);
+ QueueNotification(notification);
}
else
{
// no sleeping nodes, no dead nodes and no more nodes in the queue, so...All done
- Log::Write( LogLevel_Info, " Node query processing complete." );
- Notification* notification = new Notification( Notification::Type_AllNodesQueried );
- notification->SetHomeAndNodeIds( m_homeId, 0xff );
- QueueNotification( notification );
+ Log::Write(LogLevel_Info, " Node query processing complete.");
+ Notification* notification = new Notification(Notification::Type_AllNodesQueried);
+ notification->SetHomeAndNodeIds(m_homeId, 0xff);
+ QueueNotification(notification);
}
m_awakeNodesQueried = true;
m_allNodesQueried = true;
}
- else if( sleepingOnly )
+ else if (sleepingOnly)
{
- if (!m_awakeNodesQueried )
+ if (!m_awakeNodesQueried)
{
// only sleeping nodes remain, so signal awake nodes queried complete
- Log::Write( LogLevel_Info, " Node query processing complete except for sleeping nodes." );
- Notification* notification = new Notification( Notification::Type_AwakeNodesQueried );
- notification->SetHomeAndNodeIds( m_homeId, 0xff );
- QueueNotification( notification );
+ Log::Write(LogLevel_Info, " Node query processing complete except for sleeping nodes.");
+ Notification* notification = new Notification(Notification::Type_AwakeNodesQueried);
+ notification->SetHomeAndNodeIds(m_homeId, 0xff);
+ QueueNotification(notification);
m_awakeNodesQueried = true;
}
}
@@ -1693,37 +1575,25 @@ void Driver::CheckCompletedNodeQueries
//
// Determine if the reply is from the node we are expecting.
//-----------------------------------------------------------------------------
-bool Driver::IsExpectedReply
-(
- const uint8 _nodeId
-)
+bool Driver::IsExpectedReply(const uint8 _nodeId)
{
// Accept all controller commands or where the protocol doesn't identify the actual node
- if( m_expectedNodeId == 255 || _nodeId == 0 )
+ if (m_expectedNodeId == 255 || _nodeId == 0)
{
return true;
}
// Accept all messages that do not convey source node identification.
- if( m_expectedReply == FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO ||
- m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_INFO ||
- m_expectedReply == FUNC_ID_ZW_GET_ROUTING_INFO ||
- m_expectedReply == FUNC_ID_ZW_ASSIGN_RETURN_ROUTE ||
- m_expectedReply == FUNC_ID_ZW_DELETE_RETURN_ROUTE ||
- m_expectedReply == FUNC_ID_ZW_SEND_DATA ||
- m_expectedReply == FUNC_ID_ZW_SEND_NODE_INFORMATION ||
- m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE ||
- m_expectedReply == FUNC_ID_ZW_ENABLE_SUC ||
- m_expectedReply == FUNC_ID_ZW_SET_SUC_NODE_ID ||
- m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS )
+ if (m_expectedReply == FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO || m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_INFO || m_expectedReply == FUNC_ID_ZW_GET_ROUTING_INFO || m_expectedReply == FUNC_ID_ZW_ASSIGN_RETURN_ROUTE || m_expectedReply == FUNC_ID_ZW_DELETE_RETURN_ROUTE || m_expectedReply == FUNC_ID_ZW_SEND_DATA || m_expectedReply == FUNC_ID_ZW_SEND_NODE_INFORMATION || m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE || m_expectedReply == FUNC_ID_ZW_ENABLE_SUC
+ || m_expectedReply == FUNC_ID_ZW_SET_SUC_NODE_ID || m_expectedReply == FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS)
{
return true;
}
// Accept if source message contains node info and it is from the one we are expecting
- if( m_expectedNodeId == _nodeId )
+ if (m_expectedNodeId == _nodeId)
{
return true;
}
- Log::Write( LogLevel_Detail, "IsExpectedReply: m_expectedNodeId = %d m_expectedReply = %02x", m_expectedNodeId, m_expectedReply );
+ Log::Write(LogLevel_Detail, "IsExpectedReply: m_expectedNodeId = %d m_expectedReply = %02x", m_expectedNodeId, m_expectedReply);
return false;
}
//-----------------------------------------------------------------------------
@@ -1734,166 +1604,164 @@ bool Driver::IsExpectedReply
//
// Read data from the serial port
//-----------------------------------------------------------------------------
-bool Driver::ReadMsg
-(
-)
+bool Driver::ReadMsg()
{
uint8 buffer[1024];
- memset(buffer, 0, sizeof(uint8)* 1024);
+ memset(buffer, 0, sizeof(uint8) * 1024);
- if( !m_controller->Read( buffer, 1 ) )
+ if (!m_controller->Read(buffer, 1))
{
// Nothing to read
return false;
}
- switch( buffer[0] )
+ switch (buffer[0])
{
- case SOF:
- {
- m_SOFCnt++;
- if( m_waitingForAck )
+ case SOF:
{
- // This can happen on any normal network when a transmission overlaps an unexpected
- // reception and the data in the buffer doesn't contain the ACK. The controller will
- // notice and send us a CAN to retransmit.
- Log::Write( LogLevel_Detail, "Unsolicited message received while waiting for ACK." );
- m_ACKWaiting++;
- }
+ m_SOFCnt++;
+ if (m_waitingForAck)
+ {
+ // This can happen on any normal network when a transmission overlaps an unexpected
+ // reception and the data in the buffer doesn't contain the ACK. The controller will
+ // notice and send us a CAN to retransmit.
+ Log::Write(LogLevel_Detail, "Unsolicited message received while waiting for ACK.");
+ m_ACKWaiting++;
+ }
- // Read the length byte. Keep trying until we get it.
- m_controller->SetSignalThreshold( 1 );
- int32 response = Wait::Single( m_controller, 50 );
- if( response < 0 )
- {
- Log::Write( LogLevel_Warning, "WARNING: 50ms passed without finding the length byte...aborting frame read");
- m_readAborts++;
- break;
- }
+ // Read the length byte. Keep trying until we get it.
+ m_controller->SetSignalThreshold(1);
+ int32 response = Internal::Platform::Wait::Single(m_controller, 50);
+ if (response < 0)
+ {
+ Log::Write(LogLevel_Warning, "WARNING: 50ms passed without finding the length byte...aborting frame read");
+ m_readAborts++;
+ break;
+ }
- m_controller->Read( &buffer[1], 1 );
- m_controller->SetSignalThreshold( buffer[1] );
- if( Wait::Single( m_controller, 500 ) < 0 )
- {
- Log::Write( LogLevel_Warning, "WARNING: 500ms passed without reading the rest of the frame...aborting frame read" );
- m_readAborts++;
- m_controller->SetSignalThreshold( 1 );
- break;
- }
+ m_controller->Read(&buffer[1], 1);
+ m_controller->SetSignalThreshold(buffer[1]);
+ if (Internal::Platform::Wait::Single(m_controller, 500) < 0)
+ {
+ Log::Write(LogLevel_Warning, "WARNING: 500ms passed without reading the rest of the frame...aborting frame read");
+ m_readAborts++;
+ m_controller->SetSignalThreshold(1);
+ break;
+ }
- m_controller->Read( &buffer[2], buffer[1] );
- m_controller->SetSignalThreshold( 1 );
+ m_controller->Read(&buffer[2], buffer[1]);
+ m_controller->SetSignalThreshold(1);
- uint32 length = buffer[1] + 2;
+ uint32 length = buffer[1] + 2;
- // Log the data
- string str = "";
- for( uint32 i=0; iWrite( &ack, 1 );
- m_readCnt++;
+ if (buffer[length - 1] == checksum)
+ {
+ // Checksum correct - send ACK
+ uint8 ack = ACK;
+ m_controller->Write(&ack, 1);
+ m_readCnt++;
- // Process the received message
- ProcessMsg( &buffer[2], length-2 );
- }
- else
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Checksum incorrect - sending NAK" );
- m_badChecksum++;
- uint8 nak = NAK;
- m_controller->Write( &nak, 1 );
- m_controller->Purge();
+ // Process the received message
+ ProcessMsg(&buffer[2], length - 2);
+ }
+ else
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Checksum incorrect - sending NAK");
+ m_badChecksum++;
+ uint8 nak = NAK;
+ m_controller->Write(&nak, 1);
+ m_controller->Purge();
+ }
+ break;
}
- break;
- }
- case CAN:
- {
- // This is the other side of an unsolicited ACK. As mentioned there if we receive a message
- // just after we transmitted one, the controller will notice and tell us to retransmit here.
- // Don't increment the transmission counter as it is possible the message will never get out
- // on very busy networks with lots of unsolicited messages being received. Increase the amount
- // of retries but only up to a limit so we don't stay here forever.
- Log::Write( LogLevel_Detail, GetNodeNumber( m_currentMsg ), "CAN received...triggering resend" );
- m_CANCnt++;
- if( m_currentMsg != NULL )
- {
- m_currentMsg->SetMaxSendAttempts( m_currentMsg->GetMaxSendAttempts() + 1 );
- }
- else
+ case CAN:
{
- Log::Write( LogLevel_Warning, "m_currentMsg was NULL when trying to set MaxSendAttempts" );
- Log::QueueDump();
+ // This is the other side of an unsolicited ACK. As mentioned there if we receive a message
+ // just after we transmitted one, the controller will notice and tell us to retransmit here.
+ // Don't increment the transmission counter as it is possible the message will never get out
+ // on very busy networks with lots of unsolicited messages being received. Increase the amount
+ // of retries but only up to a limit so we don't stay here forever.
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), "CAN received...triggering resend");
+ m_CANCnt++;
+ if (m_currentMsg != NULL)
+ {
+ m_currentMsg->SetMaxSendAttempts(m_currentMsg->GetMaxSendAttempts() + 1);
+ }
+ else
+ {
+ Log::Write(LogLevel_Warning, "m_currentMsg was NULL when trying to set MaxSendAttempts");
+ Log::QueueDump();
+ }
+ WriteMsg("CAN");
+ break;
}
- WriteMsg( "CAN" );
- break;
- }
- case NAK:
- {
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: NAK received...triggering resend" );
- m_NAKCnt++;
- WriteMsg( "NAK" );
- break;
- }
-
- case ACK:
- {
- m_ACKCnt++;
- m_waitingForAck = false;
- if( m_currentMsg == NULL )
+ case NAK:
{
- Log::Write( LogLevel_StreamDetail, 255, " ACK received" );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: NAK received...triggering resend");
+ m_NAKCnt++;
+ WriteMsg("NAK");
+ break;
}
- else
+
+ case ACK:
{
- Log::Write( LogLevel_StreamDetail, GetNodeNumber( m_currentMsg ), " ACK received CallbackId 0x%.2x Reply 0x%.2x", m_expectedCallbackId, m_expectedReply );
- if( ( 0 == m_expectedCallbackId ) && ( 0 == m_expectedReply ) )
+ m_ACKCnt++;
+ m_waitingForAck = false;
+ if (m_currentMsg == NULL)
{
- // Remove the message from the queue, now that it has been acknowledged.
- RemoveCurrentMsg();
+ Log::Write(LogLevel_StreamDetail, 255, " ACK received");
+ }
+ else
+ {
+ Log::Write(LogLevel_StreamDetail, GetNodeNumber(m_currentMsg), " ACK received CallbackId 0x%.2x Reply 0x%.2x", m_expectedCallbackId, m_expectedReply);
+ if ((0 == m_expectedCallbackId) && (0 == m_expectedReply))
+ {
+ // Remove the message from the queue, now that it has been acknowledged.
+ RemoveCurrentMsg();
+ }
}
+ break;
}
- break;
- }
- default:
- {
- Log::Write( LogLevel_Warning, "WARNING: Out of frame flow! (0x%.2x). Sending NAK.", buffer[0] );
- m_OOFCnt++;
- uint8 nak = NAK;
- m_controller->Write( &nak, 1 );
- m_controller->Purge();
- break;
- }
+ default:
+ {
+ Log::Write(LogLevel_Warning, "WARNING: Out of frame flow! (0x%.2x). Sending NAK.", buffer[0]);
+ m_OOFCnt++;
+ uint8 nak = NAK;
+ m_controller->Write(&nak, 1);
+ m_controller->Purge();
+ break;
+ }
}
return true;
@@ -1903,24 +1771,22 @@ bool Driver::ReadMsg
//
// Process data received from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::ProcessMsg
-(
- uint8* _data,
- uint8 _length
-)
+void Driver::ProcessMsg(uint8* _data, uint8 _length)
{
bool handleCallback = true;
bool wasencrypted = false;
//uint8 nodeId = GetNodeNumber( m_currentMsg );
- if ((REQUEST == _data[0]) &&
- (Security::StaticGetCommandClassId() == _data[5])) {
+ if ((REQUEST == _data[0]) && FUNC_ID_APPLICATION_COMMAND_HANDLER == _data[1] && (Internal::CC::Security::StaticGetCommandClassId() == _data[5]))
+ {
/* if this message is a NONCE Report - Then just Trigger the Encrypted Send */
- if (SecurityCmd_NonceReport == _data[6]) {
- Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_NonceReport from node %d", _data[3] );
+ if (Internal::CC::SecurityCmd_NonceReport == _data[6])
+ {
+ Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_NonceReport from node %d", _data[3]);
/* handle possible resends of NONCE_REPORT messages.... See Issue #931 */
- if (!m_currentMsg) {
+ if (!m_currentMsg)
+ {
Log::Write(LogLevel_Warning, _data[3], "Received a NonceReport from node, but no pending messages. Dropping..");
return;
}
@@ -1931,15 +1797,20 @@ void Driver::ProcessMsg
return;
/* if this is a NONCE Get - Then call to the CC directly, process it, and then bail out. */
- } else if (SecurityCmd_NonceGet == _data[6]) {
- Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_NonceGet from node %d", _data[3] );
+ }
+ else if (Internal::CC::SecurityCmd_NonceGet == _data[6])
+ {
+ Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_NonceGet from node %d", _data[3]);
{
uint8 *nonce = NULL;
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( _data[3] );
- if( node ) {
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(_data[3]);
+ if (node)
+ {
nonce = node->GenerateNonceKey();
- } else {
+ }
+ else
+ {
Log::Write(LogLevel_Warning, _data[3], "Couldn't Generate Nonce Key for Node %d", _data[3]);
return;
}
@@ -1951,7 +1822,9 @@ void Driver::ProcessMsg
return;
/* if this message is encrypted, decrypt it first */
- } else if ((SecurityCmd_MessageEncap == _data[6]) || (SecurityCmd_MessageEncapNonceGet == _data[6])) {
+ }
+ else if ((Internal::CC::SecurityCmd_MessageEncap == _data[6]) || (Internal::CC::SecurityCmd_MessageEncapNonceGet == _data[6]))
+ {
uint8 _newdata[256];
uint8 SecurityCmd = _data[6];
uint8 *_nonce;
@@ -1962,20 +1835,25 @@ void Driver::ProcessMsg
/* make sure the Node Exists, and it has the Security CC */
{
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( _data[3] );
- if( node ) {
- _nonce = node->GetNonceKey(_data[_data[4]-4]);
- if (!_nonce) {
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(_data[3]);
+ if (node)
+ {
+ _nonce = node->GetNonceKey(_data[_data[4] - 4]);
+ if (!_nonce)
+ {
Log::Write(LogLevel_Warning, _data[3], "Could Not Retrieve Nonce for Node %d", _data[3]);
return;
}
- } else {
+ }
+ else
+ {
Log::Write(LogLevel_Warning, _data[3], "Can't Find Node %d for Encrypted Message", _data[3]);
return;
}
}
- if (DecryptBuffer(&_data[5], _data[4]+1, this, _data[3], this->GetControllerNodeId(), _nonce, &_newdata[0])) {
+ if (Internal::DecryptBuffer(&_data[5], _data[4] + 1, this, _data[3], this->GetControllerNodeId(), _nonce, &_newdata[0]))
+ {
/* Ok - _newdata now contains the decrypted packet */
/* copy it back to the _data packet for processing */
/* New Length - See Decrypt Packet for why these numbers*/
@@ -1986,14 +1864,17 @@ void Driver::ProcessMsg
//PrintHex("Decrypted Packet", _data, _data[4]+5);
/* if the Node has something else to send, it will encrypt a message and send it as a MessageEncapNonceGet */
- if (SecurityCmd_MessageEncapNonceGet == SecurityCmd )
+ if (Internal::CC::SecurityCmd_MessageEncapNonceGet == SecurityCmd)
{
- Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_MessageEncapNonceGet from node %d - Sending New Nonce", _data[3] );
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( _data[3] );
- if( node ) {
+ Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_MessageEncapNonceGet from node %d - Sending New Nonce", _data[3]);
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(_data[3]);
+ if (node)
+ {
_nonce = node->GenerateNonceKey();
- } else {
+ }
+ else
+ {
Log::Write(LogLevel_Warning, _data[3], "Couldn't Generate Nonce Key for Node %d", _data[3]);
return;
}
@@ -2002,16 +1883,21 @@ void Driver::ProcessMsg
wasencrypted = true;
- } else {
+ }
+ else
+ {
/* if the Node has something else to send, it will encrypt a message and send it as a MessageEncapNonceGet */
- if (SecurityCmd_MessageEncapNonceGet == SecurityCmd )
+ if (Internal::CC::SecurityCmd_MessageEncapNonceGet == SecurityCmd)
{
- Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_MessageEncapNonceGet from node %d - Sending New Nonce", _data[3] );
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( _data[3] );
- if( node ) {
+ Log::Write(LogLevel_Info, _data[3], "Received SecurityCmd_MessageEncapNonceGet from node %d - Sending New Nonce", _data[3]);
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(_data[3]);
+ if (node)
+ {
_nonce = node->GenerateNonceKey();
- } else {
+ }
+ else
+ {
Log::Write(LogLevel_Warning, _data[3], "Couldn't Generate Nonce Key for Node %d", _data[3]);
return;
}
@@ -2026,452 +1912,458 @@ void Driver::ProcessMsg
}
}
-
- if( RESPONSE == _data[0] )
+ if ( RESPONSE == _data[0])
{
- switch( _data[1] )
- {
- case FUNC_ID_SERIAL_API_GET_INIT_DATA:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSerialAPIGetInitDataResponse( _data );
- break;
- }
- case FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetControllerCapabilitiesResponse( _data );
- break;
- }
- case FUNC_ID_SERIAL_API_GET_CAPABILITIES:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetSerialAPICapabilitiesResponse( _data );
- break;
- }
- case FUNC_ID_SERIAL_API_SOFT_RESET:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSerialAPISoftResetResponse( _data );
- break;
- }
- case FUNC_ID_ZW_SEND_DATA:
- {
- HandleSendDataResponse( _data, false );
- handleCallback = false; // Skip the callback handling - a subsequent FUNC_ID_ZW_SEND_DATA request will deal with that
- break;
- }
- case FUNC_ID_ZW_GET_VERSION:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetVersionResponse( _data );
- break;
- }
- case FUNC_ID_ZW_GET_RANDOM:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetRandomResponse( _data );
- break;
- }
- case FUNC_ID_SERIAL_API_SETUP:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSerialAPISetupResponse( _data );
- break;
- }
- case FUNC_ID_ZW_MEMORY_GET_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleMemoryGetIdResponse( _data );
- break;
- }
- case FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetNodeProtocolInfoResponse( _data );
- break;
- }
- case FUNC_ID_ZW_REPLICATION_SEND_DATA:
+ switch (_data[1])
{
- HandleSendDataResponse( _data, true );
- handleCallback = false; // Skip the callback handling - a subsequent FUNC_ID_ZW_REPLICATION_SEND_DATA request will deal with that
- break;
- }
- case FUNC_ID_ZW_ASSIGN_RETURN_ROUTE:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleAssignReturnRouteResponse( _data ) )
+ case FUNC_ID_SERIAL_API_GET_INIT_DATA:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleSerialAPIGetInitDataResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_DELETE_RETURN_ROUTE:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleDeleteReturnRouteResponse( _data ) )
+ case FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleGetControllerCapabilitiesResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_ENABLE_SUC:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleEnableSUCResponse( _data );
- break;
- }
- case FUNC_ID_ZW_REQUEST_NETWORK_UPDATE:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleNetworkUpdateResponse( _data ) )
+ case FUNC_ID_SERIAL_API_GET_CAPABILITIES:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleGetSerialAPICapabilitiesResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_SET_SUC_NODE_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSetSUCNodeIdResponse( _data );
- break;
- }
- case FUNC_ID_ZW_GET_SUC_NODE_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetSUCNodeIdResponse( _data );
- break;
- }
- case FUNC_ID_ZW_REQUEST_NODE_INFO:
- {
- Log::Write( LogLevel_Detail, "" );
- if( _data[2] )
+ case FUNC_ID_SERIAL_API_SOFT_RESET:
{
- Log::Write( LogLevel_Info, _data[3], "FUNC_ID_ZW_REQUEST_NODE_INFO Request successful." );
+ Log::Write(LogLevel_Detail, "");
+ HandleSerialAPISoftResetResponse(_data);
+ break;
}
- else
+ case FUNC_ID_ZW_SEND_DATA:
{
- Log::Write( LogLevel_Info, _data[3], "FUNC_ID_ZW_REQUEST_NODE_INFO Request failed." );
+ HandleSendDataResponse(_data, false);
+ handleCallback = false; // Skip the callback handling - a subsequent FUNC_ID_ZW_SEND_DATA request will deal with that
+ break;
}
- break;
- }
- case FUNC_ID_ZW_REMOVE_FAILED_NODE_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleRemoveFailedNodeResponse( _data ) )
+ case FUNC_ID_ZW_GET_VERSION:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleGetVersionResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_IS_FAILED_NODE_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleIsFailedNodeResponse( _data );
- break;
- }
- case FUNC_ID_ZW_REPLACE_FAILED_NODE:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleReplaceFailedNodeResponse( _data ) )
+ case FUNC_ID_ZW_GET_RANDOM:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleGetRandomResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_GET_ROUTING_INFO:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetRoutingInfoResponse( _data );
- break;
- }
- case FUNC_ID_ZW_R_F_POWER_LEVEL_SET:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleRfPowerLevelSetResponse( _data );
- break;
- }
- case FUNC_ID_ZW_READ_MEMORY:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleReadMemoryResponse( _data );
- break;
- }
- case FUNC_ID_SERIAL_API_SET_TIMEOUTS:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSerialApiSetTimeoutsResponse( _data );
- break;
- }
- case FUNC_ID_MEMORY_GET_BYTE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleMemoryGetByteResponse( _data );
- break;
- }
- case FUNC_ID_ZW_GET_VIRTUAL_NODES:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleGetVirtualNodesResponse( _data );
- break;
- }
- case FUNC_ID_ZW_SET_SLAVE_LEARN_MODE:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleSetSlaveLearnModeResponse( _data ) )
+ case FUNC_ID_SERIAL_API_SETUP:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleSerialAPISetupResponse(_data);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_SEND_SLAVE_NODE_INFO:
- {
- Log::Write( LogLevel_Detail, "" );
- if( !HandleSendSlaveNodeInfoResponse( _data ) )
+ case FUNC_ID_ZW_MEMORY_GET_ID:
{
- m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
- m_expectedReply = 0;
- m_expectedCommandClassId = 0;
- m_expectedNodeId = 0;
+ Log::Write(LogLevel_Detail, "");
+ HandleMemoryGetIdResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleGetNodeProtocolInfoResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REPLICATION_SEND_DATA:
+ {
+ HandleSendDataResponse(_data, true);
+ handleCallback = false; // Skip the callback handling - a subsequent FUNC_ID_ZW_REPLICATION_SEND_DATA request will deal with that
+ break;
+ }
+ case FUNC_ID_ZW_ASSIGN_RETURN_ROUTE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleAssignReturnRouteResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_DELETE_RETURN_ROUTE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleDeleteReturnRouteResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_ENABLE_SUC:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleEnableSUCResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REQUEST_NETWORK_UPDATE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleNetworkUpdateResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_SET_SUC_NODE_ID:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSetSUCNodeIdResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_GET_SUC_NODE_ID:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleGetSUCNodeIdResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REQUEST_NODE_INFO:
+ {
+ // This code used _data[3] to log Node ID
+ // but FUNC_ID_ZW_REQUEST_NODE_INFO reply does not report back node number.
+ Log::Write(LogLevel_Detail, "");
+ if (_data[2])
+ {
+
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "FUNC_ID_ZW_REQUEST_NODE_INFO Request successful.");
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "FUNC_ID_ZW_REQUEST_NODE_INFO Request failed.");
+ }
+ break;
+ }
+ case FUNC_ID_ZW_REMOVE_FAILED_NODE_ID:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleRemoveFailedNodeResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_IS_FAILED_NODE_ID:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleIsFailedNodeResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REPLACE_FAILED_NODE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleReplaceFailedNodeResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_GET_ROUTING_INFO:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleGetRoutingInfoResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_R_F_POWER_LEVEL_SET:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleRfPowerLevelSetResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_READ_MEMORY:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleReadMemoryResponse(_data);
+ break;
+ }
+ case FUNC_ID_SERIAL_API_SET_TIMEOUTS:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSerialApiSetTimeoutsResponse(_data);
+ break;
+ }
+ case FUNC_ID_MEMORY_GET_BYTE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleMemoryGetByteResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_GET_VIRTUAL_NODES:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleGetVirtualNodesResponse(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SET_SLAVE_LEARN_MODE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleSetSlaveLearnModeResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ case FUNC_ID_ZW_SEND_SLAVE_NODE_INFO:
+ {
+ Log::Write(LogLevel_Detail, "");
+ if (!HandleSendSlaveNodeInfoResponse(_data))
+ {
+ m_expectedCallbackId = _data[2]; // The callback message won't be coming, so we force the transaction to complete
+ m_expectedReply = 0;
+ m_expectedCommandClassId = 0;
+ m_expectedNodeId = 0;
+ }
+ break;
+ }
+ /* Ignore these. They are manufacturer proprietary */
+ case FUNC_ID_PROPRIETARY_0:
+ case FUNC_ID_PROPRIETARY_1:
+ case FUNC_ID_PROPRIETARY_2:
+ case FUNC_ID_PROPRIETARY_3:
+ case FUNC_ID_PROPRIETARY_4:
+ case FUNC_ID_PROPRIETARY_5:
+ case FUNC_ID_PROPRIETARY_6:
+ case FUNC_ID_PROPRIETARY_7:
+ case FUNC_ID_PROPRIETARY_8:
+ case FUNC_ID_PROPRIETARY_9:
+ case FUNC_ID_PROPRIETARY_A:
+ case FUNC_ID_PROPRIETARY_B:
+ case FUNC_ID_PROPRIETARY_C:
+ case FUNC_ID_PROPRIETARY_D:
+ case FUNC_ID_PROPRIETARY_E:
+ {
+ break;
+ }
+ default:
+ {
+ Log::Write(LogLevel_Detail, "");
+ Log::Write(LogLevel_Info, "**TODO: handle response for 0x%.2x** Please report this message.", _data[1]);
+ break;
}
- break;
- }
- /* Ignore these. They are manufacturer proprietary */
- case FUNC_ID_PROPRIETARY_0:
- case FUNC_ID_PROPRIETARY_1:
- case FUNC_ID_PROPRIETARY_2:
- case FUNC_ID_PROPRIETARY_3:
- case FUNC_ID_PROPRIETARY_4:
- case FUNC_ID_PROPRIETARY_5:
- case FUNC_ID_PROPRIETARY_6:
- case FUNC_ID_PROPRIETARY_7:
- case FUNC_ID_PROPRIETARY_8:
- case FUNC_ID_PROPRIETARY_9:
- case FUNC_ID_PROPRIETARY_A:
- case FUNC_ID_PROPRIETARY_B:
- case FUNC_ID_PROPRIETARY_C:
- case FUNC_ID_PROPRIETARY_D:
- case FUNC_ID_PROPRIETARY_E:
- {
- break;
- }
- default:
- {
- Log::Write( LogLevel_Detail, "" );
- Log::Write( LogLevel_Info, "**TODO: handle response for 0x%.2x** Please report this message.", _data[1] );
- break;
- }
}
}
- else if( REQUEST == _data[0] )
+ else if ( REQUEST == _data[0])
{
- switch( _data[1] )
- {
- case FUNC_ID_APPLICATION_COMMAND_HANDLER:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleApplicationCommandHandlerRequest( _data, wasencrypted );
- break;
- }
- case FUNC_ID_ZW_SEND_DATA:
- {
- HandleSendDataRequest( _data, _length, false );
- break;
- }
- case FUNC_ID_ZW_REPLICATION_COMMAND_COMPLETE:
+ switch (_data[1])
{
- if( m_controllerReplication )
+ case FUNC_ID_APPLICATION_COMMAND_HANDLER:
{
- Log::Write( LogLevel_Detail, "" );
- m_controllerReplication->SendNextData();
+ Log::Write(LogLevel_Detail, "");
+ HandleApplicationCommandHandlerRequest(_data, wasencrypted);
+ break;
+ }
+ case FUNC_ID_ZW_SEND_DATA:
+ {
+ HandleSendDataRequest(_data, _length, false);
+ break;
+ }
+ case FUNC_ID_ZW_REPLICATION_COMMAND_COMPLETE:
+ {
+ if (m_controllerReplication)
+ {
+ Log::Write(LogLevel_Detail, "");
+ m_controllerReplication->SendNextData();
+ }
+ break;
+ }
+ case FUNC_ID_ZW_REPLICATION_SEND_DATA:
+ {
+ HandleSendDataRequest(_data, _length, true);
+ break;
+ }
+ case FUNC_ID_ZW_ASSIGN_RETURN_ROUTE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleAssignReturnRouteRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_DELETE_RETURN_ROUTE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleDeleteReturnRouteRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SEND_NODE_INFORMATION:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSendNodeInformationRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE:
+ case FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleNodeNeighborUpdateRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_APPLICATION_UPDATE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ handleCallback = !HandleApplicationUpdateRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_ADD_NODE_TO_NETWORK:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleAddNodeToNetworkRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleRemoveNodeFromNetworkRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_CREATE_NEW_PRIMARY:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleCreateNewPrimaryRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_CONTROLLER_CHANGE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleControllerChangeRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SET_LEARN_MODE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSetLearnModeRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REQUEST_NETWORK_UPDATE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleNetworkUpdateRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REMOVE_FAILED_NODE_ID:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleRemoveFailedNodeRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_REPLACE_FAILED_NODE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleReplaceFailedNodeRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SET_SLAVE_LEARN_MODE:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSetSlaveLearnModeRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SEND_SLAVE_NODE_INFO:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSendSlaveNodeInfoRequest(_data);
+ break;
+ }
+ case FUNC_ID_APPLICATION_SLAVE_COMMAND_HANDLER:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleApplicationSlaveCommandRequest(_data);
+ break;
+ }
+ case FUNC_ID_PROMISCUOUS_APPLICATION_COMMAND_HANDLER:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandlePromiscuousApplicationCommandHandlerRequest(_data);
+ break;
+ }
+ case FUNC_ID_ZW_SET_DEFAULT:
+ {
+ Log::Write(LogLevel_Detail, "");
+ HandleSerialAPIResetRequest(_data);
+ break;
+ }
+ /* Ignore these. They are manufacturer proprietary */
+ case FUNC_ID_PROPRIETARY_0:
+ case FUNC_ID_PROPRIETARY_1:
+ case FUNC_ID_PROPRIETARY_2:
+ case FUNC_ID_PROPRIETARY_3:
+ case FUNC_ID_PROPRIETARY_4:
+ case FUNC_ID_PROPRIETARY_5:
+ case FUNC_ID_PROPRIETARY_6:
+ case FUNC_ID_PROPRIETARY_7:
+ case FUNC_ID_PROPRIETARY_8:
+ case FUNC_ID_PROPRIETARY_9:
+ case FUNC_ID_PROPRIETARY_A:
+ case FUNC_ID_PROPRIETARY_B:
+ case FUNC_ID_PROPRIETARY_C:
+ case FUNC_ID_PROPRIETARY_D:
+ case FUNC_ID_PROPRIETARY_E:
+ {
+ break;
+ }
+ default:
+ {
+ Log::Write(LogLevel_Detail, "");
+ Log::Write(LogLevel_Info, "**TODO: handle request for 0x%.2x** Please report this message.", _data[1]);
+ break;
}
- break;
- }
- case FUNC_ID_ZW_REPLICATION_SEND_DATA:
- {
- HandleSendDataRequest( _data, _length, true );
- break;
- }
- case FUNC_ID_ZW_ASSIGN_RETURN_ROUTE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleAssignReturnRouteRequest( _data );
- break;
- }
- case FUNC_ID_ZW_DELETE_RETURN_ROUTE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleDeleteReturnRouteRequest( _data );
- break;
- }
- case FUNC_ID_ZW_SEND_NODE_INFORMATION:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSendNodeInformationRequest( _data );
- break;
- }
- case FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE:
- case FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleNodeNeighborUpdateRequest( _data );
- break;
- }
- case FUNC_ID_ZW_APPLICATION_UPDATE:
- {
- Log::Write( LogLevel_Detail, "" );
- handleCallback = !HandleApplicationUpdateRequest( _data );
- break;
- }
- case FUNC_ID_ZW_ADD_NODE_TO_NETWORK:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleAddNodeToNetworkRequest( _data );
- break;
- }
- case FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleRemoveNodeFromNetworkRequest( _data );
- break;
- }
- case FUNC_ID_ZW_CREATE_NEW_PRIMARY:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleCreateNewPrimaryRequest( _data );
- break;
- }
- case FUNC_ID_ZW_CONTROLLER_CHANGE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleControllerChangeRequest( _data );
- break;
- }
- case FUNC_ID_ZW_SET_LEARN_MODE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSetLearnModeRequest( _data );
- break;
- }
- case FUNC_ID_ZW_REQUEST_NETWORK_UPDATE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleNetworkUpdateRequest( _data );
- break;
- }
- case FUNC_ID_ZW_REMOVE_FAILED_NODE_ID:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleRemoveFailedNodeRequest( _data );
- break;
- }
- case FUNC_ID_ZW_REPLACE_FAILED_NODE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleReplaceFailedNodeRequest( _data );
- break;
- }
- case FUNC_ID_ZW_SET_SLAVE_LEARN_MODE:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSetSlaveLearnModeRequest( _data );
- break;
- }
- case FUNC_ID_ZW_SEND_SLAVE_NODE_INFO:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSendSlaveNodeInfoRequest( _data );
- break;
- }
- case FUNC_ID_APPLICATION_SLAVE_COMMAND_HANDLER:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleApplicationSlaveCommandRequest( _data );
- break;
- }
- case FUNC_ID_PROMISCUOUS_APPLICATION_COMMAND_HANDLER:
- {
- Log::Write( LogLevel_Detail, "" );
- HandlePromiscuousApplicationCommandHandlerRequest( _data );
- break;
- }
- case FUNC_ID_ZW_SET_DEFAULT:
- {
- Log::Write( LogLevel_Detail, "" );
- HandleSerialAPIResetRequest( _data );
- break;
- }
- /* Ignore these. They are manufacturer proprietary */
- case FUNC_ID_PROPRIETARY_0:
- case FUNC_ID_PROPRIETARY_1:
- case FUNC_ID_PROPRIETARY_2:
- case FUNC_ID_PROPRIETARY_3:
- case FUNC_ID_PROPRIETARY_4:
- case FUNC_ID_PROPRIETARY_5:
- case FUNC_ID_PROPRIETARY_6:
- case FUNC_ID_PROPRIETARY_7:
- case FUNC_ID_PROPRIETARY_8:
- case FUNC_ID_PROPRIETARY_9:
- case FUNC_ID_PROPRIETARY_A:
- case FUNC_ID_PROPRIETARY_B:
- case FUNC_ID_PROPRIETARY_C:
- case FUNC_ID_PROPRIETARY_D:
- case FUNC_ID_PROPRIETARY_E:
- {
- break;
- }
- default:
- {
- Log::Write( LogLevel_Detail, "" );
- Log::Write( LogLevel_Info, "**TODO: handle request for 0x%.2x** Please report this message.", _data[1] );
- break;
- }
}
}
// Generic callback handling
- if( handleCallback )
+ // This code used _data[3] in some parts to log Node ID,
+ // but not all serial data frames report back node number.
+ if (handleCallback)
{
- if( ( m_expectedCallbackId || m_expectedReply ) )
+ if ((m_expectedCallbackId || m_expectedReply))
{
- if( m_expectedCallbackId )
+ if (m_expectedCallbackId)
{
- if( m_expectedCallbackId == _data[2] )
+ if (m_expectedCallbackId == _data[2])
{
- Log::Write( LogLevel_Detail, _data[3], " Expected callbackId was received" );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), " Expected callbackId was received");
m_expectedCallbackId = 0;
- } else if (_data[2] == 0x02 || _data[2] == 0x01) {
+ }
+ else if (_data[2] == 0x02 || _data[2] == 0x01)
+ {
/* it was a NONCE request/reply. Drop it */
return;
}
}
- if( m_expectedReply )
+ if (m_expectedReply)
{
- if( m_expectedReply == _data[1] )
+ if (m_expectedReply == _data[1])
{
- if( m_expectedCommandClassId && ( m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER ) )
+ if (m_expectedCommandClassId && (m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER))
{
- if( m_expectedCallbackId == 0 && m_expectedCommandClassId == _data[5] && m_expectedNodeId == _data[3] )
+ if (m_expectedCallbackId == 0 && m_expectedCommandClassId == _data[5] && m_expectedNodeId == _data[3])
{
- Log::Write( LogLevel_Detail, _data[3], " Expected reply and command class was received" );
+ Log::Write(LogLevel_Detail, _data[3], " Expected reply and command class was received");
m_waitingForAck = false;
m_expectedReply = 0;
m_expectedCommandClassId = 0;
@@ -2480,27 +2372,27 @@ void Driver::ProcessMsg
}
else
{
- if( IsExpectedReply( _data[3] ) )
+ if (IsExpectedReply(_data[3]))
{
- Log::Write( LogLevel_Detail, _data[3], " Expected reply was received" );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), " Expected reply was received");
m_expectedReply = 0;
m_expectedNodeId = 0;
}
}
}
}
- if( !( m_expectedCallbackId || m_expectedReply ) )
+ if (!(m_expectedCallbackId || m_expectedReply))
{
- Log::Write( LogLevel_Detail, _data[3], " Message transaction complete" );
- Log::Write( LogLevel_Detail, "" );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), " Message transaction complete");
+ Log::Write(LogLevel_Detail, "");
- if( m_notifytransactions )
+ if (m_notifytransactions)
{
- Notification* notification = new Notification( Notification::Type_Notification );
- notification->SetHomeAndNodeIds( m_homeId, _data[3] );
- notification->SetNotification( Notification::Code_MsgComplete );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_Notification);
+ notification->SetHomeAndNodeIds(m_homeId, GetNodeNumber(m_currentMsg));
+ notification->SetNotification(Notification::Code_MsgComplete);
+ QueueNotification(notification);
}
RemoveCurrentMsg();
}
@@ -2512,28 +2404,26 @@ void Driver::ProcessMsg
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetVersionResponse
-(
- uint8* _data
-)
+void Driver::HandleGetVersionResponse(uint8* _data)
{
- m_libraryVersion = (char*)&_data[2];
+ m_libraryVersion = (char*) &_data[2];
- m_libraryType = _data[m_libraryVersion.size()+3];
- if( m_libraryType < 9 )
+ m_libraryType = _data[m_libraryVersion.size() + 3];
+ if (m_libraryType < 9)
{
m_libraryTypeName = c_libraryTypeNames[m_libraryType];
}
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_GET_VERSION:" );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " %s library, version %s", m_libraryTypeName.c_str(), m_libraryVersion.c_str() );
- if ( !((m_libraryType == ZW_LIB_CONTROLLER_STATIC ) || (m_libraryType == ZW_LIB_CONTROLLER)) ) {
- Log::Write( LogLevel_Fatal, GetNodeNumber( m_currentMsg), "Z-Wave Interface is not a Supported Library Type: %s", m_libraryTypeName.c_str());
- Log::Write( LogLevel_Fatal, GetNodeNumber( m_currentMsg), "Z-Wave Interface should be a Static Controller Library Type");
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_GET_VERSION:");
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " %s library, version %s", m_libraryTypeName.c_str(), m_libraryVersion.c_str());
+ if (!((m_libraryType == ZW_LIB_CONTROLLER_STATIC) || (m_libraryType == ZW_LIB_CONTROLLER)))
+ {
+ Log::Write(LogLevel_Fatal, GetNodeNumber(m_currentMsg), "Z-Wave Interface is not a Supported Library Type: %s", m_libraryTypeName.c_str());
+ Log::Write(LogLevel_Fatal, GetNodeNumber(m_currentMsg), "Z-Wave Interface should be a Static Controller Library Type");
{
- Notification* notification = new Notification( Notification::Type_UserAlerts );
- notification->SetUserAlertNotification( Notification::Alert_UnsupportedController );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_UserAlerts);
+ notification->SetUserAlertNotification(Notification::Alert_UnsupportedController);
+ QueueNotification(notification);
}
{
Notification* notification = new Notification(Notification::Type_DriverFailed);
@@ -2552,41 +2442,35 @@ void Driver::HandleGetVersionResponse
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetRandomResponse
-(
- uint8* _data
-)
+void Driver::HandleGetRandomResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, "Received reply to FUNC_ID_ZW_GET_RANDOM: %s", _data[2] ? "true" : "false" );
+ Log::Write(LogLevel_Info, "Received reply to FUNC_ID_ZW_GET_RANDOM: %s", _data[2] ? "true" : "false");
}
-void Driver::HandleSerialAPISetupResponse
-(
- uint8* _data
-)
+void Driver::HandleSerialAPISetupResponse(uint8* _data)
{
// See INS13954 for description of FUNC_ID_SERIAL_API_SETUP with command
// SERIAL_API_SETUP_CMD_TX_STATUS_REPORT
// Note: SERIAL_API_SETUP can do more things than enable this report...
- Log::Write( LogLevel_Info, "Received reply to FUNC_ID_SERIAL_API_SETUP");
+ Log::Write(LogLevel_Info, "Received reply to FUNC_ID_SERIAL_API_SETUP");
switch (_data[0])
{
- case 1:
- Log::Write(LogLevel_Info, "Successfully enabled extended txStatusReport.");
- m_hasExtendedTxStatus = true;
- break;
+ case 1:
+ Log::Write(LogLevel_Info, "Successfully enabled extended txStatusReport.");
+ m_hasExtendedTxStatus = true;
+ break;
- case 0:
- Log::Write(LogLevel_Info, "Failed to enable extended txStatusReport. Controller might not support it.");
- m_hasExtendedTxStatus = false;
- break;
+ case 0:
+ Log::Write(LogLevel_Info, "Failed to enable extended txStatusReport. Controller might not support it.");
+ m_hasExtendedTxStatus = false;
+ break;
- default:
- Log::Write(LogLevel_Info, "FUNC_ID_SERIAL_API_SETUP returned unknown status: %u", _data[0]);
- m_hasExtendedTxStatus = false;
- break;
+ default:
+ Log::Write(LogLevel_Info, "FUNC_ID_SERIAL_API_SETUP returned unknown status: %u", _data[0]);
+ m_hasExtendedTxStatus = false;
+ break;
}
}
@@ -2594,34 +2478,25 @@ void Driver::HandleSerialAPISetupResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetControllerCapabilitiesResponse
-(
- uint8* _data
-)
+void Driver::HandleGetControllerCapabilitiesResponse(uint8* _data)
{
m_controllerCaps = _data[2];
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES:" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES:");
char str[256];
- if( m_controllerCaps & ControllerCaps_SIS )
+ if (m_controllerCaps & ControllerCaps_SIS)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " There is a SUC ID Server (SIS) in this network." );
- snprintf( str, sizeof(str), " The PC controller is an inclusion %s%s%s",
- ( m_controllerCaps & ControllerCaps_SUC ) ? "static update controller (SUC)" : "controller",
- ( m_controllerCaps & ControllerCaps_OnOtherNetwork ) ? " which is using a Home ID from another network" : "",
- ( m_controllerCaps & ControllerCaps_RealPrimary ) ? " and was the original primary before the SIS was added." : "." );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), str );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " There is a SUC ID Server (SIS) in this network.");
+ snprintf(str, sizeof(str), " The PC controller is an inclusion %s%s%s", (m_controllerCaps & ControllerCaps_SUC) ? "static update controller (SUC)" : "controller", (m_controllerCaps & ControllerCaps_OnOtherNetwork) ? " which is using a Home ID from another network" : "", (m_controllerCaps & ControllerCaps_RealPrimary) ? " and was the original primary before the SIS was added." : ".");
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), str);
}
else
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " There is no SUC ID Server (SIS) in this network." );
- snprintf( str, sizeof(str), " The PC controller is a %s%s%s",
- ( m_controllerCaps & ControllerCaps_Secondary ) ? "secondary" : "primary",
- ( m_controllerCaps & ControllerCaps_SUC ) ? " static update controller (SUC)" : " controller",
- ( m_controllerCaps & ControllerCaps_OnOtherNetwork ) ? " which is using a Home ID from another network." : "." );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), str );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " There is no SUC ID Server (SIS) in this network.");
+ snprintf(str, sizeof(str), " The PC controller is a %s%s%s", (m_controllerCaps & ControllerCaps_Secondary) ? "secondary" : "primary", (m_controllerCaps & ControllerCaps_SUC) ? " static update controller (SUC)" : " controller", (m_controllerCaps & ControllerCaps_OnOtherNetwork) ? " which is using a Home ID from another network." : ".");
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), str);
}
}
@@ -2629,94 +2504,84 @@ void Driver::HandleGetControllerCapabilitiesResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetSerialAPICapabilitiesResponse
-(
- uint8* _data
-)
+void Driver::HandleGetSerialAPICapabilitiesResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Received reply to FUNC_ID_SERIAL_API_GET_CAPABILITIES" );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Serial API Version: %d.%d", _data[2], _data[3] );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Manufacturer ID: 0x%.2x%.2x", _data[4], _data[5] );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Product Type: 0x%.2x%.2x", _data[6], _data[7] );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Product ID: 0x%.2x%.2x", _data[8], _data[9] );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Received reply to FUNC_ID_SERIAL_API_GET_CAPABILITIES");
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Serial API Version: %d.%d", _data[2], _data[3]);
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Manufacturer ID: 0x%.2x%.2x", _data[4], _data[5]);
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Product Type: 0x%.2x%.2x", _data[6], _data[7]);
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Product ID: 0x%.2x%.2x", _data[8], _data[9]);
// _data[10] to _data[41] are a 256-bit bitmask with one bit set for
// each FUNC_ID_ method supported by the controller.
// Bit 0 is FUNC_ID_ 1. So FUNC_ID_SERIAL_API_GET_CAPABILITIES (0x07) will be bit 6 of the first byte.
m_serialAPIVersion[0] = _data[2];
m_serialAPIVersion[1] = _data[3];
- m_manufacturerId = ( ( (uint16)_data[4] )<<8) | (uint16)_data[5];
- m_productType = ( ( (uint16)_data[6] )<<8 ) | (uint16)_data[7];
- m_productId = ( ( (uint16)_data[8] )<<8 ) | (uint16)_data[9];
- memcpy( m_apiMask, &_data[10], sizeof( m_apiMask ) );
+ m_manufacturerId = (((uint16) _data[4]) << 8) | (uint16) _data[5];
+ m_productType = (((uint16) _data[6]) << 8) | (uint16) _data[7];
+ m_productId = (((uint16) _data[8]) << 8) | (uint16) _data[9];
+ memcpy(m_apiMask, &_data[10], sizeof(m_apiMask));
- if( IsBridgeController() )
+ if (IsBridgeController())
{
- SendMsg( new Msg( "FUNC_ID_ZW_GET_VIRTUAL_NODES", 0xff, REQUEST, FUNC_ID_ZW_GET_VIRTUAL_NODES, false ), MsgQueue_Command);
+ SendMsg(new Internal::Msg("FUNC_ID_ZW_GET_VIRTUAL_NODES", 0xff, REQUEST, FUNC_ID_ZW_GET_VIRTUAL_NODES, false), MsgQueue_Command);
}
- if( IsAPICallSupported( FUNC_ID_ZW_GET_RANDOM ) )
+ if (IsAPICallSupported( FUNC_ID_ZW_GET_RANDOM))
{
- Msg *msg = new Msg( "FUNC_ID_ZW_GET_RANDOM", 0xff, REQUEST, FUNC_ID_ZW_GET_RANDOM, false );
- msg->Append( 32 ); // 32 bytes
- SendMsg( msg, MsgQueue_Command );
+ Internal::Msg *msg = new Internal::Msg("FUNC_ID_ZW_GET_RANDOM", 0xff, REQUEST, FUNC_ID_ZW_GET_RANDOM, false);
+ msg->Append(32); // 32 bytes
+ SendMsg(msg, MsgQueue_Command);
}
- if( IsAPICallSupported( FUNC_ID_SERIAL_API_SETUP ) )
+ if (IsAPICallSupported( FUNC_ID_SERIAL_API_SETUP))
{
- Msg *msg = new Msg( "FUNC_ID_SERIAL_API_SETUP", 0xff, REQUEST, FUNC_ID_SERIAL_API_SETUP, false );
- msg->Append( SERIAL_API_SETUP_CMD_TX_STATUS_REPORT );
- msg->Append( 1 );
- SendMsg( msg, MsgQueue_Command );
+ Internal::Msg *msg = new Internal::Msg("FUNC_ID_SERIAL_API_SETUP", 0xff, REQUEST, FUNC_ID_SERIAL_API_SETUP, false);
+ msg->Append( SERIAL_API_SETUP_CMD_TX_STATUS_REPORT);
+ msg->Append(1);
+ SendMsg(msg, MsgQueue_Command);
}
-
- SendMsg( new Msg( "FUNC_ID_SERIAL_API_GET_INIT_DATA", 0xff, REQUEST, FUNC_ID_SERIAL_API_GET_INIT_DATA, false ), MsgQueue_Command);
- if( !IsBridgeController() )
+ SendMsg(new Internal::Msg("FUNC_ID_SERIAL_API_GET_INIT_DATA", 0xff, REQUEST, FUNC_ID_SERIAL_API_GET_INIT_DATA, false), MsgQueue_Command);
+ if (!IsBridgeController())
{
- Msg* msg = new Msg( "FUNC_ID_SERIAL_API_SET_TIMEOUTS", 0xff, REQUEST, FUNC_ID_SERIAL_API_SET_TIMEOUTS, false );
- msg->Append( ACK_TIMEOUT / 10 );
- msg->Append( BYTE_TIMEOUT / 10 );
- SendMsg( msg, MsgQueue_Command );
+ Internal::Msg* msg = new Internal::Msg("FUNC_ID_SERIAL_API_SET_TIMEOUTS", 0xff, REQUEST, FUNC_ID_SERIAL_API_SET_TIMEOUTS, false);
+ msg->Append( ACK_TIMEOUT / 10);
+ msg->Append( BYTE_TIMEOUT / 10);
+ SendMsg(msg, MsgQueue_Command);
}
- Msg* msg = new Msg( "FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION", 0xff, REQUEST, FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION, false, false );
- msg->Append( APPLICATION_NODEINFO_LISTENING );
- msg->Append( 0x02 ); // Generic Static Controller
- msg->Append( 0x01 ); // Specific Static PC Controller
+ Internal::Msg* msg = new Internal::Msg("FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION", 0xff, REQUEST, FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION, false, false);
+ msg->Append( APPLICATION_NODEINFO_LISTENING);
+ msg->Append(0x02); // Generic Static Controller
+ msg->Append(0x01); // Specific Static PC Controller
/* get a list of Advertised Command Classes */
- list advertisedCommandClasses = CommandClasses::GetAdvertisedCommandClasses();
- msg->Append( (uint8)advertisedCommandClasses.size() ); // Length
+ list advertisedCommandClasses = Internal::CC::CommandClasses::GetAdvertisedCommandClasses();
+ msg->Append((uint8) advertisedCommandClasses.size()); // Length
for (list::iterator it = advertisedCommandClasses.begin(); it != advertisedCommandClasses.end(); ++it)
msg->Append(*it);
- SendMsg( msg, MsgQueue_Command );
+ SendMsg(msg, MsgQueue_Command);
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSerialAPISoftResetResponse
-(
- uint8* _data
-)
+void Driver::HandleSerialAPISoftResetResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to Soft Reset." );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to Soft Reset.");
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSerialAPIResetRequest
-(
- uint8* _data
-)
+void Driver::HandleSerialAPIResetRequest(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to complete Controller Reset." );
- if( m_controllerResetEvent != NULL )
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to complete Controller Reset.");
+ if (m_controllerResetEvent != NULL)
{
m_controllerResetEvent->Set();
m_controllerResetEvent = NULL;
@@ -2727,38 +2592,32 @@ void Driver::HandleSerialAPIResetRequest
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleEnableSUCResponse
-(
- uint8* _data
-)
+void Driver::HandleEnableSUCResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to Enable SUC." );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to Enable SUC.");
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleNetworkUpdateResponse
-(
- uint8* _data
-)
+bool Driver::HandleNetworkUpdateResponse(uint8* _data)
{
bool res = true;
ControllerState state = ControllerState_InProgress;
- if( _data[2] )
+ if (_data[2])
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE - command in progress" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE - command in progress");
}
else
{
// Failed
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE - command failed" );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE - command failed");
state = ControllerState_Failed;
res = false;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
return res;
}
@@ -2766,50 +2625,50 @@ bool Driver::HandleNetworkUpdateResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSetSUCNodeIdResponse
-(
- uint8* _data
-)
+void Driver::HandleSetSUCNodeIdResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to SET_SUC_NODE_ID." );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to SET_SUC_NODE_ID.");
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetSUCNodeIdResponse
-(
- uint8* _data
-)
+void Driver::HandleGetSUCNodeIdResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to GET_SUC_NODE_ID. Node ID = %d", _data[2] );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to GET_SUC_NODE_ID. Node ID = %d", _data[2]);
m_SUCNodeId = _data[2];
- if( _data[2] == 0)
+ if (_data[2] == 0)
{
bool enableSIS = true;
Options::Get()->GetOptionAsBool("EnableSIS", &enableSIS);
- if (enableSIS) {
- if (IsAPICallSupported(FUNC_ID_ZW_ENABLE_SUC) && IsAPICallSupported(FUNC_ID_ZW_SET_SUC_NODE_ID)) {
- Log::Write( LogLevel_Info, " No SUC, so we become SIS" );
-
- Msg* msg;
- msg = new Msg( "Enable SUC", m_Controller_nodeId, REQUEST, FUNC_ID_ZW_ENABLE_SUC, false );
- msg->Append( 1 );
- msg->Append( SUC_FUNC_NODEID_SERVER ); // SIS; SUC would be ZW_SUC_FUNC_BASIC_SUC
- SendMsg( msg, MsgQueue_Send );
-
- msg = new Msg( "Set SUC node ID", m_Controller_nodeId, REQUEST, FUNC_ID_ZW_SET_SUC_NODE_ID, false );
- msg->Append( m_Controller_nodeId );
- msg->Append( 1 ); // TRUE, we want to be SUC/SIS
- msg->Append( 0 ); // no low power
- msg->Append( SUC_FUNC_NODEID_SERVER );
- SendMsg( msg, MsgQueue_Send );
- } else {
- Log::Write (LogLevel_Info, "Controller Does not Support SUC - Cannot Setup Controller as SUC Node");
+ if (enableSIS)
+ {
+ if (IsAPICallSupported(FUNC_ID_ZW_ENABLE_SUC) && IsAPICallSupported(FUNC_ID_ZW_SET_SUC_NODE_ID))
+ {
+ Log::Write(LogLevel_Info, " No SUC, so we become SIS");
+
+ Internal::Msg* msg;
+ msg = new Internal::Msg("Enable SUC", m_Controller_nodeId, REQUEST, FUNC_ID_ZW_ENABLE_SUC, false);
+ msg->Append(1);
+ msg->Append( SUC_FUNC_NODEID_SERVER); // SIS; SUC would be ZW_SUC_FUNC_BASIC_SUC
+ SendMsg(msg, MsgQueue_Send);
+
+ msg = new Internal::Msg("Set SUC node ID", m_Controller_nodeId, REQUEST, FUNC_ID_ZW_SET_SUC_NODE_ID, false);
+ msg->Append(m_Controller_nodeId);
+ msg->Append(1); // TRUE, we want to be SUC/SIS
+ msg->Append(0); // no low power
+ msg->Append( SUC_FUNC_NODEID_SERVER);
+ SendMsg(msg, MsgQueue_Send);
}
- } else {
- Log::Write( LogLevel_Info, " No SUC, not becoming SUC as option is disabled" );
+ else
+ {
+ Log::Write(LogLevel_Info, "Controller Does not Support SUC - Cannot Setup Controller as SUC Node");
+ }
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, " No SUC, not becoming SUC as option is disabled");
}
}
}
@@ -2818,33 +2677,27 @@ void Driver::HandleGetSUCNodeIdResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleMemoryGetIdResponse
-(
- uint8* _data
-)
+void Driver::HandleMemoryGetIdResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_MEMORY_GET_ID. Home ID = 0x%02x%02x%02x%02x. Our node ID = %d", _data[2], _data[3], _data[4], _data[5], _data[6] );
- m_homeId = ( ( (uint32)_data[2] )<<24 ) | ( ( (uint32)_data[3] )<<16 ) | ( ( (uint32)_data[4] )<<8 ) | ( (uint32)_data[5] );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_MEMORY_GET_ID. Home ID = 0x%02x%02x%02x%02x. Our node ID = %d", _data[2], _data[3], _data[4], _data[5], _data[6]);
+ m_homeId = (((uint32) _data[2]) << 24) | (((uint32) _data[3]) << 16) | (((uint32) _data[4]) << 8) | ((uint32) _data[5]);
m_Controller_nodeId = _data[6];
- m_controllerReplication = static_cast(ControllerReplication::Create( m_homeId, m_Controller_nodeId ));
+ m_controllerReplication = static_cast(Internal::CC::ControllerReplication::Create(m_homeId, m_Controller_nodeId));
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSerialAPIGetInitDataResponse
-(
- uint8* _data
-)
+void Driver::HandleSerialAPIGetInitDataResponse(uint8* _data)
{
int32 i;
- if( !m_init )
+ if (!m_init)
{
// Mark the driver as ready (we have to do this first or
// all the code handling notifications will go awry).
- Manager::Get()->SetDriverReady( this, true );
+ Manager::Get()->SetDriverReady(this, true);
// Read the config file first, to get the last known state
ReadCache();
@@ -2853,68 +2706,68 @@ void Driver::HandleSerialAPIGetInitDataResponse
{
// Notify the user that all node and value information has been deleted
// We need to wait to do this here so we have new information to report.
- Notification* notification = new Notification( Notification::Type_DriverReset );
- notification->SetHomeAndNodeIds( m_homeId, 0 );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_DriverReset);
+ notification->SetHomeAndNodeIds(m_homeId, 0);
+ QueueNotification(notification);
}
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_SERIAL_API_GET_INIT_DATA:" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_SERIAL_API_GET_INIT_DATA:");
m_initVersion = _data[2];
m_initCaps = _data[3];
- if( _data[4] == NUM_NODE_BITFIELD_BYTES )
+ if (_data[4] == NUM_NODE_BITFIELD_BYTES)
{
- for( i=0; iSetQueryStage( Node::QueryStage_CacheLoad );
+ node->SetQueryStage(Node::QueryStage_CacheLoad);
}
}
else
{
// This node is new
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Node %.3d - New", nodeId );
- Notification* notification = new Notification( Notification::Type_NodeNew );
- notification->SetHomeAndNodeIds( m_homeId, nodeId );
- QueueNotification( notification );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Node %.3d - New", nodeId);
+ Notification* notification = new Notification(Notification::Type_NodeNew);
+ notification->SetHomeAndNodeIds(m_homeId, nodeId);
+ QueueNotification(notification);
// Create the node and request its info
- InitNode( nodeId );
+ InitNode(nodeId);
}
}
}
else
{
- LockGuard LG(m_nodeMutex);
- if( GetNode(nodeId) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (GetNode(nodeId))
{
// This node no longer exists in the Z-Wave network
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Node %.3d - Removed", nodeId );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Node %.3d - Removed", nodeId);
delete m_nodes[nodeId];
m_nodes[nodeId] = NULL;
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, nodeId );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, nodeId);
+ QueueNotification(notification);
}
}
@@ -2929,26 +2782,23 @@ void Driver::HandleSerialAPIGetInitDataResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetNodeProtocolInfoResponse
-(
- uint8* _data
-)
+void Driver::HandleGetNodeProtocolInfoResponse(uint8* _data)
{
// The node that the protocol info response is for is not included in the message.
// We have to assume that the node is the same one as in the most recent request.
- if( !m_currentMsg )
+ if (!m_currentMsg)
{
- Log::Write( LogLevel_Warning, "WARNING: Received unexpected FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO message - ignoring.");
+ Log::Write(LogLevel_Warning, "WARNING: Received unexpected FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO message - ignoring.");
return;
}
uint8 nodeId = m_currentMsg->GetTargetNodeId();
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO" );
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO");
// Update the node with the protocol info
- if( Node* node = GetNodeUnsafe( nodeId ) )
+ if (Node* node = GetNodeUnsafe(nodeId))
{
- node->UpdateProtocolInfo( &_data[2] );
+ node->UpdateProtocolInfo(&_data[2]);
}
}
@@ -2956,26 +2806,23 @@ void Driver::HandleGetNodeProtocolInfoResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleAssignReturnRouteResponse
-(
- uint8* _data
-)
+bool Driver::HandleAssignReturnRouteResponse(uint8* _data)
{
bool res = true;
ControllerState state = ControllerState_InProgress;
- if( _data[2] )
+ if (_data[2])
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE - command in progress" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE - command in progress");
}
else
{
// Failed
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE - command failed" );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE - command failed");
state = ControllerState_Failed;
res = false;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
return res;
}
@@ -2983,26 +2830,23 @@ bool Driver::HandleAssignReturnRouteResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleDeleteReturnRouteResponse
-(
- uint8* _data
-)
+bool Driver::HandleDeleteReturnRouteResponse(uint8* _data)
{
bool res = true;
ControllerState state = ControllerState_InProgress;
- if( _data[2] )
+ if (_data[2])
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE - command in progress" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE - command in progress");
}
else
{
// Failed
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE - command failed" );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE - command failed");
state = ControllerState_Failed;
res = false;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
return res;
}
@@ -3010,60 +2854,57 @@ bool Driver::HandleDeleteReturnRouteResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleRemoveFailedNodeResponse
-(
- uint8* _data
-)
+bool Driver::HandleRemoveFailedNodeResponse(uint8* _data)
{
bool res = true;
ControllerState state = ControllerState_InProgress;
ControllerError error = ControllerError_None;
- if( _data[2] )
+ if (_data[2])
{
string reason;
- switch( _data[2] )
- {
- case FAILED_NODE_NOT_FOUND:
- {
- reason = "Node not found";
- error = ControllerError_NotFound;
- break;
- }
- case FAILED_NODE_REMOVE_PROCESS_BUSY:
- {
- reason = "Remove process busy";
- error = ControllerError_Busy;
- break;
- }
- case FAILED_NODE_REMOVE_FAIL:
- {
- reason = "Remove failed";
- error = ControllerError_Failed;
- break;
- }
- case FAILED_NODE_NOT_PRIMARY_CONTROLLER:
- {
- reason = "Not Primary Controller";
- error = ControllerError_NotPrimary;
- break;
- }
- default:
+ switch (_data[2])
{
- reason = "Command failed";
- break;
- }
+ case FAILED_NODE_NOT_FOUND:
+ {
+ reason = "Node not found";
+ error = ControllerError_NotFound;
+ break;
+ }
+ case FAILED_NODE_REMOVE_PROCESS_BUSY:
+ {
+ reason = "Remove process busy";
+ error = ControllerError_Busy;
+ break;
+ }
+ case FAILED_NODE_REMOVE_FAIL:
+ {
+ reason = "Remove failed";
+ error = ControllerError_Failed;
+ break;
+ }
+ case FAILED_NODE_NOT_PRIMARY_CONTROLLER:
+ {
+ reason = "Not Primary Controller";
+ error = ControllerError_NotPrimary;
+ break;
+ }
+ default:
+ {
+ reason = "Command failed";
+ break;
+ }
}
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - %s", reason.c_str() );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - %s", reason.c_str());
state = ControllerState_Failed;
res = false;
}
else
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - Command in progress" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - Command in progress");
}
- UpdateControllerState( state, error );
+ UpdateControllerState(state, error);
return res;
}
@@ -3071,69 +2912,66 @@ bool Driver::HandleRemoveFailedNodeResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleIsFailedNodeResponse
-(
- uint8* _data
-)
+void Driver::HandleIsFailedNodeResponse(uint8* _data)
{
ControllerState state;
- uint8 nodeId = m_currentControllerCommand ? m_currentControllerCommand->m_controllerCommandNode : GetNodeNumber( m_currentMsg );
- if( _data[2] )
+ uint8 nodeId = m_currentControllerCommand ? m_currentControllerCommand->m_controllerCommandNode : GetNodeNumber(m_currentMsg);
+ if (_data[2])
{
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_IS_FAILED_NODE_ID - node %d failed", nodeId );
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_IS_FAILED_NODE_ID - node %d failed", nodeId);
state = ControllerState_NodeFailed;
- if( Node* node = GetNodeUnsafe( nodeId ) )
+ if (Node* node = GetNodeUnsafe(nodeId))
{
- if (node->IsNodeReset()) {
+ if (node->IsNodeReset())
+ {
/* a DeviceReset has Occured. Remove the Node */
if (!BeginControllerCommand(Driver::ControllerCommand_RemoveFailedNode, NULL, NULL, true, nodeId, 0))
Log::Write(LogLevel_Warning, nodeId, "RemoveFailedNode for DeviceResetLocally Command Failed");
- Notification* notification = new Notification( Notification::Type_NodeReset );
- notification->SetHomeAndNodeIds( m_homeId, nodeId );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_NodeReset);
+ notification->SetHomeAndNodeIds(m_homeId, nodeId);
+ QueueNotification(notification);
state = ControllerState_Completed;
- } else {
- node->SetNodeAlive( false );
+ }
+ else
+ {
+ node->SetNodeAlive(false);
}
}
}
else
{
- Log::Write( LogLevel_Warning, nodeId, "Received reply to FUNC_ID_ZW_IS_FAILED_NODE_ID - node %d has not failed", nodeId );
- if( Node* node = GetNodeUnsafe( nodeId ) )
+ Log::Write(LogLevel_Warning, nodeId, "Received reply to FUNC_ID_ZW_IS_FAILED_NODE_ID - node %d has not failed", nodeId);
+ if (Node* node = GetNodeUnsafe(nodeId))
{
- node->SetNodeAlive( true );
+ node->SetNodeAlive(true);
}
state = ControllerState_NodeOK;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleReplaceFailedNodeResponse
-(
- uint8* _data
-)
+bool Driver::HandleReplaceFailedNodeResponse(uint8* _data)
{
bool res = true;
ControllerState state = ControllerState_InProgress;
- if( _data[2] )
+ if (_data[2])
{
// Command failed
- Log::Write( LogLevel_Warning, GetNodeNumber( m_currentMsg ), "WARNING: Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - command failed" );
+ Log::Write(LogLevel_Warning, GetNodeNumber(m_currentMsg), "WARNING: Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - command failed");
state = ControllerState_Failed;
res = false;
}
else
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - command in progress" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - command in progress");
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
return res;
}
@@ -3141,21 +2979,17 @@ bool Driver::HandleReplaceFailedNodeResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSendDataResponse
-(
- uint8* _data,
- bool _replication
-)
+void Driver::HandleSendDataResponse(uint8* _data, bool _replication)
{
- if( _data[2] )
+ if (_data[2])
{
- Log::Write( LogLevel_Detail, GetNodeNumber( m_currentMsg ), " %s delivered to Z-Wave stack", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA" );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), " %s delivered to Z-Wave stack", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA");
}
else
{
- Log::Write( LogLevel_Error, GetNodeNumber( m_currentMsg ), "ERROR: %s could not be delivered to Z-Wave stack", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA" );
+ Log::Write(LogLevel_Error, GetNodeNumber(m_currentMsg), "ERROR: %s could not be delivered to Z-Wave stack", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA");
m_nondelivery++;
- if( Node* node = GetNodeUnsafe( GetNodeNumber( m_currentMsg ) ) )
+ if (Node* node = GetNodeUnsafe(GetNodeNumber(m_currentMsg)))
{
node->m_sentFailed++;
}
@@ -3166,35 +3000,32 @@ void Driver::HandleSendDataResponse
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleGetRoutingInfoResponse
-(
- uint8* _data
-)
+void Driver::HandleGetRoutingInfoResponse(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "Received reply to FUNC_ID_ZW_GET_ROUTING_INFO" );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "Received reply to FUNC_ID_ZW_GET_ROUTING_INFO");
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( GetNodeNumber( m_currentMsg ) ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(GetNodeNumber(m_currentMsg)))
{
// copy the 29-byte bitmap received (29*8=232 possible nodes) into this node's neighbors member variable
- memcpy( node->m_neighbors, &_data[2], 29 );
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), " Neighbors of this node are:" );
+ memcpy(node->m_neighbors, &_data[2], 29);
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), " Neighbors of this node are:");
bool bNeighbors = false;
- for( int by=0; by<29; by++ )
+ for (int by = 0; by < 29; by++)
{
- for( int bi=0; bi<8; bi++ )
+ for (int bi = 0; bi < 8; bi++)
{
- if( (_data[2+by] & (0x01<
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSendDataRequest
-(
- uint8* _data,
- uint8 _length,
- bool _replication
-)
+void Driver::HandleSendDataRequest(uint8* _data, uint8 _length, bool _replication)
{
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- Log::Write( LogLevel_Detail, nodeId, " %s Request with callback ID 0x%.2x received (expected 0x%.2x)", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA", _data[2], _data[2] < 10 ? _data[2] : m_expectedCallbackId );
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ Log::Write(LogLevel_Detail, nodeId, " %s Request with callback ID 0x%.2x received (expected 0x%.2x)", _replication ? "ZW_REPLICATION_SEND_DATA" : "ZW_SEND_DATA", _data[2], _data[2] < 10 ? _data[2] : m_expectedCallbackId);
/* Callback ID's below 10 are reserved for NONCE messages */
- if ((_data[2] > 10 ) && ( _data[2] != m_expectedCallbackId )) {
+ if ((_data[2] > 10) && (_data[2] != m_expectedCallbackId))
+ {
// Wrong callback ID
m_callbacks++;
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Unexpected Callback ID received" );
- } else {
- Node* node = GetNodeUnsafe( nodeId );
- if( node != NULL )
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Unexpected Callback ID received");
+ }
+ else
+ {
+ Node* node = GetNodeUnsafe(nodeId);
+ if (node != NULL)
{
- if( _data[3] != TRANSMIT_COMPLETE_OK )
+ if (_data[3] != TRANSMIT_COMPLETE_OK)
{
node->m_sentFailed++;
}
@@ -3229,21 +3058,22 @@ void Driver::HandleSendDataRequest
{
node->m_lastRequestRTT = -node->m_sentTS.TimeRemaining();
- if( node->m_averageRequestRTT )
+ if (node->m_averageRequestRTT)
{
// if the average has been established, update by averaging the average and the last RTT
- node->m_averageRequestRTT = ( node->m_averageRequestRTT + node->m_lastRequestRTT ) >> 1;
+ node->m_averageRequestRTT = (node->m_averageRequestRTT + node->m_lastRequestRTT) >> 1;
}
else
{
// if this is the first observed RTT, set the average to this value
node->m_averageRequestRTT = node->m_lastRequestRTT;
}
- Log::Write(LogLevel_Info, nodeId, "Request RTT %d Average Request RTT %d", node->m_lastRequestRTT, node->m_averageRequestRTT );
+ Log::Write(LogLevel_Info, nodeId, "Request RTT %d Average Request RTT %d", node->m_lastRequestRTT, node->m_averageRequestRTT);
}
/* if the frame has txStatus message, then extract it */
// petergebruers, changed test (_length > 7) to >= 23 to avoid extracting non-existent data, highest is _data[22]
- if (_length >= 23) {
+ if (_length >= 23)
+ {
node->m_txStatusReportSupported = true;
// petergebruers:
// because OpenZWave uses "ms" everywhere, and wTransmitTicks
@@ -3253,71 +3083,66 @@ void Driver::HandleSendDataRequest
node->m_hops = _data[6];
// petergebruers: there are 5 rssi values because there are
// 4 repeaters + 1 sending node
- strncpy(node->m_rssi_1, rssi_to_string(_data[7]), sizeof(node->m_rssi_1) - 1);
- strncpy(node->m_rssi_2, rssi_to_string(_data[8]), sizeof(node->m_rssi_2) - 1);
- strncpy(node->m_rssi_3, rssi_to_string(_data[9]), sizeof(node->m_rssi_3) - 1);
- strncpy(node->m_rssi_4, rssi_to_string(_data[10]), sizeof(node->m_rssi_4) - 1);
- strncpy(node->m_rssi_5, rssi_to_string(_data[11]), sizeof(node->m_rssi_5) - 1);
+ strncpy(node->m_rssi_1, Internal::rssi_to_string(_data[7]), sizeof(node->m_rssi_1) - 1);
+ strncpy(node->m_rssi_2, Internal::rssi_to_string(_data[8]), sizeof(node->m_rssi_2) - 1);
+ strncpy(node->m_rssi_3, Internal::rssi_to_string(_data[9]), sizeof(node->m_rssi_3) - 1);
+ strncpy(node->m_rssi_4, Internal::rssi_to_string(_data[10]), sizeof(node->m_rssi_4) - 1);
+ strncpy(node->m_rssi_5, Internal::rssi_to_string(_data[11]), sizeof(node->m_rssi_5) - 1);
node->m_ackChannel = _data[12];
node->m_lastTxChannel = _data[13];
- node->m_routeScheme = (TXSTATUS_ROUTING_SCHEME)_data[14];
+ node->m_routeScheme = (TXSTATUS_ROUTING_SCHEME) _data[14];
node->m_routeUsed[0] = _data[15];
node->m_routeUsed[1] = _data[16];
node->m_routeUsed[2] = _data[17];
node->m_routeUsed[3] = _data[18];
- node->m_routeSpeed = (TXSTATUS_ROUTE_SPEED)_data[19];
+ node->m_routeSpeed = (TXSTATUS_ROUTE_SPEED) _data[19];
node->m_routeTries = _data[20];
node->m_lastFailedLinkFrom = _data[21];
node->m_lastFailedLinkTo = _data[22];
Node::NodeData nd;
node->GetNodeStatistics(&nd);
// petergebruers: changed "ChannelAck" to "AckChannel", to be consistent with docs and "TxChannel"
- Log::Write( LogLevel_Detail, nodeId, "Extended TxStatus: Time: %d, Hops: %d, Rssi: %s %s %s %s %s, AckChannel: %d, TxChannel: %d, RouteScheme: %s, Route: %d %d %d %d, RouteSpeed: %s, RouteTries: %d, FailedLinkFrom: %d, FailedLinkTo: %d",
- nd.m_txTime, nd.m_hops, nd.m_rssi_1, nd.m_rssi_2, nd.m_rssi_3, nd.m_rssi_4, nd.m_rssi_4,
- nd.m_ackChannel, nd.m_lastTxChannel, Manager::GetNodeRouteScheme(&nd).c_str(), nd.m_routeUsed[0],
- nd.m_routeUsed[1], nd.m_routeUsed[2], nd.m_routeUsed[3], Manager::GetNodeRouteSpeed(&nd).c_str(),
- nd.m_routeTries, nd.m_lastFailedLinkFrom, nd.m_lastFailedLinkTo);
+ Log::Write(LogLevel_Detail, nodeId, "Extended TxStatus: Time: %d, Hops: %d, Rssi: %s %s %s %s %s, AckChannel: %d, TxChannel: %d, RouteScheme: %s, Route: %d %d %d %d, RouteSpeed: %s, RouteTries: %d, FailedLinkFrom: %d, FailedLinkTo: %d", nd.m_txTime, nd.m_hops, nd.m_rssi_1, nd.m_rssi_2, nd.m_rssi_3, nd.m_rssi_4, nd.m_rssi_4, nd.m_ackChannel, nd.m_lastTxChannel, Manager::GetNodeRouteScheme(&nd).c_str(), nd.m_routeUsed[0], nd.m_routeUsed[1], nd.m_routeUsed[2], nd.m_routeUsed[3],
+ Manager::GetNodeRouteSpeed(&nd).c_str(), nd.m_routeTries, nd.m_lastFailedLinkFrom, nd.m_lastFailedLinkTo);
}
}
// We do this here since HandleErrorResponse/MoveMessagesToWakeUpQueue can delete m_currentMsg
- if( m_currentMsg && m_currentMsg->IsNoOperation() )
+ if (m_currentMsg && m_currentMsg->IsNoOperation())
{
- Notification* notification = new Notification( Notification::Type_Notification );
- notification->SetHomeAndNodeIds( m_homeId, GetNodeNumber( m_currentMsg) );
- notification->SetNotification( Notification::Code_NoOperation );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_Notification);
+ notification->SetHomeAndNodeIds(m_homeId, GetNodeNumber(m_currentMsg));
+ notification->SetNotification(Notification::Code_NoOperation);
+ QueueNotification(notification);
}
// Callback ID matches our expectation
- if( _data[3] != TRANSMIT_COMPLETE_OK )
+ if (_data[3] != TRANSMIT_COMPLETE_OK)
{
- if( !HandleErrorResponse( _data[3], nodeId, _replication ? "ZW_REPLICATION_END_DATA" : "ZW_SEND_DATA", !_replication ) )
+ if (!HandleErrorResponse(_data[3], nodeId, _replication ? "ZW_REPLICATION_END_DATA" : "ZW_SEND_DATA", !_replication))
{
- if( m_currentMsg && m_currentMsg->IsNoOperation() && node != NULL &&
- ( node->GetCurrentQueryStage() == Node::QueryStage_Probe ||
- node->GetCurrentQueryStage() == Node::QueryStage_CacheLoad ) )
+ if (m_currentMsg && m_currentMsg->IsNoOperation() && node != NULL && (node->GetCurrentQueryStage() == Node::QueryStage_Probe || node->GetCurrentQueryStage() == Node::QueryStage_CacheLoad))
{
- node->QueryStageRetry( node->GetCurrentQueryStage(), 3 );
+ node->QueryStageRetry(node->GetCurrentQueryStage(), 3);
}
}
}
- else if( node != NULL )
+ else if (node != NULL)
{
// If WakeUpNoMoreInformation request succeeds, update our status
- if( m_currentMsg && m_currentMsg->IsWakeUpNoMoreInformationCommand() )
+ if (m_currentMsg && m_currentMsg->IsWakeUpNoMoreInformationCommand())
{
- if( WakeUp* wakeUp = static_cast( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) )
+ if (Internal::CC::WakeUp* wakeUp = static_cast(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
{
// Mark the node as asleep
- wakeUp->SetAwake( false );
+ wakeUp->SetAwake(false);
}
}
// If node is not alive, mark it alive now
- if( !node->IsNodeAlive() )
+ if (!node->IsNodeAlive())
{
- node->SetNodeAlive( true );
+ node->SetNodeAlive(true);
}
}
// Command reception acknowledged by node, error or not, but ignore any NONCE messages
@@ -3330,486 +3155,460 @@ void Driver::HandleSendDataRequest
//
// Process a response from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleNetworkUpdateRequest
-(
- uint8* _data
-)
+void Driver::HandleNetworkUpdateRequest(uint8* _data)
{
ControllerState state = ControllerState_Failed;
ControllerError error = ControllerError_None;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- switch( _data[3] )
- {
- case SUC_UPDATE_DONE:
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Success" );
- state = ControllerState_Completed;
- break;
- }
- case SUC_UPDATE_ABORT:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - Error. Process aborted." );
- error = ControllerError_Failed;
- break;
- }
- case SUC_UPDATE_WAIT:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - SUC is busy." );
- error = ControllerError_Busy;
- break;
- }
- case SUC_UPDATE_DISABLED:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - SUC is disabled." );
- error = ControllerError_Disabled;
- break;
- }
- case SUC_UPDATE_OVERFLOW:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - Overflow. Full replication required." );
- error = ControllerError_Overflow;
- break;
- }
- default:
- {
- }
+ case SUC_UPDATE_DONE:
+ {
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Success");
+ state = ControllerState_Completed;
+ break;
+ }
+ case SUC_UPDATE_ABORT:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - Error. Process aborted.");
+ error = ControllerError_Failed;
+ break;
+ }
+ case SUC_UPDATE_WAIT:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - SUC is busy.");
+ error = ControllerError_Busy;
+ break;
+ }
+ case SUC_UPDATE_DISABLED:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - SUC is disabled.");
+ error = ControllerError_Disabled;
+ break;
+ }
+ case SUC_UPDATE_OVERFLOW:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REQUEST_NETWORK_UPDATE: Failed - Overflow. Full replication required.");
+ error = ControllerError_Overflow;
+ break;
+ }
+ default:
+ {
+ }
}
- UpdateControllerState( state, error );
+ UpdateControllerState(state, error);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleAddNodeToNetworkRequest
-(
- uint8* _data
-)
+void Driver::HandleAddNodeToNetworkRequest(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "FUNC_ID_ZW_ADD_NODE_TO_NETWORK:" );
- CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_ADD_NODE_TO_NETWORK, _data );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "FUNC_ID_ZW_ADD_NODE_TO_NETWORK:");
+ CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_ADD_NODE_TO_NETWORK, _data);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleRemoveNodeFromNetworkRequest
-(
- uint8* _data
-)
+void Driver::HandleRemoveNodeFromNetworkRequest(uint8* _data)
{
//uint8 nodeId = GetNodeNumber( m_currentMsg );
- if( m_currentControllerCommand == NULL )
+ if (m_currentControllerCommand == NULL)
{
return;
}
ControllerState state = m_currentControllerCommand->m_controllerState;
- Log::Write( LogLevel_Info, "FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK:" );
+ Log::Write(LogLevel_Info, "FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK:");
- switch( _data[3] )
- {
- case REMOVE_NODE_STATUS_LEARN_READY:
- {
- Log::Write( LogLevel_Info, "REMOVE_NODE_STATUS_LEARN_READY" );
- state = ControllerState_Waiting;
- m_currentControllerCommand->m_controllerCommandNode = 0;
- break;
- }
- case REMOVE_NODE_STATUS_NODE_FOUND:
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, "REMOVE_NODE_STATUS_NODE_FOUND" );
- state = ControllerState_InProgress;
- break;
- }
- case REMOVE_NODE_STATUS_REMOVING_SLAVE:
- {
- Log::Write( LogLevel_Info, "REMOVE_NODE_STATUS_REMOVING_SLAVE" );
- if (_data[4] != 0)
+ case REMOVE_NODE_STATUS_LEARN_READY:
{
- Log::Write( LogLevel_Info, "Removing node ID %d", _data[4] );
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ Log::Write(LogLevel_Info, "REMOVE_NODE_STATUS_LEARN_READY");
+ state = ControllerState_Waiting;
+ m_currentControllerCommand->m_controllerCommandNode = 0;
+ break;
}
- else
+ case REMOVE_NODE_STATUS_NODE_FOUND:
{
- Log::Write( LogLevel_Warning, "Remove Node Failed - NodeID 0 Returned");
- state = ControllerState_Failed;
+ Log::Write(LogLevel_Info, "REMOVE_NODE_STATUS_NODE_FOUND");
+ state = ControllerState_InProgress;
+ break;
}
- break;
- }
- case REMOVE_NODE_STATUS_REMOVING_CONTROLLER:
- {
- Log::Write( LogLevel_Info, "REMOVE_NODE_STATUS_REMOVING_CONTROLLER" );
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
- if( m_currentControllerCommand->m_controllerCommandNode == 0 ) // Some controllers don't return node number
+ case REMOVE_NODE_STATUS_REMOVING_SLAVE:
+ {
+ Log::Write(LogLevel_Info, "REMOVE_NODE_STATUS_REMOVING_SLAVE");
+ if (_data[4] != 0)
+ {
+ Log::Write(LogLevel_Info, "Removing node ID %d", _data[4]);
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ }
+ else
+ {
+ Log::Write(LogLevel_Warning, "Remove Node Failed - NodeID 0 Returned");
+ state = ControllerState_Failed;
+ }
+ break;
+ }
+ case REMOVE_NODE_STATUS_REMOVING_CONTROLLER:
{
- if( _data[5] >= 3 )
+ Log::Write(LogLevel_Info, "REMOVE_NODE_STATUS_REMOVING_CONTROLLER");
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ if (m_currentControllerCommand->m_controllerCommandNode == 0) // Some controllers don't return node number
{
- LockGuard LG(m_nodeMutex);
- for( int i=0; i<256; i++ )
+ if (_data[5] >= 3)
{
- if( m_nodes[i] == NULL )
- {
- continue;
- }
- // Ignore primary controller
- if( m_nodes[i]->m_nodeId == m_Controller_nodeId )
+ Internal::LockGuard LG(m_nodeMutex);
+ for (int i = 0; i < 256; i++)
{
- continue;
- }
- // See if we can match another way
- if( m_nodes[i]->m_basic == _data[6] &&
- m_nodes[i]->m_generic == _data[7] &&
- m_nodes[i]->m_specific == _data[8] )
- {
- if( m_currentControllerCommand->m_controllerCommandNode != 0 )
+ if (m_nodes[i] == NULL)
{
- Log::Write( LogLevel_Info, "Alternative controller lookup found more then one match. Using the first one found." );
+ continue;
}
- else
+ // Ignore primary controller
+ if (m_nodes[i]->m_nodeId == m_Controller_nodeId)
{
- m_currentControllerCommand->m_controllerCommandNode = m_nodes[i]->m_nodeId;
+ continue;
+ }
+ // See if we can match another way
+ if (m_nodes[i]->m_basic == _data[6] && m_nodes[i]->m_generic == _data[7] && m_nodes[i]->m_specific == _data[8])
+ {
+ if (m_currentControllerCommand->m_controllerCommandNode != 0)
+ {
+ Log::Write(LogLevel_Info, "Alternative controller lookup found more then one match. Using the first one found.");
+ }
+ else
+ {
+ m_currentControllerCommand->m_controllerCommandNode = m_nodes[i]->m_nodeId;
+ }
}
}
+ LG.Unlock();
+ }
+ else
+ {
+ Log::Write(LogLevel_Warning, "WARNING: Node is 0 but not enough data to perform alternative match.");
}
- LG.Unlock();
}
else
{
- Log::Write( LogLevel_Warning, "WARNING: Node is 0 but not enough data to perform alternative match." );
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
}
+ WriteCache();
+ Log::Write(LogLevel_Info, "Removing controller ID %d", m_currentControllerCommand->m_controllerCommandNode);
+ break;
}
- else
- {
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
- }
- Log::Write( LogLevel_Info, "Removing controller ID %d", m_currentControllerCommand->m_controllerCommandNode );
- break;
- }
- case REMOVE_NODE_STATUS_DONE:
- {
- Log::Write( LogLevel_Info, "REMOVE_NODE_STATUS_DONE" );
- if( !m_currentControllerCommand->m_controllerCommandDone )
+ case REMOVE_NODE_STATUS_DONE:
{
-
- // Remove Node Stop calls back through here so make sure
- // we do't do it again.
- UpdateControllerState( ControllerState_Completed );
- //AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK );
- if ( m_currentControllerCommand->m_controllerCommandNode == 0 ) // never received "removing" update
+ Log::Write(LogLevel_Info, "REMOVE_NODE_STATUS_DONE");
+ if (!m_currentControllerCommand->m_controllerCommandDone)
{
- if ( _data[4] != 0 ) // but message has the clue
+
+ // Remove Node Stop calls back through here so make sure
+ // we do't do it again.
+ UpdateControllerState(ControllerState_Completed);
+ //AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK );
+ if (m_currentControllerCommand->m_controllerCommandNode == 0) // never received "removing" update
{
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ if (_data[4] != 0) // but message has the clue
+ {
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ }
}
- }
- if ( m_currentControllerCommand->m_controllerCommandNode != 0 && m_currentControllerCommand->m_controllerCommandNode != 0xff )
- {
+ if (m_currentControllerCommand->m_controllerCommandNode != 0 && m_currentControllerCommand->m_controllerCommandNode != 0xff)
{
- LockGuard LG(m_nodeMutex);
- delete m_nodes[m_currentControllerCommand->m_controllerCommandNode];
- m_nodes[m_currentControllerCommand->m_controllerCommandNode] = NULL;
+ {
+ Internal::LockGuard LG(m_nodeMutex);
+ delete m_nodes[m_currentControllerCommand->m_controllerCommandNode];
+ m_nodes[m_currentControllerCommand->m_controllerCommandNode] = NULL;
+ }
+ WriteCache();
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, m_currentControllerCommand->m_controllerCommandNode);
+ QueueNotification(notification);
}
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, m_currentControllerCommand->m_controllerCommandNode );
- QueueNotification( notification );
}
+ return;
+ }
+ case REMOVE_NODE_STATUS_FAILED:
+ {
+ //AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK );
+ Log::Write(LogLevel_Warning, "WARNING: REMOVE_NODE_STATUS_FAILED");
+ state = ControllerState_Failed;
+ break;
+ }
+ default:
+ {
+ break;
}
- return;
- }
- case REMOVE_NODE_STATUS_FAILED:
- {
- //AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK );
- Log::Write( LogLevel_Warning, "WARNING: REMOVE_NODE_STATUS_FAILED" );
- state = ControllerState_Failed;
- break;
- }
- default:
- {
- break;
- }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleControllerChangeRequest
-(
- uint8* _data
-)
+void Driver::HandleControllerChangeRequest(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "FUNC_ID_ZW_CONTROLLER_CHANGE:" );
- CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_CONTROLLER_CHANGE, _data );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "FUNC_ID_ZW_CONTROLLER_CHANGE:");
+ CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_CONTROLLER_CHANGE, _data);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleCreateNewPrimaryRequest
-(
- uint8* _data
-)
+void Driver::HandleCreateNewPrimaryRequest(uint8* _data)
{
- Log::Write( LogLevel_Info, GetNodeNumber( m_currentMsg ), "FUNC_ID_ZW_CREATE_NEW_PRIMARY:" );
- CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_CREATE_NEW_PRIMARY, _data );
+ Log::Write(LogLevel_Info, GetNodeNumber(m_currentMsg), "FUNC_ID_ZW_CREATE_NEW_PRIMARY:");
+ CommonAddNodeStatusRequestHandler( FUNC_ID_ZW_CREATE_NEW_PRIMARY, _data);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSetLearnModeRequest
-(
- uint8* _data
-)
+void Driver::HandleSetLearnModeRequest(uint8* _data)
{
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- if( m_currentControllerCommand == NULL )
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ if (m_currentControllerCommand == NULL)
{
return;
}
ControllerState state = m_currentControllerCommand->m_controllerState;
- Log::Write( LogLevel_Info, nodeId, "FUNC_ID_ZW_SET_LEARN_MODE:" );
+ Log::Write(LogLevel_Info, nodeId, "FUNC_ID_ZW_SET_LEARN_MODE:");
- switch( _data[3] )
- {
- case LEARN_MODE_STARTED:
- {
- Log::Write( LogLevel_Info, nodeId, "LEARN_MODE_STARTED" );
- state = ControllerState_Waiting;
- break;
- }
- case LEARN_MODE_DONE:
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, nodeId, "LEARN_MODE_DONE" );
- state = ControllerState_Completed;
+ case LEARN_MODE_STARTED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "LEARN_MODE_STARTED");
+ state = ControllerState_Waiting;
+ break;
+ }
+ case LEARN_MODE_DONE:
+ {
+ Log::Write(LogLevel_Info, nodeId, "LEARN_MODE_DONE");
+ state = ControllerState_Completed;
- // Stop learn mode
- Msg* msg = new Msg( "End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false );
- msg->Append( 0 );
- SendMsg( msg, MsgQueue_Command );
+ // Stop learn mode
+ Internal::Msg* msg = new Internal::Msg("End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false);
+ msg->Append(0);
+ SendMsg(msg, MsgQueue_Command);
- // Rebuild all the node info. Group and scene data that we stored
- // during replication will be applied as we discover each node.
- InitAllNodes();
- break;
- }
- case LEARN_MODE_FAILED:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: LEARN_MODE_FAILED" );
- state = ControllerState_Failed;
+ // Rebuild all the node info. Group and scene data that we stored
+ // during replication will be applied as we discover each node.
+ InitAllNodes();
+ break;
+ }
+ case LEARN_MODE_FAILED:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: LEARN_MODE_FAILED");
+ state = ControllerState_Failed;
- // Stop learn mode
- Msg* msg = new Msg( "End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false );
- msg->Append( 0 );
- SendMsg( msg, MsgQueue_Command );
+ // Stop learn mode
+ Internal::Msg* msg = new Internal::Msg("End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false);
+ msg->Append(0);
+ SendMsg(msg, MsgQueue_Command);
- // Rebuild all the node info, since it may have been partially
- // updated by the failed command. Group and scene data that we
- // stored during replication will be applied as we discover each node.
- InitAllNodes();
- break;
- }
- case LEARN_MODE_DELETED:
- {
- Log::Write( LogLevel_Info, nodeId, "LEARN_MODE_DELETED" );
- state = ControllerState_Failed;
- // Stop learn mode
- Msg* msg = new Msg( "End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false );
- msg->Append( 0 );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
+ // Rebuild all the node info, since it may have been partially
+ // updated by the failed command. Group and scene data that we
+ // stored during replication will be applied as we discover each node.
+ InitAllNodes();
+ break;
+ }
+ case LEARN_MODE_DELETED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "LEARN_MODE_DELETED");
+ state = ControllerState_Failed;
+ // Stop learn mode
+ Internal::Msg* msg = new Internal::Msg("End Learn Mode", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false);
+ msg->Append(0);
+ SendMsg(msg, MsgQueue_Command);
+ break;
+ }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleRemoveFailedNodeRequest
-(
- uint8* _data
-)
+void Driver::HandleRemoveFailedNodeRequest(uint8* _data)
{
ControllerState state = ControllerState_Completed;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- switch( _data[3] )
- {
- case FAILED_NODE_OK:
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ switch (_data[3])
{
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - Node %d is OK, so command failed", m_currentControllerCommand->m_controllerCommandNode );
- state = ControllerState_NodeOK;
- break;
- }
- case FAILED_NODE_REMOVED:
- {
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - node %d successfully moved to failed nodes list", m_currentControllerCommand->m_controllerCommandNode );
- state = ControllerState_Completed;
+ case FAILED_NODE_OK:
{
- LockGuard LG(m_nodeMutex);
- delete m_nodes[m_currentControllerCommand->m_controllerCommandNode];
- m_nodes[m_currentControllerCommand->m_controllerCommandNode] = NULL;
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - Node %d is OK, so command failed", m_currentControllerCommand->m_controllerCommandNode);
+ state = ControllerState_NodeOK;
+ break;
}
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, m_currentControllerCommand->m_controllerCommandNode );
- QueueNotification( notification );
+ case FAILED_NODE_REMOVED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - node %d successfully moved to failed nodes list", m_currentControllerCommand->m_controllerCommandNode);
+ state = ControllerState_Completed;
+ {
+ Internal::LockGuard LG(m_nodeMutex);
+ delete m_nodes[m_currentControllerCommand->m_controllerCommandNode];
+ m_nodes[m_currentControllerCommand->m_controllerCommandNode] = NULL;
+ }
+ WriteCache();
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, m_currentControllerCommand->m_controllerCommandNode);
+ QueueNotification(notification);
- break;
- }
- case FAILED_NODE_NOT_REMOVED:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - unable to move node %d to failed nodes list", m_currentControllerCommand->m_controllerCommandNode );
- state = ControllerState_Failed;
- break;
- }
+ break;
+ }
+ case FAILED_NODE_NOT_REMOVED:
+ {
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: Received reply to FUNC_ID_ZW_REMOVE_FAILED_NODE_ID - unable to move node %d to failed nodes list", m_currentControllerCommand->m_controllerCommandNode);
+ state = ControllerState_Failed;
+ break;
+ }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleReplaceFailedNodeRequest
-(
- uint8* _data
-)
+void Driver::HandleReplaceFailedNodeRequest(uint8* _data)
{
ControllerState state = ControllerState_Completed;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- switch( _data[3] )
- {
- case FAILED_NODE_OK:
- {
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node is OK, so command failed" );
- state = ControllerState_NodeOK;
- break;
- }
- case FAILED_NODE_REPLACE_WAITING:
- {
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Waiting for new node" );
- state = ControllerState_Waiting;
- break;
- }
- case FAILED_NODE_REPLACE_DONE:
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node successfully replaced" );
- state = ControllerState_Completed;
+ case FAILED_NODE_OK:
+ {
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node is OK, so command failed");
+ state = ControllerState_NodeOK;
+ break;
+ }
+ case FAILED_NODE_REPLACE_WAITING:
+ {
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Waiting for new node");
+ state = ControllerState_Waiting;
+ break;
+ }
+ case FAILED_NODE_REPLACE_DONE:
+ {
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node successfully replaced");
+ state = ControllerState_Completed;
- // Request new node info for this device
- if( m_currentControllerCommand != NULL )
+ // Request new node info for this device
+ if (m_currentControllerCommand != NULL)
+ {
+ InitNode(m_currentControllerCommand->m_controllerCommandNode, true);
+ }
+ WriteCache();
+ break;
+ }
+ case FAILED_NODE_REPLACE_FAILED:
{
- InitNode( m_currentControllerCommand->m_controllerCommandNode, true );
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node replacement failed");
+ state = ControllerState_Failed;
+ break;
}
- break;
- }
- case FAILED_NODE_REPLACE_FAILED:
- {
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_REPLACE_FAILED_NODE - Node replacement failed" );
- state = ControllerState_Failed;
- break;
- }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleApplicationCommandHandlerRequest
-(
- uint8* _data,
- bool encrypted
-)
+void Driver::HandleApplicationCommandHandlerRequest(uint8* _data, bool encrypted)
{
uint8 status = _data[2];
uint8 nodeId = _data[3];
uint8 classId = _data[5];
- Node* node = GetNodeUnsafe( nodeId );
+ Node* node = GetNodeUnsafe(nodeId);
- if( ( status & RECEIVE_STATUS_ROUTED_BUSY ) != 0 )
+ if ((status & RECEIVE_STATUS_ROUTED_BUSY) != 0)
{
m_routedbusy++;
}
- if( ( status & RECEIVE_STATUS_TYPE_BROAD ) != 0 )
+ if ((status & RECEIVE_STATUS_TYPE_BROAD) != 0)
{
m_broadcastReadCnt++;
}
- if( node != NULL )
+ if (node != NULL)
{
node->m_receivedCnt++;
node->m_errors = 0;
- int cmp = memcmp( _data, node->m_lastReceivedMessage, sizeof(node->m_lastReceivedMessage));
- if( cmp == 0 && node->m_receivedTS.TimeRemaining() > -500 )
+ int cmp = memcmp(_data, node->m_lastReceivedMessage, sizeof(node->m_lastReceivedMessage));
+ if (cmp == 0 && node->m_receivedTS.TimeRemaining() > -500)
{
// if the exact same sequence of bytes are received within 500ms
node->m_receivedDups++;
}
else
{
- memcpy( node->m_lastReceivedMessage, _data, sizeof(node->m_lastReceivedMessage) );
+ memcpy(node->m_lastReceivedMessage, _data, sizeof(node->m_lastReceivedMessage));
}
node->m_receivedTS.SetTime();
- if( m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER && m_expectedNodeId == nodeId )
+ if (m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER && m_expectedNodeId == nodeId)
{
// Need to confirm this is the correct response to the last sent request.
// At least ignore any received messages prior to the send data request.
node->m_lastResponseRTT = -node->m_sentTS.TimeRemaining();
- if( node->m_averageResponseRTT )
+ if (node->m_averageResponseRTT)
{
// if the average has been established, update by averaging the average and the last RTT
- node->m_averageResponseRTT = ( node->m_averageResponseRTT + node->m_lastResponseRTT ) >> 1;
+ node->m_averageResponseRTT = (node->m_averageResponseRTT + node->m_lastResponseRTT) >> 1;
}
else
{
// if this is the first observed RTT, set the average to this value
node->m_averageResponseRTT = node->m_lastResponseRTT;
}
- Log::Write(LogLevel_Info, nodeId, "Response RTT %d Average Response RTT %d", node->m_lastResponseRTT, node->m_averageResponseRTT );
+ Log::Write(LogLevel_Info, nodeId, "Response RTT %d Average Response RTT %d", node->m_lastResponseRTT, node->m_averageResponseRTT);
}
else
{
node->m_receivedUnsolicited++;
}
- if ( !node->IsNodeAlive() )
+ if (!node->IsNodeAlive())
{
- node->SetNodeAlive( true );
+ node->SetNodeAlive(true);
}
}
- if( ApplicationStatus::StaticGetCommandClassId() == classId )
+ if (Internal::CC::ApplicationStatus::StaticGetCommandClassId() == classId)
{
//TODO: Test this class function or implement
}
- else if( ControllerReplication::StaticGetCommandClassId() == classId )
+ else if (Internal::CC::ControllerReplication::StaticGetCommandClassId() == classId)
{
- if( m_controllerReplication && m_currentControllerCommand && ( ControllerCommand_ReceiveConfiguration == m_currentControllerCommand->m_controllerCommand ) )
+ if (m_controllerReplication && m_currentControllerCommand && (ControllerCommand_ReceiveConfiguration == m_currentControllerCommand->m_controllerCommand))
{
- m_controllerReplication->HandleMsg( &_data[6], _data[4] );
+ m_controllerReplication->HandleMsg(&_data[6], _data[4]);
- UpdateControllerState( ControllerState_InProgress );
+ UpdateControllerState(ControllerState_InProgress);
}
}
else
{
// Allow the node to handle the message itself
- if( node != NULL )
+ if (node != NULL)
{
- node->ApplicationCommandHandler( _data, encrypted );
+ node->ApplicationCommandHandler(_data, encrypted);
}
}
}
@@ -3818,10 +3617,7 @@ void Driver::HandleApplicationCommandHandlerRequest
//
// Process a request from the Z-Wave PC interface when in promiscuous mode.
//-----------------------------------------------------------------------------
-void Driver::HandlePromiscuousApplicationCommandHandlerRequest
-(
- uint8* _data
-)
+void Driver::HandlePromiscuousApplicationCommandHandlerRequest(uint8* _data)
{
//uint8 nodeId = _data[3];
//uint8 len = _data[4];
@@ -3833,245 +3629,230 @@ void Driver::HandlePromiscuousApplicationCommandHandlerRequest
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleAssignReturnRouteRequest
-(
- uint8* _data
-)
+void Driver::HandleAssignReturnRouteRequest(uint8* _data)
{
ControllerState state;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- if( m_currentControllerCommand == NULL )
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ if (m_currentControllerCommand == NULL)
{
return;
}
- if( _data[3] )
+ if (_data[3])
{
// Failed
- HandleErrorResponse( _data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_ASSIGN_RETURN_ROUTE", true );
+ HandleErrorResponse(_data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_ASSIGN_RETURN_ROUTE", true);
state = ControllerState_Failed;
}
else
{
// Success
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE for node %d - SUCCESS", m_currentControllerCommand->m_controllerCommandNode );
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_ASSIGN_RETURN_ROUTE for node %d - SUCCESS", m_currentControllerCommand->m_controllerCommandNode);
state = ControllerState_Completed;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleDeleteReturnRouteRequest
-(
- uint8* _data
-)
+void Driver::HandleDeleteReturnRouteRequest(uint8* _data)
{
ControllerState state;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- if( m_currentControllerCommand == NULL )
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ if (m_currentControllerCommand == NULL)
{
return;
}
- if( _data[3] != TRANSMIT_COMPLETE_OK)
+ if (_data[3] != TRANSMIT_COMPLETE_OK)
{
// Failed
- HandleErrorResponse( _data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_DELETE_RETURN_ROUTE", true );
+ HandleErrorResponse(_data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_DELETE_RETURN_ROUTE", true);
state = ControllerState_Failed;
}
else
{
// Success
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE for node %d - SUCCESS", m_currentControllerCommand->m_controllerCommandNode );
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_DELETE_RETURN_ROUTE for node %d - SUCCESS", m_currentControllerCommand->m_controllerCommandNode);
state = ControllerState_Completed;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleSendNodeInformationRequest
-(
- uint8* _data
-)
+void Driver::HandleSendNodeInformationRequest(uint8* _data)
{
ControllerState state;
- uint8 nodeId = GetNodeNumber( m_currentMsg );
- if( m_currentControllerCommand == NULL )
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
+ if (m_currentControllerCommand == NULL)
{
return;
}
- if( _data[3] != TRANSMIT_COMPLETE_OK )
+ if (_data[3] != TRANSMIT_COMPLETE_OK)
{
// Failed
- HandleErrorResponse( _data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_SEND_NODE_INFORMATION" );
+ HandleErrorResponse(_data[3], m_currentControllerCommand->m_controllerCommandNode, "ZW_SEND_NODE_INFORMATION");
state = ControllerState_Failed;
}
else
{
// Success
- Log::Write( LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_SEND_NODE_INFORMATION - SUCCESS" );
+ Log::Write(LogLevel_Info, nodeId, "Received reply to FUNC_ID_ZW_SEND_NODE_INFORMATION - SUCCESS");
state = ControllerState_Completed;
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-void Driver::HandleNodeNeighborUpdateRequest
-(
- uint8* _data
-)
+void Driver::HandleNodeNeighborUpdateRequest(uint8* _data)
{
- uint8 nodeId = GetNodeNumber( m_currentMsg );
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
ControllerState state = ControllerState_Normal;
- switch( _data[3] )
- {
- case REQUEST_NEIGHBOR_UPDATE_STARTED:
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, nodeId, "REQUEST_NEIGHBOR_UPDATE_STARTED" );
- state = ControllerState_InProgress;
- break;
- }
- case REQUEST_NEIGHBOR_UPDATE_DONE:
- {
- Log::Write( LogLevel_Info, nodeId, "REQUEST_NEIGHBOR_UPDATE_DONE" );
- state = ControllerState_Completed;
+ case REQUEST_NEIGHBOR_UPDATE_STARTED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "REQUEST_NEIGHBOR_UPDATE_STARTED");
+ state = ControllerState_InProgress;
+ break;
+ }
+ case REQUEST_NEIGHBOR_UPDATE_DONE:
+ {
+ Log::Write(LogLevel_Info, nodeId, "REQUEST_NEIGHBOR_UPDATE_DONE");
+ state = ControllerState_Completed;
- // We now request the neighbour information from the
- // controller and store it in our node object.
- if( m_currentControllerCommand != NULL )
+ // We now request the neighbour information from the
+ // controller and store it in our node object.
+ if (m_currentControllerCommand != NULL)
+ {
+ RequestNodeNeighbors(m_currentControllerCommand->m_controllerCommandNode, 0);
+ }
+ break;
+ }
+ case REQUEST_NEIGHBOR_UPDATE_FAILED:
{
- RequestNodeNeighbors( m_currentControllerCommand->m_controllerCommandNode, 0 );
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: REQUEST_NEIGHBOR_UPDATE_FAILED");
+ state = ControllerState_Failed;
+ break;
+ }
+ default:
+ {
+ break;
}
- break;
- }
- case REQUEST_NEIGHBOR_UPDATE_FAILED:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: REQUEST_NEIGHBOR_UPDATE_FAILED" );
- state = ControllerState_Failed;
- break;
- }
- default:
- {
- break;
- }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
//
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
-bool Driver::HandleApplicationUpdateRequest
-(
- uint8* _data
-)
+bool Driver::HandleApplicationUpdateRequest(uint8* _data)
{
bool messageRemoved = false;
uint8 nodeId = _data[3];
- Node* node = GetNodeUnsafe( nodeId );
+ Node* node = GetNodeUnsafe(nodeId);
// If node is not alive, mark it alive now
- if( node != NULL && !node->IsNodeAlive() )
+ if (node != NULL && !node->IsNodeAlive())
{
- node->SetNodeAlive( true );
+ node->SetNodeAlive(true);
}
- switch( _data[2] )
+ switch (_data[2])
{
- case UPDATE_STATE_SUC_ID:
+ case UPDATE_STATE_SUC_ID:
{
- Log::Write( LogLevel_Info, nodeId, "UPDATE_STATE_SUC_ID from node %d", nodeId );
+ Log::Write(LogLevel_Info, nodeId, "UPDATE_STATE_SUC_ID from node %d", nodeId);
m_SUCNodeId = nodeId; // need to confirm real data here
break;
}
- case UPDATE_STATE_DELETE_DONE:
+ case UPDATE_STATE_DELETE_DONE:
{
- Log::Write( LogLevel_Info, nodeId, "** Network change **: Z-Wave node %d was removed", nodeId );
+ Log::Write(LogLevel_Info, nodeId, "** Network change **: Z-Wave node %d was removed", nodeId);
{
- LockGuard LG(m_nodeMutex);
+ Internal::LockGuard LG(m_nodeMutex);
delete m_nodes[nodeId];
m_nodes[nodeId] = NULL;
}
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, nodeId );
- QueueNotification( notification );
- break;
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, nodeId);
+ QueueNotification(notification);
+ break;
}
- case UPDATE_STATE_NEW_ID_ASSIGNED:
- {
- Log::Write( LogLevel_Info, nodeId, "** Network change **: ID %d was assigned to a new Z-Wave node", nodeId );
- // Check if the new node id is equal to the current one.... if so no operation is needed, thus no remove and add is necessary
- if ( _data[3] != _data[6] )
+ case UPDATE_STATE_NEW_ID_ASSIGNED:
{
- // Request the node protocol info (also removes any existing node and creates a new one)
- InitNode( nodeId );
+ Log::Write(LogLevel_Info, nodeId, "** Network change **: ID %d was assigned to a new Z-Wave node", nodeId);
+ // Check if the new node id is equal to the current one.... if so no operation is needed, thus no remove and add is necessary
+ if (_data[3] != _data[6])
+ {
+ // Request the node protocol info (also removes any existing node and creates a new one)
+ InitNode(nodeId);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, nodeId, "Not Re-assigning NodeID as old and new NodeID match");
+ }
+
+ break;
}
- else
+ case UPDATE_STATE_ROUTING_PENDING:
{
- Log::Write(LogLevel_Info, nodeId, "Not Re-assigning NodeID as old and new NodeID match");
+ Log::Write(LogLevel_Info, nodeId, "UPDATE_STATE_ROUTING_PENDING from node %d", nodeId);
+ break;
}
-
- break;
- }
- case UPDATE_STATE_ROUTING_PENDING:
- {
- Log::Write( LogLevel_Info, nodeId, "UPDATE_STATE_ROUTING_PENDING from node %d", nodeId );
- break;
- }
- case UPDATE_STATE_NODE_INFO_REQ_FAILED:
- {
- Log::Write( LogLevel_Warning, nodeId, "WARNING: FUNC_ID_ZW_APPLICATION_UPDATE: UPDATE_STATE_NODE_INFO_REQ_FAILED received" );
-
- // Note: Unhelpfully, the nodeId is always zero in this message. We have to
- // assume the message came from the last node to which we sent a request.
- if( m_currentMsg )
+ case UPDATE_STATE_NODE_INFO_REQ_FAILED:
{
- Node* tnode = GetNodeUnsafe( m_currentMsg->GetTargetNodeId() );
- if( tnode )
- {
- // Retry the query twice
- tnode->QueryStageRetry( Node::QueryStage_NodeInfo, 2 );
+ Log::Write(LogLevel_Warning, nodeId, "WARNING: FUNC_ID_ZW_APPLICATION_UPDATE: UPDATE_STATE_NODE_INFO_REQ_FAILED received");
- // Just in case the failure was due to the node being asleep, we try
- // to move its pending messages to its wakeup queue. If it is not
- // a sleeping device, this will have no effect.
- if( MoveMessagesToWakeUpQueue( tnode->GetNodeId(), true ) )
+ // Note: Unhelpfully, the nodeId is always zero in this message. We have to
+ // assume the message came from the last node to which we sent a request.
+ if (m_currentMsg)
+ {
+ Node* tnode = GetNodeUnsafe(m_currentMsg->GetTargetNodeId());
+ if (tnode)
{
- messageRemoved = true;
+ // Retry the query twice
+ tnode->QueryStageRetry(Node::QueryStage_NodeInfo, 2);
+
+ // Just in case the failure was due to the node being asleep, we try
+ // to move its pending messages to its wakeup queue. If it is not
+ // a sleeping device, this will have no effect.
+ if (MoveMessagesToWakeUpQueue(tnode->GetNodeId(), true))
+ {
+ messageRemoved = true;
+ }
}
}
+ break;
}
- break;
- }
- case UPDATE_STATE_NODE_INFO_REQ_DONE:
- {
- Log::Write( LogLevel_Info, nodeId, "UPDATE_STATE_NODE_INFO_REQ_DONE from node %d", nodeId );
- break;
- }
- case UPDATE_STATE_NODE_INFO_RECEIVED:
- {
- Log::Write( LogLevel_Info, nodeId, "UPDATE_STATE_NODE_INFO_RECEIVED from node %d", nodeId );
- if( node )
+ case UPDATE_STATE_NODE_INFO_REQ_DONE:
{
- node->UpdateNodeInfo( &_data[8], _data[4] - 3 );
+ Log::Write(LogLevel_Info, nodeId, "UPDATE_STATE_NODE_INFO_REQ_DONE from node %d", nodeId);
+ break;
+ }
+ case UPDATE_STATE_NODE_INFO_RECEIVED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "UPDATE_STATE_NODE_INFO_RECEIVED from node %d", nodeId);
+ if (node)
+ {
+ node->UpdateNodeInfo(&_data[8], _data[4] - 3);
+ }
+ break;
}
- break;
- }
}
- if( messageRemoved )
+ if (messageRemoved)
{
m_waitingForAck = false;
m_expectedCallbackId = 0;
@@ -4087,136 +3868,134 @@ bool Driver::HandleApplicationUpdateRequest
//
// Handle common AddNode processing for many similar commands
//-----------------------------------------------------------------------------
-void Driver::CommonAddNodeStatusRequestHandler
-(
- uint8 _funcId,
- uint8* _data
-)
+void Driver::CommonAddNodeStatusRequestHandler(uint8 _funcId, uint8* _data)
{
- uint8 nodeId = GetNodeNumber( m_currentMsg );
+ uint8 nodeId = GetNodeNumber(m_currentMsg);
ControllerState state = ControllerState_Normal;
- if( m_currentControllerCommand != NULL )
+ if (m_currentControllerCommand != NULL)
{
state = m_currentControllerCommand->m_controllerState;
}
- switch( _data[3] )
- {
- case ADD_NODE_STATUS_LEARN_READY:
- {
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_LEARN_READY" );
- m_currentControllerCommand->m_controllerAdded = false;
- state = ControllerState_Waiting;
- break;
- }
- case ADD_NODE_STATUS_NODE_FOUND:
- {
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_NODE_FOUND" );
- state = ControllerState_InProgress;
- break;
- }
- case ADD_NODE_STATUS_ADDING_SLAVE:
+ switch (_data[3])
{
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_ADDING_SLAVE" );
- Log::Write( LogLevel_Info, nodeId, "Adding node ID %d - %s", _data[4], m_currentControllerCommand->m_controllerCommandArg ? "Secure" : "Non-Secure");
- /* Discovered all the CC's are sent in this packet as well:
- * position description
- * 4 - Node ID
- * 5 - Length
- * 6 - Basic Device Class
- * 7 - Generic Device Class
- * 8 - Specific Device Class
- * 9 to Length - Command Classes
- * Last pck - CRC
- */
- if( m_currentControllerCommand != NULL )
+ case ADD_NODE_STATUS_LEARN_READY:
{
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_LEARN_READY");
m_currentControllerCommand->m_controllerAdded = false;
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
- /* make sure we dont overrun our buffer. Its ok to truncate */
- uint8 length = _data[5];
- if (length > 254) length = 254;
- memcpy(&m_currentControllerCommand->m_controllerDeviceProtocolInfo, &_data[6], length);
- m_currentControllerCommand->m_controllerDeviceProtocolInfoLength = length;
- }
- // AddNodeStop( _funcId );
- // sleep(1);
- break;
- }
- case ADD_NODE_STATUS_ADDING_CONTROLLER:
- {
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_ADDING_CONTROLLER");
- Log::Write( LogLevel_Info, nodeId, "Adding controller ID %d", _data[4] );
- /* Discovered all the CC's are sent in this packet as well:
- * position description
- * 4 - Node ID
- * 5 - Length
- * 6 - Basic Device Class
- * 7 - Generic Device Class
- * 8 - Specific Device Class
- * 9 to Length - Command Classes
- * Last pck - CRC
- */
-
- if( m_currentControllerCommand != NULL )
- {
- m_currentControllerCommand->m_controllerAdded = true;
- m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ state = ControllerState_Waiting;
+ break;
}
- // AddNodeStop( _funcId );
- break;
- }
- case ADD_NODE_STATUS_PROTOCOL_DONE:
- {
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_PROTOCOL_DONE" );
- // We added a device.
- // Get the controller out of add mode to avoid accidentally adding other devices.
- // We used to call replication here.
- AddNodeStop( _funcId );
- break;
- }
- case ADD_NODE_STATUS_DONE:
- {
- if (state == ControllerState_Failed) {
- /* if it was a failed add, we just move on */
- state = ControllerState_Completed;
+ case ADD_NODE_STATUS_NODE_FOUND:
+ {
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_NODE_FOUND");
+ state = ControllerState_InProgress;
break;
}
-
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_DONE" );
- state = ControllerState_Completed;
- if( m_currentControllerCommand != NULL && m_currentControllerCommand->m_controllerCommandNode != 0xff )
+ case ADD_NODE_STATUS_ADDING_SLAVE:
+ {
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_ADDING_SLAVE");
+ Log::Write(LogLevel_Info, nodeId, "Adding node ID %d - %s", _data[4], m_currentControllerCommand->m_controllerCommandArg ? "Secure" : "Non-Secure");
+ /* Discovered all the CC's are sent in this packet as well:
+ * position description
+ * 4 - Node ID
+ * 5 - Length
+ * 6 - Basic Device Class
+ * 7 - Generic Device Class
+ * 8 - Specific Device Class
+ * 9 to Length - Command Classes
+ * Last pck - CRC
+ */
+ if (m_currentControllerCommand != NULL)
+ {
+ m_currentControllerCommand->m_controllerAdded = false;
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ /* make sure we dont overrun our buffer. Its ok to truncate */
+ uint8 length = _data[5];
+ if (length > 254)
+ length = 254;
+ memcpy(&m_currentControllerCommand->m_controllerDeviceProtocolInfo, &_data[6], length);
+ m_currentControllerCommand->m_controllerDeviceProtocolInfoLength = length;
+ }
+ // AddNodeStop( _funcId );
+ // sleep(1);
+ break;
+ }
+ case ADD_NODE_STATUS_ADDING_CONTROLLER:
+ {
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_ADDING_CONTROLLER");
+ Log::Write(LogLevel_Info, nodeId, "Adding controller ID %d", _data[4]);
+ /* Discovered all the CC's are sent in this packet as well:
+ * position description
+ * 4 - Node ID
+ * 5 - Length
+ * 6 - Basic Device Class
+ * 7 - Generic Device Class
+ * 8 - Specific Device Class
+ * 9 to Length - Command Classes
+ * Last pck - CRC
+ */
+
+ if (m_currentControllerCommand != NULL)
+ {
+ m_currentControllerCommand->m_controllerAdded = true;
+ m_currentControllerCommand->m_controllerCommandNode = _data[4];
+ }
+ // AddNodeStop( _funcId );
+ break;
+ }
+ case ADD_NODE_STATUS_PROTOCOL_DONE:
{
- InitNode( m_currentControllerCommand->m_controllerCommandNode, true, m_currentControllerCommand->m_controllerCommandArg != 0, m_currentControllerCommand->m_controllerDeviceProtocolInfo, m_currentControllerCommand->m_controllerDeviceProtocolInfoLength );
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_PROTOCOL_DONE");
+ // We added a device.
+ // Get the controller out of add mode to avoid accidentally adding other devices.
+ // We used to call replication here.
+ AddNodeStop(_funcId);
+ break;
}
-
- // Not sure about the new controller function here.
- if( _funcId != FUNC_ID_ZW_ADD_NODE_TO_NETWORK && m_currentControllerCommand != NULL && m_currentControllerCommand->m_controllerAdded )
+ case ADD_NODE_STATUS_DONE:
{
- // Rebuild all the node info. Group and scene data that we stored
- // during replication will be applied as we discover each node.
- InitAllNodes();
+ if (state == ControllerState_Failed)
+ {
+ /* if it was a failed add, we just move on */
+ state = ControllerState_Completed;
+ break;
+ }
+
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_DONE");
+ state = ControllerState_Completed;
+ if (m_currentControllerCommand != NULL && m_currentControllerCommand->m_controllerCommandNode != 0xff)
+ {
+ InitNode(m_currentControllerCommand->m_controllerCommandNode, true, m_currentControllerCommand->m_controllerCommandArg != 0, m_currentControllerCommand->m_controllerDeviceProtocolInfo, m_currentControllerCommand->m_controllerDeviceProtocolInfoLength);
+ }
+
+ // Not sure about the new controller function here.
+ if (_funcId != FUNC_ID_ZW_ADD_NODE_TO_NETWORK && m_currentControllerCommand != NULL && m_currentControllerCommand->m_controllerAdded)
+ {
+ // Rebuild all the node info. Group and scene data that we stored
+ // during replication will be applied as we discover each node.
+ InitAllNodes();
+ }
+ break;
}
- break;
- }
- case ADD_NODE_STATUS_FAILED:
- {
- Log::Write( LogLevel_Info, nodeId, "ADD_NODE_STATUS_FAILED" );
- state = ControllerState_Failed;
+ case ADD_NODE_STATUS_FAILED:
+ {
+ Log::Write(LogLevel_Info, nodeId, "ADD_NODE_STATUS_FAILED");
+ state = ControllerState_Failed;
- // Remove the AddNode command from the queue
- RemoveCurrentMsg();
+ // Remove the AddNode command from the queue
+ RemoveCurrentMsg();
- // Get the controller out of add mode to avoid accidentally adding other devices.
- AddNodeStop( _funcId );
- break;
- }
- default:
- {
- break;
- }
+ // Get the controller out of add mode to avoid accidentally adding other devices.
+ AddNodeStop(_funcId);
+ break;
+ }
+ default:
+ {
+ break;
+ }
}
- UpdateControllerState( state );
+ UpdateControllerState(state);
}
//-----------------------------------------------------------------------------
@@ -4227,35 +4006,31 @@ void Driver::CommonAddNodeStatusRequestHandler
//
// Enable polling of a value
//-----------------------------------------------------------------------------
-bool Driver::EnablePoll
-(
- ValueID const &_valueId,
- uint8 const _intensity
-)
+bool Driver::EnablePoll(ValueID const &_valueId, uint8 const _intensity)
{
// make sure the polling thread doesn't lock the node while we're in this function
m_pollMutex->Lock();
// confirm that this node exists
uint8 nodeId = _valueId.GetNodeId();
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( nodeId );
- if( node != NULL )
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(nodeId);
+ if (node != NULL)
{
// confirm that this value is in the node's value store
- if( Value* value = node->GetValue( _valueId ) )
+ if (Internal::VC::Value* value = node->GetValue(_valueId))
{
// update the value's pollIntensity
- value->SetPollIntensity( _intensity );
+ value->SetPollIntensity(_intensity);
// Add the valueid to the polling list
// See if the node is already in the poll list.
- for( list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it )
+ for (list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it)
{
- if( (*it).m_id == _valueId )
+ if ((*it).m_id == _valueId)
{
// It is already in the poll list, so we have nothing to do.
- Log::Write( LogLevel_Detail, "EnablePoll not required to do anything (value is already in the poll list)" );
+ Log::Write(LogLevel_Detail, "EnablePoll not required to do anything (value is already in the poll list)");
value->Release();
m_pollMutex->Unlock();
return true;
@@ -4266,30 +4041,30 @@ bool Driver::EnablePoll
PollEntry pe;
pe.m_id = _valueId;
pe.m_pollCounter = value->GetPollIntensity();
- m_pollList.push_back( pe );
+ m_pollList.push_back(pe);
value->Release();
m_pollMutex->Unlock();
// send notification to indicate polling is enabled
- Notification* notification = new Notification( Notification::Type_PollingEnabled );
- notification->SetHomeAndNodeIds( m_homeId, _valueId.GetNodeId() );
- 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() );
+ Notification* notification = new Notification(Notification::Type_PollingEnabled);
+ 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());
return true;
}
// allow the poll thread to continue
m_pollMutex->Unlock();
- Log::Write( LogLevel_Info, nodeId, "EnablePoll failed - value not found for node %d", nodeId );
+ Log::Write(LogLevel_Info, nodeId, "EnablePoll failed - value not found for node %d", nodeId);
return false;
}
// allow the poll thread to continue
m_pollMutex->Unlock();
- Log::Write( LogLevel_Info, "EnablePoll failed - node %d not found", nodeId );
+ Log::Write(LogLevel_Info, "EnablePoll failed - node %d not found", nodeId);
return false;
}
@@ -4297,57 +4072,54 @@ bool Driver::EnablePoll
//
// Disable polling of a node
//-----------------------------------------------------------------------------
-bool Driver::DisablePoll
-(
- ValueID const &_valueId
-)
+bool Driver::DisablePoll(ValueID const &_valueId)
{
// make sure the polling thread doesn't lock the node while we're in this function
m_pollMutex->Lock();
// confirm that this node exists
uint8 nodeId = _valueId.GetNodeId();
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( nodeId );
- if( node != NULL)
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(nodeId);
+ if (node != NULL)
{
// See if the value is already in the poll list.
- for( list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it )
+ for (list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it)
{
- if( (*it).m_id == _valueId )
+ if ((*it).m_id == _valueId)
{
// Found it
// remove it from the poll list
- m_pollList.erase( it );
+ m_pollList.erase(it);
// get the value object and reset pollIntensity to zero (indicating no polling)
- Value* value = GetValue( _valueId );
+ Internal::VC::Value* value = GetValue(_valueId);
if (!value)
continue;
- value->SetPollIntensity( 0 );
+ value->SetPollIntensity(0);
value->Release();
m_pollMutex->Unlock();
// send notification to indicate polling is disabled
- Notification* notification = new Notification( Notification::Type_PollingDisabled );
- notification->SetHomeAndNodeIds( m_homeId, _valueId.GetNodeId() );
- QueueNotification( notification );
- Log::Write( LogLevel_Info, nodeId, "DisablePoll 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() );
+ Notification* notification = new Notification(Notification::Type_PollingDisabled);
+ notification->SetHomeAndNodeIds(m_homeId, _valueId.GetNodeId());
+ notification->SetValueId(_valueId);
+ QueueNotification(notification);
+ Log::Write(LogLevel_Info, nodeId, "DisablePoll 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());
return true;
}
}
// Not in the list
m_pollMutex->Unlock();
- Log::Write( LogLevel_Info, nodeId, "DisablePoll failed - value not on list");
+ Log::Write(LogLevel_Info, nodeId, "DisablePoll failed - value not on list");
return false;
}
// allow the poll thread to continue
m_pollMutex->Unlock();
- Log::Write( LogLevel_Info, "DisablePoll failed - node %d not found", nodeId );
+ Log::Write(LogLevel_Info, "DisablePoll failed - node %d not found", nodeId);
return false;
}
@@ -4355,18 +4127,15 @@ bool Driver::DisablePoll
//
// Check polling status of a value
//-----------------------------------------------------------------------------
-bool Driver::isPolled
-(
- ValueID const &_valueId
-)
+bool Driver::isPolled(ValueID const &_valueId)
{
bool bPolled;
// make sure the polling thread doesn't lock the node while we're in this function
m_pollMutex->Lock();
- Value* value = GetValue( _valueId );
- if( value && value->GetPollIntensity() != 0 )
+ Internal::VC::Value* value = GetValue(_valueId);
+ if (value && value->GetPollIntensity() != 0)
{
bPolled = true;
}
@@ -4375,7 +4144,8 @@ bool Driver::isPolled
bPolled = false;
}
- if (value) value->Release();
+ if (value)
+ value->Release();
/*
* This code is retained for the moment as a belt-and-suspenders test to confirm that
@@ -4384,46 +4154,46 @@ bool Driver::isPolled
*/
// confirm that this node exists
uint8 nodeId = _valueId.GetNodeId();
- LockGuard LG(m_nodeMutex);
- Node* node = GetNode( nodeId );
- if( node != NULL)
+ Internal::LockGuard LG(m_nodeMutex);
+ Node* node = GetNode(nodeId);
+ if (node != NULL)
{
// See if the value is already in the poll list.
- for( list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it )
+ for (list::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it)
{
- if( (*it).m_id == _valueId )
+ if ((*it).m_id == _valueId)
{
// Found it
- if( bPolled )
+ if (bPolled)
{
m_pollMutex->Unlock();
return true;
}
else
{
- Log::Write( LogLevel_Error, nodeId, "IsPolled setting for valueId 0x%016x is not consistent with the poll list", _valueId.GetId() );
+ Log::Write(LogLevel_Error, nodeId, "IsPolled setting for valueId 0x%016x is not consistent with the poll list", _valueId.GetId());
}
}
}
// Not in the list
- if( !bPolled )
+ if (!bPolled)
{
m_pollMutex->Unlock();
return false;
}
else
{
- Log::Write( LogLevel_Error, nodeId, "IsPolled setting for valueId 0x%016x is not consistent with the poll list", _valueId.GetId() );
+ Log::Write(LogLevel_Error, nodeId, "IsPolled setting for valueId 0x%016x is not consistent with the poll list", _valueId.GetId());
}
}
// allow the poll thread to continue
m_pollMutex->Unlock();
- Log::Write( LogLevel_Info, "isPolled failed - node %d not found (the value reported that it is%s polled)", nodeId, bPolled?"":" not" );
+ Log::Write(LogLevel_Info, "isPolled failed - node %d not found (the value reported that it is%s polled)", nodeId, bPolled ? "" : " not");
return false;
}
@@ -4431,19 +4201,15 @@ bool Driver::isPolled
//
// Set the intensity with which this value is polled
//-----------------------------------------------------------------------------
-void Driver::SetPollIntensity
-(
- ValueID const &_valueId,
- uint8 const _intensity
-)
+void Driver::SetPollIntensity(ValueID const &_valueId, uint8 const _intensity)
{
// make sure the polling thread doesn't lock the value while we're in this function
m_pollMutex->Lock();
- Value* value = GetValue( _valueId );
+ Internal::VC::Value* value = GetValue(_valueId);
if (!value)
return;
- value->SetPollIntensity( _intensity );
+ value->SetPollIntensity(_intensity);
value->Release();
m_pollMutex->Unlock();
@@ -4453,16 +4219,12 @@ void Driver::SetPollIntensity
//
// Entry point of the thread for poll Z-Wave devices
//-----------------------------------------------------------------------------
-void Driver::PollThreadEntryPoint
-(
- Event* _exitEvent,
- void* _context
-)
+void Driver::PollThreadEntryPoint(Internal::Platform::Event* _exitEvent, void* _context)
{
- Driver* driver = (Driver*)_context;
- if( driver )
+ Driver* driver = (Driver*) _context;
+ if (driver)
{
- driver->PollThreadProc( _exitEvent );
+ driver->PollThreadProc(_exitEvent);
}
}
@@ -4470,16 +4232,13 @@ void Driver::PollThreadEntryPoint
//
// Thread for poll Z-Wave devices
//-----------------------------------------------------------------------------
-void Driver::PollThreadProc
-(
- Event* _exitEvent
-)
+void Driver::PollThreadProc(Internal::Platform::Event* _exitEvent)
{
- while( 1 )
+ while (1)
{
int32 pollInterval = m_pollInterval;
- if( m_awakeNodesQueried && !m_pollList.empty() )
+ if (m_awakeNodesQueried && !m_pollList.empty())
{
// We only bother getting the lock if the pollList is not empty
m_pollMutex->Lock();
@@ -4487,13 +4246,13 @@ void Driver::PollThreadProc
// Get the next value to be polled
PollEntry pe = m_pollList.front();
m_pollList.pop_front();
- ValueID valueId = pe.m_id;
+ ValueID valueId = pe.m_id;
// only execute this poll if pe.m_pollCounter == 1; otherwise decrement the counter and process the next polled value
- if( pe.m_pollCounter != 1)
+ if (pe.m_pollCounter != 1)
{
pe.m_pollCounter--;
- m_pollList.push_back( pe );
+ m_pollList.push_back(pe);
m_pollMutex->Unlock();
continue;
}
@@ -4501,40 +4260,40 @@ void Driver::PollThreadProc
// reset the poll counter to the full pollIntensity value and push it at the end of the list
// release the value object referenced; call GetNode to ensure the node objects are locked during this period
{
- LockGuard LG(m_nodeMutex);
- (void)GetNode( valueId.GetNodeId() );
- Value* value = GetValue( valueId );
+ Internal::LockGuard LG(m_nodeMutex);
+ (void) GetNode(valueId.GetNodeId());
+ Internal::VC::Value* value = GetValue(valueId);
if (!value)
continue;
pe.m_pollCounter = value->GetPollIntensity();
- m_pollList.push_back( pe );
+ 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 (!m_bIntervalBetweenPolls)
{
- if( pollInterval < 100 )
+ 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 );
+ 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();
}
{
- LockGuard LG(m_nodeMutex);
+ Internal::LockGuard LG(m_nodeMutex);
// Request the state of the value from the node to which it belongs
- if( Node* node = GetNode( valueId.GetNodeId() ) )
+ if (Node* node = GetNode(valueId.GetNodeId()))
{
bool requestState = true;
- if( !node->IsListeningDevice() )
+ if (!node->IsListeningDevice())
{
// The device is not awake all the time. If it is not awake, we mark it
// as requiring a poll. The poll will be done next time the node wakes up.
- if( WakeUp* wakeUp = static_cast( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) )
+ if (Internal::CC::WakeUp* wakeUp = static_cast(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
{
- if( !wakeUp->IsAwake() )
+ if (!wakeUp->IsAwake())
{
wakeUp->SetPollRequired();
requestState = false;
@@ -4542,15 +4301,16 @@ void Driver::PollThreadProc
}
}
- if( requestState )
+ if (requestState)
{
// Request an update of the value
- CommandClass* cc = node->GetCommandClass( valueId.GetCommandClassId() );
- if (cc) {
+ Internal::CC::CommandClass* cc = node->GetCommandClass(valueId.GetCommandClassId());
+ if (cc)
+ {
uint16_t index = valueId.GetIndex();
uint8_t instance = valueId.GetInstance();
- Log::Write( LogLevel_Detail, node->m_nodeId, "Polling: %s index = %d instance = %d (poll queue has %d messages)", cc->GetCommandClassName().c_str(), index, instance, m_msgQueue[MsgQueue_Poll].size() );
- cc->RequestValue( 0, index, instance, MsgQueue_Poll );
+ Log::Write(LogLevel_Detail, node->m_nodeId, "Polling: %s index = %d instance = %d (poll queue has %d messages)", cc->GetCommandClassName().c_str(), index, instance, m_msgQueue[MsgQueue_Poll].size());
+ cc->RequestValue(0, index, instance, MsgQueue_Poll);
}
}
@@ -4566,30 +4326,26 @@ void Driver::PollThreadProc
// Wait until the library isn't actively sending messages (or in the midst of a transaction)
int i32;
int loopCount = 0;
- while( !m_msgQueue[MsgQueue_Poll].empty()
- || !m_msgQueue[MsgQueue_Send].empty()
- || !m_msgQueue[MsgQueue_Command].empty()
- || !m_msgQueue[MsgQueue_Query].empty()
- || m_currentMsg != NULL )
- {
- i32 = Wait::Single( _exitEvent, 10); // test conditions every 10ms
- if( i32 == 0 )
+ while (!m_msgQueue[MsgQueue_Poll].empty() || !m_msgQueue[MsgQueue_Send].empty() || !m_msgQueue[MsgQueue_Command].empty() || !m_msgQueue[MsgQueue_Query].empty() || m_currentMsg != NULL)
+ {
+ i32 = Internal::Platform::Wait::Single(_exitEvent, 10); // test conditions every 10ms
+ if (i32 == 0)
{
// Exit has been called
return;
}
loopCount++;
- if( loopCount == 3000*10 ) // 300 seconds worth of delay? Something unusual is going on
+ if (loopCount == 3000 * 10) // 300 seconds worth of delay? Something unusual is going on
{
- Log::Write( LogLevel_Warning, "Poll queue hasn't been able to execute for 300 secs or more" );
+ Log::Write(LogLevel_Warning, "Poll queue hasn't been able to execute for 300 secs or more");
Log::QueueDump();
// assert( 0 );
}
}
// ready for next poll...insert the pollInterval delay
- i32 = Wait::Single( _exitEvent, pollInterval );
- if( i32 == 0 )
+ i32 = Internal::Platform::Wait::Single(_exitEvent, pollInterval);
+ if (i32 == 0)
{
// Exit has been called
return;
@@ -4598,8 +4354,8 @@ void Driver::PollThreadProc
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 = Wait::Single( _exitEvent, 500 );
- if( i32 == 0 )
+ int32 i32 = Internal::Platform::Wait::Single(_exitEvent, 500);
+ if (i32 == 0)
{
// Exit has been called
return;
@@ -4616,16 +4372,14 @@ void Driver::PollThreadProc
//
// Delete all nodes and fetch new node data from the Z-Wave network
//-----------------------------------------------------------------------------
-void Driver::InitAllNodes
-(
-)
+void Driver::InitAllNodes()
{
// Delete all the node data
{
- LockGuard LG(m_nodeMutex);
- for( int i=0; i<256; ++i )
+ Internal::LockGuard LG(m_nodeMutex);
+ for (int i = 0; i < 256; ++i)
{
- if( m_nodes[i] )
+ if (m_nodes[i])
{
delete m_nodes[i];
m_nodes[i] = NULL;
@@ -4633,47 +4387,46 @@ void Driver::InitAllNodes
}
}
// Fetch new node data from the Z-Wave network
- m_controller->PlayInitSequence( this );
+ m_controller->PlayInitSequence(this);
}
//-----------------------------------------------------------------------------
//
// Queue a node to be interrogated for its setup details
//-----------------------------------------------------------------------------
-void Driver::InitNode
-(
- uint8 const _nodeId,
- bool newNode,
- bool secure,
- uint8 const *_protocolInfo,
- uint8 const _length
-)
+void Driver::InitNode(uint8 const _nodeId, bool newNode, bool secure, uint8 const *_protocolInfo, uint8 const _length)
{
// Delete any existing node and replace it with a new one
{
- LockGuard LG(m_nodeMutex);
- if( m_nodes[_nodeId] )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (m_nodes[_nodeId])
{
// Remove the original node
delete m_nodes[_nodeId];
- Notification* notification = new Notification( Notification::Type_NodeRemoved );
- notification->SetHomeAndNodeIds( m_homeId, _nodeId );
- QueueNotification( notification );
+ m_nodes[_nodeId] = NULL;
+ WriteCache();
+ Notification* notification = new Notification(Notification::Type_NodeRemoved);
+ notification->SetHomeAndNodeIds(m_homeId, _nodeId);
+ QueueNotification(notification);
}
// Add the new node
- m_nodes[_nodeId] = new Node( m_homeId, _nodeId );
- if (newNode == true) static_cast(m_nodes[_nodeId])->SetAddingNode();
+ m_nodes[_nodeId] = new Node(m_homeId, _nodeId);
+ if (newNode == true)
+ static_cast(m_nodes[_nodeId])->SetAddingNode();
}
- Notification* notification = new Notification( Notification::Type_NodeAdded );
- notification->SetHomeAndNodeIds( m_homeId, _nodeId );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_NodeAdded);
+ notification->SetHomeAndNodeIds(m_homeId, _nodeId);
+ QueueNotification(notification);
- if (_length == 0) {
+ if (_length == 0)
+ {
// Request the node info
- m_nodes[_nodeId]->SetQueryStage( Node::QueryStage_ProtocolInfo );
- } else {
+ m_nodes[_nodeId]->SetQueryStage(Node::QueryStage_ProtocolInfo);
+ }
+ else
+ {
if (isNetworkKeySet())
m_nodes[_nodeId]->SetSecured(secure);
else
@@ -4687,14 +4440,11 @@ void Driver::InitNode
//
// Get whether the node is a listening device that does not go to sleep
//-----------------------------------------------------------------------------
-bool Driver::IsNodeListeningDevice
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeListeningDevice(uint8 const _nodeId)
{
bool res = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
res = node->IsListeningDevice();
}
@@ -4706,14 +4456,11 @@ bool Driver::IsNodeListeningDevice
//
// Get whether the node is a listening device that does not go to sleep
//-----------------------------------------------------------------------------
-bool Driver::IsNodeFrequentListeningDevice
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeFrequentListeningDevice(uint8 const _nodeId)
{
bool res = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
res = node->IsFrequentListeningDevice();
}
@@ -4725,14 +4472,11 @@ bool Driver::IsNodeFrequentListeningDevice
//
// Get whether the node is a beam capable device.
//-----------------------------------------------------------------------------
-bool Driver::IsNodeBeamingDevice
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeBeamingDevice(uint8 const _nodeId)
{
bool res = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
res = node->IsBeamingDevice();
}
@@ -4744,14 +4488,11 @@ bool Driver::IsNodeBeamingDevice
//
// Get whether the node is a routing device that passes messages to other nodes
//-----------------------------------------------------------------------------
-bool Driver::IsNodeRoutingDevice
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeRoutingDevice(uint8 const _nodeId)
{
bool res = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
res = node->IsRoutingDevice();
}
@@ -4763,14 +4504,11 @@ bool Driver::IsNodeRoutingDevice
//
// Get the security attribute for a node
//-----------------------------------------------------------------------------
-bool Driver::IsNodeSecurityDevice
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeSecurityDevice(uint8 const _nodeId)
{
bool security = false;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
security = node->IsSecurityDevice();
}
@@ -4782,14 +4520,11 @@ bool Driver::IsNodeSecurityDevice
//
// Get the maximum baud rate of a node's communications
//-----------------------------------------------------------------------------
-uint32 Driver::GetNodeMaxBaudRate
-(
- uint8 const _nodeId
-)
+uint32 Driver::GetNodeMaxBaudRate(uint8 const _nodeId)
{
uint32 baud = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
baud = node->GetMaxBaudRate();
}
@@ -4801,14 +4536,11 @@ uint32 Driver::GetNodeMaxBaudRate
//
// Get the version number of a node
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeVersion
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeVersion(uint8 const _nodeId)
{
uint8 version = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
version = node->GetVersion();
}
@@ -4820,14 +4552,11 @@ uint8 Driver::GetNodeVersion
//
// Get the security byte of a node
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeSecurity
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeSecurity(uint8 const _nodeId)
{
uint8 security = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
security = node->GetSecurity();
}
@@ -4839,14 +4568,11 @@ uint8 Driver::GetNodeSecurity
//
// Get the basic type of a node
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeBasic
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeBasic(uint8 const _nodeId)
{
uint8 basic = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
basic = node->GetBasic();
}
@@ -4854,56 +4580,96 @@ uint8 Driver::GetNodeBasic
return basic;
}
+//-----------------------------------------------------------------------------
+//
+// Get the basic type of a node
+//-----------------------------------------------------------------------------
+string Driver::GetNodeBasicString(uint8 const _nodeId)
+{
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
+ {
+ return node->GetBasicString();
+ }
+
+ return "Unknown";
+}
+
+
+
+
//-----------------------------------------------------------------------------
//
// Get the generic type of a node
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeGeneric
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeGeneric(uint8 const _nodeId, uint8 const _instance)
{
uint8 genericType = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- genericType = node->GetGeneric();
+ genericType = node->GetGeneric(_instance);
}
return genericType;
}
+//-----------------------------------------------------------------------------
+//
+// Get the generic type of a node
+//-----------------------------------------------------------------------------
+string Driver::GetNodeGenericString(uint8 const _nodeId, uint8 const _instance)
+{
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
+ {
+ return node->GetGenericString(_instance);
+ }
+
+ return "Unknown";
+}
+
+
//-----------------------------------------------------------------------------
//
// Get the specific type of a node
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeSpecific
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeSpecific(uint8 const _nodeId, uint8 const _instance)
{
uint8 specific = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- specific = node->GetSpecific();
+ specific = node->GetSpecific(_instance);
}
return specific;
}
+//-----------------------------------------------------------------------------
+//
+// Get the specific type of a node
+//-----------------------------------------------------------------------------
+string Driver::GetNodeSpecificString(uint8 const _nodeId, uint8 const _instance)
+{
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
+ {
+ return node->GetSpecificString(_instance);
+ }
+
+ return "Unknown";
+}
+
//-----------------------------------------------------------------------------
//
// Get the basic/generic/specific type of the specified node
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-string Driver::GetNodeType
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeType(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetType();
}
@@ -4911,36 +4677,27 @@ string Driver::GetNodeType
return "Unknown";
}
-
-bool Driver::IsNodeZWavePlus
-(
- uint8 const _nodeId
-)
+bool Driver::IsNodeZWavePlus(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->IsNodeZWavePlus();
}
return false;
}
-
//-----------------------------------------------------------------------------
//
// Gets the neighbors for a node
//-----------------------------------------------------------------------------
-uint32 Driver::GetNodeNeighbors
-(
- uint8 const _nodeId,
- uint8** o_neighbors
-)
+uint32 Driver::GetNodeNeighbors(uint8 const _nodeId, uint8** o_neighbors)
{
uint32 numNeighbors = 0;
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- numNeighbors = node->GetNeighbors( o_neighbors );
+ numNeighbors = node->GetNeighbors(o_neighbors);
}
return numNeighbors;
@@ -4951,13 +4708,10 @@ uint32 Driver::GetNodeNeighbors
// Get the manufacturer name for the node with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-string Driver::GetNodeManufacturerName
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeManufacturerName(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetManufacturerName();
}
@@ -4970,13 +4724,10 @@ string Driver::GetNodeManufacturerName
// Get the product name for the node with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-string Driver::GetNodeProductName
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeProductName(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetProductName();
}
@@ -4989,13 +4740,10 @@ string Driver::GetNodeProductName
// Get the user-editable name for the node with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-string Driver::GetNodeName
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeName(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetNodeName();
}
@@ -5008,13 +4756,10 @@ string Driver::GetNodeName
// Get the user-editable string for location of the specified node
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-string Driver::GetNodeLocation
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeLocation(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetLocation();
}
@@ -5027,13 +4772,10 @@ string Driver::GetNodeLocation
// Get the manufacturer Id string value with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-uint16 Driver::GetNodeManufacturerId
-(
- uint8 const _nodeId
-)
+uint16 Driver::GetNodeManufacturerId(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetManufacturerId();
}
@@ -5046,13 +4788,10 @@ uint16 Driver::GetNodeManufacturerId
// Get the product type string value with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-uint16 Driver::GetNodeProductType
-(
- uint8 const _nodeId
-)
+uint16 Driver::GetNodeProductType(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetProductType();
}
@@ -5065,13 +4804,10 @@ uint16 Driver::GetNodeProductType
// Get the product Id string value with the specified ID
// Returns a copy of the string rather than a const ref for thread safety
//-----------------------------------------------------------------------------
-uint16 Driver::GetNodeProductId
-(
- uint8 const _nodeId
-)
+uint16 Driver::GetNodeProductId(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetProductId();
}
@@ -5083,13 +4819,10 @@ uint16 Driver::GetNodeProductId
//
// Get the node device type as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-uint16 Driver::GetNodeDeviceType
-(
- uint8 const _nodeId
-)
+uint16 Driver::GetNodeDeviceType(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetDeviceType();
}
@@ -5102,14 +4835,11 @@ uint16 Driver::GetNodeDeviceType
// Get the node DeviceType as a string as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-string Driver::GetNodeDeviceTypeString
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeDeviceTypeString(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetDeviceTypeString();
}
@@ -5117,19 +4847,14 @@ string Driver::GetNodeDeviceTypeString
return ""; // unknown
}
-
-
//-----------------------------------------------------------------------------
//
// Get the node role as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodeRole
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodeRole(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetRoleType();
}
@@ -5141,13 +4866,10 @@ uint8 Driver::GetNodeRole
//
// Get the node role as a string as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-string Driver::GetNodeRoleString
-(
- uint8 const _nodeId
-)
+string Driver::GetNodeRoleString(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetRoleTypeString();
}
@@ -5159,13 +4881,10 @@ string Driver::GetNodeRoleString
//
// Get the node role as a string as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-uint8 Driver::GetNodePlusType
-(
- uint8 const _nodeId
-)
+uint8 Driver::GetNodePlusType(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetNodeType();
}
@@ -5176,37 +4895,26 @@ uint8 Driver::GetNodePlusType
//
// Get the node role as a string as reported in the Z-Wave+ Info report.
//-----------------------------------------------------------------------------
-string Driver::GetNodePlusTypeString
-(
- uint8 const _nodeId
-)
+string Driver::GetNodePlusTypeString(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
return node->GetNodeTypeString();
}
return ""; // unknown
}
-
-
-
-
//-----------------------------------------------------------------------------
//
// Set the manufacturer name for the node with the specified ID
//-----------------------------------------------------------------------------
-void Driver::SetNodeManufacturerName
-(
- uint8 const _nodeId,
- string const& _manufacturerName
-)
+void Driver::SetNodeManufacturerName(uint8 const _nodeId, string const& _manufacturerName)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- node->SetManufacturerName( _manufacturerName );
+ node->SetManufacturerName(_manufacturerName);
}
}
@@ -5214,16 +4922,12 @@ void Driver::SetNodeManufacturerName
//
// Set the product name string value with the specified ID
//-----------------------------------------------------------------------------
-void Driver::SetNodeProductName
-(
- uint8 const _nodeId,
- string const& _productName
-)
+void Driver::SetNodeProductName(uint8 const _nodeId, string const& _productName)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- node->SetProductName( _productName );
+ node->SetProductName(_productName);
}
}
@@ -5231,16 +4935,12 @@ void Driver::SetNodeProductName
//
// Set the node name string value with the specified ID
//-----------------------------------------------------------------------------
-void Driver::SetNodeName
-(
- uint8 const _nodeId,
- string const& _nodeName
-)
+void Driver::SetNodeName(uint8 const _nodeId, string const& _nodeName)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- node->SetNodeName( _nodeName );
+ node->SetNodeName(_nodeName);
}
}
@@ -5248,16 +4948,12 @@ void Driver::SetNodeName
//
// Set the location string value with the specified ID
//-----------------------------------------------------------------------------
-void Driver::SetNodeLocation
-(
- uint8 const _nodeId,
- string const& _location
-)
+void Driver::SetNodeLocation(uint8 const _nodeId, string const& _location)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- node->SetLocation( _location );
+ node->SetLocation(_location);
}
}
@@ -5265,16 +4961,12 @@ void Driver::SetNodeLocation
//
// Helper to set the node level through the basic command class
//-----------------------------------------------------------------------------
-void Driver::SetNodeLevel
-(
- uint8 const _nodeId,
- uint8 const _level
-)
+void Driver::SetNodeLevel(uint8 const _nodeId, uint8 const _level)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
- node->SetLevel( _level );
+ node->SetLevel(_level);
}
}
@@ -5282,13 +4974,10 @@ void Driver::SetNodeLevel
//
// Helper to set the node on through the basic command class
//-----------------------------------------------------------------------------
-void Driver::SetNodeOn
-(
- uint8 const _nodeId
-)
+void Driver::SetNodeOn(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
node->SetNodeOn();
}
@@ -5298,13 +4987,10 @@ void Driver::SetNodeOn
//
// Helper to set the node off through the basic command class
//-----------------------------------------------------------------------------
-void Driver::SetNodeOff
-(
- uint8 const _nodeId
-)
+void Driver::SetNodeOff(uint8 const _nodeId)
{
- LockGuard LG(m_nodeMutex);
- if( Node* node = GetNode( _nodeId ) )
+ Internal::LockGuard LG(m_nodeMutex);
+ if (Node* node = GetNode(_nodeId))
{
node->SetNodeOff();
}
@@ -5314,16 +5000,13 @@ void Driver::SetNodeOff
//
// Get a pointer to a Value object for the specified ValueID
//-----------------------------------------------------------------------------
-Value* Driver::GetValue
-(
- ValueID const& _id
-)
+Internal::VC::Value* Driver::GetValue(ValueID const& _id)
{
// This method is only called by code that has already locked the node
- if( Node* node = m_nodes[_id.GetNodeId()] )
+ if (Node* node = m_nodes[_id.GetNodeId()])
{
- return node->GetValue( _id );
+ return node->GetValue(_id);
}
return NULL;
@@ -5337,52 +5020,43 @@ Value* Driver::GetValue
//
// Reset controller and erase all node information
//-----------------------------------------------------------------------------
-void Driver::ResetController
-(
- Event* _evt
-)
+void Driver::ResetController(Internal::Platform::Event* _evt)
{
m_controllerResetEvent = _evt;
- Log::Write( LogLevel_Info, "Reset controller and erase all node information");
- Msg* msg = new Msg( "Reset controller and erase all node information", 0xff, REQUEST, FUNC_ID_ZW_SET_DEFAULT, true );
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Info, "Reset controller and erase all node information");
+ Internal::Msg* msg = new Internal::Msg("Reset controller and erase all node information", 0xff, REQUEST, FUNC_ID_ZW_SET_DEFAULT, true);
+ SendMsg(msg, MsgQueue_Command);
}
//-----------------------------------------------------------------------------
//
// Soft-reset the Z-Wave controller chip
//-----------------------------------------------------------------------------
-void Driver::SoftReset
-(
-)
+void Driver::SoftReset()
{
- Log::Write( LogLevel_Info, "Soft-resetting the Z-Wave controller chip");
- Msg* msg = new Msg( "Soft-resetting the Z-Wave controller chip", 0xff, REQUEST, FUNC_ID_SERIAL_API_SOFT_RESET, false, false );
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Info, "Soft-resetting the Z-Wave controller chip");
+ Internal::Msg* msg = new Internal::Msg("Soft-resetting the Z-Wave controller chip", 0xff, REQUEST, FUNC_ID_SERIAL_API_SOFT_RESET, false, false);
+ SendMsg(msg, MsgQueue_Command);
}
//-----------------------------------------------------------------------------
//
// Get the neighbour information for a node from the controller
//-----------------------------------------------------------------------------
-void Driver::RequestNodeNeighbors
-(
- uint8 const _nodeId,
- uint32 const _requestFlags
-)
+void Driver::RequestNodeNeighbors(uint8 const _nodeId, uint32 const _requestFlags)
{
- if( IsAPICallSupported( FUNC_ID_ZW_GET_ROUTING_INFO ) )
+ if (IsAPICallSupported( FUNC_ID_ZW_GET_ROUTING_INFO))
{
// Note: This is not the same as RequestNodeNeighbourUpdate. This method
// merely requests the controller's current neighbour information and
// the reply will be copied into the relevant Node object for later use.
- Log::Write( LogLevel_Detail, GetNodeNumber( m_currentMsg ), "Requesting routing info (neighbor list) for Node %d", _nodeId );
- Msg* msg = new Msg( "Get Routing Info", _nodeId, REQUEST, FUNC_ID_ZW_GET_ROUTING_INFO, false );
- msg->Append( _nodeId );
- msg->Append( 0 ); // don't remove bad links
- msg->Append( 0 ); // don't remove non-repeaters
- msg->Append( 3 ); // funcid
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Detail, GetNodeNumber(m_currentMsg), "Requesting routing info (neighbor list) for Node %d", _nodeId);
+ Internal::Msg* msg = new Internal::Msg("Get Routing Info", _nodeId, REQUEST, FUNC_ID_ZW_GET_ROUTING_INFO, false);
+ msg->Append(_nodeId);
+ msg->Append(0); // don't remove bad links
+ msg->Append(0); // don't remove non-repeaters
+ msg->Append(3); // funcid
+ SendMsg(msg, MsgQueue_Command);
}
}
@@ -5391,25 +5065,17 @@ void Driver::RequestNodeNeighbors
// Start the controller performing one of its network management functions
// Create a ControllerCommand request.
//-----------------------------------------------------------------------------
-bool Driver::BeginControllerCommand
-(
- ControllerCommand _command,
- pfnControllerCallback_t _callback,
- void* _context,
- bool _highPower,
- uint8 _nodeId,
- uint8 _arg
-)
+bool Driver::BeginControllerCommand(ControllerCommand _command, pfnControllerCallback_t _callback, void* _context, bool _highPower, uint8 _nodeId, uint8 _arg)
{
ControllerCommandItem* cci;
MsgQueueItem item;
- if( _command == ControllerCommand_None )
+ if (_command == ControllerCommand_None)
{
return false;
}
- Log::Write( LogLevel_Detail, _nodeId, "Queuing (%s) %s", c_sendQueueNames[MsgQueue_Controller], c_controllerCommandNames[_command] );
+ Log::Write(LogLevel_Detail, _nodeId, "Queuing (%s) %s", c_sendQueueNames[MsgQueue_Controller], c_controllerCommandNames[_command]);
cci = new ControllerCommandItem();
cci->m_controllerCommand = _command;
cci->m_controllerCallback = _callback;
@@ -5425,7 +5091,7 @@ bool Driver::BeginControllerCommand
item.m_cci = cci;
m_sendMutex->Lock();
- m_msgQueue[MsgQueue_Controller].push_back( item );
+ m_msgQueue[MsgQueue_Controller].push_back(item);
m_queueEvent[MsgQueue_Controller]->Set();
m_sendMutex->Unlock();
@@ -5436,314 +5102,315 @@ bool Driver::BeginControllerCommand
//
// Start the controller performing one of its network management functions
//-----------------------------------------------------------------------------
-void Driver::DoControllerCommand
-(
-)
+void Driver::DoControllerCommand()
{
- UpdateControllerState( ControllerState_Starting );
- switch( m_currentControllerCommand->m_controllerCommand )
- {
- case ControllerCommand_AddDevice:
+ UpdateControllerState(ControllerState_Starting);
+ switch (m_currentControllerCommand->m_controllerCommand)
{
- if( !IsPrimaryController() )
+ case ControllerCommand_AddDevice:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotPrimary );
+ if (!IsPrimaryController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotPrimary);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Add Device");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_AddDevice", 0xff, REQUEST, FUNC_ID_ZW_ADD_NODE_TO_NETWORK, true);
+ uint8 options = ADD_NODE_ANY;
+ if (m_currentControllerCommand->m_highPower)
+ options |= OPTION_HIGH_POWER;
+ if (IsAPICallSupported(FUNC_ID_ZW_EXPLORE_REQUEST_INCLUSION))
+ options |= OPTION_NWI;
+ msg->Append(options);
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
}
- else
+ case ControllerCommand_CreateNewPrimary:
+ {
+ if (IsPrimaryController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotSecondary);
+ }
+ else if (!IsStaticUpdateController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotSUC);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Create New Primary");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_CreateNewPrimary", 0xff, REQUEST, FUNC_ID_ZW_CREATE_NEW_PRIMARY, true);
+ msg->Append( CREATE_PRIMARY_START);
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
+ }
+ case ControllerCommand_ReceiveConfiguration:
{
- Log::Write( LogLevel_Info, 0, "Add Device" );
- Msg* msg = new Msg( "ControllerCommand_AddDevice", 0xff, REQUEST, FUNC_ID_ZW_ADD_NODE_TO_NETWORK, true );
- uint8 options = ADD_NODE_ANY;
- if (m_currentControllerCommand->m_highPower) options |= OPTION_HIGH_POWER;
- if (IsAPICallSupported(FUNC_ID_ZW_EXPLORE_REQUEST_INCLUSION)) options |= OPTION_NWI;
- msg->Append( options);
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Info, 0, "Receive Configuration");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_ReceiveConfiguration", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, true);
+ msg->Append(0xff);
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- break;
- }
- case ControllerCommand_CreateNewPrimary:
- {
- if( IsPrimaryController() )
+ case ControllerCommand_RemoveDevice:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotSecondary );
+ if (!IsPrimaryController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotPrimary);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Remove Device");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_RemoveDevice", 0xff, REQUEST, FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK, true);
+ msg->Append(m_currentControllerCommand->m_highPower ? REMOVE_NODE_ANY | OPTION_HIGH_POWER : REMOVE_NODE_ANY);
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
}
- else if( !IsStaticUpdateController() )
+ case ControllerCommand_HasNodeFailed:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotSUC );
+ Log::Write(LogLevel_Info, 0, "Requesting whether node %d has failed", m_currentControllerCommand->m_controllerCommandNode);
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_HasNodeFailed", 0xff, REQUEST, FUNC_ID_ZW_IS_FAILED_NODE_ID, false);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode);
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- else
+ case ControllerCommand_RemoveFailedNode:
{
- Log::Write( LogLevel_Info, 0, "Create New Primary" );
- Msg* msg = new Msg( "ControllerCommand_CreateNewPrimary", 0xff, REQUEST, FUNC_ID_ZW_CREATE_NEW_PRIMARY, true );
- msg->Append( CREATE_PRIMARY_START );
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Info, 0, "ControllerCommand_RemoveFailedNode", m_currentControllerCommand->m_controllerCommandNode);
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_RemoveFailedNode", 0xff, REQUEST, FUNC_ID_ZW_REMOVE_FAILED_NODE_ID, true);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode);
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- break;
- }
- case ControllerCommand_ReceiveConfiguration:
- {
- Log::Write( LogLevel_Info, 0, "Receive Configuration" );
- Msg* msg = new Msg( "ControllerCommand_ReceiveConfiguration", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, true );
- msg->Append( 0xff );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_RemoveDevice:
- {
- if( !IsPrimaryController() )
+ case ControllerCommand_ReplaceFailedNode:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotPrimary );
+ Log::Write(LogLevel_Info, 0, "Replace Failed Node %d", m_currentControllerCommand->m_controllerCommandNode);
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_ReplaceFailedNode", 0xff, REQUEST, FUNC_ID_ZW_REPLACE_FAILED_NODE, true);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode);
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- else
+ case ControllerCommand_TransferPrimaryRole:
{
- Log::Write( LogLevel_Info, 0, "Remove Device" );
- Msg* msg = new Msg( "ControllerCommand_RemoveDevice", 0xff, REQUEST, FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK, true );
- msg->Append( m_currentControllerCommand->m_highPower ? REMOVE_NODE_ANY | OPTION_HIGH_POWER : REMOVE_NODE_ANY );
- SendMsg( msg, MsgQueue_Command );
+ if (!IsPrimaryController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotPrimary);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Transfer Primary Role");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_TransferPrimaryRole", 0xff, REQUEST, FUNC_ID_ZW_CONTROLLER_CHANGE, true);
+ msg->Append(m_currentControllerCommand->m_highPower ? CONTROLLER_CHANGE_START | OPTION_HIGH_POWER : CONTROLLER_CHANGE_START);
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
}
- break;
- }
- case ControllerCommand_HasNodeFailed:
- {
- Log::Write( LogLevel_Info, 0, "Requesting whether node %d has failed", m_currentControllerCommand->m_controllerCommandNode );
- Msg* msg = new Msg( "ControllerCommand_HasNodeFailed", 0xff, REQUEST, FUNC_ID_ZW_IS_FAILED_NODE_ID, false );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_RemoveFailedNode:
- {
- Log::Write( LogLevel_Info, 0, "ControllerCommand_RemoveFailedNode", m_currentControllerCommand->m_controllerCommandNode );
- Msg* msg = new Msg( "ControllerCommand_RemoveFailedNode", 0xff, REQUEST, FUNC_ID_ZW_REMOVE_FAILED_NODE_ID, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_ReplaceFailedNode:
- {
- Log::Write( LogLevel_Info, 0, "Replace Failed Node %d", m_currentControllerCommand->m_controllerCommandNode );
- Msg* msg = new Msg( "ControllerCommand_ReplaceFailedNode", 0xff, REQUEST, FUNC_ID_ZW_REPLACE_FAILED_NODE, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_TransferPrimaryRole:
- {
- if( !IsPrimaryController() )
+ case ControllerCommand_RequestNetworkUpdate:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotPrimary );
+ if (!IsStaticUpdateController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotSUC);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Request Network Update");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_RequestNetworkUpdate", 0xff, REQUEST, FUNC_ID_ZW_REQUEST_NETWORK_UPDATE, true);
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
}
- else
+ case ControllerCommand_RequestNodeNeighborUpdate:
{
- Log::Write( LogLevel_Info, 0, "Transfer Primary Role" );
- Msg* msg = new Msg( "ControllerCommand_TransferPrimaryRole", 0xff, REQUEST, FUNC_ID_ZW_CONTROLLER_CHANGE, true );
- msg->Append( m_currentControllerCommand->m_highPower ? CONTROLLER_CHANGE_START | OPTION_HIGH_POWER : CONTROLLER_CHANGE_START );
- SendMsg( msg, MsgQueue_Command );
+ if (!IsPrimaryController())
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_NotPrimary);
+ }
+ else
+ {
+ Log::Write(LogLevel_Info, 0, "Requesting Neighbor Update for node %d", m_currentControllerCommand->m_controllerCommandNode);
+ bool opts = IsAPICallSupported( FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS);
+ Internal::Msg* msg;
+ if (opts)
+ {
+ msg = new Internal::Msg("ControllerCommand_RequestNodeNeighborUpdate", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS, true);
+ }
+ else
+ {
+ msg = new Internal::Msg("ControllerCommand_RequestNodeNeighborUpdate", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE, true);
+ }
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode);
+ if (opts)
+ {
+ msg->Append(GetTransmitOptions());
+ }
+ SendMsg(msg, MsgQueue_Command);
+ }
+ break;
}
- break;
- }
- case ControllerCommand_RequestNetworkUpdate:
- {
- if( !IsStaticUpdateController() )
+ case ControllerCommand_AssignReturnRoute:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotSUC );
+ Log::Write(LogLevel_Info, 0, "Assigning return route from node %d to node %d", m_currentControllerCommand->m_controllerCommandNode, m_currentControllerCommand->m_controllerCommandArg);
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_AssignReturnRoute", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_ASSIGN_RETURN_ROUTE, true);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode); // from the node
+ msg->Append(m_currentControllerCommand->m_controllerCommandArg); // to the specific destination
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- else
+ case ControllerCommand_DeleteAllReturnRoutes:
{
- Log::Write( LogLevel_Info, 0, "Request Network Update" );
- Msg* msg = new Msg( "ControllerCommand_RequestNetworkUpdate", 0xff, REQUEST, FUNC_ID_ZW_REQUEST_NETWORK_UPDATE, true );
- SendMsg( msg, MsgQueue_Command );
+ Log::Write(LogLevel_Info, 0, "Deleting all return routes from node %d", m_currentControllerCommand->m_controllerCommandNode);
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_DeleteAllReturnRoutess", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_DELETE_RETURN_ROUTE, true);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode); // from the node
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- break;
- }
- case ControllerCommand_RequestNodeNeighborUpdate:
- {
- if( !IsPrimaryController() )
+ case ControllerCommand_SendNodeInformation:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotPrimary );
+ Log::Write(LogLevel_Info, 0, "Sending a node information frame");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_SendNodeInformation", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_SEND_NODE_INFORMATION, true);
+ msg->Append(m_currentControllerCommand->m_controllerCommandNode); // to the node
+ msg->Append(GetTransmitOptions());
+ SendMsg(msg, MsgQueue_Command);
+ break;
}
- else
+ case ControllerCommand_ReplicationSend:
{
- Log::Write( LogLevel_Info, 0, "Requesting Neighbor Update for node %d", m_currentControllerCommand->m_controllerCommandNode );
- bool opts = IsAPICallSupported( FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS );
- Msg* msg;
- if( opts )
+ if (!IsPrimaryController())
{
- msg = new Msg( "ControllerCommand_RequestNodeNeighborUpdate", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS, true );
+ UpdateControllerState(ControllerState_Error, ControllerError_NotPrimary);
}
else
{
- msg = new Msg( "ControllerCommand_RequestNodeNeighborUpdate", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE, true );
+ Log::Write(LogLevel_Info, 0, "Replication Send");
+ Internal::Msg* msg = new Internal::Msg("ControllerCommand_ReplicationSend", 0xff, REQUEST, FUNC_ID_ZW_ADD_NODE_TO_NETWORK, true);
+ msg->Append(m_currentControllerCommand->m_highPower ? ADD_NODE_CONTROLLER | OPTION_HIGH_POWER : ADD_NODE_CONTROLLER);
+ SendMsg(msg, MsgQueue_Command);
}
- msg->Append( m_currentControllerCommand->m_controllerCommandNode );
- if( opts )
- {
- msg->Append( GetTransmitOptions() );
- }
- SendMsg( msg, MsgQueue_Command );
- }
- break;
- }
- case ControllerCommand_AssignReturnRoute:
- {
- Log::Write( LogLevel_Info, 0, "Assigning return route from node %d to node %d", m_currentControllerCommand->m_controllerCommandNode, m_currentControllerCommand->m_controllerCommandArg );
- Msg* msg = new Msg( "ControllerCommand_AssignReturnRoute", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_ASSIGN_RETURN_ROUTE, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode ); // from the node
- msg->Append( m_currentControllerCommand->m_controllerCommandArg ); // to the specific destination
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_DeleteAllReturnRoutes:
- {
- Log::Write( LogLevel_Info, 0, "Deleting all return routes from node %d", m_currentControllerCommand->m_controllerCommandNode );
- Msg* msg = new Msg( "ControllerCommand_DeleteAllReturnRoutess", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_DELETE_RETURN_ROUTE, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode ); // from the node
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_SendNodeInformation:
- {
- Log::Write( LogLevel_Info, 0, "Sending a node information frame" );
- Msg* msg = new Msg( "ControllerCommand_SendNodeInformation", m_currentControllerCommand->m_controllerCommandNode, REQUEST, FUNC_ID_ZW_SEND_NODE_INFORMATION, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode ); // to the node
- msg->Append( GetTransmitOptions() );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_ReplicationSend:
- {
- if( !IsPrimaryController() )
- {
- UpdateControllerState( ControllerState_Error, ControllerError_NotPrimary );
- }
- else
- {
- Log::Write( LogLevel_Info, 0, "Replication Send" );
- Msg* msg = new Msg( "ControllerCommand_ReplicationSend", 0xff, REQUEST, FUNC_ID_ZW_ADD_NODE_TO_NETWORK, true );
- msg->Append( m_currentControllerCommand->m_highPower ? ADD_NODE_CONTROLLER | OPTION_HIGH_POWER : ADD_NODE_CONTROLLER );
- SendMsg( msg, MsgQueue_Command );
+ break;
}
- break;
- }
- case ControllerCommand_CreateButton:
- {
- if( IsBridgeController() )
+ case ControllerCommand_CreateButton:
{
- Node* node = GetNodeUnsafe( m_currentControllerCommand->m_controllerCommandNode );
- if( node != NULL )
+ if (IsBridgeController())
{
- if( node->m_buttonMap.find( m_currentControllerCommand->m_controllerCommandArg ) == node->m_buttonMap.end() && m_virtualNeighborsReceived )
+ Node* node = GetNodeUnsafe(m_currentControllerCommand->m_controllerCommandNode);
+ if (node != NULL)
{
- bool found = false;
- for( uint8 n = 1; n <= 232 && !found; n++ )
+ if (node->m_buttonMap.find(m_currentControllerCommand->m_controllerCommandArg) == node->m_buttonMap.end() && m_virtualNeighborsReceived)
{
- if( !IsVirtualNode( n ))
- continue;
-
- map::iterator it = node->m_buttonMap.begin();
- for( ; it != node->m_buttonMap.end(); ++it )
+ bool found = false;
+ for (uint8 n = 1; n <= 232 && !found; n++)
{
- // is virtual node already in map?
- if( it->second == n )
- break;
+ if (!IsVirtualNode(n))
+ continue;
+
+ map::iterator it = node->m_buttonMap.begin();
+ for (; it != node->m_buttonMap.end(); ++it)
+ {
+ // is virtual node already in map?
+ if (it->second == n)
+ break;
+ }
+ if (it == node->m_buttonMap.end()) // found unused virtual node
+ {
+ node->m_buttonMap[m_currentControllerCommand->m_controllerCommandArg] = n;
+ SendVirtualNodeInfo(n, m_currentControllerCommand->m_controllerCommandNode);
+ found = true;
+ }
}
- if( it == node->m_buttonMap.end() ) // found unused virtual node
+ if (!found) // create a new virtual node
{
- node->m_buttonMap[m_currentControllerCommand->m_controllerCommandArg] = n;
- SendVirtualNodeInfo( n, m_currentControllerCommand->m_controllerCommandNode );
- found = true;
+ Log::Write(LogLevel_Info, 0, "AddVirtualNode");
+ Internal::Msg* msg = new Internal::Msg("FUNC_ID_SERIAL_API_SLAVE_NODE_INFO", 0xff, REQUEST, FUNC_ID_SERIAL_API_SLAVE_NODE_INFO, false, false);
+ msg->Append(0); // node 0
+ msg->Append(1); // listening
+ msg->Append(0x09); // genericType window covering
+ msg->Append(0x00); // specificType undefined
+ msg->Append(0); // length
+ SendMsg(msg, MsgQueue_Command);
+
+ msg = new Internal::Msg("FUNC_ID_ZW_SET_SLAVE_LEARN_MODE", 0xff, REQUEST, FUNC_ID_ZW_SET_SLAVE_LEARN_MODE, true);
+ msg->Append(0); // node 0 to add
+ if (IsPrimaryController() || IsInclusionController())
+ {
+ msg->Append( SLAVE_LEARN_MODE_ADD);
+ }
+ else
+ {
+ msg->Append( SLAVE_LEARN_MODE_ENABLE);
+ }
+ SendMsg(msg, MsgQueue_Command);
}
}
- if( !found ) // create a new virtual node
+ else
{
- Log::Write( LogLevel_Info, 0, "AddVirtualNode" );
- Msg* msg = new Msg( "FUNC_ID_SERIAL_API_SLAVE_NODE_INFO", 0xff, REQUEST, FUNC_ID_SERIAL_API_SLAVE_NODE_INFO, false, false );
- msg->Append( 0 ); // node 0
- msg->Append( 1 ); // listening
- msg->Append( 0x09 ); // genericType window covering
- msg->Append( 0x00 ); // specificType undefined
- msg->Append( 0 ); // length
- SendMsg( msg, MsgQueue_Command );
-
- msg = new Msg( "FUNC_ID_ZW_SET_SLAVE_LEARN_MODE", 0xff, REQUEST, FUNC_ID_ZW_SET_SLAVE_LEARN_MODE, true );
- msg->Append( 0 ); // node 0 to add
- if( IsPrimaryController() || IsInclusionController() )
- {
- msg->Append( SLAVE_LEARN_MODE_ADD );
- }
- else
- {
- msg->Append( SLAVE_LEARN_MODE_ENABLE );
- }
- SendMsg( msg, MsgQueue_Command );
+ UpdateControllerState(ControllerState_Error, ControllerError_ButtonNotFound);
}
}
else
{
- UpdateControllerState( ControllerState_Error, ControllerError_ButtonNotFound );
+ UpdateControllerState(ControllerState_Error, ControllerError_NodeNotFound);
}
}
else
{
- UpdateControllerState( ControllerState_Error, ControllerError_NodeNotFound );
+ UpdateControllerState(ControllerState_Error, ControllerError_NotBridge);
}
- } else
- {
- UpdateControllerState( ControllerState_Error, ControllerError_NotBridge );
+ break;
}
- break;
- }
- case ControllerCommand_DeleteButton:
- {
- if( IsBridgeController() )
+ case ControllerCommand_DeleteButton:
{
- Node* node = GetNodeUnsafe( m_currentControllerCommand->m_controllerCommandNode );
- if( node != NULL )
+ if (IsBridgeController())
{
- // Make sure button is allocated to a virtual node.
- if( node->m_buttonMap.find( m_currentControllerCommand->m_controllerCommandArg ) != node->m_buttonMap.end() )
+ Node* node = GetNodeUnsafe(m_currentControllerCommand->m_controllerCommandNode);
+ if (node != NULL)
{
+ // Make sure button is allocated to a virtual node.
+ if (node->m_buttonMap.find(m_currentControllerCommand->m_controllerCommandArg) != node->m_buttonMap.end())
+ {
#ifdef notdef
- // We would need a reference count to decide when to free virtual nodes
- // We could do this by making the bitmap of virtual nodes into a map that also holds a reference count.
- Log::Write( LogLevel_Info, 0, "RemoveVirtualNode %d", m_currentControllerCommand->m_controllerCommandNode );
- Msg* msg = new Msg( "Remove Virtual Node", 0xff, REQUEST, FUNC_ID_ZW_SET_SLAVE_LEARN_MODE, true );
- msg->Append( m_currentControllerCommand->m_controllerCommandNode ); // from the node
- if( IsPrimaryController() || IsInclusionController() )
+ // We would need a reference count to decide when to free virtual nodes
+ // We could do this by making the bitmap of virtual nodes into a map that also holds a reference count.
+ Log::Write( LogLevel_Info, 0, "RemoveVirtualNode %d", m_currentControllerCommand->m_controllerCommandNode );
+ Msg* msg = new Msg( "Remove Virtual Node", 0xff, REQUEST, FUNC_ID_ZW_SET_SLAVE_LEARN_MODE, true );
+ msg->Append( m_currentControllerCommand->m_controllerCommandNode );// from the node
+ if( IsPrimaryController() || IsInclusionController() )
msg->Append( SLAVE_LEARN_MODE_REMOVE );
- else
+ else
msg->Append( SLAVE_LEARN_MODE_ENABLE );
- SendMsg( msg );
+ SendMsg( msg );
#endif
- node->m_buttonMap.erase( m_currentControllerCommand->m_controllerCommandArg );
- SaveButtons();
+ node->m_buttonMap.erase(m_currentControllerCommand->m_controllerCommandArg);
+ SaveButtons();
- Notification* notification = new Notification( Notification::Type_DeleteButton );
- notification->SetHomeAndNodeIds( m_homeId, m_currentControllerCommand->m_controllerCommandNode );
- notification->SetButtonId( m_currentControllerCommand->m_controllerCommandArg );
- QueueNotification( notification );
+ Notification* notification = new Notification(Notification::Type_DeleteButton);
+ notification->SetHomeAndNodeIds(m_homeId, m_currentControllerCommand->m_controllerCommandNode);
+ notification->SetButtonId(m_currentControllerCommand->m_controllerCommandArg);
+ QueueNotification(notification);
+ }
+ else
+ {
+ UpdateControllerState(ControllerState_Error, ControllerError_ButtonNotFound);
+ }
}
else
{
- UpdateControllerState( ControllerState_Error, ControllerError_ButtonNotFound );
+ UpdateControllerState(ControllerState_Error, ControllerError_NodeNotFound);
}
}
else
{
- UpdateControllerState( ControllerState_Error, ControllerError_NodeNotFound );
+ UpdateControllerState(ControllerState_Error, ControllerError_NotBridge);
}
+ break;
}
- else
+ case ControllerCommand_None:
{
- UpdateControllerState( ControllerState_Error, ControllerError_NotBridge );
+ // To keep gcc quiet
+ break;
}
- break;
- }
- case ControllerCommand_None:
- {
- // To keep gcc quiet
- break;
- }
}
}
@@ -5751,141 +5418,160 @@ void Driver::DoControllerCommand
//
// Stop the current controller function
//-----------------------------------------------------------------------------
-void Driver::UpdateControllerState( ControllerState const _state, ControllerError const _error )
+void Driver::UpdateControllerState(ControllerState const _state, ControllerError const _error)
{
- if( m_currentControllerCommand != NULL )
+ if (m_currentControllerCommand != NULL)
{
- if( _state != m_currentControllerCommand->m_controllerState )
+ if (_state != m_currentControllerCommand->m_controllerState)
{
m_currentControllerCommand->m_controllerStateChanged = true;
m_currentControllerCommand->m_controllerState = _state;
- switch( _state )
- {
- case ControllerState_Error:
- case ControllerState_Cancel:
- case ControllerState_Failed:
- case ControllerState_Sleeping:
- case ControllerState_NodeFailed:
- case ControllerState_NodeOK:
- case ControllerState_Completed:
- {
- m_currentControllerCommand->m_controllerCommandDone = true;
- m_sendMutex->Lock();
- m_queueEvent[MsgQueue_Controller]->Set();
- m_sendMutex->Unlock();
- break;
- }
- default:
+ switch (_state)
{
- break;
- }
+ case ControllerState_Error:
+ case ControllerState_Cancel:
+ case ControllerState_Failed:
+ case ControllerState_Sleeping:
+ case ControllerState_NodeFailed:
+ case ControllerState_NodeOK:
+ case ControllerState_Completed:
+ {
+ m_currentControllerCommand->m_controllerCommandDone = true;
+ m_sendMutex->Lock();
+ m_queueEvent[MsgQueue_Controller]->Set();
+ m_sendMutex->Unlock();
+ break;
+ }
+ default:
+ {
+ break;
+ }
}
}
- Notification* notification = new Notification( Notification::Type_ControllerCommand );
- notification->SetHomeAndNodeIds(m_homeId, 0);
+ Notification* notification = new Notification(Notification::Type_ControllerCommand);
+
+ // PR #1879
+ // The change below sets the nodeId in the notifications for controller state changes. These state changes are
+ // caused by controller commands. Below is a list of controller commands with what the nodeId gets set to,
+ // along with the Manager method(s) that use the controller command.
+
+ // Driver::ControllerCommand_RequestNodeNeighborUpdate: supplied nodeId (Manager::HealNetworkNode, Manager::HealNetwork)
+ // Driver::ControllerCommand_AddDevice: nodeId of an added node (Manager::AddNode)
+ // Driver::ControllerCommand_RemoveDevice: nodeId of a removed node (Manager::RemoveNode)
+ // Driver::ControllerCommand_RemoveFailedNode: supplied nodeId (Manager::RemoveFailedNode)
+ // Driver::ControllerCommand_HasNodeFailed supplied nodeId (Manager::HasNodeFailed)
+ // Driver::ControllerCommand_AssignReturnRoute: supplied nodeId (Manager::AssignReturnRoute)
+ // Driver::ControllerCommand_RequestNodeNeighborUpdate: supplied nodeId (Manager::RequestNodeNeighborUpdate)
+ // Driver::ControllerCommand_DeleteAllReturnRoutes supplied nodeId (Manager::DeleteAllReturnRoutes)
+ // Driver::ControllerCommand_SendNodeInformation: supplied nodeId (Manager::SendNodeInformation)
+ // Driver::ControllerCommand_CreateNewPrimary: unknown (Manager::CreateNewPrimary)
+ // Driver::ControllerCommand_ReceiveConfiguration: unknown (Manager::ReceiveConfiguration)
+ // Driver::ControllerCommand_ReplaceFailedNode: could be the supplied nodeId or the nodeId of the node that was added (Manager::ReplaceFailedNode)
+ // Driver::ControllerCommand_TransferPrimaryRole: unknown (Manager::TransferPrimaryRole)
+ // Driver::ControllerCommand_RequestNetworkUpdate: supplied nodeId (Manager::RequestNetworkUpdate)
+ // Driver::ControllerCommand_ReplicationSend: supplied nodeId (Manager::ReplicationSend)
+ // Driver::ControllerCommand_CreateButton: supplied nodeId (Manager::CreateButton)
+ // Driver::ControllerCommand_DeleteButton: supplied nodeId (Manager::DeleteButton)
+ notification->SetHomeAndNodeIds(m_homeId, m_currentControllerCommand->m_controllerCommandNode);
+
notification->SetCommand(m_currentControllerCommand->m_controllerCommand);
notification->SetEvent(_state);
- if( _error != ControllerError_None )
+ if (_error != ControllerError_None)
{
m_currentControllerCommand->m_controllerReturnError = _error;
/* Create a new Notification Callback */
notification->SetNotification(_error);
}
- QueueNotification( notification );
+ QueueNotification(notification);
}
}
-
-
-
//-----------------------------------------------------------------------------
//
// Stop the current controller function
//-----------------------------------------------------------------------------
-bool Driver::CancelControllerCommand
-(
-)
+bool Driver::CancelControllerCommand()
{
- if( m_currentControllerCommand == NULL )
+ if (m_currentControllerCommand == NULL)
{
// Controller is not doing anything
return false;
}
- switch( m_currentControllerCommand->m_controllerCommand )
- {
- case ControllerCommand_AddDevice:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Add Node" );
- m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no new node to initialize
- AddNodeStop( FUNC_ID_ZW_ADD_NODE_TO_NETWORK );
- break;
- }
- case ControllerCommand_CreateNewPrimary:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Create New Primary" );
- Msg* msg = new Msg( "CreateNewPrimary Stop", 0xff, REQUEST, FUNC_ID_ZW_CREATE_NEW_PRIMARY, true );
- msg->Append( CREATE_PRIMARY_STOP );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_ReceiveConfiguration:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Receive Configuration" );
- Msg* msg = new Msg( "ReceiveConfiguration Stop", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false );
- msg->Append( 0 );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_RemoveDevice:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Remove Device" );
- m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no node to remove
- AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK );
- break;
- }
- case ControllerCommand_TransferPrimaryRole:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Transfer Primary Role" );
- Msg* msg = new Msg( "Transfer Primary Role Stop", 0xff, REQUEST, FUNC_ID_ZW_CONTROLLER_CHANGE, true );
- msg->Append( CONTROLLER_CHANGE_STOP );
- SendMsg( msg, MsgQueue_Command );
- break;
- }
- case ControllerCommand_ReplicationSend:
- {
- Log::Write( LogLevel_Info, 0, "Cancel Replication Send" );
- m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no new node to initialize
- AddNodeStop( FUNC_ID_ZW_ADD_NODE_TO_NETWORK );
- break;
- }
- case ControllerCommand_CreateButton:
- case ControllerCommand_DeleteButton:
+ switch (m_currentControllerCommand->m_controllerCommand)
{
- if( m_currentControllerCommand->m_controllerCommandNode != 0 )
+ case ControllerCommand_AddDevice:
+ {
+ Log::Write(LogLevel_Info, 0, "Cancel Add Node");
+ m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no new node to initialize
+ AddNodeStop( FUNC_ID_ZW_ADD_NODE_TO_NETWORK);
+ break;
+ }
+ case ControllerCommand_CreateNewPrimary:
{
- SendSlaveLearnModeOff();
+ Log::Write(LogLevel_Info, 0, "Cancel Create New Primary");
+ Internal::Msg* msg = new Internal::Msg("CreateNewPrimary Stop", 0xff, REQUEST, FUNC_ID_ZW_CREATE_NEW_PRIMARY, true);
+ msg->Append( CREATE_PRIMARY_STOP);
+ SendMsg(msg, MsgQueue_Command);
+ break;
+ }
+ case ControllerCommand_ReceiveConfiguration:
+ {
+ Log::Write(LogLevel_Info, 0, "Cancel Receive Configuration");
+ Internal::Msg* msg = new Internal::Msg("ReceiveConfiguration Stop", 0xff, REQUEST, FUNC_ID_ZW_SET_LEARN_MODE, false, false);
+ msg->Append(0);
+ SendMsg(msg, MsgQueue_Command);
+ break;
+ }
+ case ControllerCommand_RemoveDevice:
+ {
+ Log::Write(LogLevel_Info, 0, "Cancel Remove Device");
+ m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no node to remove
+ AddNodeStop( FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK);
+ break;
+ }
+ case ControllerCommand_TransferPrimaryRole:
+ {
+ Log::Write(LogLevel_Info, 0, "Cancel Transfer Primary Role");
+ Internal::Msg* msg = new Internal::Msg("Transfer Primary Role Stop", 0xff, REQUEST, FUNC_ID_ZW_CONTROLLER_CHANGE, true);
+ msg->Append( CONTROLLER_CHANGE_STOP);
+ SendMsg(msg, MsgQueue_Command);
+ break;
+ }
+ case ControllerCommand_ReplicationSend:
+ {
+ Log::Write(LogLevel_Info, 0, "Cancel Replication Send");
+ m_currentControllerCommand->m_controllerCommandNode = 0xff; // identify the fact that there is no new node to initialize
+ AddNodeStop( FUNC_ID_ZW_ADD_NODE_TO_NETWORK);
+ break;
+ }
+ case ControllerCommand_CreateButton:
+ case ControllerCommand_DeleteButton:
+ {
+ if (m_currentControllerCommand->m_controllerCommandNode != 0)
+ {
+ SendSlaveLearnModeOff();
+ }
+ break;
+ }
+ case ControllerCommand_None:
+ case ControllerCommand_RequestNetworkUpdate:
+ case ControllerCommand_RequestNodeNeighborUpdate:
+ case ControllerCommand_AssignReturnRoute:
+ case ControllerCommand_DeleteAllReturnRoutes:
+ case ControllerCommand_RemoveFailedNode:
+ case ControllerCommand_HasNodeFailed:
+ case ControllerCommand_ReplaceFailedNode:
+ case ControllerCommand_SendNodeInformation:
+ {
+ // Cannot cancel
+ return false;
}
- break;
- }
- case ControllerCommand_None:
- case ControllerCommand_RequestNetworkUpdate:
- case ControllerCommand_RequestNodeNeighborUpdate:
- case ControllerCommand_AssignReturnRoute:
- case ControllerCommand_DeleteAllReturnRoutes:
- case ControllerCommand_RemoveFailedNode:
- case ControllerCommand_HasNodeFailed:
- case ControllerCommand_ReplaceFailedNode:
- case ControllerCommand_SendNodeInformation:
- {
- // Cannot cancel
- return false;
- }
}
- UpdateControllerState( ControllerState_Cancel );
+ UpdateControllerState(ControllerState_Cancel);
return true;
}
@@ -5893,28 +5579,25 @@ bool Driver::CancelControllerCommand
//
// Stop the Add Node mode based on API of controller
//-----------------------------------------------------------------------------
-void Driver::AddNodeStop
-(
- uint8 const _funcId
-)
+void Driver::AddNodeStop(uint8 const _funcId)
{
- if( m_currentControllerCommand == NULL )
+ if (m_currentControllerCommand == NULL)
{
// Controller is not doing anything
return;
}
- if( m_serialAPIVersion[0] == 2 && m_serialAPIVersion[1] == 76 )
+ if (m_serialAPIVersion[0] == 2 && m_serialAPIVersion[1] == 76)
{
- Msg* msg = new Msg( "Add Node Stop", 0xff, REQUEST, _funcId, false, false );
- msg->Append( ADD_NODE_STOP );
- SendMsg( msg, Driver::MsgQueue_Command );
+ Internal::Msg* msg = new Internal::Msg("Add Node Stop", 0xff, REQUEST, _funcId, false, false);
+ msg->Append( ADD_NODE_STOP);
+ SendMsg(msg, Driver::MsgQueue_Command);
}
else
{
- Msg* msg = new Msg( "Add Node Stop", 0xff, REQUEST, _funcId, false, true );
- msg->Append( ADD_NODE_STOP );
- SendMsg( msg, Driver::MsgQueue_Command );
+ Internal::Msg* msg = new Internal::Msg("Add Node Stop", 0xff, REQUEST, _funcId, false, true);
+ msg->Append( ADD_NODE_STOP);
+ SendMsg(msg, Driver::MsgQueue_Command);
}
}
@@ -5922,37 +5605,33 @@ void Driver::AddNodeStop
//