Search in sources :

Example 1 with CULCommunicationException

use of org.openhab.io.transport.cul.CULCommunicationException in project openhab1-addons by openhab.

the class MaxCulMsgHandler method transmitMessage.

private void transmitMessage(BaseMsg data, SenderQueueItem queueItem) {
    try {
        cul.send(data.rawMsg);
    } catch (CULCommunicationException e) {
        logger.error("Unable to send CUL message " + data + " because: " + e.getMessage());
    }
    /* update surplus credit value */
    boolean fastSend = false;
    if (data.isPartOfSequence()) {
        fastSend = data.getMessageSequencer().useFastSend();
    }
    enoughCredit(data.requiredCredit(), fastSend);
    this.lastTransmit = new Date();
    if (this.endOfQueueTransmit.before(this.lastTransmit)) {
        /* hit a time after the queue finished tx'ing */
        this.endOfQueueTransmit = this.lastTransmit;
    }
    if (data.msgType != MaxCulMsgType.ACK) {
        /* awaiting ack now */
        SenderQueueItem qi = queueItem;
        if (qi == null) {
            qi = new SenderQueueItem();
            qi.msg = data;
        }
        qi.expiry = new Date(this.lastTransmit.getTime() + MESSAGE_EXPIRY_PERIOD);
        this.pendingAckQueue.put(qi.msg.msgCount, qi);
        /* schedule a check of pending acks */
        TimerTask ackCheckTask = new TimerTask() {

            @Override
            public void run() {
                checkPendingAcks();
            }
        };
        Timer timer = new Timer();
        timer.schedule(ackCheckTask, qi.expiry);
    }
}
Also used : TimerTask(java.util.TimerTask) Timer(java.util.Timer) CULCommunicationException(org.openhab.io.transport.cul.CULCommunicationException) Date(java.util.Date)

Example 2 with CULCommunicationException

use of org.openhab.io.transport.cul.CULCommunicationException in project openhab1-addons by openhab.

the class FS20Binding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    FS20BindingConfig bindingConfig = null;
    for (FS20BindingProvider provider : super.providers) {
        bindingConfig = provider.getConfigForItemName(itemName);
        if (bindingConfig != null) {
            break;
        }
    }
    if (bindingConfig != null) {
        logger.debug("Received command " + command.toString() + " for item " + itemName);
        try {
            FS20Command fs20Command = FS20CommandHelper.convertHABCommandToFS20Command(command);
            culHandlerLifecycle.getCul().send("F" + bindingConfig.getAddress() + fs20Command.getHexValue());
        } catch (CULCommunicationException e) {
            logger.error("An exception occured while sending a command", e);
        }
    }
}
Also used : FS20BindingConfig(org.openhab.binding.fs20.FS20BindingConfig) FS20BindingProvider(org.openhab.binding.fs20.FS20BindingProvider) CULCommunicationException(org.openhab.io.transport.cul.CULCommunicationException)

Example 3 with CULCommunicationException

use of org.openhab.io.transport.cul.CULCommunicationException in project openhab1-addons by openhab.

the class CULIntertechnoBinding method internalReceiveCommand.

