Search in sources :

Example 1 with RFXComValueSelector

use of org.openhab.binding.rfxcom.RFXComValueSelector in project openhab1-addons by openhab.

the class RFXComBinding method executeCommand0.

private boolean executeCommand0(String itemName, Type command, final RFXComBindingProvider provider, RFXComSerialConnector connector) {
    String id = provider.getId(itemName);
    PacketType packetType = provider.getPacketType(itemName);
    Object subType = provider.getSubType(itemName);
    RFXComValueSelector valueSelector = provider.getValueSelector(itemName);
    final Future<RFXComTransmitterMessage> result;
    try {
        RFXComMessageInterface obj = RFXComMessageFactory.getMessageInterface(packetType);
        final byte seqNumber = getNextSeqNumber();
        obj.convertFromState(valueSelector, id, subType, command, seqNumber);
        byte[] data = obj.decodeMessage();
        logger.debug("Transmitting data: {}", DatatypeConverter.printHexBinary(data));
        result = resultRegistry.registerCommand(seqNumber);
        connector.sendMessage(data);
    } catch (IOException e) {
        logger.error("Message sending to RFXCOM controller failed.", e);
        return false;
    } catch (RFXComException e) {
        logger.error("Message sending to RFXCOM controller failed.", e);
        return false;
    }
    boolean success = false;
    try {
        final RFXComTransmitterMessage resp = result.get(timeout, TimeUnit.MILLISECONDS);
        switch(resp.response) {
            case ACK:
            case ACK_DELAYED:
                logger.debug("Command succesfully transmitted, '{}' received", resp.response);
                success = true;
                break;
            case NAK:
            case NAK_INVALID_AC_ADDRESS:
            case UNKNOWN:
                logger.error("Command transmit failed, '{}' received", resp.response);
                break;
        }
    } catch (InterruptedException e) {
        logger.error("No acknowledge received from RFXCOM controller, timeout {}ms due to", timeout, e);
    } catch (ExecutionException e) {
        logger.error("No acknowledge received from RFXCOM controller, timeout {}ms due to {}", timeout, e);
    } catch (TimeoutException e) {
        logger.error("No acknowledge received from RFXCOM controller, timeout {}ms due to {}", timeout, e);
    }
    return success;
}
Also used : RFXComTransmitterMessage(org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage) RFXComValueSelector(org.openhab.binding.rfxcom.RFXComValueSelector) IOException(java.io.IOException) PacketType(org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType) RFXComMessageInterface(org.openhab.binding.rfxcom.internal.messages.RFXComMessageInterface) EventObject(java.util.EventObject) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IOException (java.io.IOException)1 EventObject (java.util.EventObject)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 RFXComValueSelector (org.openhab.binding.rfxcom.RFXComValueSelector)1 PacketType (org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType)1 RFXComMessageInterface (org.openhab.binding.rfxcom.internal.messages.RFXComMessageInterface)1 RFXComTransmitterMessage (org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage)1