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. a9b7824126cc


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. a9b7824126cc6247456425859053fc6961cacd23
Date: Fri, 4 Jan 2019 12:42:08 -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  a9b7824126cc6247456425859053fc6961cacd23 (commit)
       via  a145ad4d42e6660a65227903bf1951b40e1250aa (commit)
       via  e8dd339b1a8dd805fe016494e989e2fd5c2cf4e1 (commit)
       via  5cd3c6f6d187e183fd27ad327a495ef1046de246 (commit)
       via  229a98cd0f5847635ec15eced9b6de2f72110f46 (commit)
       via  53c1334e3da138e6b903055f4047093efd367239 (commit)
       via  c9aa7e807e65681967a131b368233955282a66ce (commit)
       via  c0671d4d0665d350f66a3f5636d212001a831621 (commit)
      from  5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8 (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=a9b7824126cc6247456425859053fc6961cacd23


commit a9b7824126cc6247456425859053fc6961cacd23
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 10:41:58 2019 -0700

    Use boost time functions, format quieries

diff --git a/lib/database.h b/lib/database.h
index fc6d971..df5d43b 100644
--- a/lib/database.h
+++ b/lib/database.h
@@ -24,12 +24,20 @@
 #include "config.h"
 #endif
 
-#include <iostream> 
+#include <boost/date_time.hpp>
+#include <boost/date_time/date_facet.hpp>
+#include "boost/date_time/gregorian/gregorian.hpp"
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include "boost/date_time/local_time/local_time.hpp"
+#include <iostream>
+#include <sstream>
 #include <cstring>
 #include <list>
+#include <map>
 #include <iomanip> 
 #include <vector>
 #include <sys/time.h>
+#include "onewire.h"
 
 #ifdef HAVE_MARIADB
 # include <mysql/errmsg.h>
@@ -77,23 +85,29 @@ typedef struct
 }  meter_data_t ;
 #endif
 
+/// \class Database
+/// This is the base class for database access
 class Database
 {
 public:
     Database();
     ~Database();
-  
+
+    /// \function gettime
+    /// Return a timestamp field
+    /// @param a string to hold the formatted result
+    /// @return returns a timestamp as a string
+    // 2019-01-04 08:34:34
     std::string &gettime(std::string &time) {
-        struct timeval tp;
-        struct tm *tm, result;
-        char tmpbuf[30];  
-        gettimeofday(&tp, 0);
-        tm = localtime_r(&(tp.tv_sec), &result);
-        asctime(tm);
-        memset(tmpbuf, 0, 20);
-        strftime(tmpbuf, 20, "%Y-%m-%d %H:%M:%S", tm);
-//    DBG_MSG(DBG_INFO, "TIMESTAMP is %s\n", tmpbuf);
-        time = tmpbuf;
+        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"));
+        std::stringstream ss;
+        ss.imbue(loc);
+        ss << localtime;
+        time = ss.str();
+        std::cerr << "Time is: " << time << std::endl;
         return time;
     }
 
@@ -112,8 +126,46 @@ public:
     void dbPasswdSet(std::string passwd);
     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,
+                            std::string &result) {
+        DEBUGLOG_REPORT_FUNCTION;
+        std::string stamp;
+        result = temp->wire.family;
+        result += ", \'" + temp->wire.id + "\'";
+        result += ", \'" + std::to_string(temp->wire.type) + "\'";
+        result += ", \'" + gettime(stamp) + "\'";
+        result += ", " + std::to_string(temp->lowtemp);
+        result +=  ", " + std::to_string(temp->hightemp);
+        result += ", " + std::to_string(temp->temp) + ", \'";
+        result += temp->scale;
+        result += "\'";
+
+        std::cerr << "Formatted Query is: " << result << std::endl;
+        return result;
+    }
+
+    // family | id | alias | type | timestamp | current | volts
+    std::string formatQuery(const boost::shared_ptr<battery_t> &batt,
+                            std::string &result) {
+        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 += ", " + std::to_string(batt->current);
+        result += ", " + std::to_string(batt->volts);
+
+        std::cerr << "Formtted Query is: " << result << std::endl;
+        return result;
+    }
 private:
     enum {CLOSED, OPENED} state;
+    std::map<std::string, family_t> _family;
     dbtype          _dbtype;
     int             _dbport;
     std::string     _dbuser;

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


commit a145ad4d42e6660a65227903bf1951b40e1250aa
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 10:41:15 2019 -0700

    Add tests for formatting queries

diff --git a/testsuite/libtests/db-test.cc b/testsuite/libtests/db-test.cc
index ed644e8..8533614 100644
--- a/testsuite/libtests/db-test.cc
+++ b/testsuite/libtests/db-test.cc
@@ -21,12 +21,15 @@
 # include "config.h"
 #endif
 
-#include <unistd.h>
+#include <string>
 #include <vector>
+#include <boost/shared_ptr.hpp>
+#include <boost/regex.hpp>
+#include <boost/algorithm/string.hpp>
 #include "dejagnu.h"
 #include "database.h"
 #include "log.h"
-#include <boost/regex.hpp>
+#include "onewire.h"
 
 int verbosity;
 static void usage (void);
@@ -49,15 +52,74 @@ public:
     Test() {
         DEBUGLOG_REPORT_FUNCTION;
 
-        // Test creating commands
         std::string result;
+        // Test creating commands
         std::cerr << gettime(result) << std::endl;
         
-        if (boost::regex_match(result, boost::regex("[0-9 :\-]*"))) {
+        if (boost::regex_match(result, boost::regex("[0-9 :-]*"))) {
             runtest.pass("gettime()");
         } else {
             runtest.fail("gettime())");
         }
+
+        // Reset the output buffer and test formatting a temperature entry
+        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->temp = 50.0;
+        temp->lowtemp = 51.1;
+        temp->hightemp = 52.2;
+        temp->scale = 'F';
+        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'") {
+            runtest.pass("formatQuery(temperature_t)");
+        } else {
+            runtest.fail("formatQuery(temperature_t)");
+        }        
+        
+        // Reset the output buffer and test formatting a temperature entry
+        result.clear();
+        
+        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->current = 2.3;
+        batt->volts = 14.3;
+        batt->DC = true;
+
+        formatQuery(batt, result);
+
+        // 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"
+        ) {
+            runtest.pass("formatQuery(battery_t)");
+        } else {
+            runtest.fail("formatQuery(battery_t)");
+        }        
     };
     
     ~Test() {};

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


