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. 31f9008da3e3


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 31f9008da3e3309663edf34e743784174c6cafda
Date: Sat, 5 Jan 2019 13:03:12 -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  31f9008da3e3309663edf34e743784174c6cafda (commit)
       via  d325783b9bec3332c2f980ba845d1e9184f301fe (commit)
       via  e4c9c80adfabfd7de08e8fd282bdd662d8ae6f12 (commit)
       via  56aa3669ebfb19cdfd64e27096e97498c91ab97d (commit)
       via  d23109485b87c63916b34c35732bb0e7131aa339 (commit)
       via  cc511e9b288b7df84949f4b50405dc97f0e4b5bc (commit)
       via  13671b61696af2683ad55720c7df2e549bebfedf (commit)
       via  4944c5ee49b7abe04c232eb3603c70aa3a93d24f (commit)
      from  a9b7824126cc6247456425859053fc6961cacd23 (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=31f9008da3e3309663edf34e743784174c6cafda


commit 31f9008da3e3309663edf34e743784174c6cafda
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 11:03:01 2019 -0700

    Update to handle struct changes

diff --git a/devices/onewire.cc b/devices/onewire.cc
index 150d10d..1eb5cd8 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -43,7 +43,6 @@ Onewire::Onewire(void)
     // Initialize the table of family types
     initTable(_family);
 
-#if 0
     boost::filesystem::path p(_rootdir);
     try {
         if (boost::filesystem::exists(p) & boost::filesystem::is_directory(p)) 
{
@@ -53,8 +52,13 @@ Onewire::Onewire(void)
                     owire->device = x.path().string();
                     std::string result;
                     owire->family = getValue(owire->device, "family", result);
-                    owire->type = getValue(owire->device, "type", result);
-                    owire->id = getValue(owire->device, "id", result);
+                    if (owire->family.empty()) { // not a sensor
+                        continue;
+                    }
+                    owire->id = getValue(owire->id, "id", result);
+                    owire->id = getValue(owire->alias, "alias", result);
+                    owire->type = _family[owire->family].type;
+                    owire->device = owire->family + "." + owire->id;
                     owire->bus = false;
                     _sensors[x.path().string()] = owire;
                 }
@@ -66,7 +70,6 @@ Onewire::Onewire(void)
     } catch (const boost::filesystem::filesystem_error& ex) {
         std::cout << ex.what() << std::endl;
     }
-#endif
     
     if (_sensors.size() == 0) {
         _rootdir  = "/sys/bus/w1/devices";
@@ -83,7 +86,7 @@ Onewire::Onewire(void)
                     owire->family = owire->device.substr(0,2);
                     owire->id = owire->device.substr(3, owire->device.size());
                     owire->bus = true;
-                    owire->type =  _family[owire->family].chips;
+                    owire->type = _family[owire->family].type;
                     _sensors[x.path().string()] = owire;
                 }
             }  
