Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OHC serial transport #513

Merged
merged 6 commits into from Dec 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,10 +15,13 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.cc2531.internal.CC2531Configuration;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
import org.osgi.service.component.annotations.Activate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,19 +35,22 @@
import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit;
import com.zsmartsystems.zigbee.zcl.clusters.ZclIasZoneCluster;


/**
* The {@link CC2531Handler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Chris Jackson - Initial contribution
*/
// @NonNullByDefault
@NonNullByDefault
public class CC2531Handler extends ZigBeeCoordinatorHandler {
private final Logger logger = LoggerFactory.getLogger(CC2531Handler.class);

public CC2531Handler(Bridge coordinator) {
private final SerialPortManager serialPortManager;

@Activate
public CC2531Handler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
this.serialPortManager = serialPortManager;
}

@Override
Expand All @@ -56,7 +62,7 @@ public void initialize() {

CC2531Configuration config = getConfigAs(CC2531Configuration.class);

ZigBeePort serialPort = new ZigBeeSerialPort(config.zigbee_port, config.zigbee_baud,
ZigBeePort serialPort = new ZigBeeSerialPort(serialPortManager, config.zigbee_port, config.zigbee_baud,
FlowControl.FLOWCONTROL_OUT_RTSCTS);
final ZigBeeTransportTransmit dongle = new ZigBeeDongleTiCc2531(serialPort);

Expand All @@ -67,7 +73,7 @@ public void initialize() {

// The CC2531EMK dongle doesn't pass the MatchDescriptor commands to the stack, so we can't manage our services
// directly. Instead, register any services we want to support so the CC2531EMK can handle the MatchDescriptor.
Set<Integer> clusters = new HashSet<Integer>();
Set<Integer> clusters = new HashSet<>();
clusters.add(ZclIasZoneCluster.CLUSTER_ID);
transportConfig.addOption(TransportConfigOption.SUPPORTED_OUTPUT_CLUSTERS, clusters);

Expand Down
Expand Up @@ -27,11 +27,14 @@
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.cc2531.CC2531BindingConstants;
import org.openhab.binding.zigbee.cc2531.handler.CC2531Handler;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* The {@link CC2531HandlerFactory} is responsible for creating things and thing
Expand All @@ -42,11 +45,19 @@
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.cc2531")
@NonNullByDefault
public class CC2531HandlerFactory extends BaseThingHandlerFactory {
private Map<ThingUID, ServiceRegistration> coordinatorHandlerRegs = new HashMap<>();

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(CC2531BindingConstants.THING_TYPE_CC2531);

private final Map<ThingUID, ServiceRegistration<?>> coordinatorHandlerRegs = new HashMap<>();

private final SerialPortManager serialPortManager;

@Activate
public CC2531HandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -58,12 +69,12 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler coordinator = null;
if (thingTypeUID.equals(CC2531BindingConstants.THING_TYPE_CC2531)) {
coordinator = new CC2531Handler((Bridge) thing);
coordinator = new CC2531Handler((Bridge) thing, serialPortManager);
}

if (coordinator != null) {
coordinatorHandlerRegs.put(coordinator.getThing().getUID(), bundleContext.registerService(
ZigBeeCoordinatorHandler.class.getName(), coordinator, new Hashtable<String, Object>()));
coordinatorHandlerRegs.put(coordinator.getThing().getUID(), bundleContext
.registerService(ZigBeeCoordinatorHandler.class.getName(), coordinator, new Hashtable<>()));

return coordinator;
}
Expand All @@ -74,7 +85,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof CC2531Handler) {
ServiceRegistration coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
ServiceRegistration<?> coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
if (coordinatorHandlerReg != null) {
coordinatorHandlerReg.unregister();
coordinatorHandlerRegs.remove(thingHandler.getThing().getUID());
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
Expand All @@ -25,6 +26,7 @@
import org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler;
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback;
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressStep;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.ember.internal.EmberConfiguration;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
Expand Down Expand Up @@ -54,26 +56,30 @@
*/
// @NonNullByDefault
public class EmberHandler extends ZigBeeCoordinatorHandler implements FirmwareUpdateHandler {
private final Logger logger = LoggerFactory.getLogger(EmberHandler.class);

private ScheduledFuture<?> pollingJob;
private static final String ASH_RX_DAT = "ASH_RX_DAT";
private static final String ASH_TX_DAT = "ASH_TX_DAT";
private static final String ASH_RX_ACK = "ASH_RX_ACK";
private static final String ASH_TX_ACK = "ASH_TX_ACK";
private static final String ASH_RX_NAK = "ASH_RX_NAK";
private static final String ASH_TX_NAK = "ASH_TX_NAK";

private static final String UID_ASH_RX_DAT = "rx_dat";
private static final String UID_ASH_TX_DAT = "tx_dat";
private static final String UID_ASH_RX_ACK = "rx_ack";
private static final String UID_ASH_TX_ACK = "tx_ack";
private static final String UID_ASH_RX_NAK = "rx_nak";
private static final String UID_ASH_TX_NAK = "tx_nak";

private final Logger logger = LoggerFactory.getLogger(EmberHandler.class);

private final String ASH_RX_DAT = "ASH_RX_DAT";
private final String ASH_TX_DAT = "ASH_TX_DAT";
private final String ASH_RX_ACK = "ASH_RX_ACK";
private final String ASH_TX_ACK = "ASH_TX_ACK";
private final String ASH_RX_NAK = "ASH_RX_NAK";
private final String ASH_TX_NAK = "ASH_TX_NAK";
private final SerialPortManager serialPortManager;

private final String UID_ASH_RX_DAT = "rx_dat";
private final String UID_ASH_TX_DAT = "tx_dat";
private final String UID_ASH_RX_ACK = "rx_ack";
private final String UID_ASH_TX_ACK = "tx_ack";
private final String UID_ASH_RX_NAK = "rx_nak";
private final String UID_ASH_TX_NAK = "tx_nak";
private @Nullable ScheduledFuture<?> pollingJob;

public EmberHandler(Bridge coordinator) {
public EmberHandler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
this.serialPortManager = serialPortManager;
}

@Override
Expand All @@ -94,7 +100,8 @@ public void initialize() {
flowControl = FlowControl.FLOWCONTROL_OUT_NONE;
}

ZigBeePort serialPort = new ZigBeeSerialPort(config.zigbee_port, config.zigbee_baud, flowControl);
ZigBeePort serialPort = new ZigBeeSerialPort(serialPortManager, config.zigbee_port, config.zigbee_baud,
flowControl);
final ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(serialPort);

logger.debug("ZigBee Ember Coordinator opening Port:'{}' PAN:{}, EPAN:{}, Channel:{}", config.zigbee_port,
Expand Down
Expand Up @@ -27,26 +27,37 @@
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ember.EmberBindingConstants;
import org.openhab.binding.zigbee.ember.handler.EmberHandler;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* The {@link EmberHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Chris Jackson - Initial contribution
*/
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.ember")
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.ember")
public class EmberHandlerFactory extends BaseThingHandlerFactory {
private Map<ThingUID, ServiceRegistration> coordinatorHandlerRegs = new HashMap<>();

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(EmberBindingConstants.THING_TYPE_EMBER);

private final Map<ThingUID, ServiceRegistration<?>> coordinatorHandlerRegs = new HashMap<>();

private final SerialPortManager serialPortManager;

@Activate
public EmberHandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -58,12 +69,12 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler emberHandler = null;
if (thingTypeUID.equals(EmberBindingConstants.THING_TYPE_EMBER)) {
emberHandler = new EmberHandler((Bridge) thing);
emberHandler = new EmberHandler((Bridge) thing, serialPortManager);
}

if (emberHandler != null) {
coordinatorHandlerRegs.put(emberHandler.getThing().getUID(), bundleContext.registerService(
ZigBeeCoordinatorHandler.class.getName(), emberHandler, new Hashtable<String, Object>()));
coordinatorHandlerRegs.put(emberHandler.getThing().getUID(), bundleContext
.registerService(ZigBeeCoordinatorHandler.class.getName(), emberHandler, new Hashtable<>()));

return emberHandler;
}
Expand All @@ -74,7 +85,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof EmberHandler) {
ServiceRegistration coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
ServiceRegistration<?> coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
if (coordinatorHandlerReg != null) {
coordinatorHandlerReg.unregister();
coordinatorHandlerRegs.remove(thingHandler.getThing().getUID());
Expand Down
Expand Up @@ -23,10 +23,12 @@
import org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUpdateHandler;
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressCallback;
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressStep;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
import org.openhab.binding.zigbee.telegesis.internal.TelegesisConfiguration;
import org.osgi.service.component.annotations.Activate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,8 +54,12 @@
public class TelegesisHandler extends ZigBeeCoordinatorHandler implements FirmwareUpdateHandler {
private final Logger logger = LoggerFactory.getLogger(TelegesisHandler.class);

public TelegesisHandler(Bridge coordinator) {
private final SerialPortManager serialPortManager;

@Activate
public TelegesisHandler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
this.serialPortManager = serialPortManager;
}

@Override
Expand All @@ -65,7 +71,7 @@ public void initialize() {

TelegesisConfiguration config = getConfigAs(TelegesisConfiguration.class);

ZigBeePort serialPort = new ZigBeeSerialPort(config.zigbee_port, config.zigbee_baud,
ZigBeePort serialPort = new ZigBeeSerialPort(serialPortManager, config.zigbee_port, config.zigbee_baud,
FlowControl.FLOWCONTROL_OUT_NONE);
final ZigBeeDongleTelegesis dongle = new ZigBeeDongleTelegesis(serialPort);

Expand All @@ -78,7 +84,7 @@ public void initialize() {

// The Telegesis dongle doesn't pass the MatchDescriptor commands to the stack, so we can't manage our services
// directly. Instead, register any services we want to support so the Telegesis can handle the MatchDescriptor.
Set<Integer> clusters = new HashSet<Integer>();
Set<Integer> clusters = new HashSet<>();
clusters.add(ZclIasZoneCluster.CLUSTER_ID);
transportConfig.addOption(TransportConfigOption.SUPPORTED_OUTPUT_CLUSTERS, clusters);

Expand Down
Expand Up @@ -27,26 +27,37 @@
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.telegesis.TelegesisBindingConstants;
import org.openhab.binding.zigbee.telegesis.handler.TelegesisHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* The {@link TelegesisHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Chris Jackson - Initial contribution
*/
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.telegesis")
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.telegesis")
public class TelegesisHandlerFactory extends BaseThingHandlerFactory {
private Map<ThingUID, ServiceRegistration> coordinatorHandlerRegs = new HashMap<>();

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(TelegesisBindingConstants.THING_TYPE_TELEGESIS);

private final Map<ThingUID, ServiceRegistration<?>> coordinatorHandlerRegs = new HashMap<>();

private final SerialPortManager serialPortManager;

@Activate
public TelegesisHandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -58,7 +69,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler coordinator = null;
if (thingTypeUID.equals(TelegesisBindingConstants.THING_TYPE_TELEGESIS)) {
coordinator = new TelegesisHandler((Bridge) thing);
coordinator = new TelegesisHandler((Bridge) thing, serialPortManager);
}

if (coordinator != null) {
Expand All @@ -74,7 +85,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof TelegesisHandler) {
ServiceRegistration coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
ServiceRegistration<?> coordinatorHandlerReg = coordinatorHandlerRegs.get(thingHandler.getThing().getUID());
if (coordinatorHandlerReg != null) {
coordinatorHandlerReg.unregister();
coordinatorHandlerRegs.remove(thingHandler.getThing().getUID());
Expand Down