Added Tellstic sensor test
This commit is contained in:
parent
b405c12293
commit
253e359483
9 changed files with 119 additions and 21 deletions
4
run.sh
4
run.sh
|
|
@ -1,8 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#screen -S hal -L -d -m \
|
|
||||||
# java -cp sqlite-jdbc-3.7.2.jar:jSerialComm-1.3.4.jar:hal.jar:. se.hal.plugin.tellstick.TelstickSerialCommTest
|
|
||||||
|
|
||||||
#ant clean
|
ant clean
|
||||||
ant release
|
ant release
|
||||||
screen -S hal -L -d -m ant run
|
screen -S hal -L -d -m ant run
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportReceived(HalSensorConfig sensorConfig, HalDeviceData sensorData) {
|
public void reportReceived(HalSensorConfig sensorConfig, HalSensorData sensorData) {
|
||||||
try{
|
try{
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
Sensor sensor = findSensor(sensorConfig, registeredSensors);
|
Sensor sensor = findSensor(sensorConfig, registeredSensors);
|
||||||
|
|
@ -124,8 +124,9 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
sensor = new Sensor();
|
sensor = new Sensor();
|
||||||
detectedSensors.add(sensor);
|
detectedSensors.add(sensor);
|
||||||
}
|
}
|
||||||
|
sensor.setDeviceConfig(sensorConfig);
|
||||||
}
|
}
|
||||||
sensor.setDeviceConfig(sensorConfig); // Set the latest data
|
sensor.setDeviceData(sensorData);
|
||||||
|
|
||||||
}catch (SQLException e){
|
}catch (SQLException e){
|
||||||
logger.log(Level.WARNING, "Unable to store sensor report", e);
|
logger.log(Level.WARNING, "Unable to store sensor report", e);
|
||||||
|
|
@ -191,7 +192,7 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportReceived(HalEventConfig eventConfig, HalDeviceData eventData) {
|
public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) {
|
||||||
try {
|
try {
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
Event event = findEvent(eventConfig, registeredEvents);
|
Event event = findEvent(eventConfig, registeredEvents);
|
||||||
|
|
@ -213,8 +214,9 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
event = new Event();
|
event = new Event();
|
||||||
detectedEvents.add(event);
|
detectedEvents.add(event);
|
||||||
}
|
}
|
||||||
|
event.setDeviceConfig(eventConfig);
|
||||||
}
|
}
|
||||||
event.setDeviceConfig(eventConfig); // Set the latest data
|
event.setDeviceData(eventData);
|
||||||
|
|
||||||
}catch (SQLException e){
|
}catch (SQLException e){
|
||||||
logger.log(Level.WARNING, "Unable to store event report", e);
|
logger.log(Level.WARNING, "Unable to store event report", e);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@ package se.hal.intf;
|
||||||
|
|
||||||
public interface HalEventReportListener {
|
public interface HalEventReportListener {
|
||||||
|
|
||||||
void reportReceived(HalEventConfig e, HalDeviceData d);
|
void reportReceived(HalEventConfig e, HalEventData d);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,6 @@ package se.hal.intf;
|
||||||
|
|
||||||
public interface HalSensorReportListener {
|
public interface HalSensorReportListener {
|
||||||
|
|
||||||
void reportReceived(HalSensorConfig s, HalDeviceData d);
|
void reportReceived(HalSensorConfig s, HalSensorData d);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package se.hal.plugin.raspberry;
|
package se.hal.plugin.raspberry;
|
||||||
|
|
||||||
import se.hal.intf.HalDeviceData;
|
import se.hal.intf.*;
|
||||||
import se.hal.intf.HalSensorController;
|
|
||||||
import se.hal.intf.HalSensorConfig;
|
|
||||||
import se.hal.intf.HalSensorReportListener;
|
|
||||||
import se.hal.plugin.raspberry.hardware.RPiDS18B20;
|
import se.hal.plugin.raspberry.hardware.RPiDS18B20;
|
||||||
import se.hal.plugin.raspberry.hardware.RPiInteruptPulseFlankCounter;
|
import se.hal.plugin.raspberry.hardware.RPiInteruptPulseFlankCounter;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
@ -90,7 +87,7 @@ public class RPiController implements HalSensorController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDataReport(HalSensorConfig sensorConfig, HalDeviceData sensorData){
|
public void sendDataReport(HalSensorConfig sensorConfig, HalSensorData sensorData){
|
||||||
if(sensorListener != null){
|
if(sensorListener != null){
|
||||||
sensorListener.reportReceived(sensorConfig, sensorData);
|
sensorListener.reportReceived(sensorConfig, sensorData);
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
|
|
@ -175,9 +175,9 @@ public class TellstickSerialComm implements Runnable,
|
||||||
}
|
}
|
||||||
private void reportEvent(TellstickDevice tellstickDevice, HalDeviceData deviceData){
|
private void reportEvent(TellstickDevice tellstickDevice, HalDeviceData deviceData){
|
||||||
if (sensorListener != null && tellstickDevice instanceof HalSensorConfig)
|
if (sensorListener != null && tellstickDevice instanceof HalSensorConfig)
|
||||||
sensorListener.reportReceived((HalSensorConfig) tellstickDevice, deviceData);
|
sensorListener.reportReceived((HalSensorConfig) tellstickDevice, (HalSensorData) deviceData);
|
||||||
else if (eventListener != null && tellstickDevice instanceof HalEventConfig)
|
else if (eventListener != null && tellstickDevice instanceof HalEventConfig)
|
||||||
eventListener.reportReceived((HalEventConfig) tellstickDevice, deviceData);
|
eventListener.reportReceived((HalEventConfig) tellstickDevice, (HalEventData) deviceData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
||||||
|
|
||||||
applyConfig();
|
applyConfig();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, "Unable instantiate DeviceData: "+type, e);
|
logger.log(Level.SEVERE, "Unable instantiate DeviceConfig: "+type, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceConfig;
|
return deviceConfig;
|
||||||
|
|
@ -74,7 +74,6 @@ public abstract class AbstractDevice<T,D> extends DBBean {
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
deviceConfig = data;
|
deviceConfig = data;
|
||||||
type = data.getClass().getName();
|
type = data.getClass().getName();
|
||||||
applyConfig(); // TODO: this is a bit clunky, should probably be solved in another way
|
|
||||||
} else {
|
} else {
|
||||||
deviceConfig = null;
|
deviceConfig = null;
|
||||||
type = null;
|
type = null;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-11-19.
|
* Created by Ziver on 2015-11-19.
|
||||||
*/
|
*/
|
||||||
public class TelstickSerialCommTest {
|
public class TelstickSerialCommEventTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init(){
|
public void init(){
|
||||||
|
|
@ -47,7 +47,7 @@ public class TelstickSerialCommTest {
|
||||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||||
tellstick.setListener(new HalEventReportListener() {
|
tellstick.setListener(new HalEventReportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void reportReceived(HalEventConfig e, HalDeviceData d) {
|
public void reportReceived(HalEventConfig e, HalEventData d) {
|
||||||
list.add(e);
|
list.add(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -65,7 +65,7 @@ public class TelstickSerialCommTest {
|
||||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||||
tellstick.setListener(new HalEventReportListener() {
|
tellstick.setListener(new HalEventReportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void reportReceived(HalEventConfig e, HalDeviceData d) {
|
public void reportReceived(HalEventConfig e, HalEventData d) {
|
||||||
list.add(e);
|
list.add(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
102
test/se/hal/plugin/tellstick/TelstickSerialCommSensorTest.java
Executable file
102
test/se/hal/plugin/tellstick/TelstickSerialCommSensorTest.java
Executable file
|
|
@ -0,0 +1,102 @@
|
||||||
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import se.hal.intf.HalSensorConfig;
|
||||||
|
import se.hal.intf.HalSensorController;
|
||||||
|
import se.hal.intf.HalSensorData;
|
||||||
|
import se.hal.intf.HalSensorReportListener;
|
||||||
|
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||||
|
import zutil.converter.Converter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2015-11-19.
|
||||||
|
*/
|
||||||
|
public class TelstickSerialCommSensorTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init(){
|
||||||
|
TellstickParser.registerProtocol(TestSensor.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//############ Normal TCs
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void receiveUnregisteredSensor(){
|
||||||
|
// Setup
|
||||||
|
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||||
|
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||||
|
tellstick.setListener(new HalSensorReportListener() {
|
||||||
|
@Override
|
||||||
|
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||||
|
list.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Execution
|
||||||
|
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||||
|
assertEquals("Sensors first transmission", 0, list.size());
|
||||||
|
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||||
|
assertEquals("Sensors Second transmission", 1, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void receiveSensor(){
|
||||||
|
// Setup
|
||||||
|
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||||
|
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||||
|
tellstick.setListener(new HalSensorReportListener() {
|
||||||
|
@Override
|
||||||
|
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||||
|
list.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Execution
|
||||||
|
TestSensor sensor = new TestSensor();
|
||||||
|
sensor.testData = 0xAAAA;
|
||||||
|
tellstick.register(sensor);
|
||||||
|
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
|
||||||
|
// Verification
|
||||||
|
assertEquals("Nr of received sensors", 1, list.size());
|
||||||
|
assertEquals("Data", sensor.testData, ((TestSensor)list.get(0)).testData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static class TestSensor extends TellstickProtocol implements HalSensorConfig,TellstickDevice {
|
||||||
|
public int testData;
|
||||||
|
|
||||||
|
public TestSensor(){
|
||||||
|
super("test-prot", "test-model");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||||
|
testData = Converter.toInt(data);
|
||||||
|
|
||||||
|
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||||
|
list.add(new TellstickDecodedEntry(
|
||||||
|
this, new TemperatureSensorData(testData)
|
||||||
|
));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {return testData == ((TestSensor)obj).testData;}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDataInterval() { return 0; }
|
||||||
|
@Override
|
||||||
|
public AggregationMethod getAggregationMethod() { return null; }
|
||||||
|
@Override
|
||||||
|
public Class<? extends HalSensorController> getSensorController() { return null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue