Formatting cleanup
This commit is contained in:
parent
c7e286f51e
commit
5a1be3c2e4
50 changed files with 283 additions and 282 deletions
|
|
@ -117,7 +117,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
if (deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.put(mqttEvent.getTopic(), mqttEvent);
|
||||
} else throw new IllegalArgumentException(
|
||||
|
|
@ -126,7 +126,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
if (deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.remove(mqttEvent.getTopic());
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void send(HalEventConfig eventConfig, HalEventData eventData) {
|
||||
if(eventConfig instanceof HalMqttDeviceConfig) {
|
||||
if (eventConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) eventConfig;
|
||||
mqttBroker.publish(mqttEvent.getTopic(), Double.toString(eventData.getData()).getBytes());
|
||||
} else throw new IllegalArgumentException(
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class CameraConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Camera Settings").setWeight(200);
|
||||
|
||||
cameraConfigurations = new ArrayList<>();
|
||||
for(Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
for (Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
cameraConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ public class CameraConfigWebPage extends HalWebPage {
|
|||
User localUser = User.getLocalUser(db);
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
if (request.containsKey("action")){
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
Camera camera;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
List<User> users = User.getExternalUsers(db);
|
||||
for(User user : users){
|
||||
if(user.getHostname() == null){
|
||||
for (User user : users){
|
||||
if (user.getHostname() == null){
|
||||
logger.fine("Hostname not defined for user: "+ user.getUsername());
|
||||
continue;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
|
||||
// Check server protocol version
|
||||
int version = in.readInt();
|
||||
if(version != PCDataSynchronizationDaemon.PROTOCOL_VERSION){
|
||||
if (version != PCDataSynchronizationDaemon.PROTOCOL_VERSION){
|
||||
logger.warning("Protocol version do not match, skipping user. " +
|
||||
"(local v"+PCDataSynchronizationDaemon.PROTOCOL_VERSION+" != remote v"+version+")");
|
||||
out.writeObject(null); // Tell server we are disconnecting
|
||||
|
|
@ -96,10 +96,10 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
user.setAddress(peerData.address);
|
||||
user.save(db);
|
||||
|
||||
for(SensorDTO sensorDTO : peerData.sensors){
|
||||
for (SensorDTO sensorDTO : peerData.sensors){
|
||||
try { // We might not have the sensor plugin installed
|
||||
Sensor sensor = Sensor.getExternalSensor(db, user, sensorDTO.sensorId);
|
||||
if(sensor == null) { // new sensor
|
||||
if (sensor == null) { // new sensor
|
||||
sensor = new Sensor();
|
||||
logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
|
||||
}
|
||||
|
|
@ -120,8 +120,8 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
|
||||
// Request sensor data
|
||||
List<Sensor> sensors = Sensor.getSensors(db, user);
|
||||
for(Sensor sensor : sensors){
|
||||
if(sensor.isSynced()) {
|
||||
for (Sensor sensor : sensors){
|
||||
if (sensor.isSynced()) {
|
||||
SensorDataReqDTO req = new SensorDataReqDTO();
|
||||
req.sensorId = sensor.getExternalId();
|
||||
req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
|
||||
|
|
@ -129,7 +129,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
out.writeObject(req);
|
||||
|
||||
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
||||
if(dataList.aggregationVersion != sensor.getAggregationVersion()){
|
||||
if (dataList.aggregationVersion != sensor.getAggregationVersion()){
|
||||
logger.fine("The peer has modified its aggregated data, clearing aggregate data. oldAggregationVersion:"+sensor.getAggregationVersion()+" , newAggregationVersion:"+dataList.aggregationVersion);
|
||||
|
||||
//clear old aggregated data for sensor
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
Object obj = null;
|
||||
out.writeInt(PROTOCOL_VERSION); // send our protocol version to client
|
||||
out.flush();
|
||||
while((obj = in.readObject()) != null){
|
||||
if(obj instanceof PeerDataReqDTO){
|
||||
while ((obj = in.readObject()) != null){
|
||||
if (obj instanceof PeerDataReqDTO){
|
||||
logger.fine("Client requesting peer data");
|
||||
PeerDataRspDTO rsp = new PeerDataRspDTO();
|
||||
User localUser = User.getLocalUser(db);
|
||||
|
|
@ -111,8 +111,8 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
rsp.address = localUser.getAddress();
|
||||
|
||||
rsp.sensors = new ArrayList<>();
|
||||
for(Sensor sensor : Sensor.getLocalSensors(db)){
|
||||
if(sensor.isSynced()) {
|
||||
for (Sensor sensor : Sensor.getLocalSensors(db)){
|
||||
if (sensor.isSynced()) {
|
||||
SensorDTO dto = new SensorDTO();
|
||||
dto.sensorId = sensor.getId();
|
||||
dto.name = sensor.getName();
|
||||
|
|
@ -123,17 +123,17 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
}
|
||||
out.writeObject(rsp);
|
||||
}
|
||||
if(obj instanceof SensorDataReqDTO){
|
||||
if (obj instanceof SensorDataReqDTO){
|
||||
SensorDataReqDTO req = (SensorDataReqDTO) obj;
|
||||
Sensor sensor = Sensor.getSensor(db, req.sensorId);
|
||||
if(sensor.isSynced()) {
|
||||
if (sensor.isSynced()) {
|
||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
|
||||
stmt.setLong(1, sensor.getId());
|
||||
logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId + ", " + req.aggregationVersion);
|
||||
if(req.aggregationVersion != sensor.getAggregationVersion()){
|
||||
if (req.aggregationVersion != sensor.getAggregationVersion()){
|
||||
logger.fine("The requested aggregation version does not match the local version: " + sensor.getAggregationVersion() + ". Will re-send all aggregated data.");
|
||||
stmt.setLong(2, 0); //0 since we want to re-send all data to the peer
|
||||
}else{
|
||||
} else {
|
||||
stmt.setLong(2, req.offsetSequenceId);
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
logger.fine("Sending " + rsp.size() + " sensor data items to client");
|
||||
out.writeObject(rsp);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
||||
SensorDataListDTO rsp = new SensorDataListDTO();
|
||||
out.writeObject(rsp);
|
||||
|
|
|
|||
|
|
@ -26,44 +26,44 @@ public class RPiController implements HalSensorController {
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
if (deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
int gpioPin = powerConsumptionSensor.getGpioPin();
|
||||
if(!pinToSensorMap.containsKey("GPIO_"+gpioPin)){
|
||||
if (!pinToSensorMap.containsKey("GPIO_"+gpioPin)){
|
||||
RPiInteruptPulseFlankCounter impulseCounter = new RPiInteruptPulseFlankCounter(gpioPin, this);
|
||||
pinToSensorMap.put("GPIO_"+gpioPin, impulseCounter);
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot create a RPiPowerConsumptionSensor on GPIO pin " + gpioPin + " since is already is in use by another sensor.");
|
||||
}
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
} else if (deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
String w1Address = temperatureSensor.get1WAddress();
|
||||
if(!pinToSensorMap.containsKey("W1_"+w1Address)){
|
||||
if (!pinToSensorMap.containsKey("W1_"+w1Address)){
|
||||
RPiDS18B20 ds12b20 = new RPiDS18B20(w1Address, this);
|
||||
pinToSensorMap.put("W1_"+w1Address, ds12b20);
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot create a RPi1WireTemperatureSensor on 1-Wire address " + w1Address + " since is already is in use by another sensor.");
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot register a non-supported sensor");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
if (deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("GPIO_"+powerConsumptionSensor.getGpioPin());
|
||||
if(sensorToDeregister != null){
|
||||
if (sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
}
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
} else if (deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("W1_"+temperatureSensor.get1WAddress());
|
||||
if(sensorToDeregister != null){
|
||||
if (sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot deregister a non-supported sensor");
|
||||
return;
|
||||
}
|
||||
|
|
@ -81,16 +81,16 @@ public class RPiController implements HalSensorController {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
for(String key : this.pinToSensorMap.keySet()){
|
||||
for (String key : this.pinToSensorMap.keySet()){
|
||||
pinToSensorMap.get(key).close();
|
||||
pinToSensorMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendDataReport(HalSensorConfig sensorConfig, HalSensorData sensorData){
|
||||
if(sensorListener != null){
|
||||
if (sensorListener != null){
|
||||
sensorListener.reportReceived(sensorConfig, sensorData);
|
||||
}else{
|
||||
} else {
|
||||
logger.log(Level.WARNING, "Could not report data. No registered listener");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
private int gpioPin = -1;
|
||||
|
||||
|
||||
public RPiPowerConsumptionSensor(){ } //need to be empty for the framework to create an instance
|
||||
public RPiPowerConsumptionSensor() { } //need to be empty for the framework to create an instance
|
||||
public RPiPowerConsumptionSensor(int gpioPin) {
|
||||
this.gpioPin = gpioPin;
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
|
||||
|
||||
@Override
|
||||
public long getDataInterval(){
|
||||
public long getDataInterval() {
|
||||
return 60*1000; // 1 min
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,8 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof RPiPowerConsumptionSensor)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof RPiPowerConsumptionSensor)
|
||||
return ((RPiPowerConsumptionSensor)obj).gpioPin == gpioPin;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
return gpioPin;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "gpioPin:" + gpioPin;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class RPiTemperatureSensor implements HalSensorConfig {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof RPiTemperatureSensor && w1Address != null)
|
||||
if (obj instanceof RPiTemperatureSensor && w1Address != null)
|
||||
return this.get1WAddress().equals(((RPiTemperatureSensor) obj).w1Address);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import com.pi4j.io.gpio.RaspiPin;
|
|||
|
||||
public class RPiUtility {
|
||||
|
||||
public static Pin getPin(int gpioPin){
|
||||
switch(gpioPin){
|
||||
public static Pin getPin(int gpioPin) {
|
||||
switch(gpioPin) {
|
||||
case 0:
|
||||
return RaspiPin.GPIO_00;
|
||||
case 1:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RPiDS18B20 implements RPiSensor, Runnable {
|
||||
public class RPiDS18B20 implements RPiSensor, Runnable {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private final String DEGREE_SIGN = "\u00b0";
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
private ScheduledExecutorService scheduler;
|
||||
private W1Master w1Mater;
|
||||
|
||||
public RPiDS18B20(String w1Address, RPiController controller){
|
||||
public RPiDS18B20(String w1Address, RPiController controller) {
|
||||
this.controller = controller;
|
||||
this.w1Address = w1Address;
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
w1Mater = new W1Master();
|
||||
|
||||
//print out all sensors found
|
||||
for(TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)){
|
||||
for (TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)) {
|
||||
logger.info(String.format("1-Wire temperature sensor divice found: %-20s: %3.1f"+DEGREE_SIGN+"C\n", device.getName(), device.getTemperature(TemperatureScale.CELSIUS)));
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
scheduler.scheduleAtFixedRate(this, 10, 60, TimeUnit.SECONDS); //wait 10s and run every 60s
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
scheduler.shutdown();
|
||||
try {
|
||||
|
|
@ -52,8 +52,8 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
for(TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)){
|
||||
if(device.getName().equals(w1Address)){
|
||||
for (TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)) {
|
||||
if (device.getName().equals(w1Address)) {
|
||||
controller.sendDataReport(
|
||||
new RPiTemperatureSensor(w1Address),
|
||||
new TemperatureSensorData(
|
||||
|
|
@ -64,5 +64,5 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
private GpioPinDigitalInput irLightSensor;
|
||||
private final int gpioPin;
|
||||
|
||||
public RPiInteruptPulseFlankCounter(int gpioPin, RPiController controller){
|
||||
public RPiInteruptPulseFlankCounter(int gpioPin, RPiController controller) {
|
||||
this.controller = controller;
|
||||
this.gpioPin = gpioPin;
|
||||
|
||||
|
|
@ -42,10 +42,10 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
GpioController gpio = null;
|
||||
try{
|
||||
gpio = GpioFactory.getInstance();
|
||||
}catch(IllegalArgumentException e){
|
||||
}catch(IllegalArgumentException e) {
|
||||
logger.log(Level.SEVERE, "", e);
|
||||
throw e;
|
||||
}catch(UnsatisfiedLinkError e){
|
||||
}catch(UnsatisfiedLinkError e) {
|
||||
logger.log(Level.SEVERE, "", e);
|
||||
throw e;
|
||||
}
|
||||
|
|
@ -55,49 +55,49 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
|
||||
// create and register gpio pin listener. May require the program to be run as sudo if the GPIO pin has not been exported
|
||||
irLightSensor.addListener(this);
|
||||
|
||||
|
||||
//start a daemon thread to save the impulse count every minute
|
||||
Thread thread = new Thread(this);
|
||||
thread.setDaemon(false);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
irLightSensor.removeListener(this);
|
||||
executorPool.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GpioPinListenerDigital interface
|
||||
*/
|
||||
@Override
|
||||
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
|
||||
if(event.getState() == PinState.LOW){ //low = light went on
|
||||
if (event.getState() == PinState.LOW) { //low = light went on
|
||||
//System.out.println("IR LED turned ON");
|
||||
//logger.log(Level.INFO, "IR LED turned on");
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
impulseCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.nanoTime();
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
impulseCount = 0; //reset the impulse count
|
||||
}
|
||||
while(!executorPool.isShutdown()) {
|
||||
while (!executorPool.isShutdown()) {
|
||||
sleepNano(nanoSecondsSleep); //sleep for some time. This variable will be modified every loop to compensate for the loop time spent.
|
||||
int count = -1;
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
count = impulseCount;
|
||||
impulseCount = 0;
|
||||
}
|
||||
save(System.currentTimeMillis(), count); //save the impulse count
|
||||
long estimatedNanoTimeSpent = System.nanoTime() - startTime; //this is where the loop ends
|
||||
startTime = System.nanoTime(); //this is where the loop starts from now on
|
||||
if(estimatedNanoTimeSpent > 0){ //if no overflow
|
||||
if (estimatedNanoTimeSpent > 0) { //if no overflow
|
||||
long nanoSecondsTooMany = estimatedNanoTimeSpent - (REPORT_TIMEOUT*1000000L);
|
||||
//System.out.println("the look took ~" + estimatedNanoTimeSpent + "ns. That is " + nanoSecondsTooMany/1000000L + "ms off");
|
||||
nanoSecondsSleep -= nanoSecondsTooMany / 3; //divide by constant to take into account varaiations im loop time
|
||||
|
|
@ -109,27 +109,27 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
* Sleep for [ns] nanoseconds
|
||||
* @param ns
|
||||
*/
|
||||
private void sleepNano(long ns){
|
||||
private void sleepNano(long ns) {
|
||||
//System.out.println("will go to sleep for " + ns + "ns");
|
||||
try{
|
||||
Thread.sleep(ns/1000000L, (int)(ns%1000000L));
|
||||
}catch(InterruptedException e){
|
||||
}catch(InterruptedException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the data to the database.
|
||||
* This method should block the caller as short time as possible.
|
||||
* This method should try block the same amount of time every time it is called.
|
||||
* Try to make the time spent in the method the same for every call (low variation).
|
||||
*
|
||||
* Try to make the time spent in the method the same for every call (low variation).
|
||||
*
|
||||
* @param timestamp_end
|
||||
* @param data
|
||||
*/
|
||||
private void save(final long timestamp_end, final int data){
|
||||
private void save(final long timestamp_end, final int data) {
|
||||
//offload the timed loop by not doing the db interaction in this thread.
|
||||
executorPool.execute(new Runnable(){
|
||||
executorPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.log(Level.INFO, "Reporting data. timestamp_end="+timestamp_end+", data="+data);
|
||||
|
|
@ -141,5 +141,5 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class TellstickParser {
|
|||
} else if (data.startsWith("+V")) {
|
||||
if (data.length() > 2)
|
||||
firmwareVersion = Integer.parseInt(data.substring(2));
|
||||
}else {
|
||||
} else {
|
||||
logger.severe("Unknown prefix: " + data);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ public class TellstickParser {
|
|||
/**
|
||||
* This method blocks until a send command confirmation is received.
|
||||
*/
|
||||
public synchronized void waitSendConformation(){
|
||||
public synchronized void waitSendConformation() {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -138,13 +138,13 @@ public class TellstickSerialComm implements Runnable,
|
|||
private String readLine() throws IOException {
|
||||
StringBuilder str = new StringBuilder(50);
|
||||
int c;
|
||||
while((c = in.read()) >= 0){
|
||||
while ((c = in.read()) >= 0) {
|
||||
switch(c) {
|
||||
case -1:
|
||||
return null;
|
||||
case '\n':
|
||||
case '\r':
|
||||
if(str.length() > 0)
|
||||
if (str.length() > 0)
|
||||
return str.toString();
|
||||
break;
|
||||
default:
|
||||
|
|
@ -153,7 +153,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
return str.toString();
|
||||
}
|
||||
protected void handleLine(String data){
|
||||
protected void handleLine(String data) {
|
||||
List<TellstickDecodedEntry> decodeList = parser.decode(data);
|
||||
for (TellstickDecodedEntry entry : decodeList) {
|
||||
if (entry.getData().getTimestamp() < 0)
|
||||
|
|
@ -191,7 +191,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
|
||||
@Override
|
||||
public void send(HalEventConfig deviceConfig, HalEventData deviceData) {
|
||||
if(deviceConfig instanceof TellstickDevice) {
|
||||
if (deviceConfig instanceof TellstickDevice) {
|
||||
TellstickDevice tellstickDevice = (TellstickDevice) deviceConfig;
|
||||
TellstickProtocol prot = TellstickParser.getProtocolInstance(
|
||||
tellstickDevice.getProtocolName(),
|
||||
|
|
@ -208,7 +208,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
if (data == null)
|
||||
return;
|
||||
try {
|
||||
for(int i=0; i<data.length();i++)
|
||||
for (int i=0; i<data.length();i++)
|
||||
out.write(0xFF & data.charAt(i));
|
||||
out.write('\n');
|
||||
out.flush();
|
||||
|
|
@ -223,15 +223,15 @@ public class TellstickSerialComm implements Runnable,
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof TellstickDevice)
|
||||
if (deviceConfig instanceof TellstickDevice)
|
||||
registeredDevices.add(deviceConfig);
|
||||
else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of " + TellstickDevice.class + ": " + deviceConfig.getClass());
|
||||
}
|
||||
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz){
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz) {
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (HalDeviceConfig device : registeredDevices){
|
||||
for (HalDeviceConfig device : registeredDevices) {
|
||||
if (clazz.isAssignableFrom(device.getClass()))
|
||||
list.add((T) device);
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
|
||||
|
||||
public static TellstickSerialComm getInstance(){
|
||||
public static TellstickSerialComm getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,28 +18,28 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
* @param timing set first timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls0Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls0Timing(int timing) {
|
||||
setPullsTiming(0, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set second timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls1Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls1Timing(int timing) {
|
||||
setPullsTiming(1, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set third timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls2Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls2Timing(int timing) {
|
||||
setPullsTiming(2, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set fourth timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls3Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls3Timing(int timing) {
|
||||
setPullsTiming(3, timing); return this;
|
||||
}
|
||||
/**
|
||||
|
|
@ -47,29 +47,29 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
* @param timing set first pulls length in us between 0-2550
|
||||
* @return an instance of itself
|
||||
*/
|
||||
private void setPullsTiming(int i, int timing){ // TODO: should probably have high and low timing to be called pulls
|
||||
private void setPullsTiming(int i, int timing) { // TODO: should probably have high and low timing to be called pulls
|
||||
if (0 > timing || timing > 2550)
|
||||
throw new IllegalArgumentException("Invalid pulls "+timing+" must be between 0-2550" );
|
||||
cmd[OFFSET_TIMINGS + i] = (byte)(timing/10);
|
||||
}
|
||||
|
||||
|
||||
public TellstickCmdExtendedSend addPulls0(){
|
||||
public TellstickCmdExtendedSend addPulls0() {
|
||||
addPulls(0); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls1(){
|
||||
public TellstickCmdExtendedSend addPulls1() {
|
||||
addPulls(1); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls2(){
|
||||
public TellstickCmdExtendedSend addPulls2() {
|
||||
addPulls(2); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls3(){
|
||||
public TellstickCmdExtendedSend addPulls3() {
|
||||
addPulls(3); return this;
|
||||
}
|
||||
private void addPulls(int i) {
|
||||
if (OFFSET_PULSES+(length/4) > cmd.length)
|
||||
throw new IndexOutOfBoundsException("Maximum length "+cmd.length+" reached");
|
||||
switch (length % 4){
|
||||
switch (length % 4) {
|
||||
case 0:
|
||||
cmd[OFFSET_PULSES+ length/4] |= 0b1100_0000 & (i << 6); break;
|
||||
case 1:
|
||||
|
|
@ -83,7 +83,7 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
}
|
||||
|
||||
|
||||
public String getTransmissionString(){
|
||||
public String getTransmissionString() {
|
||||
cmd[0] = 'T';
|
||||
cmd[OFFSET_PULSE_LENGTH] = (byte)length;
|
||||
cmd[OFFSET_PULSES+(int)Math.ceil(length/4.0)] = '+';
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class TellstickCmdSend implements TellstickCmd{
|
|||
}
|
||||
|
||||
|
||||
public String getTransmissionString(){
|
||||
public String getTransmissionString() {
|
||||
cmd[0] = 'S';
|
||||
cmd[OFFSET_PULSES+length] = '+';
|
||||
return new String(cmd, 0, OFFSET_PULSES+length+1, StandardCharsets.ISO_8859_1);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ public class NexaSelfLearning implements TellstickDevice, HalEventConfig, Tellst
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NexaSelfLearning)
|
||||
return ((NexaSelfLearning) obj).house == house &&
|
||||
((NexaSelfLearning) obj).group == group &&
|
||||
((NexaSelfLearning)obj).unit == unit;
|
||||
|
|
@ -100,13 +100,13 @@ public class NexaSelfLearning implements TellstickDevice, HalEventConfig, Tellst
|
|||
}
|
||||
@Override
|
||||
public boolean equalsGroup(TellstickDeviceGroup obj) {
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
if (obj instanceof NexaSelfLearning)
|
||||
return ((NexaSelfLearning) obj).house == house &&
|
||||
(((NexaSelfLearning) obj).group || group );
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "house:" + house +
|
||||
", group:" + group +
|
||||
", unit:" + unit;
|
||||
|
|
|
|||
|
|
@ -81,14 +81,14 @@ public class NexaSelfLearningDimmer implements TellstickDevice, HalEventConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearningDimmer)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NexaSelfLearningDimmer)
|
||||
return ((NexaSelfLearningDimmer) obj).house == house &&
|
||||
((NexaSelfLearningDimmer)obj).unit == unit;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "house:" + house +
|
||||
", unit:" + unit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,14 +90,14 @@ public class Oregon0x1A2D implements TellstickDevice, HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof Oregon0x1A2D)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Oregon0x1A2D)
|
||||
return ((Oregon0x1A2D)obj).address == this.address &&
|
||||
((Oregon0x1A2D)obj).sensorType == this.sensorType;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "address:" + address + ",sensorType:" + sensorType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol {
|
|||
|
||||
|
||||
|
||||
public Oregon0x1A2DProtocol(){
|
||||
public Oregon0x1A2DProtocol() {
|
||||
super(PROTOCOL, MODEL);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol {
|
|||
OregonSensorType sensorType = device.getSensorType();
|
||||
if (sensorType == null)
|
||||
sensorType = OregonSensorType.POWER;
|
||||
switch (sensorType){
|
||||
switch (sensorType) {
|
||||
case HUMIDITY:
|
||||
dataObj = new HumiditySensorData(humidity, timestamp);
|
||||
humidityFound = true;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
OnOffEventData nexaData = new OnOffEventData();
|
||||
|
||||
System.out.println("Up and Running");
|
||||
while(true) {
|
||||
while (true) {
|
||||
Thread.sleep(2000);
|
||||
nexaData.turnOn();
|
||||
nexaDevice.setUnit(0);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class HalZigbeeControllerTest {
|
|||
|
||||
handleConsoleInput('h', controller.networkManager);
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
char input = waitForInout();
|
||||
handleConsoleInput(input, controller.networkManager);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue