Some small updates and fixes for Zigbee
This commit is contained in:
parent
326d773741
commit
65581f13d5
12 changed files with 77 additions and 38 deletions
|
|
@ -19,7 +19,6 @@ import java.util.logging.Logger;
|
|||
/**
|
||||
* This class manages all SensorController and EventController objects
|
||||
*/
|
||||
@SuppressWarnings("RedundantCast")
|
||||
public class ControllerManager implements HalSensorReportListener,
|
||||
HalEventReportListener,
|
||||
PreConfigurationActionListener,
|
||||
|
|
@ -31,21 +30,21 @@ public class ControllerManager implements HalSensorReportListener,
|
|||
/** All available sensor plugins **/
|
||||
private List<Class<? extends HalSensorConfig>> availableSensors = new ArrayList<>();
|
||||
/** List of all registered sensors **/
|
||||
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<Sensor>());
|
||||
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected sensors **/
|
||||
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<Sensor>());
|
||||
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of sensors that are currently being reconfigured **/
|
||||
private List<Sensor> limboSensors = Collections.synchronizedList(new LinkedList<Sensor>());
|
||||
private List<Sensor> limboSensors = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
|
||||
/** All available event plugins **/
|
||||
private List<Class<? extends HalEventConfig>> availableEvents = new ArrayList<>();
|
||||
/** List of all registered events **/
|
||||
private List<Event> registeredEvents = Collections.synchronizedList(new ArrayList<Event>());
|
||||
private List<Event> registeredEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of auto detected events **/
|
||||
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<Event>());
|
||||
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<>());
|
||||
/** List of all registered events **/
|
||||
private List<Event> limboEvents = Collections.synchronizedList(new LinkedList<Event>());
|
||||
private List<Event> limboEvents = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
|
||||
/** A map of all instantiated controllers **/
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
package se.hal.intf;
|
||||
|
||||
public interface HalAbstractController {
|
||||
|
||||
public interface HalAbstractController<C, L> {
|
||||
|
||||
/**
|
||||
* The framework might create dummy objects so any type of
|
||||
|
|
@ -33,13 +34,11 @@ public interface HalAbstractController {
|
|||
*/
|
||||
void initialize() throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* @return the number of registered devices.
|
||||
*/
|
||||
int size();
|
||||
|
||||
|
||||
/**
|
||||
* Close any resources associated with this controller.
|
||||
* This method could be called multiple times, first time
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* Controller interface for handling event based devices.
|
||||
*/
|
||||
public interface HalEventController extends HalAbstractController {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* Controller interface for handling Sensor devices.
|
||||
*/
|
||||
public interface HalSensorController extends HalAbstractController {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -116,7 +116,6 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
tmpl.set("availableEvents", ControllerManager.getInstance().getAvailableEvents());
|
||||
|
||||
return tmpl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package se.hal.struct;
|
|||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalAbstractController;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -50,7 +51,9 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
protected transient List<HalDeviceReportListener<T>> listeners = new LinkedList<>();
|
||||
|
||||
|
||||
/**************** DEVICE CONFIG ******************/
|
||||
// ----------------------------------------------------
|
||||
// Device config methods
|
||||
// ----------------------------------------------------
|
||||
|
||||
public Configurator<C> getDeviceConfigurator() {
|
||||
C obj = getDeviceConfig();
|
||||
|
|
@ -123,9 +126,11 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
}
|
||||
}
|
||||
|
||||
public abstract Class<?> getController();
|
||||
public abstract Class<? extends HalAbstractController> getController();
|
||||
|
||||
/**************** DEVICE DATA ******************/
|
||||
// ----------------------------------------------------
|
||||
// Device data methods
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @return the latest known data from the device
|
||||
|
|
@ -143,7 +148,9 @@ public abstract class AbstractDevice<T extends AbstractDevice, C,D extends HalDe
|
|||
*/
|
||||
protected abstract D getLatestDeviceData(DBConnection db);
|
||||
|
||||
/**************** OTHER ******************/
|
||||
// ----------------------------------------------------
|
||||
// Other methods
|
||||
// ----------------------------------------------------
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class EventControllerManagerTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TestController implements HalEventController{
|
||||
public static class TestController implements HalEventController {
|
||||
int size;
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ hal.http_port=8080
|
|||
|
||||
## Zigbee plugin
|
||||
#zigbee.com_port=COM4
|
||||
#zigbee.dongle=CC2531|CONBEE|XBEE
|
||||
|
||||
## ZWave plugin
|
||||
#zwave.com_port=COM4
|
||||
|
|
|
|||
|
|
@ -1,15 +1,30 @@
|
|||
# logging.properties
|
||||
# LogUtil.readConfiguration("logging.properties");
|
||||
|
||||
# -------------------------------------
|
||||
# HAL
|
||||
# -------------------------------------
|
||||
|
||||
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
||||
java.util.logging.ConsoleHandler.level = ALL
|
||||
java.util.logging.ConsoleHandler.formatter = zutil.log.CompactLogFormatter
|
||||
java.util.logging.FileHandler.level = ALL
|
||||
java.util.logging.FileHandler.formatter = zutil.log.CompactLogFormatter
|
||||
|
||||
|
||||
se.hal.level = ALL
|
||||
# Libs
|
||||
|
||||
zutil.level = ALL
|
||||
zutil.db.bean.level = INFO
|
||||
zutil.net.http.page.HttpFilePage.level = INFO
|
||||
zutil.net.http.page.HttpFilePage.level = INFO
|
||||
|
||||
# Hal Core
|
||||
|
||||
se.hal.level = ALL
|
||||
|
||||
# -------------------------------------
|
||||
# Plugins
|
||||
# -------------------------------------
|
||||
|
||||
#com.zsmartsystems.zigbee.level = FINE
|
||||
com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util.ByteUtils.level = INFO
|
||||
com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream.level = INFO
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue