Add rudimentary support for DS18B120 Thermometers, MH-Z19B CO2 Sensors, and ZWave.me controllers.

This commit is contained in:
MarkBryanMilligan
2021-10-26 15:45:13 -05:00
parent 883cf7865d
commit 88933a2286
19 changed files with 334 additions and 67 deletions

View File

@@ -39,13 +39,13 @@ public class Controller {
private SerialPort serialPort;
private OutputStream os;
private boolean running = false;
private AtomicInteger callbackId = new AtomicInteger(0);
private final AtomicInteger callbackId = new AtomicInteger(0);
private final Object ackMutex = new Object();
private final Object responseMutex = new Object();
private final Object callbackMutex = new Object();
private boolean responseReceived;
private final Map<Byte, Byte> callbacks = new HashMap<>();
private ExecutorService executor = Executors.newFixedThreadPool(2);
private final ExecutorService executor = Executors.newFixedThreadPool(2);
private NodeManager nodeManager;
public boolean start(String _port) {
@@ -172,9 +172,10 @@ public class Controller {
logger.debug("Finished outbound of: {}", message.describe());
}
if (message instanceof RequestMessage) {
logger.debug("Waiting for response from: {}", message.describe());
synchronized (responseMutex) {
responseMutex.wait(1000);
logger.debug("Waiting for response from: {}", message.describe());
if (!responseReceived)
responseMutex.wait(1000);
logger.debug("Response received: {}", responseReceived);
responseReceived = false;
}

View File

@@ -33,9 +33,17 @@ public abstract class MessageEngine {
}
MessageType messageType = _data[2] == 0x00 ? MessageType.REQUEST : MessageType.RESPONSE;
ControllerMessageType controllerMessageType = ControllerMessageType.fromByte((byte)(_data[3] & 0xFF));
int offset = ((messageType == MessageType.REQUEST) && NullUtils.isOneOf(controllerMessageType, ControllerMessageType.SendData, ControllerMessageType.ApplicationCommandHandler))?7:5;
CommandClass commandClass = _data.length > offset + 1 ? CommandClass.fromByte((byte)(_data[offset] & 0xFF)):CommandClass.NO_OPERATION;
byte command = ((commandClass == CommandClass.NO_OPERATION) || (_data.length <= offset+2))?0:(byte)(_data[offset+1] & 0xFF);
CommandClass commandClass = CommandClass.NO_OPERATION;
byte command = 0;
int offset = 5;
if (NullUtils.isOneOf(controllerMessageType, ControllerMessageType.SendData, ControllerMessageType.ApplicationCommandHandler)) {
if (messageType == MessageType.REQUEST)
offset = 7;
if (_data.length > offset + 1)
commandClass = CommandClass.fromByte((byte)(_data[offset] & 0xFF));
if (_data.length > offset + 2)
command = (byte)(_data[offset+1] & 0xFF);
}
Message message = messages.get(Message.toKey(controllerMessageType.data, messageType.data, commandClass.data, command));
if (message == null) {
logger.debug("Could not find message class for message: {} {} {} {}", controllerMessageType.label, messageType.name(), commandClass.label, command);

View File

@@ -0,0 +1,17 @@
package com.lanternsoftware.zwave.message.impl;
import com.lanternsoftware.zwave.message.ControllerMessageType;
import com.lanternsoftware.zwave.message.NoCommandRequestMessage;
public class AddNodeToNetworkRequest extends NoCommandRequestMessage {
public AddNodeToNetworkRequest() {
super(ControllerMessageType.AddNodeToNetwork);
}
@Override
public byte[] getPayload() {
byte[] payload = new byte[1];
payload[0] = (byte)0x05;
return payload;
}
}

View File

@@ -1,3 +1,4 @@
com.lanternsoftware.zwave.message.impl.AddNodeToNetworkRequest
com.lanternsoftware.zwave.message.impl.ApplicationUpdateRequest
com.lanternsoftware.zwave.message.impl.AssociationGetRequest
com.lanternsoftware.zwave.message.impl.AssociationReportRequest