2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dmx.internal.handler;
15 import static org.openhab.binding.dmx.internal.DmxBindingConstants.THING_TYPE_SACN_BRIDGE;
17 import java.util.ArrayList;
18 import java.util.Collections;
20 import java.util.UUID;
22 import org.openhab.binding.dmx.internal.config.SacnBridgeHandlerConfiguration;
23 import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetHandler;
24 import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
25 import org.openhab.binding.dmx.internal.dmxoverethernet.SacnNode;
26 import org.openhab.binding.dmx.internal.dmxoverethernet.SacnPacket;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.ThingStatus;
29 import org.openhab.core.thing.ThingStatusDetail;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The {@link SacnBridgeHandler} is responsible for handling the communication
36 * with sACN/E1.31 devices
38 * @author Jan N. Klug - Initial contribution
40 public class SacnBridgeHandler extends DmxOverEthernetHandler {
41 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_SACN_BRIDGE);
42 public static final int MIN_UNIVERSE_ID = 1;
43 public static final int MAX_UNIVERSE_ID = 63999;
45 private final Logger logger = LoggerFactory.getLogger(SacnBridgeHandler.class);
46 private final UUID senderUUID;
48 public SacnBridgeHandler(Bridge sacnBridge) {
50 senderUUID = UUID.randomUUID();
54 protected void updateConfiguration() {
55 SacnBridgeHandlerConfiguration configuration = getConfig().as(SacnBridgeHandlerConfiguration.class);
57 setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
58 packetTemplate.setUniverse(universe.getUniverseId());
60 receiverNodes.clear();
61 if ((configuration.mode.equals("unicast"))) {
62 if (configuration.address.isEmpty()) {
63 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
64 "Could not initialize unicast sender (address not set)");
68 receiverNodes = IpNode.fromString(configuration.address, SacnNode.DEFAULT_PORT);
69 logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
70 } catch (IllegalArgumentException e) {
71 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
76 receiverNodes = new ArrayList<>();
77 receiverNodes.add(SacnNode.getBroadcastNode(universe.getUniverseId()));
78 logger.debug("using multicast mode to {} for {}", receiverNodes, this.thing.getUID());
81 if (!configuration.localaddress.isEmpty()) {
82 senderNode = new IpNode(configuration.localaddress);
84 logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
86 refreshAlways = configuration.refreshmode.equals("always");
87 logger.debug("refresh mode set to always: {}", refreshAlways);
89 updateStatus(ThingStatus.UNKNOWN);
90 super.updateConfiguration();
92 logger.debug("updated configuration for sACN/E1.31 bridge {}", this.thing.getUID());
96 public void initialize() {
97 logger.debug("initializing sACN/E1.31 bridge {}", this.thing.getUID());
99 packetTemplate = new SacnPacket(senderUUID);
100 updateConfiguration();