return seqNbr;
}
private void executeCommand(String itemName, Type command) {
if (itemName != null) {
RFXComBindingProvider provider = findFirstMatchingBindingProvider(itemName);
if (provider == null) {
logger.warn(
"Cannot execute command because no binding provider was found for itemname '{}'",
itemName);
return;
}
if (provider.isInBinding(itemName) == false) {
logger.debug(
"Received command (item='{}', state='{}', class='{}')",
new Object[] { itemName, command.toString(),
command.getClass().toString() });
RFXComSerialConnector connector = RFXComConnection
.getCommunicator();
if (connector == null) {
logger.warn("RFXCom controller is not initialized!");
return;
}
String id = provider.getId(itemName);
PacketType packetType = provider.getPacketType(itemName);
Object subType = provider.getSubType(itemName);
RFXComValueSelector valueSelector = provider
.getValueSelector(itemName);
try {
RFXComMessageInterface obj = RFXComMessageFactory.getMessageInterface(packetType);
obj.convertFromState(valueSelector, id, subType, command, getNextSeqNumber());
byte[] data = obj.decodeMessage();
logger.debug("Transmitting data: {}",
DatatypeConverter.printHexBinary(data));
setResponseMessage(null);
connector.sendMessage(data);
} catch (RFXComException e) {
e.printStackTrace();
} catch (IOException e) {
logger.error("Message sending to RFXCOM controller failed.", e);
}
try {
synchronized (notifierObject) {
notifierObject.wait(timeout);
}
RFXComTransmitterMessage resp = getResponseMessage();
switch (resp.response) {
case ACK:
case ACK_DELAYED:
logger.debug(
"Command succesfully transmitted, '{}' received",
resp.response);
break;
case NAK:
case NAK_INVALID_AC_ADDRESS:
case UNKNOWN:
logger.error("Command transmit failed, '{}' received",
resp.response);
break;
}
} catch (InterruptedException ie) {
logger.error(
"No acknowledge received from RFXCOM controller, timeout {}ms ",
timeout);
}
}
else
{
logger.warn(
"Provider is not in binding '{}'",
provider.toString());
}
}
}