diff --git a/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Main.cpp b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5bb57db14f4c5c257460b8468ceeab02b0b5b02 --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Main.cpp @@ -0,0 +1,383 @@ +//----------------------------------------------------------------------------- +// +// Main.cpp +// +// Minimal application to test OpenZWave. +// +// Creates an OpenZWave::Driver and the waits. In Debug builds +// you should see verbose logging to the console, which will +// indicate that communications with the Z-Wave network are working. +// +// Copyright (c) 2010 Mal Lansell +// +// +// SOFTWARE NOTICE AND LICENSE +// +// This file is part of OpenZWave. +// +// 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 . +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include "Options.h" +#include "Manager.h" +#include "Driver.h" +#include "Node.h" +#include "Group.h" +#include "Notification.h" +#include "value_classes/ValueStore.h" +#include "value_classes/Value.h" +#include "value_classes/ValueBool.h" +#include "platform/Log.h" + +using namespace OpenZWave; + + bool temp = false; + + +static uint32 g_homeId = 0; +static bool g_initFailed = false; + +typedef struct +{ + uint32 m_homeId; + uint8 m_nodeId; + bool m_polled; + list m_values; +}NodeInfo; + +static list g_nodes; +static pthread_mutex_t g_criticalSection; +static pthread_cond_t initCond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t initMutex = PTHREAD_MUTEX_INITIALIZER; + +//----------------------------------------------------------------------------- +// +// Return the NodeInfo object associated with this notification +//----------------------------------------------------------------------------- +NodeInfo* GetNodeInfo +( + Notification const* _notification +) +{ + uint32 const homeId = _notification->GetHomeId(); + uint8 const nodeId = _notification->GetNodeId(); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + if( ( nodeInfo->m_homeId == homeId ) && ( nodeInfo->m_nodeId == nodeId ) ) + { + return nodeInfo; + } + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// +// Callback that is triggered when a value, group or node changes +//----------------------------------------------------------------------------- +void OnNotification +( + Notification const* _notification, + void* _context +) +{ + // Must do this inside a critical section to avoid conflicts with the main thread + pthread_mutex_lock( &g_criticalSection ); + + switch( _notification->GetType() ) + { + case Notification::Type_ValueAdded: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + // Add the new value to our list + nodeInfo->m_values.push_back( _notification->GetValueID() ); + } + break; + } + + case Notification::Type_ValueRemoved: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + // Remove the value from out list + for( list::iterator it = nodeInfo->m_values.begin(); it != nodeInfo->m_values.end(); ++it ) + { + if( (*it) == _notification->GetValueID() ) + { + nodeInfo->m_values.erase( it ); + break; + } + } + } + break; + } + + case Notification::Type_ValueChanged: + { + // One of the node values has changed + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_Group: + { + // One of the node's association groups has changed + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_NodeAdded: + { + // Add the new node to our list + NodeInfo* nodeInfo = new NodeInfo(); + nodeInfo->m_homeId = _notification->GetHomeId(); + nodeInfo->m_nodeId = _notification->GetNodeId(); + nodeInfo->m_polled = false; + g_nodes.push_back( nodeInfo ); + if (temp == true) { + Manager::Get()->CancelControllerCommand( _notification->GetHomeId() ); + } + break; + } + + case Notification::Type_NodeRemoved: + { + // Remove the node from our list + uint32 const homeId = _notification->GetHomeId(); + uint8 const nodeId = _notification->GetNodeId(); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + if( ( nodeInfo->m_homeId == homeId ) && ( nodeInfo->m_nodeId == nodeId ) ) + { + g_nodes.erase( it ); + delete nodeInfo; + break; + } + } + break; + } + + case Notification::Type_NodeEvent: + { + // We have received an event from the node, caused by a + // basic_set or hail message. + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_PollingDisabled: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo->m_polled = false; + } + break; + } + + case Notification::Type_PollingEnabled: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo->m_polled = true; + } + break; + } + + case Notification::Type_DriverReady: + { + g_homeId = _notification->GetHomeId(); + break; + } + + case Notification::Type_DriverFailed: + { + g_initFailed = true; + pthread_cond_broadcast(&initCond); + break; + } + + case Notification::Type_AwakeNodesQueried: + case Notification::Type_AllNodesQueried: + case Notification::Type_AllNodesQueriedSomeDead: + { + pthread_cond_broadcast(&initCond); + break; + } + + case Notification::Type_DriverReset: + case Notification::Type_Notification: + case Notification::Type_NodeNaming: + case Notification::Type_NodeProtocolInfo: + case Notification::Type_NodeQueriesComplete: + default: + { + } + } + + pthread_mutex_unlock( &g_criticalSection ); +} + +//----------------------------------------------------------------------------- +//
+// Create the driver and then wait +//----------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + pthread_mutexattr_t mutexattr; + + pthread_mutexattr_init ( &mutexattr ); + pthread_mutexattr_settype( &mutexattr, PTHREAD_MUTEX_RECURSIVE ); + pthread_mutex_init( &g_criticalSection, &mutexattr ); + pthread_mutexattr_destroy( &mutexattr ); + + pthread_mutex_lock( &initMutex ); + + + printf("Starting MinOZW with OpenZWave Version %s\n", Manager::getVersionAsString().c_str()); + + // Create the OpenZWave Manager. + // The first argument is the path to the config files (where the manufacturer_specific.xml file is located + // The second argument is the path for saved Z-Wave network state and the log file. If you leave it NULL + // the log file will appear in the program's working directory. + Options::Create( "../../../config/", "", "" ); + Options::Get()->AddOptionInt( "SaveLogLevel", LogLevel_Detail ); + Options::Get()->AddOptionInt( "QueueLogLevel", LogLevel_Debug ); + Options::Get()->AddOptionInt( "DumpTrigger", LogLevel_Error ); + Options::Get()->AddOptionInt( "PollInterval", 500 ); + Options::Get()->AddOptionBool( "IntervalBetweenPolls", true ); + Options::Get()->AddOptionBool("ValidateValueChanges", true); + Options::Get()->Lock(); + + Manager::Create(); + + // Add a callback handler to the manager. The second argument is a context that + // is passed to the OnNotification method. If the OnNotification is a method of + // a class, the context would usually be a pointer to that class object, to + // avoid the need for the notification handler to be a static. + Manager::Get()->AddWatcher( OnNotification, NULL ); + + // Add a Z-Wave Driver + // Modify this line to set the correct serial port for your PC interface. + +#ifdef DARWIN + string port = "/dev/cu.usbserial"; +#elif WIN32 + string port = "\\\\.\\COM6"; +#else + string port = "/dev/ttyUSB0"; +#endif + if ( argc > 1 ) + { + port = argv[1]; + } + if( strcasecmp( port.c_str(), "usb" ) == 0 ) + { + Manager::Get()->AddDriver( "HID Controller", Driver::ControllerInterface_Hid ); + } + else + { + Manager::Get()->AddDriver( port ); + } + + // Now we just wait for either the AwakeNodesQueried or AllNodesQueried notification, + // then write out the config file. + // In a normal app, we would be handling notifications and building a UI for the user. + pthread_cond_wait( &initCond, &initMutex ); + + // Since the configuration file contains command class information that is only + // known after the nodes on the network are queried, wait until all of the nodes + // on the network have been queried (at least the "listening" ones) before + // writing the configuration file. (Maybe write again after sleeping nodes have + // been queried as well.) + if( !g_initFailed ) + { + + // The section below demonstrates setting up polling for a variable. In this simple + // example, it has been hardwired to poll COMMAND_CLASS_BASIC on the each node that + // supports this setting. + pthread_mutex_lock( &g_criticalSection ); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + + // skip the controller (most likely node 1) + if( nodeInfo->m_nodeId == 1) continue; + + for( list::iterator it2 = nodeInfo->m_values.begin(); it2 != nodeInfo->m_values.end(); ++it2 ) + { + ValueID v = *it2; + if( v.GetCommandClassId() == 0x20 ) + { +// Manager::Get()->EnablePoll( v, 2 ); // enables polling with "intensity" of 2, though this is irrelevant with only one value polled + break; + } + } + } + pthread_mutex_unlock( &g_criticalSection ); + + // If we want to access our NodeInfo list, that has been built from all the + // notification callbacks we received from the library, we have to do so + // from inside a Critical Section. This is because the callbacks occur on other + // threads, and we cannot risk the list being changed while we are using it. + // We must hold the critical section for as short a time as possible, to avoid + // stalling the OpenZWave drivers. + // At this point, the program just waits for 3 minutes (to demonstrate polling), + // then exits + for( int i = 0; i < 60*3; i++ ) + { + pthread_mutex_lock( &g_criticalSection ); + // but NodeInfo list and similar data should be inside critical section + pthread_mutex_unlock( &g_criticalSection ); + sleep(1); + } + + Driver::DriverData data; + Manager::Get()->GetDriverStatistics( g_homeId, &data ); + printf("SOF: %d ACK Waiting: %d Read Aborts: %d Bad Checksums: %d\n", data.m_SOFCnt, data.m_ACKWaiting, data.m_readAborts, data.m_badChecksum); + printf("Reads: %d Writes: %d CAN: %d NAK: %d ACK: %d Out of Frame: %d\n", data.m_readCnt, data.m_writeCnt, data.m_CANCnt, data.m_NAKCnt, data.m_ACKCnt, data.m_OOFCnt); + printf("Dropped: %d Retries: %d\n", data.m_dropped, data.m_retries); + } + + // program exit (clean up) + if( strcasecmp( port.c_str(), "usb" ) == 0 ) + { + Manager::Get()->RemoveDriver( "HID Controller" ); + } + else + { + Manager::Get()->RemoveDriver( port ); + } + Manager::Get()->RemoveWatcher( OnNotification, NULL ); + Manager::Destroy(); + Options::Destroy(); + pthread_mutex_destroy( &g_criticalSection ); + return 0; +} diff --git a/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Makefile b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f5111e0266d570aee42b1c1952c181c87d093a78 --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/Makefile @@ -0,0 +1,77 @@ +# +# Makefile for OpenzWave Mac OS X applications +# Greg Satz + +# GNU make only + +# requires libudev-dev + +.SUFFIXES: .d .cpp .o .a +.PHONY: default clean + + +DEBUG_CFLAGS := -Wall -Wno-format -ggdb -DDEBUG $(CPPFLAGS) +RELEASE_CFLAGS := -Wall -Wno-unknown-pragmas -Wno-format -O3 $(CPPFLAGS) + +DEBUG_LDFLAGS := -g + +top_srcdir := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../../../) + + +INCLUDES := -I $(top_srcdir)/cpp/src -I $(top_srcdir)/cpp/tinyxml/ -I $(top_srcdir)/cpp/hidapi/hidapi/ +LIBS = $(wildcard $(LIBDIR)/*.so $(LIBDIR)/*.dylib $(top_builddir)/*.so $(top_builddir)/*.dylib $(top_builddir)/cpp/build/*.so $(top_builddir)/cpp/build/*.dylib ) +LIBSDIR = $(abspath $(dir $(firstword $(LIBS)))) +minozwsrc := $(notdir $(wildcard $(top_srcdir)/cpp/examples/MinOZW/*.cpp)) +VPATH := $(top_srcdir)/cpp/examples/MinOZW + +top_builddir ?= $(CURDIR) + +default: $(top_builddir)/MinOZW + +include $(top_srcdir)/cpp/build/support.mk + +-include $(patsubst %.cpp,$(DEPDIR)/%.d,$(minozwsrc)) + +#if we are on a Mac, add these flags and libs to the compile and link phases +ifeq ($(UNAME),Darwin) +CFLAGS += -DDARWIN +TARCH += -arch i386 -arch x86_64 +endif + +# Dup from main makefile, but that is not included when building here.. +ifeq ($(UNAME),FreeBSD) +ifeq (,$(wildcard /usr/include/iconv.h)) +CFLAGS += -I/usr/local/include +LDFLAGS+= -L/usr/local/lib -liconv +endif +LDFLAGS+= -lusb +endif + +$(OBJDIR)/MinOZW: $(patsubst %.cpp,$(OBJDIR)/%.o,$(minozwsrc)) + @echo "Linking $(OBJDIR)/MinOZW" + $(LD) $(LDFLAGS) $(TARCH) -o $@ $< $(LIBS) -pthread + +$(top_builddir)/MinOZW: $(top_srcdir)/cpp/examples/MinOZW/MinOZW.in $(OBJDIR)/MinOZW + @echo "Creating Temporary Shell Launch Script" + @$(SED) \ + -e 's|[@]LDPATH@|$(LIBSDIR)|g' \ + < "$<" > "$@" + @chmod +x $(top_builddir)/MinOZW + +clean: + @rm -rf $(DEPDIR) $(OBJDIR) $(top_builddir)/MinOZW + +ifeq ($(XMLLINT),) +xmltest: $(XMLLINT) + $(error xmllint command not found.) +else +xmltest: $(XMLLINT) + @$(XMLLINT) --noout --schema ../../../config/zwcfg.xsd zwcfg_*.xml + @$(XMLLINT) --noout --schema ../../../config/zwscene.xsd zwscene.xml +endif + +install: $(OBJDIR)/MinOZW + @echo "Installing into Prefix: $(PREFIX)" + @install -d $(DESTDIR)/$(PREFIX)/bin/ + @cp $(OBJDIR)/MinOZW $(DESTDIR)/$(PREFIX)/bin/MinOZW + @chmod 755 $(DESTDIR)/$(PREFIX)/bin/MinOZW diff --git a/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/MinOZW.in b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/MinOZW.in new file mode 100644 index 0000000000000000000000000000000000000000..216e2c09e2bb63bb5f373eaedba54fb7d961b85b --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/MinOZW/MinOZW.in @@ -0,0 +1,11 @@ +#!/bin/sh +LD_PATH=@LDPATH@ +if test $# -gt 0; then + if test $1 == "gdb"; then + LD_LIBRARY_PATH="$LD_PATH:$LD_LIBRARY_PATH" gdb .lib/MinOZW + else + LD_LIBRARY_PATH="$LD_PATH:$LD_LIBRARY_PATH" .lib/MinOZW $@ + fi +else + LD_LIBRARY_PATH="$LD_PATH:$LD_LIBRARY_PATH" .lib/MinOZW +fi diff --git a/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/Main.cpp b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/Main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af388d3c135379e4b95d1360f7aa6e7d2de84157 --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/Main.cpp @@ -0,0 +1,344 @@ +//----------------------------------------------------------------------------- +// +// Main.cpp +// +// Minimal application to test OpenZWave. +// +// Creates an OpenZWave::Driver and the waits. In Debug builds +// you should see verbose logging to the console, which will +// indicate that communications with the Z-Wave network are working. +// +// Copyright (c) 2010 Mal Lansell +// +// +// SOFTWARE NOTICE AND LICENSE +// +// This file is part of OpenZWave. +// +// 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 . +// +//----------------------------------------------------------------------------- +#include "Windows.h" +#include "Options.h" +#include "Manager.h" +#include "Driver.h" +#include "Node.h" +#include "Group.h" +#include "Notification.h" +#include "value_classes/ValueStore.h" +#include "value_classes/Value.h" +#include "value_classes/ValueBool.h" +#include "platform/Log.h" + +using namespace OpenZWave; + +static uint32 g_homeId = 0; +static bool g_initFailed = false; +static bool g_nodesQueried = false; + +typedef struct +{ + uint32 m_homeId; + uint8 m_nodeId; + bool m_polled; + list m_values; +}NodeInfo; + +static list g_nodes; +static CRITICAL_SECTION g_criticalSection; + +//----------------------------------------------------------------------------- +// +// Return the NodeInfo object associated with this notification +//----------------------------------------------------------------------------- +NodeInfo* GetNodeInfo +( + Notification const* _notification +) +{ + uint32 const homeId = _notification->GetHomeId(); + uint8 const nodeId = _notification->GetNodeId(); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + if( ( nodeInfo->m_homeId == homeId ) && ( nodeInfo->m_nodeId == nodeId ) ) + { + return nodeInfo; + } + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// +// Callback that is triggered when a value, group or node changes +//----------------------------------------------------------------------------- +void OnNotification +( + Notification const* _notification, + void* _context +) +{ + // Must do this inside a critical section to avoid conflicts with the main thread + EnterCriticalSection( &g_criticalSection ); + + switch( _notification->GetType() ) + { + case Notification::Type_ValueAdded: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + // Add the new value to our list + nodeInfo->m_values.push_back( _notification->GetValueID() ); + } + break; + } + + case Notification::Type_ValueRemoved: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + // Remove the value from out list + for( list::iterator it = nodeInfo->m_values.begin(); it != nodeInfo->m_values.end(); ++it ) + { + if( (*it) == _notification->GetValueID() ) + { + nodeInfo->m_values.erase( it ); + break; + } + } + } + break; + } + + case Notification::Type_ValueChanged: + { + // One of the node values has changed + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_Group: + { + // One of the node's association groups has changed + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_NodeAdded: + { + // Add the new node to our list + NodeInfo* nodeInfo = new NodeInfo(); + nodeInfo->m_homeId = _notification->GetHomeId(); + nodeInfo->m_nodeId = _notification->GetNodeId(); + nodeInfo->m_polled = false; + g_nodes.push_back( nodeInfo ); + break; + } + + case Notification::Type_NodeRemoved: + { + // Remove the node from our list + uint32 const homeId = _notification->GetHomeId(); + uint8 const nodeId = _notification->GetNodeId(); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + if( ( nodeInfo->m_homeId == homeId ) && ( nodeInfo->m_nodeId == nodeId ) ) + { + g_nodes.erase( it ); + delete nodeInfo; + break; + } + } + break; + } + + case Notification::Type_NodeEvent: + { + // We have received an event from the node, caused by a + // basic_set or hail message. + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo = nodeInfo; // placeholder for real action + } + break; + } + + case Notification::Type_PollingDisabled: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo->m_polled = false; + } + break; + } + + case Notification::Type_PollingEnabled: + { + if( NodeInfo* nodeInfo = GetNodeInfo( _notification ) ) + { + nodeInfo->m_polled = true; + } + break; + } + + case Notification::Type_DriverReady: + { + g_homeId = _notification->GetHomeId(); + break; + } + + case Notification::Type_DriverFailed: + { + g_initFailed = true; + break; + } + + case Notification::Type_AwakeNodesQueried: + case Notification::Type_AllNodesQueried: + case Notification::Type_AllNodesQueriedSomeDead: + { + g_nodesQueried = true; + break; + } + + case Notification::Type_DriverReset: + case Notification::Type_NodeNaming: + case Notification::Type_NodeProtocolInfo: + case Notification::Type_NodeQueriesComplete: + default: + { + } + } + + LeaveCriticalSection( &g_criticalSection ); +} + +//----------------------------------------------------------------------------- +//
+// Create the driver and then wait +//----------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + InitializeCriticalSection( &g_criticalSection ); + + // Create the OpenZWave Manager. + // The first argument is the path to the config files (where the manufacturer_specific.xml file is located + // The second argument is the path for saved Z-Wave network state and the log file. If you leave it NULL + // the log file will appear in the program's working directory. + Options::Create( "../../../../../../config/", "", "" ); + Options::Get()->AddOptionInt( "SaveLogLevel", LogLevel_Detail ); + Options::Get()->AddOptionInt( "QueueLogLevel", LogLevel_Debug ); + Options::Get()->AddOptionInt( "DumpTrigger", LogLevel_Error ); + Options::Get()->AddOptionInt( "PollInterval", 500 ); + Options::Get()->AddOptionBool( "IntervalBetweenPolls", true ); + Options::Get()->AddOptionBool("ValidateValueChanges", true); + Options::Get()->Lock(); + + Manager::Create(); + + // Add a callback handler to the manager. The second argument is a context that + // is passed to the OnNotification method. If the OnNotification is a method of + // a class, the context would usually be a pointer to that class object, to + // avoid the need for the notification handler to be a static. + Manager::Get()->AddWatcher( OnNotification, NULL ); + + // Add a Z-Wave Driver + // Modify this line to set the correct serial port for your PC interface. + + string port = "\\\\.\\COM6"; + + Manager::Get()->AddDriver( ( argc > 1 ) ? argv[1] : port ); + //Manager::Get()->AddDriver( "HID Controller", Driver::ControllerInterface_Hid ); + + // Now we just wait for either the AwakeNodesQueried or AllNodesQueried notification, + // then write out the config file. + // In a normal app, we would be handling notifications and building a UI for the user. + + // Since the configuration file contains command class information that is only + // known after the nodes on the network are queried, wait until all of the nodes + // on the network have been queried (at least the "listening" ones) before + // writing the configuration file. (Maybe write again after sleeping nodes have + // been queried as well.) + while( !g_nodesQueried ) + { + Sleep( 1000 ); + } + + if( !g_initFailed ) + { + + Manager::Get()->WriteConfig( g_homeId ); + + // The section below demonstrates setting up polling for a variable. In this simple + // example, it has been hardwired to poll COMMAND_CLASS_BASIC on the each node that + // supports this setting. + EnterCriticalSection( &g_criticalSection ); + for( list::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it ) + { + NodeInfo* nodeInfo = *it; + + // skip the controller (most likely node 1) + if( nodeInfo->m_nodeId == 1) continue; + + for( list::iterator it2 = nodeInfo->m_values.begin(); it2 != nodeInfo->m_values.end(); ++it2 ) + { + ValueID v = *it2; + if( v.GetCommandClassId() == 0x20 ) + { + Manager::Get()->EnablePoll( v, 2 ); // enables polling with "intensity" of 2, though this is irrelevant with only one value polled + break; + } + } + } + LeaveCriticalSection( &g_criticalSection ); + + // If we want to access our NodeInfo list, that has been built from all the + // notification callbacks we received from the library, we have to do so + // from inside a Critical Section. This is because the callbacks occur on other + // threads, and we cannot risk the list being changed while we are using it. + // We must hold the critical section for as short a time as possible, to avoid + // stalling the OpenZWave drivers. + // At this point, the program just waits for 3 minutes (to demonstrate polling), + // then exits + for( int i = 0; i < 60*3*10; i++ ) + { + Sleep(90); // do most of your work outside critical section + + EnterCriticalSection( &g_criticalSection ); + Sleep(10); // but NodeInfo list and similar data should be inside critical section + LeaveCriticalSection( &g_criticalSection ); + } + + Driver::DriverData data; + Manager::Get()->GetDriverStatistics( g_homeId, &data ); + printf("SOF: %d ACK Waiting: %d Read Aborts: %d Bad Checksums: %d\n", data.m_SOFCnt, data.m_ACKWaiting, data.m_readAborts, data.m_badChecksum); + printf("Reads: %d Writes: %d CAN: %d NAK: %d ACK: %d Out of Frame: %d\n", data.m_readCnt, data.m_writeCnt, data.m_CANCnt, data.m_NAKCnt, data.m_ACKCnt, data.m_OOFCnt); + printf("Dropped: %d Retries: %d\n", data.m_dropped, data.m_retries); + } + + // program exit (clean up) + Manager::Destroy(); + Options::Destroy(); + DeleteCriticalSection( &g_criticalSection ); + return 0; +} diff --git a/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2008/MinOZW.vcproj b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2008/MinOZW.vcproj new file mode 100644 index 0000000000000000000000000000000000000000..67416387b450549429bae9d768f46b6a682b3794 --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2008/MinOZW.vcproj @@ -0,0 +1,336 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..99385faea188a8a1242690b307ab95ca5a2a057c --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj @@ -0,0 +1,179 @@ + + + + + DebugDLL + Win32 + + + Debug + Win32 + + + ReleaseDLL + Win32 + + + Release + Win32 + + + + {22847D76-B1CF-4921-8B7A-61E248412C4A} + MinOZW + Win32Proj + + + + Application + MultiByte + true + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + true + true + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + Disabled + ..\..\..\..\src;..\..\..\..\src\platform;..\..\..\..\src\value_classes;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + + + $(OutDir)\OpenZWave.lib;%(AdditionalDependencies) + true + Console + MachineX86 + + + + + Disabled + ..\..\..\..\src;..\..\..\..\src\platform;..\..\..\..\src\value_classes;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;OPENZWAVE_USEDLL;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + 4251 + + + $(OutDir)\OpenZWaved.lib;%(AdditionalDependencies) + true + Console + MachineX86 + + + + + MaxSpeed + true + ..\..\..\..\src;..\..\..\..\src\platform;..\..\..\..\src\value_classes;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + + + $(OutDir)\OpenZWave.lib;%(AdditionalDependencies) + true + Console + true + true + MachineX86 + + + + + MaxSpeed + true + ..\..\..\..\src;..\..\..\..\src\platform;..\..\..\..\src\value_classes;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;OPENZWAVE_USEDLL;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + 4251 + + + $(OutDir)\OpenZWave.lib;%(AdditionalDependencies) + true + Console + true + true + MachineX86 + + + + + + + + + \ No newline at end of file diff --git a/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj.filters b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..2e0198349777131c464545b261ac0df1e6df68e2 --- /dev/null +++ b/ubuntu/open-zwave-1.5/cpp/examples/windows/MinOZW/vs2010/MinOZW.vcxproj.filters @@ -0,0 +1,14 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + \ No newline at end of file