Skip to content

Commit

Permalink
Expose String Representations for Basic, Generic and Specific Device …
Browse files Browse the repository at this point in the history
…Classes and Also Expose Generic/Specific DeviceClasses for each instance
  • Loading branch information
Fishwaldo committed Nov 25, 2019
1 parent 027d743 commit a335d2c
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 27 deletions.
57 changes: 53 additions & 4 deletions cpp/src/Driver.cpp
Expand Up @@ -4578,38 +4578,87 @@ uint8 Driver::GetNodeBasic(uint8 const _nodeId)
return basic;
}

//-----------------------------------------------------------------------------
// <Driver::GetNodeBasic>
// 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";
}




//-----------------------------------------------------------------------------
// <Driver::GetNodeGeneric>
// 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;
Internal::LockGuard LG(m_nodeMutex);
if (Node* node = GetNode(_nodeId))
{
genericType = node->GetGeneric();
genericType = node->GetGeneric(_instance);
}

return genericType;
}

//-----------------------------------------------------------------------------
// <Driver::GetNodeGeneric>
// 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";
}


//-----------------------------------------------------------------------------
// <Driver::GetNodeSpecific>
// 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;
Internal::LockGuard LG(m_nodeMutex);
if (Node* node = GetNode(_nodeId))
{
specific = node->GetSpecific();
specific = node->GetSpecific(_instance);
}

return specific;
}

//-----------------------------------------------------------------------------
// <Driver::GetNodeSpecific>
// 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";
}

//-----------------------------------------------------------------------------
// <Driver::GetNodeType>
// Get the basic/generic/specific type of the specified node
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/Driver.h
Expand Up @@ -491,8 +491,11 @@ namespace OpenZWave
uint8 GetNodeVersion(uint8 const _nodeId);
uint8 GetNodeSecurity(uint8 const _nodeId);
uint8 GetNodeBasic(uint8 const _nodeId);
uint8 GetNodeGeneric(uint8 const _nodeId);
uint8 GetNodeSpecific(uint8 const _nodeId);
string GetNodeBasicString(uint8 const _nodeId);
uint8 GetNodeGeneric(uint8 const _nodeId, uint8 _instance);
string GetNodeGenericString(uint8 const _nodeId, uint8 _instance);
uint8 GetNodeSpecific(uint8 const _nodeId, uint8 _instance);
string GetNodeSpecificString(uint8 const _nodeId, uint8 _instance);
string GetNodeType(uint8 const _nodeId);
uint32 GetNodeNeighbors(uint8 const _nodeId, uint8** o_neighbors);

Expand Down
51 changes: 47 additions & 4 deletions cpp/src/Manager.cpp
Expand Up @@ -957,36 +957,79 @@ uint8 Manager::GetNodeBasic(uint32 const _homeId, uint8 const _nodeId)
return basic;
}

//-----------------------------------------------------------------------------
// <Manager::GetNodeBasic>
// Get the basic type of a node
//-----------------------------------------------------------------------------
string Manager::GetNodeBasicString(uint32 const _homeId, uint8 const _nodeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetNodeBasicString(_nodeId);
}

return "Unknown";
}


//-----------------------------------------------------------------------------
// <Manager::GetNodeGeneric>
// Get the generic type of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId)
uint8 Manager::GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
uint8 genericType = 0;
if (Driver* driver = GetDriver(_homeId))
{
genericType = driver->GetNodeGeneric(_nodeId);
genericType = driver->GetNodeGeneric(_nodeId, _instance);
}

return genericType;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeGeneric>
// Get the generic type of a node
//-----------------------------------------------------------------------------

string Manager::GetNodeGenericString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
if (Driver *driver = GetDriver(_homeId))
{
return driver->GetNodeGenericString(_nodeId, _instance);
}
return "Unknown";
}


//-----------------------------------------------------------------------------
// <Manager::GetNodeSpecific>
// Get the specific type of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeSpecific(uint32 const _homeId, uint8 const _nodeId)
uint8 Manager::GetNodeSpecific(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
uint8 specific = 0;
if (Driver* driver = GetDriver(_homeId))
{
specific = driver->GetNodeSpecific(_nodeId);
specific = driver->GetNodeSpecific(_nodeId, _instance);
}

return specific;
}

//-----------------------------------------------------------------------------
// <Manager::GetNodeSpecific>
// Get the specific type of a node
//-----------------------------------------------------------------------------
string Manager::GetNodeSpecificString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetNodeSpecificString(_nodeId, _instance);
}

return "Unknown";
}

//-----------------------------------------------------------------------------
// <Manager::GetNodeType>
// Get a string describing the type of a node
Expand Down
34 changes: 32 additions & 2 deletions cpp/src/Manager.h
Expand Up @@ -558,21 +558,51 @@ namespace OpenZWave
*/
uint8 GetNodeBasic(uint32 const _homeId, uint8 const _nodeId);

/**
* \brief Get the basic type of a node.
* \param _homeId The Home ID of the Z-Wave controller that manages the node.
* \param _nodeId The ID of the node to query.
* \return the node's basic type.
*/
string GetNodeBasicString(uint32 const _homeId, uint8 const _nodeId);


/**
* \brief Get the generic type of a node.
* \param _homeId The Home ID of the Z-Wave controller that manages the node.
* \param _nodeId The ID of the node to query.
* \param _instance If Specified, Get the Generic Type for a Instance
* \return the node's generic type.
*/
uint8 GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId);
uint8 GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance = 0);

/**
* \brief Get the generic type of a node as a String
* \param _homeId The Home ID of the Z-Wave controller that manages the node.
* \param _nodeId The ID of the node to query.
* \param _instance If Specified, Get the Generic Type for a Instance
* \return the node's generic type.
*/
string GetNodeGenericString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance = 0);

