2 * Copyright (c) 2010-2023 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;
19 import java.util.UUID;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
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.DmxOverEthernetPacket;
25 import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
26 import org.openhab.binding.dmx.internal.dmxoverethernet.SacnNode;
27 import org.openhab.binding.dmx.internal.dmxoverethernet.SacnPacket;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.ThingStatus;
30 import org.openhab.core.thing.ThingStatusDetail;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * The {@link SacnBridgeHandler} is responsible for handling the communication
37 * with sACN/E1.31 devices
39 * @author Jan N. Klug - Initial contribution
42 public class SacnBridgeHandler extends DmxOverEthernetHandler {
43 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_SACN_BRIDGE);
44 public static final int MIN_UNIVERSE_ID = 1;
45 public static final int MAX_UNIVERSE_ID = 63999;
47 private final Logger logger = LoggerFactory.getLogger(SacnBridgeHandler.class);
48 private final UUID senderUUID;
50 public SacnBridgeHandler(Bridge sacnBridge) {
52 senderUUID = UUID.randomUUID();
56 protected void updateConfiguration() {
57 SacnBridgeHandlerConfiguration configuration = getConfig().as(SacnBridgeHandlerConfiguration.class);
59 setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
60 DmxOverEthernetPacket packetTemplate = this.packetTemplate;
61 if (packetTemplate == null) {
62 packetTemplate = new SacnPacket(senderUUID);
63 this.packetTemplate = packetTemplate;
65 packetTemplate.setUniverse(universe.getUniverseId());
67 receiverNodes.clear();
68 if (("unicast".equals(configuration.mode))) {
69 if (configuration.address.isEmpty()) {
70 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
71 "Could not initialize unicast sender (address not set)");
75 receiverNodes = IpNode.fromString(configuration.address, SacnNode.DEFAULT_PORT);
76 logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
77 } catch (IllegalArgumentException e) {
78 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
83 receiverNodes = new ArrayList<>();
84 receiverNodes.add(SacnNode.getBroadcastNode(universe.getUniverseId()));
85 logger.debug("using multicast mode to {} for {}", receiverNodes, this.thing.getUID());
88 if (!configuration.localaddress.isEmpty()) {
89 senderNode = new IpNode(configuration.localaddress);
91 logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
93 refreshAlways = "always".equals(configuration.refreshmode);
94 logger.debug("refresh mode set to always: {}", refreshAlways);
96 updateStatus(ThingStatus.UNKNOWN);
97 super.updateConfiguration();
99 logger.debug("updated configuration for sACN/E1.31 bridge {}", this.thing.getUID());
103 public void initialize() {
104 logger.debug("initializing sACN/E1.31 bridge {}", this.thing.getUID());
106 packetTemplate = new SacnPacket(senderUUID);
107 updateConfiguration();