commit e8dd339b1a8dd805fe016494e989e2fd5c2cf4e1
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 09:35:30 2019 -0700

    Add test case for Database class

diff --git a/testsuite/libtests/Makefile.am b/testsuite/libtests/Makefile.am
index 2fd7804..643b2fd 100644
--- a/testsuite/libtests/Makefile.am
+++ b/testsuite/libtests/Makefile.am
@@ -20,9 +20,14 @@
 
 AUTOMAKE_OPTIONS = dejagnu subdir-objects
 
-AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib $(LIBXML_CPPFLAGS) 
$(PQ_CPPFLAGS) -DSRCDIR=\"$(srcdir)\"
-
-check_PROGRAMS =  tcpip tutil childtcpip
+AM_CPPFLAGS = -I$(top_srcdir) \
+       -I$(top_srcdir)/lib \
+       -I$(top_srcdir)/devices \
+       $(LIBXML_CPPFLAGS) \
+       $(PQ_CPPFLAGS) \
+       -DSRCDIR=\"$(srcdir)\"
+
+check_PROGRAMS =  tcpip tutil childtcpip db
 TESTS = $(check_PROGRAMS)
 
 if BUILD_LIBXML
@@ -46,6 +51,10 @@ tutil_SOURCES = tcputil-test.cc
 tutil_LDADD = ../../lib/tcputil.lo  $(LOG)
 tutil_DEPENDENCIES = ../../lib/tcputil.lo $(LOG)
 
+db_SOURCES = db-test.cc
+db_LDADD =  $(LOG) -lpthread
+db_DEPENDENCIES = $(LOG)
+
 childtcpip_SOURCES = childtcpip.cc
 childtcpip_LDADD = ../../lib/tcpip.lo ../../lib/tcputil.lo $(LOG)
 childtcpip_DEPENDENCIES = ../../lib/tcpip.lo ../../lib/tcputil.lo $(LOG)

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


commit 5cd3c6f6d187e183fd27ad327a495ef1046de246
Author: Rob Savoye <address@hidden>
Date:   Fri Jan 4 09:35:19 2019 -0700

    Test case for Database class

diff --git a/testsuite/libtests/db-test.cc b/testsuite/libtests/db-test.cc
new file mode 100644
index 0000000..ed644e8
--- /dev/null
+++ b/testsuite/libtests/db-test.cc
@@ -0,0 +1,114 @@
+// 
+//   Copyright (C) 2018, 2019 Free Software Foundation, Inc.
+//
+//   This program is free software; you can redistribute it and/or modify
+//   it under the terms of the GNU General Public License as published by
+//   the Free Software Foundation; either version 2 of the License, or
+//   (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//   GNU General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; if not, write to the Free Software
+//   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+// This is generated by autoconf
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <unistd.h>
+#include <vector>
+#include "dejagnu.h"
+#include "database.h"
+#include "log.h"
+#include <boost/regex.hpp>
+
+int verbosity;
+static void usage (void);
+bool waitforgdb = false;
+
+TestState runtest;
+
+Database::Database() {
+    DEBUGLOG_REPORT_FUNCTION;
+};
+
+Database::~Database() {
+        DEBUGLOG_REPORT_FUNCTION;
+};
+
+// Declare a class inherited from the base class so we can access the internal
+// protected data.
+class Test : public Database {
+public:
+    Test() {
+        DEBUGLOG_REPORT_FUNCTION;
+
+        // Test creating commands
+        std::string result;
+        std::cerr << gettime(result) << std::endl;
+        
+        if (boost::regex_match(result, boost::regex("[0-9 :\-]*"))) {
+            runtest.pass("gettime()");
+        } else {
+            runtest.fail("gettime())");
+        }
+    };
+    
+    ~Test() {};
+};
+
+int
+main(int argc, char *argv[])
+{
+    int c;
+    bool dump = false;
+    char buffer[300];
+    std::string filespec;
+    
+    int retries = 3;
+
+    memset(buffer, 0, 300);
+    
+    while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
+        switch (c) {
+          case 'h':
+            usage ();
+            break;
+            
+          case 'd':
+            dump = true;
+            break;
+            
+          case 's':
+            waitforgdb = true;
+            break;
+                                                                               
 
+          case 'v':
+            verbosity++;
+            break;
+            
+          default:
+            usage ();
+            break;
+        }
+    }
+    
+    Test test;
+}
+
+static void
+usage (void)
+{
+    std::cerr << "This program tests the XML processing code." << std::endl;
+    std::cerr << "Usage: ./xml [h]" << std::endl;
+    std::cerr << "-h\tHelp" << std::endl;
+    std::cerr << "-d\tDump parsed data" << std::endl;
+    exit (-1);
+}
+

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


commit 229a98cd0f5847635ec15eced9b6de2f72110f46
Author: Rob Savoye <address@hidden>
Date:   Thu Jan 3 16:05:26 2019 -0700

    Make initTable() a global function

diff --git a/devices/onewire.cc b/devices/onewire.cc
index f68b841..150d10d 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -15,16 +15,19 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-#include <string>
 #include <boost/algorithm/string.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
 #include <iostream>
-#include <cstdio>
+#include <string>
+#include <map>
 #include <streambuf>
 #include "onewire.h"
 #include "log.h"
 
+//std::map<const std::string, family_t> initTable(
+//    std::map<const std::string, family_t> &result);
+
 ///
 /// \class Onewire
 /// Construct a class for 1wire sensors
@@ -38,7 +41,7 @@ Onewire::Onewire(void)
 //    DEBUGLOG_REPORT_FUNCTION;
 
     // Initialize the table of family types
-    initTable();
+    initTable(_family);
 
 #if 0
     boost::filesystem::path p(_rootdir);
@@ -81,10 +84,8 @@ Onewire::Onewire(void)
                     owire->id = owire->device.substr(3, owire->device.size());
                     owire->bus = true;
                     owire->type =  _family[owire->family].chips;
