Skip to content

Commit 5afd0eb

Browse files
committed
Manufacturer_id, Product_type and Product_id now as uint16_t
1 parent 9497b1f commit 5afd0eb

File tree

3 files changed

+54
-79
lines changed

3 files changed

+54
-79
lines changed

hardware/OpenZWave.cpp

Lines changed: 39 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ extern std::string szUserDataFolder;
164164

165165
#define round(a) ( int ) ( a + .5 )
166166

167+
//Should be obsolete when OZW 2.0 comes out
168+
uint16_t GetUInt16FromString(const std::string& inStr)
169+
{
170+
uint16_t xID;
171+
std::stringstream ss;
172+
ss << std::hex << inStr;
173+
ss >> xID;
174+
return xID;
175+
}
176+
167177
#ifdef _DEBUG
168178
#define DEBUG_ZWAVE_INT
169179
#endif
@@ -559,10 +569,10 @@ void COpenZWave::OnZWaveNotification(OpenZWave::Notification const* _notificatio
559569
nodeInfo.Application_version = 0;
560570
nodeInfo.szType = m_pManager->GetNodeType(_homeID, _nodeID);
561571
nodeInfo.iVersion = m_pManager->GetNodeVersion(_homeID, _nodeID);
562-
nodeInfo.Manufacturer_id = m_pManager->GetNodeManufacturerId(_homeID, _nodeID);
563572
nodeInfo.Manufacturer_name = m_pManager->GetNodeManufacturerName(_homeID, _nodeID);
564-
nodeInfo.Product_type = m_pManager->GetNodeProductType(_homeID, _nodeID);
565-
nodeInfo.Product_id = m_pManager->GetNodeProductId(_homeID, _nodeID);
573+
nodeInfo.Manufacturer_id = GetUInt16FromString(m_pManager->GetNodeManufacturerId(_homeID, _nodeID));
574+
nodeInfo.Product_type = GetUInt16FromString(m_pManager->GetNodeProductType(_homeID, _nodeID));
575+
nodeInfo.Product_id = GetUInt16FromString(m_pManager->GetNodeProductId(_homeID, _nodeID));
566576
nodeInfo.Product_name = m_pManager->GetNodeProductName(_homeID, _nodeID);
567577
nodeInfo.tClockDay = -1;
568578
nodeInfo.tClockHour = -1;
@@ -624,10 +634,10 @@ void COpenZWave::OnZWaveNotification(OpenZWave::Notification const* _notificatio
624634
if (nodeInfo->Manufacturer_name.empty())
625635
{
626636
nodeInfo->IsPlus = m_pManager->IsNodeZWavePlus(_homeID, _nodeID);
627-
nodeInfo->Manufacturer_id = m_pManager->GetNodeManufacturerId(_homeID, _nodeID);
628637
nodeInfo->Manufacturer_name = m_pManager->GetNodeManufacturerName(_homeID, _nodeID);
629-
nodeInfo->Product_type = m_pManager->GetNodeProductType(_homeID, _nodeID);
630-
nodeInfo->Product_id = m_pManager->GetNodeProductId(_homeID, _nodeID);
638+
nodeInfo->Manufacturer_id = GetUInt16FromString(m_pManager->GetNodeManufacturerId(_homeID, _nodeID));
639+
nodeInfo->Product_type = GetUInt16FromString(m_pManager->GetNodeProductType(_homeID, _nodeID));
640+
nodeInfo->Product_id = GetUInt16FromString(m_pManager->GetNodeProductId(_homeID, _nodeID));
631641
}
632642

633643
nodeInfo->Instances[instance][commandClass].Values.push_back(vID);
@@ -850,10 +860,10 @@ void COpenZWave::OnZWaveNotification(OpenZWave::Notification const* _notificatio
850860
if (nodeInfo->Product_name != product_name)
851861
{
852862
nodeInfo->IsPlus = m_pManager->IsNodeZWavePlus(_homeID, _nodeID);
853-
nodeInfo->Manufacturer_id = m_pManager->GetNodeManufacturerId(_homeID, _nodeID);
854863
nodeInfo->Manufacturer_name = m_pManager->GetNodeManufacturerName(_homeID, _nodeID);
855-
nodeInfo->Product_type = m_pManager->GetNodeProductType(_homeID, _nodeID);
856-
nodeInfo->Product_id = m_pManager->GetNodeProductId(_homeID, _nodeID);
864+
nodeInfo->Manufacturer_id = GetUInt16FromString(m_pManager->GetNodeManufacturerId(_homeID, _nodeID));
865+
nodeInfo->Product_type = GetUInt16FromString(m_pManager->GetNodeProductType(_homeID, _nodeID));
866+
nodeInfo->Product_id = GetUInt16FromString(m_pManager->GetNodeProductId(_homeID, _nodeID));
857867
nodeInfo->Product_name = product_name;
858868
AddNode(_homeID, _nodeID, nodeInfo);
859869
m_bHaveLastIncludedNodeInfo = !product_name.empty();
@@ -1430,18 +1440,14 @@ bool COpenZWave::SwitchColor(const int nodeID, const int instanceID, const int c
14301440
_log.Log(LOG_ERROR, "OpenZWave: Node has failed (or is not alive), Switch command not sent! (NodeID: %d, 0x%02x)", nodeID, nodeID);
14311441
return false;
14321442
}
1433-
// TODO: remove this print once Ziapto Bulb 2 workaround has been verified
1434-
// Gizmocuz: This has been in for quite some while, is it verified ?
1435-
//_log.Debug(DEBUG_NORM, "OpenZWave::SwitchColor Manufacturer_id: '%s', Product_type: '%s', Product_id: '%s', Application_version: %u",
1436-
// pNode->Manufacturer_id.c_str(), pNode->Product_type.c_str(), pNode->Product_id.c_str(), pNode->Application_version);
14371443

14381444
OpenZWave::ValueID vID(0, 0, OpenZWave::ValueID::ValueGenre_Basic, 0, 0, 0, OpenZWave::ValueID::ValueType_Bool);
14391445
if (GetValueByCommandClassLabel(nodeID, instanceID, COMMAND_CLASS_COLOR_CONTROL, "Color", vID) == true)
14401446
{
14411447
std::string OutColorStr = ColorStr;
1442-
if (pNode->Manufacturer_id == "0131")
1448+
if (pNode->Manufacturer_id == 0x0131)
14431449
{
1444-
if ((pNode->Product_type == "0002") && (pNode->Product_id == "0002"))
1450+
if ((pNode->Product_type == 0x0002) && (pNode->Product_id == 0x0002))
14451451
{
14461452
if (pNode->Application_version < 106)
14471453
{
@@ -1452,7 +1458,7 @@ bool COpenZWave::SwitchColor(const int nodeID, const int instanceID, const int c
14521458
}
14531459
}
14541460
}
1455-
if ((pNode->Product_type == "0002") && (pNode->Product_id == "0003"))
1461+
if ((pNode->Product_type == 0x0002) && (pNode->Product_id == 0x0003))
14561462
{
14571463
if (pNode->Application_version < 106)
14581464
{
@@ -1649,19 +1655,9 @@ void COpenZWave::AddValue(const OpenZWave::ValueID& vID, const NodeInfo* pNodeIn
16491655
_device.hasWakeup = m_pManager->IsNodeAwake(HomeID, NodeID);
16501656
_device.isListening = m_pManager->IsNodeListeningDevice(HomeID, NodeID);
16511657

1652-
int xID;
1653-
std::stringstream ss;
1654-
ss << std::hex << pNodeInfo->Manufacturer_id;
1655-
ss >> xID;
1656-
_device.Manufacturer_id = xID;
1657-
std::stringstream ss2;
1658-
ss2 << std::hex << pNodeInfo->Product_id;
1659-
ss2 >> xID;
1660-
_device.Product_id = xID;
1661-
std::stringstream ss3;
1662-
ss3 << std::hex << pNodeInfo->Product_type;
1663-
ss3 >> xID;
1664-
_device.Product_type = xID;
1658+
_device.Manufacturer_id = pNodeInfo->Manufacturer_id;
1659+
_device.Product_id = pNodeInfo->Product_id;
1660+
_device.Product_type = pNodeInfo->Product_type;
16651661

16661662
if (!vLabel.empty())
16671663
_device.label = vLabel;
@@ -1718,7 +1714,7 @@ void COpenZWave::AddValue(const OpenZWave::ValueID& vID, const NodeInfo* pNodeIn
17181714
{
17191715
if (IsNodeRGBW(HomeID, NodeID))
17201716
{
1721-
_device.label = "Fibaro RGBW";
1717+
_device.label = "RGBW";
17221718
_device.devType = ZDTYPE_SWITCH_RGBW;
17231719
_device.instanceID = 100;
17241720
InsertDevice(_device);
@@ -3157,19 +3153,9 @@ void COpenZWave::UpdateValue(const OpenZWave::ValueID& vID)
31573153
{
31583154
if (!pNode->Manufacturer_name.empty())
31593155
{
3160-
int xID;
3161-
std::stringstream ss;
3162-
ss << std::hex << pNode->Manufacturer_id;
3163-
ss >> xID;
3164-
pDevice->Manufacturer_id = xID;
3165-
std::stringstream ss2;
3166-
ss2 << std::hex << pNode->Product_id;
3167-
ss2 >> xID;
3168-
pDevice->Product_id = xID;
3169-
std::stringstream ss3;
3170-
ss3 << std::hex << pNode->Product_type;
3171-
ss3 >> xID;
3172-
pDevice->Product_type = xID;
3156+
pDevice->Manufacturer_id = pNode->Manufacturer_id;
3157+
pDevice->Product_id = pNode->Product_id;
3158+
pDevice->Product_type = pNode->Product_type;
31733159
}
31743160
}
31753161
}
@@ -4848,21 +4834,9 @@ void COpenZWave::GetNodeValuesJson(const unsigned int homeID, const int nodeID,
48484834
ivalue++;
48494835

48504836
//Aeotec Blinking state
4851-
uint32_t Manufacturer_id;
4852-
uint32_t Product_type;
4853-
uint32_t Product_id;
4854-
4855-
std::stringstream ss;
4856-
ss << std::hex << m_pManager->GetNodeManufacturerId(m_controllerID, m_controllerNodeId);
4857-
ss >> Manufacturer_id;
4858-
4859-
std::stringstream ss2;
4860-
ss2 << std::hex << m_pManager->GetNodeProductId(m_controllerID, m_controllerNodeId);
4861-
ss2 >> Product_id;
4862-
4863-
std::stringstream ss3;
4864-
ss3 << std::hex << m_pManager->GetNodeProductType(m_controllerID, m_controllerNodeId);
4865-
ss3 >> Product_type;
4837+
uint16_t Manufacturer_id = GetUInt16FromString(m_pManager->GetNodeManufacturerId(m_controllerID, m_controllerNodeId));
4838+
uint16_t Product_type = GetUInt16FromString(m_pManager->GetNodeProductType(m_controllerID, m_controllerNodeId));
4839+
uint16_t Product_id = GetUInt16FromString(m_pManager->GetNodeProductId(m_controllerID, m_controllerNodeId));
48664840

48674841
if (Manufacturer_id == 0x0086)
48684842
{
@@ -5147,21 +5121,9 @@ bool COpenZWave::ApplyNodeConfig(const unsigned int homeID, const int nodeID, co
51475121
}
51485122
else if (rvIndex == 8)
51495123
{
5150-
uint32_t Manufacturer_id;
5151-
uint32_t Product_type;
5152-
uint32_t Product_id;
5153-
5154-
std::stringstream ss;
5155-
ss << std::hex << m_pManager->GetNodeManufacturerId(m_controllerID, m_controllerNodeId);
5156-
ss >> Manufacturer_id;
5157-
5158-
std::stringstream ss2;
5159-
ss2 << std::hex << m_pManager->GetNodeProductId(m_controllerID, m_controllerNodeId);
5160-
ss2 >> Product_id;
5161-
5162-
std::stringstream ss3;
5163-
ss3 << std::hex << m_pManager->GetNodeProductType(m_controllerID, m_controllerNodeId);
5164-
ss3 >> Product_type;
5124+
uint16_t Manufacturer_id = GetUInt16FromString(m_pManager->GetNodeManufacturerId(m_controllerID, m_controllerNodeId));
5125+
uint16_t Product_type = GetUInt16FromString(m_pManager->GetNodeProductType(m_controllerID, m_controllerNodeId));
5126+
uint16_t Product_id = GetUInt16FromString(m_pManager->GetNodeProductId(m_controllerID, m_controllerNodeId));
51655127

51665128
if (Manufacturer_id == 0x0086)
51675129
{
@@ -5466,10 +5428,11 @@ namespace http {
54665428
root["result"][ii]["Description"] = sd[4];
54675429
root["result"][ii]["PollEnabled"] = (atoi(sd[5].c_str()) == 1) ? "true" : "false";
54685430
root["result"][ii]["Version"] = pNode->iVersion;
5469-
root["result"][ii]["Manufacturer_id"] = pNode->Manufacturer_id;
54705431
root["result"][ii]["Manufacturer_name"] = pNode->Manufacturer_name;
5471-
root["result"][ii]["Product_type"] = pNode->Product_type;
5472-
root["result"][ii]["Product_id"] = pNode->Product_id;
5432+
5433+
root["result"][ii]["Manufacturer_id"] = int_to_hex(pNode->Manufacturer_id);
5434+
root["result"][ii]["Product_type"] = int_to_hex(pNode->Product_type);
5435+
root["result"][ii]["Product_id"] = int_to_hex(pNode->Product_id);
54735436
root["result"][ii]["Product_name"] = pNode->Product_name;
54745437
root["result"][ii]["State"] = pOZWHardware->GetNodeStateString(homeID, nodeID);
54755438
root["result"][ii]["HaveUserCodes"] = pNode->HaveUserCodes;

hardware/OpenZWave.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class COpenZWave : public ZWaveBase
4646

4747
std::string szType;
4848
int iVersion;
49-
std::string Manufacturer_id;
49+
uint16_t Manufacturer_id;
5050
std::string Manufacturer_name;
51-
std::string Product_type;
52-
std::string Product_id;
51+
uint16_t Product_type;
52+
uint16_t Product_id;
5353
std::string Product_name;
5454
int Application_version;
5555

main/Helper.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ void stdreplace(
1616
const std::string& replaceWithWhat);
1717
void stdupper(std::string &inoutstring);
1818
void stdlower(std::string &inoutstring);
19+
20+
template< typename T > inline
21+
std::string int_to_hex(T i)
22+
{
23+
std::stringstream stream;
24+
stream << "0x"
25+
<< std::setfill('0') << std::setw(sizeof(T) * 2)
26+
<< std::hex << i;
27+
return stream.str();
28+
}
29+
30+
1931
bool file_exist (const char *filename);
2032
std::vector<std::string> GetSerialPorts(bool &bUseDirectPath);
2133
double CalculateAltitudeFromPressure(double pressure);

0 commit comments

Comments
 (0)