mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 09:51:14 +03:00
ozw: Rework and add some device specific drivers and examples.
This commit reworks ozw somewhat and adds some device specific drivers with examples. All of these drivers are kept in the UPM ozw library. The OZW class has been reworked to make it a proper singleton, since the OpenZWave::Manager() it depends on is already a singleton. This avoids issues such as opening and initializing OpenZWave multiple times. A new, relatively thin base class, ozwInterface is also now present. This class wraps some basic functionality, and handles initialization of the OZW base class. It is intended to be inherited by device driver classes. It operates on a node id for a device. Each OZW device is referenced by a node id, which does not change unless the device is removed (and possibly re-added) to a Z-Wave network. Finally, a series of device specific drivers have been implemented. These provide basic functionality to monitor and in some cases control the operation of a Z-Wave device. They are the following: ozwdump - This is a fake 'device' driver that initializes an OZW network and dumps information on all of the nodes (devices) present. Along with each node, available information on each valueid associated with that node is also printed. This fake device and it's examples replace the original ozw example. aeotecss6 - Aeotec Smart Switch 6. This device allows control of the switch, as well as reporting of information the switch makes available, such as current consumption, volts, watts, and accumulated energy use (kWh). aeotecsdg2 - Aeotec Smart Dimmer Gen 2. This device is similar to the Smart Switch 6, but also provides dimming functionality. It also provides information on energy use. aeotecdw2e - Aeotec Door/Window Sensor 2nd Edition. This device is a magnetic switch with an embedded tamper switch used to detect the opening/closing of windows and doors. This is a battery powered device. aeotecdsb09104 - Aeotec Home Energy Monitor. This device is intended to be installed at the MAINS or Breaker box. It reports current and cumulative energy consumption. tzemt400 - Trane TZEMT400 Thermostat. This device is a thermostat with Z-Wave functionality. The variant tested was the TZEMT400BB32MAA. The driver reports various information on the status of the thermostat, as well as the current measured temperature. Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
104
src/ozw/ozw.cxx
104
src/ozw/ozw.cxx
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
* Copyright (c) 2015-2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -38,9 +38,12 @@ using namespace upm;
|
||||
using namespace std;
|
||||
using namespace OpenZWave;
|
||||
|
||||
// our singleton instance
|
||||
OZW* OZW::m_instance = 0;
|
||||
|
||||
OZW::OZW()
|
||||
{
|
||||
m_initialized = false;
|
||||
m_mgrCreated = false;
|
||||
m_driverFailed = false;
|
||||
m_homeId = 0;
|
||||
@ -98,8 +101,8 @@ OZW::~OZW()
|
||||
|
||||
// delete any nodes. This should be safe after deleting the node
|
||||
// mutex since the handler is no longer registered.
|
||||
for (zwNodeMap_t::iterator it = m_zwNodeMap.begin();
|
||||
it != m_zwNodeMap.end(); ++it)
|
||||
for (auto it = m_zwNodeMap.cbegin();
|
||||
it != m_zwNodeMap.cend(); ++it)
|
||||
{
|
||||
// delete the zwNode pointer
|
||||
delete (*it).second;
|
||||
@ -108,6 +111,14 @@ OZW::~OZW()
|
||||
m_zwNodeMap.clear();
|
||||
}
|
||||
|
||||
OZW* OZW::instance()
|
||||
{
|
||||
if (!m_instance)
|
||||
m_instance = new OZW;
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
void OZW::optionsCreate(std::string configPath,
|
||||
std::string userConfigDir,
|
||||
std::string cmdLine)
|
||||
@ -117,17 +128,20 @@ void OZW::optionsCreate(std::string configPath,
|
||||
|
||||
void OZW::optionAddInt(std::string name, int val)
|
||||
{
|
||||
Options::Get()->AddOptionInt(name, val);
|
||||
if (!Options::Get()->AreLocked())
|
||||
Options::Get()->AddOptionInt(name, val);
|
||||
}
|
||||
|
||||
void OZW::optionAddBool(std::string name, bool val)
|
||||
{
|
||||
Options::Get()->AddOptionBool(name, val);
|
||||
if (!Options::Get()->AreLocked())
|
||||
Options::Get()->AddOptionBool(name, val);
|
||||
}
|
||||
|
||||
void OZW::optionAddString(std::string name, std::string val, bool append)
|
||||
{
|
||||
Options::Get()->AddOptionString(name, val, append);
|
||||
if (!Options::Get()->AreLocked())
|
||||
Options::Get()->AddOptionString(name, val, append);
|
||||
}
|
||||
|
||||
void OZW::optionsLock()
|
||||
@ -139,6 +153,16 @@ void OZW::optionsLock()
|
||||
|
||||
bool OZW::init(string devicePath, bool isHID)
|
||||
{
|
||||
if (m_initialized)
|
||||
{
|
||||
// we are already initialized...
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Already initialized, continuing..."
|
||||
<< endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// make sure options are locked
|
||||
optionsLock();
|
||||
|
||||
@ -174,6 +198,19 @@ bool OZW::init(string devicePath, bool isHID)
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we succeeded, update (sort) all of the VIDs in each zwNode, and
|
||||
// enable autoupdating from here on out.
|
||||
|
||||
lockNodes();
|
||||
for (auto it = m_zwNodeMap.cbegin();
|
||||
it != m_zwNodeMap.cend(); ++it)
|
||||
{
|
||||
(*it).second->updateVIDMap();
|
||||
(*it).second->setAutoUpdate(true);
|
||||
}
|
||||
unlockNodes();
|
||||
|
||||
m_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -249,7 +286,7 @@ void OZW::notificationHandler(Notification const* notification, void *ctx)
|
||||
// all nodes deleted. According to OZW docs, this happens
|
||||
// when a driver is reset, instead of sending potentially
|
||||
// hundreds of ValueRemoved/NodeRemoved events.
|
||||
for (zwNodeMap_t::iterator it = This->m_zwNodeMap.begin();
|
||||
for (auto it = This->m_zwNodeMap.begin();
|
||||
it != This->m_zwNodeMap.end(); ++it)
|
||||
{
|
||||
// delete the zwNode pointer
|
||||
@ -314,8 +351,8 @@ void OZW::dumpNodes(bool all)
|
||||
|
||||
lockNodes();
|
||||
|
||||
for (zwNodeMap_t::iterator it = m_zwNodeMap.begin();
|
||||
it != m_zwNodeMap.end(); ++it)
|
||||
for (auto it = m_zwNodeMap.cbegin();
|
||||
it != m_zwNodeMap.cend(); ++it)
|
||||
{
|
||||
uint8_t nodeId = (*it).first;
|
||||
|
||||
@ -323,6 +360,43 @@ void OZW::dumpNodes(bool all)
|
||||
<< ": "
|
||||
<< Manager::Get()->GetNodeProductName(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Type: "
|
||||
<< Manager::Get()->GetNodeType(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Product Type: "
|
||||
<< Manager::Get()->GetNodeProductType(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Manufacturer ID: "
|
||||
<< Manager::Get()->GetNodeManufacturerId(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Product ID: "
|
||||
<< Manager::Get()->GetNodeProductId(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Generic Type: "
|
||||
<< (int)Manager::Get()->GetNodeGeneric(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Device Type: "
|
||||
<< (int)Manager::Get()->GetNodeDeviceType(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Node Basic: "
|
||||
<< (int)Manager::Get()->GetNodeBasic(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Node Query Stage: "
|
||||
<< Manager::Get()->GetNodeQueryStage(m_homeId, nodeId)
|
||||
<< endl;
|
||||
cerr << "\t"
|
||||
<< "Is Node Info Rcvd: "
|
||||
<< Manager::Get()->IsNodeInfoReceived(m_homeId, nodeId)
|
||||
<< endl;
|
||||
|
||||
(*it).second->dumpNode(all);
|
||||
}
|
||||
|
||||
@ -898,6 +972,18 @@ bool OZW::isNodeAwake(int nodeId)
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool OZW::isNodeInfoReceived(int nodeId)
|
||||
{
|
||||
nodeId &= 0xff;
|
||||
|
||||
lockNodes();
|
||||
|
||||
bool rv = Manager::Get()->IsNodeInfoReceived(m_homeId, nodeId);
|
||||
|
||||
unlockNodes();
|
||||
return rv;
|
||||
}
|
||||
|
||||
void OZW::setDebug(bool enable)
|
||||
{
|
||||
m_debugging = enable;
|
||||
|
Reference in New Issue
Block a user