Skip to content

Commit

Permalink
Add slave length to command match function to only process expected s…
Browse files Browse the repository at this point in the history
…lave answers
  • Loading branch information
Christian S committed Jan 3, 2020
1 parent c14419e commit 380572e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import de.csdev.ebus.cfg.EBusConfigurationReaderException;
import de.csdev.ebus.cfg.IEBusConfigurationReader;
import de.csdev.ebus.command.IEBusCommandMethod.Type;
import de.csdev.ebus.command.datatypes.EBusTypeException;
import de.csdev.ebus.command.datatypes.EBusTypeRegistry;

Expand Down Expand Up @@ -253,6 +254,20 @@ public boolean matchesCommand(IEBusCommandMethod command, ByteBuffer data) {
}
}
if (i == mask.limit() - 1) {

// add additional check for master-slave telegrams
if (command.getType() == Type.MASTER_SLAVE) {

int computedSlaveLen = EBusCommandUtils.getSlaveDataLength(command);
int slaveLenPos = masterTelegram.limit() + 1;
int slaveLen = data.get(slaveLenPos);

if (slaveLen != computedSlaveLen) {
return false;
}

}

return true;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/de/csdev/ebus/command/EBusCommandUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,20 @@ public static ByteBuffer getMasterTelegramMask(IEBusCommandMethod commandChannel
return buf;
}

/**
*
* @param command
* @return
*/
public static int getSlaveDataLength(IEBusCommandMethod command) {
if (command.getType() == Type.MASTER_SLAVE) {
int len = 0;
for (IEBusValue value : command.getSlaveTypes()) {
len += value.getType().getTypeLength();
}
return len;
}

return -1;
}
}

0 comments on commit 380572e

Please sign in to comment.