/**
     *
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    IntertechnoBindingConfig config = null;
    for (CULIntertechnoBindingProvider provider : providers) {
        config = provider.getConfigForItemName(itemName);
        if (config != null) {
            break;
        }
    }
    if (config != null && culHandlerLifecycle.isCulReady() && command instanceof OnOffType) {
        OnOffType type = (OnOffType) command;
        String commandValue = null;
        switch(type) {
            case ON:
                commandValue = config.getCommandValueON();
                break;
            case OFF:
                commandValue = config.getCommandValueOFF();
                break;
        }
        if (commandValue != null) {
            try {
                culHandlerLifecycle.getCul().send("is" + config.getAddress() + commandValue);
            } catch (CULCommunicationException e) {
                logger.error("Can't write to CUL", e);
            }
        } else {
            logger.error("Can't determine value to send for command " + command.toString());
        }
    }
}
Also used : CULIntertechnoBindingProvider(org.openhab.binding.intertechno.CULIntertechnoBindingProvider) OnOffType(org.openhab.core.library.types.OnOffType) IntertechnoBindingConfig(org.openhab.binding.intertechno.IntertechnoBindingConfig) CULCommunicationException(org.openhab.io.transport.cul.CULCommunicationException)

Example 4 with CULCommunicationException

use of org.openhab.io.transport.cul.CULCommunicationException in project openhab1-addons by openhab.

the class CULManager method createNewHandler.

private <T extends CULConfig> CULHandlerInternal<T> createNewHandler(T config) throws CULDeviceException {
    String deviceType = config.getDeviceType();
    CULMode mode = config.getMode();
    logger.debug("Searching class for device type " + deviceType);
    @SuppressWarnings("unchecked") Class<? extends CULHandlerInternal<T>> culHandlerclass = (Class<? extends CULHandlerInternal<T>>) deviceTypeClasses.get(deviceType);
    if (culHandlerclass == null) {
        throw new CULDeviceException("No class for the device type " + deviceType + " is registred");
    }
    Class<?>[] constructorParametersTypes = { CULConfig.class };
    Object[] parameters = { config };
    try {
        Constructor<? extends CULHandlerInternal<T>> culHanlderConstructor = culHandlerclass.getConstructor(constructorParametersTypes);
        CULHandlerInternal<T> culHandler = culHanlderConstructor.newInstance(parameters);
        List<String> initCommands = mode.getCommands();
        if (!(culHandler instanceof CULHandlerInternal)) {
            logger.error("Class " + culHandlerclass.getCanonicalName() + " does not implement the internal interface");
            throw new CULDeviceException("This CULHandler class does not implement the internal interface: " + culHandlerclass.getCanonicalName());
        }
        CULHandlerInternal<?> internalHandler = culHandler;
        internalHandler.open();
        for (String command : initCommands) {
            internalHandler.sendWithoutCheck(command);
        }
        return culHandler;
    } catch (SecurityException e1) {
        throw new CULDeviceException("Not allowed to access the constructor ", e1);
    } catch (NoSuchMethodException e1) {
        throw new CULDeviceException("Can't find the constructor to build the CULHandler", e1);
    } catch (IllegalArgumentException e) {
        throw new CULDeviceException("Invalid arguments for constructor. CULConfig: " + config, e);
    } catch (InstantiationException e) {
        throw new CULDeviceException("Can't instantiate CULHandler object", e);
    } catch (IllegalAccessException e) {
        throw new CULDeviceException("Can't instantiate CULHandler object", e);
    } catch (InvocationTargetException e) {
        throw new CULDeviceException("Can't instantiate CULHandler object", e);
    } catch (CULCommunicationException e) {
        throw new CULDeviceException("Can't initialise RF mode", e);
    }
}
Also used : CULDeviceException(org.openhab.io.transport.cul.CULDeviceException) CULCommunicationException(org.openhab.io.transport.cul.CULCommunicationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CULMode(org.openhab.io.transport.cul.CULMode)

Aggregations

CULCommunicationException (org.openhab.io.transport.cul.CULCommunicationException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 FS20BindingConfig (org.openhab.binding.fs20.FS20BindingConfig)1 FS20BindingProvider (org.openhab.binding.fs20.FS20BindingProvider)1 CULIntertechnoBindingProvider (org.openhab.binding.intertechno.CULIntertechnoBindingProvider)1 IntertechnoBindingConfig (org.openhab.binding.intertechno.IntertechnoBindingConfig)1 OnOffType (org.openhab.core.library.types.OnOffType)1 CULDeviceException (org.openhab.io.transport.cul.CULDeviceException)1 CULMode (org.openhab.io.transport.cul.CULMode)1