Some small updates and fixes for Zigbee

This commit is contained in:
Ziver Koc 2021-01-26 01:52:50 +01:00
parent 326d773741
commit 65581f13d5
12 changed files with 77 additions and 38 deletions

View file

@ -29,7 +29,12 @@ import java.util.logging.Logger;
public class HalZigbeeController implements HalSensorController, HalEventController, HalAutoScannableController {
private static final Logger logger = LogUtil.getLogger();
public static final String ZIGBEE_DONGLE_CC2531 = "CC2531";
public static final String ZIGBEE_DONGLE_CONBEE = "CONBEE";
public static final String ZIGBEE_DONGLE_XBEE = "XBEE";
private static final String CONFIG_ZIGBEE_PORT = "zigbee.com_port";
private static final String CONFIG_ZIGBEE_DONGLE = "zigbee.dongle";
private ZigBeePort serialPort;
private ZigBeeDataStore dataStore;
@ -45,22 +50,23 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
@Override
public boolean isAvailable() {
return HalContext.containsProperty(CONFIG_ZIGBEE_PORT);
return HalContext.containsProperty(CONFIG_ZIGBEE_PORT) &&
HalContext.containsProperty(CONFIG_ZIGBEE_DONGLE);
}
@Override
public void initialize() {
initialize(
HalContext.getStringProperty(CONFIG_ZIGBEE_PORT));
initialize(HalContext.getStringProperty(CONFIG_ZIGBEE_PORT), HalContext.getStringProperty(CONFIG_ZIGBEE_DONGLE));
}
public void initialize(String comPort) {
public void initialize(String comPort, String dongleName) {
serialPort = new ZigBeeJSerialCommPort(comPort);
dataStore = new ZigBeeDataStore();
TransportConfig transportOptions = new TransportConfig();
// ----------------------------
// Initialize Transport Network
// ----------------------------
ZigBeeTransportTransmit dongle = getDongle("CC2531", serialPort);
ZigBeeTransportTransmit dongle = getDongle(dongleName, serialPort, transportOptions);
networkManager = new ZigBeeNetworkManager(dongle);
networkManager.setNetworkDataStore(dataStore);
networkManager.setSerializer(DefaultSerializer.class, DefaultDeserializer.class);
@ -77,10 +83,9 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
networkManager.setDefaultProfileId(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey());
TransportConfig transportOptions = new TransportConfig();
transportOptions.addOption(TransportConfigOption.RADIO_TX_POWER, 3);
transportOptions.addOption(TransportConfigOption.TRUST_CENTRE_JOIN_MODE, TrustCentreJoinMode.TC_JOIN_SECURE);
transportOptions.addOption(TransportConfigOption.TRUST_CENTRE_LINK_KEY, new ZigBeeKey(new int[] {
transportOptions.addOption(TransportConfigOption.TRUST_CENTRE_LINK_KEY, new ZigBeeKey(new int[] { // Add the default ZigBeeAlliance09 HA link key
0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 }));
dongle.updateTransportConfig(transportOptions);
@ -100,21 +105,22 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
// Other stuff
// -----------
/*if (dongle instanceof ZigBeeDongleTiCc2531) {
if (dongle instanceof ZigBeeDongleTiCc2531) {
ZigBeeDongleTiCc2531 tiDongle = (ZigBeeDongleTiCc2531) dongle;
tiDongle.setLedMode(1, false);
tiDongle.setLedMode(2, false);
}*/
}
}
private static ZigBeeTransportTransmit getDongle(String name, ZigBeePort serialPort) {
private static ZigBeeTransportTransmit getDongle(String name, ZigBeePort serialPort, TransportConfig transportOptions) {
switch (name) {
case "CC2531":
case ZIGBEE_DONGLE_CC2531:
transportOptions.addOption(TransportConfigOption.RADIO_TX_POWER, 3);
return new ZigBeeDongleTiCc2531(serialPort);
case "XBEE":
return new ZigBeeDongleXBee(serialPort);
case "CONBEE":
case ZIGBEE_DONGLE_CONBEE:
return new ZigBeeDongleConBee(serialPort);
case ZIGBEE_DONGLE_XBEE:
return new ZigBeeDongleXBee(serialPort);
default:
logger.severe("Unknown ZigBee dongle: " + name);
return null;

View file

@ -112,6 +112,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
return true;
} catch (Exception e) {
logger.error("Unable to open serial port: " + e.getMessage());
close();
return false;
}
}
@ -179,7 +180,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
@Override
public void write(int value) {
if (serialPort == null)
if (serialOutputstream == null)
throw new RuntimeException("Unable to write, Serial port is not open.");
try {
@ -196,7 +197,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
@Override
public int read(int timeout) {
if (serialPort == null)
if (serialInputstream == null)
throw new RuntimeException("Unable to read, Serial port is not open.");
try {
@ -212,7 +213,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
@Override
public void purgeRxBuffer() {
if (serialPort == null)
if (serialOutputstream == null)
return;
try {

View file

@ -41,7 +41,7 @@ public class HalZigbeeControllerTest {
LogUtil.setGlobalLevel(Level.ALL);
HalZigbeeController controller = new HalZigbeeController();
controller.initialize("COM3");
controller.initialize("COM4", HalZigbeeController.ZIGBEE_DONGLE_CONBEE);
System.out.println("PAN ID = " + controller.networkManager.getZigBeePanId());
System.out.println("Extended PAN ID = " + controller.networkManager.getZigBeeExtendedPanId());
@ -90,8 +90,14 @@ public class HalZigbeeControllerTest {
}
private static char waitForInout() throws IOException {
System.out.print("");
System.out.print("Input command and finish with ENTER: ");
return (char) System.in.read();
while (true) {
char input=(char)System.in.read();
if (input != '\n')
return input;
}
}
}