Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

[OneWire] Fixed digitalio write #6725

Merged
merged 4 commits into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private ArrayList<OwserverPacket> processPacket(OwserverPacket inputPacket) {
}
break;
case WRITE:
returnPacket.setPayload(inputPacket.getPayloadString());
returnPackets.add(returnPacket);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

OwserverPacket returnPacket = request(requestPacket);

Expand All @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -159,7 +163,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
*/
Expand All @@ -170,6 +174,22 @@ 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
*/
public void appendPayload(String payload) {
byte appendBytes[] = payload.getBytes();

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);

this.payloadLength = fullPayload.length;
this.payload = fullPayload;
}

/**
* set this packet payload from a OwPageBuffer
*
Expand Down