diff --git a/build.xml b/build.xml
old mode 100644
new mode 100755
index 5c43b1c5..31c391ab
--- a/build.xml
+++ b/build.xml
@@ -26,7 +26,7 @@
-
+
@@ -35,7 +35,7 @@
-
+
@@ -44,7 +44,7 @@
-
+
@@ -70,12 +70,12 @@
-
+
-
+
diff --git a/run.sh b/run.sh
index dc02820f..76728b9c 100755
--- a/run.sh
+++ b/run.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#screen -S hal -L -d -m \
-# java -cp sqlite-jdbc-3.7.2.jar:jSerialComm-1.3.4.jar:hal.jar:. se.koc.hal.plugin.tellstick.TelstickSerialCommTest
+# java -cp sqlite-jdbc-3.7.2.jar:jSerialComm-1.3.4.jar:hal.jar:. se.hal.plugin.tellstick.TelstickSerialCommTest
#ant clean
ant build
diff --git a/src/se/koc/hal/ControllerManager.java b/src/se/hal/ControllerManager.java
similarity index 98%
rename from src/se/koc/hal/ControllerManager.java
rename to src/se/hal/ControllerManager.java
index 92550a31..cc4d645c 100755
--- a/src/se/koc/hal/ControllerManager.java
+++ b/src/se/hal/ControllerManager.java
@@ -1,9 +1,8 @@
-package se.koc.hal;
+package se.hal;
-import se.koc.hal.intf.*;
-import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
-import se.koc.hal.struct.Event;
-import se.koc.hal.struct.Sensor;
+import se.hal.intf.*;
+import se.hal.struct.Event;
+import se.hal.struct.Sensor;
import zutil.db.DBConnection;
import zutil.log.LogUtil;
import zutil.plugin.PluginData;
diff --git a/src/se/koc/hal/HalClient.java b/src/se/hal/HalClient.java
similarity index 94%
rename from src/se/koc/hal/HalClient.java
rename to src/se/hal/HalClient.java
index 9d39d658..e7dafc63 100755
--- a/src/se/koc/hal/HalClient.java
+++ b/src/se/hal/HalClient.java
@@ -1,12 +1,12 @@
-package se.koc.hal;
+package se.hal;
-import se.koc.hal.bot.AliceBot;
-import se.koc.hal.intf.HalBot;
-import se.koc.hal.intf.HalSpeachToText;
-import se.koc.hal.intf.HalTextToSpeach;
-import se.koc.hal.struct.SwitchEvent;
-import se.koc.hal.stt.ManualSTTClient;
-import se.koc.hal.tts.MaryRemoteTTSClient;
+import se.hal.bot.AliceBot;
+import se.hal.intf.HalBot;
+import se.hal.intf.HalSpeachToText;
+import se.hal.intf.HalTextToSpeach;
+import se.hal.struct.SwitchEvent;
+import se.hal.stt.ManualSTTClient;
+import se.hal.tts.MaryRemoteTTSClient;
import java.util.HashMap;
import java.util.regex.Matcher;
diff --git a/src/se/koc/hal/HalContext.java b/src/se/hal/HalContext.java
similarity index 99%
rename from src/se/koc/hal/HalContext.java
rename to src/se/hal/HalContext.java
index 1f38e078..e931a826 100755
--- a/src/se/koc/hal/HalContext.java
+++ b/src/se/hal/HalContext.java
@@ -1,4 +1,4 @@
-package se.koc.hal;
+package se.hal;
import zutil.db.DBConnection;
import zutil.db.DBUpgradeHandler;
diff --git a/src/se/koc/hal/PowerChallenge.java b/src/se/hal/PowerChallenge.java
similarity index 79%
rename from src/se/koc/hal/PowerChallenge.java
rename to src/se/hal/PowerChallenge.java
index e30c39af..8726b074 100755
--- a/src/se/koc/hal/PowerChallenge.java
+++ b/src/se/hal/PowerChallenge.java
@@ -1,17 +1,17 @@
-package se.koc.hal;
+package se.hal;
-import se.koc.hal.deamon.DataAggregatorDaemon;
-import se.koc.hal.deamon.DataCleanupDaemon;
-import se.koc.hal.deamon.DataSynchronizationClient;
-import se.koc.hal.deamon.DataSynchronizationDaemon;
-import se.koc.hal.intf.HalDaemon;
-import se.koc.hal.intf.HalHttpPage;
-import se.koc.hal.page.PCConfigureHttpPage;
-import se.koc.hal.page.PCHeatMapHttpPage;
-import se.koc.hal.page.PCOverviewHttpPage;
-import se.koc.hal.struct.Event;
-import se.koc.hal.struct.Sensor;
+import se.hal.deamon.DataAggregatorDaemon;
+import se.hal.deamon.DataCleanupDaemon;
+import se.hal.deamon.DataSynchronizationClient;
+import se.hal.deamon.DataSynchronizationDaemon;
+import se.hal.intf.HalDaemon;
+import se.hal.intf.HalHttpPage;
+import se.hal.page.PCConfigureHttpPage;
+import se.hal.page.PCHeatMapHttpPage;
+import se.hal.page.PCOverviewHttpPage;
+import se.hal.struct.Event;
+import se.hal.struct.Sensor;
import zutil.db.DBConnection;
import zutil.io.file.FileUtil;
import zutil.log.CompactLogFormatter;
@@ -35,8 +35,8 @@ public class PowerChallenge {
public static void main(String[] args) throws Exception {
// init logging
CompactLogFormatter formatter = new CompactLogFormatter();
- LogUtil.setLevel("se.koc.hal", Level.FINEST);
- LogUtil.setFormatter("se.koc.hal", formatter);
+ LogUtil.setLevel("se.hal", Level.FINEST);
+ LogUtil.setFormatter("se.hal", formatter);
LogUtil.setLevel("zutil", Level.FINEST);
LogUtil.setFormatter("zutil", formatter);
LogUtil.setGlobalFormatter(formatter);
diff --git a/src/se/koc/hal/bot/AliceBot.java b/src/se/hal/bot/AliceBot.java
similarity index 94%
rename from src/se/koc/hal/bot/AliceBot.java
rename to src/se/hal/bot/AliceBot.java
index 5eb9d4cc..656bc831 100755
--- a/src/se/koc/hal/bot/AliceBot.java
+++ b/src/se/hal/bot/AliceBot.java
@@ -1,58 +1,58 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.bot;
-
-import org.alicebot.ab.Bot;
-import org.alicebot.ab.Chat;
-import org.alicebot.ab.MagicBooleans;
-import se.koc.hal.intf.HalBot;
-import zutil.io.file.FileUtil;
-
-import java.io.File;
-
-/**
- * Created by Ziver on 2015-05-07.
- */
-public class AliceBot implements HalBot{
- private Chat chatSession;
-
- @Override
- public void initialize() {
- MagicBooleans.trace_mode = false;
-
- File path = FileUtil.find("resource");
- if(path == null || !path.exists()){
- System.err.println("Bot folder does not exist");
- System.exit(1);
- }
- Bot bot = new Bot(
- "super",
- path.getAbsolutePath());
- chatSession = new Chat(bot);
- }
-
- @Override
- public String respond(String question) {
- return chatSession.multisentenceRespond(question);
- }
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.bot;
+
+import org.alicebot.ab.Bot;
+import org.alicebot.ab.Chat;
+import org.alicebot.ab.MagicBooleans;
+import se.hal.intf.HalBot;
+import zutil.io.file.FileUtil;
+
+import java.io.File;
+
+/**
+ * Created by Ziver on 2015-05-07.
+ */
+public class AliceBot implements HalBot{
+ private Chat chatSession;
+
+ @Override
+ public void initialize() {
+ MagicBooleans.trace_mode = false;
+
+ File path = FileUtil.find("resource");
+ if(path == null || !path.exists()){
+ System.err.println("Bot folder does not exist");
+ System.exit(1);
+ }
+ Bot bot = new Bot(
+ "super",
+ path.getAbsolutePath());
+ chatSession = new Chat(bot);
+ }
+
+ @Override
+ public String respond(String question) {
+ return chatSession.multisentenceRespond(question);
+ }
+}
diff --git a/src/se/koc/hal/deamon/DataAggregatorDaemon.java b/src/se/hal/deamon/DataAggregatorDaemon.java
similarity index 97%
rename from src/se/koc/hal/deamon/DataAggregatorDaemon.java
rename to src/se/hal/deamon/DataAggregatorDaemon.java
index 0cdc51a5..8856065d 100755
--- a/src/se/koc/hal/deamon/DataAggregatorDaemon.java
+++ b/src/se/hal/deamon/DataAggregatorDaemon.java
@@ -1,11 +1,11 @@
-package se.koc.hal.deamon;
+package se.hal.deamon;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalDaemon;
-import se.koc.hal.struct.Sensor;
-import se.koc.hal.intf.HalSensor.AggregationMethod;
-import se.koc.hal.struct.PowerConsumptionSensor;
-import se.koc.hal.util.TimeUtility;
+import se.hal.HalContext;
+import se.hal.intf.HalDaemon;
+import se.hal.struct.Sensor;
+import se.hal.intf.HalSensor.AggregationMethod;
+import se.hal.struct.PowerConsumptionSensor;
+import se.hal.util.TimeUtility;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
import zutil.db.handler.SimpleSQLResult;
diff --git a/src/se/koc/hal/deamon/DataCleanupDaemon.java b/src/se/hal/deamon/DataCleanupDaemon.java
similarity index 96%
rename from src/se/koc/hal/deamon/DataCleanupDaemon.java
rename to src/se/hal/deamon/DataCleanupDaemon.java
index 1bd07543..3eda6786 100755
--- a/src/se/koc/hal/deamon/DataCleanupDaemon.java
+++ b/src/se/hal/deamon/DataCleanupDaemon.java
@@ -1,10 +1,10 @@
-package se.koc.hal.deamon;
+package se.hal.deamon;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalDaemon;
-import se.koc.hal.struct.Sensor;
-import se.koc.hal.struct.PowerConsumptionSensor;
-import se.koc.hal.util.TimeUtility;
+import se.hal.HalContext;
+import se.hal.intf.HalDaemon;
+import se.hal.struct.Sensor;
+import se.hal.struct.PowerConsumptionSensor;
+import se.hal.util.TimeUtility;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
import zutil.db.handler.SimpleSQLResult;
diff --git a/src/se/koc/hal/deamon/DataSynchronizationClient.java b/src/se/hal/deamon/DataSynchronizationClient.java
similarity index 93%
rename from src/se/koc/hal/deamon/DataSynchronizationClient.java
rename to src/se/hal/deamon/DataSynchronizationClient.java
index abeefe85..142c89f2 100755
--- a/src/se/koc/hal/deamon/DataSynchronizationClient.java
+++ b/src/se/hal/deamon/DataSynchronizationClient.java
@@ -1,134 +1,134 @@
-package se.koc.hal.deamon;
-
-import se.koc.hal.HalContext;
-import se.koc.hal.deamon.DataSynchronizationDaemon.*;
-import se.koc.hal.intf.HalDaemon;
-import se.koc.hal.struct.Sensor;
-import se.koc.hal.struct.User;
-import zutil.db.DBConnection;
-import zutil.log.LogUtil;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.net.ConnectException;
-import java.net.NoRouteToHostException;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class DataSynchronizationClient implements HalDaemon {
- private static final Logger logger = LogUtil.getLogger();
- private static final long SYNC_INTERVAL = 5 * 60 * 1000; // 5 min
-
-
- @Override
- public void initiate(ScheduledExecutorService executor){
- executor.scheduleAtFixedRate(this, 10000, SYNC_INTERVAL, TimeUnit.MILLISECONDS);
- }
-
- @Override
- public void run() {
- try {
- DBConnection db = HalContext.getDB();
- List users = User.getExternalUsers(db);
- for(User user : users){
- if(user.getHostname() == null){
- logger.fine("Hostname not defined for user: "+ user.getUserName());
- continue;
- }
- logger.fine("Synchronizing user: "+ user.getUserName() +" ("+user.getHostname()+":"+user.getPort()+")");
- try (Socket s = new Socket(user.getHostname(), user.getPort());){
- ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
- ObjectInputStream in = new ObjectInputStream(s.getInputStream());
-
- // Request peer data
- out.writeObject(new PeerDataReqDTO());
- PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
- user.setUserName(peerData.username);
- user.setAddress(peerData.address);
- user.save(db);
-
- for(SensorDTO sensorDTO : peerData.sensors){
- Sensor sensor = Sensor.getExternalSensor(db, sensorDTO.sensorId);
- if(sensor != null) { // new sensor
- sensor = new Sensor();
- logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
- }
- else
- logger.fine("Updating external sensor with external_id: "+ sensorDTO.sensorId);
- sensor.setExternalId(sensorDTO.sensorId);
- sensor.setName(sensorDTO.name);
- sensor.setType(sensorDTO.type);
- sensor.setConfig(sensorDTO.config);
- sensor.save(db);
- }
-
- // Request sensor data
- List sensors = Sensor.getSensors(db, user);
- for(Sensor sensor : sensors){
- if(sensor.isSynced()) {
- SensorDataReqDTO req = new SensorDataReqDTO();
- req.sensorId = sensor.getExternalId();
- req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
- out.writeObject(req);
-
- SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
- for (SensorDataDTO data : dataList) {
- PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_aggr(sensor_id, sequence_id, timestamp_start, timestamp_end, data, confidence) VALUES(?, ?, ?, ?, ?, ?)");
- stmt.setLong(1, sensor.getId());
- stmt.setLong(2, data.sequenceId);
- stmt.setLong(3, data.timestampStart);
- stmt.setLong(4, data.timestampEnd);
- stmt.setInt(5, data.data);
- stmt.setFloat(6, data.confidence);
- DBConnection.exec(stmt);
- }
- logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getUserName());
- }
- else
- logger.fine("Skipped sensor " + sensor.getId());
- }
- out.writeObject(null); // Tell server we are disconnecting
- out.close();
- in.close();
- s.close();
-
- } catch (NoRouteToHostException |UnknownHostException|ConnectException e) {
- logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
- } catch (ClassNotFoundException|IOException e) {
- logger.log(Level.SEVERE, null, e);
- }
-
- }
- } catch (SQLException e) {
- logger.log(Level.SEVERE, null, e);
- }
- }
-
-
-
- /////////////// DTO ///////////////////////
-
- /**
- * Request Peer information and available sensors
- */
- protected static class PeerDataReqDTO implements Serializable{}
-
- /**
- * Request aggregate data for a specific sensor and offset
- */
- protected static class SensorDataReqDTO implements Serializable{
- private static final long serialVersionUID = -9066734025245139989L;
-
- public long sensorId;
- public long offsetSequenceId; // highest known sequence id
- }
-}
+package se.hal.deamon;
+
+import se.hal.HalContext;
+import se.hal.deamon.DataSynchronizationDaemon.*;
+import se.hal.intf.HalDaemon;
+import se.hal.struct.Sensor;
+import se.hal.struct.User;
+import zutil.db.DBConnection;
+import zutil.log.LogUtil;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.ConnectException;
+import java.net.NoRouteToHostException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class DataSynchronizationClient implements HalDaemon {
+ private static final Logger logger = LogUtil.getLogger();
+ private static final long SYNC_INTERVAL = 5 * 60 * 1000; // 5 min
+
+
+ @Override
+ public void initiate(ScheduledExecutorService executor){
+ executor.scheduleAtFixedRate(this, 10000, SYNC_INTERVAL, TimeUnit.MILLISECONDS);
+ }
+
+ @Override
+ public void run() {
+ try {
+ DBConnection db = HalContext.getDB();
+ List users = User.getExternalUsers(db);
+ for(User user : users){
+ if(user.getHostname() == null){
+ logger.fine("Hostname not defined for user: "+ user.getUserName());
+ continue;
+ }
+ logger.fine("Synchronizing user: "+ user.getUserName() +" ("+user.getHostname()+":"+user.getPort()+")");
+ try (Socket s = new Socket(user.getHostname(), user.getPort());){
+ ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
+ ObjectInputStream in = new ObjectInputStream(s.getInputStream());
+
+ // Request peer data
+ out.writeObject(new PeerDataReqDTO());
+ PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
+ user.setUserName(peerData.username);
+ user.setAddress(peerData.address);
+ user.save(db);
+
+ for(SensorDTO sensorDTO : peerData.sensors){
+ Sensor sensor = Sensor.getExternalSensor(db, sensorDTO.sensorId);
+ if(sensor != null) { // new sensor
+ sensor = new Sensor();
+ logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
+ }
+ else
+ logger.fine("Updating external sensor with external_id: "+ sensorDTO.sensorId);
+ sensor.setExternalId(sensorDTO.sensorId);
+ sensor.setName(sensorDTO.name);
+ sensor.setType(sensorDTO.type);
+ sensor.setConfig(sensorDTO.config);
+ sensor.save(db);
+ }
+
+ // Request sensor data
+ List sensors = Sensor.getSensors(db, user);
+ for(Sensor sensor : sensors){
+ if(sensor.isSynced()) {
+ SensorDataReqDTO req = new SensorDataReqDTO();
+ req.sensorId = sensor.getExternalId();
+ req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
+ out.writeObject(req);
+
+ SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
+ for (SensorDataDTO data : dataList) {
+ PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_aggr(sensor_id, sequence_id, timestamp_start, timestamp_end, data, confidence) VALUES(?, ?, ?, ?, ?, ?)");
+ stmt.setLong(1, sensor.getId());
+ stmt.setLong(2, data.sequenceId);
+ stmt.setLong(3, data.timestampStart);
+ stmt.setLong(4, data.timestampEnd);
+ stmt.setInt(5, data.data);
+ stmt.setFloat(6, data.confidence);
+ DBConnection.exec(stmt);
+ }
+ logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getUserName());
+ }
+ else
+ logger.fine("Skipped sensor " + sensor.getId());
+ }
+ out.writeObject(null); // Tell server we are disconnecting
+ out.close();
+ in.close();
+ s.close();
+
+ } catch (NoRouteToHostException |UnknownHostException|ConnectException e) {
+ logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
+ } catch (ClassNotFoundException|IOException e) {
+ logger.log(Level.SEVERE, null, e);
+ }
+
+ }
+ } catch (SQLException e) {
+ logger.log(Level.SEVERE, null, e);
+ }
+ }
+
+
+
+ /////////////// DTO ///////////////////////
+
+ /**
+ * Request Peer information and available sensors
+ */
+ protected static class PeerDataReqDTO implements Serializable{}
+
+ /**
+ * Request aggregate data for a specific sensor and offset
+ */
+ protected static class SensorDataReqDTO implements Serializable{
+ private static final long serialVersionUID = -9066734025245139989L;
+
+ public long sensorId;
+ public long offsetSequenceId; // highest known sequence id
+ }
+}
diff --git a/src/se/koc/hal/deamon/DataSynchronizationDaemon.java b/src/se/hal/deamon/DataSynchronizationDaemon.java
similarity index 94%
rename from src/se/koc/hal/deamon/DataSynchronizationDaemon.java
rename to src/se/hal/deamon/DataSynchronizationDaemon.java
index 4fba7687..4d4f4ad5 100755
--- a/src/se/koc/hal/deamon/DataSynchronizationDaemon.java
+++ b/src/se/hal/deamon/DataSynchronizationDaemon.java
@@ -1,167 +1,166 @@
-package se.koc.hal.deamon;
-
-import se.koc.hal.HalContext;
-import se.koc.hal.deamon.DataSynchronizationClient.*;
-import se.koc.hal.intf.HalDaemon;
-import se.koc.hal.struct.Sensor;
-import se.koc.hal.struct.User;
-import zutil.db.DBConnection;
-import zutil.db.SQLResultHandler;
-import zutil.log.LogUtil;
-import zutil.net.threaded.ThreadedTCPNetworkServer;
-import zutil.net.threaded.ThreadedTCPNetworkServerThread;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.net.Socket;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
- private static final Logger logger = LogUtil.getLogger();
-
-
- public DataSynchronizationDaemon() {
- super(HalContext.getIntegerProperty("sync_port"));
- }
-
- @Override
- public void initiate(ScheduledExecutorService executor){
- this.start();
- }
-
-
-
- @Override
- protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
- try {
- return new DataSynchronizationDaemonThread(s);
- } catch (IOException e) {
- logger.log(Level.SEVERE, "Unable to create DataSynchronizationDaemonThread", e);
- }
- return null;
- }
-
-
- private class DataSynchronizationDaemonThread implements ThreadedTCPNetworkServerThread{
- private Socket s;
- private ObjectOutputStream out;
- private ObjectInputStream in;
-
-
- public DataSynchronizationDaemonThread(Socket s) throws IOException{
- this.s = s;
- this.out = new ObjectOutputStream(s.getOutputStream());
- this.in = new ObjectInputStream(s.getInputStream());
- }
-
-
- public void run(){
- logger.fine("User connected: "+ s.getInetAddress().getHostName());
- DBConnection db = HalContext.getDB();
-
- try {
- Object obj = null;
- while((obj = in.readObject()) != null){
- if(obj instanceof PeerDataReqDTO){
- logger.fine("Client requesting peer data");
- PeerDataRspDTO rsp = new PeerDataRspDTO();
- User localUser = User.getLocalUser(db);
- rsp.username = localUser.getUserName();
- rsp.address = localUser.getAddress();
-
- rsp.sensors = new ArrayList<>();
- for(Sensor sensor : Sensor.getLocalSensors(db)){
- if(sensor.isSynced()) {
- SensorDTO dto = new SensorDTO();
- dto.sensorId = sensor.getId();
- dto.name = sensor.getName();
- dto.type = sensor.getType();
- dto.config = sensor.getConfig();
- rsp.sensors.add(dto);
- }
- }
- out.writeObject(rsp);
- }
- if(obj instanceof SensorDataReqDTO){
- SensorDataReqDTO req = (SensorDataReqDTO) obj;
- Sensor sensor = Sensor.getSensor(db, req.sensorId);
- if(sensor.isSynced()) {
- PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
- stmt.setLong(1, sensor.getId());
- stmt.setLong(2, req.offsetSequenceId);
- logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
- SensorDataListDTO rsp = DBConnection.exec(stmt, new SQLResultHandler() {
- @Override
- public SensorDataListDTO handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
- SensorDataListDTO list = new SensorDataListDTO();
- while (result.next()) {
- SensorDataDTO data = new SensorDataDTO();
- data.sequenceId = result.getLong("sensor_id");
- data.timestampStart = result.getLong("timestamp_start");
- data.timestampEnd = result.getLong("timestamp_end");
- data.data = result.getInt("data");
- data.confidence = result.getFloat("confidence");
- list.add(data);
- }
- return list;
- }
- });
- logger.fine("Sending " + rsp.size() + " sensor data items to client");
- out.writeObject(rsp);
- }
- else{
- logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
- SensorDataListDTO rsp = new SensorDataListDTO();
- out.writeObject(rsp);
- }
- }
- }
- out.close();
- in.close();
- s.close();
-
- } catch (ClassNotFoundException|IOException|SQLException e) {
- logger.log(Level.SEVERE, null, e);
- }
- logger.fine("User disconnected: "+ s.getInetAddress().getHostName());
- }
- }
-
- /////////////// DTO ///////////////////////
- protected static class PeerDataRspDTO implements Serializable{
- public String username;
- public String address;
-
- public ArrayList sensors;
- }
- protected static class SensorDTO implements Serializable{
- public long sensorId;
- public String name;
- public String type;
- public String config;
- }
-
-
- protected static class SensorDataListDTO extends ArrayList implements Serializable{
- private static final long serialVersionUID = -5701618637734020691L;
- }
- protected static class SensorDataDTO implements Serializable{
- private static final long serialVersionUID = 8494331502087736809L;
-
- public long sequenceId;
- public long timestampStart;
- public long timestampEnd;
- public int data;
- public float confidence;
- }
-}
+package se.hal.deamon;
+
+import se.hal.HalContext;
+import se.hal.deamon.DataSynchronizationClient.*;
+import se.hal.intf.HalDaemon;
+import se.hal.struct.Sensor;
+import se.hal.struct.User;
+import zutil.db.DBConnection;
+import zutil.db.SQLResultHandler;
+import zutil.log.LogUtil;
+import zutil.net.threaded.ThreadedTCPNetworkServer;
+import zutil.net.threaded.ThreadedTCPNetworkServerThread;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.Socket;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
+ private static final Logger logger = LogUtil.getLogger();
+
+
+ public DataSynchronizationDaemon() {
+ super(HalContext.getIntegerProperty("sync_port"));
+ }
+
+ @Override
+ public void initiate(ScheduledExecutorService executor){
+ this.start();
+ }
+
+
+
+ @Override
+ protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
+ try {
+ return new DataSynchronizationDaemonThread(s);
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, "Unable to create DataSynchronizationDaemonThread", e);
+ }
+ return null;
+ }
+
+
+ private class DataSynchronizationDaemonThread implements ThreadedTCPNetworkServerThread{
+ private Socket s;
+ private ObjectOutputStream out;
+ private ObjectInputStream in;
+
+
+ public DataSynchronizationDaemonThread(Socket s) throws IOException{
+ this.s = s;
+ this.out = new ObjectOutputStream(s.getOutputStream());
+ this.in = new ObjectInputStream(s.getInputStream());
+ }
+
+
+ public void run(){
+ logger.fine("User connected: "+ s.getInetAddress().getHostName());
+ DBConnection db = HalContext.getDB();
+
+ try {
+ Object obj = null;
+ while((obj = in.readObject()) != null){
+ if(obj instanceof PeerDataReqDTO){
+ logger.fine("Client requesting peer data");
+ PeerDataRspDTO rsp = new PeerDataRspDTO();
+ User localUser = User.getLocalUser(db);
+ rsp.username = localUser.getUserName();
+ rsp.address = localUser.getAddress();
+
+ rsp.sensors = new ArrayList<>();
+ for(Sensor sensor : Sensor.getLocalSensors(db)){
+ if(sensor.isSynced()) {
+ SensorDTO dto = new SensorDTO();
+ dto.sensorId = sensor.getId();
+ dto.name = sensor.getName();
+ dto.type = sensor.getType();
+ dto.config = sensor.getConfig();
+ rsp.sensors.add(dto);
+ }
+ }
+ out.writeObject(rsp);
+ }
+ if(obj instanceof SensorDataReqDTO){
+ SensorDataReqDTO req = (SensorDataReqDTO) obj;
+ Sensor sensor = Sensor.getSensor(db, req.sensorId);
+ if(sensor.isSynced()) {
+ PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
+ stmt.setLong(1, sensor.getId());
+ stmt.setLong(2, req.offsetSequenceId);
+ logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
+ SensorDataListDTO rsp = DBConnection.exec(stmt, new SQLResultHandler() {
+ @Override
+ public SensorDataListDTO handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
+ SensorDataListDTO list = new SensorDataListDTO();
+ while (result.next()) {
+ SensorDataDTO data = new SensorDataDTO();
+ data.sequenceId = result.getLong("sensor_id");
+ data.timestampStart = result.getLong("timestamp_start");
+ data.timestampEnd = result.getLong("timestamp_end");
+ data.data = result.getInt("data");
+ data.confidence = result.getFloat("confidence");
+ list.add(data);
+ }
+ return list;
+ }
+ });
+ logger.fine("Sending " + rsp.size() + " sensor data items to client");
+ out.writeObject(rsp);
+ }
+ else{
+ logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
+ SensorDataListDTO rsp = new SensorDataListDTO();
+ out.writeObject(rsp);
+ }
+ }
+ }
+ out.close();
+ in.close();
+ s.close();
+
+ } catch (ClassNotFoundException|IOException|SQLException e) {
+ logger.log(Level.SEVERE, null, e);
+ }
+ logger.fine("User disconnected: "+ s.getInetAddress().getHostName());
+ }
+ }
+
+ /////////////// DTO ///////////////////////
+ protected static class PeerDataRspDTO implements Serializable{
+ public String username;
+ public String address;
+
+ public ArrayList sensors;
+ }
+ protected static class SensorDTO implements Serializable{
+ public long sensorId;
+ public String name;
+ public String type;
+ public String config;
+ }
+
+
+ protected static class SensorDataListDTO extends ArrayList implements Serializable{
+ private static final long serialVersionUID = -5701618637734020691L;
+ }
+ protected static class SensorDataDTO implements Serializable{
+ private static final long serialVersionUID = 8494331502087736809L;
+
+ public long sequenceId;
+ public long timestampStart;
+ public long timestampEnd;
+ public int data;
+ public float confidence;
+ }
+}
diff --git a/src/se/koc/hal/intf/HalBot.java b/src/se/hal/intf/HalBot.java
similarity index 95%
rename from src/se/koc/hal/intf/HalBot.java
rename to src/se/hal/intf/HalBot.java
index 1f341ae2..577e0ef4 100755
--- a/src/se/koc/hal/intf/HalBot.java
+++ b/src/se/hal/intf/HalBot.java
@@ -1,33 +1,33 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.intf;
-
-/**
- * Created by Ziver on 2015-05-07.
- */
-public interface HalBot {
-
- public void initialize();
-
- public String respond(String question);
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.intf;
+
+/**
+ * Created by Ziver on 2015-05-07.
+ */
+public interface HalBot {
+
+ public void initialize();
+
+ public String respond(String question);
+}
diff --git a/src/se/koc/hal/intf/HalDaemon.java b/src/se/hal/intf/HalDaemon.java
similarity index 89%
rename from src/se/koc/hal/intf/HalDaemon.java
rename to src/se/hal/intf/HalDaemon.java
index e0de4298..f5698afe 100755
--- a/src/se/koc/hal/intf/HalDaemon.java
+++ b/src/se/hal/intf/HalDaemon.java
@@ -1,4 +1,4 @@
-package se.koc.hal.intf;
+package se.hal.intf;
import java.util.concurrent.ScheduledExecutorService;
diff --git a/src/se/koc/hal/intf/HalEvent.java b/src/se/hal/intf/HalEvent.java
similarity index 87%
rename from src/se/koc/hal/intf/HalEvent.java
rename to src/se/hal/intf/HalEvent.java
index 1f05f7ce..a1289d76 100755
--- a/src/se/koc/hal/intf/HalEvent.java
+++ b/src/se/hal/intf/HalEvent.java
@@ -1,6 +1,4 @@
-package se.koc.hal.intf;
-
-import zutil.parser.DataNode;
+package se.hal.intf;
/**
* Created by Ziver on 2015-12-23.
diff --git a/src/se/koc/hal/intf/HalEventController.java b/src/se/hal/intf/HalEventController.java
similarity index 97%
rename from src/se/koc/hal/intf/HalEventController.java
rename to src/se/hal/intf/HalEventController.java
index e9084df9..1dd1f551 100755
--- a/src/se/koc/hal/intf/HalEventController.java
+++ b/src/se/hal/intf/HalEventController.java
@@ -1,4 +1,4 @@
-package se.koc.hal.intf;
+package se.hal.intf;
/**
* Created by Ziver on 2015-12-15.
diff --git a/src/se/koc/hal/intf/HalEventReportListener.java b/src/se/hal/intf/HalEventReportListener.java
similarity index 76%
rename from src/se/koc/hal/intf/HalEventReportListener.java
rename to src/se/hal/intf/HalEventReportListener.java
index 0d2f6f01..869fa8de 100755
--- a/src/se/koc/hal/intf/HalEventReportListener.java
+++ b/src/se/hal/intf/HalEventReportListener.java
@@ -1,4 +1,4 @@
-package se.koc.hal.intf;
+package se.hal.intf;
public interface HalEventReportListener {
diff --git a/src/se/koc/hal/intf/HalHttpPage.java b/src/se/hal/intf/HalHttpPage.java
similarity index 95%
rename from src/se/koc/hal/intf/HalHttpPage.java
rename to src/se/hal/intf/HalHttpPage.java
index fc0e800c..4b7dc967 100755
--- a/src/se/koc/hal/intf/HalHttpPage.java
+++ b/src/se/hal/intf/HalHttpPage.java
@@ -1,7 +1,7 @@
-package se.koc.hal.intf;
+package se.hal.intf;
-import se.koc.hal.HalContext;
-import se.koc.hal.struct.User;
+import se.hal.HalContext;
+import se.hal.struct.User;
import zutil.db.DBConnection;
import zutil.io.file.FileUtil;
import zutil.net.http.HttpHeaderParser;
diff --git a/src/se/koc/hal/intf/HalSensor.java b/src/se/hal/intf/HalSensor.java
similarity index 89%
rename from src/se/koc/hal/intf/HalSensor.java
rename to src/se/hal/intf/HalSensor.java
index ef03e10b..0dbed5be 100755
--- a/src/se/koc/hal/intf/HalSensor.java
+++ b/src/se/hal/intf/HalSensor.java
@@ -1,6 +1,4 @@
-package se.koc.hal.intf;
-
-import zutil.parser.DataNode;
+package se.hal.intf;
/**
* Created by Ziver on 2015-12-23.
diff --git a/src/se/koc/hal/intf/HalSensorController.java b/src/se/hal/intf/HalSensorController.java
similarity index 97%
rename from src/se/koc/hal/intf/HalSensorController.java
rename to src/se/hal/intf/HalSensorController.java
index d449ad77..d74363fe 100755
--- a/src/se/koc/hal/intf/HalSensorController.java
+++ b/src/se/hal/intf/HalSensorController.java
@@ -1,4 +1,4 @@
-package se.koc.hal.intf;
+package se.hal.intf;
/**
* Created by Ziver on 2015-12-15.
diff --git a/src/se/koc/hal/intf/HalSensorReportListener.java b/src/se/hal/intf/HalSensorReportListener.java
similarity index 77%
rename from src/se/koc/hal/intf/HalSensorReportListener.java
rename to src/se/hal/intf/HalSensorReportListener.java
index 00421a59..9c4a73cb 100755
--- a/src/se/koc/hal/intf/HalSensorReportListener.java
+++ b/src/se/hal/intf/HalSensorReportListener.java
@@ -1,4 +1,4 @@
-package se.koc.hal.intf;
+package se.hal.intf;
public interface HalSensorReportListener {
diff --git a/src/se/koc/hal/intf/HalSpeachToText.java b/src/se/hal/intf/HalSpeachToText.java
similarity index 95%
rename from src/se/koc/hal/intf/HalSpeachToText.java
rename to src/se/hal/intf/HalSpeachToText.java
index b64634b0..67399eeb 100755
--- a/src/se/koc/hal/intf/HalSpeachToText.java
+++ b/src/se/hal/intf/HalSpeachToText.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (c) 2013 ezivkoc
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.intf;
-
-/**
- * Created with IntelliJ IDEA.
- * User: ezivkoc
- * Date: 2013-12-17
- * Time: 13:40
- */
-public interface HalSpeachToText {
- public void initSTT();
-
- public String listen();
-}
+/*
+ * Copyright (c) 2013 ezivkoc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.intf;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 13:40
+ */
+public interface HalSpeachToText {
+ public void initSTT();
+
+ public String listen();
+}
diff --git a/src/se/koc/hal/intf/HalTextToSpeach.java b/src/se/hal/intf/HalTextToSpeach.java
similarity index 95%
rename from src/se/koc/hal/intf/HalTextToSpeach.java
rename to src/se/hal/intf/HalTextToSpeach.java
index 378e80e9..60095fe3 100755
--- a/src/se/koc/hal/intf/HalTextToSpeach.java
+++ b/src/se/hal/intf/HalTextToSpeach.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (c) 2013 ezivkoc
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.intf;
-
-/**
- * Created with IntelliJ IDEA.
- * User: ezivkoc
- * Date: 2013-12-17
- * Time: 13:40
- */
-public interface HalTextToSpeach {
- public void initTTS();
-
- public void speak(String msg);
-}
+/*
+ * Copyright (c) 2013 ezivkoc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.intf;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 13:40
+ */
+public interface HalTextToSpeach {
+ public void initTTS();
+
+ public void speak(String msg);
+}
diff --git a/src/se/koc/hal/page/PCConfigureHttpPage.java b/src/se/hal/page/PCConfigureHttpPage.java
similarity index 93%
rename from src/se/koc/hal/page/PCConfigureHttpPage.java
rename to src/se/hal/page/PCConfigureHttpPage.java
index 7161b214..1527128b 100755
--- a/src/se/koc/hal/page/PCConfigureHttpPage.java
+++ b/src/se/hal/page/PCConfigureHttpPage.java
@@ -1,135 +1,135 @@
-package se.koc.hal.page;
-
-import se.koc.hal.ControllerManager;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalHttpPage;
-import se.koc.hal.struct.Sensor;
-import se.koc.hal.struct.User;
-import zutil.db.DBConnection;
-import zutil.io.file.FileUtil;
-import zutil.parser.Templator;
-import zutil.ui.Configurator;
-import zutil.ui.Configurator.*;
-
-import java.util.Map;
-
-public class PCConfigureHttpPage extends HalHttpPage {
- private class SensorDataParams{
- public Class clazz;
- public ConfigurationParam[] params;
- }
- private SensorDataParams[] sensorConfigurations;
-
-
- public PCConfigureHttpPage() {
- super("Configuration", "config");
-
- sensorConfigurations = new SensorDataParams[
- ControllerManager.getInstance().getAvailableSensors().size()];
- int i=0;
- for(Class c : ControllerManager.getInstance().getAvailableSensors()){
- sensorConfigurations[i] = new SensorDataParams();
- sensorConfigurations[i].clazz = c;
- sensorConfigurations[i].params = Configurator.getConfiguration(c);
- ++i;
- }
- }
-
- @Override
- public Templator httpRespond(
- Map session,
- Map cookie,
- Map request)
- throws Exception{
-
- DBConnection db = HalContext.getDB();
- User localUser = User.getLocalUser(db);
-
- // Save new input
- if(request.containsKey("action")){
- String action = request.get("action");
- int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
- Sensor sensor;
- User user;
- switch(action) {
- // Local User
- case "modify_local_user":
- localUser.setUserName(request.get("username"));
- localUser.setAddress(request.get("address"));
- localUser.save(db);
- break;
-
- // Local Sensors
- case "create_local_sensor":
- sensor = new Sensor();
- sensor.setName(request.get("name"));
- sensor.setType(request.get("type"));
- sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
- //sensor.setConfig(request.get("config"));
- sensor.setUser(localUser);
- sensor.save(db);
- case "modify_local_sensor":
- sensor = Sensor.getSensor(db, id);
- if(sensor != null){
- sensor.setName(request.get("name"));
- sensor.setType(request.get("type"));
- sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
- //sensor.setConfig(request.get("config"));
- sensor.save(db);
- }
- break;
- case "remove_local_sensor":
- sensor = Sensor.getSensor(db, id);
- if(sensor != null)
- sensor.delete(db);
- break;
-
- // External Users
- case "create_external_user":
- user = new User();
- user.setHostname(request.get("hostname"));
- user.setPort(Integer.parseInt(request.get("port")));
- user.setExternal(true);
- user.save(db);
- break;
- case "modify_external_user":
- user = User.getUser(db, id);
- if(user != null){
- user.setHostname(request.get("hostname"));
- user.setPort(Integer.parseInt(request.get("port")));
- user.save(db);
- }
- break;
- case "remove_external_user":
- user = User.getUser(db, id);
- if(user != null)
- user.delete(db);
- break;
-
- // External Sensors
- case "modify_external_sensor":
- sensor = Sensor.getSensor(db, id);
- if(sensor != null){
- sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
- sensor.save(db);
- }
- break;
- }
- }
-
- // Output
- Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
- tmpl.set("user", localUser);
- tmpl.set("localSensors", Sensor.getLocalSensors(db));
- tmpl.set("localSensorConf", sensorConfigurations);
- tmpl.set("detectedSensors", ControllerManager.getInstance().getDetectedSensors());
- tmpl.set("extUsers", User.getExternalUsers(db));
- tmpl.set("extSensor", Sensor.getExternalSensors(db));
-
- tmpl.set("availableSensors", ControllerManager.getInstance().getAvailableSensors());
-
- return tmpl;
-
- }
-
-}
+package se.hal.page;
+
+import se.hal.ControllerManager;
+import se.hal.HalContext;
+import se.hal.intf.HalHttpPage;
+import se.hal.struct.Sensor;
+import se.hal.struct.User;
+import zutil.db.DBConnection;
+import zutil.io.file.FileUtil;
+import zutil.parser.Templator;
+import zutil.ui.Configurator;
+import zutil.ui.Configurator.*;
+
+import java.util.Map;
+
+public class PCConfigureHttpPage extends HalHttpPage {
+ private class SensorDataParams{
+ public Class clazz;
+ public ConfigurationParam[] params;
+ }
+ private SensorDataParams[] sensorConfigurations;
+
+
+ public PCConfigureHttpPage() {
+ super("Configuration", "config");
+
+ sensorConfigurations = new SensorDataParams[
+ ControllerManager.getInstance().getAvailableSensors().size()];
+ int i=0;
+ for(Class c : ControllerManager.getInstance().getAvailableSensors()){
+ sensorConfigurations[i] = new SensorDataParams();
+ sensorConfigurations[i].clazz = c;
+ sensorConfigurations[i].params = Configurator.getConfiguration(c);
+ ++i;
+ }
+ }
+
+ @Override
+ public Templator httpRespond(
+ Map session,
+ Map cookie,
+ Map request)
+ throws Exception{
+
+ DBConnection db = HalContext.getDB();
+ User localUser = User.getLocalUser(db);
+
+ // Save new input
+ if(request.containsKey("action")){
+ String action = request.get("action");
+ int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
+ Sensor sensor;
+ User user;
+ switch(action) {
+ // Local User
+ case "modify_local_user":
+ localUser.setUserName(request.get("username"));
+ localUser.setAddress(request.get("address"));
+ localUser.save(db);
+ break;
+
+ // Local Sensors
+ case "create_local_sensor":
+ sensor = new Sensor();
+ sensor.setName(request.get("name"));
+ sensor.setType(request.get("type"));
+ sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
+ //sensor.setConfig(request.get("config"));
+ sensor.setUser(localUser);
+ sensor.save(db);
+ case "modify_local_sensor":
+ sensor = Sensor.getSensor(db, id);
+ if(sensor != null){
+ sensor.setName(request.get("name"));
+ sensor.setType(request.get("type"));
+ sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
+ //sensor.setConfig(request.get("config"));
+ sensor.save(db);
+ }
+ break;
+ case "remove_local_sensor":
+ sensor = Sensor.getSensor(db, id);
+ if(sensor != null)
+ sensor.delete(db);
+ break;
+
+ // External Users
+ case "create_external_user":
+ user = new User();
+ user.setHostname(request.get("hostname"));
+ user.setPort(Integer.parseInt(request.get("port")));
+ user.setExternal(true);
+ user.save(db);
+ break;
+ case "modify_external_user":
+ user = User.getUser(db, id);
+ if(user != null){
+ user.setHostname(request.get("hostname"));
+ user.setPort(Integer.parseInt(request.get("port")));
+ user.save(db);
+ }
+ break;
+ case "remove_external_user":
+ user = User.getUser(db, id);
+ if(user != null)
+ user.delete(db);
+ break;
+
+ // External Sensors
+ case "modify_external_sensor":
+ sensor = Sensor.getSensor(db, id);
+ if(sensor != null){
+ sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
+ sensor.save(db);
+ }
+ break;
+ }
+ }
+
+ // Output
+ Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
+ tmpl.set("user", localUser);
+ tmpl.set("localSensors", Sensor.getLocalSensors(db));
+ tmpl.set("localSensorConf", sensorConfigurations);
+ tmpl.set("detectedSensors", ControllerManager.getInstance().getDetectedSensors());
+ tmpl.set("extUsers", User.getExternalUsers(db));
+ tmpl.set("extSensor", Sensor.getExternalSensors(db));
+
+ tmpl.set("availableSensors", ControllerManager.getInstance().getAvailableSensors());
+
+ return tmpl;
+
+ }
+
+}
diff --git a/src/se/koc/hal/page/PCHeatMapHttpPage.java b/src/se/hal/page/PCHeatMapHttpPage.java
similarity index 84%
rename from src/se/koc/hal/page/PCHeatMapHttpPage.java
rename to src/se/hal/page/PCHeatMapHttpPage.java
index 4c1d1b03..8df440f3 100755
--- a/src/se/koc/hal/page/PCHeatMapHttpPage.java
+++ b/src/se/hal/page/PCHeatMapHttpPage.java
@@ -1,26 +1,26 @@
-package se.koc.hal.page;
-
-import se.koc.hal.intf.HalHttpPage;
-import zutil.io.file.FileUtil;
-import zutil.parser.Templator;
-
-import java.util.Map;
-
-public class PCHeatMapHttpPage extends HalHttpPage {
-
- public PCHeatMapHttpPage() {
- super("Heatmap", "map");
- }
-
- @Override
- public Templator httpRespond(
- Map session,
- Map cookie,
- Map request)
- throws Exception{
-
- Templator tmpl = new Templator(FileUtil.find("web-resource/heatmap.tmpl"));
- return tmpl;
- }
-
-}
+package se.hal.page;
+
+import se.hal.intf.HalHttpPage;
+import zutil.io.file.FileUtil;
+import zutil.parser.Templator;
+
+import java.util.Map;
+
+public class PCHeatMapHttpPage extends HalHttpPage {
+
+ public PCHeatMapHttpPage() {
+ super("Heatmap", "map");
+ }
+
+ @Override
+ public Templator httpRespond(
+ Map session,
+ Map cookie,
+ Map request)
+ throws Exception{
+
+ Templator tmpl = new Templator(FileUtil.find("web-resource/heatmap.tmpl"));
+ return tmpl;
+ }
+
+}
diff --git a/src/se/koc/hal/page/PCOverviewHttpPage.java b/src/se/hal/page/PCOverviewHttpPage.java
similarity index 97%
rename from src/se/koc/hal/page/PCOverviewHttpPage.java
rename to src/se/hal/page/PCOverviewHttpPage.java
index de434d18..1c3165b3 100755
--- a/src/se/koc/hal/page/PCOverviewHttpPage.java
+++ b/src/se/hal/page/PCOverviewHttpPage.java
@@ -1,8 +1,8 @@
-package se.koc.hal.page;
+package se.hal.page;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalHttpPage;
-import se.koc.hal.util.TimeUtility;
+import se.hal.HalContext;
+import se.hal.intf.HalHttpPage;
+import se.hal.util.TimeUtility;
import zutil.db.DBConnection;
import zutil.db.SQLResultHandler;
import zutil.io.file.FileUtil;
diff --git a/src/se/koc/hal/plugin/localsensor/RPiImpulseCountSensor.java b/src/se/hal/plugin/localsensor/RPiImpulseCountSensor.java
similarity index 99%
rename from src/se/koc/hal/plugin/localsensor/RPiImpulseCountSensor.java
rename to src/se/hal/plugin/localsensor/RPiImpulseCountSensor.java
index 1993aa71..f688284d 100755
--- a/src/se/koc/hal/plugin/localsensor/RPiImpulseCountSensor.java
+++ b/src/se/hal/plugin/localsensor/RPiImpulseCountSensor.java
@@ -1,4 +1,4 @@
-package se.koc.hal.plugin.localsensor;
+package se.hal.plugin.localsensor;
import com.pi4j.io.gpio.*;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
diff --git a/src/se/koc/hal/plugin/tellstick/TellstickParser.java b/src/se/hal/plugin/tellstick/TellstickParser.java
similarity index 93%
rename from src/se/koc/hal/plugin/tellstick/TellstickParser.java
rename to src/se/hal/plugin/tellstick/TellstickParser.java
index a6ecb1a8..ba0edcfb 100755
--- a/src/se/koc/hal/plugin/tellstick/TellstickParser.java
+++ b/src/se/hal/plugin/tellstick/TellstickParser.java
@@ -1,100 +1,100 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.plugin.tellstick;
-
-import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
-import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
-import zutil.converters.Converter;
-import zutil.log.LogUtil;
-
-import java.util.HashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Created by Ziver on 2015-02-18.
- */
-public class TellstickParser {
- private static final Logger logger = LogUtil.getLogger();
- private static HashMap> protocolMap;
-
- static {
- registerProtocol(NexaSelfLearning.class);
- registerProtocol(Oregon0x1A2D.class);
- }
-
-
- public TellstickProtocol decode(String data) {
- if (data.startsWith("+W")) {
- data = data.substring(2);
- HashMap map = new HashMap();
- String[] parameters = data.split(";");
- for (String parameter : parameters) {
- String[] keyValue = parameter.split(":");
- map.put(keyValue[0], keyValue[1]);
- }
-
- Class extends TellstickProtocol> protClass =
- getProtocolClass(map.get("protocol"), map.get("model"));
- if (protClass != null) {
- try {
- TellstickProtocol protocol = protClass.newInstance();
- String binData = map.get("data");
-
- protocol.decode(Converter.hexToByte(binData));
- logger.finest("Decoded: " + protocol);
- return protocol;
- } catch (Exception e) {
- logger.log(Level.WARNING, null, e);
- }
- } else {
- logger.warning("Unknown protocol: " + data);
- }
- } else if (data.startsWith("+S") || data.startsWith("+T")) {
- // This is confirmation of send commands
- }else {
- logger.severe("Unknown prefix: " + data);
- }
-
- return null;
- }
-
-
-
- public static void registerProtocol(Class extends TellstickProtocol> protClass) {
- try {
- if (protocolMap == null)
- protocolMap = new HashMap>();
- TellstickProtocol tmp = protClass.newInstance();
- protocolMap.put(
- tmp.getProtocolName() + "-" + tmp.getModelName(),
- protClass);
- } catch (Exception e) {
- logger.log(Level.SEVERE, null, e);
- }
- }
-
- public static Class extends TellstickProtocol> getProtocolClass(String protocol, String model) {
- return protocolMap.get(protocol + "-" + model);
- }
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.plugin.tellstick;
+
+import se.hal.plugin.tellstick.protocols.NexaSelfLearning;
+import se.hal.plugin.tellstick.protocols.Oregon0x1A2D;
+import zutil.converters.Converter;
+import zutil.log.LogUtil;
+
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created by Ziver on 2015-02-18.
+ */
+public class TellstickParser {
+ private static final Logger logger = LogUtil.getLogger();
+ private static HashMap> protocolMap;
+
+ static {
+ registerProtocol(NexaSelfLearning.class);
+ registerProtocol(Oregon0x1A2D.class);
+ }
+
+
+ public TellstickProtocol decode(String data) {
+ if (data.startsWith("+W")) {
+ data = data.substring(2);
+ HashMap map = new HashMap();
+ String[] parameters = data.split(";");
+ for (String parameter : parameters) {
+ String[] keyValue = parameter.split(":");
+ map.put(keyValue[0], keyValue[1]);
+ }
+
+ Class extends TellstickProtocol> protClass =
+ getProtocolClass(map.get("protocol"), map.get("model"));
+ if (protClass != null) {
+ try {
+ TellstickProtocol protocol = protClass.newInstance();
+ String binData = map.get("data");
+
+ protocol.decode(Converter.hexToByte(binData));
+ logger.finest("Decoded: " + protocol);
+ return protocol;
+ } catch (Exception e) {
+ logger.log(Level.WARNING, null, e);
+ }
+ } else {
+ logger.warning("Unknown protocol: " + data);
+ }
+ } else if (data.startsWith("+S") || data.startsWith("+T")) {
+ // This is confirmation of send commands
+ }else {
+ logger.severe("Unknown prefix: " + data);
+ }
+
+ return null;
+ }
+
+
+
+ public static void registerProtocol(Class extends TellstickProtocol> protClass) {
+ try {
+ if (protocolMap == null)
+ protocolMap = new HashMap>();
+ TellstickProtocol tmp = protClass.newInstance();
+ protocolMap.put(
+ tmp.getProtocolName() + "-" + tmp.getModelName(),
+ protClass);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, null, e);
+ }
+ }
+
+ public static Class extends TellstickProtocol> getProtocolClass(String protocol, String model) {
+ return protocolMap.get(protocol + "-" + model);
+ }
+}
diff --git a/src/se/koc/hal/plugin/tellstick/TellstickProtocol.java b/src/se/hal/plugin/tellstick/TellstickProtocol.java
similarity index 91%
rename from src/se/koc/hal/plugin/tellstick/TellstickProtocol.java
rename to src/se/hal/plugin/tellstick/TellstickProtocol.java
index 4deb1e82..1880b30c 100755
--- a/src/se/koc/hal/plugin/tellstick/TellstickProtocol.java
+++ b/src/se/hal/plugin/tellstick/TellstickProtocol.java
@@ -1,68 +1,68 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.plugin.tellstick;
-
-import se.koc.hal.intf.HalEventController;
-import se.koc.hal.intf.HalSensorController;
-
-/**
- * Created by Ziver on 2015-02-18.
- */
-public abstract class TellstickProtocol {
-
- private String protocol;
- private String model;
- private long timestamp = -1;
-
-
- public TellstickProtocol(String protocol, String model){
- this.protocol = protocol;
- this.model = model;
- }
-
-
- public String getProtocolName(){
- return protocol;
- }
- public String getModelName(){
- return model;
- }
-
- public long getTimestamp() {
- return timestamp;
- }
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
-
-
- public Class extends HalEventController> getEventController() {
- return TellstickSerialComm.class;
- }
- public Class extends HalSensorController> getSensorController() {
- return TellstickSerialComm.class;
- }
-
- public abstract String encode();
- public abstract void decode(byte[] data);
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.plugin.tellstick;
+
+import se.hal.intf.HalEventController;
+import se.hal.intf.HalSensorController;
+
+/**
+ * Created by Ziver on 2015-02-18.
+ */
+public abstract class TellstickProtocol {
+
+ private String protocol;
+ private String model;
+ private long timestamp = -1;
+
+
+ public TellstickProtocol(String protocol, String model){
+ this.protocol = protocol;
+ this.model = model;
+ }
+
+
+ public String getProtocolName(){
+ return protocol;
+ }
+ public String getModelName(){
+ return model;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+
+ public Class extends HalEventController> getEventController() {
+ return TellstickSerialComm.class;
+ }
+ public Class extends HalSensorController> getSensorController() {
+ return TellstickSerialComm.class;
+ }
+
+ public abstract String encode();
+ public abstract void decode(byte[] data);
+}
diff --git a/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java b/src/se/hal/plugin/tellstick/TellstickSerialComm.java
similarity index 94%
rename from src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java
rename to src/se/hal/plugin/tellstick/TellstickSerialComm.java
index f294ddac..5545571d 100755
--- a/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java
+++ b/src/se/hal/plugin/tellstick/TellstickSerialComm.java
@@ -1,209 +1,207 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.plugin.tellstick;
-
-import com.fazecast.jSerialComm.SerialPort;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.*;
-import zutil.io.file.FileUtil;
-import zutil.log.InputStreamLogger;
-import zutil.log.LogUtil;
-import zutil.log.OutputStreamLogger;
-import zutil.struct.TimedHashSet;
-
-import java.io.*;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
-/**
- * This version of the TwoWaySerialComm example makes use of the
- * SerialPortEventListener to avoid polling.
- */
-public class TellstickSerialComm implements Runnable, HalSensorController, HalEventController {
- private static final long TRANSMISSION_UNIQUENESS_TTL = 300; // milliseconds
- private static final Logger logger = LogUtil.getLogger();
-
- private SerialPort serial;
- private InputStream in;
- private OutputStream out;
- private TimedHashSet set; // To check for retransmissions
-
- private TellstickParser parser;
- private HalSensorReportListener sensorListener;
- private HalEventReportListener eventListener;
-
- private int registeredObjects;
-
-
-
- public TellstickSerialComm() {
- set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
- parser = new TellstickParser();
- registeredObjects = 0;
- }
-
- @Override
- public void initialize() throws Exception {
- // Read properties
- String port = HalContext.getStringProperty("tellstick.com_port");
- if (port == null)
- port = "COM1"; // defaults
-
- connect(port);
- }
-
- public void connect(String portName) throws Exception {
- logger.info("Connecting to com port... ("+ portName +")");
- serial = SerialPort.getCommPort(portName);
- serial.setBaudRate(9600);
- if(!serial.openPort())
- throw new IOException("Could not open port: "+portName);
- serial.setComPortTimeouts(
- SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
-
- in = new InputStreamLogger(serial.getInputStream());
- out = new OutputStreamLogger(serial.getOutputStream());
-
- Executors.newSingleThreadExecutor().execute(this);
- }
-
- public void close() {
- if(serial != null) {
- try {
- serial.closePort();
- in.close();
- out.close();
- } catch (IOException e) {
- logger.log(Level.SEVERE, null, e);
- }
- }
- serial = null;
- in = null;
- out = null;
- }
-
-
- public void run() {
- try {
- String data;
-
- while (in != null && (data = readLine()) != null) {
- if ((data.startsWith("+S") || data.startsWith("+T"))) {
- synchronized (this) {
- this.notifyAll();
- }
- }
- else {
- if(!set.contains(data)) {
- TellstickProtocol protocol = parser.decode(data);
- if(protocol != null) {
- if (protocol.getTimestamp() < 0)
- protocol.setTimestamp(System.currentTimeMillis());
- set.add(data);
-
- if (sensorListener != null && protocol instanceof HalSensor)
- sensorListener.reportReceived((HalSensor) protocol);
- else if (eventListener != null && protocol instanceof HalEvent)
- eventListener.reportReceived((HalEvent) protocol);
- }
- }
- }
- }
- } catch (IOException e) {
- logger.log(Level.SEVERE, null, e);
- }
- }
-
- /**
- * 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
- public void send(HalEvent event) {
- if(event instanceof TellstickProtocol)
- write((TellstickProtocol) event);
- }
- public synchronized void write(TellstickProtocol prot) {
- write(prot.encode());
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.log(Level.SEVERE, null, e);
- }
- }
- public void write(String data) {
- try {
- for(int i=0; i= 0){
+ switch(c) {
+ case '\n':
+ case '\r':
+ if(str.length() > 0)
+ return str.toString();
+ break;
+ default:
+ str.append(c);
+ }
+ }
+ return str.toString();
+ }
+
+
+ @Override
+ public void send(HalEvent event) {
+ if(event instanceof TellstickProtocol)
+ write((TellstickProtocol) event);
+ }
+ public synchronized void write(TellstickProtocol prot) {
+ write(prot.encode());
+ try {
+ this.wait();
+ } catch (InterruptedException e) {
+ logger.log(Level.SEVERE, null, e);
+ }
+ }
+ public void write(String data) {
+ try {
+ for(int i=0; i= 0; --i) {
- m.append( (house & (1 << i)) == 0 ? "01" : "10" );
- }
- // Group
- m.append("01");
-
- // On or OFF
- if (enable)
- m.append("10");
- else
- m.append("01");
-
- // Unit
- for (int i = 3; i >= 0; --i) {
- m.append( (unit & (1 << i)) == 0 ? "01" : "10" );
- }
-
- // The number of data is odd add this to make it even
- m.append("0");
- //01011001101001011010100110010101010101101001011010 01 01 1001011010 0
-
- char code = 9; // b1001, startcode
- for (int i = 0; i < m.length(); ++i) {
- code <<= 4;
- if (m.charAt(i) == '1') {
- code |= 0x08; // b1000
- } else {
- code |= 0x0A; // b1010
- }
- if (i % 2 == 0) {
- enc.append(code);
- code = 0x00;
- }
- }
-
-
- enc.append("+");
- return enc.toString();
- }
-
- public void decode(byte[] data){
- // Data positions
- // house = 0xFFFFFFC0
- // group = 0x00000020
- // method = 0x00000010
- // unit = 0x0000000F
- // ----------------h------------ g m --u-
- // 0x2CE81990 - 00101100_11101000_00011001_10 0 1 0000 - ON
- // 0x2CE81980 - 00101100_11101000_00011001_10 0 0 0000 - OFF
-
- house = 0;
- house |= (data[3] & 0xFF) << 18;
- house |= (data[2] & 0xFF) << 10;
- house |= (data[1] & 0xFF) << 2;
- house |= (data[0] & 0xC0) >>> 6;
-
- group = data[0] & 0x20;
- group >>>= 5;
-
- enable = (data[0] & 0x10) != 0;
-
- unit = data[0] & 0x0F;
- unit++;
- }
-
-
- public int getHouse() {
- return house;
- }
- public void setHouse(int house) {
- this.house = house;
- }
- public int getGroup() {
- return group;
- }
- public void setGroup(int group) {
- this.group = group;
- }
- public int getUnit() {
- return unit;
- }
- public void setUnit(int unit) {
- this.unit = unit;
- }
-
- public boolean isOn() {
- return enable;
- }
- public void turnOn() {
- enable = true;
- }
- public void turnOff() {
- enable = false;
- }
-
-
-
- public String toString(){
- return "protocol:arctech;model:selflearning;" +
- "house:"+house+
- ";group:"+group+
- ";unit:"+unit+
- ";method:"+enable;
- }
-
- public boolean equals(Object obj){
- if(obj instanceof NexaSelfLearning)
- return ((NexaSelfLearning) obj).house == house &&
- ((NexaSelfLearning)obj).unit == unit;
- return false;
- }
-
-
- @Override
- public double getData() {
- return (enable ? 1 : 0);
- }
-
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.plugin.tellstick.protocols;
+
+import se.hal.plugin.tellstick.TellstickProtocol;
+import se.hal.struct.SwitchEvent;
+import zutil.ui.Configurator;
+
+/**
+ * Created by Ziver on 2015-02-18.
+ */
+public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
+
+ @Configurator.Configurable("House code")
+ private int house = 0;
+ @Configurator.Configurable("Group code")
+ private int group = 0;
+ @Configurator.Configurable("Unit code")
+ private int unit = 0;
+
+ private boolean enable = false;
+
+
+ public NexaSelfLearning() {
+ super("arctech", "selflearning");
+ }
+
+
+ public String encode(){
+ StringBuilder enc = new StringBuilder();
+ enc.append(new char[]{'T', 127, 255, 24, 1});
+
+ enc.append((char)132);
+
+ // House
+ StringBuilder m = new StringBuilder();
+ for (int i = 25; i >= 0; --i) {
+ m.append( (house & (1 << i)) == 0 ? "01" : "10" );
+ }
+ // Group
+ m.append("01");
+
+ // On or OFF
+ if (enable)
+ m.append("10");
+ else
+ m.append("01");
+
+ // Unit
+ for (int i = 3; i >= 0; --i) {
+ m.append( (unit & (1 << i)) == 0 ? "01" : "10" );
+ }
+
+ // The number of data is odd add this to make it even
+ m.append("0");
+ //01011001101001011010100110010101010101101001011010 01 01 1001011010 0
+
+ char code = 9; // b1001, startcode
+ for (int i = 0; i < m.length(); ++i) {
+ code <<= 4;
+ if (m.charAt(i) == '1') {
+ code |= 0x08; // b1000
+ } else {
+ code |= 0x0A; // b1010
+ }
+ if (i % 2 == 0) {
+ enc.append(code);
+ code = 0x00;
+ }
+ }
+
+
+ enc.append("+");
+ return enc.toString();
+ }
+
+ public void decode(byte[] data){
+ // Data positions
+ // house = 0xFFFFFFC0
+ // group = 0x00000020
+ // method = 0x00000010
+ // unit = 0x0000000F
+ // ----------------h------------ g m --u-
+ // 0x2CE81990 - 00101100_11101000_00011001_10 0 1 0000 - ON
+ // 0x2CE81980 - 00101100_11101000_00011001_10 0 0 0000 - OFF
+
+ house = 0;
+ house |= (data[3] & 0xFF) << 18;
+ house |= (data[2] & 0xFF) << 10;
+ house |= (data[1] & 0xFF) << 2;
+ house |= (data[0] & 0xC0) >>> 6;
+
+ group = data[0] & 0x20;
+ group >>>= 5;
+
+ enable = (data[0] & 0x10) != 0;
+
+ unit = data[0] & 0x0F;
+ unit++;
+ }
+
+
+ public int getHouse() {
+ return house;
+ }
+ public void setHouse(int house) {
+ this.house = house;
+ }
+ public int getGroup() {
+ return group;
+ }
+ public void setGroup(int group) {
+ this.group = group;
+ }
+ public int getUnit() {
+ return unit;
+ }
+ public void setUnit(int unit) {
+ this.unit = unit;
+ }
+
+ public boolean isOn() {
+ return enable;
+ }
+ public void turnOn() {
+ enable = true;
+ }
+ public void turnOff() {
+ enable = false;
+ }
+
+
+
+ public String toString(){
+ return "protocol:arctech;model:selflearning;" +
+ "house:"+house+
+ ";group:"+group+
+ ";unit:"+unit+
+ ";method:"+enable;
+ }
+
+ public boolean equals(Object obj){
+ if(obj instanceof NexaSelfLearning)
+ return ((NexaSelfLearning) obj).house == house &&
+ ((NexaSelfLearning)obj).unit == unit;
+ return false;
+ }
+
+
+ @Override
+ public double getData() {
+ return (enable ? 1 : 0);
+ }
+
+}
diff --git a/src/se/koc/hal/plugin/tellstick/protocols/Oregon0x1A2D.java b/src/se/hal/plugin/tellstick/protocols/Oregon0x1A2D.java
similarity index 88%
rename from src/se/koc/hal/plugin/tellstick/protocols/Oregon0x1A2D.java
rename to src/se/hal/plugin/tellstick/protocols/Oregon0x1A2D.java
index 790cebd2..ea0233f5 100755
--- a/src/se/koc/hal/plugin/tellstick/protocols/Oregon0x1A2D.java
+++ b/src/se/hal/plugin/tellstick/protocols/Oregon0x1A2D.java
@@ -1,11 +1,7 @@
-package se.koc.hal.plugin.tellstick.protocols;
+package se.hal.plugin.tellstick.protocols;
-import se.koc.hal.intf.HalSensor;
-import se.koc.hal.intf.HalSensorController;
-import se.koc.hal.plugin.tellstick.TellstickProtocol;
-import se.koc.hal.plugin.tellstick.TellstickSerialComm;
-import se.koc.hal.struct.PowerConsumptionSensor;
-import zutil.parser.DataNode;
+import se.hal.plugin.tellstick.TellstickProtocol;
+import se.hal.struct.PowerConsumptionSensor;
import zutil.ui.Configurator;
/**
diff --git a/src/se/koc/hal/struct/DimmerEvent.java b/src/se/hal/struct/DimmerEvent.java
similarity index 95%
rename from src/se/koc/hal/struct/DimmerEvent.java
rename to src/se/hal/struct/DimmerEvent.java
index b303730c..8881c41c 100755
--- a/src/se/koc/hal/struct/DimmerEvent.java
+++ b/src/se/hal/struct/DimmerEvent.java
@@ -20,9 +20,9 @@
* THE SOFTWARE.
*/
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.intf.HalEvent;
+import se.hal.intf.HalEvent;
/**
* Created by Ziver on 2015-05-07.
diff --git a/src/se/koc/hal/struct/Event.java b/src/se/hal/struct/Event.java
similarity index 93%
rename from src/se/koc/hal/struct/Event.java
rename to src/se/hal/struct/Event.java
index 841745e7..5c2fe7f5 100755
--- a/src/se/koc/hal/struct/Event.java
+++ b/src/se/hal/struct/Event.java
@@ -1,7 +1,7 @@
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.intf.HalEvent;
-import se.koc.hal.intf.HalEventController;
+import se.hal.intf.HalEvent;
+import se.hal.intf.HalEventController;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
import zutil.db.bean.DBBeanSQLResultHandler;
@@ -10,8 +10,6 @@ import zutil.io.StringOutputStream;
import zutil.log.LogUtil;
import zutil.parser.json.JSONObjectInputStream;
import zutil.parser.json.JSONObjectOutputStream;
-import zutil.parser.json.JSONParser;
-import zutil.parser.json.JSONWriter;
import java.io.IOException;
import java.sql.PreparedStatement;
diff --git a/src/se/koc/hal/struct/PowerConsumptionSensor.java b/src/se/hal/struct/PowerConsumptionSensor.java
similarity index 63%
rename from src/se/koc/hal/struct/PowerConsumptionSensor.java
rename to src/se/hal/struct/PowerConsumptionSensor.java
index 2b5bd19b..991d1af8 100755
--- a/src/se/koc/hal/struct/PowerConsumptionSensor.java
+++ b/src/se/hal/struct/PowerConsumptionSensor.java
@@ -1,6 +1,6 @@
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.intf.HalSensor;
+import se.hal.intf.HalSensor;
/**
* Created by Ziver on 2015-12-03.
diff --git a/src/se/koc/hal/struct/Sensor.java b/src/se/hal/struct/Sensor.java
similarity index 94%
rename from src/se/koc/hal/struct/Sensor.java
rename to src/se/hal/struct/Sensor.java
index 67a95490..942891cf 100755
--- a/src/se/koc/hal/struct/Sensor.java
+++ b/src/se/hal/struct/Sensor.java
@@ -1,8 +1,8 @@
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalSensor;
-import se.koc.hal.intf.HalSensorController;
+import se.hal.HalContext;
+import se.hal.intf.HalSensor;
+import se.hal.intf.HalSensorController;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
import zutil.db.bean.DBBeanSQLResultHandler;
@@ -10,13 +10,8 @@ import zutil.db.handler.SimpleSQLResult;
import zutil.io.StringInputStream;
import zutil.io.StringOutputStream;
import zutil.log.LogUtil;
-import zutil.parser.DataNode;
import zutil.parser.json.JSONObjectInputStream;
import zutil.parser.json.JSONObjectOutputStream;
-import zutil.parser.json.JSONParser;
-import zutil.parser.json.JSONWriter;
-import zutil.ui.Configurator;
-import zutil.ui.Configurator.ConfigurationParam;
import java.io.IOException;
import java.sql.PreparedStatement;
diff --git a/src/se/koc/hal/struct/SwitchEvent.java b/src/se/hal/struct/SwitchEvent.java
similarity index 87%
rename from src/se/koc/hal/struct/SwitchEvent.java
rename to src/se/hal/struct/SwitchEvent.java
index 31a709fa..1a0b214d 100755
--- a/src/se/koc/hal/struct/SwitchEvent.java
+++ b/src/se/hal/struct/SwitchEvent.java
@@ -20,11 +20,9 @@
* THE SOFTWARE.
*/
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.intf.HalEvent;
-import se.koc.hal.plugin.tellstick.TellstickSerialComm;
-import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
+import se.hal.intf.HalEvent;
/**
* Created by Ziver on 2015-05-07.
diff --git a/src/se/koc/hal/struct/TemperatureSensor.java b/src/se/hal/struct/TemperatureSensor.java
similarity index 72%
rename from src/se/koc/hal/struct/TemperatureSensor.java
rename to src/se/hal/struct/TemperatureSensor.java
index f33cbe50..352b50cd 100755
--- a/src/se/koc/hal/struct/TemperatureSensor.java
+++ b/src/se/hal/struct/TemperatureSensor.java
@@ -1,6 +1,6 @@
-package se.koc.hal.struct;
+package se.hal.struct;
-import se.koc.hal.intf.HalSensor;
+import se.hal.intf.HalSensor;
/**
* Created by Ziver on 2015-12-03.
diff --git a/src/se/koc/hal/struct/User.java b/src/se/hal/struct/User.java
similarity index 98%
rename from src/se/koc/hal/struct/User.java
rename to src/se/hal/struct/User.java
index fb34dd0b..9bc739a6 100755
--- a/src/se/koc/hal/struct/User.java
+++ b/src/se/hal/struct/User.java
@@ -1,4 +1,4 @@
-package se.koc.hal.struct;
+package se.hal.struct;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
diff --git a/src/se/koc/hal/stt/GoogleSTTClient.java b/src/se/hal/stt/GoogleSTTClient.java
similarity index 95%
rename from src/se/koc/hal/stt/GoogleSTTClient.java
rename to src/se/hal/stt/GoogleSTTClient.java
index aa692b25..db610a21 100755
--- a/src/se/koc/hal/stt/GoogleSTTClient.java
+++ b/src/se/hal/stt/GoogleSTTClient.java
@@ -1,123 +1,123 @@
-package se.koc.hal.stt;
-
-import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
-import com.darkprograms.speech.recognizer.FlacEncoder;
-import com.darkprograms.speech.recognizer.GSpeechDuplex;
-import com.darkprograms.speech.recognizer.GSpeechResponseListener;
-import com.darkprograms.speech.recognizer.GoogleResponse;
-import se.koc.hal.intf.HalSpeachToText;
-import zutil.io.file.FileUtil;
-
-import javax.sound.sampled.AudioFileFormat;
-import java.io.File;
-
-public class GoogleSTTClient implements HalSpeachToText, GSpeechResponseListener {
- private MicrophoneAnalyzer mic;
- private File audioFile;
- private File flacFile;
- private int ambientVolume;
- private GSpeechDuplex google;
- private String response;
-
- @Override
- public void initSTT() {
- try{
- this.mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
- this.audioFile = File.createTempFile("input", "wav");
- this.flacFile = File.createTempFile("input", "flac");
-
- this.google = new GSpeechDuplex("AIzaSyBGAQ29aMvts9MObj739_HYa-tvNeEI0X8");
- this.google.addResponseListener(this);
-
- /*System.out.println("Messuring ambient noise...");
- mic.captureAudioToFile(audioFile);
- Thread.sleep(300);
- ambientVolume = mic.getAudioVolume();
- Thread.sleep(300);
- mic.close();*/
- }catch(Exception e){
- e.printStackTrace();
- }
- }
-
- @Override
- public synchronized String listen() {
- try {
- String request = null;
- while(request == null){
-
- /*mic.captureAudioToFile(audioFile);
- try{Thread.sleep(2000);}catch(Exception e){}
- mic.close();*/
-
- FlacEncoder flacEncoder = new FlacEncoder();
- //flacEncoder.convertWaveToFlac(audioFile, flacFile);
- flacEncoder.convertWaveToFlac(FileUtil.find("edu/cmu/sphinx/demo/speakerid/test.wav"), flacFile);
-
- response = null;
- google.recognize(flacFile, 8000);
- this.wait();
-
- flacFile.delete();
- audioFile.delete();
- }
-
- }catch(Exception e){
- e.printStackTrace();
- }
- return response;
- }
-
-
- public String thresholdListen(){
- try{
- boolean speaking = false;
- while(!speaking){
- mic.captureAudioToFile(audioFile);
- System.out.print("_");
-
- final int THRESHOLD = 10; //YOUR THRESHOLD VALUE.
- mic.open();
-
- int speakingVolume = -2;
-
- do{
- int volume = mic.getAudioVolume();
- if(volume>ambientVolume+THRESHOLD){
- speakingVolume = volume;
- speaking = true;
- System.out.print(".");
- Thread.sleep(1000);
- }
- if(speaking && volume+THRESHOLDambientVolume+THRESHOLD){
+ speakingVolume = volume;
+ speaking = true;
+ System.out.print(".");
+ Thread.sleep(1000);
+ }
+ if(speaking && volume+THRESHOLD voices = marytts.getAvailableVoices();
- marytts.setVoice(voices.iterator().next());
- } catch (MaryConfigurationException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- @Override
- public void speak(String msg) {
- try {
- AudioInputStream audio = marytts.generateAudio(msg);
- AudioPlayer player = new AudioPlayer(audio);
- player.start();
- player.join();
-
- } catch (SynthesisException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.tts;
+
+import marytts.LocalMaryInterface;
+import marytts.MaryInterface;
+import marytts.exceptions.MaryConfigurationException;
+import marytts.exceptions.SynthesisException;
+import marytts.util.data.audio.AudioPlayer;
+import se.hal.intf.HalTextToSpeach;
+
+import javax.sound.sampled.AudioInputStream;
+import java.util.Set;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 14:36
+ */
+public class MaryLocalTTSClient implements HalTextToSpeach {
+ private MaryInterface marytts;
+
+
+ @Override
+ public void initTTS() {
+ try {
+ marytts = new LocalMaryInterface();
+ Set voices = marytts.getAvailableVoices();
+ marytts.setVoice(voices.iterator().next());
+ } catch (MaryConfigurationException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @Override
+ public void speak(String msg) {
+ try {
+ AudioInputStream audio = marytts.generateAudio(msg);
+ AudioPlayer player = new AudioPlayer(audio);
+ player.start();
+ player.join();
+
+ } catch (SynthesisException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/se/koc/hal/tts/MaryRemoteTTSClient.java b/src/se/hal/tts/MaryRemoteTTSClient.java
similarity index 94%
rename from src/se/koc/hal/tts/MaryRemoteTTSClient.java
rename to src/se/hal/tts/MaryRemoteTTSClient.java
index bf51d61f..a501d70a 100755
--- a/src/se/koc/hal/tts/MaryRemoteTTSClient.java
+++ b/src/se/hal/tts/MaryRemoteTTSClient.java
@@ -1,72 +1,72 @@
-/*
- * Copyright (c) 2013 ezivkoc
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.tts;
-
-import marytts.MaryInterface;
-import marytts.client.RemoteMaryInterface;
-import marytts.exceptions.SynthesisException;
-import marytts.util.data.audio.AudioPlayer;
-import se.koc.hal.intf.HalTextToSpeach;
-
-import javax.sound.sampled.AudioInputStream;
-import java.io.IOException;
-import java.util.Set;
-
-/**
- * Created with IntelliJ IDEA.
- * User: ezivkoc
- * Date: 2013-12-17
- * Time: 14:36
- */
-public class MaryRemoteTTSClient implements HalTextToSpeach {
- private MaryInterface marytts;
-
-
- @Override
- public void initTTS() {
- try {
- marytts = new RemoteMaryInterface("127.0.0.1", 59125);
-
- Set voices = marytts.getAvailableVoices();
- marytts.setVoice(voices.iterator().next());
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- @Override
- public synchronized void speak(String msg) {
- try {
- AudioInputStream audio = marytts.generateAudio(msg);
- AudioPlayer player = new AudioPlayer(audio);
- player.start();
- player.join();
-
- } catch (SynthesisException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * Copyright (c) 2013 ezivkoc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.tts;
+
+import marytts.MaryInterface;
+import marytts.client.RemoteMaryInterface;
+import marytts.exceptions.SynthesisException;
+import marytts.util.data.audio.AudioPlayer;
+import se.hal.intf.HalTextToSpeach;
+
+import javax.sound.sampled.AudioInputStream;
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 14:36
+ */
+public class MaryRemoteTTSClient implements HalTextToSpeach {
+ private MaryInterface marytts;
+
+
+ @Override
+ public void initTTS() {
+ try {
+ marytts = new RemoteMaryInterface("127.0.0.1", 59125);
+
+ Set voices = marytts.getAvailableVoices();
+ marytts.setVoice(voices.iterator().next());
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @Override
+ public synchronized void speak(String msg) {
+ try {
+ AudioInputStream audio = marytts.generateAudio(msg);
+ AudioPlayer player = new AudioPlayer(audio);
+ player.start();
+ player.join();
+
+ } catch (SynthesisException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/se/koc/hal/util/TimeUtility.java b/src/se/hal/util/TimeUtility.java
similarity index 99%
rename from src/se/koc/hal/util/TimeUtility.java
rename to src/se/hal/util/TimeUtility.java
index 66a1cb14..7a7d62d8 100755
--- a/src/se/koc/hal/util/TimeUtility.java
+++ b/src/se/hal/util/TimeUtility.java
@@ -1,4 +1,4 @@
-package se.koc.hal.util;
+package se.hal.util;
import java.util.Calendar;
diff --git a/test/se/koc/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java b/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java
similarity index 92%
rename from test/se/koc/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java
rename to test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java
index 450908f2..a6e3a59d 100755
--- a/test/se/koc/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java
+++ b/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java
@@ -1,6 +1,6 @@
-package se.koc.hal.plugin.tellstick;
+package se.hal.plugin.tellstick;
-import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
+import se.hal.plugin.tellstick.protocols.NexaSelfLearning;
/**
* Created by Ziver on 2015-11-19.
diff --git a/test/se/koc/hal/plugin/tellstick/TelstickSerialCommTest.java b/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java
similarity index 88%
rename from test/se/koc/hal/plugin/tellstick/TelstickSerialCommTest.java
rename to test/se/hal/plugin/tellstick/TelstickSerialCommTest.java
index 770415be..88011f16 100755
--- a/test/se/koc/hal/plugin/tellstick/TelstickSerialCommTest.java
+++ b/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java
@@ -1,10 +1,9 @@
-package se.koc.hal.plugin.tellstick;
+package se.hal.plugin.tellstick;
-import se.koc.hal.HalContext;
-import se.koc.hal.intf.HalSensor;
-import se.koc.hal.intf.HalSensorController;
-import se.koc.hal.intf.HalSensorReportListener;
-import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
+import se.hal.HalContext;
+import se.hal.intf.HalSensor;
+import se.hal.intf.HalSensorReportListener;
+import se.hal.plugin.tellstick.protocols.Oregon0x1A2D;
import zutil.db.DBConnection;
import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil;
diff --git a/test/se/koc/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java
similarity index 95%
rename from test/se/koc/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java
rename to test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java
index e128f56c..d55977ab 100755
--- a/test/se/koc/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java
+++ b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java
@@ -1,67 +1,67 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.plugin.tellstick.protocols;
-
-import zutil.converters.Converter;
-
-import static org.junit.Assert.*;
-
-public class NexaSelfLearningTest {
-
- @org.junit.Test
- public void testEncode() throws Exception {
- NexaSelfLearning nexa = new NexaSelfLearning();
- nexa.setHouse(11772006);
- nexa.setUnit(3);
- nexa.turnOn();
-
- assertArrayEquals(
- new char[]{
- 84, 127, 255, 24, 1, 132, 154, 138, 136, 170,
- 136, 168, 170, 138, 136, 168, 168, 170, 136, 170,
- 138, 138, 138, 138, 138, 136, 168, 170, 138, 136,
- 168, 170, 138, 136, 170, 138, 136, 168, 170, 43},
- nexa.encode().toCharArray()
- );
- }
-
-
- @org.junit.Test
- public void decode_ON() throws Exception {
- NexaSelfLearning nexa = new NexaSelfLearning();
- nexa.decode(Converter.hexToByte("0x2CE81990"));
-
- assertEquals("House Code", 11772006, nexa.getHouse());
- assertEquals("Unit Code", 1, nexa.getUnit());
- assertTrue("Enabled", nexa.isOn());
- }
- @org.junit.Test
- public void decode_OFF() throws Exception {
- NexaSelfLearning nexa = new NexaSelfLearning();
- nexa.decode(Converter.hexToByte("0x2CE81980"));
-
- assertEquals("House Code", 11772006, nexa.getHouse());
- assertEquals("Unit Code", 1, nexa.getUnit());
- assertFalse("Enabled", nexa.isOn());
- }
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.plugin.tellstick.protocols;
+
+import zutil.converters.Converter;
+
+import static org.junit.Assert.*;
+
+public class NexaSelfLearningTest {
+
+ @org.junit.Test
+ public void testEncode() throws Exception {
+ NexaSelfLearning nexa = new NexaSelfLearning();
+ nexa.setHouse(11772006);
+ nexa.setUnit(3);
+ nexa.turnOn();
+
+ assertArrayEquals(
+ new char[]{
+ 84, 127, 255, 24, 1, 132, 154, 138, 136, 170,
+ 136, 168, 170, 138, 136, 168, 168, 170, 136, 170,
+ 138, 138, 138, 138, 138, 136, 168, 170, 138, 136,
+ 168, 170, 138, 136, 170, 138, 136, 168, 170, 43},
+ nexa.encode().toCharArray()
+ );
+ }
+
+
+ @org.junit.Test
+ public void decode_ON() throws Exception {
+ NexaSelfLearning nexa = new NexaSelfLearning();
+ nexa.decode(Converter.hexToByte("0x2CE81990"));
+
+ assertEquals("House Code", 11772006, nexa.getHouse());
+ assertEquals("Unit Code", 1, nexa.getUnit());
+ assertTrue("Enabled", nexa.isOn());
+ }
+ @org.junit.Test
+ public void decode_OFF() throws Exception {
+ NexaSelfLearning nexa = new NexaSelfLearning();
+ nexa.decode(Converter.hexToByte("0x2CE81980"));
+
+ assertEquals("House Code", 11772006, nexa.getHouse());
+ assertEquals("Unit Code", 1, nexa.getUnit());
+ assertFalse("Enabled", nexa.isOn());
+ }
}
\ No newline at end of file
diff --git a/test/se/koc/hal/test/GoogleTTSTest.java b/test/se/hal/test/GoogleTTSTest.java
similarity index 97%
rename from test/se/koc/hal/test/GoogleTTSTest.java
rename to test/se/hal/test/GoogleTTSTest.java
index f4413396..f84e9740 100755
--- a/test/se/koc/hal/test/GoogleTTSTest.java
+++ b/test/se/hal/test/GoogleTTSTest.java
@@ -1,83 +1,83 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.test;
-
-import zutil.io.DynamicByteArrayStream;
-
-import javax.sound.sampled.*;
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Created with IntelliJ IDEA.
- * User: ezivkoc
- * Date: 2013-12-17
- * Time: 11:24
- */
-public class GoogleTTSTest {
- public static void main(String[] args){
- try {
-/* URL url = new URL("http://translate.google.com/translate_tts?q=I+love+techcrunch");
- InputStream in = url.openStream();
- byte[] data = getContent(in);
- in.close();
-*/
- Clip push = AudioSystem.getClip();
-
- URL url = new URL("http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20World&tl=en-us");
- URLConnection con = url.openConnection();
- con.setRequestProperty("Cookie", "JSESSIONID=UX61oaN8vRhLE5pYXAjTWg; _ga=GA1.3.53937642.1385651778; HSID=AINSMauAFJWBs84WQ; APISID=RgytV3HJnm0dWjVr/AtidsIB_LJQzDmBMc; NID=67=R0kMLqIXXiOkrU8jlk4vgqLUiWUYUZRvxjf1Un0DQbQxGKt9pXXzDv-v0zSCSqLi_YNzcZujTDDr9r_KGsiPhEMfk-oKQSKvHe-DVVuwHZb2UZraJKCBAb6mPJO6AxBExoXHzU2pHd-DI1yIMxuLyVJA9RxhM_2kB4h7U0w9WiWqRNN7sU5DPVeLpF_ScW1VH9_igIR2ACK0WHvmoZXBjXDDrnUiVJt9DjkbMpHxU1o_1PnuUXi5FmfJLjrQspI; SID=DQAAANgAAADcaXZk9dA01UfdydUwIH32OGbA0k6mhbV2GSsiqcGYTUhNqLn_Z9TAlUsizBVoG-3g-ghXzpev46P--fqcR4UACZ2iVawFbfUB44B2hBmQQsFbyjGop1smPLu3cJORBLUKQ4PiZQb23GtXYg28prWlK3IFj8Wc3AHY5yoIpnssRY24k9DybwSSVt2Ww7c4ySzfw4uXxwtbSDTy0q8lmdAorjT4R6DCJwhaCGV4ysexY-vJaQE2kiRe3fPY2z9jQ6Mi9z_XjGRamLTI_AvJj-_XdQIfv0ZSo7JiEEjTUMb10Q; PREF=ID=8bf4d3a7414e8137:U=4ebb392cf34740cf:LD=sv:CR=2:TM=1368543367:LM=1387278509:GM=1:SG=1:S=fpteokIgX46FW8tp");
- con.connect();
-
-
- AudioInputStream audioPush = AudioSystem.getAudioInputStream(con.getInputStream());
-
- push.open(audioPush);
- push.start();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (UnsupportedAudioFileException e) {
- e.printStackTrace();
- } catch (LineUnavailableException e) {
- e.printStackTrace();
- }
- }
-
- public static byte[] getContent(InputStream stream) throws IOException{
- BufferedInputStream in = new BufferedInputStream(stream);
- byte[] tmp = new byte[256];
- int len;
- DynamicByteArrayStream buff = new DynamicByteArrayStream();
-
- while((len=in.read(tmp)) != -1){
- buff.append(tmp, 0, len);
- }
- return buff.getBytes();
- }
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.test;
+
+import zutil.io.DynamicByteArrayStream;
+
+import javax.sound.sampled.*;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 11:24
+ */
+public class GoogleTTSTest {
+ public static void main(String[] args){
+ try {
+/* URL url = new URL("http://translate.google.com/translate_tts?q=I+love+techcrunch");
+ InputStream in = url.openStream();
+ byte[] data = getContent(in);
+ in.close();
+*/
+ Clip push = AudioSystem.getClip();
+
+ URL url = new URL("http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20World&tl=en-us");
+ URLConnection con = url.openConnection();
+ con.setRequestProperty("Cookie", "JSESSIONID=UX61oaN8vRhLE5pYXAjTWg; _ga=GA1.3.53937642.1385651778; HSID=AINSMauAFJWBs84WQ; APISID=RgytV3HJnm0dWjVr/AtidsIB_LJQzDmBMc; NID=67=R0kMLqIXXiOkrU8jlk4vgqLUiWUYUZRvxjf1Un0DQbQxGKt9pXXzDv-v0zSCSqLi_YNzcZujTDDr9r_KGsiPhEMfk-oKQSKvHe-DVVuwHZb2UZraJKCBAb6mPJO6AxBExoXHzU2pHd-DI1yIMxuLyVJA9RxhM_2kB4h7U0w9WiWqRNN7sU5DPVeLpF_ScW1VH9_igIR2ACK0WHvmoZXBjXDDrnUiVJt9DjkbMpHxU1o_1PnuUXi5FmfJLjrQspI; SID=DQAAANgAAADcaXZk9dA01UfdydUwIH32OGbA0k6mhbV2GSsiqcGYTUhNqLn_Z9TAlUsizBVoG-3g-ghXzpev46P--fqcR4UACZ2iVawFbfUB44B2hBmQQsFbyjGop1smPLu3cJORBLUKQ4PiZQb23GtXYg28prWlK3IFj8Wc3AHY5yoIpnssRY24k9DybwSSVt2Ww7c4ySzfw4uXxwtbSDTy0q8lmdAorjT4R6DCJwhaCGV4ysexY-vJaQE2kiRe3fPY2z9jQ6Mi9z_XjGRamLTI_AvJj-_XdQIfv0ZSo7JiEEjTUMb10Q; PREF=ID=8bf4d3a7414e8137:U=4ebb392cf34740cf:LD=sv:CR=2:TM=1368543367:LM=1387278509:GM=1:SG=1:S=fpteokIgX46FW8tp");
+ con.connect();
+
+
+ AudioInputStream audioPush = AudioSystem.getAudioInputStream(con.getInputStream());
+
+ push.open(audioPush);
+ push.start();
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (UnsupportedAudioFileException e) {
+ e.printStackTrace();
+ } catch (LineUnavailableException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static byte[] getContent(InputStream stream) throws IOException{
+ BufferedInputStream in = new BufferedInputStream(stream);
+ byte[] tmp = new byte[256];
+ int len;
+ DynamicByteArrayStream buff = new DynamicByteArrayStream();
+
+ while((len=in.read(tmp)) != -1){
+ buff.append(tmp, 0, len);
+ }
+ return buff.getBytes();
+ }
+}
diff --git a/test/se/koc/hal/test/JarvisRecognizerTest.java b/test/se/hal/test/JarvisRecognizerTest.java
similarity index 96%
rename from test/se/koc/hal/test/JarvisRecognizerTest.java
rename to test/se/hal/test/JarvisRecognizerTest.java
index 56aa1cc9..229cdc63 100755
--- a/test/se/koc/hal/test/JarvisRecognizerTest.java
+++ b/test/se/hal/test/JarvisRecognizerTest.java
@@ -1,198 +1,198 @@
-/*
- * Copyright (c) 2015 Ziver
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package se.koc.hal.test;
-
-import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
-import com.darkprograms.speech.recognizer.FlacEncoder;
-import com.darkprograms.speech.recognizer.GoogleResponse;
-
-import javax.sound.sampled.AudioFileFormat;
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-public class JarvisRecognizerTest {
-
- public static void main(String[] args){
- try {
- new JarvisRecognizerTest();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public JarvisRecognizerTest() throws Exception{
- MicrophoneAnalyzer mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
-
- File audioFile = new File("bin/tmp.wav");
-
- boolean speaking = false;
- while(!speaking){
- mic.captureAudioToFile(audioFile);
-
- final int THRESHOLD = 10;//YOUR THRESHOLD VALUE.
- mic.open();
- int ambientVolume = mic.getAudioVolume();//
- int speakingVolume = -2;
-
- do{
- int volume = mic.getAudioVolume();
- System.out.println(volume);
- if(volume>ambientVolume+THRESHOLD){
- speakingVolume = volume;
- speaking = true;
- Thread.sleep(1000);
- System.out.println("SPEAKING");
- }
- if(speaking && volume+THRESHOLDambientVolume+THRESHOLD){
+ speakingVolume = volume;
+ speaking = true;
+ Thread.sleep(1000);
+ System.out.println("SPEAKING");
+ }
+ if(speaking && volume+THRESHOLD voices = marytts.getAvailableVoices();
- marytts.setVoice(voices.iterator().next());
- AudioInputStream audio = marytts.generateAudio("Hello world.");
- AudioPlayer player = new AudioPlayer(audio);
- player.start();
- player.join();
- System.exit(0);
- }
-}
+/*
+ * Copyright (c) 2015 Ziver
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package se.hal.test;
+
+import marytts.MaryInterface;
+import marytts.client.RemoteMaryInterface;
+import marytts.util.data.audio.AudioPlayer;
+
+import javax.sound.sampled.AudioInputStream;
+import java.util.Set;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ezivkoc
+ * Date: 2013-12-17
+ * Time: 12:39
+ */
+public class MaryTTS {
+ public static void main(String[] args) throws Exception {
+ MaryInterface marytts = new RemoteMaryInterface("127.0.0.1", 59125);
+
+ Set voices = marytts.getAvailableVoices();
+ marytts.setVoice(voices.iterator().next());
+ AudioInputStream audio = marytts.generateAudio("Hello world.");
+ AudioPlayer player = new AudioPlayer(audio);
+ player.start();
+ player.join();
+ System.exit(0);
+ }
+}
diff --git a/test/se/koc/hal/test/TranscriberDemo.java b/test/se/hal/test/TranscriberDemo.java
similarity index 99%
rename from test/se/koc/hal/test/TranscriberDemo.java
rename to test/se/hal/test/TranscriberDemo.java
index 6a06a86a..96d1f928 100755
--- a/test/se/koc/hal/test/TranscriberDemo.java
+++ b/test/se/hal/test/TranscriberDemo.java
@@ -20,7 +20,7 @@
* THE SOFTWARE.
*/
-package se.koc.hal.test;
+package se.hal.test;
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
import edu.cmu.sphinx.api.Configuration;
diff --git a/test/se/koc/hal/util/TimeUtilityTest.java b/test/se/hal/util/TimeUtilityTest.java
similarity index 99%
rename from test/se/koc/hal/util/TimeUtilityTest.java
rename to test/se/hal/util/TimeUtilityTest.java
index efd55b42..13939fa4 100755
--- a/test/se/koc/hal/util/TimeUtilityTest.java
+++ b/test/se/hal/util/TimeUtilityTest.java
@@ -1,4 +1,4 @@
-package se.koc.hal.util;
+package se.hal.util;
import org.junit.Before;
import org.junit.Test;