-                    std::cerr << "BUS path found: " << result <<  std::endl;
                     _sensors[x.path().string()] = owire;
                 }
-                //readBus()
             }  
         }
     }
@@ -93,6 +94,11 @@ Onewire::Onewire(void)
     dump();
 }
 
+Onewire::~Onewire(void)
+{
+//    DEBUGLOG_REPORT_FUNCTION;
+};
+
 ///
 /// Set the value in a 1wire file
 /// @param device The full device name including the family, ie... 
"28.021316A4D6AA"
@@ -222,85 +228,6 @@ Onewire::getTemperatures(void)
 }
 
 ///
-/// Initialize the table of 1wire sensor data
-///
-void
-Onewire::initTable(void)
-{
-//    DEBUGLOG_REPORT_FUNCTION;
-
-    // This is a complete chart of all supported 1 wire sensors from
-    // http://owfs.org/index.php?page=family-code-list. This is
-    // mostly used for identifying the type of sensor, and display
-    // purposes.
-    _family["A2"] = {"AC Voltage", "mCM001", ACVOLTAGE};
-    _family["82"] = {"Authorization", "DS1425", AUTH};
-    _family["30"] = {"Battery", "DS2760", BATTERY};
-    _family["32"] = {"Battery", "DS2780", BATTERY};
-    _family["35"] = {"Battery", "DS2755", BATTERY};
-    _family["2E"] = {"Battery", "DS2770", BATTERY};
-    _family["3D"] = {"Battery", "DS2781", BATTERY};
-    _family["31"] = {"Battery ID", "DS2720", BATTERY};
-    _family["26"] = {"Battery monitor", "DS2438", BATTERY};
-    _family["51"] = {"Battery monitor", "DS2751", BATTERY};
-    _family["1B"] = {"Battery monitor", "DS2436", BATTERY};
-    _family["1E"] = {"Battery monitor", "DS2437", BATTERY};
-    _family["24"] = {"Clock", "DS2415", CLOCK};
-    _family["27"] = {"Clock + interrupt", "DS2417", CLOCK};
-    _family["36"] = {"Coulomb counter", "DS2740", UNSUPPORTED};
-    _family["1D"] = {"Counter", "DS2423", UNSUPPORTED};
-    _family["16"] = {"crypto-ibutton", "DS1954 DS1957", UNSUPPORTED};
-    _family["B2"] = {"DC Current or Voltage", "mAM001", DCVOLTAGE};
-    _family["04"] = {"EconoRam Time chi", "DS2404", UNSUPPORTED};
-    _family["7E"] = {"Envoronmental Monitors", "EDS00xx", UNSUPPORTED};
-    _family["41"] = {"Hygrocron", "DS1923", UNSUPPORTED};
-    _family["81"] = {"ID found in DS2490R and DS2490B USB adapters", "USB id", 
UNSUPPORTED};
-    _family["01"] = {"ID-only", "DS2401 DS2411 DS1990R DS2490A", UNSUPPORTED};
-    _family["A6"] = {"IR Temperature", "mTS017", UNSUPPORTED};
-    _family["06"] = {"Memory", "DS1993", UNSUPPORTED};
-    _family["08"] = {"Memory", "DS1992", UNSUPPORTED};
-    _family["09"] = {"Memory", "DS2502 DS2703 DS2704", UNSUPPORTED};
-    _family["14"] = {"Memory", "DS2430A", UNSUPPORTED};
-    _family["23"] = {"Memory", "DS2433 DS1973", UNSUPPORTED};
-    _family["43"] = {"Memory", "DS28EC20", UNSUPPORTED};
-    _family["0B"] = {"Memory", "DS2505", UNSUPPORTED};
-    _family["0F"] = {"Memory", "DS2506", UNSUPPORTED};
-    _family["2D"] = {"Memory", "DS2431 DS1972", UNSUPPORTED};
-    _family["1F"] = {"Microhub", "DS2409", UNSUPPORTED};
-    _family["EF"] = {"Moisture meter.4 Channel Hub 1A", "DS1963L Monetary 
iButton", UNSUPPORTED};
-    _family["02"] = {"Multikey", "DS1991", UNSUPPORTED};
-    _family["37"] = {"password EEPROM", "DS1977", UNSUPPORTED};
-    _family["FC"] = {"Moisture Hub", "BAE0910 BAE0911", UNSUPPORTED};
-    _family["00"] = {"Provide location information", "Link locator", 
UNSUPPORTED};
-    _family["A0"] = {"Rotation Sensor", "mRS001", UNSUPPORTED};
-    _family["18"] = {"SHA iButton", "DS1963S DS1962", UNSUPPORTED};
-    _family["44"] = {"SHA-1 Authenticator", "DS28E10", UNSUPPORTED};
-    _family["34"] = {"SHA-1 Battery", "DS2703", UNSUPPORTED};
-    _family["33"] = {"SHA-1 ibutton", "DS1961s DS2432", UNSUPPORTED};
-    _family["FF"] = {"Swart LCD", "LCD", UNSUPPORTED};
-    _family["05"] = {"Switch", "Ds2405", UNSUPPORTED};
-    _family["12"] = {"Switch", "DS2406", UNSUPPORTED};
-    _family["29"] = {"Switch", "DS2408", UNSUPPORTED};
-    _family["1C"] = {"Switch", "DS28E04-100", UNSUPPORTED};
-    _family["3A"] = {"Switch", "DS2413", UNSUPPORTED};
-    _family["10"] = {"Temperature", "DS18S20", TEMPERATURE};
-    _family["22"] = {"Temperature", "DS1922", TEMPERATURE};
-    _family["28"] = {"Temperature", "DS18B20", TEMPERATURE};
-    _family["3B"] = {"Temperature/memory", "DS1825 X31826", UNSUPPORTED};
-    _family["42"] = {"Temperature/IO", "DS28EA00", UNSUPPORTED};
-    _family["B1"] = {"Thermocouple Converter", "mTC001", UNSUPPORTED};  
-    _family["B3"] = {"Thermocouple Converter", "mTC002", UNSUPPORTED};
-    _family["21"] = {"Thermocron", "DS1921", UNSUPPORTED};
-    _family["EE"] = {"Ultra Violet Index", "UVI", UNSUPPORTED};
-    _family["89"] = {"Uniqueware", "DS1982U", UNSUPPORTED};
-    _family["8B"] = {"Uniqueware", "DS1985U", UNSUPPORTED};
-    _family["8F"] = {"Uniqueware", "DS1986U", UNSUPPORTED};
-    _family["2C"] = {"Varible Resitor", "DS2890", UNSUPPORTED};
-    _family["A1"] = {"Vibratio", "mVM001", UNSUPPORTED};
-    _family["20"] = {"Voltage", "DS2450", UNSUPPORTED};
-}
-
-///
 /// Dump data about the sensors
 ///
 void
@@ -323,6 +250,85 @@ Onewire::dump(void)
     }
 }
 
