Search in sources :

Example 1 with PacketType

use of org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType 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)

Example 2 with PacketType

use of org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType in project openhab1-addons by openhab.

the class RFXComMessageFactory method getMessageInterface.

public static RFXComMessageInterface getMessageInterface(byte[] packet) throws RFXComException {
    PacketType packetType = getPacketType(packet[1]);
    try {
        String className = messageClasses.get(packetType);
        Class<?> cl = Class.forName(classUrl + className);
        Constructor<?> c = cl.getConstructor(byte[].class);
        return (RFXComMessageInterface) c.newInstance(packet);
    } catch (ClassNotFoundException e) {
        throw new RFXComException("Message " + packetType + "(" + packet[1] + ") not implemented", e);
    } catch (Exception e) {
        throw new RFXComException(e);
    }
}
Also used : RFXComException(org.openhab.binding.rfxcom.internal.RFXComException) PacketType(org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType) RFXComException(org.openhab.binding.rfxcom.internal.RFXComException)

Aggregations

PacketType (org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType)2 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 RFXComException (org.openhab.binding.rfxcom.internal.RFXComException)1 RFXComMessageInterface (org.openhab.binding.rfxcom.internal.messages.RFXComMessageInterface)1 RFXComTransmitterMessage (org.openhab.binding.rfxcom.internal.messages.RFXComTransmitterMessage)1