Skip to content

Commit c404c11

Browse files
committed
openzwave nodes, fixed issue casting string to unsigned integer
1 parent 13f86b0 commit c404c11

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Version 2.xxx (xxxx 2015)
3131
- Changed: BMP085, when forecast is unknown, its calculated directly based on the pressure
3232
- Implemented: Option to rename unused devices
3333
- Implemented: RFXCom (Serial) option to update the firmware via the web interface
34+
- Implemented: OpenZWave, multi instance association support (thanks to xs4!!!)
3435

3536
Version 2.2563 (June 14th 2015)
3637
- Implemented: WebServer, native SSL and keep-alive, big thanks to chimit!!!!

hardware/OpenZWave.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ void COpenZWave::EnableDisableDebug()
915915
bool COpenZWave::OpenSerialConnector()
916916
{
917917
_log.Log(LOG_STATUS, "OpenZWave: Starting...");
918-
_log.Log(LOG_STATUS, "OpenZWave: Version: %s", GetVersionLong().c_str());
918+
// _log.Log(LOG_STATUS, "OpenZWave: Version: %s", GetVersionLong().c_str());
919919

920920
m_allNodesQueried = false;
921921
m_updateTime = mytime(NULL);
@@ -2907,39 +2907,45 @@ int COpenZWave::ListGroupsForNode(const int nodeID)
29072907
return m_pManager->GetNumGroups(m_controllerID, nodeID);
29082908
}
29092909

2910-
int COpenZWave::ListAssociatedNodesinGroup(const int nodeID, const int groupID, std::vector<int> &nodesingroup)
2910+
int COpenZWave::ListAssociatedNodesinGroup(const int nodeID, const int groupID, std::vector<string> &nodesingroup)
29112911
{
29122912

29132913
if (m_pManager == NULL)
29142914
return 0;
29152915

2916-
uint8* arr;
2916+
InstanceAssociation* arr;
29172917
int retval = m_pManager->GetAssociations(m_controllerID, nodeID, groupID, &arr);
29182918
if (retval > 0) {
29192919
for (int i = 0; i < retval; i++) {
2920-
nodesingroup.push_back(arr[i]);
2920+
char str[32];
2921+
if (arr[i].m_instance == 0) {
2922+
snprintf( str, 32, "%d", arr[i].m_nodeId );
2923+
} else {
2924+
snprintf( str, 32, "%d.%d", arr[i].m_nodeId, arr[i].m_instance );
2925+
}
2926+
nodesingroup.push_back(str);
29212927
}
29222928
delete[] arr;
29232929
}
29242930
return retval;
29252931
}
29262932

2927-
bool COpenZWave::AddNodeToGroup(const int nodeID, const int groupID, const int addID)
2933+
bool COpenZWave::AddNodeToGroup(const int nodeID, const int groupID, const int addID, const int instance)
29282934
{
29292935

29302936
if (m_pManager == NULL)
29312937
return false;
2932-
m_pManager->AddAssociation(m_controllerID, nodeID, groupID, addID);
2933-
_log.Log(LOG_STATUS, "OpenZWave: added node: %d (0x%02x) in group: %d of node: %d (0x%02x)", addID, addID, groupID, nodeID, nodeID);
2938+
m_pManager->AddAssociation(m_controllerID, nodeID, groupID, addID, instance);
2939+
_log.Log(LOG_STATUS, "OpenZWave: added node: %d (0x%02x) instance %d in group: %d of node: %d (0x%02x)", addID, addID, instance, groupID, nodeID, nodeID);
29342940
return true;
29352941
}
29362942