+///
+/// Initialize the table of 1wire sensor data
+///
+void
+initTable(std::map<std::string, family_t> &result)
+{
+//    DEBUGLOG_REPORT_FUNCTION;
+
+    // This is a complete chart of all supported 1 wire sensors from
+    // http://owfs.org/index.php?page=family-code-list. This is
+    // mostly used for identifying the type of sensor, and display
+    // purposes.
+    result["A2"] = {"AC Voltage", "mCM001", ACVOLTAGE};
+    result["82"] = {"Authorization", "DS1425", AUTH};
+    result["30"] = {"Battery", "DS2760", BATTERY};
+    result["32"] = {"Battery", "DS2780", BATTERY};
+    result["35"] = {"Battery", "DS2755", BATTERY};
+    result["2E"] = {"Battery", "DS2770", BATTERY};
+    result["3D"] = {"Battery", "DS2781", BATTERY};
+    result["31"] = {"Battery ID", "DS2720", BATTERY};
+    result["26"] = {"Battery monitor", "DS2438", BATTERY};
+    result["51"] = {"Battery monitor", "DS2751", BATTERY};
+    result["1B"] = {"Battery monitor", "DS2436", BATTERY};
+    result["1E"] = {"Battery monitor", "DS2437", BATTERY};
+    result["24"] = {"Clock", "DS2415", CLOCK};
+    result["27"] = {"Clock + interrupt", "DS2417", CLOCK};
+    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["04"] = {"EconoRam Time chi", "DS2404", UNSUPPORTED};
+    result["7E"] = {"Envoronmental Monitors", "EDS00xx", UNSUPPORTED};
+    result["41"] = {"Hygrocron", "DS1923", UNSUPPORTED};
+    result["81"] = {"ID found in DS2490R and DS2490B USB adapters", "USB id", 
UNSUPPORTED};
+    result["01"] = {"ID-only", "DS2401 DS2411 DS1990R DS2490A", UNSUPPORTED};
+    result["A6"] = {"IR Temperature", "mTS017", UNSUPPORTED};
+    result["06"] = {"Memory", "DS1993", UNSUPPORTED};
+    result["08"] = {"Memory", "DS1992", UNSUPPORTED};
+    result["09"] = {"Memory", "DS2502 DS2703 DS2704", UNSUPPORTED};
+    result["14"] = {"Memory", "DS2430A", UNSUPPORTED};
+    result["23"] = {"Memory", "DS2433 DS1973", UNSUPPORTED};
+    result["43"] = {"Memory", "DS28EC20", UNSUPPORTED};
+    result["0B"] = {"Memory", "DS2505", UNSUPPORTED};
+    result["0F"] = {"Memory", "DS2506", UNSUPPORTED};
+    result["2D"] = {"Memory", "DS2431 DS1972", UNSUPPORTED};
+    result["1F"] = {"Microhub", "DS2409", UNSUPPORTED};
+    result["EF"] = {"Moisture meter.4 Channel Hub 1A", "DS1963L Monetary 
iButton", UNSUPPORTED};
+    result["02"] = {"Multikey", "DS1991", UNSUPPORTED};
+    result["37"] = {"password EEPROM", "DS1977", UNSUPPORTED};
+    result["FC"] = {"Moisture Hub", "BAE0910 BAE0911", UNSUPPORTED};
+    result["00"] = {"Provide location information", "Link locator", 
UNSUPPORTED};
+    result["A0"] = {"Rotation Sensor", "mRS001", UNSUPPORTED};
+    result["18"] = {"SHA iButton", "DS1963S DS1962", UNSUPPORTED};
+    result["44"] = {"SHA-1 Authenticator", "DS28E10", UNSUPPORTED};
+    result["34"] = {"SHA-1 Battery", "DS2703", UNSUPPORTED};
+    result["33"] = {"SHA-1 ibutton", "DS1961s DS2432", UNSUPPORTED};
+    result["FF"] = {"Swart LCD", "LCD", UNSUPPORTED};
+    result["05"] = {"Switch", "Ds2405", UNSUPPORTED};
+    result["12"] = {"Switch", "DS2406", UNSUPPORTED};
+    result["29"] = {"Switch", "DS2408", UNSUPPORTED};
+    result["1C"] = {"Switch", "DS28E04-100", UNSUPPORTED};
+    result["3A"] = {"Switch", "DS2413", UNSUPPORTED};
+    result["10"] = {"Temperature", "DS18S20", TEMPERATURE};
+    result["22"] = {"Temperature", "DS1922", TEMPERATURE};
+    result["28"] = {"Temperature", "DS18B20", TEMPERATURE};
+    result["3B"] = {"Temperature/memory", "DS1825 X31826", UNSUPPORTED};
+    result["42"] = {"Temperature/IO", "DS28EA00", UNSUPPORTED};
+    result["B1"] = {"Thermocouple Converter", "mTC001", UNSUPPORTED};  
+    result["B3"] = {"Thermocouple Converter", "mTC002", UNSUPPORTED};
+    result["21"] = {"Thermocron", "DS1921", UNSUPPORTED};
+    result["EE"] = {"Ultra Violet Index", "UVI", UNSUPPORTED};
+    result["89"] = {"Uniqueware", "DS1982U", UNSUPPORTED};
+    result["8B"] = {"Uniqueware", "DS1985U", UNSUPPORTED};
+    result["8F"] = {"Uniqueware", "DS1986U", UNSUPPORTED};
+    result["2C"] = {"Varible Resitor", "DS2890", UNSUPPORTED};
+    result["A1"] = {"Vibratio", "mVM001", UNSUPPORTED};
+    result["20"] = {"Voltage", "DS2450", UNSUPPORTED};
+}
+    
 // local Variables:
 // mode: C++
 // indent-tabs-mode: nil
diff --git a/devices/onewire.h b/devices/onewire.h
index 08cd7fa..11ef7c7 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -31,10 +31,8 @@
 #include <boost/filesystem.hpp>
 #include "log.h"
 
-///
 /// \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
@@ -43,10 +41,8 @@ typedef struct onewire {
     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
@@ -57,6 +53,14 @@ typedef struct temperature {
     char scale;                 ///< The scale, 'C' or 'F'
 } temperature_t;
 
+/// \typedef battery_t
+/// Contains data from a 1 wire battery monitor
+typedef struct battery {
+    float current;
+    float volts;
+    bool  DC;
+} battery_t;
+
 /// \enum family_e
 /// Represents all possible 1wire sensors types
 typedef enum { ACVOLTAGE,
@@ -71,13 +75,16 @@ typedef enum { ACVOLTAGE,
 } family_e;
 
 /// \typedef family_t
-/// Base Data for all 1wire sensors
+/// Base Data for all 1 wire sensors
 typedef struct family {
     std::string description;    ///< The description of this sensor
     std::string chips;          ///< The Dallas Semiconductor chip used for 
this sensor
     family_e    type;           ///< The type of 1wire sensor
 } family_t;
 
+///< Initialize table of 1 wire family data
+extern void initTable(std::map<std::string, ::family_t> &result);
+
 class Onewire {
 private:
     std::mutex _mutex;
@@ -89,26 +96,21 @@ private:
     std::string _rootdir;       ///< Root directory for 1wire sensors
     bool _mounted = true;       ///< Whether the data is in owfs or /sys
     ///< Table of family types of supported sensors
-    std::map<const std::string, family_t> _family;
+    std::map<std::string, family_t> _family;
     ///< All the currently installed sensors
     std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
-    void initTable(void);       ///< Initialize table of 1wire family data
 public:
     Onewire(void);
-    ~Onewire(void) {};
+    ~Onewire(void);
 
     char setScale(char scale);
     bool isMounted() { return _mounted; };
 
     // Thread have a polling frequency to avoid eating up all the cpu cycles
     // by polling to quickly.
-    int getPollSleep(void) {
-        return _poll_sleep;
-    }
+    int getPollSleep(void) { return _poll_sleep; }
 
-    void setPollSleep(int x) {
-        _poll_sleep = x;
-    }
+    void setPollSleep(int x) { _poll_sleep = x; }
 
     // see if any 1 wire sensors were found during scanning
     bool hasSensors(void) {
@@ -119,9 +121,7 @@ public:
         }
     }
 
-    float convertScale(float inc) {
-        return (inc * 1.8) + 32.0;
-    }
+    float convertScale(float inc) { return (inc * 1.8) + 32.0; }
     
     // extract a value from an owfs file
     std::string &getValue(const std::string &device, std::string file,
@@ -130,8 +130,8 @@ public:
     void setValue(const std::string &device, const std::string &file,
                           const std::string &value);
 
-    // get all the temperature fields for a device.
-    std::map<std::string, boost::shared_ptr<temperature_t>> 
&getTemperatures(void);               
+    std::map<std::string, boost::shared_ptr<temperature_t>> 
&getTemperatures(void);
+    //std::map<std::string, boost::shared_ptr<battery_t>> &getBatteries(void);
     void dump(void);
     
     std::vector<std::string> &
diff --git a/devices/ownet.cc b/devices/ownet.cc
index 9944f94..27d4e96 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -15,10 +15,12 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-#include <string>
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/make_shared.hpp>
+#include <string>
+#include <map>
+#include "onewire.h"
 #include "ownet.h"
 #include "log.h"
 
@@ -33,6 +35,9 @@ Ownet::Ownet(void)
       _owserver(false)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
+    
+    // Initialize the table of family types
+    initTable(_family);
 }
 
 ///
@@ -42,7 +47,6 @@ Ownet::Ownet(std::string &host)
     : Ownet()
 {
 //    DEBUGLOG_REPORT_FUNCTION;
-
     int retries = 2;
     if (host.find(':') == std::string::npos) {
         host += ":" + std::to_string(OWPORT);
diff --git a/devices/ownet.h b/devices/ownet.h
index c6631db..2c17a0d 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -18,13 +18,13 @@
 #ifndef __OWNET_H__
 #define __OWNET_H__
 
+#include <owcapi.h>
+#include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
 #include <mutex>
 #include <string>
 #include <vector>
 #include <map>
-#include <owcapi.h>
-#include <boost/algorithm/string.hpp>
-#include <boost/shared_ptr.hpp>
 #include "onewire.h"
 #include "log.h"
 
@@ -41,6 +41,8 @@ typedef struct ownet {
     std::string device;
 } ownet_t;
 
+void initTable(std::map<std::string, family_t> &result);
+
 ///
 /// \class Ownet
 /// Construct a class for the ownet protocol
@@ -48,12 +50,12 @@ typedef struct ownet {
 class Ownet
 {
 private:
-    enum family_t {CONTROL = 05, THERMOMETER = 10, THERMOMETER2 = 28};
     std::map<std::string, boost::shared_ptr<ownet_t>> _sensors;
     bool        _owserver;
     std::mutex  _mutex;
     int         _poll_sleep;
     char        _scale;
+    std::map<std::string, family_t> _family;
 public:
     Ownet(void);
     Ownet(std::string &host);
@@ -91,7 +93,8 @@ public:
         return _sensors;
     };
     
-    // get all the temperature fields for a device.
+    std::map<std::string, boost::shared_ptr<battery_t>> &getBatteries(void);
+
     const boost::shared_ptr<temperature_t> getTemperature(const std::string 
&device);
     
     void dump(void);

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


commit 53c1334e3da138e6b903055f4047093efd367239
Author: Rob Savoye <address@hidden>
Date:   Thu Jan 3 15:18:50 2019 -0700

    Add scheme for battery stats table

diff --git a/powerguru.sql b/powerguru.sql
index 97ec0eb..c0f437e 100644
--- a/powerguru.sql
+++ b/powerguru.sql
@@ -65,6 +65,17 @@ CREATE TABLE onewire (
   scale char(1) NOT NULL default 'F'
 );
 
+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'
+);
+
 /*!40101 SET address@hidden */;
 /*!40014 SET address@hidden */;
 /*!40014 SET address@hidden */;

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


commit c9aa7e807e65681967a131b368233955282a66ce
Author: Rob Savoye <address@hidden>
Date:   Thu Jan 3 14:11:02 2019 -0700

    Add doxygen style comments

diff --git a/devices/onewire.h b/devices/onewire.h
index 689467b..08cd7fa 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -82,17 +82,17 @@ class Onewire {
 private:
     std::mutex _mutex;
     // How long to delay between reading the sensor
-    int _poll_sleep;
-    char _scale;                // 'C' or 'F'
+    int _poll_sleep;            ///< Delay time in seconds
+    char _scale;                ///< 'C' or 'F'
     std::map<std::string, boost::shared_ptr<temperature_t>> _temps;
     // Is _rootdir (usually /mnt/1wire) mounted ?
-    std::string _rootdir;
-    bool _mounted = true;
-    // Table of family types of supported sensors
-    std::map<const std::string, family_t> _family;    
-    void initTable(void);
-    // All the currently installed sensors
+    std::string _rootdir;       ///< Root directory for 1wire sensors
+    bool _mounted = true;       ///< Whether the data is in owfs or /sys
+    ///< Table of family types of supported sensors
+    std::map<const std::string, family_t> _family;
+    ///< All the currently installed sensors
     std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
+    void initTable(void);       ///< Initialize table of 1wire family data
 public:
     Onewire(void);
     ~Onewire(void) {};

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


commit c0671d4d0665d350f66a3f5636d212001a831621
Author: Rob Savoye <address@hidden>
Date:   Thu Jan 3 14:07:20 2019 -0700

    Add doxygen style comments

diff --git a/devices/onewire.cc b/devices/onewire.cc
index 4824590..f68b841 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -25,6 +25,10 @@
 #include "onewire.h"
 #include "log.h"
 
+///
+/// \class Onewire
+/// Construct a class for 1wire sensors
+///
 Onewire::Onewire(void)
     : _scale('F'),
       _poll_sleep(300),
@@ -89,6 +93,12 @@ Onewire::Onewire(void)
     dump();
 }
 
+///
+/// Set the value in a 1wire file
+/// @param device The full device name including the family, ie... 
"28.021316A4D6AA"
+/// @param file The base name of the file to read
+/// @param value The value to set the file to
+///
 void
 Onewire::setValue(const std::string &device, const std::string &file,
                   const std::string &value)
@@ -113,7 +123,13 @@ Onewire::setValue(const std::string &device, const 
std::string &file,
     entry.close();
 }
 
-// extract a value from an owfs file
+///
+/// Get the value from a 1wire file
+/// @param device The full device name including the family, ie... 
"28.021316A4D6AA"
+/// @param file The base name of the file to read
+/// @param result String to hold the returned value
+/// @return the value from the file
+///
 std::string &
 Onewire::getValue(const std::string &device, std::string file, std::string 
&result)
 {
@@ -146,6 +162,10 @@ Onewire::getValue(const std::string &device, std::string 
file, std::string &resu
     return result;
 }
 
+///
+/// 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)
 {
@@ -201,6 +221,9 @@ Onewire::getTemperatures(void)
     return _temps;
 }
 
+///
+/// Initialize the table of 1wire sensor data
+///
 void
 Onewire::initTable(void)
 {
@@ -277,17 +300,9 @@ Onewire::initTable(void)
     _family["20"] = {"Voltage", "DS2450", UNSUPPORTED};
 }
 
-std::string &
-Onewire::readBus(const std::string &device, std::string &data)
-{
-    DEBUGLOG_REPORT_FUNCTION;
-
-    ///sys/bus/w1/devices/28-021316a4d6aa/w1_slave
-
-    return data;
-}
-               
-
+///
+/// Dump data about the sensors
+///
 void
 Onewire::dump(void)
 {
diff --git a/devices/onewire.h b/devices/onewire.h
index ed33dd5..689467b 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -1,5 +1,5 @@
 // 
-// Copyright (C) 2018 Free Software Foundation, Inc.
+// Copyright (C) 2018, 2019 Free Software Foundation, Inc.
 // 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -15,6 +15,10 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+//
+// \brief Class for 1wire sensors
+// \copyright GNU Public License.
+//
 #ifndef __ONEWIRE_H__
 #define __ONEWIRE_H__
 
@@ -27,40 +31,52 @@
 #include <boost/filesystem.hpp>
 #include "log.h"
 
-struct onewire {
-    std::string family;
-    std::string id;
-    std::string type;
-    std::string device;
-    bool bus;
-} typedef onewire_t;
-
-struct temperature {
-    std::string family;
-    std::string id;
-    std::string type;
-    float temp;
-    float lowtemp;
-    float hightemp;
-    char scale;
-} typedef temperature_t;
-
-enum { ACVOLTAGE,
-       DCVOLTAGE,
-       AUTH,
-       BATTERY,
-       CLOCK,
-       TEMPERATURE,
-       THERMCOUPLE,
-       MOISTURE,
-       UNSUPPORTED
-} typedef family_e;
-
-struct family {
-    std::string desription;
-    std::string chips;
-    family_e    type;
-} typedef family_t;
+///
+/// \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 device;         ///< The full device name
+    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
+    float temp;                 ///< The current temperature
+    float lowtemp;              ///< The lowest temperature seen
+    float hightemp;             ///< The highest temperature seen
+    char scale;                 ///< The scale, 'C' or 'F'
+} temperature_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 1wire sensors
+typedef struct family {
+    std::string description;    ///< The description of this sensor
+    std::string chips;          ///< The Dallas Semiconductor chip used for 
this sensor
+    family_e    type;           ///< The type of 1wire sensor
+} family_t;
 
 class Onewire {
 private:
@@ -115,11 +131,7 @@ public:
                           const std::string &value);
 
     // get all the temperature fields for a device.
-    std::map<std::string, boost::shared_ptr<temperature_t>> 
&getTemperatures(void);
-
-    std::string &
-    readBus(const std::string &device, std::string &data);
-               
+    std::map<std::string, boost::shared_ptr<temperature_t>> 
&getTemperatures(void);               
     void dump(void);
     
     std::vector<std::string> &
diff --git a/devices/ownet.cc b/devices/ownet.cc
index 56eb217..9944f94 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -22,10 +22,11 @@
 #include "ownet.h"
 #include "log.h"
 
-// Default host and port for the owserver
-const int OWPORT = 4304;
-const char *OWHOST = "localhost";
+const int OWPORT = 4304;        ///< TCP/IP port for owserver
+const char *OWHOST = "localhost"; ///< Remote hostname for owserver
 
+/// \class Ownet
+/// Consruct a class for OWNet support
 Ownet::Ownet(void)
     : _poll_sleep(300),
       _scale('F'),
@@ -34,6 +35,9 @@ Ownet::Ownet(void)
 //    DEBUGLOG_REPORT_FUNCTION;
 }
 
+///
+/// Consruct a class for OWNet support connected to a remote host
+/// @param host Hostname of the remote owserver
 Ownet::Ownet(std::string &host)
     : Ownet()
 {
@@ -89,9 +93,10 @@ Ownet::Ownet(std::string &host)
     std::vector<std::string>::iterator it;
     for(it = results.begin(); it != results.end(); it++,i++ ) {
         boost::shared_ptr<ownet_t> data(new ownet_t);
-        data->family = getValue(it->c_str(), "family");
-        data->type = getValue(it->c_str(), "type");
-        data->id = getValue(it->c_str(), "id");
+        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;
         }
@@ -108,26 +113,32 @@ Ownet::Ownet(std::string &host)
     dump();
 }
 
+///
+/// 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;
     
-    std::string family = getValue(device, "family");
-    std::string id = getValue(device, "id");
-    std::string type = getValue(device, "type");
+    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);
         boost::shared_ptr<temperature_t> temp(new temperature_t);
-        temp->family = getValue(device, "family");
-        temp->id = getValue(device, "id");
-        temp->type = getValue(device, "type");
+        std::string result;
+        temp->family = getValue(device, "family", result);
+        temp->id = getValue(device, "id", result);
+        temp->type = getValue(device, "type", result);
         try {
-            temp->temp = std::stof(getValue(device, "temperature"));
-            temp->lowtemp =std::stof(getValue(device, "templow"));
-            temp->hightemp = std::stof(getValue(device, "temphigh"));
+            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;
@@ -146,6 +157,10 @@ Ownet::getTemperature(const std::string &device)
     return temp;
 }
 
+///
+/// Get a list of all connected sensor devices
+/// @param an array to hold the device list
+/// @return a list of all sensors 
 const std::vector<std::string>
 Ownet::listDevices(std::vector<std::string> &list)
 {
@@ -159,8 +174,15 @@ Ownet::listDevices(std::vector<std::string> &list)
     return list;
 }
 
-std::string
-Ownet::getValue(const std::string &device, std::string file)
+///
+/// Get the value from a 1wire file
+/// @param device The full device name including the family, ie... 
"28.021316A4D6AA"
+/// @param file The base name of the file to read
+/// @param result String to hold the returned value
+/// @return the value from the file
+///
+std::string &
+Ownet::getValue(const std::string &device, std::string file, std::string 
&result)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
 
@@ -171,17 +193,20 @@ Ownet::getValue(const std::string &device, std::string 
file)
     //std::cout << "Looking for: " << data;
     int ret = OW_get(data.c_str(), &buf, &s);
     if (ret <= 0) {
-        return std::string();
+        return result;
         //} else {
         //std::cout << ", Got(" << s << "): " <<  buf;
     }
     
-    std::string value = (buf);
+    result = (buf);
     free(buf);
     
-    return value;
+    return result;
 }
 
+///
+/// Dump data about the sensors
+///
 void
 Ownet::dump(void)
 {
diff --git a/devices/ownet.h b/devices/ownet.h
index 49838cc..c6631db 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -32,14 +32,19 @@
 extern const int OWPORT;
 extern const char *OWHOST;
 
-// Data for each sensor
-struct ownet {
+/// \typedef ownet_t
+/// Holds data for an ownet connection
+typedef struct ownet {
     std::string family;
     std::string id;
     std::string type;
     std::string device;
-} typedef ownet_t;
+} ownet_t;
 
+///
+/// \class Ownet
+/// Construct a class for the ownet protocol
+///
 class Ownet
 {
 private:
@@ -75,7 +80,7 @@ public:
     bool hasSensors(void) { return (_sensors.size() > 0) ? true : false; };
 
     // extract a value from an owfs file
-    std::string getValue(const std::string &device, std::string file);
+    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) {
diff --git a/devices/serial.cc b/devices/serial.cc
index c76ff1a..3157ba3 100644
--- a/devices/serial.cc
+++ b/devices/serial.cc
@@ -68,7 +68,8 @@ const char *serial_speeds[] = {
 };
 
 
-// Translate baud rates from integers to damn B_codes.
+/// \struct damnbaud
+/// Translate baud rates from integers to damn B_codes.
 struct damnbaud {
     int rate;
     int code;
@@ -98,6 +99,10 @@ struct damnbaud baudtab[] = {
     {-1, -1},
 };
 
+///
+/// \function rate_to_code
+/// @param The baud rate as a number
+/// @return The constant for this baud rate
 int
 rate_to_code(int rate) {
     int i;
@@ -109,6 +114,8 @@ rate_to_code(int rate) {
     return -1;
 }
 
+/// \class
+/// Construct a class for handing serial port communication
 Serial::Serial(void)
 {
     // DEBUGLOG_REPORT_FUNCTION;
@@ -125,8 +132,10 @@ Serial::~Serial(void)
     //Close();
 }
 
-// Open the serial port. This function must initialize the serial port so that
-// it can be read/write in raw mode.
+/// Open the serial port. This function must initialize the serial port so that
+/// it can be read/write in raw mode.
+/// @param The full path to the serial port to open
+/// @return Whether the file could be opened or not
 retcode_t
 Serial::Open(std::string &filespec)
 {
@@ -176,7 +185,8 @@ Serial::Open(std::string &filespec)
     return SUCCESS;
 }
 
-// Close the serial port
+/// Close the serial port
+/// @return Whether the file could be closed or not
 retcode_t
 Serial::Close(void)
 {
@@ -195,6 +205,9 @@ Serial::Close(void)
     return ERROR;
 }
 
+/// Flush data in the serial port so it gets out
+///
+/// @return Whether the file could be closed or not
 retcode_t
 Serial::Flush  (void)
 {
@@ -203,6 +216,12 @@ Serial::Flush  (void)
     return SUCCESS;               // FIXME: this should be a real check
 }
 
+
+/// Read data from the serial port
+///
+/// @param buf A buffer to hold the data that is read
+/// @param nbytes The size of the buffer
+/// @return The number of bytes read
 int
 Serial::Read(char *buf, int nbytes)
 {
@@ -332,6 +351,11 @@ if ((sret == 0) && (ret <= 0)) {
 return ret;
 }
 
+/// Write data to the serial port
+///
+/// @param buf A buffer holding the data to write
+/// @param nbytes The size of the buffer
+/// @return The number of bytes written or -1 for an error
 int
 Serial::Write(const char *buf, int nbytes) const
 {
@@ -358,6 +382,10 @@ Serial::Write(const char *buf, int nbytes) const
     }
 }
 
+/// Set the baud rate
+///
+/// @param The baud rate code as returned by rate_to_code()
+/// @return Whether the baud rate could be set
 retcode_t
 Serial::SetBaud (int baudcode)
 {
@@ -395,6 +423,7 @@ Serial::SetBaud (int baudcode)
 }
 
 #if 0
+/// @return Whether the file could be closed or not
 retcode_t
 Serial::send_break (struct errcond *err) const
 {
@@ -406,6 +435,10 @@ Serial::send_break (struct errcond *err) const
 }
 #endif
 
+/// Set whether the serial port shoul duse blocking or nonblocking I/O
+///
+/// @param 
+/// @return Whether the blocking mode could be changed
 retcode_t
 Serial::SetBlocking(bool mode)
 {
@@ -425,12 +458,19 @@ Serial::SetBlocking(bool mode)
 // TIOCM_LE, TIOCM_DTR, TIOCM_RTS, TIOCM_ST, TIOCM_SR, TIOCM_CTS,
 // TIOCM_CAR, TIOCM_RNG, TIOCM_DSR, TIOCM_CD, TIOCM_RI,
 // TIOCM_OUT1,IOCM_OUT2, TIOCM_LOOP
+
+/// Set the DTR for the serial port
+/// @return Whether the DTR could be set
 retcode_t
 Serial::SetDTR (void)
 {
     return SetDTR(true);
 }
 
+/// Set the DTR for the serial port
+///
+/// @param What to set the DTR to
+/// @return Whether the DTR could be set
 retcode_t
 Serial::SetDTR (bool value)
 {
@@ -455,6 +495,8 @@ Serial::SetDTR (bool value)
     return SUCCESS;               // FIXME: this should be a real check
 }
 
+/// Set Raw mode for th serial port
+/// @return Whether the serial port could be set to raw mode
 retcode_t
 Serial::SetRaw (void)
 {
diff --git a/devices/serial.h b/devices/serial.h
index f50af22..71bdaed 100644
--- a/devices/serial.h
+++ b/devices/serial.h
@@ -1,6 +1,6 @@
 // 
-// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
-//      Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
+// 2014, 2015 2016. 2017, 2018, 2019 Free Software Foundation, Inc.
 // 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
diff --git a/lib/log.cc b/lib/log.cc
index 2461cf6..404eb2c 100644
--- a/lib/log.cc
+++ b/lib/log.cc
@@ -26,8 +26,12 @@
 #include <time.h>
 #include "log.h"
 
-src::logger lg;
+src::logger lg;                 ///< Global handle to the logger
 
+/// \function log_init
+///
+/// Write a logfile to the disk and the console
+/// @param The name of the log file to write
 void
 log_init(const std::string &name)
 {
diff --git a/lib/log.h b/lib/log.h
index 19d501c..2b962a1 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -74,6 +74,8 @@ extern void log_init(const std::string &name);
 #define TIMESTAMP_LENGTH 24             // timestamp length
 #define TIMESTAMP_FORMAT "%Y-%m-%d %H:%M:%S     " // timestamp format
 
+/// \struct __Host_Function_Report__
+/// Struct/class to print an enter/return for a method
 struct __Host_Function_Report__ {
     const char *func;
     src::logger lg;
@@ -101,9 +103,6 @@ struct __Host_Function_Report__ {
 
 #define DEBUGLOG_REPORT_RETURN
 
-unsigned char *
-ascify_buffer (unsigned char *p, const unsigned char *s, int x);
-
 #else
 # define DEBUGLOG_REPORT_FUNCTION printf("%s entered\n", __FUNCTION__)
 # define DEBUGLOG_REPORT_RETURN printf("%s return\n", __FUNCTION__)

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

Summary of changes:
 devices/onewire.cc             | 207 +++++++++++++++++++++++------------------
 devices/onewire.h              | 128 +++++++++++++------------
 devices/ownet.cc               |  73 ++++++++++-----
 devices/ownet.h                |  26 ++++--
 devices/serial.cc              |  50 +++++++++-
 devices/serial.h               |   4 +-
 lib/database.h                 |  76 ++++++++++++---
 lib/log.cc                     |   6 +-
 lib/log.h                      |   5 +-
 powerguru.sql                  |  11 +++
 testsuite/libtests/Makefile.am |  15 ++-
 testsuite/libtests/db-test.cc  | 176 +++++++++++++++++++++++++++++++++++
 12 files changed, 570 insertions(+), 207 deletions(-)
 create mode 100644 testsuite/libtests/db-test.cc


hooks/post-receive
-- 
powerguru



reply via email to

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