From f6adc96b2fe5b22297d9d36cc6fc5b831e2bb2c0 Mon Sep 17 00:00:00 2001 From: James Reuss Date: Mon, 19 Oct 2020 23:29:27 +0100 Subject: [PATCH] mega update -- support for ozw v1.6.962 --- .gitignore | 3 - .gitmodules | 0 README.md | 62 +- config.go | 10 - controller.go | 26 - controllercommand_string.go | 39 + controllererror_string.go | 35 + controllerstate_string.go | 33 + driver.go | 138 ---- go.mod | 5 + go.sum | 13 + gominozw/gominozw.go | 147 ---- gominozw/main.go | 23 + gominozw/node.go | 56 ++ gominozw/run.go | 263 ++++++ goopenzwave.go | 67 -- groups.go | 65 -- gzw_loglevel.cpp | 48 -- gzw_loglevel.h | 34 - gzw_manager.cpp | 1318 ------------------------------- gzw_manager.h | 284 ------- gzw_notification.cpp | 167 ---- gzw_notification.h | 78 -- gzw_options.cpp | 99 --- gzw_options.h | 37 - gzw_valueid.cpp | 124 --- gzw_valueid.h | 57 -- loglevel.go | 22 - manager.go | 85 +- manager_wrap.cpp | 89 +++ manager_wrap.h | 23 + network.go | 173 ---- node.go | 645 +++++++++------ node_wrap.cpp | 227 ++++++ node_wrap.h | 61 ++ nodes.go | 432 ---------- notification.go | 542 ++++++------- notificationcode_string.go | 29 + notifications.go | 46 -- notificationtype_string.go | 54 ++ options.go | 155 ++-- options_wrap.cpp | 32 + options_wrap.h | 22 + polling.go | 67 -- scenes.go | 348 -------- useralertnotification_string.go | 32 + util.cpp | 16 + util.h | 18 + value.go | 485 ++++++++++++ value_wrap.cpp | 652 +++++++++++++++ value_wrap.h | 92 +++ valuegenre_string.go | 26 + valueid.go | 533 ++----------- values.go | 554 ------------- valuetype_string.go | 33 + zwbytes.cpp | 38 - zwbytes.h | 60 -- zwlist.cpp | 40 - zwlist.h | 59 -- 59 files changed, 3178 insertions(+), 5743 deletions(-) delete mode 100644 .gitmodules delete mode 100644 config.go delete mode 100644 controller.go create mode 100644 controllercommand_string.go create mode 100644 controllererror_string.go create mode 100644 controllerstate_string.go delete mode 100644 driver.go create mode 100644 go.mod create mode 100644 go.sum delete mode 100644 gominozw/gominozw.go create mode 100644 gominozw/main.go create mode 100644 gominozw/node.go create mode 100644 gominozw/run.go delete mode 100644 goopenzwave.go delete mode 100644 groups.go delete mode 100644 gzw_loglevel.cpp delete mode 100644 gzw_loglevel.h delete mode 100644 gzw_manager.cpp delete mode 100644 gzw_manager.h delete mode 100644 gzw_notification.cpp delete mode 100644 gzw_notification.h delete mode 100644 gzw_options.cpp delete mode 100644 gzw_options.h delete mode 100644 gzw_valueid.cpp delete mode 100644 gzw_valueid.h delete mode 100644 loglevel.go create mode 100644 manager_wrap.cpp create mode 100644 manager_wrap.h delete mode 100644 network.go create mode 100644 node_wrap.cpp create mode 100644 node_wrap.h delete mode 100644 nodes.go create mode 100644 notificationcode_string.go delete mode 100644 notifications.go create mode 100644 notificationtype_string.go create mode 100644 options_wrap.cpp create mode 100644 options_wrap.h delete mode 100644 polling.go delete mode 100644 scenes.go create mode 100644 useralertnotification_string.go create mode 100644 util.cpp create mode 100644 util.h create mode 100644 value.go create mode 100644 value_wrap.cpp create mode 100644 value_wrap.h create mode 100644 valuegenre_string.go delete mode 100644 values.go create mode 100644 valuetype_string.go delete mode 100644 zwbytes.cpp delete mode 100644 zwbytes.h delete mode 100644 zwlist.cpp delete mode 100644 zwlist.h diff --git a/.gitignore b/.gitignore index a3f745a..96b53ab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,5 @@ OZW_Log.txt ozwcache_*.xml zwcfg_*.xml zwscene.xml -/.lib /gominozw/gominozw /gominozw/gominozw.exe -/open-zwave/*.dylib -/open-zwave/ozw_config diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 40ff7df..869de8b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # goopenzwave -Go bindings for the [OpenZWave](https://github.com/OpenZWave/open-zwave) library. +Go bindings for the [OpenZWave](https://github.com/OpenZWave/open-zwave) library (version 1.6+). ## Warning @@ -12,59 +12,35 @@ Most of the C++ OpenZWave library is wrapped now, but should you find anything m ## Installing OpenZWave -This package requires a system installation of [OpenZWave](https://github.com/OpenZWave/open-zwave). pkg-config is then used during the build of this package to get the open-zwave library and headers. +This package requires a system installation of [OpenZWave](https://github.com/OpenZWave/open-zwave). pkg-config is then used during the build of this package to get the OpenZWave library and headers. Note that package managers may install an old version of the library so a manual build/install from source is preferred. -Example install from source: -1. `git clone https://github.com/OpenZWave/open-zwave.git` -2. `cd open-zwave` -3. `make -j$(nproc)` -4. `sudo make install` -5. You may need to call `sudo ldconfig` now on linux systems -5. See the [open-zwave/INSTALL](https://github.com/OpenZWave/open-zwave/blob/master/INSTALL) file for more information +### macOS +1. Install [homebrew](https://brew.sh) +2. Install the OpenZWave library and dependencies: `brew install open-zwave pkg-config` (v1.6.962 http://old.openzwave.com/downloads/) -## Get the Package +### Debian (and other Linuxes) -``` -go get github.com/jimjibone/goopenzwave -``` +1. Install pkg-config: `sudo apt install pkg-config` +2. Get the source: `wget http://old.openzwave.com/downloads/openzwave-1.6.962.tar.gz && tar xzf openzwave-1.6.962.tar.gz` +3. Build and install it: `cd openzwave-1.6.962 && sudo make install` +4. Run ldconfig to update library links and cache: `sudo ldconfig` +5. See the [open-zwave/INSTALL](https://github.com/OpenZWave/open-zwave/blob/master/INSTALL) file for more information ## Example: `gominozw` -This package comes with a basic example, `gominozw`, which is a replica of the original C++ OpenZWave MinOZW utility, now written in Go. +This package comes with a basic example, `gominozw`, which is based on the original C++ OpenZWave MinOZW utility, now written in Go. -It shows how to set up the Manager with various options and listen for Notifications. Once the initial scan of devices is complete, polling for basic values is set up for the devices. +It shows how to set up the Manager with various options and listen for Notifications. Once the initial scan of devices is complete the device state information is printed to the console. To install and use: -``` -go install github.com/jimjibone/goopenzwave/gominozw -gominozw --controller /dev/ttyYourUSBDevice -``` - - -## Notes - -### open-zwave build fails with `fatal error: libudev.h: No such file or directory` on Debian/Ubuntu - -Try installing libudev with apt and build again. - -```sh -apt-get install libudev-dev -cd open-zwave && make -``` - - -### Crashes instantly on macOS 10.12 - -Do you see something like this when trying to run something with the goopenzwave package? - -``` -$ ./gominozw -h -zsh: killed ./gominozw -h -``` - -You should try building with the `-ldflags=-s` option. E.g.: `go build -ldflags=-s`. More info at [golang/go#19734](https://github.com/golang/go/issues/19734). +1. Build application: `go build -o gominozw ./gominozw` +2. Create config and user directories: `mkdir -p config user` +3. Copy openzwave config files: + - macOS: `cp -r /usr/local/Cellar/open-zwave/1.6.962/etc/openzwave/ ./config` + - Debian: `cp -r /usr/local/etc/openzwave/ ./config` +6. Run it: `./gominozw run -c ./config/openzwave -u ./user -p /dev/tty...` diff --git a/config.go b/config.go deleted file mode 100644 index bbbc047..0000000 --- a/config.go +++ /dev/null @@ -1,10 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -import "C" - -// WriteConfig saves the Z-Wave network configuration. This is so that the -// entire network does not need to be polled every time the application starts. -func WriteConfig(homeID uint32) { - C.manager_writeConfig(cmanager, C.uint32_t(homeID)) -} diff --git a/controller.go b/controller.go deleted file mode 100644 index a73a2a6..0000000 --- a/controller.go +++ /dev/null @@ -1,26 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -import "C" - -// ResetController performs a hard reset on a PC Z-Wave Controller. -// -// Resets a controller and erases its network configuration settings. The -// controller becomes a primary controller ready to add devices to a new -// network. -func ResetController(homeID uint32) { - C.manager_resetController(cmanager, C.uint32_t(homeID)) -} - -// SoftReset performs a soft reset on a PC Z-Wave Controller. -// -// Resets a controller without erasing its network configuration settings. -func SoftReset(homeID uint32) { - C.manager_softReset(cmanager, C.uint32_t(homeID)) -} - -// CancelControllerCommand cancels any in-progress command running on a -// controller. -func CancelControllerCommand(homeID uint32) { - C.manager_cancelControllerCommand(cmanager, C.uint32_t(homeID)) -} diff --git a/controllercommand_string.go b/controllercommand_string.go new file mode 100644 index 0000000..9c4836a --- /dev/null +++ b/controllercommand_string.go @@ -0,0 +1,39 @@ +// Code generated by "stringer -trimprefix=ControllerCommand_ -type=ControllerCommand"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ControllerCommand_None-0] + _ = x[ControllerCommand_AddDevice-1] + _ = x[ControllerCommand_CreateNewPrimary-2] + _ = x[ControllerCommand_ReceiveConfiguration-3] + _ = x[ControllerCommand_RemoveDevice-4] + _ = x[ControllerCommand_RemoveFailedNode-5] + _ = x[ControllerCommand_HasNodeFailed-6] + _ = x[ControllerCommand_ReplaceFailedNode-7] + _ = x[ControllerCommand_TransferPrimaryRole-8] + _ = x[ControllerCommand_RequestNetworkUpdate-9] + _ = x[ControllerCommand_RequestNodeNeighborUpdate-10] + _ = x[ControllerCommand_AssignReturnRoute-11] + _ = x[ControllerCommand_DeleteAllReturnRoutes-12] + _ = x[ControllerCommand_SendNodeInformation-13] + _ = x[ControllerCommand_ReplicationSend-14] + _ = x[ControllerCommand_CreateButton-15] + _ = x[ControllerCommand_DeleteButton-16] +} + +const _ControllerCommand_name = "NoneAddDeviceCreateNewPrimaryReceiveConfigurationRemoveDeviceRemoveFailedNodeHasNodeFailedReplaceFailedNodeTransferPrimaryRoleRequestNetworkUpdateRequestNodeNeighborUpdateAssignReturnRouteDeleteAllReturnRoutesSendNodeInformationReplicationSendCreateButtonDeleteButton" + +var _ControllerCommand_index = [...]uint16{0, 4, 13, 29, 49, 61, 77, 90, 107, 126, 146, 171, 188, 209, 228, 243, 255, 267} + +func (i ControllerCommand) String() string { + if i >= ControllerCommand(len(_ControllerCommand_index)-1) { + return "ControllerCommand(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _ControllerCommand_name[_ControllerCommand_index[i]:_ControllerCommand_index[i+1]] +} diff --git a/controllererror_string.go b/controllererror_string.go new file mode 100644 index 0000000..b68c1c6 --- /dev/null +++ b/controllererror_string.go @@ -0,0 +1,35 @@ +// Code generated by "stringer -trimprefix=ControllerError_ -type=ControllerError"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ControllerError_None-0] + _ = x[ControllerError_ButtonNotFound-1] + _ = x[ControllerError_NodeNotFound-2] + _ = x[ControllerError_NotBridge-3] + _ = x[ControllerError_NotSUC-4] + _ = x[ControllerError_NotSecondary-5] + _ = x[ControllerError_NotPrimary-6] + _ = x[ControllerError_IsPrimary-7] + _ = x[ControllerError_NotFound-8] + _ = x[ControllerError_Busy-9] + _ = x[ControllerError_Failed-10] + _ = x[ControllerError_Disabled-11] + _ = x[ControllerError_Overflow-12] +} + +const _ControllerError_name = "NoneButtonNotFoundNodeNotFoundNotBridgeNotSUCNotSecondaryNotPrimaryIsPrimaryNotFoundBusyFailedDisabledOverflow" + +var _ControllerError_index = [...]uint8{0, 4, 18, 30, 39, 45, 57, 67, 76, 84, 88, 94, 102, 110} + +func (i ControllerError) String() string { + if i >= ControllerError(len(_ControllerError_index)-1) { + return "ControllerError(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _ControllerError_name[_ControllerError_index[i]:_ControllerError_index[i+1]] +} diff --git a/controllerstate_string.go b/controllerstate_string.go new file mode 100644 index 0000000..81dcf38 --- /dev/null +++ b/controllerstate_string.go @@ -0,0 +1,33 @@ +// Code generated by "stringer -trimprefix=ControllerState_ -type=ControllerState"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ControllerState_Normal-0] + _ = x[ControllerState_Starting-1] + _ = x[ControllerState_Cancel-2] + _ = x[ControllerState_Error-3] + _ = x[ControllerState_Waiting-4] + _ = x[ControllerState_Sleeping-5] + _ = x[ControllerState_InProgress-6] + _ = x[ControllerState_Completed-7] + _ = x[ControllerState_Failed-8] + _ = x[ControllerState_NodeOK-9] + _ = x[ControllerState_NodeFailed-10] +} + +const _ControllerState_name = "NormalStartingCancelErrorWaitingSleepingInProgressCompletedFailedNodeOKNodeFailed" + +var _ControllerState_index = [...]uint8{0, 6, 14, 20, 25, 32, 40, 50, 59, 65, 71, 81} + +func (i ControllerState) String() string { + if i >= ControllerState(len(_ControllerState_index)-1) { + return "ControllerState(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _ControllerState_name[_ControllerState_index[i]:_ControllerState_index[i+1]] +} diff --git a/driver.go b/driver.go deleted file mode 100644 index a185cd1..0000000 --- a/driver.go +++ /dev/null @@ -1,138 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" -import ( - "fmt" - "unsafe" -) - -// AddDriver creates a new driver for a Z-Wave controller using the path -// specified (e.g. "/dev/ttyUSB0"). It returns an error if the controller -// already exists. -// -// This method creates a Driver object for handling communications with a single -// Z-Wave controller. In the background, the driver first tries to read -// configuration data saved during a previous run. It then queries the -// controller directly for any missing information, and a refresh of the list of -// nodes that it controls. Once this information has been received, a -// DriverReady notification callback is sent, containing the Home ID of the -// controller. This Home ID is required by most of the OpenZWave Manager class -// methods. -func AddDriver(controllerPath string) error { - cControllerPath := C.CString(controllerPath) - defer C.free(unsafe.Pointer(cControllerPath)) - ok := bool(C.manager_addDriver(cmanager, cControllerPath)) - if ok == false { - return fmt.Errorf("controller already exists") - } - return nil -} - -// RemoveDriver removes the driver for a Z-Wave controller as specified, and -// closes the controller. It returns an error if the controller could not be -// found. -// -// Drivers do not need to be explicitly removed before calling Destroy - this is -// handled automatically. -func RemoveDriver(controllerPath string) error { - cControllerPath := C.CString(controllerPath) - defer C.free(unsafe.Pointer(cControllerPath)) - ok := bool(C.manager_removeDriver(cmanager, cControllerPath)) - if ok == false { - return fmt.Errorf("controller not found") - } - return nil -} - -// GetControllerNodeID returns the node ID of the Z-Wave controller. -func GetControllerNodeID(homeID uint32) uint8 { - return uint8(C.manager_getControllerNodeId(cmanager, C.uint32_t(homeID))) -} - -// GetSUCNodeID returns the node ID of the Static Update Controller. -func GetSUCNodeID(homeID uint32) uint8 { - return uint8(C.manager_getSUCNodeId(cmanager, C.uint32_t(homeID))) -} - -// IsPrimaryController returns true if the controller is a primary controller. -// -// The primary controller is the main device used to configure and control a -// Z-Wave network. There can only be one primary controller - all other -// controllers are secondary controllers. -func IsPrimaryController(homeID uint32) bool { - return bool(C.manager_isPrimaryController(cmanager, C.uint32_t(homeID))) -} - -// IsStaticUpdateController returns true if the controller is a static update -// controller. -// -// A Static Update Controller (SUC) is a controller that must never be moved in -// normal operation and which can be used by other nodes to receive information -// about network changes. -func IsStaticUpdateController(homeID uint32) bool { - return bool(C.manager_isStaticUpdateController(cmanager, C.uint32_t(homeID))) -} - -// IsBridgeController returns true if the controller is using the bridge -// controller library. -// -// A bridge controller is able to create virtual nodes that -// can be associated with other controllers to enable events to be passed on. -func IsBridgeController(homeID uint32) bool { - return bool(C.manager_isBridgeController(cmanager, C.uint32_t(homeID))) -} - -// GetLibraryVersion returns a string version of the Z-Wave API library used by -// a controller. -func GetLibraryVersion(homeID uint32) string { - cstr := C.manager_getLibraryVersion(cmanager, C.uint32_t(homeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetLibraryTypeName returns a string containing the Z-Wave API library type -// used by a controller. -// -// The possible library types are: -// - Static Controller -// - Controller -// - Enhanced Slave -// - Slave -// - Installer -// - Routing Slave -// - Bridge Controller -// - Device Under Test -// -// The controller should never return a slave library type. For a more efficient -// test of whether a controller is a Bridge Controller, use the -// IsBridgeController method. -func GetLibraryTypeName(homeID uint32) string { - cstr := C.manager_getLibraryTypeName(cmanager, C.uint32_t(homeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetSendQueueCount returns the count of messages in the outgoing send queue. -func GetSendQueueCount(homeID uint32) int32 { - return int32(C.manager_getSendQueueCount(cmanager, C.uint32_t(homeID))) -} - -// LogDriverStatistics will send the current driver statistics to the log file. -func LogDriverStatistics(homeID uint32) { - C.manager_logDriverStatistics(cmanager, C.uint32_t(homeID)) -} - -// GetControllerInterfaceType Obtain controller interface type. -//TODO func GetControllerInterfaceType(homeID uint32) ... - -// GetControllerPath returns a string of the controller interface path. -func GetControllerPath(homeID uint32) string { - cstr := C.manager_getControllerPath(cmanager, C.uint32_t(homeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetDriverStatistics Retrieve statistics from driver. -//TODO func GetDriverStatistics(...) ... diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f93e60b --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/jimjibone/goopenzwave + +go 1.13 + +require github.com/urfave/cli/v2 v2.2.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9e80cca --- /dev/null +++ b/go.sum @@ -0,0 +1,13 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= +github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gominozw/gominozw.go b/gominozw/gominozw.go deleted file mode 100644 index 4b86f25..0000000 --- a/gominozw/gominozw.go +++ /dev/null @@ -1,147 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "os/signal" - - "github.com/jimjibone/goopenzwave" -) - -type NodeInfo struct { - HomeID uint32 - NodeID uint8 - Node *goopenzwave.Node - Values map[uint64]*goopenzwave.ValueID -} - -var Nodes = make(map[uint8]*NodeInfo) -var initialQueryComplete = make(chan bool) -var sentinitialQueryComplete = false - -func main() { - var controllerPath string - var configPath string - flag.StringVar(&controllerPath, "controller", "/dev/ttyUSB0", "the path to your controller device") - flag.StringVar(&configPath, "config", "/usr/local/etc/openzwave/", "the path to open-zwave config") - flag.Parse() - - fmt.Println("gominozw started with openzwave version:", goopenzwave.GetVersionLongAsString()) - - // Setup the OpenZWave library. - options := goopenzwave.CreateOptions(configPath, "", "") - options.AddOptionLogLevel("SaveLogLevel", goopenzwave.LogLevelNone) - options.AddOptionLogLevel("QueueLogLevel", goopenzwave.LogLevelNone) - options.AddOptionInt("DumpTrigger", 4) - options.AddOptionInt("PollInterval", 500) - options.AddOptionBool("IntervalBetweenPolls", true) - options.AddOptionBool("ValidateValueChanges", true) - options.Lock() - - // Start the library and listen for notifications. - err := goopenzwave.Start(handleNotification) - if err != nil { - fmt.Println("ERROR: failed to start goopenzwave package:", err) - return - } - - // Add a driver using the supplied controller path. - err = goopenzwave.AddDriver(controllerPath) - if err != nil { - fmt.Println("ERROR: failed to add goopenzwave driver:", err) - return - } - - // Wait here until the initial node query has completed. - <-initialQueryComplete - fmt.Println("Finished initial scan, now setting up polling...") - - // Now we will enable polling for a variable. In this simple example, it - // has been hardwired to poll COMMAND_CLASS_BASIC on each node that - // supports this setting. - for _, node := range Nodes { - // Skip the controller (most likely node 1). - if node.NodeID == 1 { - continue - } - - // For each value for this node, set up polling. - for i := range node.Values { - valueid := node.Values[i] - - if valueid.CommandClassID == 0x20 { - // Enable polling with "intensity" of 2. Though, this is - // irrelevant with only one value polled. - valueid.EnablePoll(2) - } - } - } - - fmt.Println("Initial scan complete. Now polling for updates...") - fmt.Println("Hit ctrl-c to quit") - - // Now wait for the user to quit. - sig := make(chan os.Signal, 1) - signal.Notify(sig, os.Interrupt) - <-sig - - // Print out what we know about the network. - fmt.Println("Nodes:") - for id, node := range Nodes { - fmt.Printf("\t%3d: Node: %s\n", id, node.Node) - fmt.Printf("\t Values: (%d)\n", len(node.Values)) - for i := range node.Values { - fmt.Printf("\t\t0x%x: %s\n", i, node.Values[i]) - } - } - - // All done now finish up. - goopenzwave.RemoveDriver(controllerPath) - goopenzwave.Stop() - goopenzwave.DestroyOptions() -} - -func handleNotification(notification *goopenzwave.Notification) { - fmt.Println("Received notification:", notification) - - // Switch based on notification type. - switch notification.Type { - case goopenzwave.NotificationTypeNodeAdded: - // Create a NodeInfo from the notification then add it to the - // map. - nodeinfo := &NodeInfo{ - HomeID: notification.HomeID, - NodeID: notification.NodeID, - Node: goopenzwave.NewNode(notification.HomeID, notification.NodeID), - Values: make(map[uint64]*goopenzwave.ValueID), - } - Nodes[nodeinfo.NodeID] = nodeinfo - - case goopenzwave.NotificationTypeNodeRemoved: - // Remove the NodeInfo from the map. - if _, found := Nodes[notification.NodeID]; found { - delete(Nodes, notification.NodeID) - } - - case goopenzwave.NotificationTypeValueAdded, goopenzwave.NotificationTypeValueChanged: - // Find the NodeInfo in the map and add/change the ValueID. - if node, found := Nodes[notification.NodeID]; found { - node.Values[notification.ValueID.ID] = notification.ValueID - } - - case goopenzwave.NotificationTypeValueRemoved: - // Find the NodeInfo in the map and remove the ValueID. - if node, found := Nodes[notification.NodeID]; found { - if _, foundVal := node.Values[notification.ValueID.ID]; foundVal { - delete(node.Values, notification.ValueID.ID) - } - } - - case goopenzwave.NotificationTypeAwakeNodesQueried, goopenzwave.NotificationTypeAllNodesQueried, goopenzwave.NotificationTypeAllNodesQueriedSomeDead: - // The initial node query has completed. - if sentinitialQueryComplete == false { - initialQueryComplete <- true - } - } -} diff --git a/gominozw/main.go b/gominozw/main.go new file mode 100644 index 0000000..34f1665 --- /dev/null +++ b/gominozw/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + "os" + + "github.com/urfave/cli/v2" +) + +func main() { + app := &cli.App{ + Name: "gominozw", + Usage: "gominozw example application for goopenzwave", + Commands: []*cli.Command{ + runCommand, + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} diff --git a/gominozw/node.go b/gominozw/node.go new file mode 100644 index 0000000..9dab18f --- /dev/null +++ b/gominozw/node.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + + zwave "github.com/jimjibone/goopenzwave" +) + +type Node struct { + HomeID uint32 + NodeID uint8 + Polled bool + Removed bool + + Name string + ProductName string + ManufacturerName string + + ValueIDs []zwave.ValueID +} + +func (n Node) String() string { + var name, product, manufacturer string + if n.Name != "" { + name = ", name: " + n.Name + } + if n.ProductName != "" { + product = ", product: " + n.ProductName + } + if n.ManufacturerName != "" { + manufacturer = ", manufacturer: " + n.ManufacturerName + } + return fmt.Sprintf("{homeid: %d, nodeid: %d, polled: %t, removed: %t%s%s%s, valueids: %d}", + n.HomeID, + n.NodeID, + n.Polled, + n.Removed, + name, + product, + manufacturer, + len(n.ValueIDs), + ) +} + +type NodeValue struct { + ValueID zwave.ValueID + Label string + Value string + Units string + List []string + Help string +} + +func (n NodeValue) String() string { + return fmt.Sprintf("{id: %s, label: %s, value: %s, units: %s, list: %q, help: %s}", n.ValueID, n.Label, n.Value, n.Units, n.List, n.Help) +} diff --git a/gominozw/run.go b/gominozw/run.go new file mode 100644 index 0000000..d5030f6 --- /dev/null +++ b/gominozw/run.go @@ -0,0 +1,263 @@ +package main + +import ( + "fmt" + "os" + "os/signal" + + zwave "github.com/jimjibone/goopenzwave" + "github.com/urfave/cli/v2" +) + +var runCommand = &cli.Command{ + Name: "run", + Description: "runs goopenzwave", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "controller", + Aliases: []string{"p"}, + Usage: `path to the controller device (e.g. "/dev/ttyUSB0" on Linux or "\\.\COM3" on Windows)`, + Required: true, + }, + &cli.StringFlag{ + Name: "config-dir", + Aliases: []string{"c"}, + Usage: "path to the openzwave config folder", + Value: "./config/", + }, + &cli.StringFlag{ + Name: "user-dir", + Aliases: []string{"u"}, + Usage: "path to the openzwave user folder", + Value: "./user/", + }, + }, + Action: func(c *cli.Context) error { + zwave.OptionsCreate(c.String("config-dir"), c.String("user-dir"), "") + zwave.OptionsAddInt("SaveLogLevel", 4) + zwave.OptionsAddInt("QueueLogLevel", 4) + zwave.OptionsLock() + defer zwave.OptionsDestroy() + + zwave.ManagerCreate() + defer zwave.ManagerDestroy() + + driverfailed := make(chan struct{}) + var nodes []*Node + findNode := func(homeid uint32, nodeid uint8) *Node { + for _, n := range nodes { + if n.HomeID == homeid && n.NodeID == nodeid { + return n + } + } + return nil + } + removeValueID := func(n *Node, val zwave.ValueID) { + for i, v := range n.ValueIDs { + if v.Equal(val) { + // https://github.com/golang/go/wiki/SliceTricks + n.ValueIDs = append(n.ValueIDs[:i], n.ValueIDs[i+1:]...) + return + } + } + } + removeNode := func(homeid uint32, nodeid uint8) { + for _, n := range nodes { + if n.HomeID == homeid && n.NodeID == nodeid { + // // https://github.com/golang/go/wiki/SliceTricks + // if i < len(nodes)-1 { + // copy(nodes[i:], nodes[i+1:]) + // } + // nodes[len(nodes)-1] = nil + // nodes = nodes[:len(nodes)-1] + // return + n.Removed = true + } + } + } + zwave.ManagerAddWatcher(func(n zwave.Notification) { + if n.Type != zwave.NotificationType_ValueChanged { + fmt.Println("Notification:", n.String()) + } + switch n.Type { + case zwave.NotificationType_ValueAdded: // A new node value has been added to OpenZWave's list. These notifications occur after a node has been discovered, and details of its command classes have been received. Each command class may generate one or more values depending on the complexity of the item being represented. + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + node.ValueIDs = append(node.ValueIDs, n.ValueID) + fmt.Println(" Node value added:", node, n.ValueID) + } + + case zwave.NotificationType_ValueRemoved: // A node value has been removed from OpenZWave's list. This only occurs when a node is removed. + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + removeValueID(node, n.ValueID) + fmt.Println(" Node value removed:", node, n.ValueID) + } + + case zwave.NotificationType_ValueChanged: // A node value has been updated from the Z-Wave network and it is different from the previous value. + case zwave.NotificationType_ValueRefreshed: // A node value has been updated from the Z-Wave network. + case zwave.NotificationType_Group: // The associations for the node have changed. The application should rebuild any group information it holds about the node. + case zwave.NotificationType_NodeNew: // A new node has been found (not already stored in zwcfg*.xml file) + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node == nil { + node := &Node{ + HomeID: n.ValueID.HomeID(), + NodeID: n.ValueID.NodeID(), + Polled: false, + } + nodes = append(nodes, node) + fmt.Println(" Node new:", node) + } else { + fmt.Println(" Node already new:", node) + } + + case zwave.NotificationType_NodeAdded: // A new node has been added to OpenZWave's list. This may be due to a device being added to the Z-Wave network, or because the application is initializing itself. + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node == nil { + node := &Node{ + HomeID: n.ValueID.HomeID(), + NodeID: n.ValueID.NodeID(), + Polled: false, + } + nodes = append(nodes, node) + fmt.Println(" Node added:", node) + } else { + fmt.Println(" Node already added:", node) + } + + case zwave.NotificationType_NodeRemoved: // A node has been removed from OpenZWave's list. This may be due to a device being removed from the Z-Wave network, or because the application is closing. + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + fmt.Println(" Node removed:", node) + removeNode(n.ValueID.HomeID(), n.ValueID.NodeID()) + } + + case zwave.NotificationType_NodeProtocolInfo: // Basic node information has been received, such as whether the node is a listening device, a routing device and its baud rate and basic, generic and specific types. It is after this notification that you can call Manager::GetNodeType to obtain a label containing the device description. + case zwave.NotificationType_NodeNaming: // One of the node names has changed (name, manufacturer, product). + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + node.Name = zwave.GetNodeName(node.HomeID, node.NodeID) + node.ProductName = zwave.GetNodeProductName(node.HomeID, node.NodeID) + node.ManufacturerName = zwave.GetNodeManufacturerName(node.HomeID, node.NodeID) + fmt.Println(" Node naming:", node) + } + + case zwave.NotificationType_NodeEvent: // A node has triggered an event. This is commonly caused when a node sends a Basic_Set command to the controller. The event value is stored in the notification. + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + fmt.Println(" Node event:", node, n.GetEvent()) + } + + case zwave.NotificationType_PollingDisabled: // Polling of a node has been successfully turned off by a call to Manager::DisablePoll + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + node.Polled = false + fmt.Println(" Node polling disabled:", node) + } + + case zwave.NotificationType_PollingEnabled: // Polling of a node has been successfully turned on by a call to Manager::EnablePoll + if node := findNode(n.ValueID.HomeID(), n.ValueID.NodeID()); node != nil { + node.Polled = true + fmt.Println(" Node polling enabled:", node) + } + + case zwave.NotificationType_SceneEvent: // Scene Activation Set received (Depreciated in 1.8) + case zwave.NotificationType_CreateButton: // Handheld controller button event created + case zwave.NotificationType_DeleteButton: // Handheld controller button event deleted + case zwave.NotificationType_ButtonOn: // Handheld controller button on pressed event + case zwave.NotificationType_ButtonOff: // Handheld controller button off pressed event + case zwave.NotificationType_DriverReady: // A driver for a PC Z-Wave controller has been added and is ready to use. The notification will contain the controller's Home ID, which is needed to call most of the Manager methods. + fmt.Println(" Driver ready") + + case zwave.NotificationType_DriverFailed: // Driver failed to load + // Exit the app now... or try again + fmt.Println(" Driver failed") + close(driverfailed) + + case zwave.NotificationType_DriverReset: // All nodes and values for this driver have been removed. This is sent instead of potentially hundreds of individual node and value notifications. + case zwave.NotificationType_EssentialNodeQueriesComplete: // The queries on a node that are essential to its operation have been completed. The node can now handle incoming messages. + case zwave.NotificationType_NodeQueriesComplete: // All the initialization queries on a node have been completed. + case zwave.NotificationType_AwakeNodesQueried: // All awake nodes have been queried, so client application can expected complete data for these nodes. + // Ready to start doing things from this point + fmt.Println(" Awake nodes queried") + close(driverfailed) + + case zwave.NotificationType_AllNodesQueriedSomeDead: // All nodes have been queried but some dead nodes found. + // Ready to start doing things from this point + fmt.Println(" All nodes queried some dead") + close(driverfailed) + + case zwave.NotificationType_AllNodesQueried: // All nodes have been queried, so client application can expected complete data. + // Ready to start doing things from this point + fmt.Println(" All nodes queried") + close(driverfailed) + + case zwave.NotificationType_Notification: // An error has occurred that we need to report. + case zwave.NotificationType_DriverRemoved: // The Driver is being removed. (either due to Error or by request) Do Not Call Any Driver Related Methods after receiving this call + case zwave.NotificationType_ControllerCommand: // When Controller Commands are executed, Notifications of Success/Failure etc are communicated via this Notification Notification::GetEvent returns Driver::ControllerCommand and Notification::GetNotification returns Driver::ControllerState + case zwave.NotificationType_NodeReset: // The Device has been reset and thus removed from the NodeList in OZW + case zwave.NotificationType_UserAlerts: // Warnings and Notifications Generated by the library that should be displayed to the user (eg, out of date config files) + case zwave.NotificationType_ManufacturerSpecificDBReady: // The ManufacturerSpecific Database Is Ready + } + }) + + zwave.ManagerAddDriver(c.String("controller")) + defer zwave.ManagerRemoveDriver(c.String("controller")) + + fmt.Println("version:", zwave.ManagerVersionString()) + fmt.Println("version:", zwave.ManagerVersionLongString()) + major, minor := zwave.ManagerVersion() + fmt.Printf("version: major: %d, minor: %d\n", major, minor) + + // wait for ctrl-c + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt) + select { + case <-sig: + case <-driverfailed: + } + signal.Reset(os.Interrupt) + + fmt.Printf("nodes: %d\n", len(nodes)) + for _, node := range nodes { + fmt.Printf("node: %s, name: %s, product: %s, manufacturer: %s\n", + node, + zwave.GetNodeName(node.HomeID, node.NodeID), + zwave.GetNodeProductName(node.HomeID, node.NodeID), + zwave.GetNodeManufacturerName(node.HomeID, node.NodeID), + ) + for _, vid := range node.ValueIDs { + valid, err := zwave.IsValueValid(vid) + if err != nil { + panic(err) + } + if valid { + name, err := zwave.GetValueLabel(vid, -1) + if err != nil { + panic(err) + } + val, err := zwave.GetValueAsString(vid) + if err != nil { + panic(err) + } + units, err := zwave.GetValueUnits(vid) + if err != nil { + panic(err) + } + var list []string + if vid.Type() == zwave.ValueType_List { + list, err = zwave.GetValueListItems(vid) + if err != nil { + panic(err) + } + } + help, err := zwave.GetValueHelp(vid, -1) + if err != nil { + panic(err) + } + fmt.Printf(" valueid: %s\n", vid) + fmt.Printf(" name: %s\n", name) + fmt.Printf(" val: %s (%s)\n", val, units) + fmt.Printf(" list: %q\n", list) + fmt.Printf(" help: %s\n", help) + } else { + fmt.Printf(" valueid: %s, INVALID\n", vid) + } + } + } + + return nil + }, +} diff --git a/goopenzwave.go b/goopenzwave.go deleted file mode 100644 index 570cf29..0000000 --- a/goopenzwave.go +++ /dev/null @@ -1,67 +0,0 @@ -package goopenzwave - -// #cgo pkg-config: libopenzwave -// #include "gzw_manager.h" -// #include "gzw_notification.h" -// #include -import "C" -import ( - "fmt" -) - -var ( - started bool - notificationHandler NotificationHandler -) - -// NotificationHandler defines the format for a function that will handle new -// Notification's as they arrive. -type NotificationHandler func(notification *Notification) - -// Start will create a new OpenZWave Manager, starting the library execution. -// The OpenZWave Options must be created and locked before calling this. See the -// Options struct. Also pass a NotificationHandler function to this as -// notifications will also be started. -func Start(handler NotificationHandler) error { - // Only start once. - if started { - return fmt.Errorf("already started") - } - - // Create the manager. - err := createManager() - if err != nil { - return fmt.Errorf("failed to create manager: %s", err) - } - - // Start notifications. - err = startNotifications() - if err != nil { - return err - } - - // Set the notification handler. - notificationHandler = handler - - return nil -} - -// Stop will stop notifications and destroy the manager. Do this just before you -// quit your app. Don't forget to destroy the Options object after calling this. -func Stop() error { - // Check we have started. - if started { - return fmt.Errorf("already started") - } - - // Stop notifications. - err := stopNotifications() - if err != nil { - return err - } - - // Destroy the manager. - destroyManager() - - return nil -} diff --git a/groups.go b/groups.go deleted file mode 100644 index 5cc503b..0000000 --- a/groups.go +++ /dev/null @@ -1,65 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" -import "unsafe" - -// GetNumGroups returns the number of association groups reported by this node. -// -// In Z-Wave, groups are numbered starting from one. For example, if a call to -// GetNumGroups returns 4, the _groupIdx value to use in calls to -// GetAssociations, AddAssociation and RemoveAssociation will be a number -// between 1 and 4. -func GetNumGroups(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNumGroups(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetAssociations returns the associations for a group. -// -// Makes a copy of the list of associated nodes in the group, and returns it in -// an array of uint8's. The caller is responsible for freeing the array memory -// with a call to delete []. -//TODO func GetAssociations(homeID uint32, nodeID uint8, groupIDx uint8, uint8 **o_associations) ... - -// GetAssociations returns the associations for a group. -// -// Makes a copy of the list of associated nodes in the group, and returns it in -// an array of InstanceAssociation's. The caller is responsible for freeing the -// array memory with a call to delete []. -//TODO func GetAssociations(homeID uint32, nodeID uint8, groupIDx uint8, InstanceAssociation **o_associations) ... - -// GetMaxAssociations returns the maximum number of associations for a group. -func GetMaxAssociations(homeID uint32, nodeID uint8, groupIDx uint8) uint8 { - return uint8(C.manager_getMaxAssociations(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(groupIDx))) -} - -// GetGroupLabel returns a label for the particular group of a node. This label -// is populated by the device specific configuration files. -func GetGroupLabel(homeID uint32, nodeID uint8, groupIDx uint8) string { - cstr := C.manager_getGroupLabel(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(groupIDx)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// AddAssociation adds a node to an association group. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the association data held in this class is updated directly. -// This will be reverted by a future Association message from the device if the -// Z-Wave message actually failed to get through. Notification callbacks will be -// sent in both cases. -func AddAssociation(homeID uint32, nodeID uint8, groupIDx uint8, targetNodeID uint8, instance uint8) { - C.manager_addAssociation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(groupIDx), C.uint8_t(targetNodeID), C.uint8_t(instance)) -} - -// RemoveAssociation removes a node from an association group. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the association data held in this class is updated directly. -// This will be reverted by a future Association message from the device if the -// Z-Wave message actually failed to get through. Notification callbacks will be -// sent in both cases. -func RemoveAssociation(homeID uint32, nodeID uint8, groupIDx uint8, targetNodeID uint8, instance uint8) { - C.manager_removeAssociation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(groupIDx), C.uint8_t(targetNodeID), C.uint8_t(instance)) -} diff --git a/gzw_loglevel.cpp b/gzw_loglevel.cpp deleted file mode 100644 index e118246..0000000 --- a/gzw_loglevel.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "gzw_loglevel.h" - -OpenZWave::LogLevel loglevel_toLogLevel(loglevel_t level) -{ - OpenZWave::LogLevel loglevel; - switch (level) { - case loglevel_invalid: - loglevel = OpenZWave::LogLevel_Invalid; - break; - case loglevel_none: - loglevel = OpenZWave::LogLevel_None; - break; - case loglevel_always: - loglevel = OpenZWave::LogLevel_Always; - break; - case loglevel_fatal: - loglevel = OpenZWave::LogLevel_Fatal; - break; - case loglevel_error: - loglevel = OpenZWave::LogLevel_Error; - break; - case loglevel_warning: - loglevel = OpenZWave::LogLevel_Warning; - break; - case loglevel_alert: - loglevel = OpenZWave::LogLevel_Alert; - break; - case loglevel_info: - loglevel = OpenZWave::LogLevel_Info; - break; - case loglevel_detail: - loglevel = OpenZWave::LogLevel_Detail; - break; - case loglevel_debug: - loglevel = OpenZWave::LogLevel_Debug; - break; - case loglevel_streamdetail: - loglevel = OpenZWave::LogLevel_StreamDetail; - break; - case loglevel_internal: - loglevel = OpenZWave::LogLevel_Internal; - break; - default: - loglevel = OpenZWave::LogLevel_Invalid; - break; - } - return loglevel; -} diff --git a/gzw_loglevel.h b/gzw_loglevel.h deleted file mode 100644 index 33b6f86..0000000 --- a/gzw_loglevel.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef GOOPENZWAVE_LOGLEVEL -#define GOOPENZWAVE_LOGLEVEL - -#include -#include -#include - -#ifdef __cplusplus -#include -extern "C" { -#endif - -// enum loglevel -typedef enum { - loglevel_invalid = 0, - loglevel_none, - loglevel_always, - loglevel_fatal, - loglevel_error, - loglevel_warning, - loglevel_alert, - loglevel_info, - loglevel_detail, - loglevel_debug, - loglevel_streamdetail, - loglevel_internal -} loglevel_t; - -#ifdef __cplusplus -} -OpenZWave::LogLevel loglevel_toLogLevel(loglevel_t level); -#endif - -#endif // define GOOPENZWAVE_LOGLEVEL diff --git a/gzw_manager.cpp b/gzw_manager.cpp deleted file mode 100644 index 4787205..0000000 --- a/gzw_manager.cpp +++ /dev/null @@ -1,1318 +0,0 @@ -#include "gzw_manager.h" -#include -#include -#include -#include - -// -// Construction. -// - -manager_t manager_create() -{ - OpenZWave::Manager *man = OpenZWave::Manager::Create(); - return (manager_t)man; -} - -manager_t manager_get() -{ - OpenZWave::Manager *man = OpenZWave::Manager::Get(); - return (manager_t)man; -} - -void manager_destroy() -{ - OpenZWave::Manager::Destroy(); -} - -char* manager_getVersionAsString() -{ - return strdup(OpenZWave::Manager::getVersionAsString().c_str()); -} - -char* manager_getVersionLongAsString() -{ - return strdup(OpenZWave::Manager::getVersionLongAsString().c_str()); -} - -void manager_getVersion(uint16_t *major, uint16_t *minor) -{ - ozwversion ver = OpenZWave::Manager::getVersion(); - *major = ver._v >> 16 & 0x00FF; - *minor = ver._v & 0x00FF; -} - -// -// Configuration. -// - -void manager_writeConfig(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->WriteConfig(homeId); -} - -options_t manager_getOptions(manager_t m) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return (options_t)man->GetOptions(); -} - -// -// Drivers. -// - -bool manager_addDriver(manager_t m, const char *controllerPath) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - if (strcasecmp(controllerPath, "usb") == 0) { - return man->AddDriver("HID Controller", OpenZWave::Driver::ControllerInterface_Hid); - } else { - return man->AddDriver(controllerPath); - } -} - -bool manager_removeDriver(manager_t m, const char *controllerPath) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - if (strcasecmp(controllerPath, "usb") == 0) { - return man->RemoveDriver("HID Controller"); - } else { - return man->RemoveDriver(controllerPath); - } -} - -uint8_t manager_getControllerNodeId(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetControllerNodeId(homeId); -} - -uint8_t manager_getSUCNodeId(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetSUCNodeId(homeId); -} - -bool manager_isPrimaryController(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsPrimaryController(homeId); -} - -bool manager_isStaticUpdateController(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsStaticUpdateController(homeId); -} - -bool manager_isBridgeController(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsBridgeController(homeId); -} - -char* manager_getLibraryVersion(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetLibraryVersion(homeId).c_str()); -} - -char* manager_getLibraryTypeName(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetLibraryTypeName(homeId).c_str()); -} - -int32_t manager_getSendQueueCount(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetSendQueueCount(homeId); -} - -void manager_logDriverStatistics(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->LogDriverStatistics(homeId); -} - -//TODO driver_controllerInterface_t manager_getControllerInterfaceType(manager_t m, uint32_t homeId) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// return man->GetControllerInterfaceType(homeId); -// } - -char* manager_getControllerPath(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetControllerPath(homeId).c_str()); -} - -// -// Polling Z-Wave devices. -// - -int32_t manager_getPollInterval(manager_t m) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetPollInterval(); -} - -void manager_setPollInterval(manager_t m, int32_t milliseconds, bool intervalBetweenPolls) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SetPollInterval(milliseconds, intervalBetweenPolls); -} - -bool manager_enablePoll(manager_t m, valueid_t valueid, uint8_t intensity) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->EnablePoll(*val, intensity); -} - -bool manager_disablePoll(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->DisablePoll(*val); -} - -bool manager_isPolled(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->isPolled(*val); -} - -void manager_setPollIntensity(manager_t m, valueid_t valueid, uint8_t intensity) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - man->SetPollIntensity(*val, intensity); -} - -uint8_t manager_getPollIntensity(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->DisablePoll(*val); -} - -// -// Node information. -// - -bool manager_refreshNodeInfo(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RefreshNodeInfo(homeId, nodeId); -} - -bool manager_requestNodeState(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RequestNodeState(homeId, nodeId); -} - -bool manager_requestNodeDynamic(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RequestNodeDynamic(homeId, nodeId); -} - -bool manager_isNodeListeningDevice(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeListeningDevice(homeId, nodeId); -} - -bool manager_isNodeFrequentListeningDevice(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeFrequentListeningDevice(homeId, nodeId); -} - -bool manager_isNodeBeamingDevice(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeBeamingDevice(homeId, nodeId); -} - -bool manager_isNodeRoutingDevice(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeRoutingDevice(homeId, nodeId); -} - -bool manager_isNodeSecurityDevice(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeSecurityDevice(homeId, nodeId); -} - -uint32_t manager_getNodeMaxBaudRate(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeMaxBaudRate(homeId, nodeId); -} - -uint8_t manager_getNodeVersion(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeVersion(homeId, nodeId); -} - -uint8_t manager_getNodeSecurity(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeSecurity(homeId, nodeId); -} - -bool manager_isNodeZWavePlus(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeZWavePlus(homeId, nodeId); -} - -uint8_t manager_getNodeBasic(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeBasic(homeId, nodeId); -} - -uint8_t manager_getNodeGeneric(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeGeneric(homeId, nodeId); -} - -uint8_t manager_getNodeSpecific(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeSpecific(homeId, nodeId); -} - -char* manager_getNodeType(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeType(homeId, nodeId).c_str()); -} - -//TODO uint32_t manager_getNodeNeighbors(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t **nodeNeighbors) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// return man->GetNodeNeighbours(homeId, nodeId); -// } - -char* manager_getNodeManufacturerName(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeManufacturerName(homeId, nodeId).c_str()); -} - -char* manager_getNodeProductName(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeProductName(homeId, nodeId).c_str()); -} - -char* manager_getNodeName(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeName(homeId, nodeId).c_str()); -} - -char* manager_getNodeLocation(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeLocation(homeId, nodeId).c_str()); -} - -char* manager_getNodeManufacturerId(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeManufacturerId(homeId, nodeId).c_str()); -} - -char* manager_getNodeProductType(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeProductType(homeId, nodeId).c_str()); -} - -char* manager_getNodeProductId(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeProductId(homeId, nodeId).c_str()); -} - -void manager_setNodeManufacturerName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* manufacturerName) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - std::string str(manufacturerName); - man->SetNodeManufacturerName(homeId, nodeId, str); -} - -void manager_setNodeProductName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* productName) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - std::string str(productName); - man->SetNodeProductName(homeId, nodeId, str); -} - -void manager_setNodeName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* nodeName) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - std::string str(nodeName); - man->SetNodeName(homeId, nodeId, str); -} - -void manager_setNodeLocation(manager_t m, uint32_t homeId, uint8_t nodeId, const char* location) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - std::string str(location); - man->SetNodeLocation(homeId, nodeId, str); -} - -void manager_setNodeOn(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SetNodeOn(homeId, nodeId); -} - -void manager_setNodeOff(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SetNodeOff(homeId, nodeId); -} - -void manager_setNodeLevel(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t level) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SetNodeLevel(homeId, nodeId, level); -} - -bool manager_isNodeInfoReceived(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeInfoReceived(homeId, nodeId); -} - -bool manager_getNodeClassInformation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t commandClassId, char **o_name, uint8_t *o_version) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - bool result; - std::string str; - result = man->GetNodeClassInformation(homeId, nodeId, commandClassId, &str, o_version); - if (*o_name) { - free(*o_name); - } - *o_name = strdup(str.c_str()); - return result; -} - -bool manager_isNodeAwake(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeAwake(homeId, nodeId); -} - -bool manager_isNodeFailed(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->IsNodeFailed(homeId, nodeId); -} - -char* manager_getNodeQueryStage(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeQueryStage(homeId, nodeId).c_str()); -} - -uint16_t manager_getNodeDeviceType(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeDeviceType(homeId, nodeId); -} - -char* manager_getNodeDeviceTypeString(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeDeviceTypeString(homeId, nodeId).c_str()); -} - -uint8_t manager_getNodeRole(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodeRole(homeId, nodeId); -} - -char* manager_getNodeRoleString(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodeRoleString(homeId, nodeId).c_str()); -} - -uint8_t manager_getNodePlusType(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNodePlusType(homeId, nodeId); -} - -char* manager_getNodePlusTypeString(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetNodePlusTypeString(homeId, nodeId).c_str()); -} - -// -// Values. -// - -char* manager_getValueLabel(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return strdup(man->GetValueLabel(*val).c_str()); -} - -void manager_setValueLabel(manager_t m, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - man->SetValueLabel(*val, str); -} - -char* manager_getValueUnits(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return strdup(man->GetValueUnits(*val).c_str()); -} - -void manager_setValueUnits(manager_t m, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - man->SetValueUnits(*val, str); -} - -char* manager_getValueHelp(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return strdup(man->GetValueHelp(*val).c_str()); -} - -void manager_setValueHelp(manager_t m, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - man->SetValueHelp(*val, str); -} - -int32_t manager_getValueMin(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueMin(*val); -} - -int32_t manager_getValueMax(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueMax(*val); -} - -bool manager_isValueReadOnly(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->IsValueReadOnly(*val); -} - -bool manager_isValueWriteOnly(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->IsValueWriteOnly(*val); -} - -bool manager_isValueSet(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->IsValueSet(*val); -} - -bool manager_isValuePolled(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->IsValuePolled(*val); -} - -bool manager_getValueAsBool(manager_t m, valueid_t valueid, bool *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsBool(*val, o_value); -} - -bool manager_getValueAsByte(manager_t m, valueid_t valueid, uint8_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsByte(*val, o_value); -} - -bool manager_getValueAsFloat(manager_t m, valueid_t valueid, float *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsFloat(*val, o_value); -} - -bool manager_getValueAsInt(manager_t m, valueid_t valueid, int32_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsInt(*val, o_value); -} - -bool manager_getValueAsShort(manager_t m, valueid_t valueid, int16_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsShort(*val, o_value); -} - -bool manager_getValueAsString(manager_t m, valueid_t valueid, char **o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str; - bool result = man->GetValueAsString(*val, &str); - if (*o_value) { - free(*o_value); - } - *o_value = strdup(str.c_str()); - return result; -} - -bool manager_getValueAsRaw(manager_t m, valueid_t valueid, zwbytes_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueAsRaw(*val, &(o_value->data), (uint8_t*)&(o_value->size)); -} - -bool manager_getValueListSelectionAsString(manager_t m, valueid_t valueid, char **o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str; - bool result = man->GetValueListSelection(*val, &str); - if (*o_value) { - free(*o_value); - } - *o_value = strdup(str.c_str()); - return result; -} - -bool manager_getValueListSelectionAsInt32(manager_t m, valueid_t valueid, int32_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueListSelection(*val, o_value); -} - -bool manager_getValueListItems(manager_t m, valueid_t valueid, zwlist_t **o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::vector list; - bool result = man->GetValueListItems(*val, &list); - if (*o_value) { - zwlist_free(*o_value); - } - *o_value = zwlist_copy(list); - return result; -} - -bool manager_getValueFloatPrecision(manager_t m, valueid_t valueid, uint8_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetValueFloatPrecision(*val, o_value); -} - -bool manager_setValueBool(manager_t m, valueid_t valueid, bool value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value); -} - -bool manager_setValueUint8(manager_t m, valueid_t valueid, uint8_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value); -} - -bool manager_setValueFloat(manager_t m, valueid_t valueid, float value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value); -} - -bool manager_setValueInt32(manager_t m, valueid_t valueid, int32_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value); -} - -bool manager_setValueInt16(manager_t m, valueid_t valueid, int16_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value); -} - -bool manager_setValueBytes(manager_t m, valueid_t valueid, zwbytes_t *value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetValue(*val, value->data, (uint8_t)value->size); -} - -bool manager_setValueString(manager_t m, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - return man->SetValue(*val, str); -} - -bool manager_setValueListSelection(manager_t m, valueid_t valueid, const char* selectedItem) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(selectedItem); - return man->SetValueListSelection(*val, str); -} - -bool manager_refreshValue(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->RefreshValue(*val); -} - -void manager_setChangeVerified(manager_t m, valueid_t valueid, bool verify) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - man->SetChangeVerified(*val, verify); -} - -bool manager_getChangeVerified(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetChangeVerified(*val); -} - -bool manager_pressButton(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->PressButton(*val); -} - -bool manager_releaseButton(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->ReleaseButton(*val); -} - -// -// Climate control schedules. -// - -uint8_t manager_getNumSwitchPoints(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetNumSwitchPoints(*val); -} - -bool manager_setSwitchPoint(manager_t m, valueid_t valueid, uint8_t hours, uint8_t minutes, int8_t setback) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSwitchPoint(*val, hours, minutes, setback); -} - -bool manager_removeSwitchPoint(manager_t m, valueid_t valueid, uint8_t hours, uint8_t minutes) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->RemoveSwitchPoint(*val, hours, minutes); -} - -void manager_clearSwitchPoints(manager_t m, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->ClearSwitchPoints(*val); -} - -bool manager_getSwitchPoint(manager_t m, valueid_t valueid, uint8_t idx, uint8_t *o_hours, uint8_t *o_minutes, int8_t *o_setback) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->GetSwitchPoint(*val, idx, o_hours, o_minutes, o_setback); -} - -// -// Switch all. -// - -void manager_switchAllOn(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SwitchAllOn(homeId); -} - -void manager_switchAllOff(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SwitchAllOff(homeId); -} - - -// -// Configuration parameters. -// - -bool manager_setConfigParam(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t param, int32_t value, uint8_t size) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->SetConfigParam(homeId, nodeId, param, value, size); -} - -void manager_requestConfigParam(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t param) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->RequestConfigParam(homeId, nodeId, param); -} - -void manager_requestAllConfigParams(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->RequestAllConfigParams(homeId, nodeId); -} - -// -// Groups. -// - -uint8_t manager_getNumGroups(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNumGroups(homeId, nodeId); -} - -uint32_t manager_getAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t **o_associations) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetAssociations(homeId, nodeId, groupIdx, o_associations); -} - -//TODO uint32_t manager_getAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, instanceassociation_t **o_associations) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// return man->GetAssociations(homeId, nodeId, groupIdx, ...); -// } - -uint8_t manager_getMaxAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetMaxAssociations(homeId, nodeId, groupIdx); -} - -char* manager_getGroupLabel(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetGroupLabel(homeId, nodeId, groupIdx).c_str()); -} - -void manager_addAssociation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t targetNodeId, uint8_t instance) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->AddAssociation(homeId, nodeId, groupIdx, targetNodeId, instance); -} - -void manager_removeAssociation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t targetNodeId, uint8_t instance) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->RemoveAssociation(homeId, nodeId, groupIdx, targetNodeId, instance); -} - -// -// Notifications. -// - -static void manager_notificationHandler(OpenZWave::Notification const* notification, void* userdata) -{ - // Note that OpenZWave will delete the notification object when it thinks we - // are done with it. Probably when we return control to it. - notification_t noti = (notification_t)notification; - goNotificationCB(noti, userdata); -} - -bool manager_addWatcher(manager_t m, void *userdata) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->AddWatcher(manager_notificationHandler, userdata); -} - -bool manager_removeWatcher(manager_t m, void *userdata) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RemoveWatcher(manager_notificationHandler, userdata); -} - -// -// Controller commands. -// - -void manager_resetController(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->ResetController(homeId); -} - -void manager_softReset(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->SoftReset(homeId); -} - -bool manager_cancelControllerCommand(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->CancelControllerCommand(homeId); -} - -// -// Network commands. -// - -void manager_testNetworkNode(manager_t m, uint32_t homeId, uint8_t nodeId, uint32_t count) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->TestNetworkNode(homeId, nodeId, count); -} - -void manager_testNetwork(manager_t m, uint32_t homeId, uint32_t count) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->TestNetwork(homeId, count); -} - -void manager_healNetworkNode(manager_t m, uint32_t homeId, uint8_t nodeId, bool doRR) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->HealNetworkNode(homeId, nodeId, doRR); -} - -void manager_healNetwork(manager_t m, uint32_t homeId, bool doRR) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->HealNetwork(homeId, doRR); -} - -bool manager_addNode(manager_t m, uint32_t homeId, bool doSecurity) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->AddNode(homeId, doSecurity); -} - -bool manager_removeNode(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RemoveNode(homeId); -} - -bool manager_removeFailedNode(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RemoveFailedNode(homeId, nodeId); -} - -bool manager_hasNodeFailed(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->HasNodeFailed(homeId, nodeId); -} - -bool manager_requestNodeNeighborUpdate(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RequestNodeNeighborUpdate(homeId, nodeId); -} - -bool manager_assignReturnRoute(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->AssignReturnRoute(homeId, nodeId); -} - -bool manager_deleteAllReturnRoutes(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->DeleteAllReturnRoutes(homeId, nodeId); -} - -bool manager_sendNodeInformation(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->SendNodeInformation(homeId, nodeId); -} - -bool manager_createNewPrimary(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->CreateNewPrimary(homeId); -} - -bool manager_receiveConfiguration(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->ReceiveConfiguration(homeId); -} - -bool manager_replaceFailedNode(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->ReplaceFailedNode(homeId, nodeId); -} - -bool manager_transferPrimaryRole(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->TransferPrimaryRole(homeId); -} - -bool manager_requestNetworkUpdate(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RequestNetworkUpdate(homeId, nodeId); -} - -bool manager_replicationSend(manager_t m, uint32_t homeId, uint8_t nodeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->ReplicationSend(homeId, nodeId); -} - -bool manager_createButton(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t buttonid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->CreateButton(homeId, nodeId, buttonid); -} - -bool manager_deleteButton(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t buttonid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->DeleteButton(homeId, nodeId, buttonid); -} - -// -// Scene commands. -// - -uint8_t manager_getNumScenes(manager_t m) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetNumScenes(); -} - -uint8_t manager_getAllScenes(manager_t m, uint8_t **sceneIds) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->GetAllScenes(sceneIds); -} - -void manager_removeAllScenes(manager_t m, uint32_t homeId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - man->RemoveAllScenes(homeId); -} - -uint8_t manager_createScene(manager_t m) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->CreateScene(); -} - -bool manager_removeScene(manager_t m, uint8_t sceneId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->RemoveScene(sceneId); -} - -bool manager_addSceneValueBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValue(sceneId, *val, value); -} - -bool manager_addSceneValueUint8(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValue(sceneId, *val, value); -} - -bool manager_addSceneValueFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValue(sceneId, *val, value); -} - -bool manager_addSceneValueInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValue(sceneId, *val, value); -} - -bool manager_addSceneValueInt16(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValue(sceneId, *val, value); -} - -bool manager_addSceneValueString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - return man->AddSceneValue(sceneId, *val, str); -} - -bool manager_addSceneValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - return man->AddSceneValueListSelection(sceneId, *val, str); -} - -bool manager_addSceneValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->AddSceneValueListSelection(sceneId, *val, value); -} - -bool manager_removeSceneValue(manager_t m, uint8_t sceneId, valueid_t valueid) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->RemoveSceneValue(sceneId, *val); -} - -//TODO int manager_sceneGetValues(manager_t m, uint8_t sceneId, valueidlist_t *o_value) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; -// std::vector values; -// int result = man->SceneGetValues(sceneId, *val, &values); -// valueid_copyValueIDList(o_value, values); -// return result; -// } - -bool manager_sceneGetValueAsBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueAsBool(sceneId, *val, o_value); -} - -bool manager_sceneGetValueAsByte(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueAsByte(sceneId, *val, o_value); -} - -bool manager_sceneGetValueAsFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueAsFloat(sceneId, *val, o_value); -} - -bool manager_sceneGetValueAsInt(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueAsInt(sceneId, *val, o_value); -} - -bool manager_sceneGetValueAsShort(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueAsShort(sceneId, *val, o_value); -} - -bool manager_sceneGetValueAsString(manager_t m, uint8_t sceneId, valueid_t valueid, char **o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str; - bool result = man->SceneGetValueAsString(sceneId, *val, &str); - if (*o_value) { - free(*o_value); - } - *o_value = strdup(str.c_str()); - return result; -} - -bool manager_sceneGetValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, char **o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str; - bool result = man->SceneGetValueListSelection(sceneId, *val, &str); - if (*o_value) { - free(*o_value); - } - *o_value = strdup(str.c_str()); - return result; -} - -bool manager_sceneGetValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t *o_value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SceneGetValueListSelection(sceneId, *val, o_value); -} - -bool manager_setSceneValueBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValue(sceneId, *val, value); -} - -bool manager_setSceneValueUint8(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValue(sceneId, *val, value); -} - -bool manager_setSceneValueFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValue(sceneId, *val, value); -} - -bool manager_setSceneValueInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValue(sceneId, *val, value); -} - -bool manager_setSceneValueInt16(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValue(sceneId, *val, value); -} - -bool manager_setSceneValueString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - return man->SetSceneValue(sceneId, *val, str); -} - -bool manager_setSceneValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - std::string str(value); - return man->SetSceneValueListSelection(sceneId, *val, str); -} - -bool manager_setSceneValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - return man->SetSceneValueListSelection(sceneId, *val, value); -} - -char* manager_getSceneLabel(manager_t m, uint8_t sceneId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return strdup(man->GetSceneLabel(sceneId).c_str()); -} - -void manager_setSceneLabel(manager_t m, uint8_t sceneId, const char* value) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - std::string str(value); - man->SetSceneLabel(sceneId, str); -} - -bool manager_sceneExists(manager_t m, uint8_t sceneId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->SceneExists(sceneId); -} - -bool manager_activateScene(manager_t m, uint8_t sceneId) -{ - OpenZWave::Manager *man = (OpenZWave::Manager*)m; - return man->ActivateScene(sceneId); -} - -// -// Statistics retreival interface. -// - -//TODO void manager_getDriverStatistics(manager_t m, uint32_t homeId, driver_driverdata_t *data) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// OpenZWave::Driver::DriverData *driverData = (OpenZWave::Driver::DriverData*)data; -// man->GetDriverStatistics(homeId, driverData); -// } -// -//TODO void manager_getNodeStatistics(manager_t m, uint32_t homeId, uint8_t nodeId, node_nodedata_t *data) -// { -// OpenZWave::Manager *man = (OpenZWave::Manager*)m; -// OpenZWave::Node::NodeData *nodeData = (OpenZWave::Node::NodeData*)data; -// man->GetNodeStatistics(homeId, nodeId, nodeData); -// } diff --git a/gzw_manager.h b/gzw_manager.h deleted file mode 100644 index 4df3f69..0000000 --- a/gzw_manager.h +++ /dev/null @@ -1,284 +0,0 @@ -#ifndef GOOPENZWAVE_MANAGER -#define GOOPENZWAVE_MANAGER - -#include -#include -#include -#include "zwbytes.h" -#include "zwlist.h" -#include "gzw_options.h" -#include "gzw_notification.h" - -#ifdef __cplusplus -extern "C" { -#endif - - // Types. - typedef void* manager_t; - - // - // Construction. - // - - manager_t manager_create(); - manager_t manager_get(); - void manager_destroy(); - char* manager_getVersionAsString(); /*!< C string must be freed. */ - char* manager_getVersionLongAsString(); /*!< C string must be freed. */ - void manager_getVersion(uint16_t *major, uint16_t *minor); - - // - // Configuration. - // - - void manager_writeConfig(manager_t m, uint32_t homeId); - options_t manager_getOptions(manager_t m); - - // - // Drivers. - // - - bool manager_addDriver(manager_t m, const char* controllerPath); - bool manager_removeDriver(manager_t m, const char* controllerPath); - uint8_t manager_getControllerNodeId(manager_t m, uint32_t homeId); - uint8_t manager_getSUCNodeId(manager_t m, uint32_t homeId); - bool manager_isPrimaryController(manager_t m, uint32_t homeId); - bool manager_isStaticUpdateController(manager_t m, uint32_t homeId); - bool manager_isBridgeController(manager_t m, uint32_t homeId); - char* manager_getLibraryVersion(manager_t m, uint32_t homeId); /*!< C string must be freed. */ - char* manager_getLibraryTypeName(manager_t m, uint32_t homeId); /*!< C string must be freed. */ - int32_t manager_getSendQueueCount(manager_t m, uint32_t homeId); - void manager_logDriverStatistics(manager_t m, uint32_t homeId); -//TODO driver_controllerInterface_t manager_getControllerInterfaceType(manager_t m, uint32_t homeId); - char* manager_getControllerPath(manager_t m, uint32_t homeId); /*!< C string must be freed. */ - - // - // Polling Z-Wave devices. - // - - int32_t manager_getPollInterval(manager_t m); - void manager_setPollInterval(manager_t m, int32_t milliseconds, bool intervalBetweenPolls); - bool manager_enablePoll(manager_t m, valueid_t valueid, uint8_t intensity); - bool manager_disablePoll(manager_t m, valueid_t valueid); - bool manager_isPolled(manager_t m, valueid_t valueid); - void manager_setPollIntensity(manager_t m, valueid_t valueid, uint8_t intensity); - uint8_t manager_getPollIntensity(manager_t m, valueid_t valueid); - - // - // Node information. - // - - bool manager_refreshNodeInfo(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_requestNodeState(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_requestNodeDynamic(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeListeningDevice(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeFrequentListeningDevice(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeBeamingDevice(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeRoutingDevice(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeSecurityDevice(manager_t m, uint32_t homeId, uint8_t nodeId); - uint32_t manager_getNodeMaxBaudRate(manager_t m, uint32_t homeId, uint8_t nodeId); - uint8_t manager_getNodeVersion(manager_t m, uint32_t homeId, uint8_t nodeId); - uint8_t manager_getNodeSecurity(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeZWavePlus(manager_t m, uint32_t homeId, uint8_t nodeId); - uint8_t manager_getNodeBasic(manager_t m, uint32_t homeId, uint8_t nodeId); - uint8_t manager_getNodeGeneric(manager_t m, uint32_t homeId, uint8_t nodeId); - uint8_t manager_getNodeSpecific(manager_t m, uint32_t homeId, uint8_t nodeId); - char* manager_getNodeType(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ -//TODO uint32_t manager_getNodeNeighbors(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t **nodeNeighbors); - char* manager_getNodeManufacturerName(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeProductName(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeName(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeLocation(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeManufacturerId(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeProductType(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - char* manager_getNodeProductId(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - void manager_setNodeManufacturerName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* manufacturerName); - void manager_setNodeProductName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* productName); - void manager_setNodeName(manager_t m, uint32_t homeId, uint8_t nodeId, const char* nodeName); - void manager_setNodeLocation(manager_t m, uint32_t homeId, uint8_t nodeId, const char* location); - void manager_setNodeOn(manager_t m, uint32_t homeId, uint8_t nodeId); - void manager_setNodeOff(manager_t m, uint32_t homeId, uint8_t nodeId); - void manager_setNodeLevel(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t level); - bool manager_isNodeInfoReceived(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_getNodeClassInformation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t commandClassId, char **o_name, uint8_t *o_version); - bool manager_isNodeAwake(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_isNodeFailed(manager_t m, uint32_t homeId, uint8_t nodeId); - char* manager_getNodeQueryStage(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - uint16_t manager_getNodeDeviceType(manager_t m, uint32_t homeId, uint8_t nodeId); - char* manager_getNodeDeviceTypeString(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - uint8_t manager_getNodeRole(manager_t m, uint32_t homeId, uint8_t nodeId); - char* manager_getNodeRoleString(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - uint8_t manager_getNodePlusType(manager_t m, uint32_t homeId, uint8_t nodeId); - char* manager_getNodePlusTypeString(manager_t m, uint32_t homeId, uint8_t nodeId); /*!< C string must be freed. */ - - // - // Values. - // - - char* manager_getValueLabel(manager_t m, valueid_t valueid); - void manager_setValueLabel(manager_t m, valueid_t valueid, const char* value); - char* manager_getValueUnits(manager_t m, valueid_t valueid); - void manager_setValueUnits(manager_t m, valueid_t valueid, const char* value); - char* manager_getValueHelp(manager_t m, valueid_t valueid); - void manager_setValueHelp(manager_t m, valueid_t valueid, const char* value); - int32_t manager_getValueMin(manager_t m, valueid_t valueid); - int32_t manager_getValueMax(manager_t m, valueid_t valueid); - bool manager_isValueReadOnly(manager_t m, valueid_t valueid); - bool manager_isValueWriteOnly(manager_t m, valueid_t valueid); - bool manager_isValueSet(manager_t m, valueid_t valueid); - bool manager_isValuePolled(manager_t m, valueid_t valueid); - bool manager_getValueAsBool(manager_t m, valueid_t valueid, bool *o_value); - bool manager_getValueAsByte(manager_t m, valueid_t valueid, uint8_t *o_value); - bool manager_getValueAsFloat(manager_t m, valueid_t valueid, float *o_value); - bool manager_getValueAsInt(manager_t m, valueid_t valueid, int32_t *o_value); - bool manager_getValueAsShort(manager_t m, valueid_t valueid, int16_t *o_value); - bool manager_getValueAsString(manager_t m, valueid_t valueid, char **o_value); - bool manager_getValueAsRaw(manager_t m, valueid_t valueid, zwbytes_t *o_value); - bool manager_getValueListSelectionAsString(manager_t m, valueid_t valueid, char **o_value); - bool manager_getValueListSelectionAsInt32(manager_t m, valueid_t valueid, int32_t *o_value); - bool manager_getValueListItems(manager_t m, valueid_t valueid, zwlist_t **o_value); - bool manager_getValueFloatPrecision(manager_t m, valueid_t valueid, uint8_t *o_value); - bool manager_setValueBool(manager_t m, valueid_t valueid, bool value); - bool manager_setValueUint8(manager_t m, valueid_t valueid, uint8_t value); - bool manager_setValueFloat(manager_t m, valueid_t valueid, float value); - bool manager_setValueInt32(manager_t m, valueid_t valueid, int32_t value); - bool manager_setValueInt16(manager_t m, valueid_t valueid, int16_t value); - bool manager_setValueBytes(manager_t m, valueid_t valueid, zwbytes_t *value); - bool manager_setValueString(manager_t m, valueid_t valueid, const char* value); - bool manager_setValueListSelection(manager_t m, valueid_t valueid, const char* selectedItem); - bool manager_refreshValue(manager_t m, valueid_t valueid); - void manager_setChangeVerified(manager_t m, valueid_t valueid, bool verify); - bool manager_getChangeVerified(manager_t m, valueid_t valueid); - bool manager_pressButton(manager_t m, valueid_t valueid); - bool manager_releaseButton(manager_t m, valueid_t valueid); - - // - // Climate control schedules. - // - - uint8_t manager_getNumSwitchPoints(manager_t m, valueid_t valueid); - bool manager_setSwitchPoint(manager_t m, valueid_t valueid, uint8_t hours, uint8_t minutes, int8_t setback); - bool manager_removeSwitchPoint(manager_t m, valueid_t valueid, uint8_t hours, uint8_t minutes); - void manager_clearSwitchPoints(manager_t m, valueid_t valueid); - bool manager_getSwitchPoint(manager_t m, valueid_t valueid, uint8_t idx, uint8_t *o_hours, uint8_t *o_minutes, int8_t *o_setback); - - // - // Switch all. - // - - void manager_switchAllOn(manager_t m, uint32_t homeId); - void manager_switchAllOff(manager_t m, uint32_t homeId); - - // - // Configuration parameters. - // - - bool manager_setConfigParam(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t param, int32_t value, uint8_t size); - void manager_requestConfigParam(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t param); - void manager_requestAllConfigParams(manager_t m, uint32_t homeId, uint8_t nodeId); - - // - // Groups. - // - - uint8_t manager_getNumGroups(manager_t m, uint32_t homeId, uint8_t nodeId); - uint32_t manager_getAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t **o_associations); -//TODO uint32_t manager_getAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, instanceassociation_t **o_associations); - uint8_t manager_getMaxAssociations(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx); - char* manager_getGroupLabel(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx); - void manager_addAssociation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t targetNodeId, uint8_t instance); - void manager_removeAssociation(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t groupIdx, uint8_t targetNodeId, uint8_t instance); - - // - // Notifications. - // - - extern void goNotificationCB(notification_t notification, void *userdata); /*!< Must be implemented in cgo. */ - bool manager_addWatcher(manager_t m, void *userdata); - bool manager_removeWatcher(manager_t m, void *userdata); - - // - // Controller commands. - // - - void manager_resetController(manager_t m, uint32_t homeId); - void manager_softReset(manager_t m, uint32_t homeId); - bool manager_cancelControllerCommand(manager_t m, uint32_t homeId); - - // - // Network commands. - // - - void manager_testNetworkNode(manager_t m, uint32_t homeId, uint8_t nodeId, uint32_t count); - void manager_testNetwork(manager_t m, uint32_t homeId, uint32_t count); - void manager_healNetworkNode(manager_t m, uint32_t homeId, uint8_t nodeId, bool doRR); - void manager_healNetwork(manager_t m, uint32_t homeId, bool doRR); - bool manager_addNode(manager_t m, uint32_t homeId, bool doSecurity); - bool manager_removeNode(manager_t m, uint32_t homeId); - bool manager_removeFailedNode(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_hasNodeFailed(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_requestNodeNeighborUpdate(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_assignReturnRoute(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_deleteAllReturnRoutes(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_sendNodeInformation(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_createNewPrimary(manager_t m, uint32_t homeId); - bool manager_receiveConfiguration(manager_t m, uint32_t homeId); - bool manager_replaceFailedNode(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_transferPrimaryRole(manager_t m, uint32_t homeId); - bool manager_requestNetworkUpdate(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_replicationSend(manager_t m, uint32_t homeId, uint8_t nodeId); - bool manager_createButton(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t buttonid); - bool manager_deleteButton(manager_t m, uint32_t homeId, uint8_t nodeId, uint8_t buttonid); - - // - // Scene commands. - // - - uint8_t manager_getNumScenes(manager_t m); - uint8_t manager_getAllScenes(manager_t m, uint8_t **sceneIds); - void manager_removeAllScenes(manager_t m, uint32_t homeId); - uint8_t manager_createScene(manager_t m); - bool manager_removeScene(manager_t m, uint8_t sceneId); - bool manager_addSceneValueBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool value); - bool manager_addSceneValueUint8(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t value); - bool manager_addSceneValueFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float value); - bool manager_addSceneValueInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value); - bool manager_addSceneValueInt16(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t value); - bool manager_addSceneValueString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value); - bool manager_addSceneValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value); - bool manager_addSceneValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value); - bool manager_removeSceneValue(manager_t m, uint8_t sceneId, valueid_t valueid); -//TODO int manager_sceneGetValues(manager_t m, uint8_t sceneId, valueidlist_t *o_value); - bool manager_sceneGetValueAsBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool *o_value); - bool manager_sceneGetValueAsByte(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t *o_value); - bool manager_sceneGetValueAsFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float *o_value); - bool manager_sceneGetValueAsInt(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t *o_value); - bool manager_sceneGetValueAsShort(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t *o_value); - bool manager_sceneGetValueAsString(manager_t m, uint8_t sceneId, valueid_t valueid, char **o_value); - bool manager_sceneGetValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, char **o_value); - bool manager_sceneGetValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t *o_value); - bool manager_setSceneValueBool(manager_t m, uint8_t sceneId, valueid_t valueid, bool value); - bool manager_setSceneValueUint8(manager_t m, uint8_t sceneId, valueid_t valueid, uint8_t value); - bool manager_setSceneValueFloat(manager_t m, uint8_t sceneId, valueid_t valueid, float value); - bool manager_setSceneValueInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value); - bool manager_setSceneValueInt16(manager_t m, uint8_t sceneId, valueid_t valueid, int16_t value); - bool manager_setSceneValueString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value); - bool manager_setSceneValueListSelectionString(manager_t m, uint8_t sceneId, valueid_t valueid, const char* value); - bool manager_setSceneValueListSelectionInt32(manager_t m, uint8_t sceneId, valueid_t valueid, int32_t value); - char* manager_getSceneLabel(manager_t m, uint8_t sceneId); - void manager_setSceneLabel(manager_t m, uint8_t sceneId, const char* value); - bool manager_sceneExists(manager_t m, uint8_t sceneId); - bool manager_activateScene(manager_t m, uint8_t sceneId); - - // - // Statistics retreival interface. - // - -//TODO void manager_getDriverStatistics(manager_t m, uint32_t homeId, driver_driverdata_t *data); -//TODO void manager_getNodeStatistics(manager_t m, uint32_t homeId, uint8_t nodeId, node_nodedata_t *data); - -#ifdef __cplusplus -} -#endif - -#endif // define GOOPENZWAVE_MANAGER diff --git a/gzw_notification.cpp b/gzw_notification.cpp deleted file mode 100644 index d9da4c1..0000000 --- a/gzw_notification.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include "gzw_notification.h" -#include -#include - -// -// Public member functions. -// - -notification_type notification_getType(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - notification_type noti_type; - switch (noti->GetType()) { - case OpenZWave::Notification::Type_ValueAdded: - noti_type = notification_type_valueAdded; - break; - case OpenZWave::Notification::Type_ValueRemoved: - noti_type = notification_type_valueRemoved; - break; - case OpenZWave::Notification::Type_ValueChanged: - noti_type = notification_type_valueChanged; - break; - case OpenZWave::Notification::Type_ValueRefreshed: - noti_type = notification_type_valueRefreshed; - break; - case OpenZWave::Notification::Type_Group: - noti_type = notification_type_group; - break; - case OpenZWave::Notification::Type_NodeNew: - noti_type = notification_type_nodeNew; - break; - case OpenZWave::Notification::Type_NodeAdded: - noti_type = notification_type_nodeAdded; - break; - case OpenZWave::Notification::Type_NodeRemoved: - noti_type = notification_type_nodeRemoved; - break; - case OpenZWave::Notification::Type_NodeProtocolInfo: - noti_type = notification_type_nodeProtocolInfo; - break; - case OpenZWave::Notification::Type_NodeNaming: - noti_type = notification_type_nodeNaming; - break; - case OpenZWave::Notification::Type_NodeEvent: - noti_type = notification_type_nodeEvent; - break; - case OpenZWave::Notification::Type_PollingDisabled: - noti_type = notification_type_pollingDisabled; - break; - case OpenZWave::Notification::Type_PollingEnabled: - noti_type = notification_type_pollingEnabled; - break; - case OpenZWave::Notification::Type_SceneEvent: - noti_type = notification_type_sceneEvent; - break; - case OpenZWave::Notification::Type_CreateButton: - noti_type = notification_type_createButton; - break; - case OpenZWave::Notification::Type_DeleteButton: - noti_type = notification_type_deleteButton; - break; - case OpenZWave::Notification::Type_ButtonOn: - noti_type = notification_type_buttonOn; - break; - case OpenZWave::Notification::Type_ButtonOff: - noti_type = notification_type_buttonOff; - break; - case OpenZWave::Notification::Type_DriverReady: - noti_type = notification_type_driverReady; - break; - case OpenZWave::Notification::Type_DriverFailed: - noti_type = notification_type_driverFailed; - break; - case OpenZWave::Notification::Type_DriverReset: - noti_type = notification_type_driverReset; - break; - case OpenZWave::Notification::Type_EssentialNodeQueriesComplete: - noti_type = notification_type_essentialNodeQueriesComplete; - break; - case OpenZWave::Notification::Type_NodeQueriesComplete: - noti_type = notification_type_nodeQueriesComplete; - break; - case OpenZWave::Notification::Type_AwakeNodesQueried: - noti_type = notification_type_awakeNodesQueried; - break; - case OpenZWave::Notification::Type_AllNodesQueriedSomeDead: - noti_type = notification_type_allNodesQueriedSomeDead; - break; - case OpenZWave::Notification::Type_AllNodesQueried: - noti_type = notification_type_allNodesQueried; - break; - case OpenZWave::Notification::Type_Notification: - noti_type = notification_type_notification; - break; - case OpenZWave::Notification::Type_DriverRemoved: - noti_type = notification_type_driverRemoved; - break; - case OpenZWave::Notification::Type_ControllerCommand: - noti_type = notification_type_controllerCommand; - break; - case OpenZWave::Notification::Type_NodeReset: - noti_type = notification_type_nodeReset; - break; - } - return noti_type; -} - -uint32_t notification_getHomeId(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetHomeId(); -} - -uint8_t notification_getNodeId(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetNodeId(); -} - -valueid_t notification_getValueId(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - valueid_t valid = (OpenZWave::ValueID*)&(noti->GetValueID()); - return valid; -} - -uint8_t notification_getGroupIdx(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetGroupIdx(); -} - -uint8_t notification_getEvent(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetEvent(); -} - -uint8_t notification_getButtonId(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetButtonId(); -} - -uint8_t notification_getSceneId(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetSceneId(); -} - -uint8_t notification_getNotification(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetNotification(); -} - -uint8_t notification_getByte(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return noti->GetEvent(); -} - -char* notification_getAsString(notification_t n) -{ - OpenZWave::Notification *noti = (OpenZWave::Notification*)n; - return strdup(noti->GetAsString().c_str()); -} diff --git a/gzw_notification.h b/gzw_notification.h deleted file mode 100644 index 52958bd..0000000 --- a/gzw_notification.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef GOOPENZWAVE_NOTIFICATION -#define GOOPENZWAVE_NOTIFICATION - -#include -#include -#include -#include "gzw_valueid.h" - -#ifdef __cplusplus -extern "C" { -#endif - - // Types. - typedef void* notification_t; - - // enum notification_type - typedef enum { - notification_type_valueAdded = 0, - notification_type_valueRemoved, - notification_type_valueChanged, - notification_type_valueRefreshed, - notification_type_group, - notification_type_nodeNew, - notification_type_nodeAdded, - notification_type_nodeRemoved, - notification_type_nodeProtocolInfo, - notification_type_nodeNaming, - notification_type_nodeEvent, - notification_type_pollingDisabled, - notification_type_pollingEnabled, - notification_type_sceneEvent, - notification_type_createButton, - notification_type_deleteButton, - notification_type_buttonOn, - notification_type_buttonOff, - notification_type_driverReady, - notification_type_driverFailed, - notification_type_driverReset, - notification_type_essentialNodeQueriesComplete, - notification_type_nodeQueriesComplete, - notification_type_awakeNodesQueried, - notification_type_allNodesQueriedSomeDead, - notification_type_allNodesQueried, - notification_type_notification, - notification_type_driverRemoved, - notification_type_controllerCommand, - notification_type_nodeReset - } notification_type; - - // enum notification_code - typedef enum { - notification_code_msgComplete = 0, - notification_code_timeout, - notification_code_noOperation, - notification_code_awake, - notification_code_sleep, - notification_code_dead, - notification_code_alive - } notification_code; - - // Public member functions. - notification_type notification_getType(notification_t n); - uint32_t notification_getHomeId(notification_t n); - uint8_t notification_getNodeId(notification_t n); - valueid_t notification_getValueId(notification_t n); - uint8_t notification_getGroupIdx(notification_t n); - uint8_t notification_getEvent(notification_t n); - uint8_t notification_getButtonId(notification_t n); - uint8_t notification_getSceneId(notification_t n); - uint8_t notification_getNotification(notification_t n); - uint8_t notification_getByte(notification_t n); - char* notification_getAsString(notification_t n); - -#ifdef __cplusplus -} -#endif - -#endif // define GOOPENZWAVE_NOTIFICATION diff --git a/gzw_options.cpp b/gzw_options.cpp deleted file mode 100644 index cfbb1ac..0000000 --- a/gzw_options.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "gzw_options.h" -#include -#include -#include - -// -// Static public member functions. -// - -options_t options_create(const char* configPath, const char* userPath, const char* commandLine) -{ - OpenZWave::Options *opts = OpenZWave::Options::Create(configPath, userPath, commandLine); - return (options_t)opts; -} - -bool options_destroy() -{ - return OpenZWave::Options::Destroy(); -} - -options_t options_get() -{ - OpenZWave::Options *opts = OpenZWave::Options::Get(); - return (options_t)opts; -} - -// -// Public member functions. -// - -bool options_lock(options_t o) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - return opts->Lock(); -} - -bool options_addOptionBool(options_t o, const char* name, bool value) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - return opts->AddOptionBool(inStr, value); -} - -bool options_addOptionInt(options_t o, const char* name, int32_t value) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - return opts->AddOptionInt(inStr, value); -} - -bool options_addOptionLogLevel(options_t o, const char* name, loglevel_t level) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - return opts->AddOptionInt(inStr, loglevel_toLogLevel(level)); -} - -bool options_addOptionString(options_t o, const char* name, const char* value, bool append) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - std::string _value(value); - return opts->AddOptionString(inStr, _value, append); -} - -bool options_getOptionAsBool(options_t o, const char* name, bool* o_value) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - return opts->GetOptionAsBool(inStr, o_value); -} - -bool options_getOptionAsInt(options_t o, const char* name, int32_t* o_value) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - return opts->GetOptionAsInt(inStr, o_value); -} - -bool options_getOptionAsString(options_t o, const char* name, char **o_value) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - std::string inStr(name); - std::string str; - bool result = opts->GetOptionAsString(inStr, &str); - if (*o_value) { - free(*o_value); - } - *o_value = strdup(str.c_str()); - return result; -} - -//TODO OptionType options_getOptionType(string const &inStr); - -bool options_areLocked(options_t o) -{ - OpenZWave::Options *opts = (OpenZWave::Options*)o; - return opts->AreLocked(); -} diff --git a/gzw_options.h b/gzw_options.h deleted file mode 100644 index 8ca2fae..0000000 --- a/gzw_options.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GOOPENZWAVE_OPTIONS -#define GOOPENZWAVE_OPTIONS - -#include -#include -#include -#include "gzw_loglevel.h" - -#ifdef __cplusplus -extern "C" { -#endif - - // Types. - typedef void* options_t; - - // Static public member functions. - options_t options_create(const char* configPath, const char* userPath, const char* commandLine); - bool options_destroy(); - options_t options_get(); - - // Public member functions. - bool options_lock(options_t o); - bool options_addOptionBool(options_t o, const char* name, bool value); - bool options_addOptionInt(options_t o, const char* name, int32_t value); - bool options_addOptionLogLevel(options_t o, const char* name, loglevel_t level); - bool options_addOptionString(options_t o, const char* name, const char* value, bool append); - bool options_getOptionAsBool(options_t o, const char* name, bool* o_value); - bool options_getOptionAsInt(options_t o, const char* name, int32_t* o_value); - bool options_getOptionAsString(options_t o, const char* name, char **o_value); -//TODO OptionType options_getOptionType(string const &_name); - bool options_areLocked(options_t o); - -#ifdef __cplusplus -} -#endif - -#endif // define GOOPENZWAVE_OPTIONS diff --git a/gzw_valueid.cpp b/gzw_valueid.cpp deleted file mode 100644 index 7907caa..0000000 --- a/gzw_valueid.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "gzw_valueid.h" -#include - -// -// Public member functions. -// - -uint32_t valueid_getHomeId(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetHomeId(); -} - -uint8_t valueid_getNodeId(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetNodeId(); -} - -valueid_genre valueid_getGenre(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - valueid_genre val_genre; - switch (valid->GetGenre()) { - case OpenZWave::ValueID::ValueGenre_Basic: - val_genre = valueid_genre_basic; - break; - case OpenZWave::ValueID::ValueGenre_User: - val_genre = valueid_genre_user; - break; - case OpenZWave::ValueID::ValueGenre_Config: - val_genre = valueid_genre_config; - break; - case OpenZWave::ValueID::ValueGenre_System: - val_genre = valueid_genre_system; - break; - case OpenZWave::ValueID::ValueGenre_Count: - val_genre = valueid_genre_count; - break; - } - return val_genre; -} - -uint8_t valueid_getCommandClassId(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetCommandClassId(); -} - -uint8_t valueid_getInstance(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetInstance(); -} - -uint8_t valueid_getIndex(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetIndex(); -} - -valueid_type valueid_getType(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - valueid_type val_type; - switch (valid->GetType()) { - case OpenZWave::ValueID::ValueType_Bool: - val_type = valueid_type_bool; - break; - case OpenZWave::ValueID::ValueType_Byte: - val_type = valueid_type_byte; - break; - case OpenZWave::ValueID::ValueType_Decimal: - val_type = valueid_type_decimal; - break; - case OpenZWave::ValueID::ValueType_Int: - val_type = valueid_type_int; - break; - case OpenZWave::ValueID::ValueType_List: - val_type = valueid_type_list; - break; - case OpenZWave::ValueID::ValueType_Schedule: - val_type = valueid_type_schedule; - break; - case OpenZWave::ValueID::ValueType_Short: - val_type = valueid_type_short; - break; - case OpenZWave::ValueID::ValueType_String: - val_type = valueid_type_string; - break; - case OpenZWave::ValueID::ValueType_Button: - val_type = valueid_type_button; - break; - case OpenZWave::ValueID::ValueType_Raw: - val_type = valueid_type_raw; - break; - // case OpenZWave::ValueID::ValueType_Max: - // val_type = valueid_type_max; - // break; - } - return val_type; -} - -uint64_t valueid_getId(valueid_t v) -{ - OpenZWave::ValueID *valid = (OpenZWave::ValueID*)v; - return valid->GetId(); -} - -// -// Go helper functions. -// - -valueid_t valueid_create(uint32_t homeId, uint64_t id) -{ - OpenZWave::ValueID *valueid = new OpenZWave::ValueID(homeId, (uint64)id); - return (valueid_t)valueid; -} - -void valueid_free(valueid_t valueid) -{ - OpenZWave::ValueID *val = (OpenZWave::ValueID*)valueid; - delete val; -} diff --git a/gzw_valueid.h b/gzw_valueid.h deleted file mode 100644 index 9873d73..0000000 --- a/gzw_valueid.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef GOOPENZWAVE_VALUEID -#define GOOPENZWAVE_VALUEID - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - // Types. - typedef void* valueid_t; - - // enum valueid_genre - typedef enum { - valueid_genre_basic = 0, - valueid_genre_user, - valueid_genre_config, - valueid_genre_system, - valueid_genre_count - } valueid_genre; - - // enum valueid_type - typedef enum { - valueid_type_bool = 0, - valueid_type_byte, - valueid_type_decimal, - valueid_type_int, - valueid_type_list, - valueid_type_schedule, - valueid_type_short, - valueid_type_string, - valueid_type_button, - valueid_type_raw, - valueid_type_max = valueid_type_raw - } valueid_type; - - // Public member functions. - uint32_t valueid_getHomeId(valueid_t v); - uint8_t valueid_getNodeId(valueid_t v); - valueid_genre valueid_getGenre(valueid_t v); - uint8_t valueid_getCommandClassId(valueid_t v); - uint8_t valueid_getInstance(valueid_t v); - uint8_t valueid_getIndex(valueid_t v); - valueid_type valueid_getType(valueid_t v); - uint64_t valueid_getId(valueid_t v); - - // Go helper functions. - valueid_t valueid_create(uint32_t homeId, uint64_t id); - void valueid_free(valueid_t valueid); - -#ifdef __cplusplus -} -#endif - -#endif // define GOOPENZWAVE_VALUEID diff --git a/loglevel.go b/loglevel.go deleted file mode 100644 index 6762b7f..0000000 --- a/loglevel.go +++ /dev/null @@ -1,22 +0,0 @@ -package goopenzwave - -// #include "gzw_loglevel.h" -// #include -import "C" - -type LogLevel int32 - -const ( - LogLevelInvalid = LogLevel(C.loglevel_invalid) - LogLevelNone = LogLevel(C.loglevel_none) - LogLevelAlways = LogLevel(C.loglevel_always) - LogLevelFatal = LogLevel(C.loglevel_fatal) - LogLevelError = LogLevel(C.loglevel_error) - LogLevelWarning = LogLevel(C.loglevel_warning) - LogLevelAlert = LogLevel(C.loglevel_alert) - LogLevelInfo = LogLevel(C.loglevel_info) - LogLevelDetail = LogLevel(C.loglevel_detail) - LogLevelDebug = LogLevel(C.loglevel_debug) - LogLevelStreamdetail = LogLevel(C.loglevel_streamdetail) - LogLevelInternal = LogLevel(C.loglevel_internal) -) diff --git a/manager.go b/manager.go index 1359139..d844153 100644 --- a/manager.go +++ b/manager.go @@ -1,72 +1,73 @@ package goopenzwave -// #include "gzw_manager.h" -// #include "gzw_notification.h" +// #cgo pkg-config: libopenzwave +// #include "manager_wrap.h" // #include import "C" import ( - "fmt" "unsafe" ) var ( - cmanager C.manager_t + watchers []func(notification Notification) ) -// createManager creates the Manager singleton object. The Manager provides the -// public interface to OpenZWave, exposing all the functionality required to add -// Z-Wave support to an application. There can be only one Manager in an -// OpenZWave application. An Options object must be created and Locked first, -// otherwise the call to Manager::Create will fail. Once the Manager has been -// created, call AddWatcher to install a notification callback handler, and then -// call the AddDriver method for each attached PC Z-Wave controller in turn. -func createManager() error { - cmanager = C.manager_create() - if cmanager == nil { - return fmt.Errorf("libopenzwave returned NULL pointer") - } - return nil +// ManagerCreate creates the Manager singleton object. The Manager provides the public interface to OpenZWave, exposing all the functionality required to add Z-Wave support to an application. There can be only one Manager in an OpenZWave application. An Options object must be created and Locked first, otherwise the call to Manager::Create will fail. Once the Manager has been created, call AddWatcher to install a notification callback handler, and then call the AddDriver method for each attached PC Z-Wave controller in turn. +// Wraps `Manager* OpenZWave::Manager::Create(...)`. +func ManagerCreate() { + C.manager_create() +} + +func ManagerAddWatcher(watcher func(notification Notification)) { + // Manager::Get()->AddWatcher( OnNotification, NULL ); + watchers = append(watchers, watcher) +} + +func ManagerAddDriver(port string) { + // Manager::Get()->AddDriver( port ); + cport := C.CString(port) + defer C.free(unsafe.Pointer(cport)) + _ = C.manager_add_driver(cport) } -// getManager gets a pointer to the Manager object. -func getManager() C.manager_t { - return cmanager +func ManagerRemoveDriver(port string) { + // Manager::Get()->RemoveDriver( port ); + cport := C.CString(port) + defer C.free(unsafe.Pointer(cport)) + _ = C.manager_remove_driver(cport) } -// destroyManager deletes the Manager and cleans up any associated objects. -func destroyManager() { +func ManagerDestroy() { + // Manager::Get()->RemoveWatcher( OnNotification, NULL ); + // Manager::Destroy(); C.manager_destroy() } -// GetVersionAsString returns the Version Number of OZW as a string. -func GetVersionAsString() string { - cstr := C.manager_getVersionAsString() +func ManagerVersionString() string { + cstr := C.manager_get_version_as_string() defer C.free(unsafe.Pointer(cstr)) return C.GoString(cstr) } -// GetVersionLongAsString returns the Version Number including Git commit of OZW -// as a string. -func GetVersionLongAsString() string { - cstr := C.manager_getVersionLongAsString() +func ManagerVersionLongString() string { + cstr := C.manager_get_version_long_as_string() defer C.free(unsafe.Pointer(cstr)) return C.GoString(cstr) } -// Version represents the OpenZWave library version as major and minor integers. -type Version struct { - Major int - Minor int +func ManagerVersion() (major, minor uint16) { + version := C.manager_get_version() + return uint16((version >> 16) & 0x00ff), uint16(version & 0x00ff) } -// GetVersion returns the Version Number as the Version Struct (Only Major/Minor -// returned). -func GetVersion() Version { - var cMajor C.uint16_t - var cMinor C.uint16_t - C.manager_getVersion(&cMajor, &cMinor) - return Version{ - Major: int(cMajor), - Minor: int(cMinor), +// goNotificationWatcher called by the C++ OpenZWave library when there is a new notification. +//export goNotificationWatcher +func goNotificationWatcher(n_type uint8, n_vhomeid, n_vid0, n_vid1 uint32, n_byte, n_event, n_command, n_useralerttype uint8, n_comport *C.char, n_comport_size C.int) { + // This function is called by OpenZWave (via a C wrapper) when a + // notification is available. + comport := C.GoStringN(n_comport, n_comport_size) + notification := createNotification(n_type, n_vhomeid, n_vid0, n_vid1, n_byte, n_event, n_command, n_useralerttype, comport) + for _, watcher := range watchers { + watcher(notification) } } diff --git a/manager_wrap.cpp b/manager_wrap.cpp new file mode 100644 index 0000000..704beae --- /dev/null +++ b/manager_wrap.cpp @@ -0,0 +1,89 @@ +#include "manager_wrap.h" +#include "openzwave/Manager.h" +#include "openzwave/Notification.h" +#include "openzwave/value_classes/ValueID.h" +#include "_cgo_export.h" // defines goNotificationWatcher +#ifndef GO_COMPLIER + // void goNotificationWatcher(uint8_t, uint32_t, uint32_t, uint32_t, uint8_t, uint8_t, uint8_t, uint8_t, char*, long); + // goNotificationWatcher(unsigned char, unsigned int, unsigned int, unsigned int, unsigned char, unsigned char, unsigned char, unsigned char, char*, unsigned long) +#endif + +static void manager_notificationWatcher(OpenZWave::Notification const* notification, void* userdata); + +void manager_create() +{ + OpenZWave::Manager::Create(); + OpenZWave::Manager::Get()->AddWatcher(manager_notificationWatcher, nullptr); +} + +bool manager_add_driver(const char* port) +{ + return OpenZWave::Manager::Get()->AddDriver(port); +} + +bool manager_remove_driver(const char* port) +{ + return OpenZWave::Manager::Get()->RemoveDriver(port); +} + +void manager_destroy() +{ + OpenZWave::Manager::Get()->RemoveWatcher(manager_notificationWatcher, nullptr); + OpenZWave::Manager::Destroy(); +} + +// char* manager_strdup(const char *src) +// { +// char *dst = static_cast(malloc(strlen(src) + 1)); // Space for length plus nul +// if (dst == nullptr) return nullptr; // No memory +// strcpy(dst, src); // Copy the characters +// return dst; // Return the new string +// } + +char* manager_get_version_as_string() +{ + std::string str = OpenZWave::Manager::Get()->getVersionAsString(); + return strdup(str.c_str()); +} + +char* manager_get_version_long_as_string() +{ + std::string str = OpenZWave::Manager::Get()->getVersionLongAsString(); + return strdup(str.c_str()); +} + +uint32_t manager_get_version() +{ + return OpenZWave::Manager::Get()->getVersion()._v; +} + +static void manager_notificationWatcher(OpenZWave::Notification const* n, void*) +{ + // uint8 groupidx = n->GetGroupIdx(); // Get the index of the association group that has been changed. Only valid in Notification::Type_Group notifications. + // uint8 event = n->GetEvent(); // Get the event value of a notification. Only valid in Notification::Type_NodeEvent and Notification::Type_ControllerCommand notifications. + // uint8 buttonid = n->GetButtonId(); // Get the button id of a notification. Only valid in Notification::Type_CreateButton, Notification::Type_DeleteButton, Notification::Type_ButtonOn and Notification::Type_ButtonOff notifications. + // uint8 notification = n->GetNotification(); // Get the notification code from a notification. Only valid for Notification::Type_Notification or Notification::Type_ControllerCommand notifications. + // uint8 command = n->GetCommand(); // Get the (controller) command from a notification. Only valid for Notification::Type_ControllerCommand notifications. + // uint8 byteval = n->GetByte(); // Helper function to simplify wrapping the notification class. Should not normally need to be called. + // uint8 retry = n->GetRetry(); // Helper function to return the Timeout to wait for. Only valid for Notification::Type_UserAlerts - Notification::Alert_ApplicationStatus_Retry. + // OpenZWave::Notification::UserAlertNotification uan = n->GetUserAlertType(); // Retrieve the User Alert Type Enum to determine what this message is about. + // std::string comport = n->GetComPort(); // Return the Comport associated with the DriverFailed Message. + + uint8_t n_type = static_cast(n->GetType()); + uint32_t n_vhomeid = n->GetValueID().GetHomeId(); + uint32_t n_vid0 = static_cast(n->GetValueID().GetId() & 0xFFFFFFFF); + uint32_t n_vid1 = static_cast((n->GetValueID().GetId() >> 32) & 0xFFFFFFFF); + uint8 n_byte = n->GetByte(); + uint8 n_event = 0; + if ((OpenZWave::Notification::Type_NodeEvent == n_type) || (OpenZWave::Notification::Type_ControllerCommand == n_type)) { + n_event = n->GetEvent(); + } + uint8 n_command = 0; + if (OpenZWave::Notification::Type_ControllerCommand == n_type) { + n_command = n->GetCommand(); + } + uint8_t n_useralerttype = static_cast(n->GetUserAlertType()); + std::string n_comport = n->GetComPort(); + + goNotificationWatcher(n_type, n_vhomeid, n_vid0, n_vid1, n_byte, n_event, n_command, n_useralerttype, const_cast(n_comport.c_str()), static_cast(n_comport.size())); +} diff --git a/manager_wrap.h b/manager_wrap.h new file mode 100644 index 0000000..9c1daba --- /dev/null +++ b/manager_wrap.h @@ -0,0 +1,23 @@ +#ifndef GOOPENZWAVE_MANAGER_WRAP_H +#define GOOPENZWAVE_MANAGER_WRAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void manager_create(); +bool manager_add_driver(const char* port); +bool manager_remove_driver(const char* port); +void manager_destroy(); +char* manager_get_version_as_string(); +char* manager_get_version_long_as_string(); +uint32_t manager_get_version(); /* major << 16 | minor */ + +#ifdef __cplusplus +} +#endif + +#endif // GOOPENZWAVE_MANAGER_WRAP_H diff --git a/network.go b/network.go deleted file mode 100644 index 15a0306..0000000 --- a/network.go +++ /dev/null @@ -1,173 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" - -// TestNetworkNode tests the network node. -// -// Sends a series of messages to a network node for testing network reliability. -func TestNetworkNode(homeID uint32, nodeID uint8, count uint32) { - C.manager_testNetworkNode(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint32_t(count)) -} - -// TestNetwork tests the network. -// -// Sends a series of messages to every node on the network for testing network -// reliability. -func TestNetwork(homeID uint32, count uint32) { - C.manager_testNetwork(cmanager, C.uint32_t(homeID), C.uint32_t(count)) -} - -// HealNetworkNode heals a network node by requesting that the node rediscovers -// their neighbors. -// -// Sends a ControllerCommand_RequestNodeNeighborUpdate to the node. -func HealNetworkNode(homeID uint32, nodeID uint8, doRR bool) { - C.manager_healNetworkNode(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.bool(doRR)) -} - -// HealNetwork heals a network by requesting node's rediscover their neighbors. -// -// Sends a ControllerCommand_RequestNodeNeighborUpdate to every node. Can take a -// while on larger networks. -func HealNetwork(homeID uint32, doRR bool) { - C.manager_healNetwork(cmanager, C.uint32_t(homeID), C.bool(doRR)) -} - -// AddNode starts the Inclusion Process to add a Node to the Network. It will -// return true if the command was sent to the controller successfully. -// -// The Status of the Node Inclusion is communicated via Notifications. -// Specifically, you should monitor ControllerCommand Notifications. -func AddNode(homeID uint32, doSecurity bool) bool { - return bool(C.manager_addNode(cmanager, C.uint32_t(homeID), C.bool(doSecurity))) -} - -// RemoveNode removes a Device from the Z-Wave Network. It will return true if -// the command was sent to the controller successfully. -// -// The Status of the Node Removal is communicated via Notifications. -// Specifically, you should monitor ControllerCommand Notifications. -func RemoveNode(homeID uint32) bool { - return bool(C.manager_removeNode(cmanager, C.uint32_t(homeID))) -} - -// RemoveFailedNode removes a Failed Device from the Z-Wave Network. It will -// return true if the command was sent to the controller successfully. -// -// This Command will remove a failed node from the network. The Node should be -// on the Controllers Failed Node List, otherwise this command will fail. You -// can use the HasNodeFailed function below to test if the Controller believes -// the Node has Failed. The Status of the Node Removal is communicated via -// Notifications. Specifically, you should monitor ControllerCommand -// Notifications. -func RemoveFailedNode(homeID uint32, nodeID uint8) bool { - return bool(C.manager_removeFailedNode(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// HasNodeFailed checks if the Controller Believes a Node has Failed. The result -// is then communicated via a Notification. It will return true if the command -// was sent to the controller successfully. -// -// This is different from the IsNodeFailed call in that we test the Controllers -// Failed Node List, whereas the IsNodeFailed is testing our list of Failed -// Nodes, which might be different. The Results will be communicated via -// Notifications. Specifically, you should monitor the ControllerCommand -// notifications. -func HasNodeFailed(homeID uint32, nodeID uint8) bool { - return bool(C.manager_hasNodeFailed(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// RequestNodeNeighborUpdate will ask a Node to update its Neighbor Tables. It -// will return true if the command was sent to the controller successfully. -// -// This command will ask a Node to update its Neighbor Tables. -func RequestNodeNeighborUpdate(homeID uint32, nodeID uint8) bool { - return bool(C.manager_requestNodeNeighborUpdate(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// AssignReturnRoute will ask a Node to update its update its Return Route to -// the Controller. It will return true if the command was sent to the controller -// successfully. -func AssignReturnRoute(homeID uint32, nodeID uint8) bool { - return bool(C.manager_assignReturnRoute(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// DeleteAllReturnRoutes will ask a Node to delete all Return Routes. It will -// return true if the command was sent to the controller successfully. -// -// This command will ask a Node to delete all its return routes, and will -// rediscover when needed. -func DeleteAllReturnRoutes(homeID uint32, nodeID uint8) bool { - return bool(C.manager_deleteAllReturnRoutes(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// SendNodeInformation sends a NIF frame from the Controller to a Node. It will -// return true if the command was sent to the controller successfully. -// -// This command send a NIF frame from the Controller to a Node. -func SendNodeInformation(homeID uint32, nodeID uint8) bool { - return bool(C.manager_sendNodeInformation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// CreateNewPrimary will create a new primary controller when old primary fails. -// Requires SUC. It will return true if the command was sent to the controller -// successfully. -// -// This command Creates a new Primary Controller when the Old Primary has -// Failed. -// -// Requires a SUC on the network to function. -func CreateNewPrimary(homeID uint32) bool { - return bool(C.manager_createNewPrimary(cmanager, C.uint32_t(homeID))) -} - -// ReceiveConfiguration will receive network configuration information from -// the primary controller. Requires secondary. This command prepares the -// controller to recieve Network Configuration from a Secondary Controller. It -// will return true if the command was sent to the controller successfully. -func ReceiveConfiguration(homeID uint32) bool { - return bool(C.manager_receiveConfiguration(cmanager, C.uint32_t(homeID))) -} - -// ReplaceFailedNode will replace a failed device with another. If the node is -// not in the controller's failed nodes list, or the node responds, this command -// will fail. You can check if a Node is in the Controllers Failed node list by -// using the HasNodeFailed method. It will return true if the command was sent -// to the controller successfully. -func ReplaceFailedNode(homeID uint32, nodeID uint8) bool { - return bool(C.manager_replaceFailedNode(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// TransferPrimaryRole adds a new controller to the network and make it the -// primary. The existing primary will become a secondary controller. It will -// return true if the command was sent to the controller successfully. -func TransferPrimaryRole(homeID uint32) bool { - return bool(C.manager_transferPrimaryRole(cmanager, C.uint32_t(homeID))) -} - -// RequestNetworkUpdate updates the controller with network information from the -// SUC/SIS. It will return true if the command was sent to the controller -// successfully. -func RequestNetworkUpdate(homeID uint32, nodeID uint8) bool { - return bool(C.manager_requestNetworkUpdate(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// ReplicationSend sends information from primary to secondary. It will return -// true if the command was sent to the controller successfully. -func ReplicationSend(homeID uint32, nodeID uint8) bool { - return bool(C.manager_replicationSend(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// CreateButton create a handheld button id. It will return true if the command -// was sent to the controller successfully. -func CreateButton(homeID uint32, nodeID uint8, buttonID uint8) bool { - return bool(C.manager_createButton(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(buttonID))) -} - -// DeleteButton deletes a handheld button id. It will return true if the command -// was sent to the controller successfully. -func DeleteButton(homeID uint32, nodeID uint8, buttonID uint8) bool { - return bool(C.manager_deleteButton(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(buttonID))) -} diff --git a/node.go b/node.go index 53398a8..b0ef183 100644 --- a/node.go +++ b/node.go @@ -1,256 +1,419 @@ package goopenzwave -import ( - "fmt" -) - -// Node contains all necessary information for a Node from the OpenZWave -// library. Create a new Node by using the `NewNode` function with the HomeID -// and NodeID as supplied from a Notification. -type Node struct { - HomeID uint32 - NodeID uint8 -} - -// NewNode will create a new Node object filled with the data available from the -// Manager based on the homeID and nodeID. -func NewNode(homeID uint32, nodeID uint8) *Node { - return &Node{ - HomeID: homeID, - NodeID: nodeID, - } -} - -// String will return a string containing some useful information about the -// Node. -func (n *Node) String() string { - return fmt.Sprintf("Node{HomeID: 0x%x, NodeID: %d, BasicType: %d, "+ - "GenericType: %d, SpecificType: %d, NodeType: %q, "+ - "ManufacturerName: %q, ProductName: %q, NodeName: %q, Location: %q, "+ - "ManufacturerID: %q, ProductType: %q, ProductID: %q}", - n.HomeID, - n.NodeID, - GetNodeBasicType(n.HomeID, n.NodeID), - GetNodeGenericType(n.HomeID, n.NodeID), - GetNodeSpecificType(n.HomeID, n.NodeID), - GetNodeType(n.HomeID, n.NodeID), - GetNodeManufacturerName(n.HomeID, n.NodeID), - GetNodeProductName(n.HomeID, n.NodeID), - GetNodeName(n.HomeID, n.NodeID), - GetNodeLocation(n.HomeID, n.NodeID), - GetNodeManufacturerID(n.HomeID, n.NodeID), - GetNodeProductType(n.HomeID, n.NodeID), - GetNodeProductID(n.HomeID, n.NodeID), - ) -} - -// RefeshInfo Trigger the fetching of fixed data about a node. Causes the node's data to be obtained from the Z-Wave network in the same way as if it had just been added. This method would normally be called automatically by OpenZWave, but if you know that a node has been changed, calling this method will force a refresh of all of the data held by the library. This can be especially useful for devices that were asleep when the application was first run. This is the same as the query state starting from the beginning. -func (n *Node) RefeshInfo() bool { - return RefreshNodeInfo(n.HomeID, n.NodeID) -} - -// RequestState Trigger the fetching of dynamic value data for a node. Causes the node's values to be requested from the Z-Wave network. This is the same as the query state starting from the associations state. -func (n *Node) RequestState() bool { - return RequestNodeState(n.HomeID, n.NodeID) -} - -// RequestDynamic Trigger the fetching of just the dynamic value data for a node. Causes the node's values to be requested from the Z-Wave network. This is the same as the query state starting from the dynamic state. -func (n *Node) RequestDynamic() bool { - return RequestNodeDynamic(n.HomeID, n.NodeID) -} - -// IsListeningDevice Get whether the node is a listening device that does not go to sleep. -func (n *Node) IsListeningDevice() bool { - return IsNodeListeningDevice(n.HomeID, n.NodeID) -} - -// IsFrequentListeningDevice Get whether the node is a frequent listening device that goes to sleep but can be woken up by a beam. Useful to determine node and controller consistency. -func (n *Node) IsFrequentListeningDevice() bool { - return IsNodeFrequentListeningDevice(n.HomeID, n.NodeID) -} - -// IsBeamingDevice Get whether the node is a beam capable device. -func (n *Node) IsBeamingDevice() bool { - return IsNodeBeamingDevice(n.HomeID, n.NodeID) -} - -// IsRoutingDevice Get whether the node is a routing device that passes messages to other nodes. -func (n *Node) IsRoutingDevice() bool { - return IsNodeRoutingDevice(n.HomeID, n.NodeID) -} - -// IsSecurityDevice Get the security attribute for a node. True if node supports security features. -func (n *Node) IsSecurityDevice() bool { - return IsNodeSecurityDevice(n.HomeID, n.NodeID) -} - -// GetMaxBaudRate Get the maximum baud rate of a node's communications. -func (n *Node) GetMaxBaudRate() uint32 { - return GetNodeMaxBaudRate(n.HomeID, n.NodeID) -} - -// GetVersion Get the version number of a node. -func (n *Node) GetVersion() uint8 { - return GetNodeVersion(n.HomeID, n.NodeID) -} - -// GetSecurity Get the security byte of a node. -func (n *Node) GetSecurity() uint8 { - return GetNodeSecurity(n.HomeID, n.NodeID) -} - -// IsZWavePlus Is this a ZWave+ Supported Node? -func (n *Node) IsZWavePlus() bool { - return IsNodeZWavePlus(n.HomeID, n.NodeID) -} - -// GetBasicType Get the basic type of a node. -func (n *Node) GetBasicType() uint8 { - return GetNodeBasicType(n.HomeID, n.NodeID) -} - -// GetGenericType Get the generic type of a node. -func (n *Node) GetGenericType() uint8 { - return GetNodeGenericType(n.HomeID, n.NodeID) -} - -// GetSpecificType Get the specific type of a node. -func (n *Node) GetSpecificType() uint8 { - return GetNodeSpecificType(n.HomeID, n.NodeID) -} - -// GetType Get a human-readable label describing the node The label is taken from the Z-Wave specific, generic or basic type, depending on which of those values are specified by the node. -func (n *Node) GetType() string { - return GetNodeType(n.HomeID, n.NodeID) -} - -// TODO: implement node.GetNeighbors -// GetNeighbors Get the bitmap of this node's neighbors. -// func (n *Node) GetNeighbors() bool -// return GetNodeNeighbors(n.HomeID, n.NodeID) -// } - -// GetManufacturerName Get the manufacturer name of a device The manufacturer name would normally be handled by the Manufacturer Specific commmand class, taking the manufacturer ID reported by the device and using it to look up the name from the manufacturer_specific.xml file in the OpenZWave config folder. However, there are some devices that do not support the command class, so to enable the user to manually set the name, it is stored with the node data and accessed via this method rather than being reported via a command class Value object. -func (n *Node) GetManufacturerName() string { - return GetNodeManufacturerName(n.HomeID, n.NodeID) -} - -// GetProductName Get the product name of a device The product name would normally be handled by the Manufacturer Specific commmand class, taking the product Type and ID reported by the device and using it to look up the name from the manufacturer_specific.xml file in the OpenZWave config folder. However, there are some devices that do not support the command class, so to enable the user to manually set the name, it is stored with the node data and accessed via this method rather than being reported via a command class Value object. -func (n *Node) GetProductName() string { - return GetNodeProductName(n.HomeID, n.NodeID) -} - -// GetName Get the name of a node The node name is a user-editable label for the node that would normally be handled by the Node Naming commmand class, but many devices do not support it. So that a node can always be named, OpenZWave stores it with the node data, and provides access through this method and SetNodeName, rather than reporting it via a command class Value object. The maximum length of a node name is 16 characters. -func (n *Node) GetName() string { - return GetNodeName(n.HomeID, n.NodeID) -} - -// GetLocation Get the location of a node The node location is a user-editable string that would normally be handled by the Node Naming commmand class, but many devices do not support it. So that a node can always report its location, OpenZWave stores it with the node data, and provides access through this method and SetNodeLocation, rather than reporting it via a command class Value object. -func (n *Node) GetLocation() string { - return GetNodeLocation(n.HomeID, n.NodeID) -} - -// GetManufacturerID Get the manufacturer ID of a device The manufacturer ID is a four digit hex code and would normally be handled by the Manufacturer Specific commmand class, but not all devices support it. Although the value reported by this method will be an empty string if the command class is not supported and cannot be set by the user, the manufacturer ID is still stored with the node data (rather than being reported via a command class Value object) to retain a consistent approach with the other manufacturer specific data. -func (n *Node) GetManufacturerID() string { - return GetNodeManufacturerID(n.HomeID, n.NodeID) -} - -// GetProductType Get the product type of a device The product type is a four digit hex code and would normally be handled by the Manufacturer Specific commmand class, but not all devices support it. Although the value reported by this method will be an empty string if the command class is not supported and cannot be set by the user, the product type is still stored with the node data (rather than being reported via a command class Value object) to retain a consistent approach with the other manufacturer specific data. -func (n *Node) GetProductType() string { - return GetNodeProductType(n.HomeID, n.NodeID) -} - -// GetProductID Get the product ID of a device The product ID is a four digit hex code and would normally be handled by the Manufacturer Specific commmand class, but not all devices support it. Although the value reported by this method will be an empty string if the command class is not supported and cannot be set by the user, the product ID is still stored with the node data (rather than being reported via a command class Value object) to retain a consistent approach with the other manufacturer specific data. -func (n *Node) GetProductID() string { - return GetNodeProductID(n.HomeID, n.NodeID) -} - -// SetManufacturerName Set the manufacturer name of a device The manufacturer name would normally be handled by the Manufacturer Specific commmand class, taking the manufacturer ID reported by the device and using it to look up the name from the manufacturer_specific.xml file in the OpenZWave config folder. However, there are some devices that do not support the command class, so to enable the user to manually set the name, it is stored with the node data and accessed via this method rather than being reported via a command class Value object. -func (n *Node) SetManufacturerName(name string) { - SetNodeManufacturerName(n.HomeID, n.NodeID, name) -} - -// SetProductName Set the product name of a device The product name would normally be handled by the Manufacturer Specific commmand class, taking the product Type and ID reported by the device and using it to look up the name from the manufacturer_specific.xml file in the OpenZWave config folder. However, there are some devices that do not support the command class, so to enable the user to manually set the name, it is stored with the node data and accessed via this method rather than being reported via a command class Value object. -func (n *Node) SetProductName(name string) { - SetNodeProductName(n.HomeID, n.NodeID, name) -} - -// SetName Set the name of a node The node name is a user-editable label for the node that would normally be handled by the Node Naming commmand class, but many devices do not support it. So that a node can always be named, OpenZWave stores it with the node data, and provides access through this method and GetNodeName, rather than reporting it via a command class Value object. If the device does support the Node Naming command class, the new name will be sent to the node. The maximum length of a node name is 16 characters. -func (n *Node) SetName(name string) { - SetNodeName(n.HomeID, n.NodeID, name) -} +// #cgo pkg-config: libopenzwave +// #include +// #include +// #include "node_wrap.h" +// #include "util.h" +import "C" +import "unsafe" -// SetLocation Set the location of a node The node location is a user-editable string that would normally be handled by the Node Naming commmand class, but many devices do not support it. So that a node can always report its location, OpenZWave stores it with the node data, and provides access through this method and GetNodeLocation, rather than reporting it via a command class Value object. If the device does support the Node Naming command class, the new location will be sent to the node. -func (n *Node) SetLocation(location string) { - SetNodeLocation(n.HomeID, n.NodeID, location) +// Refresh a Node and Reload it into OZW. +// +// Causes the node's Supported CommandClasses and Capabilities to be obtained +// from the Z-Wave network. This method would normally be called automatically +// by OpenZWave, but if you know that a node's capabilities or command classes +// has been changed, calling this method will force a refresh of that information. +// This call shouldn't be needed except in special circumstances. +// Returns true if the request was sent successfully. +func RefreshNodeInfo(homeID uint32, nodeID uint8) bool { + return bool(C.manager_refresh_node_info(C.uint32_t(homeID), C.uint8_t(nodeID))) } - -// SetOn Turns a node on This is a helper method to simplify basic control of a node. It is the equivalent of changing the level reported by the node's Basic command class to 255, and will generate a ValueChanged notification from that class. This command will turn on the device at its last known level, if supported by the device, otherwise it will turn it on at 100%. -func (n *Node) SetOn() { - SetNodeOn(n.HomeID, n.NodeID) -} - -// SetOff Turns a node off This is a helper method to simplify basic control of a node. It is the equivalent of changing the level reported by the node's Basic command class to zero, and will generate a ValueChanged notification from that class. -func (n *Node) SetOff() { - SetNodeOff(n.HomeID, n.NodeID) -} - -// SetLevel Sets the basic level of a node This is a helper method to simplify basic control of a node. It is the equivalent of changing the value reported by the node's Basic command class and will generate a ValueChanged notification from that class. -func (n *Node) SetLevel(level uint8) { - SetNodeLevel(n.HomeID, n.NodeID, level) + +// Trigger the fetching of dynamic value data for a node. +// +// Causes the node's values to be requested from the Z-Wave network. This is the +// same as the query state starting from the associations state. +// Returns true if the request was sent successfully. +func RequestNodeState(homeID uint32, nodeID uint8) bool { + return bool(C.manager_request_node_state(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Trigger the fetching of just the dynamic value data for a node. +// +// Causes the node's values to be requested from the Z-Wave network. This is the +// same as the query state starting from the dynamic state. +// Returns true if the request was sent successfully. +func RequestNodeDynamic(homeID uint32, nodeID uint8) bool { + return bool(C.manager_request_node_dynamic(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Request the values of all known configurable parameters from a device. +func RequestNodeAllConfigParams(homeID uint32, nodeID uint8) { + C.ozw_RequestAllConfigParams(C.uint32_t(homeID), C.uint8_t(nodeID)) } -// IsInfoReceived Get whether the node information has been received. -func (n *Node) IsInfoReceived() bool { - return IsNodeInfoReceived(n.HomeID, n.NodeID) +// Get whether the node is a listening device that does not go to sleep. +// +// Returns true if the request was sent successfully. +func IsNodeListeningDevice(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_listening_device(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node is a frequent listening device that goes to sleep but can be woken up by a beam. Useful to determine node and controller consistency. +// +// Returns true if the request was sent successfully. +func IsNodeFrequentListeningDevice(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_frequent_listening_device(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node is a beam capable device. +// +// Returns true if the request was sent successfully. +func IsNodeBeamingDevice(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_beaming_device(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node is a routing device that passes messages to other nodes +// +// Returns true if the request was sent successfully. +func IsNodeRoutingDevice(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_routing_device(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the security attribute for a node. True if node supports security features. +// +// Returns true if the request was sent successfully. +func IsNodeSecurityDevice(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_security_device(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the maximum baud rate of a node's communications. +// +// Returns the baud rate in bits per second. +func GetNodeMaxBaudRate(homeID uint32, nodeID uint8) uint32 { + return uint32(C.manager_get_node_max_baud_rate(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the version number of a node. +// +// Returns the node's version number. +func GetNodeVersion(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_version(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the security byte of a node +// +// Returns the node's security byte. +func GetNodeSecurity(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_security(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Is this a ZWave+ Supported Node? +// +// Returns If this node is a Z-Wave Plus Node. +func IsNodeZWavePlus(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_zwave_plus(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the basic type of a node. +// +// Returns the node's basic type. +func GetNodeBasic(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_basic(C.uint32_t(homeID), C.uint8_t(nodeID))) } -// GetClassInformation Get whether the node has the defined class available or not. -func (n *Node) GetClassInformation(commandClassID uint8) (bool, string, uint8) { - return GetNodeClassInformation(n.HomeID, n.NodeID, commandClassID) +// Get the generic type of a node. Set instance to 0 if not required. +// +// Returns the node's generic type. +// +// TODO: utilise instance argument in v1.6+ +func GetNodeGeneric(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_generic(C.uint32_t(homeID), C.uint8_t(nodeID))) } -// IsAwake Get whether the node is awake or asleep. -func (n *Node) IsAwake() bool { - return IsNodeAwake(n.HomeID, n.NodeID) +// Get the specific type of a node. Set instance to 0 if not required. +// +// Returns the node's specific type. +// +// TODO: utilise instance argument in v1.6+ +func GetNodeSpecific(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_specific(C.uint32_t(homeID), C.uint8_t(nodeID))) } -// IsFailed Get whether the node is working or has failed. -func (n *Node) IsFailed() bool { - return IsNodeFailed(n.HomeID, n.NodeID) +// Get a human-readable label describing the node. +// +// The label is taken from the Z-Wave specific, generic or basic type, depending on which of those values are specified by the node. +// Returns A string containing the label text. +func GetNodeType(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_type(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) } -// GetQueryStage Get whether the node's query stage as a string. -func (n *Node) GetQueryStage() string { - return GetNodeQueryStage(n.HomeID, n.NodeID) -} - -// GetDeviceType Get the node device type as reported in the Z-Wave+ Info report. -func (n *Node) GetDeviceType() uint16 { - return GetNodeDeviceType(n.HomeID, n.NodeID) -} - -// GetDeviceTypeString Get the node device type as reported in the Z-Wave+ Info report. -func (n *Node) GetDeviceTypeString() string { - return GetNodeDeviceTypeString(n.HomeID, n.NodeID) -} - -// GetRole Get the node device type as reported in the Z-Wave+ Info report. -func (n *Node) GetRole() uint8 { - return GetNodeRole(n.HomeID, n.NodeID) -} - -// GetRoleString Get the node role as reported in the Z-Wave+ Info report. -func (n *Node) GetRoleString() string { - return GetNodeRoleString(n.HomeID, n.NodeID) -} - -// GetPlusType Get the node PlusType as reported in the Z-Wave+ Info report. -func (n *Node) GetPlusType() uint8 { - return GetNodePlusType(n.HomeID, n.NodeID) -} - -// GetPlusTypeString Get the node PlusType as reported in the Z-Wave+ Info report. -func (n *Node) GetPlusTypeString() string { - return GetNodePlusTypeString(n.HomeID, n.NodeID) +// Get the bitmap of this node's neighbors. See SyncronizeNodeNeighbors. +// +// Returns an array of uint8s to hold the neighbor bitmap. +func GetNodeNeighbors(homeID uint32, nodeID uint8) []uint8 { + cres := C.manager_get_node_neighbors(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cres)) + getval := func(i uint32) uint32 { + return *(*uint32)(C.ptr_at((*unsafe.Pointer)(unsafe.Pointer(cres)), C.uint32_t(i))) + } + size := getval(0) + var res []uint8 + for i := uint32(0); i < size; i++ { + res = append(res, uint8(getval(i+1))) + } + return res +} + +// Update the List of Neighbors on a particular node. +// +// This retrieves the latest copy of the Neighbor lists for a particular node and should be called +// before calling GetNodeNeighbors to ensure OZW returns the most recent list of Neighbors. +func SyncronizeNodeNeighbors(homeID uint32, nodeID uint8) { + C.manager_syncronize_node_neighbors(C.uint32_t(homeID), C.uint8_t(nodeID)) +} + +// Get the manufacturer name of a device. +// +// The manufacturer name would normally be handled by the Manufacturer Specific command class, +// taking the manufacturer ID reported by the device and using it to look up the name from the +// manufacturer_specific.xml file in the OpenZWave config folder. +// However, there are some devices that do not support the command class, so to enable the user +// to manually set the name, it is stored with the node data and accessed via this method rather +// than being reported via a command class Value object. +// +// Returns a string containing the node's manufacturer name. +// +// See SetNodeManufacturerName, GetNodeProductName, SetNodeProductName. +func GetNodeManufacturerName(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_manufacturer_name(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the product name of a device. +// +// The product name would normally be handled by the Manufacturer Specific command class, +// taking the product Type and ID reported by the device and using it to look up the name from the +// manufacturer_specific.xml file in the OpenZWave config folder. +// However, there are some devices that do not support the command class, so to enable the user +// to manually set the name, it is stored with the node data and accessed via this method rather +// than being reported via a command class Value object. +// +// Returns a string containing the node's product name. +// +// See SetNodeProductName, GetNodeManufacturerName, SetNodeManufacturerName. +func GetNodeProductName(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_product_name(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the name of a node. +// +// The node name is a user-editable label for the node that would normally be handled by the +// Node Naming command class, but many devices do not support it. So that a node can always +// be named, OpenZWave stores it with the node data, and provides access through this method +// and SetNodeName, rather than reporting it via a command class Value object. +// The maximum length of a node name is 16 characters. +// +// Returns a string containing the node's name. +// +// See SetNodeName, GetNodeLocation, SetNodeLocation. +func GetNodeName(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_name(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the location of a node. +// +// The node location is a user-editable string that would normally be handled by the Node Naming +// command class, but many devices do not support it. So that a node can always report its +// location, OpenZWave stores it with the node data, and provides access through this method +// and SetNodeLocation, rather than reporting it via a command class Value object. +// +// Returns a string containing the node's location. +// +// See SetNodeLocation, GetNodeName, SetNodeName. +func GetNodeLocation(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_location(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the manufacturer ID of a device. +// +// The manufacturer ID is a four digit hex code and would normally be handled by the Manufacturer +// Specific command class, but not all devices support it. Although the value reported by this +// method will be an empty string if the command class is not supported and cannot be set by the +// user, the manufacturer ID is still stored with the node data (rather than being reported via a +// command class Value object) to retain a consistent approach with the other manufacturer specific data. +// +// Returns A string containing the node's manufacturer ID, or an empty string if the manufacturer +// specific command class is not supported by the device. +// +// See GetNodeProductType, GetNodeProductId, GetNodeManufacturerName, GetNodeProductName. +// +// TODO: Change the return to uint16 in 2.0 time frame +func GetNodeManufacturerID(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_manufacturer_id(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the product type of a device. +// +// The product type is a four digit hex code and would normally be handled by the Manufacturer Specific +// command class, but not all devices support it. Although the value reported by this method will +// be an empty string if the command class is not supported and cannot be set by the user, the product +// type is still stored with the node data (rather than being reported via a command class Value object) +// to retain a consistent approach with the other manufacturer specific data. +// +// Returns a string containing the node's product type, or an empty string if the manufacturer +// specific command class is not supported by the device. +// +// See GetNodeManufacturerId, GetNodeProductId, GetNodeManufacturerName, GetNodeProductName. +// +// TODO: Change the return to uint16 in 2.0 time frame +func GetNodeProductType(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_product_type(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the product ID of a device. +// +// The product ID is a four digit hex code and would normally be handled by the Manufacturer Specific +// command class, but not all devices support it. Although the value reported by this method will +// be an empty string if the command class is not supported and cannot be set by the user, the product +// ID is still stored with the node data (rather than being reported via a command class Value object) +// to retain a consistent approach with the other manufacturer specific data. +// +// Returns a string containing the node's product ID, or an empty string if the manufacturer +// specific command class is not supported by the device. +// +// See GetNodeManufacturerId, GetNodeProductType, GetNodeManufacturerName, GetNodeProductName. +// +// TODO: Change the return to uint16 in 2.0 time frame +func GetNodeProductId(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_product_type(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Set the manufacturer name of a device. +// +// The manufacturer name would normally be handled by the Manufacturer Specific command class, +// taking the manufacturer ID reported by the device and using it to look up the name from the +// manufacturer_specific.xml file in the OpenZWave config folder. +// However, there are some devices that do not support the command class, so to enable the user +// to manually set the name, it is stored with the node data and accessed via this method rather +// than being reported via a command class Value object. +// +// See GetNodeManufacturerName, GetNodeProductName, SetNodeProductName. +func SetNodeManufacturerName(homeID uint32, nodeID uint8, manufacturerName string) { + cstr := C.CString(manufacturerName) + defer C.free(unsafe.Pointer(cstr)) + C.manager_set_node_manufacturer_name(C.uint32_t(homeID), C.uint8_t(nodeID), cstr) +} + +// Set the product name of a device. +// +// The product name would normally be handled by the Manufacturer Specific command class, +// taking the product Type and ID reported by the device and using it to look up the name from the +// manufacturer_specific.xml file in the OpenZWave config folder. +// However, there are some devices that do not support the command class, so to enable the user +// to manually set the name, it is stored with the node data and accessed via this method rather +// than being reported via a command class Value object. +// +// See GetNodeProductName, GetNodeManufacturerName, SetNodeManufacturerName. +func SetNodeProductName(homeID uint32, nodeID uint8, productName string) { + cstr := C.CString(productName) + defer C.free(unsafe.Pointer(cstr)) + C.manager_set_node_product_name(C.uint32_t(homeID), C.uint8_t(nodeID), cstr) +} + +// Set the name of a node. +// +// The node name is a user-editable label for the node that would normally be handled by the +// Node Naming command class, but many devices do not support it. So that a node can always +// be named, OpenZWave stores it with the node data, and provides access through this method +// and GetNodeName, rather than reporting it via a command class Value object. +// If the device does support the Node Naming command class, the new name will be sent to the node. +// The maximum length of a node name is 16 characters. +// +// See GetNodeName, GetNodeLocation, SetNodeLocation. +func SetNodeName(homeID uint32, nodeID uint8, nodeName string) { + cstr := C.CString(nodeName) + defer C.free(unsafe.Pointer(cstr)) + C.manager_set_node_name(C.uint32_t(homeID), C.uint8_t(nodeID), cstr) +} + +// Set the location of a node. +// +// The node location is a user-editable string that would normally be handled by the Node Naming +// command class, but many devices do not support it. So that a node can always report its +// location, OpenZWave stores it with the node data, and provides access through this method +// and GetNodeLocation, rather than reporting it via a command class Value object. +// If the device does support the Node Naming command class, the new location will be sent to the node. +// +// See GetNodeLocation, GetNodeName, SetNodeName. +func SetNodeLocation(homeID uint32, nodeID uint8, location string) { + cstr := C.CString(location) + defer C.free(unsafe.Pointer(cstr)) + C.manager_set_node_location(C.uint32_t(homeID), C.uint8_t(nodeID), cstr) +} + +// Get whether the node information has been received. +// +// Returns true if the node information has been received yet. +func IsNodeInfoReceived(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_info_received(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node has the defined class available or not. +// +// Returns true if the node does have the class instantiated, will return name & version. +func GetNodeClassInformation(homeID uint32, nodeID uint8, commandClassId uint8) (className string, classVersion uint8, hasClass bool) { + res := C.manager_get_node_class_information(C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(commandClassId)) + defer C.manager_free_node_class_information(res) + return C.GoString(res.className), uint8(res.classVersion), bool(res.ok) +} + +// Get whether the node is awake or asleep. +// +// Returns true if the node is awake. +func IsNodeAwake(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_awake(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node is working or has failed. +// +// Returns true if the node has failed and is no longer part of the network. +func IsNodeFailed(homeID uint32, nodeID uint8) bool { + return bool(C.manager_is_node_failed(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get whether the node's query stage as a string. +// +// Returns name of current query stage as a string.. +func GetNodeQueryStage(homeID uint32, nodeID uint8) string { + cstr := C.manager_get_node_query_stage(C.uint32_t(homeID), C.uint8_t(nodeID)) + defer C.free(unsafe.Pointer(cstr)) + return C.GoString(cstr) +} + +// Get the node device type as reported in the Z-Wave+ Info report. +// +// Returns the node's DeviceType. +func GetNodeDeviceType(homeID uint32, nodeID uint8) uint16 { + return uint16(C.manager_get_node_device_type(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the node role as reported in the Z-Wave+ Info report. +// +// Returns the node's user icon.. +func GetNodeRole(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_role(C.uint32_t(homeID), C.uint8_t(nodeID))) +} + +// Get the node PlusType as reported in the Z-Wave+ Info report. +// +// Returns the node's PlusType. +func GetNodePlusType(homeID uint32, nodeID uint8) uint8 { + return uint8(C.manager_get_node_plus_type(C.uint32_t(homeID), C.uint8_t(nodeID))) } diff --git a/node_wrap.cpp b/node_wrap.cpp new file mode 100644 index 0000000..3e129ca --- /dev/null +++ b/node_wrap.cpp @@ -0,0 +1,227 @@ +#include "node_wrap.h" +#include "openzwave/Manager.h" + +bool manager_refresh_node_info(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->RefreshNodeInfo(homeId, nodeId); +} + +bool manager_request_node_state(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->RequestNodeState(homeId, nodeId); +} + +bool manager_request_node_dynamic(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->RequestNodeDynamic(homeId, nodeId); +} + +void ozw_RequestAllConfigParams(uint32_t const homeId, uint8_t const nodeId) +{ + OpenZWave::Manager::Get()->RequestAllConfigParams(homeId, nodeId); +} + +bool manager_is_node_listening_device(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeListeningDevice(homeId, nodeId); +} + +bool manager_is_node_frequent_listening_device(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeFrequentListeningDevice(homeId, nodeId); +} + +bool manager_is_node_beaming_device(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeBeamingDevice(homeId, nodeId); +} + +bool manager_is_node_routing_device(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeRoutingDevice(homeId, nodeId); +} + +bool manager_is_node_security_device(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeSecurityDevice(homeId, nodeId); +} + +uint32_t manager_get_node_max_baud_rate(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeMaxBaudRate(homeId, nodeId); +} + +uint8_t manager_get_node_version(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeVersion(homeId, nodeId); +} + +uint8_t manager_get_node_security(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeSecurity(homeId, nodeId); +} + +bool manager_is_node_zwave_plus(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeZWavePlus(homeId, nodeId); +} + +uint8_t manager_get_node_basic(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeBasic(homeId, nodeId); +} + +uint8_t manager_get_node_generic(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeGeneric(homeId, nodeId); +} + +uint8_t manager_get_node_specific(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeSpecific(homeId, nodeId); +} + +char* manager_get_node_type(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeType(homeId, nodeId); + return strdup(str.c_str()); +} + +uint32_t* manager_get_node_neighbors(uint32_t const homeId, uint8_t const nodeId) +{ + // returns number of neighbours. + // array is always of size 29. + // we will return a new array of uint32's, with the first being the size, followed by the result. + uint8_t* neighbors = nullptr; + uint32_t size = OpenZWave::Manager::Get()->GetNodeNeighbors(homeId, nodeId, &neighbors); + uint32_t* res = static_cast(malloc((size+1) * sizeof(uint32_t))); + res[0] = size; + for (uint32_t i = 0; i < size; ++i) { + res[i+1] = static_cast(neighbors[i]); + } + return res; +} + +void manager_syncronize_node_neighbors(uint32_t const homeId, uint8_t const nodeId) +{ + OpenZWave::Manager::Get()->SyncronizeNodeNeighbors(homeId, nodeId); +} + +char* manager_get_node_manufacturer_name(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeManufacturerName(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_product_name(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeProductName(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_name(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeName(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_location(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeLocation(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_manufacturer_id(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeManufacturerId(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_product_type(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeProductType(homeId, nodeId); + return strdup(str.c_str()); +} + +char* manager_get_node_product_id(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeProductId(homeId, nodeId); + return strdup(str.c_str()); +} + +void manager_set_node_manufacturer_name(uint32_t const homeId, uint8_t const nodeId, const char* manufacturerName) +{ + OpenZWave::Manager::Get()->SetNodeManufacturerName(homeId, nodeId, manufacturerName); +} + +void manager_set_node_product_name(uint32_t const homeId, uint8_t const nodeId, const char* productName) +{ + OpenZWave::Manager::Get()->SetNodeProductName(homeId, nodeId, productName); +} + +void manager_set_node_name(uint32_t const homeId, uint8_t const nodeId, const char* nodeName) +{ + OpenZWave::Manager::Get()->SetNodeName(homeId, nodeId, nodeName); +} + +void manager_set_node_location(uint32_t const homeId, uint8_t const nodeId, const char* location) +{ + OpenZWave::Manager::Get()->SetNodeLocation(homeId, nodeId, location); +} + +bool manager_is_node_info_received(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeInfoReceived(homeId, nodeId); +} + +manager_node_class_information* manager_get_node_class_information(uint32_t const homeId, uint8_t const nodeId, uint8_t const commandClassId) +{ + std::string classNameTmp; + uint8_t classVersionTmp; + bool ok = OpenZWave::Manager::Get()->GetNodeClassInformation(homeId, nodeId, commandClassId, &classNameTmp, &classVersionTmp); + manager_node_class_information* res = static_cast(malloc(sizeof(manager_node_class_information))); + res->ok = ok; + res->className = strdup(classNameTmp.c_str()); + res->classVersion = classVersionTmp; + return res; +} + +void manager_free_node_class_information(manager_node_class_information* ptr) +{ + if (ptr) + { + free(ptr->className); + free(ptr); + } +} + +bool manager_is_node_awake(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeAwake(homeId, nodeId); +} + +bool manager_is_node_failed(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->IsNodeFailed(homeId, nodeId); +} + +char* manager_get_node_query_stage(uint32_t const homeId, uint8_t const nodeId) +{ + std::string str = OpenZWave::Manager::Get()->GetNodeQueryStage(homeId, nodeId); + return strdup(str.c_str()); +} + +uint16_t manager_get_node_device_type(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeDeviceType(homeId, nodeId); +} + +uint8_t manager_get_node_role(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodeRole(homeId, nodeId); +} + +uint8_t manager_get_node_plus_type(uint32_t const homeId, uint8_t const nodeId) +{ + return OpenZWave::Manager::Get()->GetNodePlusType(homeId, nodeId); +} diff --git a/node_wrap.h b/node_wrap.h new file mode 100644 index 0000000..e417484 --- /dev/null +++ b/node_wrap.h @@ -0,0 +1,61 @@ +#ifndef GOOPENZWAVE_NODE_WRAP_H +#define GOOPENZWAVE_NODE_WRAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + bool ok; + char* className; + uint8_t classVersion; +} manager_node_class_information; + +bool manager_refresh_node_info(uint32_t const homeId, uint8_t const nodeId); +bool manager_request_node_state(uint32_t const homeId, uint8_t const nodeId); +bool manager_request_node_dynamic(uint32_t const homeId, uint8_t const nodeId); +void ozw_RequestAllConfigParams(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_listening_device(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_frequent_listening_device(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_beaming_device(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_routing_device(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_security_device(uint32_t const homeId, uint8_t const nodeId); +uint32_t manager_get_node_max_baud_rate(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_version(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_security(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_zwave_plus(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_basic(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_generic(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_specific(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_type(uint32_t const homeId, uint8_t const nodeId); +uint32_t* manager_get_node_neighbors(uint32_t const homeId, uint8_t const nodeId); +void manager_syncronize_node_neighbors(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_manufacturer_name(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_product_name(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_name(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_location(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_manufacturer_id(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_product_type(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_product_id(uint32_t const homeId, uint8_t const nodeId); +void manager_set_node_manufacturer_name(uint32_t const homeId, uint8_t const nodeId, const char* manufacturerName); +void manager_set_node_product_name(uint32_t const homeId, uint8_t const nodeId, const char* productName); +void manager_set_node_name(uint32_t const homeId, uint8_t const nodeId, const char* nodeName); +void manager_set_node_location(uint32_t const homeId, uint8_t const nodeId, const char* location); +bool manager_is_node_info_received(uint32_t const homeId, uint8_t const nodeId); +manager_node_class_information* manager_get_node_class_information(uint32_t const homeId, uint8_t const nodeId, uint8_t const commandClassId); +void manager_free_node_class_information(manager_node_class_information* ptr); +bool manager_is_node_awake(uint32_t const homeId, uint8_t const nodeId); +bool manager_is_node_failed(uint32_t const homeId, uint8_t const nodeId); +char* manager_get_node_query_stage(uint32_t const homeId, uint8_t const nodeId); +uint16_t manager_get_node_device_type(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_role(uint32_t const homeId, uint8_t const nodeId); +uint8_t manager_get_node_plus_type(uint32_t const homeId, uint8_t const nodeId); + +#ifdef __cplusplus +} +#endif + +#endif // GOOPENZWAVE_NODE_WRAP_H diff --git a/nodes.go b/nodes.go deleted file mode 100644 index fb6ff0c..0000000 --- a/nodes.go +++ /dev/null @@ -1,432 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" -import ( - "unsafe" -) - -// RefreshNodeInfo triggers the fetching of fixed data about a node. Returns -// true if the request was sent successfully. -// -// Causes the node's data to be obtained from the Z-Wave network in the same way -// as if it had just been added. This method would normally be called -// automatically by OpenZWave, but if you know that a node has been changed, -// calling this method will force a refresh of all of the data held by the -// library. This can be especially useful for devices that were asleep when the -// application was first run. This is the same as the query state starting from -// the beginning. -func RefreshNodeInfo(homeID uint32, nodeID uint8) bool { - return bool(C.manager_refreshNodeInfo(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// RequestNodeState triggers the fetching of dynamic value data for a node. -// Returns true if the request was sent successfully. -// -// Causes the node's values to be requested from the Z-Wave network. This is the -// same as the query state starting from the associations state. -func RequestNodeState(homeID uint32, nodeID uint8) bool { - return bool(C.manager_requestNodeState(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// RequestNodeDynamic triggers the fetching of just the dynamic value data for a -// node. Returns true if the request was sent successfully. -// -// Causes the node's values to be requested from the Z-Wave network. This is the -// same as the query state starting from the dynamic state. -func RequestNodeDynamic(homeID uint32, nodeID uint8) bool { - return bool(C.manager_requestNodeDynamic(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeListeningDevice returns true if the node is a listening device that -// does not go to sleep. -func IsNodeListeningDevice(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeListeningDevice(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeFrequentListeningDevice returns true if the node is a frequent -// listening device that goes to sleep but can be woken up by a beam. Useful to -// determine node and controller consistency. -func IsNodeFrequentListeningDevice(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeFrequentListeningDevice(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeBeamingDevice returns true if the node is a beam capable device. -func IsNodeBeamingDevice(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeBeamingDevice(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeRoutingDevice returns true if the node is a routing device that passes -// messages to other nodes. -func IsNodeRoutingDevice(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeRoutingDevice(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeSecurityDevice returns true if the node supports security features. -func IsNodeSecurityDevice(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeSecurityDevice(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeMaxBaudRate returns the maximum baud rate of a node's communications. -func GetNodeMaxBaudRate(homeID uint32, nodeID uint8) uint32 { - return uint32(C.manager_getNodeMaxBaudRate(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeVersion returns the version number of a node. -func GetNodeVersion(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeVersion(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeSecurity returns the security byte of a node. -func GetNodeSecurity(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeSecurity(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeZWavePlus returns true if this a ZWave+ Supported Node. -func IsNodeZWavePlus(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeZWavePlus(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeBasicType returns the basic type of a node. -func GetNodeBasicType(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeBasic(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeGenericType returns the generic type of a node. -func GetNodeGenericType(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeGeneric(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeSpecificType returns the specific type of a node. -func GetNodeSpecificType(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeSpecific(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeType returns a human-readable label describing the node. -// -// The label is taken from the Z-Wave specific, generic or basic type, depending -// on which of those values are specified by the node. -func GetNodeType(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeType(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeNeighbours returns the bitmap of this node's neighbors. -//TODO func GetNodeNeighbours(homeID uint32, nodeID uint8) (uint32, uint8 nodeNeighbors) - -// GetNodeManufacturerName returns the manufacturer name of a device. -// -// The manufacturer name would normally be handled by the Manufacturer Specific -// commmand class, taking the manufacturer ID reported by the device and using -// it to look up the name from the manufacturer_specific.xml file in the -// OpenZWave config folder. However, there are some devices that do not support -// the command class, so to enable the user to manually set the name, it is -// stored with the node data and accessed via this method rather than being -// reported via a command class Value object. -func GetNodeManufacturerName(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeManufacturerName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeProductName returns the product name of a device. -// -// The product name would normally be handled by the Manufacturer Specific -// commmand class, taking the product Type and ID reported by the device and -// using it to look up the name from the manufacturer_specific.xml file in the -// OpenZWave config folder. However, there are some devices that do not support -// the command class, so to enable the user to manually set the name, it is -// stored with the node data and accessed via this method rather than being -// reported via a command class Value object. -func GetNodeProductName(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeProductName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeName returns the name of a node. -// -// The node name is a user-editable label for the node that would normally be -// handled by the Node Naming commmand class, but many devices do not support -// it. So that a node can always be named, OpenZWave stores it with the node -// data, and provides access through this method and SetNodeName, rather than -// reporting it via a command class Value object. The maximum length of a node -// name is 16 characters. -func GetNodeName(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeLocation returns the location of a node. -// -// The node location is a user-editable string that would normally be handled by -// the Node Naming commmand class, but many devices do not support it. So that a -// node can always report its location, OpenZWave stores it with the node data, -// and provides access through this method and SetNodeLocation, rather than -// reporting it via a command class Value object. -func GetNodeLocation(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeLocation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeManufacturerID returns the manufacturer ID of a device. -// -// The manufacturer ID is a four digit hex code and would normally be handled by -// the Manufacturer Specific commmand class, but not all devices support it. -// Although the value reported by this method will be an empty string if the -// command class is not supported and cannot be set by the user, the -// manufacturer ID is still stored with the node data (rather than being -// reported via a command class Value object) to retain a consistent approach -// with the other manufacturer specific data. -func GetNodeManufacturerID(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeManufacturerId(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeProductType returns the product type of a device. -// -// The product type is a four digit hex code and would normally be handled by -// the Manufacturer Specific commmand class, but not all devices support it. -// Although the value reported by this method will be an empty string if the -// command class is not supported and cannot be set by the user, the product -// type is still stored with the node data (rather than being reported via a -// command class Value object) to retain a consistent approach with the other -// manufacturer specific data. -func GetNodeProductType(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeProductType(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeProductID returns the product ID of a device. -// -// The product ID is a four digit hex code and would normally be handled by the -// Manufacturer Specific commmand class, but not all devices support it. -// Although the value reported by this method will be an empty string if the -// command class is not supported and cannot be set by the user, the product ID -// is still stored with the node data (rather than being reported via a command -// class Value object) to retain a consistent approach with the other -// manufacturer specific data. -func GetNodeProductID(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeProductId(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// SetNodeManufacturerName sets the manufacturer name of a device. -// -// The manufacturer name would normally be handled by the Manufacturer Specific -// commmand class, taking the manufacturer ID reported by the device and using -// it to look up the name from the manufacturer_specific.xml file in the -// OpenZWave config folder. However, there are some devices that do not support -// the command class, so to enable the user to manually set the name, it is -// stored with the node data and accessed via this method rather than being -// reported via a command class Value object. -func SetNodeManufacturerName(homeID uint32, nodeID uint8, manufacturerName string) { - cstr := C.CString(manufacturerName) - C.manager_setNodeManufacturerName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), cstr) - defer C.free(unsafe.Pointer(cstr)) -} - -// SetNodeProductName sets the product name of a device. -// -// The product name would normally be handled by the Manufacturer Specific -// commmand class, taking the product Type and ID reported by the device and -// using it to look up the name from the manufacturer_specific.xml file in the -// OpenZWave config folder. However, there are some devices that do not support -// the command class, so to enable the user to manually set the name, it is -// stored with the node data and accessed via this method rather than being -// reported via a command class Value object. -func SetNodeProductName(homeID uint32, nodeID uint8, productName string) { - cstr := C.CString(productName) - C.manager_setNodeProductName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), cstr) - defer C.free(unsafe.Pointer(cstr)) -} - -// SetNodeName sets the name of a node. -// -// The node name is a user-editable label for the node that would normally be -// handled by the Node Naming commmand class, but many devices do not support -// it. So that a node can always be named, OpenZWave stores it with the node -// data, and provides access through this method and GetNodeName, rather than -// reporting it via a command class Value object. If the device does support the -// Node Naming command class, the new name will be sent to the node. The maximum -// length of a node name is 16 characters. -func SetNodeName(homeID uint32, nodeID uint8, nodeName string) { - cstr := C.CString(nodeName) - C.manager_setNodeName(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), cstr) - defer C.free(unsafe.Pointer(cstr)) -} - -// SetNodeLocation sets the location of a node. -// -// The node location is a user-editable string that would normally be handled by -// the Node Naming commmand class, but many devices do not support it. So that a -// node can always report its location, OpenZWave stores it with the node data, -// and provides access through this method and GetNodeLocation, rather than -// reporting it via a command class Value object. If the device does support the -// Node Naming command class, the new location will be sent to the node. -func SetNodeLocation(homeID uint32, nodeID uint8, location string) { - cstr := C.CString(location) - C.manager_setNodeLocation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), cstr) - defer C.free(unsafe.Pointer(cstr)) -} - -// SetNodeOn turns a node on. -// -// This is a helper method to simplify basic control of a node. It is the -// equivalent of changing the level reported by the node's Basic command class -// to 255, and will generate a ValueChanged notification from that class. This -// command will turn on the device at its last known level, if supported by the -// device, otherwise it will turn it on at 100%. -func SetNodeOn(homeID uint32, nodeID uint8) { - C.manager_setNodeOn(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) -} - -// SetNodeOff turns a node off. -// -// This is a helper method to simplify basic control of a node. It is the -// equivalent of changing the level reported by the node's Basic command class -// to zero, and will generate a ValueChanged notification from that class. -func SetNodeOff(homeID uint32, nodeID uint8) { - C.manager_setNodeOff(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) -} - -// SetNodeLevel sets the basic level of a node. -// -// This is a helper method to simplify basic control of a node. It is the -// equivalent of changing the value reported by the node's Basic command class -// and will generate a ValueChanged notification from that class. -func SetNodeLevel(homeID uint32, nodeID uint8, level uint8) { - C.manager_setNodeLevel(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(level)) -} - -// IsNodeInfoReceived returns whether the node information has been received. -func IsNodeInfoReceived(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeInfoReceived(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeClassInformation returns true if the node has the defined class -// available or not, and the class name and version if available. -func GetNodeClassInformation(homeID uint32, nodeID uint8, commandClassID uint8) (bool, string, uint8) { - var cClassName *C.char - var cClassVersion C.uint8_t - result := bool(C.manager_getNodeClassInformation(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(commandClassID), &cClassName, &cClassVersion)) - goClassName := C.GoString(cClassName) - goClassVersion := uint8(cClassVersion) - C.free(unsafe.Pointer(cClassName)) - return result, goClassName, goClassVersion -} - -// IsNodeAwake returns true if the node is awake, otherwise false if it is -// asleep. -func IsNodeAwake(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeAwake(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// IsNodeFailed returns true if the node is working, otherwise false if it has -// failed. -func IsNodeFailed(homeID uint32, nodeID uint8) bool { - return bool(C.manager_isNodeFailed(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeQueryStage returns the node's query stage as a string. -func GetNodeQueryStage(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeQueryStage(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeDeviceType returns the node device type as reported in the Z-Wave+ -// Info report. -func GetNodeDeviceType(homeID uint32, nodeID uint8) uint16 { - return uint16(C.manager_getNodeDeviceType(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeDeviceTypeString returns a string of the node device type as reported -// in the Z-Wave+ Info report. -func GetNodeDeviceTypeString(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeDeviceTypeString(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodeRole returns the node role as reported in the Z-Wave+ Info report. -func GetNodeRole(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodeRole(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodeRoleString returns a string of the node role as reported in the -// Z-Wave+ Info report. -func GetNodeRoleString(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodeRoleString(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// GetNodePlusType returns the node PlusType as reported in the Z-Wave+ Info -// report. -func GetNodePlusType(homeID uint32, nodeID uint8) uint8 { - return uint8(C.manager_getNodePlusType(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID))) -} - -// GetNodePlusTypeString returns a string of the node PlusType as reported in -// the Z-Wave+ Info report. -func GetNodePlusTypeString(homeID uint32, nodeID uint8) string { - cstr := C.manager_getNodePlusTypeString(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) - defer C.free(unsafe.Pointer(cstr)) - return C.GoString(cstr) -} - -// SetNodeConfigParam sets the value of a configurable parameter in a device. -// Returns true if the message setting was sent to the device. -// -// Some devices have various parameters that can be configured to control the -// device behaviour. These are not reported by the device over the Z-Wave -// network, but can usually be found in the device's user manual. This method -// returns immediately, without waiting for confirmation from the device that -// the change has been made. -func SetNodeConfigParam(homeID uint32, nodeID uint8, param uint8, value int32, size uint8) bool { - return bool(C.manager_setConfigParam(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(param), C.int32_t(value), C.uint8_t(size))) -} - -// SwitchAllOn Switch all devices on. All devices that support the SwitchAll command class will be turned on. -func SwitchAllOn(homeID uint32) { - C.manager_switchAllOn(cmanager, C.uint32_t(homeID)) -} - -// SwitchAllOff Switch all devices off. All devices that support the SwitchAll command class will be turned off. -func SwitchAllOff(homeID uint32) { - C.manager_switchAllOff(cmanager, C.uint32_t(homeID)) -} - -// RequestNodeConfigParam requests the value of a configurable parameter from a -// device. -// -// Some devices have various parameters that can be configured to control the -// device behaviour. These are not reported by the device over the Z-Wave -// network, but can usually be found in the device's user manual. This method -// requests the value of a parameter from the device, and then returns -// immediately, without waiting for a response. If the parameter index is valid -// for this device, and the device is awake, the value will eventually be -// reported via a ValueChanged notification callback. The ValueID reported in -// the callback will have an index set the same as _param and a command class -// set to the same value as returned by a call to -// Configuration::StaticGetCommandClassId. -func RequestNodeConfigParam(homeID uint32, nodeID uint8, param uint8) { - C.manager_requestConfigParam(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID), C.uint8_t(param)) -} - -// RequestNodeAllConfigParam requests the values of all known configurable -// parameters from a device. -func RequestNodeAllConfigParam(homeID uint32, nodeID uint8) { - C.manager_requestAllConfigParams(cmanager, C.uint32_t(homeID), C.uint8_t(nodeID)) -} - -// GetNodeStatistics Retrieve statistics per node. -//TODO func GetNodeStatistics(...) ... diff --git a/notification.go b/notification.go index 5d48493..950e7c7 100644 --- a/notification.go +++ b/notification.go @@ -1,337 +1,271 @@ package goopenzwave -// #include "gzw_notification.h" -// #include -import "C" -import ( - "fmt" -) +import "fmt" -// NotificationType defines a type for the notification type enum. -type NotificationType int +//go:generate stringer -trimprefix=NotificationType_ -type=NotificationType +//go:generate stringer -trimprefix=NotificationCode_ -type=NotificationCode +//go:generate stringer -trimprefix=UserAlertNotification_ -type=UserAlertNotification +//go:generate stringer -trimprefix=ControllerCommand_ -type=ControllerCommand +//go:generate stringer -trimprefix=ControllerState_ -type=ControllerState +//go:generate stringer -trimprefix=ControllerError_ -type=ControllerError -const ( - NotificationTypeValueAdded NotificationType = iota - NotificationTypeValueRemoved - NotificationTypeValueChanged - NotificationTypeValueRefreshed - NotificationTypeGroup - NotificationTypeNodeNew - NotificationTypeNodeAdded - NotificationTypeNodeRemoved - NotificationTypeNodeProtocolInfo - NotificationTypeNodeNaming - NotificationTypeNodeEvent - NotificationTypePollingDisabled - NotificationTypePollingEnabled - NotificationTypeSceneEvent - NotificationTypeCreateButton - NotificationTypeDeleteButton - NotificationTypeButtonOn - NotificationTypeButtonOff - NotificationTypeDriverReady - NotificationTypeDriverFailed - NotificationTypeDriverReset - NotificationTypeEssentialNodeQueriesComplete - NotificationTypeNodeQueriesComplete - NotificationTypeAwakeNodesQueried - NotificationTypeAllNodesQueriedSomeDead - NotificationTypeAllNodesQueried - NotificationTypeNotification - NotificationTypeDriverRemoved - NotificationTypeControllerCommand - NotificationTypeNodeReset -) +type Notification struct { + Type NotificationType + ValueID ValueID + Byte uint8 + Event uint8 + Command uint8 + UserAlertNotification UserAlertNotification + ComPort string +} -func (nt NotificationType) String() string { - switch nt { - case NotificationTypeValueAdded: - return "ValueAdded" - case NotificationTypeValueRemoved: - return "ValueRemoved" - case NotificationTypeValueChanged: - return "ValueChanged" - case NotificationTypeValueRefreshed: - return "ValueRefreshed" - case NotificationTypeGroup: - return "Group" - case NotificationTypeNodeNew: - return "NodeNew" - case NotificationTypeNodeAdded: - return "NodeAdded" - case NotificationTypeNodeRemoved: - return "NodeRemoved" - case NotificationTypeNodeProtocolInfo: - return "NodeProtocolInfo" - case NotificationTypeNodeNaming: - return "NodeNaming" - case NotificationTypeNodeEvent: - return "NodeEvent" - case NotificationTypePollingDisabled: - return "PollingDisabled" - case NotificationTypePollingEnabled: - return "PollingEnabled" - case NotificationTypeSceneEvent: - return "SceneEvent" - case NotificationTypeCreateButton: - return "CreateButton" - case NotificationTypeDeleteButton: - return "DeleteButton" - case NotificationTypeButtonOn: - return "ButtonOn" - case NotificationTypeButtonOff: - return "ButtonOff" - case NotificationTypeDriverReady: - return "DriverReady" - case NotificationTypeDriverFailed: - return "DriverFailed" - case NotificationTypeDriverReset: - return "DriverReset" - case NotificationTypeEssentialNodeQueriesComplete: - return "EssentialNodeQueriesComplete" - case NotificationTypeNodeQueriesComplete: - return "NodeQueriesComplete" - case NotificationTypeAwakeNodesQueried: - return "AwakeNodesQueried" - case NotificationTypeAllNodesQueriedSomeDead: - return "AllNodesQueriedSomeDead" - case NotificationTypeAllNodesQueried: - return "AllNodesQueried" - case NotificationTypeNotification: - return "Notification" - case NotificationTypeDriverRemoved: - return "DriverRemoved" - case NotificationTypeControllerCommand: - return "ControllerCommand" - case NotificationTypeNodeReset: - return "NodeReset" +func createNotification(n_type uint8, n_vhomeid, n_vid0, n_vid1 uint32, n_byte, n_event, n_command, n_useralerttype uint8, n_comport string) Notification { + return Notification{ + Type: NotificationType(n_type), + ValueID: ValueID{n_vhomeid, n_vid0, n_vid1}, + Byte: n_byte, + Event: n_event, + Command: n_command, + UserAlertNotification: UserAlertNotification(n_useralerttype), + ComPort: n_comport, } - return "UNKNOWN" } -// NotificationCode defines a type for the notification code enum. -type NotificationCode int +func (n Notification) String() string { + out := "{" + n.Type.String() + ", ValueID:" + n.ValueID.String() + switch n.Type { + case NotificationType_ValueAdded: // A new node value has been added to OpenZWave's list. These notifications occur after a node has been discovered, and details of its command classes have been received. Each command class may generate one or more values depending on the complexity of the item being represented. + case NotificationType_ValueRemoved: // A node value has been removed from OpenZWave's list. This only occurs when a node is removed. + case NotificationType_ValueChanged: // A node value has been updated from the Z-Wave network and it is different from the previous value. + case NotificationType_ValueRefreshed: // A node value has been updated from the Z-Wave network. + case NotificationType_Group: // The associations for the node have changed. The application should rebuild any group information it holds about the node. + out += fmt.Sprintf(", GroupIdx:%d", n.GetGroupIdx()) + case NotificationType_NodeNew: // A new node has been found (not already stored in zwcfg*.xml file) + case NotificationType_NodeAdded: // A new node has been added to OpenZWave's list. This may be due to a device being added to the Z-Wave network, or because the application is initializing itself. + case NotificationType_NodeRemoved: // A node has been removed from OpenZWave's list. This may be due to a device being removed from the Z-Wave network, or because the application is closing. + case NotificationType_NodeProtocolInfo: // Basic node information has been received, such as whether the node is a listening device, a routing device and its baud rate and basic, generic and specific types. It is after this notification that you can call Manager::GetNodeType to obtain a label containing the device description. + case NotificationType_NodeNaming: // One of the node names has changed (name, manufacturer, product). + out += fmt.Sprintf(", Name:%s, Product:%s, Manufacturer:%s", + GetNodeName(n.ValueID.HomeID(), n.ValueID.NodeID()), + GetNodeProductName(n.ValueID.HomeID(), n.ValueID.NodeID()), + GetNodeManufacturerName(n.ValueID.HomeID(), n.ValueID.NodeID()), + ) + case NotificationType_NodeEvent: // A node has triggered an event. This is commonly caused when a node sends a Basic_Set command to the controller. The event value is stored in the notification. + out += fmt.Sprintf(", NodeEvent:%d", n.GetEvent()) + case NotificationType_PollingDisabled: // Polling of a node has been successfully turned off by a call to Manager::DisablePoll + case NotificationType_PollingEnabled: // Polling of a node has been successfully turned on by a call to Manager::EnablePoll + case NotificationType_SceneEvent: // Scene Activation Set received (Depreciated in 1.8) + case NotificationType_CreateButton: // Handheld controller button event created + case NotificationType_DeleteButton: // Handheld controller button event deleted + case NotificationType_ButtonOn: // Handheld controller button on pressed event + case NotificationType_ButtonOff: // Handheld controller button off pressed event + case NotificationType_DriverReady: // A driver for a PC Z-Wave controller has been added and is ready to use. The notification will contain the controller's Home ID, which is needed to call most of the Manager methods. + case NotificationType_DriverFailed: // Driver failed to load + out += fmt.Sprintf(", ComPort:%s", n.GetComPort()) + case NotificationType_DriverReset: // All nodes and values for this driver have been removed. This is sent instead of potentially hundreds of individual node and value notifications. + case NotificationType_EssentialNodeQueriesComplete: // The queries on a node that are essential to its operation have been completed. The node can now handle incoming messages. + case NotificationType_NodeQueriesComplete: // All the initialization queries on a node have been completed. + case NotificationType_AwakeNodesQueried: // All awake nodes have been queried, so client application can expected complete data for these nodes. + case NotificationType_AllNodesQueriedSomeDead: // All nodes have been queried but some dead nodes found. + case NotificationType_AllNodesQueried: // All nodes have been queried, so client application can expected complete data. + case NotificationType_Notification: // An error has occurred that we need to report. + out += fmt.Sprintf(", Notification:%s", n.GetNotification()) + case NotificationType_DriverRemoved: // The Driver is being removed. (either due to Error or by request) Do Not Call Any Driver Related Methods after receiving this call + case NotificationType_ControllerCommand: // When Controller Commands are executed, Notifications of Success/Failure etc are communicated via this. Notification Notification::GetEvent returns Driver::ControllerCommand and Notification::GetNotification returns Driver::ControllerState + out += fmt.Sprintf(", ControllerCommand:%s, ControllerState:%s", ControllerCommand(n.GetEvent()), ControllerState(n.GetNotification())) + case NotificationType_NodeReset: // The Device has been reset and thus removed from the NodeList in OZW + case NotificationType_UserAlerts: // Warnings and Notifications Generated by the library that should be displayed to the user (eg, out of date config files) + out += fmt.Sprintf(", UserAlerts:%s", n.GetUserAlertType()) + case NotificationType_ManufacturerSpecificDBReady: // The ManufacturerSpecific Database Is Ready + } + out += "}" + return out +} -const ( - NotificationCodeMsgComplete NotificationCode = iota // C.notification_code_msgComplete - NotificationCodeTimeout // C.notification_code_timeout - NotificationCodeNoOperation // C.notification_code_noOperation - NotificationCodeAwake // C.notification_code_awake - NotificationCodeSleep // C.notification_code_sleep - NotificationCodeDead // C.notification_code_dead - NotificationCodeAlive // C.notification_code_alive -) +// GetGroupIdx for association group that has been changed. Only valid in NotificationType_Group notifications. +func (n Notification) GetGroupIdx() uint8 { + if NotificationType_Group == n.Type { + return n.Byte + } + return 0 +} -func (nc NotificationCode) String() string { - switch nc { - case NotificationCodeMsgComplete: - return "MsgComplete" - case NotificationCodeTimeout: - return "Timeout" - case NotificationCodeNoOperation: - return "NoOperation" - case NotificationCodeAwake: - return "Awake" - case NotificationCodeSleep: - return "Sleep" - case NotificationCodeDead: - return "Dead" - case NotificationCodeAlive: - return "Alive" +// GetEvent returns the event value of a notification. Only valid in NotificationType_NodeEvent and +// NotificationType_ControllerCommand notifications. +func (n Notification) GetEvent() uint8 { + if NotificationType_NodeEvent == n.Type || NotificationType_ControllerCommand == n.Type { + return n.Event } - return "UNKNOWN" + return 0 } -// Notification is a container for the C++ OpenZWave library Notification class. -type Notification struct { - Type NotificationType - HomeID uint32 - NodeID uint8 - ValueID *ValueID - GroupIDX *uint8 - Event *uint8 - ButtonID *uint8 - SceneID *uint8 - Notification *NotificationCode +// GetButtonID of a notification. Only valid in NotificationType_CreateButton, NotificationType_DeleteButton, +// NotificationType_ButtonOn and NotificationType_ButtonOff notifications. +func (n Notification) GetButtonID() uint8 { + if NotificationType_CreateButton == n.Type || NotificationType_DeleteButton == n.Type || NotificationType_ButtonOn == n.Type || NotificationType_ButtonOff == n.Type { + return n.Byte + } + return 0 } -// buildNotification builds a new Notification filled with the relevant -// information from the OpenZWave::Notification as received from the OpenZWave -// library. -func buildNotification(n C.notification_t) *Notification { - notification := &Notification{ - HomeID: uint32(C.notification_getHomeId(n)), - NodeID: uint8(C.notification_getNodeId(n)), +/** +* GetNotification code from a notification. Only valid for NotificationType_Notification or NotificationType_ControllerCommand notifications. + */ +func (n Notification) GetNotification() NotificationCode { + if NotificationType_Notification == n.Type || NotificationType_ControllerCommand == n.Type { + return NotificationCode(n.Byte) } + return 0 +} - switch C.notification_getType(n) { - case C.notification_type_valueAdded: - notification.Type = NotificationTypeValueAdded - case C.notification_type_valueRemoved: - notification.Type = NotificationTypeValueRemoved - case C.notification_type_valueChanged: - notification.Type = NotificationTypeValueChanged - case C.notification_type_valueRefreshed: - notification.Type = NotificationTypeValueRefreshed - case C.notification_type_group: - notification.Type = NotificationTypeGroup - case C.notification_type_nodeNew: - notification.Type = NotificationTypeNodeNew - case C.notification_type_nodeAdded: - notification.Type = NotificationTypeNodeAdded - case C.notification_type_nodeRemoved: - notification.Type = NotificationTypeNodeRemoved - case C.notification_type_nodeProtocolInfo: - notification.Type = NotificationTypeNodeProtocolInfo - case C.notification_type_nodeNaming: - notification.Type = NotificationTypeNodeNaming - case C.notification_type_nodeEvent: - notification.Type = NotificationTypeNodeEvent - case C.notification_type_pollingDisabled: - notification.Type = NotificationTypePollingDisabled - case C.notification_type_pollingEnabled: - notification.Type = NotificationTypePollingEnabled - case C.notification_type_sceneEvent: - notification.Type = NotificationTypeSceneEvent - case C.notification_type_createButton: - notification.Type = NotificationTypeCreateButton - case C.notification_type_deleteButton: - notification.Type = NotificationTypeDeleteButton - case C.notification_type_buttonOn: - notification.Type = NotificationTypeButtonOn - case C.notification_type_buttonOff: - notification.Type = NotificationTypeButtonOff - case C.notification_type_driverReady: - notification.Type = NotificationTypeDriverReady - case C.notification_type_driverFailed: - notification.Type = NotificationTypeDriverFailed - case C.notification_type_driverReset: - notification.Type = NotificationTypeDriverReset - case C.notification_type_essentialNodeQueriesComplete: - notification.Type = NotificationTypeEssentialNodeQueriesComplete - case C.notification_type_nodeQueriesComplete: - notification.Type = NotificationTypeNodeQueriesComplete - case C.notification_type_awakeNodesQueried: - notification.Type = NotificationTypeAwakeNodesQueried - case C.notification_type_allNodesQueriedSomeDead: - notification.Type = NotificationTypeAllNodesQueriedSomeDead - case C.notification_type_allNodesQueried: - notification.Type = NotificationTypeAllNodesQueried - case C.notification_type_notification: - notification.Type = NotificationTypeNotification - case C.notification_type_driverRemoved: - notification.Type = NotificationTypeDriverRemoved - case C.notification_type_controllerCommand: - notification.Type = NotificationTypeControllerCommand - case C.notification_type_nodeReset: - notification.Type = NotificationTypeNodeReset +// GetCommand returns the (controller) command from a notification. Only valid for NotificationType_ControllerCommand notifications. +func (n Notification) GetCommand() uint8 { + if NotificationType_ControllerCommand == n.Type { + return n.Command } + return 0 +} - switch notification.Type { - case NotificationTypeValueAdded, NotificationTypeValueRemoved, NotificationTypeValueChanged, NotificationTypeValueRefreshed: - notification.ValueID = buildValueID(C.notification_getValueId(n)) +// GetRetry is a helper function to return the timeout to wait for. Only valid for NotificationType_UserAlerts - UserAlertNotification_ApplicationStatus_Retry. +func (n Notification) GetRetry() uint8 { + if NotificationType_UserAlerts == n.Type && UserAlertNotification_ApplicationStatus_Retry == n.UserAlertNotification { + return n.Byte + } + return 0 +} - case NotificationTypeGroup: - if notification.GroupIDX == nil { - notification.GroupIDX = new(uint8) - } - *(notification.GroupIDX) = uint8(C.notification_getGroupIdx(n)) +// GetUserAlertType returns the User Alert Type Enum to determine what this message is about. +func (n Notification) GetUserAlertType() UserAlertNotification { + return n.UserAlertNotification +} - case NotificationTypeNodeNew, NotificationTypeNodeAdded, NotificationTypeNodeRemoved, NotificationTypeNodeProtocolInfo, NotificationTypeNodeNaming: - // No notification info. +// GetComPort returns the Comport associated with the DriverFailed Message. +func (n Notification) GetComPort() string { + return n.ComPort +} - case NotificationTypeNodeEvent: - if notification.Event == nil { - notification.Event = new(uint8) - } - *(notification.Event) = uint8(C.notification_getEvent(n)) +// NotificationType for various Z-Wave events sent to the watchers registered with the ManagerAddWatcher method. +type NotificationType uint8 - case NotificationTypePollingDisabled, NotificationTypePollingEnabled: - // No notification info. +const ( + NotificationType_ValueAdded NotificationType = iota // A new node value has been added to OpenZWave's list. These notifications occur after a node has been discovered, and details of its command classes have been received. Each command class may generate one or more values depending on the complexity of the item being represented. + NotificationType_ValueRemoved // A node value has been removed from OpenZWave's list. This only occurs when a node is removed. + NotificationType_ValueChanged // A node value has been updated from the Z-Wave network and it is different from the previous value. + NotificationType_ValueRefreshed // A node value has been updated from the Z-Wave network. + NotificationType_Group // The associations for the node have changed. The application should rebuild any group information it holds about the node. + NotificationType_NodeNew // A new node has been found (not already stored in zwcfg*.xml file) + NotificationType_NodeAdded // A new node has been added to OpenZWave's list. This may be due to a device being added to the Z-Wave network, or because the application is initializing itself. + NotificationType_NodeRemoved // A node has been removed from OpenZWave's list. This may be due to a device being removed from the Z-Wave network, or because the application is closing. + NotificationType_NodeProtocolInfo // Basic node information has been received, such as whether the node is a listening device, a routing device and its baud rate and basic, generic and specific types. It is after this notification that you can call Manager::GetNodeType to obtain a label containing the device description. + NotificationType_NodeNaming // One of the node names has changed (name, manufacturer, product). + NotificationType_NodeEvent // A node has triggered an event. This is commonly caused when a node sends a Basic_Set command to the controller. The event value is stored in the notification. + NotificationType_PollingDisabled // Polling of a node has been successfully turned off by a call to Manager::DisablePoll + NotificationType_PollingEnabled // Polling of a node has been successfully turned on by a call to Manager::EnablePoll + NotificationType_SceneEvent // Scene Activation Set received (Depreciated in 1.8) + NotificationType_CreateButton // Handheld controller button event created + NotificationType_DeleteButton // Handheld controller button event deleted + NotificationType_ButtonOn // Handheld controller button on pressed event + NotificationType_ButtonOff // Handheld controller button off pressed event + NotificationType_DriverReady // A driver for a PC Z-Wave controller has been added and is ready to use. The notification will contain the controller's Home ID, which is needed to call most of the Manager methods. + NotificationType_DriverFailed // Driver failed to load + NotificationType_DriverReset // All nodes and values for this driver have been removed. This is sent instead of potentially hundreds of individual node and value notifications. + NotificationType_EssentialNodeQueriesComplete // The queries on a node that are essential to its operation have been completed. The node can now handle incoming messages. + NotificationType_NodeQueriesComplete // All the initialization queries on a node have been completed. + NotificationType_AwakeNodesQueried // All awake nodes have been queried, so client application can expected complete data for these nodes. + NotificationType_AllNodesQueriedSomeDead // All nodes have been queried but some dead nodes found. + NotificationType_AllNodesQueried // All nodes have been queried, so client application can expected complete data. + NotificationType_Notification // An error has occurred that we need to report. + NotificationType_DriverRemoved // The Driver is being removed. (either due to Error or by request) Do Not Call Any Driver Related Methods after receiving this call + NotificationType_ControllerCommand // When Controller Commands are executed, Notifications of Success/Failure etc are communicated via this Notification Notification::GetEvent returns Driver::ControllerCommand and Notification::GetNotification returns Driver::ControllerState + NotificationType_NodeReset // The Device has been reset and thus removed from the NodeList in OZW + NotificationType_UserAlerts // Warnings and Notifications Generated by the library that should be displayed to the user (eg, out of date config files) + NotificationType_ManufacturerSpecificDBReady // The ManufacturerSpecific Database Is Ready +) - case NotificationTypeSceneEvent: - if notification.SceneID == nil { - notification.SceneID = new(uint8) - } - *(notification.SceneID) = uint8(C.notification_getSceneId(n)) +// NotificationCodes for NotificationType_Notification convey some extra information defined here. +type NotificationCode uint8 - case NotificationTypeCreateButton, NotificationTypeDeleteButton, NotificationTypeButtonOn, NotificationTypeButtonOff: - if notification.ButtonID == nil { - notification.ButtonID = new(uint8) - } - *(notification.ButtonID) = uint8(C.notification_getButtonId(n)) +const ( + NotificationCode_MsgComplete NotificationCode = iota // Completed messages + NotificationCode_Timeout // Messages that timeout will send a Notification with this code. + NotificationCode_NoOperation // Report on NoOperation message sent completion + NotificationCode_Awake // Report when a sleeping node wakes up + NotificationCode_Sleep // Report when a node goes to sleep + NotificationCode_Dead // Report when a node is presumed dead + NotificationCode_Alive // Report when a node is revived +) - case NotificationTypeDriverReady, NotificationTypeDriverFailed, NotificationTypeDriverReset: - // No notification info. +// UserAlertNotification for messages that should be displayed to users to inform them of potential issues such as Out of Date configuration files etc. +type UserAlertNotification uint8 - case NotificationTypeEssentialNodeQueriesComplete, NotificationTypeNodeQueriesComplete, NotificationTypeAwakeNodesQueried, NotificationTypeAllNodesQueriedSomeDead, NotificationTypeAllNodesQueried: - // No notification info. +const ( + UserAlertNotification_None UserAlertNotification = iota // No Alert Currently Present + UserAlertNotification_ConfigOutOfDate // One of the Config Files is out of date. Use GetNodeId to determine which node is effected. + UserAlertNotification_MFSOutOfDate // the manufacturer_specific.xml file is out of date. + UserAlertNotification_ConfigFileDownloadFailed // A Config File failed to download + UserAlertNotification_DNSError // A error occurred performing a DNS Lookup + UserAlertNotification_NodeReloadRequired // A new Config file has been discovered for this node, and its pending a Reload to Take affect + UserAlertNotification_UnsupportedController // The Controller is not running a Firmware Library we support + UserAlertNotification_ApplicationStatus_Retry // Application Status CC returned a Retry Later Message + UserAlertNotification_ApplicationStatus_Queued // Command Has been Queued for later execution + UserAlertNotification_ApplicationStatus_Rejected // Command has been rejected +) - case NotificationTypeNotification: - if notification.Notification == nil { - notification.Notification = new(NotificationCode) - } - switch C.notification_getNotification(n) { - case C.notification_code_msgComplete: - *notification.Notification = NotificationCodeMsgComplete - case C.notification_code_timeout: - *notification.Notification = NotificationCodeTimeout - case C.notification_code_noOperation: - *notification.Notification = NotificationCodeNoOperation - case C.notification_code_awake: - *notification.Notification = NotificationCodeAwake - case C.notification_code_sleep: - *notification.Notification = NotificationCodeSleep - case C.notification_code_dead: - *notification.Notification = NotificationCodeDead - case C.notification_code_alive: - *notification.Notification = NotificationCodeAlive - } +// ControllerCommand to be used with the BeginControllerCommand method. +type ControllerCommand uint8 - case NotificationTypeDriverRemoved: - // No notification info. +const ( + ControllerCommand_None ControllerCommand = iota // No command. + ControllerCommand_AddDevice // Add a new device or controller to the Z-Wave network. + ControllerCommand_CreateNewPrimary // Add a new controller to the Z-Wave network. Used when old primary fails. Requires SUC. + ControllerCommand_ReceiveConfiguration // Receive Z-Wave network configuration information from another controller. + ControllerCommand_RemoveDevice // Remove a device or controller from the Z-Wave network. + ControllerCommand_RemoveFailedNode // Move a node to the controller's failed nodes list. This command will only work if the node cannot respond. + ControllerCommand_HasNodeFailed // Check whether a node is in the controller's failed nodes list. + ControllerCommand_ReplaceFailedNode // Replace a non-responding node with another. The node must be in the controller's list of failed nodes for this command to succeed. + ControllerCommand_TransferPrimaryRole // Make a different controller the primary. + ControllerCommand_RequestNetworkUpdate // Request network information from the SUC/SIS. + ControllerCommand_RequestNodeNeighborUpdate // Get a node to rebuild its neighbour list. This method also does RequestNodeNeighbors + ControllerCommand_AssignReturnRoute // Assign a network return routes to a device. + ControllerCommand_DeleteAllReturnRoutes // Delete all return routes from a device. + ControllerCommand_SendNodeInformation // Send a node information frame + ControllerCommand_ReplicationSend // Send information from primary to secondary + ControllerCommand_CreateButton // Create an id that tracks handheld button presses + ControllerCommand_DeleteButton // Delete id that tracks handheld button presses +) - case NotificationTypeControllerCommand: - if notification.Event == nil { - notification.Event = new(uint8) - } - *(notification.Event) = uint8(C.notification_getEvent(n)) - if notification.Notification == nil { - notification.Notification = new(NotificationCode) - } - *(notification.Notification) = NotificationCode(C.notification_getNotification(n)) +// ControllerState is reported via the callback handler passed into the BeginControllerCommand method. +type ControllerState uint8 - case NotificationTypeNodeReset: - // No notification info. - } +const ( + ControllerState_Normal ControllerState = iota // No command in progress. + ControllerState_Starting // The command is starting. + ControllerState_Cancel // The command was canceled. + ControllerState_Error // Command invocation had error(s) and was aborted + ControllerState_Waiting // Controller is waiting for a user action. + ControllerState_Sleeping // Controller command is on a sleep queue wait for device. + ControllerState_InProgress // The controller is communicating with the other device to carry out the command. + ControllerState_Completed // The command has completed successfully. + ControllerState_Failed // The command has failed. + ControllerState_NodeOK // Used only with ControllerCommand_HasNodeFailed to indicate that the controller thinks the node is OK. + ControllerState_NodeFailed // Used only with ControllerCommand_HasNodeFailed to indicate that the controller thinks the node has failed. +) - return notification -} +// ControllerError provides some more information about controller failures. +type ControllerError uint8 -func (n *Notification) String() string { - var pointed []string - if n.ValueID != nil { - pointed = append(pointed, fmt.Sprintf("ValueID: %s", n.ValueID)) - } - if n.GroupIDX != nil { - pointed = append(pointed, fmt.Sprintf("GroupIDX: %d", *(n.GroupIDX))) - } - if n.Event != nil { - pointed = append(pointed, fmt.Sprintf("Event: %d", *(n.Event))) - } - if n.ButtonID != nil { - pointed = append(pointed, fmt.Sprintf("ButtonID: %d", *(n.ButtonID))) - } - if n.SceneID != nil { - pointed = append(pointed, fmt.Sprintf("SceneID: %d", *(n.SceneID))) - } - if n.Notification != nil { - pointed = append(pointed, fmt.Sprintf("Notification: %s", *(n.Notification))) - } - output := fmt.Sprintf("<%s, HomeID: 0x%x, NodeID: %d", n.Type, n.HomeID, n.NodeID) - for i := range pointed { - output = fmt.Sprintf("%s, %s", output, pointed[i]) - } - output = fmt.Sprintf("%s>", output) - return output -} +const ( + ControllerError_None ControllerError = iota + ControllerError_ButtonNotFound // Button + ControllerError_NodeNotFound // Button + ControllerError_NotBridge // Button + ControllerError_NotSUC // CreateNewPrimary + ControllerError_NotSecondary // CreateNewPrimary + ControllerError_NotPrimary // RemoveFailedNode, AddNodeToNetwork + ControllerError_IsPrimary // ReceiveConfiguration + ControllerError_NotFound // RemoveFailedNode + ControllerError_Busy // RemoveFailedNode, RequestNetworkUpdate + ControllerError_Failed // RemoveFailedNode, RequestNetworkUpdate + ControllerError_Disabled // RequestNetworkUpdate error + ControllerError_Overflow // RequestNetworkUpdate error +) diff --git a/notificationcode_string.go b/notificationcode_string.go new file mode 100644 index 0000000..5e37aa1 --- /dev/null +++ b/notificationcode_string.go @@ -0,0 +1,29 @@ +// Code generated by "stringer -trimprefix=NotificationCode_ -type=NotificationCode"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NotificationCode_MsgComplete-0] + _ = x[NotificationCode_Timeout-1] + _ = x[NotificationCode_NoOperation-2] + _ = x[NotificationCode_Awake-3] + _ = x[NotificationCode_Sleep-4] + _ = x[NotificationCode_Dead-5] + _ = x[NotificationCode_Alive-6] +} + +const _NotificationCode_name = "MsgCompleteTimeoutNoOperationAwakeSleepDeadAlive" + +var _NotificationCode_index = [...]uint8{0, 11, 18, 29, 34, 39, 43, 48} + +func (i NotificationCode) String() string { + if i >= NotificationCode(len(_NotificationCode_index)-1) { + return "NotificationCode(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NotificationCode_name[_NotificationCode_index[i]:_NotificationCode_index[i+1]] +} diff --git a/notifications.go b/notifications.go deleted file mode 100644 index 846375a..0000000 --- a/notifications.go +++ /dev/null @@ -1,46 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include "gzw_notification.h" -// #include -import "C" -import ( - "fmt" - "unsafe" -) - -// startNotifications Calls the OpenZWave AddWatcher function. New notifications -// are received by this package and made available via the Notifications -// channel. -func startNotifications() error { - ok := C.manager_addWatcher(cmanager, nil) - if ok { - return nil - } - return fmt.Errorf("failed to add watcher") -} - -// stopNotifications Calls the OpenZWave RemoveWatcher function. This stops any -// future notifications being received. -func stopNotifications() error { - ok := C.manager_removeWatcher(cmanager, nil) - if ok { - return nil - } - return fmt.Errorf("failed to remove watcher") -} - -// goNotificationCB called by the C++ OpenZWave library when there is a new -// notification. -//export goNotificationCB -func goNotificationCB(cnotification C.notification_t, userdata unsafe.Pointer) { - // This function is called by OpenZWave (via a C wrapper) when a - // notification is available. All data must be extracted from the - // notification object before we return as OpenZWave will delete the object. - - // Convert the C notification_t to Go Notification. - notification := buildNotification(cnotification) - - // Allow the assigned handler to deal with it. - notificationHandler(notification) -} diff --git a/notificationtype_string.go b/notificationtype_string.go new file mode 100644 index 0000000..c336b63 --- /dev/null +++ b/notificationtype_string.go @@ -0,0 +1,54 @@ +// Code generated by "stringer -trimprefix=NotificationType_ -type=NotificationType"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NotificationType_ValueAdded-0] + _ = x[NotificationType_ValueRemoved-1] + _ = x[NotificationType_ValueChanged-2] + _ = x[NotificationType_ValueRefreshed-3] + _ = x[NotificationType_Group-4] + _ = x[NotificationType_NodeNew-5] + _ = x[NotificationType_NodeAdded-6] + _ = x[NotificationType_NodeRemoved-7] + _ = x[NotificationType_NodeProtocolInfo-8] + _ = x[NotificationType_NodeNaming-9] + _ = x[NotificationType_NodeEvent-10] + _ = x[NotificationType_PollingDisabled-11] + _ = x[NotificationType_PollingEnabled-12] + _ = x[NotificationType_SceneEvent-13] + _ = x[NotificationType_CreateButton-14] + _ = x[NotificationType_DeleteButton-15] + _ = x[NotificationType_ButtonOn-16] + _ = x[NotificationType_ButtonOff-17] + _ = x[NotificationType_DriverReady-18] + _ = x[NotificationType_DriverFailed-19] + _ = x[NotificationType_DriverReset-20] + _ = x[NotificationType_EssentialNodeQueriesComplete-21] + _ = x[NotificationType_NodeQueriesComplete-22] + _ = x[NotificationType_AwakeNodesQueried-23] + _ = x[NotificationType_AllNodesQueriedSomeDead-24] + _ = x[NotificationType_AllNodesQueried-25] + _ = x[NotificationType_Notification-26] + _ = x[NotificationType_DriverRemoved-27] + _ = x[NotificationType_ControllerCommand-28] + _ = x[NotificationType_NodeReset-29] + _ = x[NotificationType_UserAlerts-30] + _ = x[NotificationType_ManufacturerSpecificDBReady-31] +} + +const _NotificationType_name = "ValueAddedValueRemovedValueChangedValueRefreshedGroupNodeNewNodeAddedNodeRemovedNodeProtocolInfoNodeNamingNodeEventPollingDisabledPollingEnabledSceneEventCreateButtonDeleteButtonButtonOnButtonOffDriverReadyDriverFailedDriverResetEssentialNodeQueriesCompleteNodeQueriesCompleteAwakeNodesQueriedAllNodesQueriedSomeDeadAllNodesQueriedNotificationDriverRemovedControllerCommandNodeResetUserAlertsManufacturerSpecificDBReady" + +var _NotificationType_index = [...]uint16{0, 10, 22, 34, 48, 53, 60, 69, 80, 96, 106, 115, 130, 144, 154, 166, 178, 186, 195, 206, 218, 229, 257, 276, 293, 316, 331, 343, 356, 373, 382, 392, 419} + +func (i NotificationType) String() string { + if i >= NotificationType(len(_NotificationType_index)-1) { + return "NotificationType(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NotificationType_name[_NotificationType_index[i]:_NotificationType_index[i+1]] +} diff --git a/options.go b/options.go index 889ec8d..96a1513 100644 --- a/options.go +++ b/options.go @@ -1,127 +1,68 @@ package goopenzwave -// #include "gzw_options.h" +// #cgo pkg-config: libopenzwave +// #include "options_wrap.h" // #include import "C" import "unsafe" -// Options is a container for the C++ OpenZWave library Options class. -type Options struct { - options C.options_t -} - -// CreateOptions creates an object to manage the program options. -func CreateOptions(configPath, userPath, commandLine string) *Options { - o := &Options{} +// OptionsCreate creates the openzwave program options object. +// configPath is the path to the OpenZWave library config folder, which contains XML descriptions of Z-Wave manufacturers and products. +// userPath is the path to the application's user data folder where the OpenZWave should store the Z-Wave network configuration and state. +// commandLine is the program's command line options. +// Wraps `Options* OpenZWave::Options::Create(...)`. +func OptionsCreate(configPath, userPath, commandLine string) { + // Options::Create( "../../../config/", "", "" ); cConfigPath := C.CString(configPath) cUserPath := C.CString(userPath) cCommandLine := C.CString(commandLine) - o.options = C.options_create(cConfigPath, cUserPath, cCommandLine) - C.free(unsafe.Pointer(cConfigPath)) - C.free(unsafe.Pointer(cUserPath)) - C.free(unsafe.Pointer(cCommandLine)) - return o -} - -// DestroyOptions deletes the Options and cleans up any associated objects. The -// application is responsible for destroying the Options object, but this must -// not be done until after the Manager object has been destroyed. -func DestroyOptions() bool { - if C.bool(C.options_destroy()) { - return true - } - return false -} - -// GetOptions gets a pointer to the Options singleton object. -func GetOptions() *Options { - o := &Options{} - o.options = C.options_get() - return o -} - -// Lock locks the options. Reads in option values from the XML options file and -// command line string and marks the options as locked. Once locked, no more -// calls to AddOption can be made. The options must be locked before the -// Manager::Create method is called. -func (o *Options) Lock() bool { - return bool(C.options_lock(o.options)) + defer C.free(unsafe.Pointer(cConfigPath)) + defer C.free(unsafe.Pointer(cUserPath)) + defer C.free(unsafe.Pointer(cCommandLine)) + C.options_create(cConfigPath, cUserPath, cCommandLine) } -// AddOptionBool add a boolean option to the program. Adds an option to the -// program whose value can then be read from a file or command line. All calls -// to AddOptionInt must be made before Lock. -func (o *Options) AddOptionBool(name string, value bool) bool { - cName := C.CString(name) - result := bool(C.options_addOptionBool(o.options, cName, C.bool(value))) - C.free(unsafe.Pointer(cName)) - return result +// OptionsAddBool adds a boolean option to the program. Must be called before OptionsLock. +// name is the name of the option. Option names are case insensitive and must be unique. +// defaultval is the default value for this option. +// Wraps `bool OpenZWave::Options::AddOptionBool(...)`. +func OptionsAddBool(name string, defaultval bool) { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + _ = C.options_add_bool(cname, C.bool(defaultval)) } -// AddOptionInt add an integer option to the program. Adds an option to the -// program whose value can then be read from a file or command line. All calls -// to AddOptionInt must be made before Lock. -func (o *Options) AddOptionInt(name string, value int32) bool { - cName := C.CString(name) - result := bool(C.options_addOptionInt(o.options, cName, C.int32_t(value))) - C.free(unsafe.Pointer(cName)) - return result +// OptionsAddInt adds an integer option to the program. Must be called before OptionsLock. +// name is the name of the option. Option names are case insensitive and must be unique. +// defaultval is the default value for this option. +// Wraps `bool OpenZWave::Options::AddOptionInt(...)`. +func OptionsAddInt(name string, defaultval int32) { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + _ = C.options_add_int(cname, C.int32_t(defaultval)) } -// AddOptionLogLevel add a log level option to the program. Adds an option to -// the program whose value can then be read from a file or command line. All -// calls to AddOptionLogLevel must be made before Lock. -func (o *Options) AddOptionLogLevel(name string, value LogLevel) bool { - cName := C.CString(name) - result := bool(C.options_addOptionLogLevel(o.options, cName, C.loglevel_t(value))) - C.free(unsafe.Pointer(cName)) - return result +// OptionsAddString adds a string option to the program. Must be called before OptionsLock. +// name is the name of the option. Option names are case insensitive and must be unique. +// defaultval is the default value for this option. +// append, if set to true, will cause values read from the command line or XML file to be concatenated into a comma delimited list. If false, newer values will overwrite older ones +// Wraps `bool OpenZWave::Options::AddOptionString(...)`. +func OptionsAddString(name string, defaultval string, append bool) { + cname := C.CString(name) + cdefaultval := C.CString(defaultval) + defer C.free(unsafe.Pointer(cname)) + defer C.free(unsafe.Pointer(cdefaultval)) + _ = C.options_add_string(cname, cdefaultval, C.bool(append)) } -// AddOptionString add a string option to the program. Adds an option to the -// program whose value can then be read from a file or command line. All calls -// to AddOptionString must be made before Lock. -func (o *Options) AddOptionString(name string, value string, append bool) bool { - cName := C.CString(name) - cValue := C.CString(value) - result := bool(C.options_addOptionString(o.options, cName, cValue, C.bool(append))) - C.free(unsafe.Pointer(cName)) - C.free(unsafe.Pointer(cValue)) - return result +// OptionsLock reads in option values from the XML options file and command line string and marks the options as locked. Once locked, no more calls to OptionsAdd* can be made. The options must be locked before the ManagerCreate function is called. +// Wraps `bool OpenZWave::Options::Lock()`. +func OptionsLock() { + _ = C.options_lock() } -// GetOptionAsBool get the value of a boolean option. -func (o *Options) GetOptionAsBool(name string) (bool, bool) { - cName := C.CString(name) - var cValue C.bool - result := bool(C.options_getOptionAsBool(o.options, cName, &cValue)) - C.free(unsafe.Pointer(cName)) - return result, bool(cValue) -} - -// GetOptionAsInt get the value of an integer option. -func (o *Options) GetOptionAsInt(name string) (bool, int32) { - cName := C.CString(name) - var cValue C.int32_t - result := bool(C.options_getOptionAsInt(o.options, cName, &cValue)) - C.free(unsafe.Pointer(cName)) - return result, int32(cValue) -} - -// GetOptionAsString get the value of a string option. -func (o *Options) GetOptionAsString(name string) (bool, string) { - cName := C.CString(name) - var cstr *C.char - result := bool(C.options_getOptionAsString(o.options, cName, &cstr)) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return result, gostr -} - -// GetOptionType get the type of value stored in an option. -//TODO OptionType options_getOptionType(string const &_name); - -// AreLocked test whether the options have been locked. -func (o *Options) AreLocked() bool { - return bool(C.options_areLocked(o.options)) +// OptionsDestroy deletes the Options and cleans up any associated objects. The application is responsible for destroying the Options object, but this must not be done until after the Manager object has been destroyed. +// Wraps `bool OpenZWave::Options::Destroy()`. +func OptionsDestroy() { + _ = C.options_destroy() } diff --git a/options_wrap.cpp b/options_wrap.cpp new file mode 100644 index 0000000..3e2c07e --- /dev/null +++ b/options_wrap.cpp @@ -0,0 +1,32 @@ +#include "options_wrap.h" +#include "openzwave/Options.h" + +void options_create(const char* configPath, const char* userPath, const char* commandLine) +{ + OpenZWave::Options::Create(configPath, userPath, commandLine); +} + +bool options_add_bool(const char* name, bool defaultval) +{ + return OpenZWave::Options::Get()->AddOptionBool(name, defaultval); +} + +bool options_add_int(const char* name, int32_t defaultval) +{ + return OpenZWave::Options::Get()->AddOptionInt(name, defaultval); +} + +bool options_add_string(const char* name, const char* defaultval, bool append) +{ + return OpenZWave::Options::Get()->AddOptionString(name, defaultval, append); +} + +bool options_lock() +{ + return OpenZWave::Options::Get()->Lock(); +} + +bool options_destroy() +{ + return OpenZWave::Options::Destroy(); +} diff --git a/options_wrap.h b/options_wrap.h new file mode 100644 index 0000000..0d80970 --- /dev/null +++ b/options_wrap.h @@ -0,0 +1,22 @@ +#ifndef GOOPENZWAVE_OPTIONS_WRAP_H +#define GOOPENZWAVE_OPTIONS_WRAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void options_create(const char* configPath, const char* userPath, const char* commandLine); +bool options_add_bool(const char* name, bool defaultval); +bool options_add_int(const char* name, int32_t defaultval); +bool options_add_string(const char* name, const char* defaultval, bool append); +bool options_lock(); +bool options_destroy(); + +#ifdef __cplusplus +} +#endif + +#endif // GOOPENZWAVE_OPTIONS_WRAP_H diff --git a/polling.go b/polling.go deleted file mode 100644 index 244f5cf..0000000 --- a/polling.go +++ /dev/null @@ -1,67 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" - -// GetPollInterval returns the time period between polls of a node's state. -func GetPollInterval() int32 { - return int32(C.manager_getPollInterval(cmanager)) -} - -// SetPollInterval will set the time period between polls of a node's state. -// -// Due to patent concerns, some devices do not report state changes -// automatically to the controller. These devices need to have their state -// polled at regular intervals. The length of the interval is the same for all -// devices. To even out the Z-Wave network traffic generated by polling, -// OpenZWave divides the polling interval by the number of devices that have -// polling enabled, and polls each in turn. It is recommended that if possible, -// the interval should not be set shorter than the number of polled devices in -// seconds (so that the network does not have to cope with more than one poll -// per second). -func SetPollInterval(milliseconds int32, intervalBetweenPolls bool) { - C.manager_setPollInterval(cmanager, C.int32_t(milliseconds), C.bool(intervalBetweenPolls)) -} - -// EnablePoll enables the polling of a device's state. Returns true if polling -// was enabled. -func EnablePoll(homeID uint32, valueID uint64, intensity uint8) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_enablePoll(cmanager, cvalueid, C.uint8_t(intensity))) -} - -// DisablePoll disables the polling of a device's state. Returns true if polling -// was disabled. -func DisablePoll(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_disablePoll(cmanager, cvalueid)) -} - -// IsPolled returns true if the device's state is being polled. -func IsPolled(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_isPolled(cmanager, cvalueid)) -} - -// SetPollIntensity sets the frequency of polling. -// -// - 0 = none -// - 1 = every time through the list -// - 2 = every other time -// - etc. -func SetPollIntensity(homeID uint32, valueID uint64, intensity uint8) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - C.manager_setPollIntensity(cmanager, cvalueid, C.uint8_t(intensity)) -} - -// GetPollIntensity returns the polling intensity of a device's state. -func GetPollIntensity(homeID uint32, valueID uint64) uint8 { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return uint8(C.manager_getPollIntensity(cmanager, cvalueid)) -} diff --git a/scenes.go b/scenes.go deleted file mode 100644 index e84031f..0000000 --- a/scenes.go +++ /dev/null @@ -1,348 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include -import "C" -import ( - "fmt" - "unsafe" -) - -// GetNumScenes returns the number of scenes that have been defined. -func GetNumScenes() uint8 { - return uint8(C.manager_getNumScenes(cmanager)) -} - -// GetAllScenes Gets a list of all the SceneIds. -//TODO(jimjibone) func GetAllScenes(...) ... - -// RemoveAllScenes removes all the SceneIds. -func RemoveAllScenes(homeID uint32) { - C.manager_removeAllScenes(cmanager, C.uint32_t(homeID)) -} - -// CreateScene creates a new Scene and returns the scene ID. -func CreateScene() uint8 { - return uint8(C.manager_createScene(cmanager)) -} - -// RemoveScene removes an existing Scene. Returns true if the scene was removed. -func RemoveScene(sceneID uint8) bool { - return bool(C.manager_removeScene(cmanager, C.uint8_t(sceneID))) -} - -// AddSceneValueBool adds a bool Value ID to an existing scene. Returns true if -// the Value ID was added. -func AddSceneValueBool(sceneID uint8, homeID uint32, valueID uint64, value bool) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueBool(cmanager, C.uint8_t(sceneID), cvalueid, C.bool(value))) -} - -// AddSceneValueUint8 adds a bool Value ID to an existing scene. Returns true if -// the Value ID was added. -func AddSceneValueUint8(sceneID uint8, homeID uint32, valueID uint64, value uint8) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueUint8(cmanager, C.uint8_t(sceneID), cvalueid, C.uint8_t(value))) -} - -// AddSceneValueFloat adds a decimal Value ID to an existing scene. Returns true -// if the Value ID was added. -func AddSceneValueFloat(sceneID uint8, homeID uint32, valueID uint64, value float32) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueFloat(cmanager, C.uint8_t(sceneID), cvalueid, C.float(value))) -} - -// AddSceneValueInt32 adds a 32-bit signed integer Value ID to an existing -// scene. Returns true if the Value ID was added. -func AddSceneValueInt32(sceneID uint8, homeID uint32, valueID uint64, value int32) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueInt32(cmanager, C.uint8_t(sceneID), cvalueid, C.int32_t(value))) -} - -// AddSceneValueInt16 adds a 16-bit signed integer Value ID to an existing -// scene. Returns true if the Value ID was added. -func AddSceneValueInt16(sceneID uint8, homeID uint32, valueID uint64, value int16) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueInt16(cmanager, C.uint8_t(sceneID), cvalueid, C.int16_t(value))) -} - -// AddSceneValueString adds a string Value ID to an existing scene. Returns true -// if the Value ID was added. -func AddSceneValueString(sceneID uint8, homeID uint32, valueID uint64, value string) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - result := bool(C.manager_addSceneValueString(cmanager, C.uint8_t(sceneID), cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - return result -} - -// AddSceneValueListSelectionString adds the selected item list Value ID to an -// existing scene (as a string). Returns true if the Value ID was added. -func AddSceneValueListSelectionString(sceneID uint8, homeID uint32, valueID uint64, value string) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - result := bool(C.manager_addSceneValueListSelectionString(cmanager, C.uint8_t(sceneID), cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - return result -} - -// AddSceneValueListSelectionInt32 adds the selected item list Value ID to an -// existing scene (as a integer). Returns true if the Value ID was added. -func AddSceneValueListSelectionInt32(sceneID uint8, homeID uint32, valueID uint64, value int32) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_addSceneValueListSelectionInt32(cmanager, C.uint8_t(sceneID), cvalueid, C.int32_t(value))) -} - -// RemoveSceneValue removes the Value ID from an existing scene. -// TODO: bool RemoveSceneValue (uint8 const _sceneId, ValueID const &_valueId) ... - -// SceneGetValues retrieves the scene's list of values. -// TODO: int SceneGetValues (uint8 const _sceneId, vector< ValueID > *o_value) ... - -// GetSceneValueAsBool returns a scene's value as a bool and returns an error if -// the value was not obtained. -func GetSceneValueAsBool(sceneID uint8, homeID uint32, valueID uint64) (bool, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cbool C.bool - ok := bool(C.manager_sceneGetValueAsBool(cmanager, C.uint8_t(sceneID), cvalueid, &cbool)) - if ok == false { - return bool(cbool), fmt.Errorf("bool value was not obtained") - } - return bool(cbool), nil -} - -// GetSceneValueAsByte returns a scene's value as a byte and returns an error if -// the value was not obtained. -func GetSceneValueAsByte(sceneID uint8, homeID uint32, valueID uint64) (byte, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cbyte C.uint8_t - ok := bool(C.manager_sceneGetValueAsByte(cmanager, C.uint8_t(sceneID), cvalueid, &cbyte)) - if ok == false { - return byte(cbyte), fmt.Errorf("byte value was not obtained") - } - return byte(cbyte), nil -} - -// GetSceneValueAsFloat returns a scene's value as a float and returns an error -// if the value was not obtained. -func GetSceneValueAsFloat(sceneID uint8, homeID uint32, valueID uint64) (float32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cfloat C.float - ok := bool(C.manager_sceneGetValueAsFloat(cmanager, C.uint8_t(sceneID), cvalueid, &cfloat)) - if ok == false { - return float32(cfloat), fmt.Errorf("float value was not obtained") - } - return float32(cfloat), nil -} - -// GetSceneValueAsInt returns a scene's value as a 32-bit signed integer and -// returns an error if the value was not obtained. -func GetSceneValueAsInt(sceneID uint8, homeID uint32, valueID uint64) (int32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cint C.int32_t - ok := bool(C.manager_sceneGetValueAsInt(cmanager, C.uint8_t(sceneID), cvalueid, &cint)) - if ok == false { - return int32(cint), fmt.Errorf("int value was not obtained") - } - return int32(cint), nil -} - -// GetSceneValueAsShort returns a scene's value as a 16-bit signed integer and -// returns an error if the value was not obtained. -func GetSceneValueAsShort(sceneID uint8, homeID uint32, valueID uint64) (int16, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cshort C.int16_t - ok := bool(C.manager_sceneGetValueAsShort(cmanager, C.uint8_t(sceneID), cvalueid, &cshort)) - if ok == false { - return int16(cshort), fmt.Errorf("short value was not obtained") - } - return int16(cshort), nil -} - -// GetSceneValueAsString returns a scene's value as a string and returns an -// error if the value was not obtained. -func GetSceneValueAsString(sceneID uint8, homeID uint32, valueID uint64) (string, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cstr *C.char - ok := bool(C.manager_sceneGetValueAsString(cmanager, C.uint8_t(sceneID), cvalueid, &cstr)) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - if ok == false { - return gostr, fmt.Errorf("string value was not obtained") - } - return gostr, nil -} - -// GetSceneValueListSelectionString returns a scene's value list as a string and -// returns an error if the value was not obtained. -func GetSceneValueListSelectionString(sceneID uint8, homeID uint32, valueID uint64) (string, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cstr *C.char - ok := bool(C.manager_sceneGetValueListSelectionString(cmanager, C.uint8_t(sceneID), cvalueid, &cstr)) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - if ok == false { - return gostr, fmt.Errorf("string list value was not obtained") - } - return gostr, nil -} - -// GetSceneValueListSelectionInt32 returns a scene's value list as an integer -// and returns an error if the value was not obtained. -func GetSceneValueListSelectionInt32(sceneID uint8, homeID uint32, valueID uint64) (int32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cint C.int32_t - ok := bool(C.manager_sceneGetValueListSelectionInt32(cmanager, C.uint8_t(sceneID), cvalueid, &cint)) - if ok == false { - return int32(cint), fmt.Errorf("int list value was not obtained") - } - return int32(cint), nil -} - -// SetSceneValueBool sets a bool Value ID to an existing scene's ValueID. -// Returns an error if the Value ID was not added. -func SetSceneValueBool(sceneID uint8, homeID uint32, valueID uint64, value bool) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueBool(cmanager, C.uint8_t(sceneID), cvalueid, C.bool(value))) - if ok == false { - return fmt.Errorf("bool value was not added to scene") - } - return nil -} - -// SetSceneValueUint8 sets a byte Value ID to an existing scene's ValueID. -// Returns an error if the Value ID was not added. -func SetSceneValueUint8(sceneID uint8, homeID uint32, valueID uint64, value uint8) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueUint8(cmanager, C.uint8_t(sceneID), cvalueid, C.uint8_t(value))) - if ok == false { - return fmt.Errorf("byte value was not added to scene") - } - return nil -} - -// SetSceneValueFloat sets a decimal Value ID to an existing scene's ValueID. -// Returns an error if the Value ID was not added. -func SetSceneValueFloat(sceneID uint8, homeID uint32, valueID uint64, value float32) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueFloat(cmanager, C.uint8_t(sceneID), cvalueid, C.float(value))) - if ok == false { - return fmt.Errorf("float value was not added to scene") - } - return nil -} - -// SetSceneValueInt32 sets a 32-bit signed integer Value ID to an existing -// scene's ValueID. Returns an error if the Value ID was not added. -func SetSceneValueInt32(sceneID uint8, homeID uint32, valueID uint64, value int32) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueInt32(cmanager, C.uint8_t(sceneID), cvalueid, C.int32_t(value))) - if ok == false { - return fmt.Errorf("32-bit signed integer value was not added to scene") - } - return nil -} - -// SetSceneValueInt16 sets a 16-bit integer Value ID to an existing scene's -// ValueID. Returns an error if the Value ID was not added. -func SetSceneValueInt16(sceneID uint8, homeID uint32, valueID uint64, value int16) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueInt16(cmanager, C.uint8_t(sceneID), cvalueid, C.int16_t(value))) - if ok == false { - return fmt.Errorf("16-bit integer value was not added to scene") - } - return nil -} - -// SetSceneValueString sets a string Value ID to an existing scene's ValueID. -// Returns an error if the Value ID was not added. -func SetSceneValueString(sceneID uint8, homeID uint32, valueID uint64, value string) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - ok := bool(C.manager_setSceneValueString(cmanager, C.uint8_t(sceneID), cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - if ok == false { - return fmt.Errorf("string value was not added to scene") - } - return nil -} - -// SetSceneValueListSelectionString sets the list selected item Value ID to an -// existing scene's ValueID (as a string). Returns an error if the Value ID was -// not added. -func SetSceneValueListSelectionString(sceneID uint8, homeID uint32, valueID uint64, value string) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - ok := bool(C.manager_setSceneValueListSelectionString(cmanager, C.uint8_t(sceneID), cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - if ok == false { - return fmt.Errorf("string value list selection was not added to scene") - } - return nil -} - -// SetSceneValueListSelectionInt32 sets the list selected item Value ID to an -// existing scene's ValueID (as a integer). Returns an error if the Value ID was -// not added. -func SetSceneValueListSelectionInt32(sceneID uint8, homeID uint32, valueID uint64, value int32) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSceneValueListSelectionInt32(cmanager, C.uint8_t(sceneID), cvalueid, C.int32_t(value))) - if ok == false { - return fmt.Errorf("int value list selection was not added to scene") - } - return nil -} - -// GetSceneLabel returns a label for the particular scene. -func GetSceneLabel(sceneID uint8) string { - cstr := C.manager_getSceneLabel(cmanager, C.uint8_t(sceneID)) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return gostr -} - -// SetSceneLabel sets a label for the particular scene. -func SetSceneLabel(sceneID uint8, value string) { - cstring := C.CString(value) - C.manager_setSceneLabel(cmanager, C.uint8_t(sceneID), cstring) - C.free(unsafe.Pointer(cstring)) -} - -// SceneExists returns true if a Scene ID is defined. -func SceneExists(sceneID uint8) bool { - return bool(C.manager_sceneExists(cmanager, C.uint8_t(sceneID))) -} - -// ActivateScene activates a given scene to perform all its actions. Returns an -// error if the scene was not activated. -func ActivateScene(sceneID uint8) error { - ok := bool(C.manager_activateScene(cmanager, C.uint8_t(sceneID))) - if ok == false { - return fmt.Errorf("failed to activate scene") - } - return nil -} diff --git a/useralertnotification_string.go b/useralertnotification_string.go new file mode 100644 index 0000000..3d285f2 --- /dev/null +++ b/useralertnotification_string.go @@ -0,0 +1,32 @@ +// Code generated by "stringer -trimprefix=UserAlertNotification_ -type=UserAlertNotification"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[UserAlertNotification_None-0] + _ = x[UserAlertNotification_ConfigOutOfDate-1] + _ = x[UserAlertNotification_MFSOutOfDate-2] + _ = x[UserAlertNotification_ConfigFileDownloadFailed-3] + _ = x[UserAlertNotification_DNSError-4] + _ = x[UserAlertNotification_NodeReloadRequired-5] + _ = x[UserAlertNotification_UnsupportedController-6] + _ = x[UserAlertNotification_ApplicationStatus_Retry-7] + _ = x[UserAlertNotification_ApplicationStatus_Queued-8] + _ = x[UserAlertNotification_ApplicationStatus_Rejected-9] +} + +const _UserAlertNotification_name = "NoneConfigOutOfDateMFSOutOfDateConfigFileDownloadFailedDNSErrorNodeReloadRequiredUnsupportedControllerApplicationStatus_RetryApplicationStatus_QueuedApplicationStatus_Rejected" + +var _UserAlertNotification_index = [...]uint8{0, 4, 19, 31, 55, 63, 81, 102, 125, 149, 175} + +func (i UserAlertNotification) String() string { + if i >= UserAlertNotification(len(_UserAlertNotification_index)-1) { + return "UserAlertNotification(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _UserAlertNotification_name[_UserAlertNotification_index[i]:_UserAlertNotification_index[i+1]] +} diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000..b8dc238 --- /dev/null +++ b/util.cpp @@ -0,0 +1,16 @@ +#include "util.h" + +void* ptr_at(void **ptr, uint32_t idx) +{ + return ptr[idx]; +} + +char* str_at(char** ptr, uint32_t idx) +{ + return ptr[idx]; +} + +int32_t int32_at(int32_t* ptr, uint32_t idx) +{ + return ptr[idx]; +} diff --git a/util.h b/util.h new file mode 100644 index 0000000..c4c4b26 --- /dev/null +++ b/util.h @@ -0,0 +1,18 @@ +#ifndef GOOPENZWAVE_UTIL_H +#define GOOPENZWAVE_UTIL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void* ptr_at(void **ptr, uint32_t idx); +char* str_at(char** ptr, uint32_t idx); +int32_t int32_at(int32_t* ptr, uint32_t idx); + +#ifdef __cplusplus +} +#endif + +#endif // GOOPENZWAVE_UTIL_H diff --git a/value.go b/value.go new file mode 100644 index 0000000..5517bae --- /dev/null +++ b/value.go @@ -0,0 +1,485 @@ +package goopenzwave + +// #cgo pkg-config: libopenzwave +// #include +// #include +// #include "value_wrap.h" +// #include "util.h" +import "C" +import ( + "errors" + "unsafe" +) + +var ( + ErrInvalidValueID = errors.New("invalid valueid") + ErrInvalidHomeID = errors.New("invalid homeid") +) + +type ValueError struct { + Type C.ozw_exception + Msg string +} + +func (v ValueError) Error() string { + return v.Msg +} + +func newValueError(res *C.value_result) *ValueError { + if res.is_err == true { + return &ValueError{ + Type: res.err_type, + Msg: C.GoString(res.err_msg), + } + } + return nil +} + +// Gets the user-friendly label for the value. pos is the bit to get the label for if its a BitSet ValueID, -1 for no bitset. +func GetValueLabel(id ValueID, pos int32) (string, error) { + res := C.ozw_GetValueLabel(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.int32_t(pos)) + defer C.value_result_free(res) + if res.is_err { + return "", newValueError(res) + } + return C.GoString(res.val_string), nil +} + +// Sets the user-friendly label for the value. pos is the bit to set the label for if its a BitSet ValueID, -1 for no bitset. +func SetValueLabel(id ValueID, label string, pos int32) error { + cstr := C.CString(label) + defer C.free(unsafe.Pointer(cstr)) + res := C.ozw_SetValueLabel(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), cstr, C.int32_t(pos)) + defer C.value_result_free(res) + return newValueError(res) +} + +// Gets the units that the value is measured in. +func GetValueUnits(id ValueID) (string, error) { + res := C.ozw_GetValueUnits(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return "", newValueError(res) + } + return C.GoString(res.val_string), nil +} + +// Sets the units that the value is measured in. +func SetValueUnits(id ValueID, units string) error { + cstr := C.CString(units) + defer C.free(unsafe.Pointer(cstr)) + res := C.ozw_SetValueUnits(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), cstr) + defer C.value_result_free(res) + return newValueError(res) +} + +// Gets a help string describing the value's purpose and usage. pos is the bit to get the help for if its a BitSet ValueID, -1 for no bitset. +func GetValueHelp(id ValueID, pos int32) (string, error) { + res := C.ozw_GetValueHelp(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.int32_t(pos)) + defer C.value_result_free(res) + if res.is_err { + return "", newValueError(res) + } + return C.GoString(res.val_string), nil +} + +// Sets a help string describing the value's purpose and usage. pos is the bit to set the help for if its a BitSet ValueID. +func SetValueHelp(id ValueID, help string, pos int32) error { + cstr := C.CString(help) + defer C.free(unsafe.Pointer(cstr)) + res := C.ozw_SetValueHelp(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), cstr, C.int32_t(pos)) + defer C.value_result_free(res) + return newValueError(res) +} + +// Gets the minimum that this value may contain. +func GetValueMin(id ValueID) (int32, error) { + res := C.ozw_GetValueMin(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return int32(res.val_int), nil +} + +// Gets the maximum that this value may contain. +func GetValueMax(id ValueID) (int32, error) { + res := C.ozw_GetValueMax(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return int32(res.val_int), nil +} + +// Test whether the value is read-only. +func IsValueReadOnly(id ValueID) (bool, error) { + res := C.ozw_IsValueReadOnly(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Test whether the value is write-only. +func IsValueWriteOnly(id ValueID) (bool, error) { + res := C.ozw_IsValueWriteOnly(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Test whether the value has been set. +func IsValueSet(id ValueID) (bool, error) { + res := C.ozw_IsValueSet(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Test whether the value is currently being polled. +func IsValuePolled(id ValueID) (bool, error) { + res := C.ozw_IsValuePolled(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Test whether the ValueID is valid. +func IsValueValid(id ValueID) (bool, error) { + res := C.ozw_IsValueValid(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Gets a the value of a Bit from a BitSet ValueID. pos is the bit you want to test for. +func GetValueAsBitSet(id ValueID, pos uint8) (bool, error) { + res := C.ozw_GetValueAsBitSet(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.uint8_t(pos)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Gets a value as a bool. +func GetValueAsBool(id ValueID) (bool, error) { + res := C.ozw_GetValueAsBool(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Gets a value as an 8-bit unsigned integer. +func GetValueAsByte(id ValueID) (byte, error) { + res := C.ozw_GetValueAsByte(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return byte(res.val_byte), nil +} + +// Gets a value as a float. +func GetValueAsFloat(id ValueID) (float32, error) { + res := C.ozw_GetValueAsFloat(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0.0, newValueError(res) + } + return float32(res.val_float), nil +} + +// Gets a value as a 32-bit signed integer. +func GetValueAsInt(id ValueID) (int32, error) { + res := C.ozw_GetValueAsInt(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return int32(res.val_int), nil +} + +// Gets a value as a 16-bit signed integer. +func GetValueAsShort(id ValueID) (int16, error) { + res := C.ozw_GetValueAsShort(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return int16(res.val_short), nil +} + +// Gets a value as a string. +func GetValueAsString(id ValueID) (string, error) { + res := C.ozw_GetValueAsString(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return "", newValueError(res) + } + return C.GoString(res.val_string), nil +} + +// Gets a value as a collection of bytes. +func GetValueAsRaw(id ValueID) ([]byte, error) { + res := C.ozw_GetValueAsRaw(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return nil, newValueError(res) + } + return C.GoBytes(unsafe.Pointer(res.val_raw), C.int(res.val_raw_len)), nil +} + +// Gets the selected item from a list (as a string). +func GetValueListSelectionString(id ValueID) (string, error) { + res := C.ozw_GetValueListSelectionString(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return "", newValueError(res) + } + return C.GoString(res.val_string), nil +} + +// Gets the selected item from a list (as an integer). +func GetValueListSelectionInt(id ValueID) (int32, error) { + res := C.ozw_GetValueListSelectionInt(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return int32(res.val_int), nil +} + +// Gets the list of items from a list value. +func GetValueListItems(id ValueID) ([]string, error) { + res := C.ozw_GetValueListItems(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return nil, newValueError(res) + } + size := uint32(res.val_item_list_len) + var items []string + for i := uint32(0); i < size; i++ { + items = append(items, C.GoString(C.str_at(res.val_item_list, C.uint32_t(i)))) + } + return items, nil +} + +// Gets the list of values from a list value. +func GetValueListValues(id ValueID) ([]int32, error) { + res := C.ozw_GetValueListValues(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return nil, newValueError(res) + } + size := uint32(res.val_value_list_len) + var items []int32 + for i := uint32(0); i < size; i++ { + items = append(items, int32(C.int32_at(res.val_value_list, C.uint32_t(i)))) + } + return items, nil +} + +// Gets a float value's precision. +func GetValueFloatPrecision(id ValueID) (uint8, error) { + res := C.ozw_GetValueFloatPrecision(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return uint8(res.val_byte), nil +} + +// Sets the state of a bit in a BitSet ValueID. +func SetValueBitSet(id ValueID, pos uint8, value bool) error { + res := C.ozw_SetValueBitSet(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.uint8_t(pos), C.bool(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the state of a bool. +func SetValueBool(id ValueID, value bool) error { + res := C.ozw_SetValueBool(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.bool(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value of a byte. +func SetValueByte(id ValueID, value byte) error { + res := C.ozw_SetValueByte(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.uint8_t(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value of a decimal. +func SetValueFloat(id ValueID, value float32) error { + res := C.ozw_SetValueFloat(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.float(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value of a 32-bit signed integer. +func SetValueInt(id ValueID, value int32) error { + res := C.ozw_SetValueInt(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.int32_t(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value of a 16-bit signed integer. +func SetValueShort(id ValueID, value int16) error { + res := C.ozw_SetValueShort(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.int16_t(value)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value of a collection of bytes. +func SetValueRaw(id ValueID, value []byte) error { + cvalue := C.CBytes(value) + defer C.free(unsafe.Pointer(cvalue)) + res := C.ozw_SetValueRaw(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), (*C.uchar)(cvalue), C.uint8_t(len(value))) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the value from a string, regardless of type. +func SetValueString(id ValueID, value string) error { + cvalue := C.CString(value) + defer C.free(unsafe.Pointer(cvalue)) + res := C.ozw_SetValueString(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), cvalue) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the selected item in a list. +func SetValueListSelection(id ValueID, selectedItem string) error { + cvalue := C.CString(selectedItem) + defer C.free(unsafe.Pointer(cvalue)) + res := C.ozw_SetValueListSelection(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), cvalue) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Refreshes the specified value from the Z-Wave network. +func RefreshValue(id ValueID) error { + res := C.ozw_RefreshValue(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets a flag indicating whether value changes noted upon a refresh should be verified. If so, the +// library will immediately refresh the value a second time whenever a change is observed. This helps to filter +// out spurious data reported occasionally by some devices. +func SetChangeVerified(id ValueID, verify bool) error { + res := C.ozw_SetChangeVerified(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.bool(verify)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Determine if value changes upon a refresh should be verified. If so, the +// library will immediately refresh the value a second time whenever a change is observed. This helps to filter +// out spurious data reported occasionally by some devices. +func GetChangeVerified(id ValueID) (bool, error) { + res := C.ozw_GetChangeVerified(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return false, newValueError(res) + } + return bool(res.val_bool), nil +} + +// Starts an activity in a device. +// Since buttons are write-only values that do not report a state, no notification callbacks are sent. +func PressButton(id ValueID) error { + res := C.ozw_PressButton(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Stops an activity in a device. +// Since buttons are write-only values that do not report a state, no notification callbacks are sent. +func ReleaseButton(id ValueID) error { + res := C.ozw_ReleaseButton(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Sets the Valid BitMask for a BitSet ValueID +func SetBitMask(id ValueID, mask uint32) error { + res := C.ozw_SetBitMask(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1), C.uint32_t(mask)) + defer C.value_result_free(res) + if res.is_err { + return newValueError(res) + } + return nil +} + +// Gets the Valid BitMask for a BitSet ValueID. +func GetBitMask(id ValueID) (uint32, error) { + res := C.ozw_GetBitMask(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return uint32(res.val_int), nil +} + +// Gets the size of a BitMask ValueID - Either 1, 2 or 4. +func GetBitSetSize(id ValueID) (uint8, error) { + res := C.ozw_GetBitSetSize(C.uint32_t(id.homeid), C.uint32_t(id.id0), C.uint32_t(id.id1)) + defer C.value_result_free(res) + if res.is_err { + return 0, newValueError(res) + } + return uint8(res.val_byte), nil +} diff --git a/value_wrap.cpp b/value_wrap.cpp new file mode 100644 index 0000000..a281563 --- /dev/null +++ b/value_wrap.cpp @@ -0,0 +1,652 @@ +#include "value_wrap.h" +#include "openzwave/Manager.h" + +value_result* value_result_new() +{ + value_result* res = static_cast(malloc(sizeof(value_result))); + memset(res, 0, sizeof(value_result)); + return res; +} + +void value_result_free(value_result* res) +{ + if (res) + { + if (res->val_string) free(res->val_string); + if (res->val_raw) free(res->val_raw); + + if (res->val_item_list) + { + for (uint8_t i = 0; i < res->val_item_list_len; ++i) + { + if (res->val_item_list[i]) + { + free(res->val_item_list[i]); + } + } + free(res->val_item_list); + } + + if (res->val_value_list) free(res->val_value_list); + if (res->err_msg) free(res->err_msg); + free(res); + } +} + +void value_result_set_err(value_result* res, OpenZWave::OZWException& e) +{ + if (res) + { + res->is_ok = false; + res->is_err = true; + + if (res->err_msg) free(res->err_msg); + res->err_msg = strdup(e.GetMsg().c_str()); + + switch (e.GetType()) + { + case OpenZWave::OZWException::OZWEXCEPTION_OPTIONS: + res->err_type = OZWEXCEPTION_OPTIONS; + break; + case OpenZWave::OZWException::OZWEXCEPTION_CONFIG: + res->err_type = OZWEXCEPTION_CONFIG; + break; + case OpenZWave::OZWException::OZWEXCEPTION_INVALID_HOMEID: + res->err_type = OZWEXCEPTION_INVALID_HOMEID; + break; + case OpenZWave::OZWException::OZWEXCEPTION_INVALID_VALUEID: + res->err_type = OZWEXCEPTION_INVALID_VALUEID; + break; + case OpenZWave::OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID: + res->err_type = OZWEXCEPTION_CANNOT_CONVERT_VALUEID; + break; + case OpenZWave::OZWException::OZWEXCEPTION_SECURITY_FAILED: + res->err_type = OZWEXCEPTION_SECURITY_FAILED; + break; + case OpenZWave::OZWException::OZWEXCEPTION_INVALID_NODEID: + res->err_type = OZWEXCEPTION_INVALID_NODEID; + break; + } + } +} + +OpenZWave::ValueID build_valueid(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + return OpenZWave::ValueID(homeid, (((static_cast(vid1) << 32) & 0xFFFFFFFF00000000) | (static_cast(vid0) & 0x00000000FFFFFFFF))); +} + +value_result* ozw_GetValueLabel(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32_t pos) +{ + value_result* res = value_result_new(); + try { + // string GetValueLabel(ValueID const& _id, int32 _pos = -1); + std::string str = OpenZWave::Manager::Get()->GetValueLabel(build_valueid(homeid, vid0, vid1), pos); + res->is_ok = true; + res->val_string = strdup(str.c_str()); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueLabel(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value, int32_t pos) +{ + value_result* res = value_result_new(); + try { + // void SetValueLabel(ValueID const& _id, string const& _value, int32 _pos = -1); + OpenZWave::Manager::Get()->SetValueLabel(build_valueid(homeid, vid0, vid1), value, pos); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueUnits(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // string GetValueUnits(ValueID const& _id); + std::string str = OpenZWave::Manager::Get()->GetValueUnits(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + res->val_string = strdup(str.c_str()); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueUnits(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value) +{ + value_result* res = value_result_new(); + try { + // void SetValueUnits(ValueID const& _id, string const& _value); + OpenZWave::Manager::Get()->SetValueUnits(build_valueid(homeid, vid0, vid1), value); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueHelp(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32_t pos) +{ + value_result* res = value_result_new(); + try { + // string GetValueHelp(ValueID const& _id, int32 _pos = -1); + std::string str = OpenZWave::Manager::Get()->GetValueHelp(build_valueid(homeid, vid0, vid1), pos); + res->is_ok = true; + res->val_string = strdup(str.c_str()); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueHelp(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value, int32_t pos) +{ + value_result* res = value_result_new(); + try { + // void SetValueHelp(ValueID const& _id, string const& _value, int32 _pos = -1); + OpenZWave::Manager::Get()->SetValueHelp(build_valueid(homeid, vid0, vid1), value, pos); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueMin(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // int32 GetValueMin(ValueID const& _id); + res->val_int = OpenZWave::Manager::Get()->GetValueMin(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueMax(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // int32 GetValueMax(ValueID const& _id); + res->val_int = OpenZWave::Manager::Get()->GetValueMax(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_IsValueReadOnly(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool IsValueReadOnly(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->IsValueReadOnly(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_IsValueWriteOnly(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool IsValueWriteOnly(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->IsValueWriteOnly(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_IsValueSet(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool IsValueSet(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->IsValueSet(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_IsValuePolled(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool IsValuePolled(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->IsValuePolled(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_IsValueValid(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool IsValueValid(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->IsValueValid(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsBitSet(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t pos) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsBitSet(ValueID const& _id, uint8 _pos, bool* o_value); + bool out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsBitSet(build_valueid(homeid, vid0, vid1), pos, &out); + res->val_bool = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsBool(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsBool(ValueID const& _id, bool* o_value); + bool out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsBool(build_valueid(homeid, vid0, vid1), &out); + res->val_bool = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsByte(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsByte(ValueID const& _id, uint8* o_value); + uint8_t out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsByte(build_valueid(homeid, vid0, vid1), &out); + res->val_byte = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsFloat(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsFloat(ValueID const& _id, float* o_value); + float out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsFloat(build_valueid(homeid, vid0, vid1), &out); + res->val_float = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsInt(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsInt(ValueID const& _id, int32* o_value); + int32_t out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsInt(build_valueid(homeid, vid0, vid1), &out); + res->val_int = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsShort(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsShort(ValueID const& _id, int16* o_value); + int16_t out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsShort(build_valueid(homeid, vid0, vid1), &out); + res->val_short = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsString(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsString(ValueID const& _id, string* o_value); + std::string out; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsString(build_valueid(homeid, vid0, vid1), &out); + res->val_string = strdup(out.c_str()); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueAsRaw(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueAsRaw(ValueID const& _id, uint8** o_value, uint8* o_length); + uint8_t* out = nullptr; + uint8_t outlen = 0; + res->is_ok = OpenZWave::Manager::Get()->GetValueAsRaw(build_valueid(homeid, vid0, vid1), &out, &outlen); + res->val_raw = out; + res->val_raw_len = outlen; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueListSelectionString(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueListSelection(ValueID const& _id, string* o_value); + std::string out; + res->is_ok = OpenZWave::Manager::Get()->GetValueListSelection(build_valueid(homeid, vid0, vid1), &out); + res->val_string = strdup(out.c_str()); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueListSelectionInt(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueListSelection(ValueID const& _id, int32* o_value); + int32_t out; + res->is_ok = OpenZWave::Manager::Get()->GetValueListSelection(build_valueid(homeid, vid0, vid1), &out); + res->val_int = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueListItems(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueListItems(ValueID const& _id, vector* o_value); + std::vector out; + res->is_ok = OpenZWave::Manager::Get()->GetValueListItems(build_valueid(homeid, vid0, vid1), &out); + res->val_item_list_len = out.size(); + res->val_item_list = static_cast(malloc(out.size() * sizeof(char*))); + for (uint8_t i = 0; i < res->val_item_list_len; ++i) + { + res->val_item_list[i] = strdup(out[i].c_str()); + } + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueListValues(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueListValues(ValueID const& _id, vector* o_value); + std::vector out; + res->is_ok = OpenZWave::Manager::Get()->GetValueListValues(build_valueid(homeid, vid0, vid1), &out); + res->val_value_list_len = out.size(); + res->val_value_list = static_cast(malloc(out.size() * sizeof(int32_t))); + for (uint8_t i = 0; i < res->val_value_list_len; ++i) + { + res->val_value_list[i] = out[i]; + } + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetValueFloatPrecision(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetValueFloatPrecision(ValueID const& _id, uint8* o_value); + uint8_t out; + res->is_ok = OpenZWave::Manager::Get()->GetValueFloatPrecision(build_valueid(homeid, vid0, vid1), &out); + res->val_byte = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueBitSet(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t pos, bool value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, uint8 _pos, bool const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), pos, value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueBool(uint32_t homeid, uint32_t vid0, uint32_t vid1, bool value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, bool const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueByte(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8 value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, uint8 const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueFloat(uint32_t homeid, uint32_t vid0, uint32_t vid1, float value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, float const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueInt(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32 value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, int32 const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueShort(uint32_t homeid, uint32_t vid0, uint32_t vid1, int16 value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, int16 const _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueRaw(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t const* value, uint8_t length) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, uint8 const* _value, uint8 const _length); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), value, length); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueString(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value) +{ + value_result* res = value_result_new(); + try { + // bool SetValue(ValueID const& _id, string const& _value); + res->is_ok = OpenZWave::Manager::Get()->SetValue(build_valueid(homeid, vid0, vid1), std::string(value)); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetValueListSelection(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* selectedItem) +{ + value_result* res = value_result_new(); + try { + // bool SetValueListSelection(ValueID const& _id, string const& _selectedItem); + res->is_ok = OpenZWave::Manager::Get()->SetValueListSelection(build_valueid(homeid, vid0, vid1), std::string(selectedItem)); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_RefreshValue(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool RefreshValue(ValueID const& _id); + res->is_ok = OpenZWave::Manager::Get()->RefreshValue(build_valueid(homeid, vid0, vid1)); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetChangeVerified(uint32_t homeid, uint32_t vid0, uint32_t vid1, bool verify) +{ + value_result* res = value_result_new(); + try { + // void SetChangeVerified(ValueID const& _id, bool _verify); + OpenZWave::Manager::Get()->SetChangeVerified(build_valueid(homeid, vid0, vid1), verify); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetChangeVerified(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // void GetChangeVerified(ValueID const& _id); + res->val_bool = OpenZWave::Manager::Get()->GetChangeVerified(build_valueid(homeid, vid0, vid1)); + res->is_ok = true; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_PressButton(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool PressButton(ValueID const& _id); + res->is_ok = OpenZWave::Manager::Get()->PressButton(build_valueid(homeid, vid0, vid1)); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_ReleaseButton(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool ReleaseButton(ValueID const& _id); + res->is_ok = OpenZWave::Manager::Get()->ReleaseButton(build_valueid(homeid, vid0, vid1)); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_SetBitMask(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint32_t mask) +{ + value_result* res = value_result_new(); + try { + // bool SetBitMask(ValueID const& _id, uint32 _mask); + res->is_ok = OpenZWave::Manager::Get()->SetBitMask(build_valueid(homeid, vid0, vid1), mask); + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetBitMask(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetBitMask(ValueID const& _id, int32* o_mask); + int32_t out; + res->is_ok = OpenZWave::Manager::Get()->GetBitMask(build_valueid(homeid, vid0, vid1), &out); + res->val_int = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} + +value_result* ozw_GetBitSetSize(uint32_t homeid, uint32_t vid0, uint32_t vid1) +{ + value_result* res = value_result_new(); + try { + // bool GetBitSetSize(ValueID const& _id, uint8* o_size); + uint8_t out; + res->is_ok = OpenZWave::Manager::Get()->GetBitSetSize(build_valueid(homeid, vid0, vid1), &out); + res->val_byte = out; + } catch (OpenZWave::OZWException& e) { + value_result_set_err(res, e); + } + return res; +} diff --git a/value_wrap.h b/value_wrap.h new file mode 100644 index 0000000..c290c6f --- /dev/null +++ b/value_wrap.h @@ -0,0 +1,92 @@ +#ifndef GOOPENZWAVE_VALUE_WRAP_H +#define GOOPENZWAVE_VALUE_WRAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + OZWEXCEPTION_OPTIONS, + OZWEXCEPTION_CONFIG, + OZWEXCEPTION_INVALID_HOMEID, + OZWEXCEPTION_INVALID_VALUEID, + OZWEXCEPTION_CANNOT_CONVERT_VALUEID, + OZWEXCEPTION_SECURITY_FAILED, + OZWEXCEPTION_INVALID_NODEID +} ozw_exception; + +typedef struct { + bool is_ok; + bool val_bool; + uint8_t val_byte; + int16_t val_short; + int32_t val_int; + float val_float; + char* val_string; + uint8_t* val_raw; + uint8_t val_raw_len; + char** val_item_list; + uint8_t val_item_list_len; + int32_t* val_value_list; + uint8_t val_value_list_len; + + bool is_err; + ozw_exception err_type; + char* err_msg; +} value_result; + +value_result* value_result_new(); +void value_result_free(value_result* res); + +value_result* ozw_GetValueLabel(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32_t pos); // val_string +value_result* ozw_SetValueLabel(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value, int32_t pos); +value_result* ozw_GetValueUnits(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_string +value_result* ozw_SetValueUnits(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value); +value_result* ozw_GetValueHelp(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32_t pos); // val_string +value_result* ozw_SetValueHelp(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value, int32_t pos); +value_result* ozw_GetValueMin(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_int +value_result* ozw_GetValueMax(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_int +value_result* ozw_IsValueReadOnly(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_IsValueWriteOnly(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_IsValueSet(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_IsValuePolled(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_IsValueValid(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_GetValueAsBitSet(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t pos); // val_bool +value_result* ozw_GetValueAsBool(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_GetValueAsByte(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_byte +value_result* ozw_GetValueAsFloat(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_float +value_result* ozw_GetValueAsInt(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_int +value_result* ozw_GetValueAsShort(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_short +value_result* ozw_GetValueAsString(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_string +value_result* ozw_GetValueAsRaw(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_raw +value_result* ozw_GetValueListSelectionString(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_string +value_result* ozw_GetValueListSelectionInt(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_int +value_result* ozw_GetValueListItems(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_item_list +value_result* ozw_GetValueListValues(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_value_list +value_result* ozw_GetValueFloatPrecision(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_byte +value_result* ozw_SetValueBitSet(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t pos, bool value); +value_result* ozw_SetValueBool(uint32_t homeid, uint32_t vid0, uint32_t vid1, bool value); +value_result* ozw_SetValueByte(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t value); +value_result* ozw_SetValueFloat(uint32_t homeid, uint32_t vid0, uint32_t vid1, float value); +value_result* ozw_SetValueInt(uint32_t homeid, uint32_t vid0, uint32_t vid1, int32_t value); +value_result* ozw_SetValueShort(uint32_t homeid, uint32_t vid0, uint32_t vid1, int16_t value); +value_result* ozw_SetValueRaw(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint8_t const* value, uint8_t length); +value_result* ozw_SetValueString(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* value); +value_result* ozw_SetValueListSelection(uint32_t homeid, uint32_t vid0, uint32_t vid1, const char* selectedItem); +value_result* ozw_RefreshValue(uint32_t homeid, uint32_t vid0, uint32_t vid1); +value_result* ozw_SetChangeVerified(uint32_t homeid, uint32_t vid0, uint32_t vid1, bool verify); +value_result* ozw_GetChangeVerified(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_bool +value_result* ozw_PressButton(uint32_t homeid, uint32_t vid0, uint32_t vid1); +value_result* ozw_ReleaseButton(uint32_t homeid, uint32_t vid0, uint32_t vid1); +value_result* ozw_SetBitMask(uint32_t homeid, uint32_t vid0, uint32_t vid1, uint32_t mask); +value_result* ozw_GetBitMask(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_int +value_result* ozw_GetBitSetSize(uint32_t homeid, uint32_t vid0, uint32_t vid1); // val_byte + +#ifdef __cplusplus +} +#endif + +#endif // GOOPENZWAVE_VALUE_WRAP_H diff --git a/valuegenre_string.go b/valuegenre_string.go new file mode 100644 index 0000000..958355d --- /dev/null +++ b/valuegenre_string.go @@ -0,0 +1,26 @@ +// Code generated by "stringer -trimprefix=ValueGenre_ -type=ValueGenre"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ValueGenre_Basic-0] + _ = x[ValueGenre_User-1] + _ = x[ValueGenre_Config-2] + _ = x[ValueGenre_System-3] +} + +const _ValueGenre_name = "BasicUserConfigSystem" + +var _ValueGenre_index = [...]uint8{0, 5, 9, 15, 21} + +func (i ValueGenre) String() string { + if i >= ValueGenre(len(_ValueGenre_index)-1) { + return "ValueGenre(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _ValueGenre_name[_ValueGenre_index[i]:_ValueGenre_index[i+1]] +} diff --git a/valueid.go b/valueid.go index 77fcf85..3b2a4d2 100644 --- a/valueid.go +++ b/valueid.go @@ -1,500 +1,103 @@ package goopenzwave -// #include "gzw_valueid.h" -// #include -import "C" -import ( - "fmt" -) +import "fmt" + +//go:generate stringer -trimprefix=ValueGenre_ -type=ValueGenre +//go:generate stringer -trimprefix=ValueType_ -type=ValueType -// ValueIDGenre defines a type for the valueid genre enum. -type ValueIDGenre int +type ValueGenre uint8 const ( - ValueIDGenreBasic ValueIDGenre = iota - ValueIDGenreUser - ValueIDGenreConfig - ValueIDGenreSystem - ValueIDGenreCount + ValueGenre_Basic ValueGenre = iota // The 'level' as controlled by basic commands. Usually duplicated by another command class. + ValueGenre_User // Basic values an ordinary user would be interested in. + ValueGenre_Config // Device-specific configuration parameters. These cannot be automatically discovered via Z-Wave, and are usually described in the user manual instead. + ValueGenre_System // Values of significance only to users who understand the Z-Wave protocol ) -func (v ValueIDGenre) String() string { - switch v { - case ValueIDGenreBasic: - return "Basic" - case ValueIDGenreUser: - return "User" - case ValueIDGenreConfig: - return "Config" - case ValueIDGenreSystem: - return "System" - case ValueIDGenreCount: - return "Count" - } - return "UNKNOWN" -} - -// ValueIDType defines a type for the valueid type enum. -type ValueIDType int +type ValueType uint8 const ( - ValueIDTypeBool ValueIDType = iota - ValueIDTypeByte - ValueIDTypeDecimal - ValueIDTypeInt - ValueIDTypeList - ValueIDTypeSchedule - ValueIDTypeShort - ValueIDTypeString - ValueIDTypeButton - ValueIDTypeRaw - ValueIDTypeMax + ValueType_Bool ValueType = iota // Boolean, true or false + ValueType_Byte // 8-bit unsigned value + ValueType_Decimal // Represents a non-integer value as a string, to avoid floating point accuracy issues. + ValueType_Int // 32-bit signed value + ValueType_List // List from which one item can be selected + ValueType_Schedule // Complex type used with the Climate Control Schedule command class + ValueType_Short // 16-bit signed value + ValueType_String // Text string + ValueType_Button // A write-only value that is the equivalent of pressing a button to send a command to a device + ValueType_Raw // A collection of bytes + ValueType_BitSet // A collection of bits ) -func (v ValueIDType) String() string { - switch v { - case ValueIDTypeBool: - return "Bool" - case ValueIDTypeByte: - return "Byte" - case ValueIDTypeDecimal: - return "Decimal" - case ValueIDTypeInt: - return "Int" - case ValueIDTypeList: - return "List" - case ValueIDTypeSchedule: - return "Schedule" - case ValueIDTypeShort: - return "Short" - case ValueIDTypeString: - return "String" - case ValueIDTypeButton: - return "Button" - case ValueIDTypeRaw: // also ValueIDTypeMax - return "Raw/Max" - } - return "UNKNOWN" -} - -// ValueID contains all appropriate information available for a ValueID from the -// OpenZWave library. You should not create a new ValueID manually, but receive -// it from the goopenzwave package after a Notification has been received from -// the OpenZWave library. type ValueID struct { - HomeID uint32 - NodeID uint8 - Genre ValueIDGenre - CommandClassID uint8 - Instance uint8 - Index uint8 - Type ValueIDType - ID uint64 -} - -// buildValueID creates a new valueid.ValueID from the C valueid_t (and -// therefore C++ ValueID) value. -func buildValueID(v C.valueid_t) *ValueID { - vid := &ValueID{ - HomeID: uint32(C.valueid_getHomeId(v)), - NodeID: uint8(C.valueid_getNodeId(v)), - CommandClassID: uint8(C.valueid_getCommandClassId(v)), - Instance: uint8(C.valueid_getInstance(v)), - Index: uint8(C.valueid_getIndex(v)), - ID: uint64(C.valueid_getId(v)), - } - - switch C.valueid_getGenre(v) { - case C.valueid_genre_basic: - vid.Genre = ValueIDGenreBasic - case C.valueid_genre_user: - vid.Genre = ValueIDGenreUser - case C.valueid_genre_config: - vid.Genre = ValueIDGenreConfig - case C.valueid_genre_system: - vid.Genre = ValueIDGenreSystem - case C.valueid_genre_count: - vid.Genre = ValueIDGenreCount - } - - switch C.valueid_getType(v) { - case C.valueid_type_bool: - vid.Type = ValueIDTypeBool - case C.valueid_type_byte: - vid.Type = ValueIDTypeByte - case C.valueid_type_decimal: - vid.Type = ValueIDTypeDecimal - case C.valueid_type_int: - vid.Type = ValueIDTypeInt - case C.valueid_type_list: - vid.Type = ValueIDTypeList - case C.valueid_type_schedule: - vid.Type = ValueIDTypeSchedule - case C.valueid_type_short: - vid.Type = ValueIDTypeShort - case C.valueid_type_string: - vid.Type = ValueIDTypeString - case C.valueid_type_button: - vid.Type = ValueIDTypeButton - case C.valueid_type_raw: - vid.Type = ValueIDTypeRaw - // case C.valueid_type_max: - // vid.Type = ValueIDTypeMax - } - - return vid -} - -// IDString will create a string representation of the ID for use as a key. -func (v *ValueID) IDString() string { - return fmt.Sprintf("%d", v.ID) -} - -func (v *ValueID) StringFull() string { - return fmt.Sprintf("{Label: %s, Value: %s, Units: %q, Min: %d, Max: %d, RO: %t, WO: %t, Genre: %s, CommandClassID: %d, Instance: %d, Index: %d, Type: %s, Help: %s, HomeID: 0x%x, ID: 0x%x}", - v.GetLabel(), - v.GetAsString(), - v.GetUnits(), - v.GetMin(), - v.GetMax(), - v.IsReadOnly(), - v.IsWriteOnly(), - v.Genre, - v.CommandClassID, - v.Instance, - v.Index, - v.Type, - v.GetHelp(), - v.HomeID, - v.ID) -} - -func (v *ValueID) String() string { - units := "" - minmax := "" - ro := "" - wo := "" - help := "" - if v.GetUnits() != "" { - units = " (" + v.GetUnits() + ")" - } - if v.GetMin() != 0 || v.GetMax() != 0 { - minmax = fmt.Sprintf(" [%d -> %d]", v.GetMin(), v.GetMax()) - } - if v.IsReadOnly() { - ro = ", readonly" - } - if v.IsWriteOnly() { - wo = ", writeonly" - } - if v.GetHelp() != "" { - help = ", help: " + v.GetHelp() - } - return fmt.Sprintf("{%s (%s): %s%s%s%s%s, genre: %s%s}", - v.GetLabel(), - v.Type, - v.GetAsString(), - units, - minmax, - ro, - wo, - v.Genre, - help, - ) -} - -// GetLabel returns the user-friendly label for the value. -func (v *ValueID) GetLabel() string { - return GetValueLabel(v.HomeID, v.ID) + homeid uint32 + id0 uint32 + id1 uint32 } -// SetLabel sets the user-friendly label for the value. -func (v *ValueID) SetLabel(label string) { - SetValueLabel(v.HomeID, v.ID, label) -} - -// GetUnits returns the units that the value is measured in. -func (v *ValueID) GetUnits() string { - return GetValueUnits(v.HomeID, v.ID) -} - -// SetUnits sets the units that the value is measured in. -func (v *ValueID) SetUnits(units string) { - SetValueUnits(v.HomeID, v.ID, units) -} - -// GetHelp returns a help string describing the value's purpose and usage. -func (v *ValueID) GetHelp() string { - return GetValueHelp(v.HomeID, v.ID) -} - -// SetHelp sets a help string describing the value's purpose and usage. -func (v *ValueID) SetHelp(help string) { - SetValueHelp(v.HomeID, v.ID, help) -} - -// GetMin returns the minimum that this value may contain. -func (v *ValueID) GetMin() int32 { - return GetValueMin(v.HomeID, v.ID) -} - -// GetMax returns the maximum that this value may contain. -func (v *ValueID) GetMax() int32 { - return GetValueMax(v.HomeID, v.ID) -} - -// IsReadOnly returns true if the value is read-only. -func (v *ValueID) IsReadOnly() bool { - return IsValueReadOnly(v.HomeID, v.ID) -} - -// IsWriteOnly returns true if the value is write-only. -func (v *ValueID) IsWriteOnly() bool { - return IsValueWriteOnly(v.HomeID, v.ID) -} - -// IsSet returns true if the value has been set. -func (v *ValueID) IsSet() bool { - return IsValueSet(v.HomeID, v.ID) -} +// ID0 Packing: +// Bits +// 24-31: 8 bits. Node ID of device +// 22-23: 2 bits. genre of value (see ValueGenre enum). +// 14-21: 8 bits. ID of command class that created and manages this value. +// 12-13: Unused. +// 04-11: 8 bits. Instance of the Value +// 00-03: 4 bits. Type of value (bool, byte, string etc). -// IsPolled returns true if the value is currently being polled. -func (v *ValueID) IsPolled() bool { - return IsValuePolled(v.HomeID, v.ID) -} - -// GetAsBool returns the value as a bool. It will also return an error if the -// value is not a bool type. -func (v *ValueID) GetAsBool() (bool, error) { - return GetValueAsBool(v.HomeID, v.ID) -} - -// GetAsByte returns the value as an 8-bit unsigned integer. It will also -// return an error if the value is not of byte type. -func (v *ValueID) GetAsByte() (byte, error) { - return GetValueAsByte(v.HomeID, v.ID) -} - -// GetAsFloat returns the value as a float. It will also return an error if -// the value is not a decimal type. -func (v *ValueID) GetAsFloat() (float32, error) { - return GetValueAsFloat(v.HomeID, v.ID) -} - -// GetAsInt returns the value as a 32-bit signed integer. It will also -// return an error if the value is not of 32-bit signed integer type. -func (v *ValueID) GetAsInt() (int32, error) { - return GetValueAsInt(v.HomeID, v.ID) -} - -// GetAsShort returns the value as a 16-bit signed integer. It will also -// return an error if the value is not of 16-bit signed integer type. -func (v *ValueID) GetAsShort() (int16, error) { - return GetValueAsShort(v.HomeID, v.ID) -} - -// GetAsString returns the value as a string, regardless of its actual -// type. -func (v *ValueID) GetAsString() string { - return GetValueAsString(v.HomeID, v.ID) -} - -// GetAsRaw returns the value as a raw byte slice. It will also return an -// error if the value is not of raw type. -func (v *ValueID) GetAsRaw() ([]byte, error) { - return GetValueAsRaw(v.HomeID, v.ID) -} - -// GetListSelectionAsString returns selected item from a list as a string. -// It will also return an error if the value is not of list type. -func (v *ValueID) GetListSelectionAsString() (string, error) { - return GetValueListSelectionAsString(v.HomeID, v.ID) -} - -// GetListSelectionAsInt32 returns selected item from a list as an integer. -// It will also return an error if the value is not of list type. -func (v *ValueID) GetListSelectionAsInt32() (int32, error) { - return GetValueListSelectionAsInt32(v.HomeID, v.ID) -} - -// GetListItems returns the list of items from a list value. It will also -// return an error if the value is not of list type. -func (v *ValueID) GetListItems() ([]string, error) { - return GetValueListItems(v.HomeID, v.ID) -} - -// GetFloatPrecision returns the float value's precision. It will also -// return an error if the value is not of decimal type. -func (v *ValueID) GetFloatPrecision() (uint8, error) { - return GetValueFloatPrecision(v.HomeID, v.ID) -} - -// SetBool sets the state of a bool. It will return an error if the value -// is not of bool type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetBool(value bool) error { - return SetValueBool(v.HomeID, v.ID, value) -} - -// SetUint8 sets the value of a byte. It will return an error if the value -// is not of byte type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetUint8(value uint8) error { - return SetValueUint8(v.HomeID, v.ID, value) -} - -// SetFloat sets the value of a decimal. It will return an error if the -// value is not of decimal type. -// -// It is usually better to handle decimal values using strings rather than -// floats, to avoid floating point accuracy issues. Due to the possibility of a -// device being asleep, the command is assumed to succeed, and the value held by -// the node is updated directly. This will be reverted by a future status -// message from the device if the Z-Wave message actually failed to get through. -// Notification callbacks will be sent in both cases. -func (v *ValueID) SetFloat(value float32) error { - return SetValueFloat(v.HomeID, v.ID, value) -} - -// SetInt32 sets the value of a 32-bit signed integer. It will return an -// error if the value is not of 32-bit signed integer type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetInt32(value int32) error { - return SetValueInt32(v.HomeID, v.ID, value) -} - -// SetInt16 sets the value of a 16-bit signed integer. It will return an -// error if the value is not of 16-bit signed integer type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetInt16(value int16) error { - return SetValueInt16(v.HomeID, v.ID, value) -} - -// SetBytes sets the value of a raw value. It will return an error if the -// value is not of raw type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetBytes(value []byte) error { - return SetValueBytes(v.HomeID, v.ID, value) -} - -// SetString sets the value from a string, regardless of type. It will -// return an error if the value could not be parsed into the correct type for -// the value. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetString(value string) error { - return SetValueString(v.HomeID, v.ID, value) -} +// ID1 Packing: +// Bits +// 16-31: 16 bits. Instance Index of the command class. -// SetListSelection sets the selected item in a list. It will return an -// error if the value is not of list type or if the selection is not in the -// list. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func (v *ValueID) SetListSelection(selectedItem string) error { - return SetValueListSelection(v.HomeID, v.ID, selectedItem) +// HomeID of the driver that controls the node containing the value. +func (v ValueID) HomeID() uint32 { + return v.homeid } -// Refresh refreshes the specified value from the Z-Wave network. It will -// return true if the driver and node were found, otherwise false. -// -// A call to this function causes the library to send a message to the network -// to retrieve the current value of the specified ValueID (just like a poll, -// except only one-time, not recurring). -func (v *ValueID) Refresh() bool { - return RefreshValue(v.HomeID, v.ID) +// NodeID of the device reporting the value. +func (v ValueID) NodeID() uint8 { + return uint8((v.id0 & 0xff000000) >> 24) } -// SetChangeVerified sets a flag indicating whether value changes noted upon a -// refresh should be verified. If so, the library will immediately refresh the -// value a second time whenever a change is observed. This helps to filter out -// spurious data reported occasionally by some devices. -func (v *ValueID) SetChangeVerified(verify bool) { - SetChangeVerified(v.HomeID, v.ID, verify) +// Genre is the classification of the value to enable low level system or configuration parameters to be filtered out. +func (v ValueID) Genre() ValueGenre { + return ValueGenre((v.id0 & 0x00c00000) >> 22) } -// GetChangeVerified returns true if value changes upon a refresh should be -// verified. If so, the library will immediately refresh the value a second time -// whenever a change is observed. This helps to filter out spurious data -// reported occasionally by some devices. -func (v *ValueID) GetChangeVerified() bool { - return GetChangeVerified(v.HomeID, v.ID) +// CommandClassID is the Z-Wave command class that created and manages this value. Knowledge of command classes is not required to use OpenZWave, but this information is exposed in case it is of interest. +func (v ValueID) CommandClassID() uint8 { + return uint8((v.id0 & 0x003fc000) >> 14) } -// PressButton starts an activity in a device. It will return an error if the -// value is not of button type. -// -// Since buttons are write-only values that do not report a state, no -// notification callbacks are sent. -func (v *ValueID) PressButton() error { - return PressButton(v.HomeID, v.ID) +// Instance of this value. It is possible for there to be multiple instances of a command class, although currently it appears that only the SensorMultilevel command class ever does this. Knowledge of instances and command classes is not required to use OpenZWave, but this information is exposed in case it is of interest. +func (v ValueID) Instance() uint8 { + return uint8((v.id0 & 0xff0) >> 4) } -// ReleaseButton stops an activity in a device. It will return an error if the -// value is not of button type. -// -// Since buttons are write-only values that do not report a state, no -// notification callbacks are sent. -func (v *ValueID) ReleaseButton() error { - return ReleaseButton(v.HomeID, v.ID) +// Index is used to identify one of multiple values created and managed by a command class. In the case of configurable parameters (handled by the configuration command class), the index is the same as the parameter ID. Knowledge of command classes is not required to use OpenZWave, but this information is exposed in case it is of interest. +func (v ValueID) Index() uint16 { + return uint16((v.id1 & 0xffff0000) >> 16) } -// EnablePoll enables the polling of a device's state. Returns true if polling -// was enabled. -func (v *ValueID) EnablePoll(intensity uint8) bool { - return EnablePoll(v.HomeID, v.ID, intensity) +// Type describes the data held by the value and enables the user to select the correct value accessor method in the Manager class. +func (v ValueID) Type() ValueType { + return ValueType(v.id0 & 0x0000000f) } -// DisablePoll disables the polling of a device's state. Returns true if polling -// was disabled. -func (v *ValueID) DisablePoll() bool { - return DisablePoll(v.HomeID, v.ID) +func (v ValueID) String() string { + return fmt.Sprintf("{HomeID:%d, NodeID:%d, Genre:%s, CC:%d, Instance:%d, Idx:%d, Type:%s}", v.HomeID(), v.NodeID(), v.Genre(), v.CommandClassID(), v.Instance(), v.Index(), v.Type()) } -// SetPollIntensity sets the frequency of polling. -// -// - 0 = none -// - 1 = every time through the list -// - 2 = every other time -// - etc. -func (v *ValueID) SetPollIntensity(intensity uint8) { - SetPollIntensity(v.HomeID, v.ID, intensity) +// Equal reports whether v and o represent the same openzwave value. +func (v ValueID) Equal(o ValueID) bool { + return (v.homeid == o.homeid) && (v.id0 == o.id0) && (v.id1 == o.id1) } -// GetPollIntensity returns the polling intensity of a device's state. -func (v *ValueID) GetPollIntensity() uint8 { - return GetPollIntensity(v.HomeID, v.ID) +// SortIndex returns a deterministic index based on the ValueID command class, +// instance and index. +func (v ValueID) SortIndex() uint32 { + // 8 bits CC ID + // 8 bits Instance + // 16 bits Instance Index + return (uint32(v.CommandClassID())<<24)&0xff000000 | (uint32(v.Instance())<<16)&0x00ff0000 | uint32(v.Index())&0xffff0000 } diff --git a/values.go b/values.go deleted file mode 100644 index 5ff143c..0000000 --- a/values.go +++ /dev/null @@ -1,554 +0,0 @@ -package goopenzwave - -// #include "gzw_manager.h" -// #include "gzw_valueid.h" -// #include "zwbytes.h" -// #include "zwlist.h" -// #include -import "C" -import ( - "fmt" - "unsafe" -) - -// GetValueLabel returns the user-friendly label for the value. -func GetValueLabel(homeID uint32, valueID uint64) string { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstr := C.manager_getValueLabel(cmanager, cvalueid) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return gostr -} - -// SetValueLabel sets the user-friendly label for the value. -func SetValueLabel(homeID uint32, valueID uint64, value string) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstr := C.CString(value) - C.manager_setValueLabel(cmanager, cvalueid, cstr) - C.free(unsafe.Pointer(cstr)) -} - -// GetValueUnits returns the units that the value is measured in. -func GetValueUnits(homeID uint32, valueID uint64) string { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstr := C.manager_getValueUnits(cmanager, cvalueid) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return gostr -} - -// SetValueUnits sets the units that the value is measured in. -func SetValueUnits(homeID uint32, valueID uint64, value string) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - C.manager_setValueUnits(cmanager, cvalueid, cstring) - C.free(unsafe.Pointer(cstring)) -} - -// GetValueHelp returns a help string describing the value's purpose and usage. -func GetValueHelp(homeID uint32, valueID uint64) string { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstr := C.manager_getValueHelp(cmanager, cvalueid) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return gostr -} - -// SetValueHelp sets a help string describing the value's purpose and usage. -func SetValueHelp(homeID uint32, valueID uint64, value string) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - C.manager_setValueHelp(cmanager, cvalueid, cstring) - C.free(unsafe.Pointer(cstring)) -} - -// GetValueMin returns the minimum that this value may contain. -func GetValueMin(homeID uint32, valueID uint64) int32 { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return int32(C.manager_getValueMin(cmanager, cvalueid)) -} - -// GetValueMax returns the maximum that this value may contain. -func GetValueMax(homeID uint32, valueID uint64) int32 { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return int32(C.manager_getValueMax(cmanager, cvalueid)) -} - -// IsValueReadOnly returns true if the value is read-only. -func IsValueReadOnly(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_isValueReadOnly(cmanager, cvalueid)) -} - -// IsValueWriteOnly returns true if the value is write-only. -func IsValueWriteOnly(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_isValueWriteOnly(cmanager, cvalueid)) -} - -// IsValueSet returns true if the value has been set. -func IsValueSet(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_isValueSet(cmanager, cvalueid)) -} - -// IsValuePolled returns true if the value is currently being polled. -func IsValuePolled(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_isValuePolled(cmanager, cvalueid)) -} - -// GetValueAsBool returns the value as a bool. It will also return an error if -// the value is not a bool type. -func GetValueAsBool(homeID uint32, valueID uint64) (bool, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cbool C.bool - ok := bool(C.manager_getValueAsBool(cmanager, cvalueid, &cbool)) - if ok == false { - return bool(cbool), fmt.Errorf("value is not of bool type") - } - return bool(cbool), nil -} - -// GetValueAsByte returns the value as an 8-bit unsigned integer. It will also -// return an error if the value is not of byte type. -func GetValueAsByte(homeID uint32, valueID uint64) (byte, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cbyte C.uint8_t - ok := bool(C.manager_getValueAsByte(cmanager, cvalueid, &cbyte)) - if ok == false { - return byte(cbyte), fmt.Errorf("value is not of byte type") - } - return byte(cbyte), nil -} - -// GetValueAsFloat returns the value as a float. It will also return an error if -// the value is not a decimal type. -func GetValueAsFloat(homeID uint32, valueID uint64) (float32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cfloat C.float - ok := bool(C.manager_getValueAsFloat(cmanager, cvalueid, &cfloat)) - if ok == false { - return float32(cfloat), fmt.Errorf("value is not of decimal type") - } - return float32(cfloat), nil -} - -// GetValueAsInt returns the value as a 32-bit signed integer. It will also -// return an error if the value is not of 32-bit signed integer type. -func GetValueAsInt(homeID uint32, valueID uint64) (int32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cint C.int32_t - ok := bool(C.manager_getValueAsInt(cmanager, cvalueid, &cint)) - if ok == false { - return int32(cint), fmt.Errorf("value is not of 32-bit signed integer type") - } - return int32(cint), nil -} - -// GetValueAsShort returns the value as a 16-bit signed integer. It will also -// return an error if the value is not of 16-bit signed integer type. -func GetValueAsShort(homeID uint32, valueID uint64) (int16, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cshort C.int16_t - ok := bool(C.manager_getValueAsShort(cmanager, cvalueid, &cshort)) - if ok == false { - return int16(cshort), fmt.Errorf("value is not of 16-bit signed integer type") - } - return int16(cshort), nil -} - -// GetValueAsString returns the value as a string, regardless of its actual -// type. -func GetValueAsString(homeID uint32, valueID uint64) string { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cstr *C.char - _ = C.manager_getValueAsString(cmanager, cvalueid, &cstr) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - return gostr -} - -// GetValueAsRaw returns the value as a raw byte slice. It will also return an -// error if the value is not of raw type. -func GetValueAsRaw(homeID uint32, valueID uint64) ([]byte, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - zwbytes := C.zwbytes_new() - ok := bool(C.manager_getValueAsRaw(cmanager, cvalueid, zwbytes)) - if ok == false { - return nil, fmt.Errorf("value is not of raw type") - } - gobytes := make([]byte, zwbytes.size) - for i := 0; i < int(zwbytes.size); i++ { - gobytes[i] = byte(C.zwbytes_at(zwbytes, C.size_t(i))) - } - return gobytes, nil -} - -// GetValueListSelectionAsString returns selected item from a list as a string. -// It will also return an error if the value is not of list type. -func GetValueListSelectionAsString(homeID uint32, valueID uint64) (string, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cstr *C.char - ok := bool(C.manager_getValueListSelectionAsString(cmanager, cvalueid, &cstr)) - gostr := C.GoString(cstr) - C.free(unsafe.Pointer(cstr)) - if ok == false { - return gostr, fmt.Errorf("value is not of list type") - } - return gostr, nil -} - -// GetValueListSelectionAsInt32 returns selected item from a list as an integer. -// It will also return an error if the value is not of list type. -func GetValueListSelectionAsInt32(homeID uint32, valueID uint64) (int32, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cint C.int32_t - ok := bool(C.manager_getValueListSelectionAsInt32(cmanager, cvalueid, &cint)) - if ok == false { - return int32(cint), fmt.Errorf("value is not of list type") - } - return int32(cint), nil -} - -// GetValueListItems returns the list of items from a list value. It will also -// return an error if the value is not of list type. -func GetValueListItems(homeID uint32, valueID uint64) ([]string, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var clist *C.zwlist_t - ok := bool(C.manager_getValueListItems(cmanager, cvalueid, &clist)) - golist := make([]string, int(C.zwlist_size(clist))) - if ok == false { - return nil, fmt.Errorf("value is not of list type") - } - for i := 0; i < int(C.zwlist_size(clist)); i++ { - cstr := C.zwlist_at(clist, C.size_t(i)) - golist[i] = C.GoString(cstr) - } - C.zwlist_free(clist) - return golist, nil -} - -// GetValueFloatPrecision returns the float value's precision. It will also -// return an error if the value is not of decimal type. -func GetValueFloatPrecision(homeID uint32, valueID uint64) (uint8, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var cprecision C.uint8_t - ok := bool(C.manager_getValueFloatPrecision(cmanager, cvalueid, &cprecision)) - if ok == false { - return uint8(cprecision), fmt.Errorf("value is not of decimal type") - } - return uint8(cprecision), nil -} - -// SetValueBool sets the state of a bool. It will return an error if the value -// is not of bool type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueBool(homeID uint32, valueID uint64, value bool) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setValueBool(cmanager, cvalueid, C.bool(value))) - if ok == false { - return fmt.Errorf("value is not of bool type") - } - return nil -} - -// SetValueUint8 sets the value of a byte. It will return an error if the value -// is not of byte type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueUint8(homeID uint32, valueID uint64, value uint8) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setValueUint8(cmanager, cvalueid, C.uint8_t(value))) - if ok == false { - return fmt.Errorf("value is not of byte type") - } - return nil -} - -// SetValueFloat sets the value of a decimal. It will return an error if the -// value is not of decimal type. -// -// It is usually better to handle decimal values using strings rather than -// floats, to avoid floating point accuracy issues. Due to the possibility of a -// device being asleep, the command is assumed to succeed, and the value held by -// the node is updated directly. This will be reverted by a future status -// message from the device if the Z-Wave message actually failed to get through. -// Notification callbacks will be sent in both cases. -func SetValueFloat(homeID uint32, valueID uint64, value float32) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setValueFloat(cmanager, cvalueid, C.float(value))) - if ok == false { - return fmt.Errorf("value is not of decimal type") - } - return nil -} - -// SetValueInt32 sets the value of a 32-bit signed integer. It will return an -// error if the value is not of 32-bit signed integer type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueInt32(homeID uint32, valueID uint64, value int32) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setValueInt32(cmanager, cvalueid, C.int32_t(value))) - if ok == false { - return fmt.Errorf("value is not of 32-bit signed integer type") - } - return nil -} - -// SetValueInt16 sets the value of a 16-bit signed integer. It will return an -// error if the value is not of 16-bit signed integer type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueInt16(homeID uint32, valueID uint64, value int16) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setValueInt16(cmanager, cvalueid, C.int16_t(value))) - if ok == false { - return fmt.Errorf("value is not of 16-bit signed integer type") - } - return nil -} - -// SetValueBytes sets the value of a raw value. It will return an error if the -// value is not of raw type. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueBytes(homeID uint32, valueID uint64, value []byte) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - zwbytes := C.zwbytes_new() - C.zwbytes_reserve(zwbytes, C.size_t(len(value))) - for i := range value { - C.zwbytes_set(zwbytes, C.size_t(i), C.uint8_t(value[i])) - } - ok := bool(C.manager_setValueBytes(cmanager, cvalueid, zwbytes)) - C.zwbytes_free(zwbytes) - if ok == false { - return fmt.Errorf("value is not of raw type") - } - return nil -} - -// SetValueString sets the value from a string, regardless of type. It will -// return an error if the value could not be parsed into the correct type for -// the value. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueString(homeID uint32, valueID uint64, value string) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(value) - ok := bool(C.manager_setValueString(cmanager, cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - if ok == false { - return fmt.Errorf("could not parse string into correct type for value") - } - return nil -} - -// SetValueListSelection sets the selected item in a list. It will return an -// error if the value is not of list type or if the selection is not in the -// list. -// -// Due to the possibility of a device being asleep, the command is assumed to -// succeed, and the value held by the node is updated directly. This will be -// reverted by a future status message from the device if the Z-Wave message -// actually failed to get through. Notification callbacks will be sent in both -// cases. -func SetValueListSelection(homeID uint32, valueID uint64, selection string) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - cstring := C.CString(selection) - ok := bool(C.manager_setValueListSelection(cmanager, cvalueid, cstring)) - C.free(unsafe.Pointer(cstring)) - if ok == false { - return fmt.Errorf("value is not of list type or selection is not in the list") - } - return nil -} - -// RefreshValue refreshes the specified value from the Z-Wave network. It will -// return true if the driver and node were found, otherwise false. -// -// A call to this function causes the library to send a message to the network -// to retrieve the current value of the specified ValueID (just like a poll, -// except only one-time, not recurring). -func RefreshValue(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_refreshValue(cmanager, cvalueid)) -} - -// SetChangeVerified sets a flag indicating whether value changes noted upon a -// refresh should be verified. If so, the library will immediately refresh the -// value a second time whenever a change is observed. This helps to filter out -// spurious data reported occasionally by some devices. -func SetChangeVerified(homeID uint32, valueID uint64, verify bool) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - C.manager_setChangeVerified(cmanager, cvalueid, C.bool(verify)) -} - -// GetChangeVerified returns true if value changes upon a refresh should be -// verified. If so, the library will immediately refresh the value a second time -// whenever a change is observed. This helps to filter out spurious data -// reported occasionally by some devices. -func GetChangeVerified(homeID uint32, valueID uint64) bool { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - return bool(C.manager_getChangeVerified(cmanager, cvalueid)) -} - -// PressButton starts an activity in a device. It will return an error if the -// value is not of button type. -// -// Since buttons are write-only values that do not report a state, no -// notification callbacks are sent. -func PressButton(homeID uint32, valueID uint64) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_pressButton(cmanager, cvalueid)) - if ok == false { - return fmt.Errorf("value is not of button type") - } - return nil -} - -// ReleaseButton stops an activity in a device. It will return an error if the -// value is not of button type. -// -// Since buttons are write-only values that do not report a state, no -// notification callbacks are sent. -func ReleaseButton(homeID uint32, valueID uint64) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_releaseButton(cmanager, cvalueid)) - if ok == false { - return fmt.Errorf("value is not of button type") - } - return nil -} - -// -// Also, climate control schedules. -// - -// GetNumSwitchPoints returns the number of switch points defined in a schedule. -// It will return zero if the value if not of schedule type. -func GetNumSwitchPoints(homeID uint32, valueID uint64) (uint8, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - result := uint8(C.manager_getNumSwitchPoints(cmanager, cvalueid)) - if result == 0 { - return result, fmt.Errorf("value is not of schedule type") - } - return result, nil -} - -// SetSwitchPoint sets a switch point in the schedule. It will return an error -// if the value is not of schedule type. -// -// Inserts a new switch point into the schedule, unless a switch point already -// exists at the specified time in which case that switch point is updated with -// the new setback value instead. A maximum of nine switch points can be set in -// the schedule. -func SetSwitchPoint(homeID uint32, valueID uint64, hours, minutes uint8, setback int8) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_setSwitchPoint(cmanager, cvalueid, C.uint8_t(hours), C.uint8_t(minutes), C.int8_t(setback))) - if ok == false { - return fmt.Errorf("value is not of schedule type") - } - return nil -} - -// RemoveSwitchPoint removes a switch point from the schedule. It will return an -// error if the value is not of schedule type or there is no switch point with -// the specified time values. -func RemoveSwitchPoint(homeID uint32, valueID uint64, hours, minutes uint8) error { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - ok := bool(C.manager_removeSwitchPoint(cmanager, cvalueid, C.uint8_t(hours), C.uint8_t(minutes))) - if ok == false { - return fmt.Errorf("value is not of schedule type or no switch point found with specified time values") - } - return nil -} - -// ClearSwitchPoints clears all switch points from the schedule. -func ClearSwitchPoints(homeID uint32, valueID uint64) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - C.manager_clearSwitchPoints(cmanager, cvalueid) -} - -// GetSwitchPoint returns switch point data from the schedule. It will also -// return an error if the value is not of schedule type. -// -// It retrieves the time and setback values from a switch point in the schedule. -func GetSwitchPoint(homeID uint32, valueID uint64, idx uint8) (uint8, uint8, int8, error) { - cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID)) - defer C.valueid_free(cvalueid) - var chours C.uint8_t - var cminutes C.uint8_t - var csetback C.int8_t - ok := bool(C.manager_getSwitchPoint(cmanager, cvalueid, C.uint8_t(idx), &chours, &cminutes, &csetback)) - if ok == false { - return uint8(chours), uint8(cminutes), int8(csetback), fmt.Errorf("value is not of schedule type") - } - return uint8(chours), uint8(cminutes), int8(csetback), nil -} diff --git a/valuetype_string.go b/valuetype_string.go new file mode 100644 index 0000000..01f9b86 --- /dev/null +++ b/valuetype_string.go @@ -0,0 +1,33 @@ +// Code generated by "stringer -trimprefix=ValueType_ -type=ValueType"; DO NOT EDIT. + +package goopenzwave + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ValueType_Bool-0] + _ = x[ValueType_Byte-1] + _ = x[ValueType_Decimal-2] + _ = x[ValueType_Int-3] + _ = x[ValueType_List-4] + _ = x[ValueType_Schedule-5] + _ = x[ValueType_Short-6] + _ = x[ValueType_String-7] + _ = x[ValueType_Button-8] + _ = x[ValueType_Raw-9] + _ = x[ValueType_BitSet-10] +} + +const _ValueType_name = "BoolByteDecimalIntListScheduleShortStringButtonRawBitSet" + +var _ValueType_index = [...]uint8{0, 4, 8, 15, 18, 22, 30, 35, 41, 47, 50, 56} + +func (i ValueType) String() string { + if i >= ValueType(len(_ValueType_index)-1) { + return "ValueType(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]] +} diff --git a/zwbytes.cpp b/zwbytes.cpp deleted file mode 100644 index 7dbc568..0000000 --- a/zwbytes.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "zwbytes.h" -#include -#include -#include - -zwbytes_t* zwbytes_new() -{ - zwbytes_t *bytes = (zwbytes_t*)malloc(sizeof(zwbytes_t)); - bytes->data = NULL; - bytes->size = 0; - return bytes; -} - -void zwbytes_reserve(zwbytes_t *bytes, size_t size) -{ - bytes->data = (uint8_t*)realloc(bytes->data, size * sizeof(uint8_t)); - bytes->size = size; -} - -void zwbytes_set(zwbytes_t *bytes, size_t pos, uint8_t val) -{ - if (pos >= bytes->size) return; - bytes->data[pos] = val; -} - -uint8_t zwbytes_at(zwbytes_t *bytes, size_t pos) -{ - if (pos >= bytes->size) return 0; - return bytes->data[pos]; -} - -void zwbytes_free(zwbytes_t *bytes) -{ - if (bytes->data != NULL) { - free(bytes->data); - } - free(bytes); -} diff --git a/zwbytes.h b/zwbytes.h deleted file mode 100644 index 75e9998..0000000 --- a/zwbytes.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef ZWBYTES_H -#define ZWBYTES_H - -#include - -#ifdef __cplusplus -#include -#include -extern "C" { -#endif - -/** - * zwbytes_t is a container for byte arrays. - */ -typedef struct { - uint8_t* data; - size_t size; -} zwbytes_t; - -/** - * zwbytes_new creates and returns a new, empty zwbytes_t object. Make sure to - * destroy it when finished with zwbytes_free. - * @return An empty zwbytes_t object. - */ -zwbytes_t* zwbytes_new(); - -/** - * zwbytes_reserve resizes the zwbytes_t, if necessary, to the new size. - * @param bytes The zwbytes_t object to operate on. - * @param size The new size. - */ -void zwbytes_reserve(zwbytes_t *bytes, size_t size); - -/** - * zwbytes_set sets the value of the byte at the given position. - * @param bytes The zwbytes_t object to operate on. - * @param pos The position of the byte to set. - * @param val The byte value to set. - */ -void zwbytes_set(zwbytes_t *bytes, size_t pos, uint8_t val); - -/** - * zwbytes_at returns the value of the byte at the given position. - * @param bytes The zwbytes_t object to operate on. - * @param pos The position of the byte to get. - * @return The value of the byte. - */ -uint8_t zwbytes_at(zwbytes_t *bytes, size_t pos); - -/** - * zwbytes_free frees the zwbytes_t object. - * @param list The zwbytes_t object to free. - */ -void zwbytes_free(zwbytes_t *bytes); - -#ifdef __cplusplus -} // end extern "C" -#endif - -#endif // define ZWBYTES_H diff --git a/zwlist.cpp b/zwlist.cpp deleted file mode 100644 index 39f317e..0000000 --- a/zwlist.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "zwlist.h" -#include -#include -#include - -zwlist_t *zwlist_new() -{ - std::vector *vec = new std::vector(); - assert(vec); - return (zwlist_t*)vec; -} - -size_t zwlist_size(zwlist_t *list) -{ - assert(list); - std::vector *vec = (std::vector*)list; - return vec->size(); -} - -char* zwlist_at(zwlist_t *list, size_t pos) -{ - assert(list); - std::vector *vec = (std::vector*)list; - char* cstr = strdup(vec->at(pos).c_str()); - return cstr; -} - -void zwlist_free(zwlist_t *list) -{ - assert(list); - std::vector *vec = (std::vector*)list; - delete vec; -} - -zwlist_t* zwlist_copy(std::vector &vec) -{ - std::vector *out = new std::vector(vec); - assert(out); - return (zwlist_t*)out; -} diff --git a/zwlist.h b/zwlist.h deleted file mode 100644 index dff31fb..0000000 --- a/zwlist.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef ZWLIST_H -#define ZWLIST_H - -#include - -#ifdef __cplusplus -#include -#include -extern "C" { -#endif - -/** - * zwlist_t is a C-friendly wrapper around a std::vector*. - */ -typedef void* zwlist_t; - -/** - * zwlist_new creates and returns a new, empty zwlist_t object. Make sure to - * destroy it when finished with zwlist_free. - * @return An empty zwlist_t object. - */ -zwlist_t* zwlist_new(); - -/** - * zwlist_size returns the size of the zwlist_t object. - * @param list The zwlist_t object to operate on. - * @return The number of items in the zwlist_t. - */ -size_t zwlist_size(zwlist_t *list); - -/** - * zwlist_at returns a copy of the item from the given position in the list. The - * caller must free the returned string when finished. - * @param list The zwlist_t object to operate on. - * @param pos The position of the item to return within the list. - * @return A copy of the item string. Free when finished. - */ -char* zwlist_at(zwlist_t *list, size_t pos); - -/** - * zwlist_free frees the zwlist_t object. - * @param list The zwlist_t object to free. - */ -void zwlist_free(zwlist_t *list); - -#ifdef __cplusplus -} // end extern "C" - -/** - * zwlist_copy copies the vector and returns it. Make sure to destroy it when - * finished with zwlist_free. - * @param vec The vector to copy. - * @return A new zwlist_t object containing a copy of vec. - */ -zwlist_t* zwlist_copy(std::vector &vec); - -#endif - -#endif // define ZWLIST_H