diff --git a/.classpath b/.classpath index f04bd82a..d213a787 100644 --- a/.classpath +++ b/.classpath @@ -23,6 +23,7 @@ + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/build.xml b/build.xml new file mode 100644 index 00000000..b70ce87f --- /dev/null +++ b/build.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/junit-4.12.jar b/lib/junit-4.12.jar new file mode 100644 index 00000000..3a7fc266 Binary files /dev/null and b/lib/junit-4.12.jar differ diff --git a/lib/sqlite-jdbc-3.7.2.jar.REMOVED.git-id b/lib/sqlite-jdbc-3.7.2.jar.REMOVED.git-id new file mode 100644 index 00000000..76e5d285 --- /dev/null +++ b/lib/sqlite-jdbc-3.7.2.jar.REMOVED.git-id @@ -0,0 +1 @@ +b0bec7b000d369a8f3dcaa9c6cd0b3ce87aed454 \ No newline at end of file diff --git a/src/se/koc/hal/plugin/localsensor/ImpulseTracker.java b/src/se/koc/hal/plugin/localsensor/ImpulseTracker.java index 56a2fd71..722ad1ca 100644 --- a/src/se/koc/hal/plugin/localsensor/ImpulseTracker.java +++ b/src/se/koc/hal/plugin/localsensor/ImpulseTracker.java @@ -1,8 +1,12 @@ package se.koc.hal.plugin.localsensor; -import java.io.IOException; +import java.sql.SQLException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.logging.Logger; + +import zutil.db.DBConnection; +import zutil.log.LogUtil; import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; @@ -14,17 +18,19 @@ import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; import com.pi4j.io.gpio.event.GpioPinListenerDigital; public class ImpulseTracker implements Runnable { - + private static final Logger logger = LogUtil.getLogger(); + private static final int IMPULSE_REPORT_TIMEOUT = 60000; //one minute private long nanoSecondsSleep = IMPULSE_REPORT_TIMEOUT * 1000000L; private Integer impulseCount = 0; private ExecutorService executorPool; + private final DBConnection db; - public static void main(String args[]) throws InterruptedException, IOException { + public static void main(String args[]) throws Exception { new ImpulseTracker(); } - public ImpulseTracker() throws InterruptedException, IOException{ + public ImpulseTracker() throws Exception{ // create gpio controller final GpioController gpio = GpioFactory.getInstance(); @@ -48,6 +54,9 @@ public class ImpulseTracker implements Runnable { this.executorPool = Executors.newCachedThreadPool(); + logger.info("Connecting to db..."); + db = new DBConnection(DBConnection.DBMS.SQLite, "hal.db"); + //start a daemon thread to save the impulse count every minute Thread thread = new Thread(this); thread.setDaemon(true); @@ -92,15 +101,13 @@ public class ImpulseTracker implements Runnable { executorPool.execute(new Runnable(){ @Override public void run() { - //this.listener. + try { + db.exec("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUE("+timestamp_end+", "+2+", "+data+")"); + } catch (SQLException e) { + e.printStackTrace(); + } } }); } - /* - public void setListener(Object listener){ - this.listener = listener; - } - */ - }