@@ -172,59 +175,75 @@ Onewire::getValue(const std::string &device, std::string 
file, std::string &resu
 /// Get all the temperatures from all the temperture sensors
 /// @return The temperatures from all temperature sensors
 ///
-std::map<std::string, boost::shared_ptr<temperature_t>> &
-Onewire::getTemperatures(void)
+
+const boost::shared_ptr<battery_t>
+Onewire::getBattery(const std::string &device)
 {
     //DEBUGLOG_REPORT_FUNCTION;
+    // boost::shared_ptr<temperature_t> temp = 
boost::make_shared<temperature_t>(1);
+    std::string family = _sensors[device]->family;
+    if (_sensors[device]->type == BATTERY) {
+        boost::shared_ptr<battery_t> batt(new battery_t);
+        std::string result;
+        batt->id = getValue(device, "id", result);
+        batt->current = std::stof(getValue(device, "current", result));
+        batt->volts = std::stof(getValue(device, "volts", result));
+        batt->DC = true;
+        return batt;
+    } else {
+        BOOST_LOG_SEV(lg, severity_level::warning) << device << " is not a 
battery!";
+    }
 
-    _temps.clear();
+    boost::shared_ptr<battery_t> batt;
+    return batt;
+}
 
-    std::map<std::string, boost::shared_ptr<onewire_t>>::iterator sit;
-    for (sit = _sensors.begin(); sit != _sensors.end(); sit++) {
-        boost::shared_ptr<temperature_t> temp(new temperature_t);
-        temp->family = sit->second->family;
-        temp->id = sit->second->id;
-        temp->type = sit->second->type;
-        std::string result;
-        if (sit->second->bus == true) {
-            getValue(sit->first, "w1_slave", result);
-            // FIXME: calculate the position value
-            std::string value = result.substr(69, result.size());
-            temp->scale = _scale;
-            temp->temp = std::stof(value)/1000;
-            temp->lowtemp = 0;
+const boost::shared_ptr<temperature_t>
+Onewire::getTemperature(const std::string &device)
+{
+    //DEBUGLOG_REPORT_FUNCTION;
+
+    std::string family = _sensors[device]->family;
+    bool bus = _sensors[device]->bus;
+    boost::shared_ptr<temperature_t> temp(new temperature_t);
+    temp->id = _sensors[device]->id;
+    std::string result;
+    if (bus) {
+        getValue(device, "w1_slave", result);
+        // FIXME: calculate the position value
+        std::string value = result.substr(69, result.size());
+        temp->scale = _scale;
+        temp->temp = std::stof(value)/1000;
+        temp->lowtemp = 0;
+        temp->hightemp = 0;
+        if (_scale == 'F') {
+            temp->temp = convertScale(temp->temp);
+        }
+    } else {
+        getValue(device, "temperature", result);
+        if (result.size() == 0) {
+            temp->temp = 0;
+        } else {
+            temp->temp = std::stof(result);
+        }
+        getValue(device, "temphigh", result);
+        if (result.size() == 0) {
             temp->hightemp = 0;
-            if (_scale == 'F') {
-                temp->temp = convertScale(temp->temp);
-            }
-            _temps[sit->first] = temp;
         } else {
-            getValue(sit->first, "temperature", result);
-            if (result.size() == 0) {
-                temp->temp = 0;
-            } else {
-                temp->temp = std::stof(result);
-            }
-            getValue(sit->first, "temphigh", result);
-            if (result.size() == 0) {
-                temp->hightemp = 0;
-            } else {
-                temp->hightemp = std::stof(result);
-            }
-            getValue(sit->first, "templow", result);
-            if (result.size() == 0) {
-                temp->lowtemp = 0;
-            } else {
-                temp->lowtemp = std::stof(result);
-            }
-            
-            getValue("", "/settings/units/temperature_scale", result);
-            temp->scale = result[0];
-            _temps[sit->first] = temp;
+            temp->hightemp = std::stof(result);
         }
+        getValue(device, "templow", result);
+        if (result.size() == 0) {
+            temp->lowtemp = 0;
+        } else {
+            temp->lowtemp = std::stof(result);
+        }
+
+        getValue("", "/settings/units/temperature_scale", result);
+        temp->scale = result[0];
     }
-    
-    return _temps;
+
+    return temp;
 }
 
 ///
@@ -279,7 +298,7 @@ initTable(std::map<std::string, family_t> &result)
     result["36"] = {"Coulomb counter", "DS2740", UNSUPPORTED};
     result["1D"] = {"Counter", "DS2423", UNSUPPORTED};
     result["16"] = {"crypto-ibutton", "DS1954 DS1957", UNSUPPORTED};
-    result["B2"] = {"DC Current or Voltage", "mAM001", DCVOLTAGE};
+    result["B2"] = {"DC Current or Voltage", "mAM001", BATTERY};
     result["04"] = {"EconoRam Time chi", "DS2404", UNSUPPORTED};
     result["7E"] = {"Envoronmental Monitors", "EDS00xx", UNSUPPORTED};
     result["41"] = {"Hygrocron", "DS1923", UNSUPPORTED};
diff --git a/devices/onewire.h b/devices/onewire.h
index 11ef7c7..3e7a2e2 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -31,22 +31,34 @@
 #include <boost/filesystem.hpp>
 #include "log.h"
 
+/// \enum family_e
+/// Represents all possible 1wire sensors types
+typedef enum { ACVOLTAGE,
+               DCVOLTAGE,
+               AUTH,
+               BATTERY,
+               CLOCK,
+               TEMPERATURE,
+               THERMCOUPLE,
+               MOISTURE,
+               UNSUPPORTED
+} family_e;
+
 /// \typedef onewire_t
 /// Contains data about each 1 wire sensor
 typedef struct onewire {
     std::string family;         ///< The family type, a 2 digit code
     std::string id;             ///< The device ID of the sensor
-    std::string type;           ///< The type of 1wire sensor
+    std::string alias;          ///< Alternate name for this sensor
     std::string device;         ///< The full device name
+    family_e    type;           ///< The type of 1wire sensor
     bool bus;                   ///< Whether the data is in owfs or not
 } onewire_t;
 
 /// \struct temperature_t
 /// Contains data from a 1 wire temperature sensor
 typedef struct temperature {
-    std::string family;         ///< The family type, a 2 digit code
-    std::string id;             ///< The device ID of the sensor
-    std::string type;           ///< The type of 1wire sensor
+    std::string id;             ///< The unique ID used for this sensor
     float temp;                 ///< The current temperature
     float lowtemp;              ///< The lowest temperature seen
     float hightemp;             ///< The highest temperature seen
@@ -56,24 +68,12 @@ typedef struct temperature {
 /// \typedef battery_t
 /// Contains data from a 1 wire battery monitor
 typedef struct battery {
+    std::string id;             ///< The unique ID used for this sensor
     float current;
     float volts;
     bool  DC;
 } battery_t;
 
-/// \enum family_e
-/// Represents all possible 1wire sensors types
-typedef enum { ACVOLTAGE,
-               DCVOLTAGE,
-               AUTH,
-               BATTERY,
-               CLOCK,
-               TEMPERATURE,
-               THERMCOUPLE,
-               MOISTURE,
-               UNSUPPORTED
-} family_e;
-
 /// \typedef family_t
 /// Base Data for all 1 wire sensors
 typedef struct family {
@@ -91,7 +91,7 @@ private:
     // How long to delay between reading the sensor
     int _poll_sleep;            ///< Delay time in seconds
     char _scale;                ///< 'C' or 'F'
-    std::map<std::string, boost::shared_ptr<temperature_t>> _temps;
+    // std::map<std::string, boost::shared_ptr<temperature_t>> _temps;
     // Is _rootdir (usually /mnt/1wire) mounted ?
     std::string _rootdir;       ///< Root directory for 1wire sensors
     bool _mounted = true;       ///< Whether the data is in owfs or /sys
@@ -112,6 +112,10 @@ public:
 
     void setPollSleep(int x) { _poll_sleep = x; }
 
+    const std::map<std::string, boost::shared_ptr<onewire_t>> getSensors(void) 
{
+        return _sensors;
+    };
+
     // see if any 1 wire sensors were found during scanning
     bool hasSensors(void) {
         if (_sensors.size() >0) {
@@ -130,8 +134,8 @@ public:
     void setValue(const std::string &device, const std::string &file,
                           const std::string &value);
 
-    std::map<std::string, boost::shared_ptr<temperature_t>> 
&getTemperatures(void);
-    //std::map<std::string, boost::shared_ptr<battery_t>> &getBatteries(void);
+    const boost::shared_ptr<battery_t> getBattery(const std::string &device);
+    const boost::shared_ptr<temperature_t> getTemperature(const std::string 
&device);
     void dump(void);
     
     std::vector<std::string> &
diff --git a/devices/ownet.cc b/devices/ownet.cc
index 27d4e96..6d7d8c8 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -18,6 +18,9 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/make_shared.hpp>
+#include <boost/regex.hpp>
+#include <string>
+#include <string>
 #include <string>
 #include <map>
 #include "onewire.h"
@@ -96,50 +99,95 @@ Ownet::Ownet(std::string &host)
     int i = 0;
     std::vector<std::string>::iterator it;
     for(it = results.begin(); it != results.end(); it++,i++ ) {
-        boost::shared_ptr<ownet_t> data(new ownet_t);
+        boost::shared_ptr<onewire_t> data(new onewire_t);
         std::string result;
         data->family = getValue(it->c_str(), "family", result);
-        data->type = getValue(it->c_str(), "type", result);
-        data->id = getValue(it->c_str(), "id", result);
-        if (data->type.length() == 0 || data->id.length() == 0) {
-            break;
-        }
-        std::string dev = *it + "temperature";
-        if (OW_present(dev.c_str()) == 0) {
-            BOOST_LOG(lg) << "Temperature sensor found: " << *it;
-        } else {
-            BOOST_LOG(lg) << "Temperature sensor not found!";
+        if (data->family.empty()) { // not a sensor
+            continue;
         }
+        data->id = getValue(it->c_str(), "id", result);
+        data->alias = getValue(it->c_str(), "alias", result);
+        data->device = data->family + "." + data->id;
+        data->type = _family[data->family].type;
         std::lock_guard<std::mutex> guard(_mutex);
         _sensors[*it] = data;
+        std::string device = *it;
+        switch (data->type) {
+          case TEMPERATURE:
+          {
+              BOOST_LOG(lg) << device << " is a thermometer";
+              boost::shared_ptr<temperature_t> temp(getTemperature(device));
+              if (temp) {
+                  try {
+                      temp->id = data->id;
+                      temp->temp = std::stof(getValue(device, "temperature", 
result));
+                      temp->lowtemp =std::stof(getValue(device, "templow", 
result));
+                      temp->hightemp = std::stof(getValue(device, "temphigh", 
result));
+                  } catch (const std::exception& e) {
+                      temp->temp = 0;
+                      temp->lowtemp = 0;
+                      temp->hightemp = 0;
+                  }
+              }
+              break;
+          }
+          case BATTERY:
+          {
+              BOOST_LOG(lg) << device << " is a battery";
+              boost::shared_ptr<battery_t> power(getBattery(device));
+              power->id = data->id;
+              try {
+                  power->volts = std::stof(getValue(device, "volts", result));
+                  power->current = std::stof(getValue(device, "current", 
result));
+                  power->DC = true; // FIXME: this shouldn't be hardcoded
+              } catch (const std::exception& e) {
+                  power->volts = 0;
+                  power->current = 0;
+              }
+              break;
+          }
+        };
+
     }
 
     dump();
 }
 
-///
+const boost::shared_ptr<battery_t>
+Ownet::getBattery(const std::string &device)
+{
+    //DEBUGLOG_REPORT_FUNCTION;
+    // boost::shared_ptr<temperature_t> temp = 
boost::make_shared<temperature_t>(1);
+    std::string result;
+    if (_sensors[device]->type == BATTERY) {
+        boost::shared_ptr<battery_t> batt(new battery_t);
+        batt->id = _sensors[device]->id;
+        batt->current = std::stof(getValue(device, "current", result));
+        batt->volts = std::stof(getValue(device, "volts", result));
+        batt->DC = true;
+        return batt;
+    } else {
+        BOOST_LOG_SEV(lg, severity_level::warning) << device << " is not a 
battery!";
+    }
+
+    boost::shared_ptr<battery_t> batt;
+    return batt;
+}
+
 /// Get the temperature(s) via ownet from a temperature sensor
 /// @param device The full device name including the family, ie... 
"28.021316A4D6AA"
 /// @return The temerature(s) from a temperature sensor
 const boost::shared_ptr<temperature_t>
 Ownet::getTemperature(const std::string &device)
 {
-    // DEBUGLOG_REPORT_FUNCTION;
+    //DEBUGLOG_REPORT_FUNCTION;
     
     std::string result;
-    std::string family = getValue(device, "family", result);
-    std::string id = getValue(device, "id", result);
-    std::string type = getValue(device, "type", result);
-    
-    if (family == "10" | family == "28") {
-        // BOOST_LOG(lg) << device << " is a thermometer";
-        // boost::shared_ptr<temperature_t> temp = 
boost::make_shared<temperature_t>(1);
+    if (_sensors[device]->type == TEMPERATURE) {
         boost::shared_ptr<temperature_t> temp(new temperature_t);
-        std::string result;
-        temp->family = getValue(device, "family", result);
-        temp->id = getValue(device, "id", result);
-        temp->type = getValue(device, "type", result);
         try {
+            std::string result;
+            temp->id = _sensors[device]->id;
             temp->temp = std::stof(getValue(device, "temperature", result));
             temp->lowtemp =std::stof(getValue(device, "templow", result));
             temp->hightemp = std::stof(getValue(device, "temphigh", result));
@@ -155,7 +203,7 @@ Ownet::getTemperature(const std::string &device)
         temp->scale = buffer[0];
         return temp;
     } else {
-        BOOST_LOG(lg) << device << " is not a thermometer";
+        BOOST_LOG_SEV(lg, severity_level::warning) << device << " is not a 
thermometer";
     }
     boost::shared_ptr<temperature_t> temp;
     return temp;
@@ -170,7 +218,7 @@ Ownet::listDevices(std::vector<std::string> &list)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
     
-    std::map<std::string, boost::shared_ptr<ownet_t>>::iterator sit;
+    std::map<std::string, boost::shared_ptr<onewire_t>>::iterator sit;
     for (sit = _sensors.begin(); sit != _sensors.end(); sit++) {
         std::string dev = sit->first.substr(sit->first.size()-1);
         list.push_back(sit->first);
@@ -216,12 +264,23 @@ Ownet::dump(void)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
 
-    std::map<std::string, boost::shared_ptr<ownet_t>>::iterator sit;
+    std::map<family_e, std::string> table;
+    table[ACVOLTAGE] = "ACVOLTAGE";
+    table[DCVOLTAGE] = "DCVOLTAGE";
+    table[AUTH] = "AUTHENTICATIN";
+    table[BATTERY] = "BATTERY";
+    table[CLOCK] = "CLOCK";
+    table[TEMPERATURE] = "TEMPERATURE";
+    table[THERMCOUPLE] = "THERMOCOUPLE";
+    table[MOISTURE] = "MOISTURE";
+    table[UNSUPPORTED] = "UNSUPORTED";
+
+    std::map<std::string, boost::shared_ptr<onewire_t>>::iterator sit;
     for (sit = _sensors.begin(); sit != _sensors.end(); sit++) {
         std::cout << "Data for device: " << sit->first << std::endl;
         std::cout << "\tfamily: " << sit->second->family << std::endl;
-        std::cout << "\ttype: " << sit->second->type << std::endl;
         std::cout << "\tid: " << sit->second->id << std::endl;
+        std::cout << "\ttype: " << table[sit->second->type] << std::endl;
     }
     // std::map<std::string, boost::shared_ptr<temperature_t>>::iterator tit;
     // for (tit = _temperatures.begin(); tit != _temperatures.end(); tit++) {
diff --git a/devices/ownet.h b/devices/ownet.h
index 2c17a0d..b9b2b4c 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -32,17 +32,6 @@
 extern const int OWPORT;
 extern const char *OWHOST;
 
-/// \typedef ownet_t
-/// Holds data for an ownet connection
-typedef struct ownet {
-    std::string family;
-    std::string id;
-    std::string type;
-    std::string device;
-} ownet_t;
-
-void initTable(std::map<std::string, family_t> &result);
-
 ///
 /// \class Ownet
 /// Construct a class for the ownet protocol
@@ -50,7 +39,7 @@ void initTable(std::map<std::string, family_t> &result);
 class Ownet
 {
 private:
-    std::map<std::string, boost::shared_ptr<ownet_t>> _sensors;
+    std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
     bool        _owserver;
     std::mutex  _mutex;
     int         _poll_sleep;
@@ -85,15 +74,15 @@ public:
     std::string &getValue(const std::string &device, std::string file, 
std::string &result);
 
     // return a handle to all the sensors
-    const boost::shared_ptr<ownet_t> &getSensor(const std::string &device) {
+    const boost::shared_ptr<onewire_t> &getSensor(const std::string &device) {
         return _sensors[device];
     };
 
-    const std::map<std::string, boost::shared_ptr<ownet_t>> getSensors(void) {
+    const std::map<std::string, boost::shared_ptr<onewire_t>> getSensors(void) 
{
         return _sensors;
     };
     
-    std::map<std::string, boost::shared_ptr<battery_t>> &getBatteries(void);
+    const boost::shared_ptr<battery_t> getBattery(const std::string &device);
 
     const boost::shared_ptr<temperature_t> getTemperature(const std::string 
&device);
     

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=d325783b9bec3332c2f980ba845d1e9184f301fe


commit d325783b9bec3332c2f980ba845d1e9184f301fe
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 10:59:47 2019 -0700

    Constructor moved to database.h

diff --git a/lib/postgresql.cc b/lib/postgresql.cc
index f20c0d3..44e1e86 100644
--- a/lib/postgresql.cc
+++ b/lib/postgresql.cc
@@ -29,6 +29,7 @@
 #include <sstream>
 
 #include "database.h"
+#include "onewire.h"
 #include "log.h"
 
 #ifdef HAVE_LIBPQ
@@ -40,19 +41,6 @@
 const int LINELEN = 80;
 const int QUERYLEN = 10000;
 
-Database::Database()
-    : _dbtype(NODB), _dbport(0)
-{
-
-    // These values may be replaced on the command line. These are the
-    // default behaviour.
-    _tblname  = DBTABLE;
-    _dbname   = DBNAME;
-    _dbuser   = DBUSER;
-    _dbpasswd = DBPASS;
-    _dbhost   = DBHOST;
-}
-
 Database::~Database()
 {
     //closeDB();
@@ -117,15 +105,15 @@ Database::closeDB (void)
 }
 
 bool
-Database::queryInsert(const std::string &query)
+Database::queryInsert(const std::string &query, const std::string &db)
 {
     //DEBUGLOG_REPORT_FUNCTION;
 
     int retries, result;
-    std::string str = "INSERT INTO onewire VALUES(";
+    std::string str = "INSERT INTO " + db + "  VALUES(";
     str += query + ");";
 
-    BOOST_LOG(lg) << "Query is: " << query;
+    BOOST_LOG_SEV(lg, severity_level::debug) << "Query is: " << str;
     
     if (PQexec(_connection, str.c_str()) == nullptr) {
         std::cerr << "Lost connection to the database server, shutting 
down...";

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=e4c9c80adfabfd7de08e8fd282bdd662d8ae6f12


commit e4c9c80adfabfd7de08e8fd282bdd662d8ae6f12
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 10:57:33 2019 -0700

    Update to match new schemas

diff --git a/lib/database.h b/lib/database.h
index df5d43b..c5a60fc 100644
--- a/lib/database.h
+++ b/lib/database.h
@@ -1,5 +1,6 @@
 // 
-// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
+// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+// 2013, 2014, 205, 206, 2017, 2018, 2019
 //      Free Software Foundation, Inc.
 // 
 // This program is free software; you can redistribute it and/or modify
@@ -90,7 +91,26 @@ typedef struct
 class Database
 {
 public:
-    Database();
+    Database() : _dbtype(NODB), _dbport(0) {
+        _ftable[ACVOLTAGE] = "ACVOLTAGE";
+        _ftable[DCVOLTAGE] = "DCVOLTAGE";
+        _ftable[AUTH] = "AUTHENTICATIN";
+        _ftable[BATTERY] = "BATTERY";
+        _ftable[CLOCK] = "CLOCK";
+        _ftable[TEMPERATURE] = "TEMPERATURE";
+        _ftable[THERMCOUPLE] = "THERMOCOUPLE";
+        _ftable[MOISTURE] = "MOISTURE";
+        _ftable[UNSUPPORTED] = "UNSUPORTED";
+
+        // These values may be replaced on the command line. These are the
+        // default behaviour.
+        _tblname  = DBTABLE;
+        _dbname   = DBNAME;
+        _dbuser   = DBUSER;
+        _dbpasswd = DBPASS;
+        _dbhost   = DBHOST;
+    };
+
     ~Database();
 
     /// \function gettime
@@ -99,7 +119,7 @@ public:
     /// @return returns a timestamp as a string
     // 2019-01-04 08:34:34
     std::string &gettime(std::string &time) {
-        DEBUGLOG_REPORT_FUNCTION;
+        //DEBUGLOG_REPORT_FUNCTION;
         using namespace boost::posix_time;
         boost::posix_time::ptime localtime = 
boost::posix_time::second_clock::local_time();
         static std::locale loc(std::cout.getloc(), new time_facet("%Y-%m-%d 
%H:%M:%S"));
@@ -107,7 +127,6 @@ public:
         ss.imbue(loc);
         ss << localtime;
         time = ss.str();
-        std::cerr << "Time is: " << time << std::endl;
         return time;
     }
 
@@ -116,7 +135,7 @@ public:
     bool queryInsert(std::vector<meter_data_t *> data);
     //bool queryInsert(temperature_t &data);
     bool queryInsert(meter_data_t *data);
-    bool queryInsert(const std::string &query);
+    bool queryInsert(const std::string &query, const std::string &db);
     void *queryResults(const char *query);
     //bool deleteDB(etamsg_t *data);
     //bool insertDB(etamsg_t *data);
@@ -127,44 +146,61 @@ public:
     void dbNameSet(std::string name);
     void dbHostSet(std::string host);
 
-    // family | id | type | timestamp | temphigh | templow | temperature | 
scale
-    std::string formatQuery(boost::shared_ptr<temperature_t> &temp,
+    // family | id | alias | type | timestamp 
+    std::string formatQuery(boost::shared_ptr<onewire_t> &one,
                             std::string &result) {
-        DEBUGLOG_REPORT_FUNCTION;
+        //DEBUGLOG_REPORT_FUNCTION;
+
+        result.clear();
+        result = "\'" + one->family + "\'";
+        result += ", \'" + one->id + "\'";
+        result += ", \'" + one->alias + "\'";
+        result += ", " +  _ftable[one->type];
         std::string stamp;
-        result = temp->wire.family;
-        result += ", \'" + temp->wire.id + "\'";
-        result += ", \'" + std::to_string(temp->wire.type) + "\'";
         result += ", \'" + gettime(stamp) + "\'";
+
+        //BOOST_LOG_SEV(lg, severity_level::debug) << "Formatted Query is: " 
<< result;
+        return result;
+    }
+
+    //  id | temperature | temphigh | templow | scale | timestamp
+    std::string formatQuery(boost::shared_ptr<temperature_t> &temp,
+                            std::string &result) {
+        //DEBUGLOG_REPORT_FUNCTION;
+        result.clear();
+        result = "\'" + temp->id + "\'";
+        result += ", " + std::to_string(temp->temp);
+        result += ", " + std::to_string(temp->hightemp);
         result += ", " + std::to_string(temp->lowtemp);
-        result +=  ", " + std::to_string(temp->hightemp);
-        result += ", " + std::to_string(temp->temp) + ", \'";
+        result += ", \'";
         result += temp->scale;
-        result += "\'";
+        std::string stamp;
+        result += "\', \'" + gettime(stamp) + "\'";
 
-        std::cerr << "Formatted Query is: " << result << std::endl;
+        //BOOST_LOG_SEV(lg, severity_level::debug) << "Formatted Query is: " 
<< result;
         return result;
     }
 
-    // family | id | alias | type | timestamp | current | volts
+    // id | current | volts | type | timestamp
     std::string formatQuery(const boost::shared_ptr<battery_t> &batt,
                             std::string &result) {
-        DEBUGLOG_REPORT_FUNCTION;
+        //DEBUGLOG_REPORT_FUNCTION;
 
-        std::string stamp;
-        result = batt->wire.family;
-        result += ", \'" + batt->wire.id + "\'";
-        result += ", \'" + batt->wire.alias + "\'";
-        result += ", \'" + std::to_string(batt->wire.type) + "\'";
-        result += ", \'" + gettime(stamp) + "\'";
+        result.clear();
+        result = "\'" + batt->id + "\'";
         result += ", " + std::to_string(batt->current);
         result += ", " + std::to_string(batt->volts);
+        result += ", \'";
+        result += (batt->DC == true ? "DC\'" : "AC\'");
+        std::string stamp;
+        result += ", \'" + gettime(stamp) + "\'";
 
-        std::cerr << "Formtted Query is: " << result << std::endl;
+        //BOOST_LOG_SEV(lg, severity_level::debug) << "Formatted Query is: " 
<< result;
         return result;
     }
 private:
     enum {CLOSED, OPENED} state;
+    std::map<family_e, std::string> _ftable;
     std::map<std::string, family_t> _family;
     dbtype          _dbtype;
     int             _dbport;

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=56aa3669ebfb19cdfd64e27096e97498c91ab97d


commit 56aa3669ebfb19cdfd64e27096e97498c91ab97d
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 10:56:28 2019 -0700

    Add boost date_time library

diff --git a/configure.ac b/configure.ac
index a45c66e..612370f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -393,7 +393,7 @@ if (test x"${has_boost_filesystem}" = x"no" \
    -o x"${has_boost_regex}" = x"no" -o x"${has_boost_system}" = x"np"); then
   AC_MSG_ERROR([You need all the boost libraries!])
 fi
-LIBS="-lboost_filesystem -lboost_system -lboost_regex -lboost_log 
-lboost_log_setup -lboost_thread"
+LIBS="-lboost_filesystem -lboost_system -lboost_regex -lboost_log 
-lboost_log_setup -lboost_thread -lboost_date_time"
 AC_DEFINE([BOOST_LOG_DYN_LINK], [1], [Force Boost::logging to be dynamically 
linked])
 dnl AC_DEFINE(]BOOST_ALL_DYN_LINK], [1], [Fo ])
 

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=d23109485b87c63916b34c35732bb0e7131aa339


commit d23109485b87c63916b34c35732bb0e7131aa339
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 10:55:57 2019 -0700

    Remove chips field

diff --git a/powerguru.sql b/powerguru.sql
index 4f90046..2cea00d 100644
--- a/powerguru.sql
+++ b/powerguru.sql
@@ -77,7 +77,6 @@ CREATE TABLE onewire (
   family char(2) NOT NULL default '0',
   id varchar(12) NOT NULL default '0',
   alias varchar(12) NOT NULL default '0',
-  chips varchar(24) NOT NULL default '0',
   type  wire_type NOT NULL default 'UNSUPPORTED',
   "timestamp" timestamp without time zone
 );

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=cc511e9b288b7df84949f4b50405dc97f0e4b5bc


commit cc511e9b288b7df84949f4b50405dc97f0e4b5bc
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 12:39:21 2019 -0700

    Add a voltage type enum

diff --git a/powerguru.sql b/powerguru.sql
index 0630fd0..4f90046 100644
--- a/powerguru.sql
+++ b/powerguru.sql
@@ -34,6 +34,10 @@
 --
 -- Name: data; Type: TYPE; Schema: public; Owner: rob
 --
+CREATE TYPE public.volt_type AS ENUM (
+    'AC',
+    'DC'
+);
 
 CREATE TYPE public.wire_type AS ENUM (
     'ACVOLTAGE',
@@ -93,6 +97,7 @@ CREATE TABLE battery (
   id char(16) NOT NULL default '0',
   current float NOT NULL default '0',
   volts float NOT NULL default '0',
+  type volt_type NOT NULL default 'DC',
   "timestamp" timestamp without time zone
 );
 

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=13671b61696af2683ad55720c7df2e549bebfedf


commit 13671b61696af2683ad55720c7df2e549bebfedf
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 12:38:59 2019 -0700

    Adjust tests due to changed schemas

diff --git a/testsuite/libtests/db-test.cc b/testsuite/libtests/db-test.cc
index 8533614..beaa55d 100644
--- a/testsuite/libtests/db-test.cc
+++ b/testsuite/libtests/db-test.cc
@@ -37,10 +37,6 @@ bool waitforgdb = false;
 
 TestState runtest;
 
-Database::Database() {
-    DEBUGLOG_REPORT_FUNCTION;
-};
-
 Database::~Database() {
         DEBUGLOG_REPORT_FUNCTION;
 };
@@ -62,15 +58,35 @@ public:
             runtest.fail("gettime())");
         }
 
+        std::vector<std::string> items;
+
+        // family | id | alias | chips | type | timestamp 
+        result.clear();
+        boost::shared_ptr<onewire_t> one(new onewire_t);
+        one->family = "24";
+        one->id = "97C6697351AB";
+        one->alias = "";
+        one->chips = "DS2415";
+        one->type = CLOCK;
+        formatQuery(one, result);
+
+        boost::split(items, result, boost::is_any_of(","));        
+        std::cerr << items[1] << std::endl;        
+        if (items[0] == "'24'"
+            && items[1] == " '97C6697351AB'"
+            && items[3] == " 'DS2415'"
+            && items[4] == " CLOCK"
+        ) {
+            runtest.pass("formatQuery(onewire_t)");
+        } else {
+            runtest.fail("formatQuery(onewire_t)");
+        }        
+        
         // Reset the output buffer and test formatting a temperature entry
+        //  id | temperature | temphigh | templow | scale | timestamp
         result.clear();
         boost::shared_ptr<temperature_t> temp(new temperature_t);
-        temp->wire.family = "28";
-        temp->wire.id = "67C6697351FF";
-        temp->wire.chips = "DS18B20";
-        temp->wire.device = "10.67C6697351FF";
-        temp->wire.type = TEMPERATURE;
-        temp->wire.bus = false;
+        temp->id = "67C6697351FF";
         temp->temp = 50.0;
         temp->lowtemp = 51.1;
         temp->hightemp = 52.2;
@@ -78,14 +94,13 @@ public:
         formatQuery(temp, result);
 
         // Split the string cause it's easier to match than a complex regex
-        std::vector<std::string> items;
-        boost::split(items, result, boost::is_any_of(","));        
-        if (items[0] == "28"
-            && items[1] == " '67C6697351FF'"
-            && items[2] == " '5'"
-            && items[4] == " 51.099998"
-            && items[5] == " 52.200001"
-            && items[6] == " 50.000000" && items[7] == " 'F'") {
+        boost::split(items, result, boost::is_any_of(","));
+        if (items[0] == "'67C6697351FF'"
+            && items[1] == " 50.000000"
+            && items[2] == " 52.200001"
+            && items[3] == " 51.099998"
+            && items[4] == " 'F'"
+        ) {
             runtest.pass("formatQuery(temperature_t)");
         } else {
             runtest.fail("formatQuery(temperature_t)");
@@ -94,13 +109,9 @@ public:
         // Reset the output buffer and test formatting a temperature entry
         result.clear();
         
+        // id | current | volts | timestamp
         boost::shared_ptr<battery_t> batt(new battery_t);
-        batt->wire.family = "B2";
-        batt->wire.id = "4AEC29CDBAAB";
-        batt->wire.chips = "mAM001";
-        batt->wire.device = "B2.4AEC29CDBAAB";
-        batt->wire.type = BATTERY;
-        batt->wire.bus = false;
+        batt->id = "4AEC29CDBAAB";
         batt->current = 2.3;
         batt->volts = 14.3;
         batt->DC = true;
@@ -110,11 +121,10 @@ public:
         // Split the string cause it's easier to match than a complex regex
         items.clear();
         boost::split(items, result, boost::is_any_of(","));
-        if (items[0] == "B2"
-            && items[1] == " '4AEC29CDBAAB'"
-            && items[3] == " '3'"
-            && items[5] == " 2.300000"
-            && items[6] == " 14.300000"
+        if (items[0] == "'4AEC29CDBAAB'"
+            && items[1] == " 2.300000"
+            && items[2] == " 14.300000"
+            && items[3] == " 'DC'"
         ) {
             runtest.pass("formatQuery(battery_t)");
         } else {

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=4944c5ee49b7abe04c232eb3603c70aa3a93d24f


commit 4944c5ee49b7abe04c232eb3603c70aa3a93d24f
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 11:19:31 2019 -0700

    Add new tables for temperature and battery data

diff --git a/powerguru.sql b/powerguru.sql
index c0f437e..0630fd0 100644
--- a/powerguru.sql
+++ b/powerguru.sql
@@ -32,6 +32,21 @@
 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE="NO_AUTO_VALUE_ON_ZERO" */;
 
 --
+-- Name: data; Type: TYPE; Schema: public; Owner: rob
+--
+
+CREATE TYPE public.wire_type AS ENUM (
+    'ACVOLTAGE',
+    'DCVOLTAGE',
+    'AUTH',
+    'BATTERY',
+    'CLOCK',
+    'TEMPERATURE',
+    'MOISTURE',
+    'UNSUPPORTED'
+);
+
+--
 -- Table structure for table `meters`
 --
 DROP TABLE IF EXISTS meters;
@@ -55,25 +70,30 @@ CREATE TABLE meters (
 
 DROP TABLE IF EXISTS onewire;
 CREATE TABLE onewire (
-  family integer NOT NULL default '0',
-  id char(16) NOT NULL default '0',
-  type char(12) NOT NULL default '0',
-  "timestamp" timestamp without time zone,
+  family char(2) NOT NULL default '0',
+  id varchar(12) NOT NULL default '0',
+  alias varchar(12) NOT NULL default '0',
+  chips varchar(24) NOT NULL default '0',
+  type  wire_type NOT NULL default 'UNSUPPORTED',
+  "timestamp" timestamp without time zone
+);
+
+DROP TABLE IF EXISTS temperature;
+CREATE TABLE temperature (
+  id varchar(12) NOT NULL default '0',
+  temperature float NOT NULL default '0',
   temphigh float NOT NULL default '0',
   templow float NOT NULL default '0',
-  temperature float NOT NULL default '0',
-  scale char(1) NOT NULL default 'F'
+  scale char(1) NOT NULL default 'F',
+  "timestamp" timestamp without time zone
 );
 
 DROP TABLE IF EXISTS battery;
 CREATE TABLE battery (
-  family integer NOT NULL default '0',
   id char(16) NOT NULL default '0',
-  alias char(16) NOT NULL default '0',
-  type char(12) NOT NULL default '0',
-  "timestamp" timestamp without time zone,
   current float NOT NULL default '0',
-  volts float NOT NULL default '0'
+  volts float NOT NULL default '0',
+  "timestamp" timestamp without time zone
 );
 
 /*!40101 SET address@hidden */;

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

Summary of changes:
 configure.ac                  |   2 +-
 devices/onewire.cc            | 121 ++++++++++++++++++++++++------------------
 devices/onewire.h             |  44 ++++++++-------
 devices/ownet.cc              | 115 +++++++++++++++++++++++++++++----------
 devices/ownet.h               |  19 ++-----
 lib/database.h                |  84 ++++++++++++++++++++---------
 lib/postgresql.cc             |  20 ++-----
 powerguru.sql                 |  46 ++++++++++++----
 testsuite/libtests/db-test.cc |  68 ++++++++++++++----------
 9 files changed, 324 insertions(+), 195 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

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