├── .gitignore ├── .travis.yml ├── DEVICES.md ├── LICENSE ├── README.md ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── whizzosoftware │ │ │ └── wzwave │ │ │ ├── ZWaveRuntimeException.java │ │ │ ├── channel │ │ │ ├── ACKInboundHandler.java │ │ │ ├── FrameQueueHandler.java │ │ │ ├── TransactionInboundHandler.java │ │ │ ├── TransactionTimeoutHandler.java │ │ │ ├── ZWaveChannelContext.java │ │ │ ├── ZWaveChannelInboundHandler.java │ │ │ ├── ZWaveChannelListener.java │ │ │ └── event │ │ │ │ ├── DataFrameSentEvent.java │ │ │ │ ├── NodeSleepChangeEvent.java │ │ │ │ ├── SendDataTransactionCompletedEvent.java │ │ │ │ ├── SendDataTransactionFailedEvent.java │ │ │ │ ├── TransactionCompletedEvent.java │ │ │ │ ├── TransactionFailedEvent.java │ │ │ │ ├── TransactionStartedEvent.java │ │ │ │ └── TransactionTimeoutEvent.java │ │ │ ├── codec │ │ │ ├── ZWaveFrameDecoder.java │ │ │ └── ZWaveFrameEncoder.java │ │ │ ├── commandclass │ │ │ ├── AlarmCommandClass.java │ │ │ ├── AlarmSensorCommandClass.java │ │ │ ├── BasicCommandClass.java │ │ │ ├── BatteryCommandClass.java │ │ │ ├── BinarySensorCommandClass.java │ │ │ ├── BinarySwitchCommandClass.java │ │ │ ├── ColorControlCommandClass.java │ │ │ ├── CommandClass.java │ │ │ ├── CommandClassFactory.java │ │ │ ├── CommandClassParseException.java │ │ │ ├── IndicatorCommandClass.java │ │ │ ├── ManufacturerSpecificCommandClass.java │ │ │ ├── MeterCommandClass.java │ │ │ ├── MultiInstanceCommandClass.java │ │ │ ├── MultilevelSensorCommandClass.java │ │ │ ├── MultilevelSwitchCommandClass.java │ │ │ ├── NoOperationCommandClass.java │ │ │ ├── VersionCommandClass.java │ │ │ └── WakeUpCommandClass.java │ │ │ ├── controller │ │ │ ├── ZWaveController.java │ │ │ ├── ZWaveControllerContext.java │ │ │ ├── ZWaveControllerListener.java │ │ │ └── netty │ │ │ │ └── NettyZWaveController.java │ │ │ ├── frame │ │ │ ├── ACK.java │ │ │ ├── AddNodeToNetwork.java │ │ │ ├── ApplicationCommand.java │ │ │ ├── ApplicationUpdate.java │ │ │ ├── CAN.java │ │ │ ├── DataFrame.java │ │ │ ├── DataFrameType.java │ │ │ ├── Frame.java │ │ │ ├── GetRoutingInfo.java │ │ │ ├── GetSUCNodeId.java │ │ │ ├── InitData.java │ │ │ ├── MemoryGetId.java │ │ │ ├── NAK.java │ │ │ ├── NodeProtocolInfo.java │ │ │ ├── OutboundDataFrame.java │ │ │ ├── RemoveNodeFromNetwork.java │ │ │ ├── RequestNodeInfo.java │ │ │ ├── SendData.java │ │ │ ├── SetDefault.java │ │ │ ├── Version.java │ │ │ └── transaction │ │ │ │ ├── AbstractDataFrameTransaction.java │ │ │ │ ├── DataFrameTransaction.java │ │ │ │ ├── NodeInclusionTransaction.java │ │ │ │ ├── RequestCallbackTransaction.java │ │ │ │ ├── RequestNodeInfoTransaction.java │ │ │ │ ├── RequestResponseCallbackTransaction.java │ │ │ │ ├── RequestResponseTransaction.java │ │ │ │ └── SendDataTransaction.java │ │ │ ├── node │ │ │ ├── BasicDeviceClasses.java │ │ │ ├── MultiChannelEncapsulatingNodeContext.java │ │ │ ├── NodeContext.java │ │ │ ├── NodeCreationException.java │ │ │ ├── NodeInfo.java │ │ │ ├── NodeListener.java │ │ │ ├── WrapperedNodeContext.java │ │ │ ├── ZWaveEndpoint.java │ │ │ ├── ZWaveMultiChannelEndpoint.java │ │ │ ├── ZWaveNode.java │ │ │ ├── ZWaveNodeFactory.java │ │ │ ├── ZWaveNodeState.java │ │ │ ├── generic │ │ │ │ ├── AlarmSensor.java │ │ │ │ ├── BinarySensor.java │ │ │ │ ├── BinarySwitch.java │ │ │ │ ├── Meter.java │ │ │ │ ├── MultilevelSensor.java │ │ │ │ ├── MultilevelSwitch.java │ │ │ │ └── StaticController.java │ │ │ └── specific │ │ │ │ ├── AdvancedZensorNetAlarmSensor.java │ │ │ │ ├── AdvancedZensorNetSmokeSensor.java │ │ │ │ ├── BasicRoutingAlarmSensor.java │ │ │ │ ├── BasicRoutingSmokeSensor.java │ │ │ │ ├── BasicZensorNetAlarmSensor.java │ │ │ │ ├── BasicZensorNetSmokeSensor.java │ │ │ │ ├── BinaryPowerSwitch.java │ │ │ │ ├── MultilevelPowerSwitch.java │ │ │ │ ├── PCController.java │ │ │ │ ├── RoutingAlarmSensor.java │ │ │ │ ├── RoutingBinarySensor.java │ │ │ │ ├── RoutingSmokeSensor.java │ │ │ │ ├── SimpleMeter.java │ │ │ │ ├── ZensorNetAlarmSensor.java │ │ │ │ └── ZensorNetSmokeSensor.java │ │ │ ├── persist │ │ │ ├── PersistenceContext.java │ │ │ ├── PersistentStore.java │ │ │ └── mapdb │ │ │ │ ├── MapDbPersistenceContext.java │ │ │ │ └── MapDbPersistentStore.java │ │ │ ├── product │ │ │ ├── ProductInfo.java │ │ │ └── ProductRegistry.java │ │ │ └── util │ │ │ └── ByteUtil.java │ └── resources │ │ └── logback.xml └── test │ └── java │ └── com │ └── whizzosoftware │ └── wzwave │ ├── MockChannel.java │ ├── channel │ ├── FrameQueueHandlerTest.java │ ├── MockChannelHandlerContext.java │ ├── MockZWaveChannelContext.java │ └── TransactionInboundHandlerTest.java │ ├── codec │ ├── ZWaveFrameDecoderTest.java │ └── ZWaveFrameEncoderTest.java │ ├── commandclass │ ├── ColorControlCommandClassTest.java │ ├── CommandClassFactoryTest.java │ ├── IndicatorCommandClassTest.java │ ├── ManufacturerSpecificCommandClassTest.java │ ├── MeterCommandClassTest.java │ ├── MultiInstanceCommandClassTest.java │ ├── MultilevelCommandClassTest.java │ └── VersionCommandClassTest.java │ ├── controller │ ├── MockZWaveControllerContext.java │ └── netty │ │ └── NettyZWaveControllerTest.java │ ├── frame │ ├── AddNodeToNetworkTest.java │ ├── ApplicationCommandTest.java │ ├── ApplicationUpdateTest.java │ ├── InitDataTest.java │ ├── MemoryGetIdTest.java │ ├── NodeProtocolInfoTest.java │ ├── RequestNodeInfoTest.java │ ├── SendDataTest.java │ ├── VersionTest.java │ └── transaction │ │ ├── RequestCallbackTransactionTest.java │ │ ├── RequestNodeInfoTransactionTest.java │ │ ├── RequestResponseTransactionTest.java │ │ └── SendDataTransactionTest.java │ ├── node │ ├── BinarySwitchTest.java │ ├── MockNodeContext.java │ ├── MultiChannelEncapsulatingNodeContextTest.java │ ├── MultiInstanceBinaryPowerSwitchTest.java │ ├── RoutingBinarySensorTest.java │ ├── StaticControllerTest.java │ ├── ZWaveNodeFactoryTest.java │ └── ZWaveNodeTest.java │ ├── persist │ ├── MapDbPersistentStoreTest.java │ ├── MockPersistenceContext.java │ └── MockPersistentStore.java │ ├── product │ └── ProductRegistryTest.java │ └── util │ └── ByteUtilTest.java └── wzwave.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij stuff 2 | *.iml 3 | .idea 4 | 5 | 6 | # GEdit backups 7 | *.*~ 8 | 9 | # Built application files 10 | *.apk 11 | *.ap_ 12 | 13 | # Files for the Dalvik VM 14 | *.dex 15 | 16 | # Java class files 17 | *.class 18 | 19 | # Generated files 20 | bin/ 21 | gen/ 22 | 23 | # Gradle files 24 | .gradle/ 25 | build/ 26 | 27 | # Local configuration file (sdk path, etc) 28 | local.properties 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | # Log Files 34 | *.log 35 | 36 | *.class 37 | 38 | # Package Files # 39 | *.jar 40 | *.war 41 | *.ear 42 | 43 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 44 | hs_err_pid* 45 | 46 | #eclipse 47 | .classpath 48 | .project 49 | .settings 50 | target 51 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | cache: 4 | directories: 5 | - $HOME/.m2 6 | matrix: 7 | include: 8 | - name: "Javadoc" 9 | env: 10 | - TEST_SUITE='javadoc:jar' 11 | - TEST_TAG=javadoc 12 | - name: "Unit tests" 13 | env: 14 | - TEST_SUITE='test jacoco:report coveralls:report' 15 | - TEST_TAG=utest 16 | script: 17 | - mvn $TEST_SUITE -B 18 | after_success: 19 | - echo $TEST_TAG 20 | - echo $TRAVIS_REPO_SLUG 21 | - echo $TRAVIS_BRANCH 22 | - echo $TRAVIS_PULL_REQUEST 23 | - echo $TRAVIS_TEST_RESULT 24 | - test $TEST_TAG = utest && test $TRAVIS_REPO_SLUG = whizzosoftware/WZWave && test $TRAVIS_BRANCH = master && test $TRAVIS_PULL_REQUEST = false && test $TRAVIS_TEST_RESULT = 0 && echo "oss-jfrog-artifactory-snapshots\${env.OSSRH_USER}\${env.OSSRH_PASS}" > ~/settings.xml 25 | - test $TEST_TAG = utest && test $TRAVIS_REPO_SLUG = whizzosoftware/WZWave && test $TRAVIS_BRANCH = master && test $TRAVIS_PULL_REQUEST = false && test $TRAVIS_TEST_RESULT = 0 && mvn deploy --settings ~/settings.xml 26 | -------------------------------------------------------------------------------- /DEVICES.md: -------------------------------------------------------------------------------- 1 | # Supported Devices 2 | 3 | This document provides a list of the current Z-Wave devices that have been tested with the WZWave library. 4 | 5 | Currently, a device on the supported list means that it was successfully tested by a WZWave user. Minimally, it shows up as a recognized device type (e.g. Unknown Switch) and it's primary function can be accessed (e.g. the switch can be turned on/off). Additional functionality may or may not be present (e.g. a power outlet may be controllable but not yet report energy usage). 6 | 7 | If the device supports the Z-Wave "Manufacturer Specific" command class, then ideally the manufacturer name and device name have been entered in WZWave so that it can be recognized more specifically (e.g. Aeon Labs Smart Energy Strip). 8 | 9 | Manufacturer | Name | Device Type 10 | -------------|---------------------------|-------------------- 11 | Aeon Labs | Home Energy Meter | Power monitor 12 | Aeon Labs | Home Energy Meter G2 | Power monitor 13 | Aeon Labs | Smart Energy Strip | Power outlet 14 | Aeon Labs | Smart Energy Switch | Power outlet 15 | Aeon Labs | Water sensor | Sensor 16 | Aeon Labs | Z-Stick 2 | PC Controller 17 | Everspring | SM103 Door/Window Sensor | Sensor 18 | Fibargroup | Metered Wall Plug Switch | Power outlet 19 | GE / Jasco | 45604 Outdoor Module | Power outlet 20 | GE / Jasco | 45609 Relay switch | Power outlet 21 | GE / Jasco | 45612 Dimmer switch | Light dimmer/switch 22 | Philio | PAN11 Smart Energy Switch | Power outlet 23 | Z-Wave.Me | UZB | PC Controller -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/whizzosoftware/WZWave.svg)](https://travis-ci.org/whizzosoftware/WZWave) 2 | [![Coverage Status](https://coveralls.io/repos/whizzosoftware/WZWave/badge.svg)](https://coveralls.io/r/whizzosoftware/WZWave) 3 | 4 | ## Overview 5 | 6 | The goal of this project is to create a Java-native, open-source library for controlling Z-Wave 7 | PC controllers. 8 | 9 | Z-Wave is a wireless protocol used for home automation. It use low-power RF to control smart devices such as 10 | lights, power outlets, thermostats and more. A PC controller (e.g. a USB dongle) provides applications a gateway 11 | to the wireless Z-Wave device network. More information can be found at 12 | [this Wikipedia article](http://en.wikipedia.org/wiki/Z-Wave). 13 | 14 | WZWave was primarily created to add Z-Wave support to the open source [Hobson automation hub](http://hobson-automation.com). 15 | 16 | ![](https://raw.githubusercontent.com/whizzosoftware/WZWave/master/wzwave.jpg) 17 | 18 | ### Why Z-Wave? 19 | 20 | The Z-Wave alliance has over 250 independent manufacturers as of 2014 (source: Wikipedia) including big names like 21 | GE, ADT, Ingersoll-Rand and Trane. The smart devices are relatively inexpensive, readily available and interoperable 22 | between manufacturers (something that can't be said for some other wireless home automation technologies out there). 23 | 24 | ### Why WZWave? 25 | 26 | The biggest drawback with Z-Wave is the PC controller serial protocol is not freely available. ~~To obtain official 27 | information requires signing an NDA and paying a hefty fee to get the Z-Wave SDK. As I understand it, software 28 | developed under the NDA cannot be made freely available.~~ Hence the need for projects like this. 29 | 30 | **Update:** Sigma Designs has made a good portion of the Z-Wave API public and available without requiring an NDA. It 31 | is available from the 32 | [Z-Wave Public Specification website](http://z-wave.sigmadesigns.com/design-z-wave/z-wave-public-specification/). 33 | 34 | In my research, I was unable to find any native Java libraries that would interface with a Z-Wave controller. Granted, 35 | there were libraries that used JNI to wrapper the excellent 36 | [open-zwave library](https://code.google.com/p/open-zwave/) but that meant deferring most of the work to a binary 37 | library. Thus, WZWave was created to be a fully Java-native solution. 38 | 39 | WZWave was created using a combination of studying online resources, studying the open-zwave project as well as 40 | copious amounts of reverse engineering. 41 | 42 | Note: The project is not affiliated or endorsed by Sigma Designs and only publicly available resources were used in 43 | its creation. 44 | 45 | ### Status 46 | 47 | WZWave is still very early days and is under active development. Only a limited subset of devices have been tested 48 | but support will continue to grow over time. 49 | 50 | I encourage anyone that wants to get involved to please do so. The project really needs developers to get involved 51 | to help increase robustness and device support! 52 | 53 | Please see the project's [wiki page](https://whizzosoftware.atlassian.net/wiki/display/WZWAV/WZWave+Home) for more 54 | information. 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/ZWaveRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave; 11 | 12 | public class ZWaveRuntimeException extends RuntimeException { 13 | public ZWaveRuntimeException(String message) { 14 | super(message); 15 | } 16 | 17 | public ZWaveRuntimeException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/ACKInboundHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel; 11 | 12 | import com.whizzosoftware.wzwave.frame.ACK; 13 | import com.whizzosoftware.wzwave.frame.DataFrame; 14 | import io.netty.channel.ChannelHandlerContext; 15 | import io.netty.channel.ChannelInboundHandlerAdapter; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | /** 20 | * An inbound handler that sends ACK frames when necessary. 21 | * 22 | * @author Dan Noguerol 23 | */ 24 | public class ACKInboundHandler extends ChannelInboundHandlerAdapter { 25 | private static final Logger logger = LoggerFactory.getLogger(ZWaveChannelInboundHandler.class); 26 | 27 | @Override 28 | public void channelRead(ChannelHandlerContext ctx, Object msg) { 29 | if (msg instanceof DataFrame) { 30 | logger.trace("Sending ACK for received data frame: {}", msg); 31 | ctx.channel().writeAndFlush(new ACK()); 32 | } 33 | ctx.fireChannelRead(msg); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/TransactionTimeoutHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel; 11 | 12 | import com.whizzosoftware.wzwave.channel.event.TransactionTimeoutEvent; 13 | import io.netty.channel.ChannelHandlerContext; 14 | import io.netty.channel.ChannelInboundHandler; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | /** 19 | * Handles the situation where a data frame transaction times out. It will alert its handler so follow-on 20 | * action can be taken. 21 | * 22 | * @author Dan Noguerol 23 | */ 24 | public class TransactionTimeoutHandler implements Runnable { 25 | private static final Logger logger = LoggerFactory.getLogger(TransactionTimeoutHandler.class); 26 | 27 | private String id; 28 | private ChannelHandlerContext context; 29 | private ChannelInboundHandler handler; 30 | 31 | public TransactionTimeoutHandler(String id, ChannelHandlerContext context, ChannelInboundHandler handler) { 32 | this.id = id; 33 | this.context = context; 34 | this.handler = handler; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | @Override 42 | public void run() { 43 | try { 44 | handler.userEventTriggered(context, new TransactionTimeoutEvent(id)); 45 | } catch (Exception e) { 46 | logger.error("Error timing out transaction", e); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/ZWaveChannelContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel; 11 | 12 | import com.whizzosoftware.wzwave.frame.OutboundDataFrame; 13 | 14 | /** 15 | * An interface that allows firing events and writing data frames. 16 | * 17 | * @author Dan Noguerol 18 | */ 19 | public interface ZWaveChannelContext { 20 | void fireEvent(Object o); 21 | void writeFrame(OutboundDataFrame f); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/ZWaveChannelListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel; 11 | 12 | import com.whizzosoftware.wzwave.channel.event.TransactionCompletedEvent; 13 | import com.whizzosoftware.wzwave.channel.event.TransactionFailedEvent; 14 | import com.whizzosoftware.wzwave.channel.event.TransactionStartedEvent; 15 | import com.whizzosoftware.wzwave.frame.*; 16 | 17 | /** 18 | * An interface with callbacks of interest from the Z-Wave network. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public interface ZWaveChannelListener { 23 | void onLibraryInfo(String libraryVersion); 24 | void onControllerInfo(int homeId, byte nodeId); 25 | void onNodeProtocolInfo(byte nodeId, NodeProtocolInfo nodeProtocolInfo); 26 | void onApplicationCommand(ApplicationCommand cmd); 27 | void onApplicationUpdate(ApplicationUpdate update); 28 | void onTransactionStarted(TransactionStartedEvent evt); 29 | void onTransactionComplete(TransactionCompletedEvent evt); 30 | void onTransactionFailed(TransactionFailedEvent evt); 31 | 32 | /** 33 | * Called when an AddNodeToNetwork frame is received. 34 | * 35 | * @param addNode the received frame 36 | */ 37 | void onAddNodeToNetwork(AddNodeToNetwork addNode); 38 | 39 | /** 40 | * Called when a RemoveNodeFromNetwork frame is received. 41 | * 42 | * @param removeNode the received frame 43 | */ 44 | void onRemoveNodeFromNetwork(RemoveNodeFromNetwork removeNode); 45 | 46 | /** 47 | * Called when a SetDefault frame is received due to the controller being factory reset. 48 | */ 49 | void onSetDefault(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/DataFrameSentEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | /** 15 | * An event fired when a data frame is sent to the Z-Wave network. 16 | * 17 | * @author Dan Noguerol 18 | */ 19 | public class DataFrameSentEvent { 20 | private DataFrame dataFrame; 21 | private boolean listeningNode; 22 | 23 | /** 24 | * Constructor. 25 | * 26 | * @param dataFrame the data frame that was sent 27 | * @param listeningNode indicates if the destination node is a listening node 28 | */ 29 | public DataFrameSentEvent(DataFrame dataFrame, boolean listeningNode) { 30 | this.dataFrame = dataFrame; 31 | this.listeningNode = listeningNode; 32 | } 33 | 34 | public DataFrame getDataFrame() { 35 | return dataFrame; 36 | } 37 | 38 | public boolean isListeningNode() { 39 | return listeningNode; 40 | } 41 | 42 | @Override 43 | public String toString() 44 | { 45 | return "DataFrameSentEvent{" + 46 | "listeningNode=" + isListeningNode() + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/NodeSleepChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | /** 13 | * An event sent when a node's sleeping state has changed. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class NodeSleepChangeEvent { 18 | private byte nodeId; 19 | private boolean sleeping; 20 | 21 | public NodeSleepChangeEvent(byte nodeId, boolean sleeping) { 22 | this.nodeId = nodeId; 23 | this.sleeping = sleeping; 24 | } 25 | 26 | public byte getNodeId() { 27 | return nodeId; 28 | } 29 | 30 | public boolean isSleeping() { 31 | return sleeping; 32 | } 33 | 34 | @Override 35 | public String toString() 36 | { 37 | return "NodeSleepChangeEvent{" + 38 | "sleeping=" + isSleeping() + 39 | ", nodeId=" + getNodeId() + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/SendDataTransactionCompletedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | public class SendDataTransactionCompletedEvent extends TransactionCompletedEvent { 15 | public SendDataTransactionCompletedEvent(String id, DataFrame frame, byte nodeId) { 16 | super(id, frame, nodeId); 17 | } 18 | 19 | @Override 20 | public String toString() 21 | { 22 | return "SendDataTransactionCompletedEvent{" + 23 | "id=" + getId() + 24 | ", nodeId=" + getNodeId() + 25 | '}'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/SendDataTransactionFailedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | public class SendDataTransactionFailedEvent extends TransactionFailedEvent { 15 | private boolean listeningNode; 16 | private boolean tgtNodeACKReceived; 17 | 18 | public SendDataTransactionFailedEvent(String id, DataFrame startFrame, byte nodeId, boolean listeningNode, boolean tgtNodeACKReceived) { 19 | super(id, startFrame, nodeId); 20 | this.listeningNode = listeningNode; 21 | this.tgtNodeACKReceived = tgtNodeACKReceived; 22 | } 23 | 24 | public boolean isListeningNode() { 25 | return listeningNode; 26 | } 27 | 28 | public boolean isTargetNodeACKReceived() { 29 | return tgtNodeACKReceived; 30 | } 31 | 32 | @Override 33 | public String toString() 34 | { 35 | return "SendDataTransactionFailedEvent{" + 36 | "id=" + getId() + 37 | ", nodeId=" + getNodeId() + 38 | ", listeningNode=" + isListeningNode() + 39 | ", tgtNodeACKReceived=" + isTargetNodeACKReceived() + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/TransactionCompletedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | /** 15 | * A user event that indicates a Z-Wave data frame transaction has completed. 16 | * 17 | * @author Dan Noguerol 18 | */ 19 | public class TransactionCompletedEvent { 20 | private String id; 21 | private DataFrame frame; 22 | private Byte nodeId; 23 | 24 | /** 25 | * Constructor. 26 | * 27 | * @param id the transaction ID 28 | * @param frame the data frame associated with the completed transaction 29 | */ 30 | public TransactionCompletedEvent(String id, DataFrame frame) { 31 | this.id = id; 32 | this.frame = frame; 33 | } 34 | 35 | /** 36 | * Constructor. 37 | * 38 | * @param id the transaction ID 39 | * @param frame the data frame associated with the completed transaction 40 | * @param nodeId the node ID associated with the transaction 41 | */ 42 | public TransactionCompletedEvent(String id, DataFrame frame, byte nodeId) { 43 | this(id, frame); 44 | this.nodeId = nodeId; 45 | } 46 | 47 | public String getId() { 48 | return id; 49 | } 50 | 51 | public boolean hasFrame() { 52 | return (frame != null); 53 | } 54 | 55 | public DataFrame getFrame() { 56 | return frame; 57 | } 58 | 59 | public Byte getNodeId() { 60 | return nodeId; 61 | } 62 | 63 | @Override 64 | public String toString() 65 | { 66 | return "TransactionCompletedEvent{" + 67 | "id=" + getId() + 68 | ", nodeId=" + getNodeId() + 69 | '}'; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/TransactionFailedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | /** 15 | * A user event that indicates a Z-Wave data frame transaction has failed. 16 | * 17 | * @author Dan Noguerol 18 | */ 19 | public class TransactionFailedEvent { 20 | private String id; 21 | private Byte nodeId; 22 | private DataFrame startFrame; 23 | 24 | /** 25 | * Constructor. 26 | * 27 | * @param id the transaction ID 28 | * @param startFrame the data frame that initiated the transaction 29 | */ 30 | public TransactionFailedEvent(String id, DataFrame startFrame) { 31 | this(id, startFrame, null); 32 | } 33 | 34 | /** 35 | * Constructor. 36 | * 37 | * @param id the transaction ID 38 | * @param startFrame the data frame that initiated the transaction 39 | * @param nodeId the node ID associated with the transaction 40 | */ 41 | public TransactionFailedEvent(String id, DataFrame startFrame, Byte nodeId) { 42 | this.id = id; 43 | this.nodeId = nodeId; 44 | this.startFrame = startFrame; 45 | } 46 | 47 | public String getId() { 48 | return id; 49 | } 50 | 51 | public Byte getNodeId() { 52 | return nodeId; 53 | } 54 | 55 | public boolean hasStartFrame() { 56 | return (startFrame != null); 57 | } 58 | 59 | public DataFrame getStartFrame() { 60 | return startFrame; 61 | } 62 | 63 | @Override 64 | public String toString() 65 | { 66 | return "TransactionFailedEvent{" + 67 | "id=" + getId() + 68 | ", nodeId=" + getNodeId() + 69 | '}'; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/TransactionStartedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | /** 13 | * A user event that indicates a Z-Wave data frame transaction has started. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class TransactionStartedEvent { 18 | private String id; 19 | 20 | public TransactionStartedEvent(String id) { 21 | this.id = id; 22 | } 23 | 24 | public String getId() { 25 | return id; 26 | } 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "TransactionStartedEvent{" + 32 | "id=" + getId() + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/channel/event/TransactionTimeoutEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel.event; 11 | 12 | /** 13 | * A user event that indicates a Z-Wave data frame transaction has timed out. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class TransactionTimeoutEvent { 18 | private String id; 19 | 20 | public TransactionTimeoutEvent(String id) { 21 | this.id = id; 22 | } 23 | 24 | public String getId() { 25 | return id; 26 | } 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "TransactionTimeoutEvent{" + 32 | "id=" + getId() + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/codec/ZWaveFrameEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.codec; 11 | 12 | import com.whizzosoftware.wzwave.frame.*; 13 | import com.whizzosoftware.wzwave.util.ByteUtil; 14 | import io.netty.buffer.ByteBuf; 15 | import io.netty.channel.ChannelHandlerContext; 16 | import io.netty.handler.codec.MessageToByteEncoder; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | /** 21 | * Class responsible for converting a Z-Wave frame into a stream of bytes. 22 | * 23 | * @author Dan Noguerol 24 | */ 25 | public class ZWaveFrameEncoder extends MessageToByteEncoder { 26 | private static final Logger logger = LoggerFactory.getLogger(ZWaveFrameEncoder.class); 27 | 28 | @Override 29 | protected void encode(ChannelHandlerContext channelHandlerContext, Frame frame, ByteBuf byteBuf) throws Exception { 30 | byte[] bytes = frame.getBytes(); 31 | logger.debug("SENT {}: {}", frame.toString(), ByteUtil.createString(bytes, bytes.length)); 32 | byteBuf.writeBytes(bytes); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/AlarmCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | public class AlarmCommandClass extends CommandClass { 17 | private final Logger logger = LoggerFactory.getLogger(getClass()); 18 | 19 | public static final byte ALARM_GET = 0x04; 20 | public static final byte ALARM_REPORT = 0x05; 21 | 22 | public static final byte ID = (byte)0x71; 23 | 24 | private byte type; 25 | private byte level; 26 | 27 | @Override 28 | public byte getId() { 29 | return ID; 30 | } 31 | 32 | @Override 33 | public String getName() { 34 | return "COMMAND_CLASS_ALARM"; 35 | } 36 | 37 | public byte getType() { 38 | return type; 39 | } 40 | 41 | public byte getLevel() { 42 | return level; 43 | } 44 | 45 | @Override 46 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 47 | if (ccb[startIndex+1] == ALARM_REPORT) { 48 | type = ccb[startIndex+2]; 49 | level = ccb[startIndex+3]; 50 | } else { 51 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 52 | } 53 | } 54 | 55 | @Override 56 | public int queueStartupMessages(NodeContext context, byte nodeId) { 57 | context.sendDataFrame(createGet(nodeId)); 58 | return 1; 59 | } 60 | 61 | public DataFrame createGet(byte nodeId) { 62 | return createSendDataFrame("ALARM_GET", nodeId, new byte[] {AlarmCommandClass.ID, ALARM_GET}, true); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "AlarmCommandClass{" + 68 | "version=" + getVersion() + 69 | ", type=" + type + 70 | ", level=" + level + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/AlarmSensorCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Alarm Sensor Command Class. 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class AlarmSensorCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | public static final byte SENSOR_ALARM_GET = 0x01; 25 | public static final byte SENSOR_ALARM_REPORT = 0x02; 26 | 27 | public static final byte ID = (byte)0x9C; 28 | 29 | private Type type; 30 | private byte level; 31 | 32 | @Override 33 | public byte getId() { 34 | return ID; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "COMMAND_CLASS_SENSOR_ALARM"; 40 | } 41 | 42 | public Type getType() { 43 | return type; 44 | } 45 | 46 | public byte getLevel() { 47 | return level; 48 | } 49 | 50 | @Override 51 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 52 | if (ccb[startIndex+1] == SENSOR_ALARM_REPORT) { 53 | type = Type.convert(ccb[startIndex+2]); 54 | level = ccb[startIndex+3]; 55 | } else { 56 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 57 | } 58 | } 59 | 60 | @Override 61 | public int queueStartupMessages(NodeContext context, byte nodeId) { 62 | context.sendDataFrame(createGet(nodeId)); 63 | return 1; 64 | } 65 | 66 | public DataFrame createGet(byte nodeId) { 67 | return createSendDataFrame("SENSOR_ALARM_GET", nodeId, new byte[] {AlarmSensorCommandClass.ID, SENSOR_ALARM_GET}, true); 68 | } 69 | 70 | public enum Type { 71 | GENERAL, 72 | SMOKE, 73 | CARBON_MONOXIDE, 74 | CARBON_DIOXIDE, 75 | HEAT, 76 | FLOOD; 77 | 78 | public static Type convert(byte b) { 79 | return Type.values()[b]; 80 | } 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return "AlarmSensorCommandClass{" + 86 | "version=" + getVersion() + 87 | ", type=" + type + 88 | ", level=" + level + 89 | '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/BasicCommandClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.commandclass; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | import com.whizzosoftware.wzwave.node.NodeContext; 14 | import com.whizzosoftware.wzwave.util.ByteUtil; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | /** 19 | * Basic Command Class 20 | * 21 | * @author Dan Noguerol 22 | */ 23 | public class BasicCommandClass extends CommandClass { 24 | private final Logger logger = LoggerFactory.getLogger(getClass()); 25 | 26 | public static final byte BASIC_SET = 0x01; 27 | public static final byte BASIC_GET = 0x02; 28 | public static final byte BASIC_REPORT = 0x03; 29 | 30 | public static final byte ID = (byte)0x20; 31 | 32 | private Byte value; 33 | 34 | @Override 35 | public byte getId() { 36 | return ID; 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return "COMMAND_CLASS_BASIC"; 42 | } 43 | 44 | public Byte getValue() { 45 | return value; 46 | } 47 | 48 | @Override 49 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 50 | if (ccb[startIndex+1] == BASIC_REPORT || ccb[startIndex+1] == BASIC_SET) { 51 | value = ccb[startIndex+2]; 52 | logger.debug("Received updated value: {}", ByteUtil.createString(value)); 53 | } else { 54 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 55 | } 56 | } 57 | 58 | @Override 59 | public int queueStartupMessages(NodeContext context, byte nodeId) { 60 | context.sendDataFrame(createGet(nodeId)); 61 | return 1; 62 | } 63 | 64 | public DataFrame createSet(byte nodeId, byte value) { 65 | return createSendDataFrame("BASIC_SET", nodeId, new byte[]{BasicCommandClass.ID, BASIC_SET, value}, false); 66 | } 67 | 68 | public DataFrame createGet(byte nodeId) { 69 | return createSendDataFrame("BASIC_GET", nodeId, new byte[]{BasicCommandClass.ID, BASIC_GET}, true); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "BasicCommandClass{" + 75 | "version=" + getVersion() + 76 | ", value=" + value + 77 | '}'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/BatteryCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Battery Command Class 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class BatteryCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | private static final byte BATTERY_GET = 0x02; 25 | private static final byte BATTERY_REPORT = 0x03; 26 | 27 | public static final byte ID = (byte)0x80; 28 | 29 | private Byte level; 30 | 31 | @Override 32 | public byte getId() { 33 | return ID; 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return "COMMAND_CLASS_BATTERY"; 39 | } 40 | 41 | public Byte getLevel() { 42 | return level; 43 | } 44 | 45 | @Override 46 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 47 | if (ccb[startIndex+1] == BATTERY_REPORT) { 48 | if (ccb[startIndex+2] >= 0x00 && ccb[startIndex+2] <= 0x64) { 49 | level = ccb[startIndex+2]; 50 | logger.debug("Received updated level: {}", ByteUtil.createString(level)); 51 | } else if (ccb[startIndex+2] == 0xFF) { 52 | logger.debug("Received battery low warning"); 53 | } else { 54 | logger.warn("Ignoring invalid report value: {}", ByteUtil.createString(ccb[startIndex+2])); 55 | } 56 | } else { 57 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 58 | } 59 | } 60 | 61 | @Override 62 | public int queueStartupMessages(NodeContext context, byte nodeId) { 63 | context.sendDataFrame(createGet(nodeId)); 64 | return 1; 65 | } 66 | 67 | public DataFrame createGet(byte nodeId) { 68 | return createSendDataFrame("BATTERY_GET", nodeId, new byte[]{BatteryCommandClass.ID, BATTERY_GET}, true); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "BatteryCommandClass{" + 74 | "version=" + getVersion() + 75 | ", level=" + level + 76 | '}'; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/BinarySensorCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Binary Switch Command Class 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class BinarySensorCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | private static final byte SENSOR_BINARY_SET = 0x01; 25 | private static final byte SENSOR_BINARY_GET = 0x02; 26 | private static final byte SENSOR_BINARY_REPORT = 0x03; 27 | 28 | public static final byte ID = 0x30; 29 | 30 | public Boolean isIdle; 31 | 32 | @Override 33 | public byte getId() { 34 | return ID; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "COMMAND_CLASS_SENSOR_BINARY"; 40 | } 41 | 42 | public Boolean isIdle() { 43 | return isIdle; 44 | } 45 | 46 | @Override 47 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 48 | // some devices (e.g. Everspring SM103) seem to use SENSOR_BINARY_SET rather than SENSOR_BINARY_REPORT 49 | // when sending unsolicited updates 50 | if (ccb[startIndex+1] == SENSOR_BINARY_REPORT || ccb[startIndex+1] == SENSOR_BINARY_SET) { 51 | if (ccb[startIndex+2] == 0x00) { 52 | isIdle = true; 53 | logger.debug("Received updated isIdle (true)"); 54 | } else if ((ccb[startIndex+2] & 0xFF) == 0xFF || ccb[startIndex+2] == 0x63) { 55 | isIdle = false; 56 | logger.debug("Received updated isIdle (false)"); 57 | } else { 58 | logger.warn("Ignoring invalid report value: {}", ByteUtil.createString(ccb[startIndex+2])); 59 | } 60 | } else { 61 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 62 | } 63 | } 64 | 65 | @Override 66 | public int queueStartupMessages(NodeContext context, byte nodeId) { 67 | context.sendDataFrame(createGet(nodeId)); 68 | return 1; 69 | } 70 | 71 | public DataFrame createGet(byte nodeId) { 72 | return createSendDataFrame("SENSOR_BINARY_GET", nodeId, new byte[]{BinarySensorCommandClass.ID, SENSOR_BINARY_GET}, true); 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "BinarySensorCommandClass{" + 78 | "version=" + getVersion() + 79 | ", isIdle=" + isIdle + 80 | '}'; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/BinarySwitchCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Binary Switch Command Class 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class BinarySwitchCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | public static final byte SWITCH_BINARY_SET = 0x01; 25 | public static final byte SWITCH_BINARY_GET = 0x02; 26 | public static final byte SWITCH_BINARY_REPORT = 0x03; 27 | 28 | public static final byte ID = 0x25; 29 | 30 | private Boolean isOn; 31 | 32 | @Override 33 | public byte getId() { 34 | return ID; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "COMMAND_CLASS_SWITCH_BINARY"; 40 | } 41 | 42 | public Boolean isOn() { 43 | return isOn; 44 | } 45 | 46 | @Override 47 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 48 | if (ccb[startIndex+1] == SWITCH_BINARY_REPORT) { 49 | if (ccb[startIndex+2] == 0x00) { 50 | isOn = false; 51 | logger.debug("Received updated isOn (false)"); 52 | } else if ((ccb[startIndex+2] >= 0x01 && ccb[startIndex+2] <= 0x63) || ccb[startIndex+2] == (byte)0xFF) { 53 | isOn = true; 54 | logger.debug("Received updated isOn (true)"); 55 | } else { 56 | logger.error("Ignoring invalid report value: {}", ByteUtil.createString(ccb[startIndex+2])); 57 | } 58 | } else { 59 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 60 | } 61 | } 62 | 63 | @Override 64 | public int queueStartupMessages(NodeContext context, byte nodeId) { 65 | context.sendDataFrame(createGet(nodeId)); 66 | return 1; 67 | } 68 | 69 | public DataFrame createGet(byte nodeId) { 70 | return createSendDataFrame("SWITCH_BINARY_GET", nodeId, new byte[]{BinarySwitchCommandClass.ID, SWITCH_BINARY_GET}, true); 71 | } 72 | 73 | public DataFrame createSet(byte nodeId, boolean isOn) { 74 | return createSendDataFrame("SWITCH_BINARY_SET", nodeId, new byte[]{BinarySwitchCommandClass.ID, SWITCH_BINARY_SET, isOn ? (byte) 0xFF : (byte) 0x00}, false); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "BinarySwitchCommandClass{" + 80 | "version=" + getVersion() + 81 | ", isOn=" + isOn + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/ColorControlCommandClass.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.commandclass; 2 | 3 | import com.whizzosoftware.wzwave.frame.DataFrame; 4 | import com.whizzosoftware.wzwave.node.NodeContext; 5 | import com.whizzosoftware.wzwave.util.ByteUtil; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class ColorControlCommandClass extends CommandClass { 10 | private final Logger logger = LoggerFactory.getLogger(getClass()); 11 | 12 | public static final byte ID = (byte)0x33; 13 | 14 | public static final byte CAPABILITY_GET = 0x00; 15 | public static final byte CAPABILITY_REPORT = 0x01; 16 | public static final byte START_CAPABILITY_LEVEL_CHANGE = 0x02; 17 | public static final byte STATE_GET = 0x03; 18 | public static final byte STATE_REPORT = 0x04; 19 | public static final byte STATE_SET = 0x05; 20 | public static final byte STOP_STATE_CHANGE = 0x06; 21 | 22 | public static final byte CAPABILITY_ID_WARM_WHITE = 0x00; 23 | public static final byte CAPABILITY_ID_COLD_WHITE = 0x01; 24 | public static final byte CAPABILITY_ID_RED = 0x02; 25 | public static final byte CAPABILITY_ID_GREEN = 0x03; 26 | public static final byte CAPABILITY_ID_BLUE = 0x04; 27 | 28 | private Byte capabilityId; 29 | private Byte value; 30 | 31 | @Override 32 | public byte getId() { 33 | return ID; 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return "COMMAND_CLASS_COLOR_CONTROL"; 39 | } 40 | 41 | public Byte getCapabilityId() { 42 | return capabilityId; 43 | } 44 | 45 | public Byte getValue() { 46 | return value; 47 | } 48 | 49 | @Override 50 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 51 | if (ccb[startIndex+1] == STATE_REPORT) { 52 | capabilityId = ccb[startIndex+2]; 53 | value = ccb[startIndex+3]; 54 | logger.debug("Received capability ID {} with value {}", ByteUtil.createString(capabilityId), ByteUtil.createString(value)); 55 | } else { 56 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 57 | } 58 | } 59 | 60 | @Override 61 | public int queueStartupMessages(NodeContext context, byte nodeId) { 62 | return 0; 63 | } 64 | 65 | public DataFrame createGet(byte nodeId, byte capabilityId) { 66 | return createSendDataFrame("COLOR_CONTROL_GET", nodeId, new byte[]{ColorControlCommandClass.ID, STATE_GET, capabilityId}, true); 67 | } 68 | 69 | public DataFrame createSet(byte nodeId, byte capabilityId, byte value) { 70 | return createSendDataFrame("COLOR_CONTROL_SET", nodeId, new byte[]{ColorControlCommandClass.ID, STATE_SET, 0x02, capabilityId, value}, false); 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return "ColorControlCommandClass{" + 76 | "version=" + getVersion() + 77 | ", capabilityId=" + capabilityId + 78 | ", value=" + value + 79 | '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/CommandClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.commandclass; 11 | 12 | /** 13 | * Convenience factory class that creates CommandClass instances from a command class ID byte. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class CommandClassFactory { 18 | public static CommandClass createCommandClass(byte commandClassId) { 19 | switch (commandClassId) { 20 | case AlarmCommandClass.ID: 21 | return new AlarmCommandClass(); 22 | case AlarmSensorCommandClass.ID: 23 | return new AlarmSensorCommandClass(); 24 | case BasicCommandClass.ID: 25 | return new BasicCommandClass(); 26 | case BatteryCommandClass.ID: 27 | return new BatteryCommandClass(); 28 | case BinarySensorCommandClass.ID: 29 | return new BinarySensorCommandClass(); 30 | case BinarySwitchCommandClass.ID: 31 | return new BinarySwitchCommandClass(); 32 | case ColorControlCommandClass.ID: 33 | return new ColorControlCommandClass(); 34 | case IndicatorCommandClass.ID: 35 | return new IndicatorCommandClass(); 36 | case ManufacturerSpecificCommandClass.ID: 37 | return new ManufacturerSpecificCommandClass(); 38 | case MeterCommandClass.ID: 39 | return new MeterCommandClass(); 40 | case MultiInstanceCommandClass.ID: 41 | return new MultiInstanceCommandClass(); 42 | case MultilevelSensorCommandClass.ID: 43 | return new MultilevelSensorCommandClass(); 44 | case MultilevelSwitchCommandClass.ID: 45 | return new MultilevelSwitchCommandClass(); 46 | case NoOperationCommandClass.ID: 47 | return new NoOperationCommandClass(); 48 | case VersionCommandClass.ID: 49 | return new VersionCommandClass(); 50 | case WakeUpCommandClass.ID: 51 | return new WakeUpCommandClass(); 52 | default: 53 | return null; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/CommandClassParseException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | /** 11 | * Exception thrown when there is a problem parsing command class data. 12 | * 13 | * @author Dan Noguerol 14 | */ 15 | public class CommandClassParseException extends Exception { 16 | public CommandClassParseException(String message) { 17 | super(message); 18 | } 19 | 20 | public CommandClassParseException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/IndicatorCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2019 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * IndicatorCommand Class 18 | * 19 | * @author Per Otterström 20 | */ 21 | public class IndicatorCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | public static final byte INDICATOR_SET = 0x01; 25 | public static final byte INDICATOR_GET = 0x02; 26 | public static final byte INDICATOR_REPORT = 0x03; 27 | 28 | public static final byte ID = (byte)0x87; 29 | 30 | private Boolean isOn; 31 | 32 | @Override 33 | public byte getId() { 34 | return ID; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "COMMAND_CLASS_INDICATOR"; 40 | } 41 | 42 | public Boolean isOn() { 43 | return isOn; 44 | } 45 | 46 | @Override 47 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 48 | if (ccb[startIndex+1] == INDICATOR_REPORT) { 49 | if (ccb[startIndex+2] == 0x00) { 50 | isOn = false; 51 | logger.debug("Received updated isOn (false)"); 52 | } else if ((ccb[startIndex+2] >= 0x01 && ccb[startIndex+2] <= 0x63) || ccb[startIndex+2] == (byte)0xFF) { 53 | isOn = true; 54 | logger.debug("Received updated isOn (true)"); 55 | } else { 56 | logger.error("Ignoring invalid report value: {}", ByteUtil.createString(ccb[startIndex+2])); 57 | } 58 | } else { 59 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 60 | } 61 | } 62 | 63 | @Override 64 | public int queueStartupMessages(NodeContext context, byte nodeId) { 65 | context.sendDataFrame(createGet(nodeId)); 66 | return 1; 67 | } 68 | 69 | public DataFrame createGet(byte nodeId) { 70 | return createSendDataFrame("INDICATOR_GET", nodeId, new byte[]{IndicatorCommandClass.ID, INDICATOR_GET}, true); 71 | } 72 | 73 | public DataFrame createSet(byte nodeId, boolean isOn) { 74 | return createSendDataFrame("INDICATOR_SET", nodeId, new byte[]{IndicatorCommandClass.ID, INDICATOR_SET, isOn ? (byte) 0xFF : (byte) 0x00}, false); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "IndicatorCommandClass{" + 80 | "version=" + getVersion() + 81 | ", isOn=" + isOn + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/MultilevelSwitchCommandClass.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import com.whizzosoftware.wzwave.frame.DataFrame; 11 | import com.whizzosoftware.wzwave.node.NodeContext; 12 | import com.whizzosoftware.wzwave.util.ByteUtil; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Multilevel Switch Command Class 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class MultilevelSwitchCommandClass extends CommandClass { 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); 23 | 24 | private static final byte SWITCH_MULTILEVEL_SET = 0x01; 25 | private static final byte SWITCH_MULTILEVEL_GET = 0x02; 26 | private static final byte SWITCH_MULTILEVEL_REPORT = 0x03; 27 | 28 | public static final byte ID = 0x26; 29 | 30 | private Byte level; 31 | 32 | @Override 33 | public byte getId() { 34 | return ID; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return "COMMAND_CLASS_SWITCH_MULTILEVEL"; 40 | } 41 | 42 | public Byte getLevel() { 43 | return level; 44 | } 45 | 46 | @Override 47 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 48 | if (ccb[startIndex+1] == SWITCH_MULTILEVEL_REPORT) { 49 | if ((ccb[startIndex+2] >= 0x00 && ccb[startIndex+2] <= 0x63) || ccb[startIndex+2] == 0xFF) { 50 | level = ccb[startIndex+2]; 51 | logger.debug("Received updated level: {}", ByteUtil.createString(level)); 52 | } else { 53 | logger.warn("Ignoring invalid report value: {}", ByteUtil.createString(ccb[startIndex+2])); 54 | } 55 | } else { 56 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 57 | } 58 | } 59 | 60 | @Override 61 | public int queueStartupMessages(NodeContext context, byte nodeId) { 62 | context.sendDataFrame(createGet(nodeId)); 63 | return 1; 64 | } 65 | 66 | public DataFrame createSet(byte nodeId, byte level) { 67 | return createSendDataFrame("SWITCH_MULTILEVEL_SET", nodeId, new byte[]{MultilevelSwitchCommandClass.ID, SWITCH_MULTILEVEL_SET, level}, false); 68 | } 69 | 70 | public DataFrame createGet(byte nodeId) { 71 | return createSendDataFrame("SWITCH_MULTILEVEL_GET", nodeId, new byte[]{MultilevelSwitchCommandClass.ID, SWITCH_MULTILEVEL_GET}, true); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "MultilevelSwitchCommandClass{" + 77 | "version=" + getVersion() + 78 | ", level=" + level + 79 | '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/NoOperationCommandClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.commandclass; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | import com.whizzosoftware.wzwave.node.NodeContext; 14 | 15 | public class NoOperationCommandClass extends CommandClass { 16 | public static final byte ID = 0x00; 17 | 18 | public DataFrame createGet(byte nodeId) { 19 | return createSendDataFrame("COMMAND_CLASS_NO_OPERATION", nodeId, new byte[] {NoOperationCommandClass.ID}, false); 20 | } 21 | 22 | @Override 23 | public byte getId() { 24 | return ID; 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return "COMMAND_CLASS_NO_OPERATION"; 30 | } 31 | 32 | @Override 33 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 34 | } 35 | 36 | @Override 37 | public int queueStartupMessages(NodeContext context, byte nodeId) { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "NoOperationCommandClass{" + 44 | "version=" + getVersion() + 45 | '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/commandclass/WakeUpCommandClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.commandclass; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeContext; 13 | import com.whizzosoftware.wzwave.util.ByteUtil; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | /** 18 | * Wake Up Command Class 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class WakeUpCommandClass extends CommandClass { 23 | private final Logger logger = LoggerFactory.getLogger(getClass()); 24 | 25 | private static final byte WAKE_UP_INTERVAL_SET = 0x04; 26 | private static final byte WAKE_UP_INTERVAL_GET = 0x05; 27 | private static final byte WAKE_UP_INTERVAL_REPORT = 0x06; 28 | private static final byte WAKE_UP_NOTIFICATION = 0x07; 29 | private static final byte WAKE_UP_NO_MORE_INFORMATION = 0x08; 30 | 31 | public static final byte ID = (byte)0x84; 32 | 33 | @Override 34 | public byte getId() { 35 | return ID; 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return "COMMAND_CLASS_WAKE_UP"; 41 | } 42 | 43 | @Override 44 | public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) { 45 | if (ccb[startIndex+1] == WAKE_UP_NOTIFICATION) { 46 | logger.debug("Received wake up notification; flushing wakeup command queue"); 47 | context.setSleeping(false); 48 | } else { 49 | logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex+1])); 50 | } 51 | } 52 | 53 | @Override 54 | public int queueStartupMessages(NodeContext context, byte nodeId) { 55 | return 0; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "WakeUpCommandClass{" + 61 | "version=" + getVersion() + 62 | '}'; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/controller/ZWaveController.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.controller; 11 | 12 | import com.whizzosoftware.wzwave.node.ZWaveNode; 13 | import com.whizzosoftware.wzwave.frame.DataFrame; 14 | 15 | import java.util.Collection; 16 | 17 | /** 18 | * Interface representing a physical Z-Wave controller. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public interface ZWaveController { 23 | /** 24 | * Sets a listener for Z-Wave events. 25 | * 26 | * @param listener the listener 27 | */ 28 | void setListener(ZWaveControllerListener listener); 29 | 30 | /** 31 | * Start the controller (i.e. start processing events). 32 | */ 33 | void start(); 34 | 35 | /** 36 | * Stops the controller (i.e. stop processing events). 37 | */ 38 | void stop(); 39 | 40 | /** 41 | * Returns the home ID of this controller. 42 | * 43 | * @return an int 44 | */ 45 | int getHomeId(); 46 | 47 | /** 48 | * Returns the node ID of this controller. 49 | * 50 | * @return a byte 51 | */ 52 | byte getNodeId(); 53 | 54 | /** 55 | * Returns the controller's Z-Wave library version 56 | * 57 | * @return the version String 58 | */ 59 | String getLibraryVersion(); 60 | 61 | /** 62 | * Returns the collection of nodes this controller knows about. 63 | * 64 | * @return a Collection of nodes 65 | */ 66 | Collection getNodes(); 67 | 68 | /** 69 | * Returns a specific node. 70 | * 71 | * @param nodeId the ID of the node 72 | * 73 | * @return a ZWaveNode instance (or null if not found) 74 | */ 75 | ZWaveNode getNode(byte nodeId); 76 | 77 | /** 78 | * Sends a data frame to the Z-Wave network. 79 | * 80 | * @param dataFrame the data frame 81 | */ 82 | void sendDataFrame(DataFrame dataFrame); 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/controller/ZWaveControllerContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.controller; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | public interface ZWaveControllerContext { 15 | /** 16 | * Returns the controller node ID. 17 | * 18 | * @return a byte 19 | */ 20 | byte getNodeId(); 21 | 22 | /** 23 | * Sends a data frame to the Z-Wave network. 24 | * 25 | * @param frame the data frame to send 26 | * @param isListeningNode indicates whether the node is known to be a listening node 27 | */ 28 | void sendDataFrame(DataFrame frame, boolean isListeningNode); 29 | 30 | /** 31 | * Sends an event to the WZWave runtime. 32 | * 33 | * @param e the event 34 | */ 35 | void sendEvent(Object e); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/controller/ZWaveControllerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.controller; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeInfo; 13 | import com.whizzosoftware.wzwave.node.ZWaveEndpoint; 14 | 15 | /** 16 | * Listener interface for Z-Wave related events. 17 | * 18 | * @author Dan Noguerol 19 | */ 20 | public interface ZWaveControllerListener { 21 | /** 22 | * Callback when a new Z-Wave node has been discovered and interrogated. 23 | * 24 | * @param node the new Z-Wave node 25 | */ 26 | void onZWaveNodeAdded(ZWaveEndpoint node); 27 | 28 | /** 29 | * Callback when an existing Z-Wave node is updated. 30 | * 31 | * @param node the updated Z-Wave node 32 | */ 33 | void onZWaveNodeUpdated(ZWaveEndpoint node); 34 | 35 | /** 36 | * Callback when the initialization of the Z-Wave network has failed. 37 | * 38 | * @param t the cause 39 | */ 40 | void onZWaveConnectionFailure(Throwable t); 41 | 42 | /** 43 | * Callback when the library has determined information about the Z-Wave controller. 44 | * 45 | * @param libraryVersion the library version of the controller 46 | * @param homeId the home ID of the controller 47 | * @param nodeId the node ID of the controller 48 | */ 49 | void onZWaveControllerInfo(String libraryVersion, Integer homeId, Byte nodeId); 50 | 51 | /** 52 | * Callback when the Z-Wave controller has started network inclusion mode. 53 | */ 54 | void onZWaveInclusionStarted(); 55 | 56 | /** 57 | * Callback when a the Z-Wave controller has either successfully or unsuccessfully included a new node. This 58 | * call will be received prior to the node interview. 59 | * 60 | * @param nodeInfo information about the new node 61 | * @param success whether the inclusion was successful 62 | */ 63 | void onZWaveInclusion(NodeInfo nodeInfo, boolean success); 64 | 65 | /** 66 | * Callback when the Z-Wave controller has stopped network inclusion mode. 67 | */ 68 | void onZWaveInclusionStopped(); 69 | 70 | /** 71 | * Callback when the Z-Wave controller has started network exclusion mode. 72 | */ 73 | void onZWaveExclusionStarted(); 74 | 75 | /** 76 | * Callback when the Z-Wave controller has either successfully or unsuccessfully excluded a node. 77 | * 78 | * @param nodeInfo information about the new node 79 | * @param success whether the exclusion was successful 80 | */ 81 | void onZWaveExclusion(NodeInfo nodeInfo, boolean success); 82 | 83 | /** 84 | * Callback when the Z-Wave controller has stopped network exclusion mode. 85 | */ 86 | void onZWaveExclusionStopped(); 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/ACK.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * An acknowledgement (ACK) frame. This is an indicator to a source node that a 14 | * destination node has received a frame sent to it. 15 | * 16 | * @author Dan Noguerol 17 | */ 18 | public class ACK extends Frame { 19 | public static final byte ID = 0x06; 20 | 21 | @Override 22 | public byte[] getBytes() { 23 | return new byte[] { ID }; 24 | } 25 | 26 | public String toString() { 27 | return "ACK"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/ApplicationCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.util.ByteUtil; 15 | import io.netty.buffer.ByteBuf; 16 | 17 | /** 18 | * An application command data frame. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class ApplicationCommand extends DataFrame { 23 | public static final byte ID = 0x04; 24 | 25 | private byte nodeId; 26 | private byte status; 27 | private byte[] commandClassBytes; 28 | 29 | public ApplicationCommand(DataFrameType type, byte rxStatus, byte sourceNode, byte[] commandClassBytes) { 30 | super(type, ID, null); 31 | 32 | byte[] b = new byte[commandClassBytes.length + 2]; 33 | b[0] = rxStatus; 34 | b[1] = sourceNode; 35 | System.arraycopy(commandClassBytes, 0, b, 2, commandClassBytes.length); 36 | setData(b); 37 | 38 | this.nodeId = sourceNode; 39 | this.status = rxStatus; 40 | this.commandClassBytes = commandClassBytes; 41 | } 42 | 43 | public ApplicationCommand(ByteBuf buffer) { 44 | super(buffer); 45 | 46 | this.status = buffer.readByte(); 47 | this.nodeId = buffer.readByte(); 48 | 49 | byte cmdLength = buffer.readByte(); 50 | commandClassBytes = buffer.readBytes(cmdLength).array(); 51 | } 52 | 53 | public byte getNodeId() { 54 | return nodeId; 55 | } 56 | 57 | public byte getStatus() { 58 | return status; 59 | } 60 | 61 | public byte getCommandClassId() { 62 | return commandClassBytes[0]; 63 | } 64 | 65 | public byte[] getCommandClassBytes() { 66 | return commandClassBytes; 67 | } 68 | 69 | public String toString() { 70 | return "ZW_APPLICATION_COMMAND_HANDLER[" + ByteUtil.createString(getNodeId()) + "]: " + ByteUtil.createString(commandClassBytes, commandClassBytes.length); 71 | } 72 | 73 | @Override 74 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 75 | return null; 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/ApplicationUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.node.NodeInfo; 14 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 15 | import io.netty.buffer.ByteBuf; 16 | 17 | /** 18 | * An application update data frame. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class ApplicationUpdate extends DataFrame { 23 | public static final byte ID = 0x49; 24 | 25 | public static final byte UPDATE_STATE_NODE_INFO_REQ_FAILED = (byte)0x81; 26 | public static final byte UPDATE_STATE_NODE_INFO_RECEIVED = (byte)0x84; 27 | 28 | private Byte nodeId; 29 | private byte state; 30 | private NodeInfo nodeInfo; 31 | 32 | public ApplicationUpdate() { 33 | super(DataFrameType.REQUEST, ID, null); 34 | } 35 | 36 | public ApplicationUpdate(DataFrameType type, byte state, byte nodeId) { 37 | this(type, state, nodeId, null); 38 | } 39 | 40 | public ApplicationUpdate(DataFrameType type, byte state, byte nodeId, NodeInfo nodeInfo) { 41 | super(type, ID, null); 42 | this.state = state; 43 | this.nodeId = nodeId; 44 | this.nodeInfo = nodeInfo; 45 | } 46 | 47 | public ApplicationUpdate(ByteBuf buffer) { 48 | super(buffer); 49 | state = buffer.readByte(); 50 | this.nodeId = buffer.readByte(); 51 | if (state == UPDATE_STATE_NODE_INFO_RECEIVED) { 52 | nodeInfo = new NodeInfo(this.nodeId, buffer, dataFrameLength - 6); 53 | } else { 54 | buffer.readByte(); // read 0 length 55 | } 56 | } 57 | 58 | public Byte getNodeId() { 59 | return nodeId; 60 | } 61 | 62 | public void setNodeId(Byte nodeId) { 63 | this.nodeId = nodeId; 64 | } 65 | 66 | public byte getState() { 67 | return state; 68 | } 69 | 70 | public NodeInfo getNodeInfo() { 71 | return nodeInfo; 72 | } 73 | 74 | public boolean didInfoRequestFail() { 75 | return (state == UPDATE_STATE_NODE_INFO_REQ_FAILED); 76 | } 77 | 78 | @Override 79 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 80 | return null; 81 | } 82 | 83 | public String toString() { 84 | String s = "ZW_APPLICATION_CONTROLLER_UPDATE"; 85 | if (state == UPDATE_STATE_NODE_INFO_REQ_FAILED) { 86 | s += "[failed]"; 87 | } else if (state == UPDATE_STATE_NODE_INFO_RECEIVED) { 88 | s += "[success]"; 89 | } 90 | return s; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/CAN.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * A cancel (CAN) frame. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class CAN extends Frame { 18 | public static final byte ID = 0x18; 19 | 20 | @Override 21 | public byte[] getBytes() { 22 | return new byte[] { ID }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/DataFrameType.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * An enumeration for data frame types. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public enum DataFrameType { 18 | REQUEST, 19 | RESPONSE 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/Frame.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * Abstract base class for all Z-Wave frames. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | abstract public class Frame { 18 | abstract public byte[] getBytes(); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/GetRoutingInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import io.netty.buffer.ByteBuf; 15 | 16 | /** 17 | * A get routing info data frame. 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public class GetRoutingInfo extends DataFrame { 22 | public static final byte ID = (byte)0x80; 23 | 24 | private byte[] nodeMask; 25 | 26 | public GetRoutingInfo() { 27 | super(DataFrameType.REQUEST, ID, null); 28 | } 29 | 30 | public GetRoutingInfo(ByteBuf buffer) { 31 | super(buffer); 32 | nodeMask = buffer.readBytes(29).array(); 33 | } 34 | 35 | public byte[] getNodeMask() { 36 | return nodeMask; 37 | } 38 | 39 | @Override 40 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/GetSUCNodeId.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.frame; 2 | 3 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 4 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 5 | import io.netty.buffer.ByteBuf; 6 | 7 | public class GetSUCNodeId extends DataFrame { 8 | public static final byte ID = (byte)0x56; 9 | 10 | private byte sucNodeId; 11 | 12 | public GetSUCNodeId(ByteBuf buffer) { 13 | super(buffer); 14 | sucNodeId = buffer.readByte(); 15 | } 16 | 17 | public byte getSucNodeId() { 18 | return sucNodeId; 19 | } 20 | 21 | @Override 22 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/InitData.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.frame.transaction.RequestResponseTransaction; 15 | import com.whizzosoftware.wzwave.util.ByteUtil; 16 | import io.netty.buffer.ByteBuf; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * An init data data frame. Retrieves a list of known node IDs from the controller. 23 | * 24 | * @author Dan Noguerol 25 | */ 26 | public class InitData extends DataFrame { 27 | public static final byte ID = 0x02; 28 | 29 | private static final int NODE_BITMASK_SIZE = 29; 30 | 31 | private byte version; 32 | private byte capabilities; 33 | private List nodes = new ArrayList<>(); 34 | 35 | public InitData() { 36 | super(DataFrameType.REQUEST, ID, null); 37 | } 38 | 39 | public InitData(ByteBuf buffer) { 40 | super(buffer); 41 | 42 | this.version = buffer.readByte(); 43 | this.capabilities = buffer.readByte(); 44 | 45 | // read the node information form the bit mask 46 | if (buffer.readByte() == NODE_BITMASK_SIZE) { 47 | // 29 bytes * 8 bits == 232 == the number of possible nodes in the network 48 | for (int i=0; i < NODE_BITMASK_SIZE; i++) { 49 | byte b = buffer.readByte(); 50 | for (int j=0; j < 8; j++) { 51 | byte nodeId = (byte)((i*8)+j+1); 52 | if ((b & (0x01 << j)) > 0) { 53 | nodes.add(nodeId); 54 | } 55 | } 56 | } 57 | } 58 | 59 | buffer.readByte(); // unsure what this is 60 | buffer.readByte(); // unsure what this is 61 | } 62 | 63 | public byte getVersion() { 64 | return version; 65 | } 66 | 67 | public byte getCapabilities() { 68 | return capabilities; 69 | } 70 | 71 | public List getNodes() { 72 | return nodes; 73 | } 74 | 75 | @Override 76 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 77 | return new RequestResponseTransaction(ctx, this, listeningNode); 78 | } 79 | 80 | public String toString() { 81 | if (getType() == DataFrameType.REQUEST) { 82 | return "ZW_INIT_DATA"; 83 | } else { 84 | StringBuilder sb = new StringBuilder("ZW_INIT_DATA"); 85 | if (nodes.size() > 0) { 86 | sb.append(": nodes "); 87 | for (Byte b : nodes) { 88 | sb.append(ByteUtil.createString(b)).append(" "); 89 | } 90 | } 91 | return sb.toString(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/MemoryGetId.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.frame.transaction.RequestResponseTransaction; 15 | import io.netty.buffer.ByteBuf; 16 | 17 | /** 18 | * Retrieves the home ID and node ID from a controller. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class MemoryGetId extends DataFrame { 23 | public static final byte ID = 0x20; 24 | 25 | private Integer homeId; 26 | private Byte nodeId; 27 | 28 | public MemoryGetId() { 29 | super(DataFrameType.REQUEST, ID, null); 30 | } 31 | 32 | public MemoryGetId(ByteBuf buffer) { 33 | super(buffer); 34 | 35 | homeId = (((int)buffer.readByte()) << 24) | (((int)buffer.readByte()) << 16) | (((int)buffer.readByte()) << 8) | ((int)buffer.readByte()); 36 | nodeId = buffer.readByte(); 37 | } 38 | 39 | public Integer getHomeId() { 40 | return homeId; 41 | } 42 | 43 | public Byte getNodeId() { 44 | return nodeId; 45 | } 46 | 47 | @Override 48 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 49 | return new RequestResponseTransaction(ctx, this, listeningNode); 50 | } 51 | 52 | public String toString() { 53 | String s = "ZW_MEMORY_GET_ID"; 54 | if (homeId != null) { 55 | s += "[" + homeId + "," + nodeId + "]"; 56 | } 57 | return s; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/NAK.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * A negative acknowledgement (NAK) frame. 14 | * 15 | * @author Dan Noguerol 16 | */ 17 | public class NAK extends Frame { 18 | public static final byte ID = 0x15; 19 | 20 | @Override 21 | public byte[] getBytes() { 22 | return new byte[] { ID }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/OutboundDataFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | /** 13 | * A wrapper class that provides an indication of whether an outbound data frame is destined for a listening node. 14 | * This is important to know in transmission failure situations. 15 | * 16 | * @author Dan Noguerol 17 | */ 18 | public class OutboundDataFrame { 19 | private DataFrame dataFrame; 20 | private boolean isListeningNode; 21 | 22 | public OutboundDataFrame(DataFrame dataFrame, boolean isListeningNode) { 23 | this.dataFrame = dataFrame; 24 | this.isListeningNode = isListeningNode; 25 | } 26 | 27 | public boolean hasDataFrame() { 28 | return (dataFrame != null); 29 | } 30 | 31 | public DataFrame getDataFrame() { 32 | return dataFrame; 33 | } 34 | 35 | public boolean isListeningNode() { 36 | return isListeningNode; 37 | } 38 | 39 | public boolean matchesTransaction(String transactionId) { 40 | return (transactionId != null && transactionId.equals(dataFrame.getTransactionId())); 41 | } 42 | 43 | public String toString() { 44 | return dataFrame.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/RequestNodeInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************** 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.frame.transaction.RequestNodeInfoTransaction; 15 | import com.whizzosoftware.wzwave.util.ByteUtil; 16 | import io.netty.buffer.ByteBuf; 17 | 18 | /** 19 | * Requests information about a particular node. 20 | * 21 | * @author Dan Noguerol 22 | */ 23 | public class RequestNodeInfo extends DataFrame { 24 | public static final byte ID = 0x60; 25 | 26 | public static final byte UPDATE_STATE_NODE_INFO_REQ_FAILED = 0x00; 27 | public static final byte UPDATE_STATE_NODE_INFO_RECEIVED = 0x01; 28 | 29 | private Byte nodeId; 30 | private Byte retVal; 31 | 32 | public RequestNodeInfo(byte nodeId) { 33 | super(DataFrameType.REQUEST, ID, new byte[]{nodeId}); 34 | this.nodeId = nodeId; 35 | } 36 | 37 | public RequestNodeInfo(ByteBuf buffer) { 38 | super(buffer); 39 | retVal = buffer.readByte(); 40 | } 41 | 42 | public Byte getNodeId() { 43 | return nodeId; 44 | } 45 | 46 | public Byte getRetVal() { 47 | return retVal; 48 | } 49 | 50 | public Boolean wasSuccessfullySent() { 51 | return (retVal != null && retVal == (byte)0x01); 52 | } 53 | 54 | @Override 55 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 56 | return new RequestNodeInfoTransaction(ctx, this, listeningNode); 57 | } 58 | 59 | public String toString() { 60 | if (nodeId != null) { 61 | return "REQUEST_NODE_INFO(" + ByteUtil.createString(nodeId) + ")"; 62 | } else { 63 | switch (retVal) { 64 | case UPDATE_STATE_NODE_INFO_REQ_FAILED: 65 | return "REQUEST_NODE_INFO[failed]"; 66 | case UPDATE_STATE_NODE_INFO_RECEIVED: 67 | return "REQUEST_NODE_INFO[success]"; 68 | default: 69 | return "REQUEST_NODE_INFO: " + retVal; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/SetDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.frame.transaction.RequestCallbackTransaction; 15 | import io.netty.buffer.ByteBuf; 16 | 17 | /** 18 | * Requests that the controller reset to factory defaults. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class SetDefault extends DataFrame { 23 | public static final byte ID = 0x42; 24 | 25 | public SetDefault() { 26 | super(DataFrameType.REQUEST, ID, null); 27 | } 28 | 29 | public SetDefault(ByteBuf buffer) { 30 | super(buffer); 31 | buffer.readByte(); // funcId 32 | } 33 | 34 | @Override 35 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 36 | return new RequestCallbackTransaction(ctx, this, listeningNode); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.transaction.DataFrameTransaction; 14 | import com.whizzosoftware.wzwave.frame.transaction.RequestResponseTransaction; 15 | import io.netty.buffer.ByteBuf; 16 | 17 | /** 18 | * Message for retrieving version information. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class Version extends DataFrame { 23 | public static final byte ID = 0x15; 24 | 25 | private String libraryVersion; 26 | private byte libraryType; 27 | 28 | public Version() { 29 | super(DataFrameType.REQUEST, ID, null); 30 | } 31 | 32 | public Version(String libraryVersion, byte libraryType) { 33 | super(DataFrameType.RESPONSE, ID, null); 34 | this.libraryVersion = libraryVersion; 35 | this.libraryType = libraryType; 36 | } 37 | 38 | public Version(ByteBuf buffer) { 39 | super(buffer); 40 | libraryVersion = new String(buffer.readBytes(12).array()).trim(); 41 | libraryType = buffer.readByte(); 42 | } 43 | 44 | public String getLibraryVersion() { 45 | return libraryVersion; 46 | } 47 | 48 | public byte getLibraryType() { 49 | return libraryType; 50 | } 51 | 52 | @Override 53 | public DataFrameTransaction createTransaction(ZWaveChannelContext ctx, boolean listeningNode) { 54 | return new RequestResponseTransaction(ctx, this, listeningNode); 55 | } 56 | 57 | public String toString() { 58 | String s = "ZW_VERSION"; 59 | if (libraryVersion != null) { 60 | s += "[" + libraryVersion + "]"; 61 | } 62 | return s; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/transaction/AbstractDataFrameTransaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame.transaction; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.channel.event.TransactionFailedEvent; 14 | import com.whizzosoftware.wzwave.channel.event.TransactionStartedEvent; 15 | import com.whizzosoftware.wzwave.frame.DataFrame; 16 | import com.whizzosoftware.wzwave.frame.OutboundDataFrame; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import java.util.UUID; 21 | 22 | /** 23 | * Abstract base class for all DataFrameTransaction implementations. 24 | * 25 | * @author Dan Noguerol 26 | */ 27 | abstract class AbstractDataFrameTransaction implements DataFrameTransaction { 28 | private static final int MAX_SEND_COUNT = 2; 29 | 30 | private final Logger logger = LoggerFactory.getLogger(getClass()); 31 | 32 | private String id = UUID.randomUUID().toString(); 33 | private DataFrame startFrame; 34 | private boolean listeningNode; 35 | 36 | AbstractDataFrameTransaction(ZWaveChannelContext ctx, DataFrame startFrame, boolean listeningNode) { 37 | this.startFrame = startFrame; 38 | this.listeningNode = listeningNode; 39 | ctx.fireEvent(new TransactionStartedEvent(getId())); 40 | } 41 | 42 | public String getId() { 43 | return id; 44 | } 45 | 46 | public long getTimeout() { 47 | return 2000; 48 | } 49 | 50 | public DataFrame getStartFrame() { 51 | return startFrame; 52 | } 53 | 54 | public void timeout(ZWaveChannelContext ctx) { 55 | attemptResend(ctx, false); 56 | } 57 | 58 | @Override 59 | public boolean isListeningNode() { 60 | return listeningNode; 61 | } 62 | 63 | /** 64 | * Attempts to re-send the data frame that initiated this transaction. 65 | * 66 | * @param ctx the ChannelHandlerContext 67 | * @param dueToCAN indicates whether the re-send attempt was due to a CAN frame that was received 68 | * 69 | * @return boolean indicating whether re-send was attempted 70 | */ 71 | boolean attemptResend(ZWaveChannelContext ctx, boolean dueToCAN) { 72 | if (startFrame.getSendCount() < MAX_SEND_COUNT) { 73 | logger.debug("Transaction {} has failed - will reset and resend initial request", getId()); 74 | reset(); 75 | // if a CAN was received, then we decrement the send count by one so this attempt doesn't count towards the maximum resend count 76 | if (dueToCAN) { 77 | startFrame.decrementSendCount(); 78 | } 79 | ctx.writeFrame(new OutboundDataFrame(startFrame, isListeningNode())); 80 | return true; 81 | } else { 82 | logger.debug("Exceeded max transaction resends"); 83 | ctx.fireEvent(new TransactionFailedEvent(getId(), startFrame)); 84 | return false; 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/transaction/DataFrameTransaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame.transaction; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.frame.DataFrame; 14 | import com.whizzosoftware.wzwave.frame.Frame; 15 | 16 | /** 17 | * A DataFrameTransaction is used to identify when a data frame sent to the Z-Wave network has completed its flow. 18 | * The completion of the flow indicates when the next queued data frame can be sent out. In the simplest cases, a 19 | * transaction is complete when a single ACK is received. In more complex cases, it may be that multiple data frames 20 | * need to be received before the transaction is considered complete. 21 | * 22 | * @author Dan Noguerol 23 | */ 24 | public interface DataFrameTransaction { 25 | /** 26 | * Get the globally unique ID for this transaction. 27 | * 28 | * @return a String 29 | */ 30 | String getId(); 31 | 32 | /** 33 | * Returns the first frame of the transaction. 34 | * 35 | * @return a DataFrame 36 | */ 37 | DataFrame getStartFrame(); 38 | 39 | /** 40 | * The transaction timeout interval. 41 | * 42 | * @return an interval in milliseconds 43 | */ 44 | long getTimeout(); 45 | 46 | /** 47 | * Add a Frame to the transaction. 48 | * 49 | * @param ctx the channel context 50 | * @param f the next frame 51 | * 52 | * @return indicates whether the frame was consumed by the transaction 53 | */ 54 | boolean addFrame(ZWaveChannelContext ctx, Frame f); 55 | 56 | /** 57 | * Forces a transaction timeout. 58 | * 59 | * @param ctx the channel context 60 | */ 61 | void timeout(ZWaveChannelContext ctx); 62 | 63 | /** 64 | * Indicates whether the destination node for this message transaction is known to be actively listening. 65 | * 66 | * @return a boolean 67 | */ 68 | boolean isListeningNode(); 69 | 70 | /** 71 | * Identifies whether the transaction is complete. 72 | * 73 | * @return a boolean 74 | */ 75 | boolean isComplete(); 76 | 77 | /** 78 | * Resets the transaction to its initial state. 79 | */ 80 | void reset(); 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/frame/transaction/RequestNodeInfoTransaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.frame.transaction; 11 | 12 | import com.whizzosoftware.wzwave.channel.ZWaveChannelContext; 13 | import com.whizzosoftware.wzwave.channel.event.TransactionCompletedEvent; 14 | import com.whizzosoftware.wzwave.frame.ApplicationUpdate; 15 | import com.whizzosoftware.wzwave.frame.DataFrame; 16 | import com.whizzosoftware.wzwave.frame.RequestNodeInfo; 17 | 18 | /** 19 | * DataFrameTransaction implementation for RequestNodeInfo exchanges. 20 | * 21 | * @author Dan Noguerol 22 | */ 23 | public class RequestNodeInfoTransaction extends RequestResponseCallbackTransaction { 24 | public RequestNodeInfoTransaction(ZWaveChannelContext ctx, DataFrame startFrame, boolean listeningNode) { 25 | super(ctx, startFrame, listeningNode); 26 | } 27 | 28 | @Override 29 | protected void completeTransaction(ZWaveChannelContext ctx, DataFrame finalFrame) { 30 | setState(STATE_COMPLETE); 31 | 32 | // if there's an ApplicationUpdate with no node ID (e.g. when there's a app update failure), attempt 33 | // to set the node ID based on the request frame that triggered it 34 | if (finalFrame instanceof ApplicationUpdate) { 35 | ApplicationUpdate update = (ApplicationUpdate)finalFrame; 36 | if ((update.getNodeId() == null || update.getNodeId() == 0) && getStartFrame() instanceof RequestNodeInfo) { 37 | update.setNodeId(((RequestNodeInfo)getStartFrame()).getNodeId()); 38 | } 39 | } 40 | 41 | ctx.fireEvent(new TransactionCompletedEvent(getId(), finalFrame)); 42 | } 43 | 44 | protected boolean wasSendSuccessful(DataFrame dataFrame) { 45 | if (dataFrame instanceof RequestNodeInfo) { 46 | return ((RequestNodeInfo)dataFrame).wasSuccessfullySent(); 47 | } else { 48 | return false; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/BasicDeviceClasses.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.node; 2 | 3 | public class BasicDeviceClasses { 4 | public static final byte CONTROLLER = 0x01; 5 | public static final byte STATIC_CONTROLLER = 0x02; 6 | public static final byte SLAVE = 0x03; 7 | public static final byte ROUTING_SLAVE = 0x04; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/MultiChannelEncapsulatingNodeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.MultiInstanceCommandClass; 14 | import com.whizzosoftware.wzwave.frame.DataFrame; 15 | import com.whizzosoftware.wzwave.frame.SendData; 16 | 17 | import java.util.Collection; 18 | 19 | /** 20 | * A NodeContext implementation that wrappers another NodeContext but encapsulates all SendData frames in a 21 | * multi-instance command before queueing them. This is needed so that command classes within endpoints can 22 | * send their data correctly. 23 | * 24 | * @author Dan Noguerol 25 | */ 26 | public class MultiChannelEncapsulatingNodeContext implements NodeContext { 27 | private MultiInstanceCommandClass micc; 28 | private byte destEndpoint; 29 | private NodeContext context; 30 | 31 | public MultiChannelEncapsulatingNodeContext(MultiInstanceCommandClass micc, byte destEndpoint, NodeContext context) { 32 | this.micc = micc; 33 | this.destEndpoint = destEndpoint; 34 | this.context = context; 35 | } 36 | 37 | @Override 38 | public byte getNodeId() { 39 | return context.getNodeId(); 40 | } 41 | 42 | @Override 43 | public void sendDataFrame(DataFrame d) { 44 | boolean responseExpected = (d instanceof SendData) && ((SendData)d).isResponseExpected(); 45 | DataFrame ed = micc.createMultiChannelCommandEncapsulation((byte)0, destEndpoint, d, responseExpected); 46 | if (ed == null) { 47 | ed = d; 48 | } 49 | context.sendDataFrame(ed); 50 | } 51 | 52 | @Override 53 | public void setSleeping(boolean sleeping) { 54 | context.setSleeping(sleeping); 55 | } 56 | 57 | @Override 58 | public CommandClass getCommandClass(byte commandClassId) { 59 | return context.getCommandClass(commandClassId); 60 | } 61 | 62 | @Override 63 | public Collection getCommandClasses() { 64 | return context.getCommandClasses(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/NodeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 13 | import com.whizzosoftware.wzwave.frame.DataFrame; 14 | 15 | import java.util.Collection; 16 | 17 | /** 18 | * An interface passed to command classes to allow them to indirectly interact with their node. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public interface NodeContext { 23 | /** 24 | * Returns the node ID. 25 | * 26 | * @return a node ID 27 | */ 28 | byte getNodeId(); 29 | 30 | /** 31 | * Queue a data frame for sending. 32 | * 33 | * @param d the data frame 34 | */ 35 | void sendDataFrame(DataFrame d); 36 | 37 | /** 38 | * Sets the sleeping status of the node. 39 | * 40 | * @param sleeping whether the node is sleeping or not 41 | */ 42 | void setSleeping(boolean sleeping); 43 | 44 | /** 45 | * Retrieve a command class for the node associated with this context. 46 | * 47 | * @param commandClassId the command class ID 48 | * 49 | * @return a CommandClass instance of none if not found 50 | */ 51 | CommandClass getCommandClass(byte commandClassId); 52 | 53 | /** 54 | * Retrieve all command classes for the node associated with this context. 55 | * 56 | * @return a Collection of CommandClass instances 57 | */ 58 | Collection getCommandClasses(); 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/NodeCreationException.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.node; 2 | 3 | public class NodeCreationException extends Exception { 4 | public NodeCreationException(String message) { 5 | super(message); 6 | } 7 | 8 | public NodeCreationException(String message, Throwable cause) { 9 | super(message, cause); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/NodeInfo.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import java.util.Arrays; 12 | 13 | /** 14 | * Encapsulates Z-Wave node information. 15 | * 16 | * @author Dan Noguerol 17 | */ 18 | public class NodeInfo { 19 | private byte nodeId; 20 | private byte basicDeviceClass; 21 | private byte genericDeviceClass; 22 | private byte specificDeviceClass; 23 | private byte[] commandClasses; 24 | 25 | public NodeInfo(byte nodeId, byte basicDeviceClass, byte genericDeviceClass, byte specificDeviceClass) { 26 | this(nodeId, basicDeviceClass, genericDeviceClass, specificDeviceClass, null); 27 | } 28 | 29 | public NodeInfo(byte nodeId, byte basicDeviceClass, byte genericDeviceClass, byte specificDeviceClass, byte[] commandClasses) { 30 | this.nodeId = nodeId; 31 | this.basicDeviceClass = basicDeviceClass; 32 | this.genericDeviceClass = genericDeviceClass; 33 | this.specificDeviceClass = specificDeviceClass; 34 | this.commandClasses = commandClasses; 35 | } 36 | 37 | public NodeInfo(byte nodeId, ByteBuf buffer, int nodeInfoLength) { 38 | this.nodeId = nodeId; 39 | buffer.readByte(); 40 | basicDeviceClass = buffer.readByte(); 41 | genericDeviceClass = buffer.readByte(); 42 | specificDeviceClass = buffer.readByte(); 43 | commandClasses = buffer.readBytes(nodeInfoLength - 3).array(); 44 | } 45 | 46 | public byte getNodeId() { 47 | return nodeId; 48 | } 49 | 50 | public byte getBasicDeviceClass() { 51 | return basicDeviceClass; 52 | } 53 | 54 | public byte getGenericDeviceClass() { 55 | return genericDeviceClass; 56 | } 57 | 58 | public byte getSpecificDeviceClass() { 59 | return specificDeviceClass; 60 | } 61 | 62 | public boolean hasCommandClass(byte cclass) { 63 | if (commandClasses != null) { 64 | for (int i = 0; i < commandClasses.length; i++) { 65 | if (commandClasses[i] == cclass) { 66 | return true; 67 | } 68 | } 69 | } 70 | return false; 71 | } 72 | 73 | public byte[] getCommandClasses() { 74 | return commandClasses; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "NodeInfo [nodeId=" + nodeId + ", basicDeviceClass=" + basicDeviceClass + ", genericDeviceClass=" + genericDeviceClass 80 | + ", specificDeviceClass=" + specificDeviceClass + ", commandClasses=" + Arrays.toString(commandClasses) + "]"; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/NodeListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node; 9 | 10 | /** 11 | * Interface for classes that want to monitor node events. 12 | * 13 | * @author Dan Noguerol 14 | */ 15 | public interface NodeListener { 16 | /** 17 | * Called when a node is started. 18 | * 19 | * @param node the node that was started 20 | */ 21 | public void onNodeStarted(ZWaveNode node); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/WrapperedNodeContext.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node; 9 | 10 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 11 | import com.whizzosoftware.wzwave.controller.ZWaveControllerContext; 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | import java.util.Collection; 15 | 16 | public class WrapperedNodeContext implements NodeContext { 17 | private ZWaveControllerContext context; 18 | private ZWaveNode node; 19 | 20 | public WrapperedNodeContext(ZWaveControllerContext context, ZWaveNode node) { 21 | this.context = context; 22 | this.node = node; 23 | } 24 | 25 | @Override 26 | public byte getNodeId() { 27 | return node.getNodeId(); 28 | } 29 | 30 | @Override 31 | public void sendDataFrame(DataFrame d) { 32 | node.sendDataFrame(context, d); 33 | } 34 | 35 | @Override 36 | public void setSleeping(boolean sleeping) { 37 | node.setSleeping(context, sleeping); 38 | } 39 | 40 | @Override 41 | public CommandClass getCommandClass(byte commandClassId) { 42 | return node.getCommandClass(commandClassId); 43 | } 44 | 45 | @Override 46 | public Collection getCommandClasses() { 47 | return node.getCommandClasses(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/ZWaveMultiChannelEndpoint.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node; 9 | 10 | /** 11 | * Class that represents a multi-channel node endpoint. Multi-instance/Multi-channel Z-Wave devices can have multiple 12 | * endpoints which act like "child nodes" with their own identify and command classes. 13 | * 14 | * @author Dan Noguerol 15 | */ 16 | public class ZWaveMultiChannelEndpoint extends ZWaveEndpoint { 17 | public static final byte ALARM_SENSOR = (byte)0xA1; 18 | public static final byte AV_CONTROL_POINT = 0x03; 19 | public static final byte BINARY_SENSOR = 0x20; 20 | public static final byte BINARY_SWITCH = 0x10; 21 | public static final byte DISPLAY = 0x04; 22 | public static final byte ENERGY_CONTROL = 0x40; 23 | public static final byte METER = 0x31; 24 | public static final byte MULTI_LEVEL_SENSOR = 0x21; 25 | public static final byte MULTI_LEVEL_SWITCH = 0x11; 26 | public static final byte PULSE_METER = 0x30; 27 | public static final byte REMOTE_SWITCH = 0x12; 28 | public static final byte THERMOSTAT = 0x08; 29 | public static final byte TOGGLE_SWITCH = 0x13; 30 | public static final byte VENTILATION = 0x16; 31 | 32 | private byte number; 33 | 34 | public ZWaveMultiChannelEndpoint(byte nodeId, byte number, byte genericDeviceClass, byte specificDeviceClass) { 35 | super(nodeId, genericDeviceClass, specificDeviceClass); 36 | this.number = number; 37 | } 38 | 39 | public byte getNumber() { 40 | return number; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/ZWaveNodeState.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node; 9 | 10 | /** 11 | * Enumeration for Z-Wave node state. 12 | * 13 | * @author Dan Noguerol 14 | */ 15 | public enum ZWaveNodeState { 16 | Ping, 17 | NodeInfo, 18 | RetrieveVersionPending, 19 | RetrieveVersionSent, 20 | RetrieveStatePending, 21 | RetrieveStateSent, 22 | Started 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/AlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.node.NodeInfo; 14 | import com.whizzosoftware.wzwave.node.NodeListener; 15 | import com.whizzosoftware.wzwave.node.ZWaveNode; 16 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 17 | 18 | /** 19 | * An alarm sensor node. 20 | * 21 | * @author Dan Noguerol 22 | */ 23 | public class AlarmSensor extends ZWaveNode { 24 | public static final byte ID = (byte)0xA1; 25 | 26 | public AlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 27 | super(info, listening, listener); 28 | 29 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 30 | } 31 | 32 | public AlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 33 | super(pctx, nodeId, listener); 34 | } 35 | 36 | @Override 37 | protected void refresh(boolean deferIfNotListening) { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/BinarySensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BinarySensorCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.ZWaveNode; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | /** 21 | * A Binary Sensor node. 22 | * 23 | * @author Dan Noguerol 24 | */ 25 | public class BinarySensor extends ZWaveNode { 26 | public static final byte ID = 0x20; 27 | 28 | private Byte value = null; 29 | 30 | public BinarySensor(NodeInfo info, boolean listening, NodeListener listener) { 31 | super(info, listening, listener); 32 | 33 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 34 | addCommandClass(BinarySensorCommandClass.ID, new BinarySensorCommandClass()); 35 | } 36 | 37 | public BinarySensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 38 | super(pctx, nodeId, listener); 39 | } 40 | 41 | public Byte getValue() { 42 | return value; 43 | } 44 | 45 | public CommandClass getCommandClass(byte commandClassId) { 46 | if (commandClassId == 0x20) { 47 | return getCommandClass(BinarySensorCommandClass.ID); 48 | } else { 49 | return super.getCommandClass(commandClassId); 50 | } 51 | } 52 | 53 | @Override 54 | protected void refresh(boolean deferIfNotListening) { 55 | // queueDataFrame(BinarySensorCommandClass.createGetv1(getNodeId())); 56 | } 57 | 58 | public Boolean isSensorIdle() { 59 | BinarySensorCommandClass cc = (BinarySensorCommandClass)getCommandClass(BinarySensorCommandClass.ID); 60 | if (cc != null) { 61 | return cc.isIdle(); 62 | } else { 63 | return null; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/BinarySwitch.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BinarySwitchCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.ZWaveEndpoint; 18 | import com.whizzosoftware.wzwave.node.ZWaveNode; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | /** 22 | * A Binary Switch node. 23 | * 24 | * @author Dan Noguerol 25 | */ 26 | public class BinarySwitch extends ZWaveNode { 27 | public static final byte ID = 0x10; 28 | 29 | public BinarySwitch(NodeInfo info, boolean listening, NodeListener listener) { 30 | super(info, listening, listener); 31 | 32 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 33 | addCommandClass(BinarySwitchCommandClass.ID, new BinarySwitchCommandClass()); 34 | } 35 | 36 | public BinarySwitch(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 37 | super(pctx, nodeId, listener); 38 | } 39 | 40 | protected CommandClass performBasicCommandClassMapping(BasicCommandClass cc) { 41 | // Basic commands should get mapped to BinarySwitch commands 42 | return getCommandClass(BinarySwitchCommandClass.ID); 43 | } 44 | 45 | @Override 46 | protected void refresh(boolean deferIfNotListening) { 47 | // TODO 48 | // sendDataFrame(BinarySwitchCommandClass.createGetv1(getNodeId()), deferIfNotListening); 49 | } 50 | 51 | static public Boolean isOn(ZWaveEndpoint endpoint) { 52 | BinarySwitchCommandClass cc = (BinarySwitchCommandClass)endpoint.getCommandClass(BinarySwitchCommandClass.ID); 53 | if (cc != null) { 54 | return cc.isOn(); 55 | } else { 56 | return null; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/Meter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.node.NodeInfo; 14 | import com.whizzosoftware.wzwave.node.NodeListener; 15 | import com.whizzosoftware.wzwave.node.ZWaveNode; 16 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 17 | 18 | public class Meter extends ZWaveNode { 19 | public static final byte ID = (byte)0x31; 20 | 21 | public Meter(NodeInfo info, boolean listening, NodeListener listener) { 22 | super(info, listening, listener); 23 | 24 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 25 | } 26 | 27 | public Meter(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 28 | super(pctx, nodeId, listener); 29 | } 30 | 31 | @Override 32 | protected void refresh(boolean deferIfNotListening) { 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/MultilevelSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.MultilevelSensorCommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.ZWaveNode; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | /** 21 | * A Multilevel Sensor node. 22 | * 23 | * @author Dan Noguerol 24 | */ 25 | public class MultilevelSensor extends ZWaveNode { 26 | public static final byte ID = 0x21; 27 | 28 | public MultilevelSensor(NodeInfo info, boolean listening, NodeListener listener) { 29 | super(info, listening, listener); 30 | 31 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 32 | addCommandClass(MultilevelSensorCommandClass.ID, new MultilevelSensorCommandClass()); 33 | } 34 | 35 | public MultilevelSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 36 | super(pctx, nodeId, listener); 37 | } 38 | 39 | protected CommandClass performBasicCommandClassMapping(BasicCommandClass cc) { 40 | // Basic commands should get mapped to MultilevelSensor commands 41 | return getCommandClass(MultilevelSensorCommandClass.ID); 42 | } 43 | 44 | @Override 45 | protected void refresh(boolean deferIfNotListening) { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/MultilevelSwitch.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BasicCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.MultilevelSwitchCommandClass; 14 | import com.whizzosoftware.wzwave.node.NodeInfo; 15 | import com.whizzosoftware.wzwave.node.NodeListener; 16 | import com.whizzosoftware.wzwave.node.ZWaveNode; 17 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 18 | 19 | /** 20 | * A Multilevel Switch node. 21 | * 22 | * @author Dan Noguerol 23 | */ 24 | public class MultilevelSwitch extends ZWaveNode { 25 | public static final byte ID = 0x11; 26 | 27 | public MultilevelSwitch(NodeInfo info, boolean listening, NodeListener listener) { 28 | super(info, listening, listener); 29 | 30 | addCommandClass(BasicCommandClass.ID, new BasicCommandClass()); 31 | addCommandClass(MultilevelSwitchCommandClass.ID, new MultilevelSwitchCommandClass()); 32 | } 33 | 34 | public MultilevelSwitch(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 35 | super(pctx, nodeId, listener); 36 | } 37 | 38 | @Override 39 | protected void refresh(boolean deferIfNotListening) { 40 | // queueDataFrame(MultilevelSwitchCommandClass.createGetv1(getNodeId())); 41 | } 42 | 43 | public Byte getLevel() { 44 | MultilevelSwitchCommandClass cc = (MultilevelSwitchCommandClass)getCommandClass(MultilevelSwitchCommandClass.ID); 45 | if (cc != null) { 46 | return cc.getLevel(); 47 | } else { 48 | return null; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/generic/StaticController.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.generic; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeInfo; 13 | import com.whizzosoftware.wzwave.node.NodeListener; 14 | import com.whizzosoftware.wzwave.node.ZWaveNode; 15 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 16 | 17 | /** 18 | * A Static Controller node. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class StaticController extends ZWaveNode { 23 | public static final byte ID = 0x02; 24 | 25 | public StaticController(NodeInfo info, NodeListener listener) { 26 | super(info, true, listener); 27 | } 28 | 29 | public StaticController(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 30 | super(pctx, nodeId, listener); 31 | } 32 | 33 | @Override 34 | protected void refresh(boolean deferIfNotListening) { 35 | } 36 | 37 | @Override 38 | protected boolean shouldRequestNodeInfo() { 39 | return false; 40 | } 41 | 42 | @Override 43 | protected boolean shouldRequestState() { 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/AdvancedZensorNetAlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class AdvancedZensorNetAlarmSensor extends AlarmSensor { 22 | static public final byte ID = 0x05; 23 | 24 | public AdvancedZensorNetAlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public AdvancedZensorNetAlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/AdvancedZensorNetSmokeSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class AdvancedZensorNetSmokeSensor extends AlarmSensor { 22 | static public final byte ID = 0x0A; 23 | 24 | public AdvancedZensorNetSmokeSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public AdvancedZensorNetSmokeSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/BasicRoutingAlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | public class BasicRoutingAlarmSensor extends AlarmSensor { 21 | static public final byte ID = 0x01; 22 | 23 | public BasicRoutingAlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 24 | super(info, listening, listener); 25 | 26 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 27 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 28 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 29 | } 30 | 31 | public BasicRoutingAlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 32 | super(pctx, nodeId, listener); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/BasicRoutingSmokeSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | public class BasicRoutingSmokeSensor extends AlarmSensor { 21 | static public final byte ID = 0x06; 22 | 23 | public BasicRoutingSmokeSensor(NodeInfo info, boolean listening, NodeListener listener) { 24 | super(info, listening, listener); 25 | 26 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 27 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 28 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 29 | } 30 | 31 | public BasicRoutingSmokeSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 32 | super(pctx, nodeId, listener); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/BasicZensorNetAlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | public class BasicZensorNetAlarmSensor extends AlarmSensor { 21 | static public final byte ID = 0x03; 22 | 23 | public BasicZensorNetAlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 24 | super(info, listening, listener); 25 | 26 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 27 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 28 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 29 | } 30 | 31 | public BasicZensorNetAlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 32 | super(pctx, nodeId, listener); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/BasicZensorNetSmokeSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 15 | import com.whizzosoftware.wzwave.node.NodeInfo; 16 | import com.whizzosoftware.wzwave.node.NodeListener; 17 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 18 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 19 | 20 | public class BasicZensorNetSmokeSensor extends AlarmSensor { 21 | static public final byte ID = 0x08; 22 | 23 | public BasicZensorNetSmokeSensor(NodeInfo info, boolean listening, NodeListener listener) { 24 | super(info, listening, listener); 25 | 26 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 27 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 28 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 29 | } 30 | 31 | public BasicZensorNetSmokeSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 32 | super(pctx, nodeId, listener); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/BinaryPowerSwitch.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.node.specific; 9 | 10 | import com.whizzosoftware.wzwave.node.NodeInfo; 11 | import com.whizzosoftware.wzwave.node.NodeListener; 12 | import com.whizzosoftware.wzwave.node.generic.BinarySwitch; 13 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 14 | 15 | /** 16 | * A Binary Power Switch node. 17 | * 18 | * @author Dan Noguerol 19 | */ 20 | public class BinaryPowerSwitch extends BinarySwitch { 21 | static public final byte ID = 0x01; 22 | 23 | public BinaryPowerSwitch(NodeInfo info, boolean listening, NodeListener listener) { 24 | super(info, listening, listener); 25 | } 26 | 27 | public BinaryPowerSwitch(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 28 | super(pctx, nodeId, listener); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/MultilevelPowerSwitch.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeInfo; 13 | import com.whizzosoftware.wzwave.node.NodeListener; 14 | import com.whizzosoftware.wzwave.node.generic.MultilevelSwitch; 15 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 16 | 17 | /** 18 | * A Multilevel Power Switch node. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class MultilevelPowerSwitch extends MultilevelSwitch { 23 | static public final byte ID = 0x01; 24 | 25 | public MultilevelPowerSwitch(NodeInfo info, boolean listening, NodeListener listener) { 26 | super(info, listening, listener); 27 | } 28 | 29 | public MultilevelPowerSwitch(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 30 | super(pctx, nodeId, listener); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/PCController.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeInfo; 13 | import com.whizzosoftware.wzwave.node.NodeListener; 14 | import com.whizzosoftware.wzwave.node.generic.StaticController; 15 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 16 | 17 | /** 18 | * A PC Controller node. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class PCController extends StaticController { 23 | static public final byte ID = 0x01; 24 | 25 | public PCController(NodeInfo info, NodeListener listener) { 26 | super(info, listener); 27 | } 28 | 29 | public PCController(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 30 | super(pctx, nodeId, listener); 31 | } 32 | 33 | @Override 34 | protected void refresh(boolean deferIfNotListening) { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/RoutingAlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class RoutingAlarmSensor extends AlarmSensor { 22 | static public final byte ID = 0x02; 23 | 24 | public RoutingAlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public RoutingAlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/RoutingBinarySensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.WakeUpCommandClass; 13 | import com.whizzosoftware.wzwave.node.NodeInfo; 14 | import com.whizzosoftware.wzwave.node.NodeListener; 15 | import com.whizzosoftware.wzwave.node.generic.BinarySensor; 16 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 17 | 18 | /** 19 | * A Routing Binary Sensor node. 20 | * 21 | * @author Dan Noguerol 22 | */ 23 | public class RoutingBinarySensor extends BinarySensor { 24 | static public final byte ID = 0x01; 25 | 26 | public RoutingBinarySensor(NodeInfo info, boolean listening, NodeListener listener) { 27 | super(info, listening, listener); 28 | 29 | addCommandClass(WakeUpCommandClass.ID, new WakeUpCommandClass()); 30 | } 31 | 32 | public RoutingBinarySensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 33 | super(pctx, nodeId, listener); 34 | } 35 | 36 | public Byte getBatteryLevel() { 37 | return null; 38 | } 39 | 40 | public Boolean isBatteryLow() { 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/RoutingSmokeSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class RoutingSmokeSensor extends AlarmSensor { 22 | static public final byte ID = 0x07; 23 | 24 | public RoutingSmokeSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public RoutingSmokeSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/SimpleMeter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 14 | import com.whizzosoftware.wzwave.node.NodeInfo; 15 | import com.whizzosoftware.wzwave.node.NodeListener; 16 | import com.whizzosoftware.wzwave.node.generic.Meter; 17 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 18 | 19 | public class SimpleMeter extends Meter { 20 | static public final byte ID = 0x01; 21 | 22 | public SimpleMeter(NodeInfo info, boolean listening, NodeListener listener) { 23 | super(info, listening, listener); 24 | 25 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 26 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 27 | } 28 | 29 | public SimpleMeter(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 30 | super(pctx, nodeId, listener); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/ZensorNetAlarmSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class ZensorNetAlarmSensor extends AlarmSensor { 22 | static public final byte ID = 0x04; 23 | 24 | public ZensorNetAlarmSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public ZensorNetAlarmSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/node/specific/ZensorNetSmokeSensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node.specific; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.AlarmSensorCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.BatteryCommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.ManufacturerSpecificCommandClass; 15 | import com.whizzosoftware.wzwave.commandclass.VersionCommandClass; 16 | import com.whizzosoftware.wzwave.node.NodeInfo; 17 | import com.whizzosoftware.wzwave.node.NodeListener; 18 | import com.whizzosoftware.wzwave.node.generic.AlarmSensor; 19 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 20 | 21 | public class ZensorNetSmokeSensor extends AlarmSensor { 22 | static public final byte ID = 0x09; 23 | 24 | public ZensorNetSmokeSensor(NodeInfo info, boolean listening, NodeListener listener) { 25 | super(info, listening, listener); 26 | 27 | addCommandClass(AlarmSensor.ID, new AlarmSensorCommandClass()); 28 | addCommandClass(ManufacturerSpecificCommandClass.ID, new ManufacturerSpecificCommandClass()); 29 | addCommandClass(VersionCommandClass.ID, new VersionCommandClass()); 30 | addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass()); 31 | } 32 | 33 | public ZensorNetSmokeSensor(PersistenceContext pctx, Byte nodeId, NodeListener listener) { 34 | super(pctx, nodeId, listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/persist/PersistenceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist; 11 | 12 | import java.util.Map; 13 | 14 | /** 15 | * A context interface passed to nodes and command classes when they are saving state. 16 | * 17 | * @author Dan Noguerol 18 | */ 19 | public interface PersistenceContext { 20 | /** 21 | * Get a map for saving node state. 22 | * 23 | * @param nodeId the node ID being saved 24 | * 25 | * @return a Map 26 | */ 27 | Map getNodeMap(int nodeId); 28 | 29 | /** 30 | * Get a map for saving command class state. 31 | * 32 | * @param nodeId the node ID that owns the command class 33 | * @param commandClassId the command class ID being saved 34 | * 35 | * @return a Map 36 | */ 37 | Map getCommandClassMap(int nodeId, int commandClassId); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/persist/PersistentStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeCreationException; 13 | import com.whizzosoftware.wzwave.node.NodeListener; 14 | import com.whizzosoftware.wzwave.node.ZWaveNode; 15 | 16 | /** 17 | * An interface for persistent storage. 18 | * 19 | * @author Dan Noguerol 20 | */ 21 | public interface PersistentStore { 22 | /** 23 | * Retrieve a persisted node. 24 | * 25 | * @param nodeId the node ID 26 | * @param listener a listener 27 | * 28 | * @return a ZWaveNode (or null if not found) 29 | * @throws NodeCreationException if node data is found but fails to be restored 30 | */ 31 | ZWaveNode getNode(byte nodeId, NodeListener listener) throws NodeCreationException; 32 | 33 | /** 34 | * Persists a node. 35 | * 36 | * @param node the node to save 37 | */ 38 | void saveNode(ZWaveNode node); 39 | 40 | /** 41 | * Closes the persistent store. 42 | */ 43 | void close(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/persist/mapdb/MapDbPersistenceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist.mapdb; 11 | 12 | import com.whizzosoftware.wzwave.persist.PersistenceContext; 13 | import org.mapdb.DB; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * A MapDb implementation of PersistenceContext. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class MapDbPersistenceContext implements PersistenceContext { 23 | private DB db; 24 | 25 | public MapDbPersistenceContext(DB db) { 26 | this.db = db; 27 | } 28 | 29 | @Override 30 | public Map getNodeMap(int nodeId) { 31 | String key = Integer.toString(nodeId); 32 | return db.createHashMap(key).makeOrGet(); 33 | } 34 | 35 | @Override 36 | public Map getCommandClassMap(int nodeId, int commandClassId) { 37 | String key = nodeId + "." + commandClassId; 38 | return db.createHashMap(key).makeOrGet(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/persist/mapdb/MapDbPersistentStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist.mapdb; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeCreationException; 13 | import com.whizzosoftware.wzwave.node.NodeListener; 14 | import com.whizzosoftware.wzwave.node.ZWaveNode; 15 | import com.whizzosoftware.wzwave.node.ZWaveNodeFactory; 16 | import com.whizzosoftware.wzwave.persist.PersistentStore; 17 | import org.mapdb.DB; 18 | import org.mapdb.DBMaker; 19 | 20 | import java.io.File; 21 | 22 | /** 23 | * A MapDb implementation of PersistentStore. 24 | * 25 | * @author Dan Noguerol 26 | */ 27 | public class MapDbPersistentStore implements PersistentStore { 28 | private DB db; 29 | 30 | public MapDbPersistentStore(File dataDirectory) { 31 | db = DBMaker.newFileDB(new File(dataDirectory, "store")).make(); 32 | } 33 | 34 | public MapDbPersistenceContext getContext() { 35 | return new MapDbPersistenceContext(db); 36 | } 37 | 38 | @Override 39 | public ZWaveNode getNode(byte nodeId, NodeListener listener) throws NodeCreationException { 40 | return ZWaveNodeFactory.createNode(getContext(), nodeId, listener); 41 | } 42 | 43 | @Override 44 | public void saveNode(ZWaveNode node) { 45 | node.save(getContext()); 46 | db.commit(); 47 | } 48 | 49 | @Override 50 | public void close() { 51 | db.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/product/ProductInfo.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.product; 9 | 10 | /** 11 | * Class that encapsulates information about a product. 12 | * 13 | * @author Dan Noguerol 14 | */ 15 | public class ProductInfo { 16 | public static final String UNKNOWN = "Unknown"; 17 | 18 | private Integer manufacturerId; 19 | private String manufacturer; 20 | private Integer productTypeId; 21 | private Integer productId; 22 | private String name; 23 | 24 | public ProductInfo(Integer manufacturerId, Integer productTypeId, Integer productId) { 25 | this.manufacturerId = manufacturerId; 26 | this.productTypeId = productTypeId; 27 | this.productId = productId; 28 | } 29 | 30 | public Integer getManufacturerId() { 31 | return manufacturerId; 32 | } 33 | 34 | public void setManufacturerId(Integer manufacturerId) { 35 | this.manufacturerId = manufacturerId; 36 | } 37 | 38 | public String getManufacturer() { 39 | return manufacturer; 40 | } 41 | 42 | public void setManufacturer(String manufacturer) { 43 | this.manufacturer = manufacturer; 44 | } 45 | 46 | public Integer getProductTypeId() { 47 | return productTypeId; 48 | } 49 | 50 | public void setProductTypeId(Integer productTypeId) { 51 | this.productTypeId = productTypeId; 52 | } 53 | 54 | public Integer getProductId() { 55 | return productId; 56 | } 57 | 58 | public void setProductId(Integer productId) { 59 | this.productId = productId; 60 | } 61 | 62 | public String getName() { 63 | return name; 64 | } 65 | 66 | public void setName(String name) { 67 | this.name = name; 68 | } 69 | 70 | public boolean isComplete() { 71 | return (manufacturer != null && name != null && !UNKNOWN.equals(manufacturer) && !UNKNOWN.equals(name)); 72 | } 73 | 74 | public String toString() { 75 | if (manufacturer != null) { 76 | if (name == null) { 77 | name = UNKNOWN; 78 | } 79 | return manufacturer + " " + name; 80 | } else { 81 | return UNKNOWN; 82 | } 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/com/whizzosoftware/wzwave/util/ByteUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.util; 11 | 12 | import com.whizzosoftware.wzwave.frame.Frame; 13 | import io.netty.buffer.ByteBuf; 14 | 15 | import java.math.BigDecimal; 16 | 17 | /** 18 | * A utility class for various byte related functions. 19 | * 20 | * @author Dan Noguerol 21 | */ 22 | public class ByteUtil { 23 | final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); 24 | 25 | static public String createString(Frame message) { 26 | byte[] b = message.getBytes(); 27 | return createString(b, b.length); 28 | } 29 | 30 | static public String createString(byte[] bytes, int length) { 31 | return createString(bytes, 0, length); 32 | } 33 | 34 | static public String createString(byte[] bytes, int startIndex, int length) { 35 | char[] hexChars = new char[length * 5]; 36 | int v; 37 | for (int j=startIndex; j < length; j++) { 38 | v = bytes[j] & 0xFF; 39 | hexChars[j * 5] = '0'; 40 | hexChars[j * 5 + 1] = 'x'; 41 | hexChars[j * 5 + 2] = hexArray[v >>> 4]; 42 | hexChars[j * 5 + 3] = hexArray[v & 0x0F]; 43 | hexChars[j * 5 + 4] = ' '; 44 | } 45 | return new String(hexChars); 46 | } 47 | 48 | static public String createString(ByteBuf buf) { 49 | int length = buf.readableBytes(); 50 | char[] hexChars = new char[length * 5]; 51 | int v; 52 | int i = 0; 53 | for (int j=buf.readerIndex(); j < buf.readerIndex() + length; j++) { 54 | v = buf.getByte(j) & 0xFF; 55 | hexChars[i * 5] = '0'; 56 | hexChars[i * 5 + 1] = 'x'; 57 | hexChars[i * 5 + 2] = hexArray[v >>> 4]; 58 | hexChars[i * 5 + 3] = hexArray[v & 0x0F]; 59 | hexChars[i * 5 + 4] = ' '; 60 | i++; 61 | } 62 | return new String(hexChars); 63 | } 64 | 65 | static public String createString(byte b) { 66 | char[] hexChars = new char[4]; 67 | int v = b & 0xFF; 68 | hexChars[0] = '0'; 69 | hexChars[1] = 'x'; 70 | hexChars[2] = hexArray[v >>> 4]; 71 | hexChars[3] = hexArray[v & 0x0F]; 72 | return new String(hexChars); 73 | } 74 | 75 | static public int convertTwoBytesToInt(byte msb, byte lsb) { 76 | return (msb << 8) | (lsb); 77 | } 78 | 79 | static public double parseValue(byte[] b, int start, int length, int precision) { 80 | long value = 0; 81 | for (int i=start; i < start+length; i++) { 82 | int shift = 8 * ((length - (i - start)) - 1); 83 | value += (b[i] & 0xFF) << shift; 84 | } 85 | return new BigDecimal(value).movePointLeft(precision).doubleValue(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/channel/MockZWaveChannelContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.channel; 11 | 12 | import com.whizzosoftware.wzwave.frame.OutboundDataFrame; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class MockZWaveChannelContext implements ZWaveChannelContext { 18 | private final List writeQueue = new ArrayList<>(); 19 | private final List userEvents = new ArrayList<>(); 20 | 21 | public List getWriteQueue() { 22 | return writeQueue; 23 | } 24 | 25 | public List getUserEvents() { 26 | return userEvents; 27 | } 28 | 29 | @Override 30 | public void fireEvent(Object o) { 31 | userEvents.add(o); 32 | } 33 | 34 | @Override 35 | public void writeFrame(OutboundDataFrame f) { 36 | writeQueue.add(f); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/codec/ZWaveFrameEncoderTest.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.codec; 2 | 3 | import com.whizzosoftware.wzwave.frame.ACK; 4 | import com.whizzosoftware.wzwave.frame.CAN; 5 | import com.whizzosoftware.wzwave.frame.NAK; 6 | import io.netty.buffer.ByteBuf; 7 | import io.netty.buffer.Unpooled; 8 | import org.junit.Test; 9 | import static org.junit.Assert.*; 10 | 11 | public class ZWaveFrameEncoderTest { 12 | @Test 13 | public void testACK() throws Exception { 14 | ZWaveFrameEncoder encoder = new ZWaveFrameEncoder(); 15 | ByteBuf buf = Unpooled.buffer(); 16 | encoder.encode(null, new ACK(), buf); 17 | assertEquals(1, buf.readableBytes()); 18 | assertEquals(ACK.ID, buf.getByte(0)); 19 | } 20 | 21 | @Test 22 | public void testNAK() throws Exception { 23 | ZWaveFrameEncoder encoder = new ZWaveFrameEncoder(); 24 | ByteBuf buf = Unpooled.buffer(); 25 | encoder.encode(null, new NAK(), buf); 26 | assertEquals(1, buf.readableBytes()); 27 | assertEquals(NAK.ID, buf.getByte(0)); 28 | } 29 | 30 | @Test 31 | public void testCAN() throws Exception { 32 | ZWaveFrameEncoder encoder = new ZWaveFrameEncoder(); 33 | ByteBuf buf = Unpooled.buffer(); 34 | encoder.encode(null, new CAN(), buf); 35 | assertEquals(1, buf.readableBytes()); 36 | assertEquals(CAN.ID, buf.getByte(0)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/commandclass/CommandClassFactoryTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.commandclass; 9 | 10 | import org.junit.Test; 11 | import static org.junit.Assert.*; 12 | 13 | public class CommandClassFactoryTest { 14 | @Test 15 | public void testCommandClassCreate() { 16 | assertTrue(CommandClassFactory.createCommandClass(BasicCommandClass.ID) instanceof BasicCommandClass); 17 | assertTrue(CommandClassFactory.createCommandClass(BatteryCommandClass.ID) instanceof BatteryCommandClass); 18 | assertTrue(CommandClassFactory.createCommandClass(BinarySensorCommandClass.ID) instanceof BinarySensorCommandClass); 19 | assertTrue(CommandClassFactory.createCommandClass(BinarySwitchCommandClass.ID) instanceof BinarySwitchCommandClass); 20 | assertTrue(CommandClassFactory.createCommandClass(ColorControlCommandClass.ID) instanceof ColorControlCommandClass); 21 | assertTrue(CommandClassFactory.createCommandClass(IndicatorCommandClass.ID) instanceof IndicatorCommandClass); 22 | assertTrue(CommandClassFactory.createCommandClass(ManufacturerSpecificCommandClass.ID) instanceof ManufacturerSpecificCommandClass); 23 | assertTrue(CommandClassFactory.createCommandClass(MeterCommandClass.ID) instanceof MeterCommandClass); 24 | assertTrue(CommandClassFactory.createCommandClass(MultiInstanceCommandClass.ID) instanceof MultiInstanceCommandClass); 25 | assertTrue(CommandClassFactory.createCommandClass(MultilevelSensorCommandClass.ID) instanceof MultilevelSensorCommandClass); 26 | assertTrue(CommandClassFactory.createCommandClass(MultilevelSwitchCommandClass.ID) instanceof MultilevelSwitchCommandClass); 27 | assertTrue(CommandClassFactory.createCommandClass(VersionCommandClass.ID) instanceof VersionCommandClass); 28 | assertTrue(CommandClassFactory.createCommandClass(WakeUpCommandClass.ID) instanceof WakeUpCommandClass); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/commandclass/MultilevelCommandClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2013 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.commandclass; 11 | 12 | import org.junit.Test; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class MultilevelCommandClassTest { 17 | @Test 18 | public void testReport() { 19 | MultilevelSensorCommandClass cc = new MultilevelSensorCommandClass(); 20 | cc.onApplicationCommand(null, new byte[] {0x31, 0x05, 0x04, 0x64, 0x00, 0x06, (byte)0xFE, 0x14}, 0); 21 | assertEquals(MultilevelSensorCommandClass.Type.Power, cc.getType()); 22 | assertEquals(MultilevelSensorCommandClass.Scale.Watt, cc.getScale()); 23 | assertEquals(1, cc.getValues().size()); 24 | assertEquals(459.26, cc.getValues().get(0), 2); 25 | 26 | cc.onApplicationCommand(null, new byte[] {0x31, 0x05, 0x04, 0x64, 0x00, 0x06, (byte)0xFE, 0x14, 0x00, 0x06, (byte)0xFE, 0x14}, 0); 27 | assertEquals(2, cc.getValues().size()); 28 | assertEquals(459.26, cc.getValues().get(0), 2); 29 | assertEquals(459.26, cc.getValues().get(1), 2); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/controller/MockZWaveControllerContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2014 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.controller; 11 | 12 | import com.whizzosoftware.wzwave.frame.DataFrame; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class MockZWaveControllerContext implements ZWaveControllerContext { 18 | private List sentFrames = new ArrayList<>(); 19 | 20 | @Override 21 | public byte getNodeId() { 22 | return 0x01; 23 | } 24 | 25 | @Override 26 | public void sendDataFrame(DataFrame frame, boolean isListeningNode) { 27 | sentFrames.add(frame); 28 | } 29 | 30 | @Override 31 | public void sendEvent(Object e) { 32 | 33 | } 34 | 35 | public int getSentFrameCount() { 36 | return sentFrames.size(); 37 | } 38 | 39 | public List getSentFrames() { 40 | return sentFrames; 41 | } 42 | 43 | public void clearSentFrames() { 44 | sentFrames.clear(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/AddNodeToNetworkTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | 14 | import static junit.framework.TestCase.assertTrue; 15 | import static org.junit.Assert.assertEquals; 16 | import static org.junit.Assert.assertFalse; 17 | import static org.junit.Assert.assertNotNull; 18 | 19 | public class AddNodeToNetworkTest { 20 | @Test 21 | public void testRequestConstructor() { 22 | AddNodeToNetwork f = new AddNodeToNetwork(AddNodeToNetwork.ADD_NODE_ANY); 23 | byte[] b = f.getBytes(); 24 | assertEquals(7, b.length); 25 | } 26 | 27 | @Test 28 | public void testResponseConstructorWithNoNodeInfo() { 29 | byte[] b = new byte[] {0x01, 0x07, 0x00, 0x4A, 0x02, 0x01, 0x00, 0x00, (byte)0xB1}; 30 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 31 | AddNodeToNetwork f = new AddNodeToNetwork(buffer); 32 | assertEquals(1, buffer.readableBytes()); 33 | assertEquals(AddNodeToNetwork.ADD_NODE_STATUS_LEARN_READY, f.getStatus()); 34 | assertEquals(0, f.getSource()); 35 | assertFalse(f.hasNodeInfo()); 36 | } 37 | 38 | @Test 39 | public void testResponseConstructorWithNodeInfo() { 40 | byte[] b = new byte[] {0x01, 0x14, 0x00, 0x4A, 0x01, 0x03, 0x02, 0x0D, 0x04, 0x10, 0x01, 0x25, 0x31, 0x32, 0x27, 0x70, (byte)0x85, 0x72, (byte)0x86, (byte)0xEF, (byte)0x82, (byte)0xD4}; 41 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 42 | AddNodeToNetwork f = new AddNodeToNetwork(buffer); 43 | assertEquals(1, buffer.readableBytes()); 44 | assertEquals(AddNodeToNetwork.ADD_NODE_STATUS_ADDING_SLAVE, f.getStatus()); 45 | assertEquals(2, f.getSource()); 46 | assertTrue(f.hasNodeInfo()); 47 | assertEquals(0x04, f.getNodeInfo().getBasicDeviceClass()); 48 | assertEquals(0x10, f.getNodeInfo().getGenericDeviceClass()); 49 | assertEquals(0x01, f.getNodeInfo().getSpecificDeviceClass()); 50 | assertNotNull(f.getNodeInfo().getCommandClasses()); 51 | assertEquals(10, f.getNodeInfo().getCommandClasses().length); 52 | assertEquals(0x25, f.getNodeInfo().getCommandClasses()[0]); 53 | assertEquals(0x31, f.getNodeInfo().getCommandClasses()[1]); 54 | assertEquals(0x32, f.getNodeInfo().getCommandClasses()[2]); 55 | assertEquals(0x27, f.getNodeInfo().getCommandClasses()[3]); 56 | assertEquals(0x70, f.getNodeInfo().getCommandClasses()[4]); 57 | assertEquals((byte)0x85, f.getNodeInfo().getCommandClasses()[5]); 58 | assertEquals(0x72, f.getNodeInfo().getCommandClasses()[6]); 59 | assertEquals((byte)0x86, f.getNodeInfo().getCommandClasses()[7]); 60 | assertEquals((byte)0xEF, f.getNodeInfo().getCommandClasses()[8]); 61 | assertEquals((byte)0x82, f.getNodeInfo().getCommandClasses()[9]); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/ApplicationCommandTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import com.whizzosoftware.wzwave.commandclass.BinarySwitchCommandClass; 11 | import io.netty.buffer.ByteBuf; 12 | import io.netty.buffer.Unpooled; 13 | import org.junit.Test; 14 | import static org.junit.Assert.*; 15 | 16 | public class ApplicationCommandTest { 17 | @Test 18 | public void testExplicitConstructor() { 19 | ApplicationCommand cmd = new ApplicationCommand(DataFrameType.REQUEST, (byte)0, (byte)6, new byte[] {0x25, 0x03, 0x00}); 20 | byte[] b = cmd.getBytes(); 21 | assertEquals(10, b.length); 22 | assertEquals((byte)0x01, b[0]); 23 | assertEquals((byte)0x08, b[1]); 24 | assertEquals((byte)0x00, b[2]); 25 | assertEquals((byte)0x04, b[3]); 26 | assertEquals((byte)0x00, b[4]); 27 | assertEquals((byte)0x06, b[5]); 28 | assertEquals((byte)0x25, b[6]); 29 | assertEquals((byte)0x03, b[7]); 30 | assertEquals((byte)0x00, b[8]); 31 | assertEquals(-45, b[9]); 32 | } 33 | 34 | @Test 35 | public void testByteArrayConstructor() { 36 | byte[] b1 = {0x01,0x09,0x00,0x04,0x00,0x06,0x03,0x25,0x03,0x00,-45}; 37 | ByteBuf buffer = Unpooled.wrappedBuffer(b1); 38 | ApplicationCommand cmd = new ApplicationCommand(buffer); 39 | assertEquals(1, buffer.readableBytes()); 40 | assertEquals(0, cmd.getStatus()); 41 | assertEquals(6, cmd.getNodeId()); 42 | assertEquals(BinarySwitchCommandClass.ID, cmd.getCommandClassId()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/ApplicationUpdateTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | import static org.junit.Assert.*; 14 | 15 | public class ApplicationUpdateTest { 16 | @Test 17 | public void testConstructorWithNodeInfoReceived() { 18 | byte[] b = new byte[] {0x01, 16, 0x00, 0x49, (byte)0x84, 0x02, 0x0a, 0x04, 0x10, 0x01, 0x25, 0x27, 0x75, 0x73, (byte)0x86, 0x72, 0x77, (byte)0xb8}; 19 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 20 | ApplicationUpdate au = new ApplicationUpdate(buffer); 21 | assertEquals(1, buffer.readableBytes()); 22 | assertEquals(ApplicationUpdate.UPDATE_STATE_NODE_INFO_RECEIVED, au.getState()); 23 | assertEquals((byte)0x02, (byte)au.getNodeId()); 24 | assertNotNull(au.getNodeInfo()); 25 | assertEquals((byte)0x04, au.getNodeInfo().getBasicDeviceClass()); 26 | assertEquals((byte)0x10, au.getNodeInfo().getGenericDeviceClass()); 27 | assertEquals((byte)0x01, au.getNodeInfo().getSpecificDeviceClass()); 28 | assertEquals(7, au.getNodeInfo().getCommandClasses().length); 29 | assertEquals((byte)0x25, au.getNodeInfo().getCommandClasses()[0]); 30 | assertEquals((byte)0x27, au.getNodeInfo().getCommandClasses()[1]); 31 | assertEquals((byte)0x75, au.getNodeInfo().getCommandClasses()[2]); 32 | assertEquals((byte)0x73, au.getNodeInfo().getCommandClasses()[3]); 33 | assertEquals((byte)0x86, au.getNodeInfo().getCommandClasses()[4]); 34 | assertEquals((byte)0x72, au.getNodeInfo().getCommandClasses()[5]); 35 | assertEquals((byte)0x77, au.getNodeInfo().getCommandClasses()[6]); 36 | } 37 | 38 | @Test 39 | public void testConstructorWithNodeInfoRequestFailed() { 40 | byte[] b = new byte[] {0x01, 6, 0x00, 0x49, (byte)0x81, 0x00, 0x00, 0x31}; 41 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 42 | ApplicationUpdate au = new ApplicationUpdate(buffer); 43 | assertEquals(1, buffer.readableBytes()); 44 | assertEquals(ApplicationUpdate.UPDATE_STATE_NODE_INFO_REQ_FAILED, au.getState()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/InitDataTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | 14 | import java.util.List; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | public class InitDataTest { 19 | @Test 20 | public void testRequestConstructor() { 21 | InitData v = new InitData(); 22 | byte[] b = v.getBytes(); 23 | assertEquals(5, b.length); 24 | assertEquals(0x01, b[0]); // SOF 25 | assertEquals(0x03, b[1]); // length 26 | assertEquals(0x00, b[2]); // type (request) 27 | assertEquals(0x02, b[3]); // command ID 28 | assertEquals((byte)0xFE, b[4]); // checksum 29 | } 30 | 31 | @Test 32 | public void testResponseConstructor() { 33 | byte[] b = new byte[] {0x01, 0x25, 0x01, 0x02, 0x05, 0x00, 0x1d, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, (byte)0xe2}; 34 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 35 | InitData id = new InitData(buffer); 36 | assertEquals(1, buffer.readableBytes()); 37 | List nodes = id.getNodes(); 38 | assertEquals(2, nodes.size()); 39 | assertEquals(1, (int)nodes.get(0)); 40 | assertEquals(14, (int)nodes.get(1)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/MemoryGetIdTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | import static org.junit.Assert.*; 14 | 15 | public class MemoryGetIdTest { 16 | @Test 17 | public void testRequestConstructor() { 18 | MemoryGetId mgid = new MemoryGetId(); 19 | byte[] b = mgid.getBytes(); 20 | assertEquals(5, b.length); 21 | assertEquals(0x01, b[0]); 22 | assertEquals(0x03, b[1]); 23 | assertEquals(0x00, b[2]); 24 | assertEquals(0x20, b[3]); 25 | assertEquals((byte)0xDC, b[4]); 26 | } 27 | 28 | @Test 29 | public void testResponseConstructor() { 30 | byte[] b = new byte[] {0x01, 0x08, 0x01, 0x20, 0x01, 0x6a, 0x2d, (byte)0xec, 0x01, 0x7d}; 31 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 32 | MemoryGetId mgid = new MemoryGetId(buffer); 33 | assertEquals(1, buffer.readableBytes()); 34 | assertEquals(-20, (int)mgid.getHomeId()); // TODO 35 | assertEquals(0x01, (byte)mgid.getNodeId()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/NodeProtocolInfoTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | public class NodeProtocolInfoTest { 17 | @Test 18 | public void testRequestConstructor() { 19 | NodeProtocolInfo mgid = new NodeProtocolInfo((byte)0x01); 20 | byte[] b = mgid.getBytes(); 21 | assertEquals(6, b.length); 22 | assertEquals(0x01, b[0]); 23 | assertEquals(0x04, b[1]); 24 | assertEquals(0x00, b[2]); 25 | assertEquals(0x41, b[3]); 26 | assertEquals(0x01, b[4]); 27 | assertEquals((byte)0xBB, b[5]); 28 | } 29 | 30 | @Test 31 | public void testResponseConstructor() { 32 | byte[] b = new byte[] {0x01, 0x09, 0x01, 0x41, (byte)0x92, 0x16, 0x00, 0x02, 0x02, 0x01, 0x33}; 33 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 34 | NodeProtocolInfo npi = new NodeProtocolInfo(buffer); 35 | assertEquals(1, buffer.readableBytes()); 36 | assertTrue(npi.isListening()); 37 | assertTrue(npi.isBeaming()); 38 | assertFalse(npi.isRouting()); 39 | assertEquals(40000, npi.getMaxBaudRate()); 40 | assertEquals(3, npi.getVersion()); 41 | assertFalse(npi.hasSecurity()); 42 | assertEquals(0x02, npi.getBasicDeviceClass()); 43 | assertEquals(0x02, npi.getGenericDeviceClass()); 44 | assertEquals(0x01, npi.getSpecificDeviceClass()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/RequestNodeInfoTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | public class RequestNodeInfoTest { 17 | @Test 18 | public void testRequestConstructor() { 19 | RequestNodeInfo mgid = new RequestNodeInfo((byte)0x01); 20 | byte[] b = mgid.getBytes(); 21 | assertEquals(6, b.length); 22 | assertEquals(0x01, b[0]); 23 | assertEquals(0x04, b[1]); 24 | assertEquals(0x00, b[2]); 25 | assertEquals(0x60, b[3]); 26 | assertEquals(0x01, b[4]); 27 | assertEquals((byte)0x9A, b[5]); 28 | } 29 | 30 | @Test 31 | public void testResponseConstructor() { 32 | byte[] b = new byte[] {0x01, 0x04, 0x01, 0x60, 0x01, (byte)0x9B}; 33 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 34 | RequestNodeInfo rni = new RequestNodeInfo(buffer); 35 | assertEquals(1, buffer.readableBytes()); 36 | assertNotNull(rni.getRetVal()); 37 | assertEquals((byte)0x01, (byte)rni.getRetVal()); 38 | assertTrue(rni.wasSuccessfullySent()); 39 | assertEquals(1, buffer.readableBytes()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/SendDataTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | import static org.junit.Assert.*; 14 | 15 | public class SendDataTest { 16 | @Test 17 | public void testMessageArgConstructor() { 18 | SendData sd = new SendData("", (byte)0x02, new byte[] {(byte)0xFF}, (byte)0x05, (byte)0x01, true); 19 | byte[] mb = sd.getBytes(); 20 | assertEquals(10, mb.length); 21 | assertEquals(0x01, mb[0]); 22 | assertEquals(0x08, mb[1]); 23 | assertEquals(0x00, mb[2]); 24 | assertEquals(0x13, mb[3]); 25 | assertEquals(0x02, mb[4]); 26 | assertEquals(0x01, mb[5]); 27 | assertEquals((byte)0xFF, mb[6]); 28 | assertEquals(0x05, mb[7]); 29 | assertEquals(0x01, mb[8]); 30 | assertEquals(28, mb[9]); 31 | } 32 | 33 | @Test 34 | public void testMessageByteArrayConstructorWithRequest() { 35 | byte[] b = new byte[] {0x01, 0x09, 0x00, 0x13, 0x06, 0x02, 0x25, 0x02, 0x05, 0x08, -45}; 36 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 37 | SendData sd = new SendData(buffer); 38 | assertEquals(1, buffer.readableBytes()); 39 | assertEquals(DataFrameType.REQUEST, sd.getType()); 40 | assertFalse(sd.hasRetVal()); 41 | assertEquals((byte)0x06, sd.getNodeId()); 42 | assertTrue(sd.hasCallbackId()); 43 | assertEquals((byte)0x08, (byte)sd.getCallbackId()); 44 | } 45 | 46 | @Test 47 | public void testMessageByteArrayConstructorWithRetval() { 48 | byte[] b = new byte[] {0x01, 0x04, 0x01, 0x13, 0x01, (byte)0xE8}; 49 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 50 | SendData sd = new SendData(buffer); 51 | assertEquals(1, buffer.readableBytes()); 52 | assertEquals(DataFrameType.RESPONSE, sd.getType()); 53 | assertTrue(sd.hasRetVal()); 54 | assertEquals((byte)0x01, (byte)sd.getRetVal()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/VersionTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.frame; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.Unpooled; 12 | import org.junit.Test; 13 | import static org.junit.Assert.*; 14 | 15 | public class VersionTest { 16 | @Test 17 | public void testRequestConstructor() { 18 | Version v = new Version(); 19 | byte[] b = v.getBytes(); 20 | assertEquals(5, b.length); 21 | assertEquals(0x01, b[0]); // SOF 22 | assertEquals(0x03, b[1]); // length 23 | assertEquals(0x00, b[2]); // type (request) 24 | assertEquals(0x15, b[3]); // command ID 25 | assertEquals((byte)0xE9, b[4]); // checksum 26 | } 27 | 28 | @Test 29 | public void testResponseConstructor() { 30 | byte[] b = new byte[] {0x01, 0x10, 0x01, 0x15, 0x5a, 0x2d, 0x57, 0x61, 0x76, 0x65, 0x20, 0x32, 0x2e, 0x37, 0x38, 0x00, 0x01, (byte)0x9b}; 31 | ByteBuf buffer = Unpooled.wrappedBuffer(b); 32 | Version v = new Version(buffer); 33 | assertEquals(1, buffer.readableBytes()); 34 | assertEquals("Z-Wave 2.78", v.getLibraryVersion()); 35 | assertEquals(0x01, v.getLibraryType()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/frame/transaction/RequestNodeInfoTransactionTest.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.frame.transaction; 2 | 3 | import com.whizzosoftware.wzwave.channel.MockZWaveChannelContext; 4 | import com.whizzosoftware.wzwave.channel.event.TransactionCompletedEvent; 5 | import com.whizzosoftware.wzwave.channel.event.TransactionStartedEvent; 6 | import com.whizzosoftware.wzwave.frame.*; 7 | import io.netty.buffer.Unpooled; 8 | 9 | import org.junit.Test; 10 | import static org.junit.Assert.*; 11 | 12 | public class RequestNodeInfoTransactionTest { 13 | @Test 14 | public void testSendSuccess() { 15 | MockZWaveChannelContext ctx = new MockZWaveChannelContext(); 16 | RequestNodeInfo startFrame = new RequestNodeInfo((byte)0x2c); 17 | 18 | // start transaction 19 | RequestNodeInfoTransaction t = new RequestNodeInfoTransaction(ctx, startFrame, true); 20 | assertEquals(1, ctx.getUserEvents().size()); 21 | assertEquals(0, ctx.getWriteQueue().size()); 22 | assertTrue(ctx.getUserEvents().get(0) instanceof TransactionStartedEvent); 23 | 24 | // receive ACK 25 | assertTrue(t.addFrame(ctx, new ACK())); 26 | assertFalse(t.isComplete()); 27 | assertEquals(1, ctx.getUserEvents().size()); 28 | assertEquals(0, ctx.getWriteQueue().size()); 29 | 30 | // receive RequestNodeInfo 31 | assertTrue(t.addFrame(null, new RequestNodeInfo(Unpooled.wrappedBuffer(new byte[] {0x01, 0x04, 0x01, 0x60, 0x01, (byte)0x9b})))); 32 | assertFalse(t.isComplete()); 33 | assertEquals(1, ctx.getUserEvents().size()); 34 | assertEquals(0, ctx.getWriteQueue().size()); 35 | 36 | // receive ApplicationUpdate 37 | t.addFrame(ctx, new ApplicationUpdate(DataFrameType.REQUEST, ApplicationUpdate.UPDATE_STATE_NODE_INFO_RECEIVED, (byte)0x2c)); 38 | assertTrue(t.isComplete()); 39 | assertEquals(2, ctx.getUserEvents().size()); 40 | assertEquals(0, ctx.getWriteQueue().size()); 41 | assertTrue(ctx.getUserEvents().get(1) instanceof TransactionCompletedEvent); 42 | } 43 | 44 | @Test 45 | public void testSendFailure() { 46 | MockZWaveChannelContext ctx = new MockZWaveChannelContext(); 47 | 48 | RequestNodeInfo startFrame = new RequestNodeInfo((byte)0x2c); 49 | 50 | // start transaction 51 | RequestNodeInfoTransaction t = new RequestNodeInfoTransaction(ctx, startFrame, true); 52 | assertEquals(1, ctx.getUserEvents().size()); 53 | assertEquals(0, ctx.getWriteQueue().size()); 54 | assertTrue(ctx.getUserEvents().get(0) instanceof TransactionStartedEvent); 55 | 56 | // receive ACK 57 | assertTrue(t.addFrame(ctx, new ACK())); 58 | assertFalse(t.isComplete()); 59 | assertEquals(1, ctx.getUserEvents().size()); 60 | assertEquals(0, ctx.getWriteQueue().size()); 61 | 62 | // receive RequestNodeInfo 63 | assertTrue(t.addFrame(ctx, new RequestNodeInfo(Unpooled.wrappedBuffer(new byte[]{0x01, 0x04, 0x01, 0x60, 0x00, (byte) 0x9a})))); 64 | assertFalse(t.isComplete()); 65 | assertEquals(1, ctx.getUserEvents().size()); 66 | assertEquals(1, ctx.getWriteQueue().size()); 67 | assertTrue(ctx.getWriteQueue().get(0) instanceof OutboundDataFrame); 68 | assertTrue(((OutboundDataFrame)ctx.getWriteQueue().get(0)).getDataFrame() == startFrame); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/node/MockNodeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 13 | import com.whizzosoftware.wzwave.frame.DataFrame; 14 | 15 | import java.util.*; 16 | 17 | public class MockNodeContext implements NodeContext { 18 | private byte id; 19 | private Map commandClassMap = new HashMap<>(); 20 | private List sentDataFrames = new ArrayList<>(); 21 | 22 | public MockNodeContext(byte id, CommandClass[] classes) { 23 | this.id = id; 24 | if (classes != null) { 25 | for (CommandClass c : classes) { 26 | commandClassMap.put(c.getId(), c); 27 | } 28 | } 29 | } 30 | 31 | @Override 32 | public byte getNodeId() { 33 | return id; 34 | } 35 | 36 | @Override 37 | public void sendDataFrame(DataFrame d) { 38 | sentDataFrames.add(d); 39 | } 40 | 41 | @Override 42 | public void setSleeping(boolean sleeping) { 43 | 44 | } 45 | 46 | public List getSentDataFrames() { 47 | return sentDataFrames; 48 | } 49 | 50 | public void clearSentDataFrames() { 51 | sentDataFrames.clear(); 52 | } 53 | 54 | @Override 55 | public CommandClass getCommandClass(byte commandClassId) { 56 | return commandClassMap.get(commandClassId); 57 | } 58 | 59 | @Override 60 | public Collection getCommandClasses() { 61 | return commandClassMap.values(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/node/MultiChannelEncapsulatingNodeContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node; 11 | 12 | import com.whizzosoftware.wzwave.commandclass.BinarySwitchCommandClass; 13 | import com.whizzosoftware.wzwave.commandclass.CommandClass; 14 | import com.whizzosoftware.wzwave.commandclass.MultiInstanceCommandClass; 15 | import com.whizzosoftware.wzwave.frame.DataFrame; 16 | import com.whizzosoftware.wzwave.frame.SendData; 17 | import org.junit.Test; 18 | 19 | import static junit.framework.TestCase.assertFalse; 20 | import static org.junit.Assert.assertEquals; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | public class MultiChannelEncapsulatingNodeContextTest { 24 | @Test 25 | public void testResponseExpected() { 26 | MultiInstanceCommandClass micc = new MultiInstanceCommandClass(); 27 | micc.setVersion(2); 28 | BinarySwitchCommandClass bscc = new BinarySwitchCommandClass(); 29 | MockNodeContext ctx = new MockNodeContext((byte)0x01, new CommandClass[] {micc, bscc}); 30 | MultiChannelEncapsulatingNodeContext enctx = new MultiChannelEncapsulatingNodeContext(micc, (byte)0x01, ctx); 31 | enctx.sendDataFrame(bscc.createSet((byte)0x01, true)); 32 | assertEquals(1, ctx.getSentDataFrames().size()); 33 | DataFrame f = ctx.getSentDataFrames().get(0); 34 | assertTrue(f instanceof SendData); 35 | assertFalse(((SendData)f).isResponseExpected()); 36 | 37 | enctx.sendDataFrame(bscc.createGet((byte)0x01)); 38 | assertEquals(2, ctx.getSentDataFrames().size()); 39 | f = ctx.getSentDataFrames().get(1); 40 | assertTrue(f instanceof SendData); 41 | assertTrue(((SendData)f).isResponseExpected()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/node/StaticControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.whizzosoftware.wzwave.node; 2 | 3 | import com.whizzosoftware.wzwave.controller.MockZWaveControllerContext; 4 | import com.whizzosoftware.wzwave.frame.NodeProtocolInfo; 5 | import com.whizzosoftware.wzwave.node.generic.StaticController; 6 | import com.whizzosoftware.wzwave.node.specific.PCController; 7 | 8 | import org.junit.Test; 9 | import static org.junit.Assert.*; 10 | 11 | public class StaticControllerTest { 12 | @Test 13 | public void testNoRequestNodeInfo() { 14 | MockZWaveControllerContext ctx = new MockZWaveControllerContext(); 15 | PCController c = new PCController(new NodeInfo((byte)0x01, BasicDeviceClasses.ROUTING_SLAVE, StaticController.ID, PCController.ID), null); 16 | // PC Controller should not send out a RequestNodeInfo frame 17 | assertEquals(0, ctx.getSentFrameCount()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/node/ZWaveNodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.node; 11 | 12 | import com.whizzosoftware.wzwave.controller.MockZWaveControllerContext; 13 | import com.whizzosoftware.wzwave.node.generic.BinarySwitch; 14 | import com.whizzosoftware.wzwave.node.specific.BinaryPowerSwitch; 15 | import org.junit.Test; 16 | 17 | import static junit.framework.TestCase.assertTrue; 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertFalse; 20 | 21 | public class ZWaveNodeTest { 22 | @Test 23 | public void testLifecycleStartupListeningNodeWithFailedPing() { 24 | MockZWaveControllerContext ctx = new MockZWaveControllerContext(); 25 | MockNode node = new MockNode((byte)0x02, BasicDeviceClasses.ROUTING_SLAVE, BinarySwitch.ID, BinaryPowerSwitch.ID, true, null); 26 | node.startInterview(ctx); 27 | assertEquals(ZWaveNodeState.Ping, node.getState()); 28 | assertEquals(1, ctx.getSentFrames().size()); 29 | node.onSendDataCallback(ctx, false); 30 | assertFalse(node.isAvailable()); 31 | assertFalse(node.isSleeping()); 32 | assertTrue(node.isStarted()); 33 | } 34 | 35 | @Test 36 | public void testLifecycleStartupNonListeningNodeWithFailedPing() { 37 | MockZWaveControllerContext ctx = new MockZWaveControllerContext(); 38 | MockNode node = new MockNode((byte)0x02, BasicDeviceClasses.ROUTING_SLAVE, BinarySwitch.ID, BinaryPowerSwitch.ID, false, null); 39 | node.startInterview(ctx); 40 | assertEquals(ZWaveNodeState.Ping, node.getState()); 41 | assertEquals(1, ctx.getSentFrames().size()); 42 | node.onSendDataCallback(ctx, false); 43 | assertTrue(node.isAvailable()); 44 | assertTrue(node.isSleeping()); 45 | assertTrue(node.isStarted()); 46 | } 47 | 48 | private class MockNode extends ZWaveNode { 49 | public MockNode(byte nodeId, byte basicDeviceClass, byte genericDeviceClass, byte specificDeviceClass, boolean isListeningNode, NodeListener listener) { 50 | super(new NodeInfo(nodeId, basicDeviceClass, genericDeviceClass, specificDeviceClass), isListeningNode, listener); 51 | } 52 | 53 | @Override 54 | protected void refresh(boolean deferIfNotListening) { 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/persist/MapDbPersistentStoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist; 11 | 12 | import com.whizzosoftware.wzwave.node.BasicDeviceClasses; 13 | import com.whizzosoftware.wzwave.node.NodeInfo; 14 | import com.whizzosoftware.wzwave.node.ZWaveNode; 15 | import com.whizzosoftware.wzwave.node.generic.BinarySwitch; 16 | import com.whizzosoftware.wzwave.node.specific.BinaryPowerSwitch; 17 | import com.whizzosoftware.wzwave.persist.mapdb.MapDbPersistentStore; 18 | import org.junit.Rule; 19 | import org.junit.Test; 20 | import org.junit.rules.TemporaryFolder; 21 | 22 | import static junit.framework.TestCase.assertTrue; 23 | import static org.junit.Assert.assertEquals; 24 | 25 | public class MapDbPersistentStoreTest { 26 | @Rule 27 | public TemporaryFolder folder = new TemporaryFolder(); 28 | 29 | @Test 30 | public void testSaveAndRestoreNode() throws Exception { 31 | ZWaveNode node = new BinaryPowerSwitch(new NodeInfo((byte)0x02, BasicDeviceClasses.ROUTING_SLAVE, BinarySwitch.ID, BinaryPowerSwitch.ID), true, null); 32 | MapDbPersistentStore store = new MapDbPersistentStore(folder.newFolder()); 33 | store.saveNode(node); 34 | node = store.getNode((byte)0x02, null); 35 | assertEquals(0x02, node.getNodeId()); 36 | assertEquals(BasicDeviceClasses.ROUTING_SLAVE, (byte)node.getBasicDeviceClass()); 37 | assertEquals(BinarySwitch.ID, (byte)node.getGenericDeviceClass()); 38 | assertEquals(BinaryPowerSwitch.ID, (byte)node.getSpecificDeviceClass()); 39 | assertEquals(3, node.getCommandClasses().size()); 40 | assertTrue(node.isListeningNode()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/persist/MockPersistenceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | public class MockPersistenceContext implements PersistenceContext { 16 | private Map map = new HashMap<>(); 17 | 18 | @Override 19 | public Map getNodeMap(int nodeId) { 20 | String key = Integer.toString(nodeId); 21 | Map m = (Map)map.get(key); 22 | if (m == null) { 23 | m = new HashMap<>(); 24 | map.put(key, m); 25 | } 26 | return m; 27 | } 28 | 29 | @Override 30 | public Map getCommandClassMap(int nodeId, int commandClassId) { 31 | String key = nodeId + "." + commandClassId; 32 | Map m = (Map)map.get(key); 33 | if (m == null) { 34 | m = new HashMap<>(); 35 | map.put(key, m); 36 | } 37 | return m; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/persist/MockPersistentStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.persist; 11 | 12 | import com.whizzosoftware.wzwave.node.NodeListener; 13 | import com.whizzosoftware.wzwave.node.ZWaveNode; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | public class MockPersistentStore implements PersistentStore { 19 | private Map nodes = new HashMap<>(); 20 | 21 | @Override 22 | public ZWaveNode getNode(byte nodeId, NodeListener listener) { 23 | return nodes.get(nodeId); 24 | } 25 | 26 | @Override 27 | public void saveNode(ZWaveNode node) { 28 | nodes.put(node.getNodeId(), node); 29 | } 30 | 31 | @Override 32 | public void close() { 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/product/ProductRegistryTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Whizzo Software, LLC. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | *******************************************************************************/ 8 | package com.whizzosoftware.wzwave.product; 9 | 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Tests of {@link ProductRegistry}. 16 | * 17 | * @author Linus Brimstedt 18 | */ 19 | public class ProductRegistryTest { 20 | 21 | @Test 22 | public void testLookupProductUnknown() throws Exception { 23 | ProductInfo nullInfo = new ProductInfo(null, null, null); 24 | 25 | ProductInfo info = ProductRegistry.lookupProduct(8, 123, 123); 26 | assertFalse(info.isComplete()); 27 | } 28 | 29 | @Test 30 | public void testLookupProductKnown() throws Exception { 31 | ProductInfo info = ProductRegistry.lookupProduct(316, 1, 17); 32 | assertEquals("Philio Technology Corporation", info.getManufacturer()); 33 | assertEquals("Smart Energy Plug In Switch (PAN11)", info.getName()); 34 | assertTrue(info.isComplete()); 35 | } 36 | 37 | @Test 38 | public void testLookupPhilioPan16() { 39 | ProductInfo info = ProductRegistry.lookupProduct(316, 1, 41); 40 | assertEquals("Philio Technology Corporation", info.getManufacturer()); 41 | assertEquals("Smart Energy Plug In Switch (PAN16)", info.getName()); 42 | assertTrue(info.isComplete()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/whizzosoftware/wzwave/util/ByteUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016 Whizzo Software, LLC. 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | ******************************************************************************* 9 | */ 10 | package com.whizzosoftware.wzwave.util; 11 | 12 | import org.junit.Test; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class ByteUtilTest { 17 | @Test 18 | public void testParseValue() { 19 | assertEquals(1, ByteUtil.parseValue(new byte[] {(byte)0x01}, 0, 1, 0), 0); 20 | assertEquals(127, ByteUtil.parseValue(new byte[] {(byte)0x7F}, 0, 1, 0), 0); 21 | assertEquals(65535, ByteUtil.parseValue(new byte[] {(byte)0xFF, (byte)0xFF}, 0, 2, 0), 0); 22 | assertEquals(16777215, ByteUtil.parseValue(new byte[] {(byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF}, 0, 4, 0), 0); 23 | assertEquals(2147483647, ByteUtil.parseValue(new byte[] {(byte)0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF}, 0, 4, 0), 0); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /wzwave.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whizzosoftware/WZWave/b5a337842605bb88f4cb4c31211c4793dc4811e5/wzwave.jpg --------------------------------------------------------------------------------