2937-
bool COpenZWave::RemoveNodeFromGroup(const int nodeID, const int groupID, const int removeID)
2943+
bool COpenZWave::RemoveNodeFromGroup(const int nodeID, const int groupID, const int removeID, const int instance)
29382944
{
29392945
if (m_pManager == NULL)
29402946
return false;
2941-
m_pManager->RemoveAssociation(m_controllerID, nodeID, groupID, removeID);
2942-
_log.Log(LOG_STATUS, "OpenZWave: removed node: %d (0x%02x) from group: %d of node: %d (0x%02x)", removeID, removeID, groupID, nodeID, nodeID);
2947+
m_pManager->RemoveAssociation(m_controllerID, nodeID, groupID, removeID, instance);
2948+
_log.Log(LOG_STATUS, "OpenZWave: removed node: %d (0x%02x) instance %d from group: %d of node: %d (0x%02x)", removeID, removeID, instance, groupID, nodeID, nodeID);
29432949

29442950
return true;
29452951
}
@@ -3920,7 +3926,7 @@ namespace http {
39203926
{
39213927
std::vector<std::string> sd = *itt;
39223928

3923-
unsigned int homeID = atoi(sd[1].c_str());
3929+
unsigned int homeID = boost::lexical_cast<unsigned int>(sd[1]);
39243930
int nodeID = atoi(sd[2].c_str());
39253931
//if (nodeID>1) //Don't include the controller
39263932
{
@@ -4272,7 +4278,9 @@ namespace http {
42724278
if (pHardware != NULL)
42734279
{
42744280
COpenZWave *pOZWHardware = (COpenZWave*)pHardware;
4275-
pOZWHardware->RemoveNodeFromGroup(atoi(node.c_str()), atoi(group.c_str()), atoi(removenode.c_str()));
4281+
int nodeId = 0, instance = 0;
4282+
sscanf(removenode.c_str(),"%d.%d", &nodeId, &instance);
4283+
pOZWHardware->RemoveNodeFromGroup(atoi(node.c_str()), atoi(group.c_str()), nodeId, instance);
42764284
root["status"] = "OK";
42774285
root["title"] = "ZWaveRemoveGroupNode";
42784286
}
@@ -4302,7 +4310,9 @@ namespace http {
43024310
if (pHardware != NULL)
43034311
{
43044312
COpenZWave *pOZWHardware = (COpenZWave*)pHardware;
4305-
pOZWHardware->AddNodeToGroup(atoi(node.c_str()), atoi(group.c_str()), atoi(addnode.c_str()));
4313+
int nodeId = 0, instance = 0;
4314+
sscanf(addnode.c_str(),"%d.%d", &nodeId, &instance);
4315+
pOZWHardware->AddNodeToGroup(atoi(node.c_str()), atoi(group.c_str()), nodeId, instance);
43064316
root["status"] = "OK";
43074317
root["title"] = "ZWaveAddGroupNode";
43084318
}
@@ -4347,14 +4357,14 @@ namespace http {
43474357
if (numGroups > MaxNoOfGroups)
43484358
MaxNoOfGroups = numGroups;
43494359

4350-
std::vector< int > nodesingroup;
4360+
std::vector< string > nodesingroup;
43514361
int gi = 0;
43524362
for (int x = 1; x <= numGroups; x++)
43534363
{
43544364
int numNodesInGroup = pOZWHardware->ListAssociatedNodesinGroup(nodeID, x, nodesingroup);
43554365
if (numNodesInGroup > 0) {
43564366
std::stringstream list;
4357-
std::copy(nodesingroup.begin(), nodesingroup.end(), std::ostream_iterator<int>(list, ","));
4367+
std::copy(nodesingroup.begin(), nodesingroup.end(), std::ostream_iterator<string>(list, ","));
43584368
root["result"]["nodes"][ii]["groups"][gi]["id"] = x;
43594369
root["result"]["nodes"][ii]["groups"][gi]["nodes"] = list.str();
43604370
}

hardware/OpenZWave.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ class COpenZWave : public AsyncSerial, public ZWaveBase, public COpenZWaveContro
112112
bool HardResetDevice();
113113
bool HealNetwork();
114114
bool HealNode(const int nodeID);
115-
bool GetFailedState();
116-
bool NetworkInfo(const int hwID,std::vector< std::vector< int > > &NodeArray);
117-
int ListGroupsForNode(const int nodeID);
118-
int ListAssociatedNodesinGroup(const int nodeID,const int groupID,std::vector< int > &nodesingroup);
119-
bool AddNodeToGroup(const int nodeID,const int groupID, const int addID);
120-
bool RemoveNodeFromGroup(const int nodeID,const int groupID, const int removeID);
121-
std::string GetConfigFile(std::string &szConfigFile);
122-
123-
void NightlyNodeHeal();
115+
bool GetFailedState();
116+
bool NetworkInfo(const int hwID,std::vector< std::vector< int > > &NodeArray);
117+
int ListGroupsForNode(const int nodeID);
118+
int ListAssociatedNodesinGroup(const int nodeID,const int groupID,std::vector< string > &nodesingroup);
119+
bool AddNodeToGroup(const int nodeID,const int groupID, const int addID, const int instance);
120+
bool RemoveNodeFromGroup(const int nodeID,const int groupID, const int removeID, const int instance);
121+
std::string GetConfigFile(std::string &szConfigFile);
122+
123+
void NightlyNodeHeal();
124124

125125
bool m_awakeNodesQueried;
126126
bool m_allNodesQueried;

msbuild/domoticz.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
<ConfigurationType>Application</ConfigurationType>
2121
<UseDebugLibraries>true</UseDebugLibraries>
2222
<CharacterSet>MultiByte</CharacterSet>
23-
<PlatformToolset>v100</PlatformToolset>
23+
<PlatformToolset>v120</PlatformToolset>
2424
</PropertyGroup>
2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2626
<ConfigurationType>Application</ConfigurationType>
2727
<UseDebugLibraries>false</UseDebugLibraries>
2828
<WholeProgramOptimization>true</WholeProgramOptimization>
2929
<CharacterSet>MultiByte</CharacterSet>
30-
<PlatformToolset>v100</PlatformToolset>
30+
<PlatformToolset>v120</PlatformToolset>
3131
</PropertyGroup>
3232
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3333
<ImportGroup Label="ExtensionSettings">

0 commit comments

Comments
 (0)