/**
* \brief Get the specific type of a node.
* \param _homeId The Home ID of the Z-Wave controller that manages the node.
* \param _nodeId The ID of the node to query.
* \param _instance If Specified, Get the Specific Type for a Instance
* \return the node's specific type.
*/
uint8 GetNodeSpecific(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance = 0);

/**
* \brief Get the specific type of a node as a string
* \param _homeId The Home ID of the Z-Wave controller that manages the node.
* \param _nodeId The ID of the node to query.
* \param _instance If Specified, Get the Specific Type for a Instance
* \return the node's specific type.
*/
uint8 GetNodeSpecific(uint32 const _homeId, uint8 const _nodeId);
string GetNodeSpecificString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance = 0);


/**
* \brief Get a human-readable label describing the node
Expand Down
97 changes: 97 additions & 0 deletions cpp/src/Node.cpp
Expand Up @@ -1631,6 +1631,103 @@ uint8 Node::GetNumInstances(uint8 const _ccid)
return instances;
}

string Node::GetBasicString()
{
char str[32];
string label;
uint8 _basic = GetBasic();

snprintf(str, sizeof(str), "Basic 0x%.2x", _basic);
label = str;

// Read in the device class data if it has not been read already.
if (!s_deviceClassesLoaded)
{
ReadDeviceClasses();
}
if (s_basicDeviceClasses.find(_basic) != s_basicDeviceClasses.end()) {
return s_basicDeviceClasses.at(_basic);
}
return "Unknown";
}

uint8 Node::GetGeneric(uint8 const _instance) const
{
if (_instance > 0) {
if (Internal::CC::MultiInstance *cc = static_cast<Internal::CC::MultiInstance *>(GetCommandClass(Internal::CC::MultiInstance::StaticGetCommandClassId())))
{
return cc->GetGenericInstanceDeviceType(_instance);
}
}
return m_generic;
}
string Node::GetGenericString(uint8 const _instance)
{
char str[32];
string label;
uint8 _generic = GetGeneric(_instance);

snprintf(str, sizeof(str), "Generic 0x%.2x", _generic);
label = str;

// Read in the device class data if it has not been read already.
if (!s_deviceClassesLoaded)
{
ReadDeviceClasses();
}

// Get the Generic device class label
if (s_genericDeviceClasses.find(_generic) != s_genericDeviceClasses.end())
{
GenericDeviceClass* genericDeviceClass = s_genericDeviceClasses.at(_generic);
label = genericDeviceClass->GetLabel();
}
return label;
}


uint8 Node::GetSpecific(uint8 const _instance) const
{
if (_instance > 0) {
if (Internal::CC::MultiInstance *cc = static_cast<Internal::CC::MultiInstance *>(GetCommandClass(Internal::CC::MultiInstance::StaticGetCommandClassId())))
{
return cc->GetSpecificInstanceDeviceType(_instance);
}
}
return m_specific;
}

string Node::GetSpecificString(uint8 const _instance)
{
char str[32];
string label;
uint8 _generic = GetGeneric(_instance);
uint8 _specific = GetSpecific(_instance);

snprintf(str, sizeof(str), "Specific 0x%.2x", _specific);
label = str;

// Read in the device class data if it has not been read already.
if (!s_deviceClassesLoaded)
{
ReadDeviceClasses();
}

// Get the Generic device class label
if (s_genericDeviceClasses.find(_generic) != s_genericDeviceClasses.end())
{
GenericDeviceClass* genericDeviceClass = s_genericDeviceClasses.at(_generic);
label = genericDeviceClass->GetLabel();
// Override with any specific device class label
if (DeviceClass* specificDeviceClass = genericDeviceClass->GetSpecificDeviceClass(_specific))
{
label = specificDeviceClass->GetLabel();
}

}
return label;
}

void Node::SetSecuredClasses(uint8 const* _data, uint8 const _length, uint32 const _instance)
{
uint32 i;
Expand Down
17 changes: 8 additions & 9 deletions cpp/src/Node.h
Expand Up @@ -351,14 +351,13 @@ namespace OpenZWave
{
return m_basic;
}
uint8 GetGeneric() const
{
return m_generic;
}
uint8 GetSpecific() const
{
return m_specific;
}
string GetBasicString();
uint8 GetGeneric(uint8 const _instance) const;
string GetGenericString(uint8 const _instance);
uint8 GetSpecific(uint8 const _instance) const;
string GetSpecificString(uint8 const _instance);
string GetEndPointDeviceClassLabel(uint8 const _generic, uint8 const _specific);

string const& GetType() const
{
return m_type;
Expand Down Expand Up @@ -531,6 +530,7 @@ namespace OpenZWave
*
*/
uint8 GetNumInstances(uint8 const _ccid);

private:
/**
* Creates the specified command class object and adds it to the node (via the
Expand Down Expand Up @@ -763,7 +763,6 @@ namespace OpenZWave
bool SetPlusDeviceClasses(uint8 const _role, uint8 const _nodeType, uint16 const _deviceType); // Set the device class data for the node based on the Zwave+ info report
bool AddMandatoryCommandClasses(uint8 const* _commandClasses); // Add mandatory command classes as specified in the device_classes.xml to the node.
void ReadDeviceClasses(); // Read the static device class data from the device_classes.xml file
string GetEndPointDeviceClassLabel(uint8 const _generic, uint8 const _specific);

static bool s_deviceClassesLoaded; // True if the xml file has already been loaded
static map<uint8, string> s_basicDeviceClasses; // Map of basic device classes.
Expand Down

0 comments on commit a335d2c

Please sign in to comment.