Bug fixes
Former-commit-id: e2dd5aecc8d9fd521d97bff04a9336f6c5008aad
This commit is contained in:
parent
060f784611
commit
e08f1b4477
7 changed files with 65 additions and 24 deletions
4
Hal.iml
4
Hal.iml
|
|
@ -30,7 +30,9 @@
|
||||||
<NATIVE>
|
<NATIVE>
|
||||||
<root url="file://$MODULE_DIR$/lib" />
|
<root url="file://$MODULE_DIR$/lib" />
|
||||||
</NATIVE>
|
</NATIVE>
|
||||||
<SOURCES />
|
<SOURCES>
|
||||||
|
<root url="jar://$USER_HOME$/.ideaLibSources/jSerialComm-1.3.10-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
<jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
|
<jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
|
|
|
||||||
3
hal.conf.example
Executable file
3
hal.conf.example
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
http_port=8080
|
||||||
|
sync_port=6666
|
||||||
|
tellstick.com_port=COM5
|
||||||
|
|
@ -50,6 +50,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
/////////////////////////////// SENSORS ///////////////////////////////////
|
/////////////////////////////// SENSORS ///////////////////////////////////
|
||||||
|
|
||||||
public void register(Sensor sensor) throws IllegalAccessException, InstantiationException {
|
public void register(Sensor sensor) throws IllegalAccessException, InstantiationException {
|
||||||
|
logger.info("Registering new sensor(id: "+ sensor.getId() +"): "+ sensor.getSensorData().getClass());
|
||||||
Class<? extends HalSensorController> c = sensor.getController();
|
Class<? extends HalSensorController> c = sensor.getController();
|
||||||
HalSensorController controller = getControllerInstance(c);
|
HalSensorController controller = getControllerInstance(c);
|
||||||
|
|
||||||
|
|
@ -59,6 +60,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deregister(Sensor sensor){
|
public void deregister(Sensor sensor){
|
||||||
|
logger.info("Deregistering sensor(id: "+ sensor.getId() +"): "+ sensor.getSensorData().getClass());
|
||||||
Class<? extends HalSensorController> c = sensor.getController();
|
Class<? extends HalSensorController> c = sensor.getController();
|
||||||
HalSensorController controller = (HalSensorController) controllerMap.get(c);;
|
HalSensorController controller = (HalSensorController) controllerMap.get(c);;
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
|
@ -91,7 +93,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
|
|
||||||
if (sensor != null) {
|
if (sensor != null) {
|
||||||
PreparedStatement stmt =
|
PreparedStatement stmt =
|
||||||
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, event_id, data) VALUES(?, ?, ?)");
|
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
|
||||||
stmt.setLong(1, sensorData.getTimestamp());
|
stmt.setLong(1, sensorData.getTimestamp());
|
||||||
stmt.setLong(2, sensor.getId());
|
stmt.setLong(2, sensor.getId());
|
||||||
stmt.setDouble(3, sensorData.getData());
|
stmt.setDouble(3, sensorData.getData());
|
||||||
|
|
@ -112,6 +114,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
//////////////////////////////// EVENTS ///////////////////////////////////
|
//////////////////////////////// EVENTS ///////////////////////////////////
|
||||||
|
|
||||||
public void register(Event event) throws IllegalAccessException, InstantiationException {
|
public void register(Event event) throws IllegalAccessException, InstantiationException {
|
||||||
|
logger.info("Registering new event(id: "+ event.getId() +"): "+ event.getEventData().getClass());
|
||||||
Class<? extends HalEventController> c = event.getController();
|
Class<? extends HalEventController> c = event.getController();
|
||||||
HalEventController controller = getControllerInstance(c);
|
HalEventController controller = getControllerInstance(c);
|
||||||
|
|
||||||
|
|
@ -121,6 +124,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deregister(Event event){
|
public void deregister(Event event){
|
||||||
|
logger.info("Deregistering event(id: "+ event.getId() +"): "+ event.getEventData().getClass());
|
||||||
Class<? extends HalEventController> c = event.getController();
|
Class<? extends HalEventController> c = event.getController();
|
||||||
HalEventController controller = (HalEventController) controllerMap.get(c);
|
HalEventController controller = (HalEventController) controllerMap.get(c);
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
|
@ -179,7 +183,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
controller = controllerMap.get(c);
|
controller = controllerMap.get(c);
|
||||||
else {
|
else {
|
||||||
// Instantiate controller
|
// Instantiate controller
|
||||||
logger.fine("Instantiating new controller: " + c.getName());
|
logger.info("Instantiating new controller: " + c.getName());
|
||||||
try {
|
try {
|
||||||
controller = c.newInstance();
|
controller = c.newInstance();
|
||||||
if(controller instanceof HalSensorController) {
|
if(controller instanceof HalSensorController) {
|
||||||
|
|
@ -209,7 +213,7 @@ public class ControllerManager implements HalSensorReportListener, HalEventRepor
|
||||||
|
|
||||||
if(size < 0){
|
if(size < 0){
|
||||||
// Remove controller as it has no more registered sensors
|
// Remove controller as it has no more registered sensors
|
||||||
logger.fine("Closing controller as it has no more registered sensors: "+controller.getClass().getName());
|
logger.info("Closing controller as it has no more registered objects: "+controller.getClass().getName());
|
||||||
controllerMap.remove(controller.getClass());
|
controllerMap.remove(controller.getClass());
|
||||||
|
|
||||||
if(controller instanceof HalSensorController)
|
if(controller instanceof HalSensorController)
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,6 @@ public class TellstickParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private TellstickProtocol previus;
|
|
||||||
|
|
||||||
public TellstickProtocol decode(String data) {
|
public TellstickProtocol decode(String data) {
|
||||||
if (data.startsWith("+W")) {
|
if (data.startsWith("+W")) {
|
||||||
data = data.substring(2);
|
data = data.substring(2);
|
||||||
|
|
@ -62,12 +60,10 @@ public class TellstickParser {
|
||||||
try {
|
try {
|
||||||
TellstickProtocol protocol = protClass.newInstance();
|
TellstickProtocol protocol = protClass.newInstance();
|
||||||
String binData = map.get("data");
|
String binData = map.get("data");
|
||||||
|
|
||||||
protocol.decode(Converter.hexToByte(binData));
|
protocol.decode(Converter.hexToByte(binData));
|
||||||
if(!protocol.equals(previus)) {
|
|
||||||
previus = protocol;
|
|
||||||
logger.finest("Decoded: " + protocol);
|
logger.finest("Decoded: " + protocol);
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.WARNING, null, e);
|
logger.log(Level.WARNING, null, e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private SerialPort serial;
|
private SerialPort serial;
|
||||||
private BufferedReader in;
|
private InputStream in;
|
||||||
private BufferedWriter out;
|
private OutputStream out;
|
||||||
private TimedHashSet set; // To check for retransmissions
|
private TimedHashSet set; // To check for retransmissions
|
||||||
|
|
||||||
private TellstickParser parser;
|
private TellstickParser parser;
|
||||||
|
|
@ -84,8 +84,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
serial.setComPortTimeouts(
|
serial.setComPortTimeouts(
|
||||||
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
|
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
|
||||||
|
|
||||||
in = new BufferedReader(new InputStreamReader(new InputStreamLogger(serial.getInputStream()), "UTF-8"));
|
in = new InputStreamLogger(serial.getInputStream());
|
||||||
out = new BufferedWriter(new OutputStreamWriter(new OutputStreamLogger(serial.getOutputStream()), "UTF-8"));
|
out = new OutputStreamLogger(serial.getOutputStream());
|
||||||
|
|
||||||
Executors.newSingleThreadExecutor().execute(this);
|
Executors.newSingleThreadExecutor().execute(this);
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,8 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String data;
|
String data;
|
||||||
while (in != null && (data = in.readLine()) != null) {
|
|
||||||
|
while (in != null && (data = readLine()) != null) {
|
||||||
if ((data.startsWith("+S") || data.startsWith("+T"))) {
|
if ((data.startsWith("+S") || data.startsWith("+T"))) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.notifyAll();
|
this.notifyAll();
|
||||||
|
|
@ -118,14 +119,16 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
else {
|
else {
|
||||||
if(!set.contains(data)) {
|
if(!set.contains(data)) {
|
||||||
TellstickProtocol protocol = parser.decode(data);
|
TellstickProtocol protocol = parser.decode(data);
|
||||||
if(protocol.getTimestamp() < 0)
|
if(protocol != null) {
|
||||||
|
if (protocol.getTimestamp() < 0)
|
||||||
protocol.setTimestamp(System.currentTimeMillis());
|
protocol.setTimestamp(System.currentTimeMillis());
|
||||||
set.add(data);
|
set.add(data);
|
||||||
|
|
||||||
if (sensorListener != null && protocol instanceof HalSensor)
|
if (sensorListener != null && protocol instanceof HalSensor)
|
||||||
sensorListener.reportReceived((HalSensor)protocol);
|
sensorListener.reportReceived((HalSensor) protocol);
|
||||||
else if (eventListener != null && protocol instanceof HalEvent)
|
else if (eventListener != null && protocol instanceof HalEvent)
|
||||||
eventListener.reportReceived((HalEvent)protocol);
|
eventListener.reportReceived((HalEvent) protocol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,6 +137,26 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There seems to be an issue with read(...) methods only read() is working
|
||||||
|
*/
|
||||||
|
private String readLine() throws IOException {
|
||||||
|
StringBuilder str = new StringBuilder(50);
|
||||||
|
char c = 0;
|
||||||
|
while((c = (char)in.read()) >= 0){
|
||||||
|
switch(c) {
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
if(str.length() > 0)
|
||||||
|
return str.toString();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
str.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(HalEvent event) {
|
public void send(HalEvent event) {
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
|
||||||
|
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "class:command;protocol:arctech;model:selflearning;" +
|
return "protocol:arctech;model:selflearning;" +
|
||||||
"house:"+house+
|
"house:"+house+
|
||||||
";group:"+group+
|
";group:"+group+
|
||||||
";unit:"+unit+
|
";unit:"+unit+
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,19 @@ public class Oregon0x1A2D extends TellstickProtocol implements PowerConsumptionS
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj){
|
||||||
|
if(! (obj instanceof Oregon0x1A2D))
|
||||||
|
return false;
|
||||||
|
return ((Oregon0x1A2D)obj).address == this.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "protocol:oregon;model:0x1A2D;" +
|
||||||
|
"address:"+address+
|
||||||
|
";temperature:"+temperature+
|
||||||
|
";humidity:"+humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public double getTemperature(){
|
public double getTemperature(){
|
||||||
return temperature;
|
return temperature;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue