Search in sources :

Example 1 with IpNode

use of org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode in project smarthome by eclipse.

the class ArtnetBridgeHandler method updateConfiguration.

@Override
protected void updateConfiguration() {
    Configuration configuration = getConfig();
    setUniverse(configuration.get(CONFIG_UNIVERSE), MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
    packetTemplate.setUniverse(universe.getUniverseId());
    receiverNodes.clear();
    if (configuration.get(CONFIG_ADDRESS) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not initialize sender (address not set)");
        uninstallScheduler();
        logger.debug("remote address not set for {}", this.thing.getUID());
        return;
    } else {
        try {
            receiverNodes = IpNode.fromString((String) configuration.get(CONFIG_ADDRESS), ArtnetNode.DEFAULT_PORT);
            logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
        } catch (IllegalArgumentException e) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
            return;
        }
    }
    if (configuration.get(CONFIG_LOCAL_ADDRESS) != null) {
        senderNode = new IpNode((String) configuration.get(CONFIG_LOCAL_ADDRESS));
    }
    logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
    if (configuration.get(CONFIG_REFRESH_MODE) != null) {
        refreshAlways = (((String) configuration.get(CONFIG_REFRESH_MODE)).equals("always"));
    }
    logger.debug("refresh mode set to always: {}", refreshAlways);
    updateStatus(ThingStatus.UNKNOWN);
    super.updateConfiguration();
    logger.debug("updated configuration for ArtNet bridge {}", this.thing.getUID());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode)

Example 2 with IpNode

use of org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode in project smarthome by eclipse.

the class Lib485BridgeHandler method openConnection.

@Override
protected void openConnection() {
    if (getThing().getStatus() != ThingStatus.ONLINE) {
        for (IpNode receiverNode : receiverNodes.keySet()) {
            Socket socket = receiverNodes.get(receiverNode);
            if (socket == null) {
                try {
                    socket = new Socket(receiverNode.getAddressString(), receiverNode.getPort());
                } catch (IOException e) {
                    logger.debug("Could not connect to {} in {}: {}", receiverNode, this.thing.getUID(), e.getMessage());
                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "could not connect to " + receiverNode.toString());
                    return;
                }
            }
            if (socket.isConnected()) {
                receiverNodes.put(receiverNode, socket);
            } else {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
                receiverNodes.put(receiverNode, null);
                return;
            }
        }
        updateStatus(ThingStatus.ONLINE);
    }
}
Also used : IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode) IOException(java.io.IOException) Socket(java.net.Socket)

Example 3 with IpNode

use of org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode in project smarthome by eclipse.

the class Lib485BridgeHandler method sendDmxData.

@Override
protected void sendDmxData() {
    if (getThing().getStatus() == ThingStatus.ONLINE) {
        long now = System.currentTimeMillis();
        universe.calculateBuffer(now);
        for (IpNode receiverNode : receiverNodes.keySet()) {
            Socket socket = receiverNodes.get(receiverNode);
            if (socket.isConnected()) {
                try {
                    socket.getOutputStream().write(universe.getBuffer());
                } catch (IOException e) {
                    logger.debug("Could not send to {} in {}: {}", receiverNode, this.thing.getUID(), e.getMessage());
                    closeConnection(ThingStatusDetail.COMMUNICATION_ERROR, "could not send DMX data");
                    return;
                }
            } else {
                closeConnection(ThingStatusDetail.NONE, "reconnect");
                return;
            }
        }
    } else {
        openConnection();
    }
}
Also used : IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode) IOException(java.io.IOException) Socket(java.net.Socket)

Example 4 with IpNode

use of org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode in project smarthome by eclipse.

the class Lib485BridgeHandler method closeConnection.

@Override
protected void closeConnection() {
    for (IpNode receiverNode : receiverNodes.keySet()) {
        Socket socket = receiverNodes.get(receiverNode);
        if ((socket != null) && (!socket.isClosed())) {
            try {
                socket.close();
            } catch (IOException e) {
                logger.warn("Could not close socket {} in {}: {}", receiverNode, this.thing.getUID(), e.getMessage());
            }
        }
        receiverNodes.put(receiverNode, null);
    }
}
Also used : IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode) IOException(java.io.IOException) Socket(java.net.Socket)

Example 5 with IpNode

use of org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode in project smarthome by eclipse.

the class Lib485BridgeHandler method updateConfiguration.

@Override
protected void updateConfiguration() {
    Configuration configuration = getConfig();
    universe = new Universe(MIN_UNIVERSE_ID);
    receiverNodes.clear();
    if (configuration.get(CONFIG_ADDRESS) == null) {
        receiverNodes.put(new IpNode("localhost:9020"), null);
        logger.debug("sending to {} for {}", receiverNodes, this.thing.getUID());
    } else {
        try {
            for (IpNode receiverNode : IpNode.fromString((String) configuration.get(CONFIG_ADDRESS), DEFAULT_PORT)) {
                receiverNodes.put(receiverNode, null);
                logger.debug("sending to {} for {}", receiverNode, this.thing.getUID());
            }
        } catch (IllegalArgumentException e) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
            return;
        }
    }
    super.updateConfiguration();
    updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE);
    logger.debug("updated configuration for Lib485 bridge {}", this.thing.getUID());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) IpNode(org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode) Universe(org.eclipse.smarthome.binding.dmx.internal.multiverse.Universe)

Aggregations

IpNode (org.eclipse.smarthome.binding.dmx.internal.dmxoverethernet.IpNode)6 IOException (java.io.IOException)3 Socket (java.net.Socket)3 Configuration (org.eclipse.smarthome.config.core.Configuration)3 Universe (org.eclipse.smarthome.binding.dmx.internal.multiverse.Universe)1