powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. d7254cf34cea


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. d7254cf34cea36e0553c2f63da2a29a1d12f431a
Date: Sat, 22 Dec 2018 16:49:27 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  d7254cf34cea36e0553c2f63da2a29a1d12f431a (commit)
      from  56490f832d5a50916a85fa80784f0b020efd5a44 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=d7254cf34cea36e0553c2f63da2a29a1d12f431a


commit d7254cf34cea36e0553c2f63da2a29a1d12f431a
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 14:49:21 2018 -0700

    Add scale (C or F) to temperature_t. Don't write to DB here.

diff --git a/devices/ownet.cc b/devices/ownet.cc
index eb21c1e..ad3b9d9 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -27,6 +27,9 @@
 
 extern LogFile dbglogfile;
 
+//const char DEFAULT_ARGV[] = "--fake 28 --fake 10";
+const char DEFAULT_ARGV[] = "-s 192.168.0.50:4304";
+
 Ownet::Ownet(const std::string &host)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
@@ -37,8 +40,11 @@ Ownet::Ownet(const std::string &host)
 
     //OW_init("/dev/ttyS0");
     int count = 5;
+    std::string hostname = "-s " + host;
+    const char *argv = hostname.c_str();
+
     while (count-- > 0) {
-        if (OW_init("192.168.0.50:4304") < 0) {
+        if (OW_init(argv) < 0) {
             dbglogfile << "WARNING: Couldn't connect to owserver!" << 
std::endl;
             //return;
         } else {
@@ -51,7 +57,7 @@ Ownet::Ownet(const std::string &host)
     OW_set_error_print("2");
     // (0=default, 1=err_connect, 2=err_call, 3=err_data, 4=err_detail,
     // 5=err_debug, 6=err_beyond)
-    OW_set_error_level("4");
+    OW_set_error_level("0");
     OW_get("/", &buf, &s);
     // buf looks like:
     // 
10.67C6697351FF/,05.4AEC29CDBAAB/,bus.0/,uncached/,settings/,system/,statistics/,structure/,simultaneous/,alarm/
@@ -61,6 +67,8 @@ Ownet::Ownet(const std::string &host)
     // return;
     //}
 
+    OW_put("/settings/units/temperature_scale", &_scale, 1);
+
     std::vector<std::string> results;
     if (buf != 0) {
         boost::split(results, buf, boost::is_any_of(","));
@@ -71,13 +79,6 @@ Ownet::Ownet(const std::string &host)
         }
     }
 
-#ifdef HAVE_LIBPQ
-    if (!pdb.openDB()) {
-        dbglogfile << "ERROR: Couldn't open database!" << std::endl;
-        exit(1);
-    }
-#endif
-
     int i = 0;
     std::vector<std::string>::iterator it;
     for(it = results.begin(); it != results.end(); it++,i++ ) {
@@ -91,25 +92,6 @@ Ownet::Ownet(const std::string &host)
         std::string dev = *it + "temperature";
         if (OW_present(dev.c_str()) == 0) {
             dbglogfile << "Temperature sensor found: " << *it << std::endl;
-            temperature_t *temp = new temperature_t[1];
-            memset(temp, 0, sizeof(temperature_t));
-            temp->temp = std::stof(getValue(*it, "temperature"));
-            temp->lowtemp = std::stof(getValue(*it, "templow"));
-            temp->hightemp = std::stof(getValue(*it, "temphigh"));
-            _temperatures[*it] = temp;
-
-            std::string stamp;
-#ifdef HAVE_LIBPQ
-            stamp = pdb.gettime(stamp);
-            std::string query = data->family + ',';
-            query += "\'" + data->id;
-            query += "\', \'" + data->type;
-            query += "\', \'" + stamp;
-            query += "\', " + std::to_string(temp->temp);
-            query += ", " + std::to_string(temp->lowtemp);
-            query +=  ", " + std::to_string(temp->hightemp);
-            pdb.queryInsert(query);
-#endif
         } else {
             dbglogfile << "Temperature sensor not found!" << std::endl;
         }
@@ -129,12 +111,12 @@ void Ownet::dump(void)
         std::cout << "\ttype: " << sit->second->type << std::endl;
         std::cout << "\tid: " << sit->second->id << std::endl;
     }
-    std::map<std::string, temperature_t *>::iterator tit;
-    for (tit = _temperatures.begin(); tit != _temperatures.end(); tit++) {
-        std::cout << "\tCurrent temperature: " << tit->second->temp << 
std::endl;
-        std::cout << "\tLow temperture: " << tit->second->lowtemp << std::endl;
-        std::cout << "\tHigh Temperature: " << tit->second->hightemp << 
std::endl;
-    }
+    // std::map<std::string, temperature_t *>::iterator tit;
+    // for (tit = _temperatures.begin(); tit != _temperatures.end(); tit++) {
+    //     std::cout << "\tCurrent temperature: " << tit->second->temp << 
std::endl;
+    //     std::cout << "\tLow temperture: " << tit->second->lowtemp << 
std::endl;
+    //     std::cout << "\tHigh Temperature: " << tit->second->hightemp << 
std::endl;
+    // }
 }
 
 // local Variables:
diff --git a/devices/ownet.h b/devices/ownet.h
index b3d0439..4d19b8c 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -31,6 +31,7 @@
 #include <log.h>
 #include <owcapi.h>
 #include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
 #include "database.h"
 
 extern LogFile dbglogfile;
@@ -43,9 +44,13 @@ struct ownet {
 } typedef ownet_t;
 
 struct temperature {
+    std::string family;
+    std::string id;
+    std::string type;
     float temp;
     float lowtemp;
     float hightemp;
+    char scale;
 } typedef temperature_t;
 
 class Ownet {
@@ -53,19 +58,19 @@ private:
     enum family_t {CONTROL = 05, THERMOMETER = 10, THERMOMETER2 = 28};
     std::map<std::string, ownet_t *> _sensors;
     bool _owserver = false;
-    std::map<std::string, temperature_t *> _temperatures;
+    //std::map<std::string, temperature_t *> _temperatures;
     std::mutex _mutex;
-    int poll_sleep = 2;
-#ifdef HAVE_LIBPQ
-    Database pdb;
-#endif
+    int poll_sleep = 60;
+    char _scale = 'F';
 public:
     Ownet(void);
     Ownet(const std::string &host);
     ~Ownet(void) {
         OW_finish();
     };
-    //
+
+    char setScale(char scale) { OW_put("/settings/units/temperature_scale", 
&_scale, 1); };
+
     // Thread have a polling frequency to avoid eating up all the cpu cycles
     // by polling to quickly.
     int getPollSleep(void) {
@@ -120,39 +125,31 @@ public:
     }
 
     // get all the temperature fields for a device.
-    temperature_t *getTemperature(const std::string &device) {
+    boost::shared_ptr<temperature_t> getTemperature(const std::string &device) 
{
         // DEBUGLOG_REPORT_FUNCTION;
 
         std::string family = getValue(device, "family");
         std::string id = getValue(device, "id");
         std::string type = getValue(device, "type");
 
-        temperature_t *temp = 0;
         if (family == "10" | family == "28") {
             // dbglogfile << device << " is a thermometer" << std::endl;
-            temp = new temperature_t[1];
+            boost::shared_ptr<temperature_t> temp(new temperature_t);
+            temp->family = getValue(device, "family");
+            temp->id = getValue(device, "id");
+            temp->type = getValue(device, "type");
             temp->temp = std::stof(getValue(device, "temperature"));
             temp->lowtemp =std::stof(getValue(device, "templow"));
             temp->hightemp = std::stof(getValue(device, "temphigh"));
-            // Add data to the database
-            std::string stamp;
-#ifdef HAVE_LIBPQ
-            stamp = pdb.gettime(stamp);
-            std::string query = family + ',';
-            query += "\'" + id;
-            query += "\', \'" + type;
-            query += "\', \'" + stamp;
-            query += "\', " + std::to_string(temp->temp);
-            query += ", " + std::to_string(temp->lowtemp);
-            query +=  ", " + std::to_string(temp->hightemp);
-            pdb.queryInsert(query);
-#endif
-
-            std::lock_guard<std::mutex> guard(_mutex);
-            _temperatures[device] = temp;
+            char *buffer;
+            size_t blen;
+            OW_get("/settings/units/temperature_scale", &buffer, &blen);
+            temp->scale = buffer[0];
+            return temp;
         } else {
             dbglogfile << device << " is not a thermometer" << std::endl;
         }
+        boost::shared_ptr<temperature_t> temp;
         return temp;
     }
 

-----------------------------------------------------------------------

Summary of changes:
 devices/ownet.cc | 50 ++++++++++++++++----------------------------------
 devices/ownet.h  | 47 ++++++++++++++++++++++-------------------------
 2 files changed, 38 insertions(+), 59 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]