From 3757e376325a188498341fbbfde3f2fc2e238f2b Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Sun, 23 Dec 2018 11:09:21 +0100 Subject: [PATCH 1/4] fix digital output Signed-off-by: Jan N. Klug --- .../internal/device/DS2406_DS2413.java | 3 +++ .../onewire/internal/device/DS2408.java | 8 +++----- .../internal/owserver/OwserverConnection.java | 4 ++-- .../internal/owserver/OwserverPacket.java | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2406_DS2413.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2406_DS2413.java index 97b347b8b4c..9b94e3601be 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2406_DS2413.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2406_DS2413.java @@ -43,6 +43,9 @@ public void configureChannels() throws OwException { outParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/PIO.A")); ioConfig.add(new DigitalIoConfig(callback.getThing(), 0, inParam, outParam)); + inParam = new OwDeviceParameterMap(); + outParam = new OwDeviceParameterMap(); + inParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/sensed.B")); outParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/PIO.B")); ioConfig.add(new DigitalIoConfig(callback.getThing(), 1, inParam, outParam)); diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2408.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2408.java index 5f8acd877a1..9003563ecb9 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2408.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/device/DS2408.java @@ -36,12 +36,10 @@ public DS2408(String sensorId, OwBaseThingHandler callback) { public void configureChannels() throws OwException { ioConfig.clear(); - OwDeviceParameterMap inParam = new OwDeviceParameterMap(); - OwDeviceParameterMap outParam = new OwDeviceParameterMap(); - - inParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("uncached/", "/sensed")); - outParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/PIO")); for (int i = 0; i < 8; i++) { + OwDeviceParameterMap inParam = new OwDeviceParameterMap(); + OwDeviceParameterMap outParam = new OwDeviceParameterMap(); + inParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("uncached/", String.format("/sensed.%d", i))); outParam.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter(String.format("/PIO.%d", i))); ioConfig.add(new DigitalIoConfig(callback.getThing(), i, inParam, outParam)); diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java index d0453044fb2..b5b2b964f8a 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java @@ -248,13 +248,13 @@ public OwPageBuffer readPages(String path) throws OwException { /** * write a DecimalType * - * @param path full owfs path to the sensor + * @param path full owfs path to the sensor * @param value the value to write * @throws OwException */ public void writeDecimalType(String path, DecimalType value) throws OwException { OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.WRITE, path); - requestPacket.setPayload(String.valueOf(value)); + requestPacket.appendPayload(String.valueOf(value), true); OwserverPacket returnPacket = request(requestPacket); diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java index 98e25125e2b..f2d58a1c527 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java @@ -159,7 +159,7 @@ public OwserverTemperatureScale getTemperatureScale() { } /** - * set this packet payload from a string + * set (or replace) this packet's payload from a string * * @param payload string representation of the payload */ @@ -170,6 +170,23 @@ public void setPayload(String payload) { System.arraycopy(bytes, 0, this.payload, 0, bytes.length); } + /** + * append to this packet's payload from a string + * + * @param payload string representation of the payload to append + * @param separator if a space should be added in front of the payload + */ + public void appendPayload(String payload, boolean separator) { + String fullPayload = getPayloadString(); + + if (separator) { + fullPayload += " "; + } + fullPayload += payload; + + setPayload(fullPayload); + } + /** * set this packet payload from a OwPageBuffer * From 5b60d11fffa23defe204c4dec05302cfc3eedc56 Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Mon, 24 Dec 2018 11:44:38 +0100 Subject: [PATCH 2/4] further fixes Signed-off-by: Jan N. Klug --- .../internal/owserver/OwserverConnection.java | 2 +- .../internal/owserver/OwserverPacket.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java index b5b2b964f8a..1069d177626 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java @@ -254,7 +254,7 @@ public OwPageBuffer readPages(String path) throws OwException { */ public void writeDecimalType(String path, DecimalType value) throws OwException { OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.WRITE, path); - requestPacket.appendPayload(String.valueOf(value), true); + requestPacket.appendPayload(String.valueOf(value)); OwserverPacket returnPacket = request(requestPacket); diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java index f2d58a1c527..220fcf2d163 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverPacket.java @@ -98,7 +98,11 @@ public OwserverPacket(OwserverMessageType owMessageType, String path, OwserverCo setPayload(path); setTemperatureScale(OwserverTemperatureScale.CENTIGRADE); setControlFlags(owControlFlags); - packetSize = 0x00001000; + if (owMessageType == OwserverMessageType.WRITE) { + packetSize = 0x00000001; + } else { + packetSize = 0x00010000; + } } /** @@ -173,18 +177,17 @@ public void setPayload(String payload) { /** * append to this packet's payload from a string * - * @param payload string representation of the payload to append - * @param separator if a space should be added in front of the payload + * @param payload string representation of the payload to append */ - public void appendPayload(String payload, boolean separator) { - String fullPayload = getPayloadString(); + public void appendPayload(String payload) { + byte appendBytes[] = payload.getBytes(); - if (separator) { - fullPayload += " "; - } - fullPayload += payload; + byte[] fullPayload = new byte[this.payload.length + appendBytes.length]; + System.arraycopy(this.payload, 0, fullPayload, 0, this.payload.length); + System.arraycopy(appendBytes, 0, fullPayload, this.payload.length, appendBytes.length); - setPayload(fullPayload); + this.payloadLength = fullPayload.length; + this.payload = fullPayload; } /** From ec2c969b50ee0519508ace358b5eb31dc5cb4389 Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Tue, 25 Dec 2018 09:58:45 +0100 Subject: [PATCH 3/4] fix wrong error message Signed-off-by: Jan N. Klug --- .../binding/onewire/internal/owserver/OwserverConnection.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java index 1069d177626..906bc6aebc9 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire/src/main/java/org/eclipse/smarthome/binding/onewire/internal/owserver/OwserverConnection.java @@ -270,6 +270,8 @@ public void writeDecimalType(String path, DecimalType value) throws OwException */ private OwserverPacket request(OwserverPacket requestPacket) throws OwException { OwserverPacket returnPacket = new OwserverPacket(OwserverPacketType.RETURN); + // answer to value write is always empty + boolean payloadExpected = requestPacket.getMessageType() != OwserverMessageType.WRITE; try { write(requestPacket); do { @@ -279,7 +281,7 @@ private OwserverPacket request(OwserverPacket requestPacket) throws OwException } else { returnPacket = read(false); } - } while (returnPacket.isPingPacket() || !returnPacket.hasPayload()); + } while (returnPacket.isPingPacket() || !(returnPacket.hasPayload() == payloadExpected)); } catch (OwException e) { logger.debug("failed requesting {}->{} [{}]", requestPacket, returnPacket, e.getMessage()); throw e; From 133a6a9ccd6dce005b98978d96f1478c5375e802 Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Tue, 25 Dec 2018 10:57:04 +0100 Subject: [PATCH 4/4] fix failing test Signed-off-by: Jan N. Klug --- .../smarthome/binding/onewire/test/OwserverTestServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/binding/org.eclipse.smarthome.binding.onewire.test/src/test/java/org/eclipse/smarthome/binding/onewire/test/OwserverTestServer.java b/extensions/binding/org.eclipse.smarthome.binding.onewire.test/src/test/java/org/eclipse/smarthome/binding/onewire/test/OwserverTestServer.java index 5280213d6a6..03b9053563b 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.onewire.test/src/test/java/org/eclipse/smarthome/binding/onewire/test/OwserverTestServer.java +++ b/extensions/binding/org.eclipse.smarthome.binding.onewire.test/src/test/java/org/eclipse/smarthome/binding/onewire/test/OwserverTestServer.java @@ -140,7 +140,6 @@ private ArrayList processPacket(OwserverPacket inputPacket) { } break; case WRITE: - returnPacket.setPayload(inputPacket.getPayloadString()); returnPackets.add(returnPacket); break; default: