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. 0c47e74d1635


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 0c47e74d16350892beddfc93e4c0815831719e1c
Date: Fri, 28 Dec 2018 17:02:00 -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  0c47e74d16350892beddfc93e4c0815831719e1c (commit)
       via  cccbfe19ac25889898cb765a34f993bdd4917f34 (commit)
       via  20d83415925fb57c13b7a14aea655acc10a30f50 (commit)
       via  65387678abcd3f41ce8c6812ea92e989c372b69c (commit)
       via  89260cbe6325f01c5a087e111126bd210f60cce0 (commit)
      from  c0c819e26cf34406d741033bfdd32e5932b36eff (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=0c47e74d16350892beddfc93e4c0815831719e1c


commit 0c47e74d16350892beddfc93e4c0815831719e1c
Author: Rob Savoye <address@hidden>
Date:   Fri Dec 28 15:01:46 2018 -0700

    Cleanup shared_ptr usage, remove unused headers

diff --git a/devices/Makefile.am b/devices/Makefile.am
index ec1e839..a188a70 100644
--- a/devices/Makefile.am
+++ b/devices/Makefile.am
@@ -1,6 +1,5 @@
-# 
-# Copyright (C) 2005, 2006, 2007, 2008,        2009, 2010, 2011
-#      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
@@ -31,7 +30,7 @@ address@hidden@
 # These headers get installed
 # include_HEADERS = log.h err.h proc.h serial.h xantrex.h outback.h
 
-libpdev_la_CPPFLAGS = -I$(top_srcdir)/lib -I..
+libpdev_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I..
 libpdev_la_LIBDADD = -lboost_filesystem
 
 libpdev_la_SOURCES = onewire.cc
diff --git a/devices/onewire.cc b/devices/onewire.cc
index 2d8f454..293706d 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -1,6 +1,5 @@
 // 
-// Copyright (C) 2018
-//      Free Software Foundation, Inc.
+// Copyright (C) 2018 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
@@ -16,26 +15,24 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "log.h"
-#include "onewire.h"
 #include <string>
 #include <boost/algorithm/string.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
-#include<iostream>
-#include<fstream>
+#include <iostream>
+#include <cstdio>
+#include "onewire.h"
 
 extern LogFile dbglogfile;
 
 Onewire::Onewire(void)
+    : _scale('F'),
+      _poll_sleep(300),
+    _mounted(false),
+    _rootdir("/mnt/1wire")
 {
     DEBUGLOG_REPORT_FUNCTION;
 
-    _rootdir = "/mnt/1wire";
     boost::filesystem::path p(_rootdir);
     try {
         if (boost::filesystem::exists(p) & boost::filesystem::is_directory(p)) 
{
@@ -53,6 +50,7 @@ Onewire::Onewire(void)
             }
         } else {
             std::cerr << "ERROR: " << _rootdir << " doesn't exist" << 
std::endl;
+            _mounted = false;
         }
     } catch (const boost::filesystem::filesystem_error& ex) {
         std::cout << ex.what() << std::endl;
@@ -68,6 +66,11 @@ Onewire::setValue(const std::string &device, const 
std::string &file,
 {
     DEBUGLOG_REPORT_FUNCTION;
 
+    // Don't try to do anything if the owfs isn't mounted and we somehow got 
here anyway.
+    if (!_mounted) {
+        return;
+    }
+
     std::string filespec;
     if (!device.empty()) {
         filespec = device +"/";
@@ -87,6 +90,11 @@ Onewire::getValue(const std::string &device, std::string 
file, std::string &resu
 {
 //    DEBUGLOG_REPORT_FUNCTION;
 
+    // Don't try to do anything if the owfs isn't mounted and we somehow got 
here anyway.
+    if (!_mounted) {
+        return result;
+    }
+
     std::string filespec;
     if (!device.empty()) {
         filespec = device +"/";
@@ -94,20 +102,25 @@ Onewire::getValue(const std::string &device, std::string 
file, std::string &resu
         filespec = _rootdir; 
     }
     filespec += file;
-    std::ifstream entry(filespec);
-    entry >> result;
-    entry.close();
-    std::cerr << "Getting " << filespec << ", value: " << result<< std::endl;
-
+    try {
+        std::ifstream entry(filespec);
+        entry.rdbuf()->pubsetbuf(0, 0);
+        entry >> result;
+        entry.close();
+    } catch (const std::exception& e) {
+        dbglogfile << "Warning: iostream failure! " << e.what() << std::endl;
+    }
+    //std::cerr << "Getting " << filespec << ", value: " << result<< std::endl;
     return result;
 }
 
 std::map<std::string, boost::shared_ptr<temperature_t>> &
 Onewire::getTemperatures(void)
 {
-    DEBUGLOG_REPORT_FUNCTION;
+    //DEBUGLOG_REPORT_FUNCTION;
 
     _temps.clear();
+
     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);
diff --git a/devices/onewire.h b/devices/onewire.h
index f5435fe..7f27ba3 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -1,6 +1,5 @@
 // 
-// Copyright (C) 2018.
-//      Free Software Foundation, Inc.
+// Copyright (C) 2018 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
@@ -19,20 +18,14 @@
 #ifndef __ONEWIRE_H__
 #define __ONEWIRE_H__
 
-// This is generated by autoconf
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include <mutex>
 #include <string>
 #include <vector>
 #include <map>
-#include <log.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
-#include "database.h"
 #include <boost/filesystem.hpp>
+#include "log.h"
 
 extern LogFile dbglogfile;
 
@@ -59,15 +52,17 @@ class Onewire {
 private:
     std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
     std::mutex _mutex;
-    int _poll_sleep = 60;
-    char _scale = 'F';
+    int _poll_sleep;
+    char _scale;
     std::string _rootdir;
     std::map<std::string, boost::shared_ptr<temperature_t>> _temps;
+    bool _mounted = true;
 public:
     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.
diff --git a/devices/ownet.cc b/devices/ownet.cc
index 5e74115..575ae91 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -37,6 +37,7 @@ Ownet::Ownet(void)
 }
 
 Ownet::Ownet(std::string &host)
+    : Ownet()
 {
     DEBUGLOG_REPORT_FUNCTION;
 
@@ -46,7 +47,7 @@ Ownet::Ownet(std::string &host)
     }
     dbglogfile << "Trying to connect to the owserver on " << host << std::endl;
 
-    // OW_init() takes what looks like a stadard command line
+    // OW_init() takes what looks like a standard command line
     std::string argv = "-s " + host;
 
     // On my machine, it never seems to connect on the first attempt,
@@ -84,7 +85,7 @@ Ownet::Ownet(std::string &host)
         }
     }
 
-    // Iterate through all the directorys in the root dir
+    // Iterate through all the directories in the root dir
     int i = 0;
     std::vector<std::string>::iterator it;
     for(it = results.begin(); it != results.end(); it++,i++ ) {
@@ -106,7 +107,7 @@ Ownet::Ownet(std::string &host)
     }
 }
 
-boost::shared_ptr<temperature_t> &
+const boost::shared_ptr<temperature_t>
 Ownet::getTemperature(const std::string &device)
 {
     // DEBUGLOG_REPORT_FUNCTION;
@@ -137,7 +138,7 @@ Ownet::getTemperature(const std::string &device)
     return temp;
 }
 
-std::vector<std::string> &
+const std::vector<std::string>
 Ownet::listDevices(std::vector<std::string> &list)
 {
     DEBUGLOG_REPORT_FUNCTION;
diff --git a/devices/ownet.h b/devices/ownet.h
index bd7ad2c..f7c708b 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -80,20 +80,20 @@ public:
     std::string getValue(const std::string &device, std::string file);
 
     // return a handle to all the sensors
-    boost::shared_ptr<ownet_t> &getSensor(const std::string &device) {
+    const boost::shared_ptr<ownet_t> &getSensor(const std::string &device) {
         return _sensors[device];
     };
 
-    std::map<std::string, boost::shared_ptr<ownet_t>> &getSensors(void) {
+    const std::map<std::string, boost::shared_ptr<ownet_t>> getSensors(void) {
         return _sensors;
     };
     
     // get all the temperature fields for a device.
-    boost::shared_ptr<temperature_t> &getTemperature(const std::string 
&device);
+    const boost::shared_ptr<temperature_t> getTemperature(const std::string 
&device);
     
     void dump(void);
     
-    std::vector<std::string> &
+    const std::vector<std::string>
     listDevices(std::vector<std::string> &list);
 };
 

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


commit cccbfe19ac25889898cb765a34f993bdd4917f34
Author: Rob Savoye <address@hidden>
Date:   Fri Dec 28 14:58:24 2018 -0700

    Add a target to run cppclean

diff --git a/Makefile.am b/Makefile.am
index cd9479f..8f3dab0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -103,6 +103,16 @@ mudflap:
 apidoc:
        $(MAKE) -C doc $@
 
+# Google's C++ utility https://github.com/myint/cppclean
+cppclean:
+       @-cppclean --include-path=. --include-path=$(top_srcdir)/lib 
$(top_srcdir)/devices >& /tmp/cppclean.tmp
+       @echo ""
+       @echo "Static data, be careful in threads"
+       @grep "static data" /tmp/cppclean.tmp
+       @echo ""
+       @echo "Other issues found by cppclean"
+       @grep -v "static data" /tmp/cppclean.tmp
+
 dump:
        @echo "Dumping configure options"
 if BUILD_SNMP

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


commit 20d83415925fb57c13b7a14aea655acc10a30f50
Author: Rob Savoye <address@hidden>
Date:   Fri Dec 28 14:16:14 2018 -0700

    Move more code to the source file

diff --git a/devices/ownet.cc b/devices/ownet.cc
index ad3b9d9..5e74115 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -1,6 +1,5 @@
 // 
-// Copyright (C) 2005, 2006 - 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
@@ -16,59 +15,65 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "log.h"
-#include "ownet.h"
 #include <string>
 #include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include "ownet.h"
 
-extern LogFile dbglogfile;
+//extern LogFile dbglogfile;
+#define dbglogfile std::cerr
 
-//const char DEFAULT_ARGV[] = "--fake 28 --fake 10";
-const char DEFAULT_ARGV[] = "-s 192.168.0.50:4304";
+// Default host and port for the owserver
+const int OWPORT = 4304;
+const char *OWHOST = "localhost";
 
-Ownet::Ownet(const std::string &host)
+Ownet::Ownet(void)
+    : _poll_sleep(60),
+      _scale('F'),
+      _owserver(false)
 {
-//    DEBUGLOG_REPORT_FUNCTION;
+    DEBUGLOG_REPORT_FUNCTION;
+}
 
-    dbglogfile << "Trying to connect to the owserver" << std::endl;
-    char *buf = 0;
-    size_t s  = 0;
+Ownet::Ownet(std::string &host)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+
+    int retries = 2;
+    if (host.find(':') == std::string::npos) {
+        host += ":" + std::to_string(OWPORT);
+    }
+    dbglogfile << "Trying to connect to the owserver on " << host << std::endl;
 
-    //OW_init("/dev/ttyS0");
-    int count = 5;
-    std::string hostname = "-s " + host;
-    const char *argv = hostname.c_str();
+    // OW_init() takes what looks like a stadard command line
+    std::string argv = "-s " + host;
 
-    while (count-- > 0) {
-        if (OW_init(argv) < 0) {
-            dbglogfile << "WARNING: Couldn't connect to owserver!" << 
std::endl;
+    // On my machine, it never seems to connect on the first attempt,
+    // but always does on the second.
+    while (retries-- > 0) {
+        if (OW_init(argv.c_str()) < 0) {
+            dbglogfile << "WARNING: Couldn't connect to owserver with " << 
argv << std::endl;
             //return;
         } else {
-            dbglogfile << "Connected to owserver." << std::endl;
+            dbglogfile << "Connected to owserver on host " << host << 
std::endl;
             _owserver = true;
             break;
         }
     }
-    // 0=mixed  output,  1=syslog, 2=console.
-    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("0");
-    OW_get("/", &buf, &s);
-    // buf looks like:
-    // 
10.67C6697351FF/,05.4AEC29CDBAAB/,bus.0/,uncached/,settings/,system/,statistics/,structure/,simultaneous/,alarm/
-    //
-    //if (s <= 0) {
-    //    dbglogfile << "S: " << (int)s << std::endl;
-    // return;
-    //}
 
+    // Setup ownet
+    OW_set_error_print("2"); // 0=mixed  output,  1=syslog, 2=console.
+    OW_set_error_level("0"); // (0=default, 1=err_connect, 2=err_call,
+                             // 3=err_data, 4=err_detail,
+                             // 5=err_debug, 6=err_beyond)
+    // Set the default temperature scale, 'F' or 'C'
     OW_put("/settings/units/temperature_scale", &_scale, 1);
 
+    // Get a directory listing of the rootdir
+    char *buf = 0;
+    size_t s  = 0;
+    OW_get("/", &buf, &s);
     std::vector<std::string> results;
     if (buf != 0) {
         boost::split(results, buf, boost::is_any_of(","));
@@ -79,10 +84,11 @@ Ownet::Ownet(const std::string &host)
         }
     }
 
+    // Iterate through all the directorys in the root dir
     int i = 0;
     std::vector<std::string>::iterator it;
     for(it = results.begin(); it != results.end(); it++,i++ ) {
-        ownet_t *data = new ownet_t[1];
+        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");
@@ -100,18 +106,84 @@ Ownet::Ownet(const std::string &host)
     }
 }
 
-void Ownet::dump(void)
+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");
+    
+    if (family == "10" | family == "28") {
+        // dbglogfile << device << " is a thermometer" << std::endl;
+        // 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");
+        temp->temp = std::stof(getValue(device, "temperature"));
+        temp->lowtemp =std::stof(getValue(device, "templow"));
+        temp->hightemp = std::stof(getValue(device, "temphigh"));
+        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;
+}
+
+std::vector<std::string> &
+Ownet::listDevices(std::vector<std::string> &list)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+    
+    std::map<std::string, boost::shared_ptr<ownet_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);
+    }
+    return list;
+}
+
+std::string
+Ownet::getValue(const std::string &device, std::string file)
+{
+    char * buf;
+    size_t s  = 0;
+    
+    std::string data = device + file;
+    //std::cout << "Looking for: " << data;
+    int ret = OW_get(data.c_str(), &buf, &s);
+    if (ret <= 0) {
+        return std::string();
+        //} else {
+        //std::cout << ", Got(" << s << "): " <<  buf << std::endl;
+    }
+    
+    std::string value = (buf);
+    free(buf);
+    
+    return value;
+}
+
+void
+Ownet::dump(void)
 {
 //    DEBUGLOG_REPORT_FUNCTION;
 
-    std::map<std::string, ownet_t *>::iterator sit;
+    std::map<std::string, boost::shared_ptr<ownet_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::map<std::string, temperature_t *>::iterator tit;
+    // std::map<std::string, boost::shared_ptr<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;
diff --git a/devices/ownet.h b/devices/ownet.h
index 2e644ac..bd7ad2c 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -1,6 +1,5 @@
 // 
-// Copyright (C) 2005, 2006-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
@@ -19,24 +18,23 @@
 #ifndef __OWNET_H__
 #define __OWNET_H__
 
-// This is generated by autoconf
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include <mutex>
 #include <string>
 #include <vector>
 #include <map>
-#include <log.h>
 #include <owcapi.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
-#include "database.h"
 #include "onewire.h"
+#include "log.h"
 
 extern LogFile dbglogfile;
 
+// Default host and port for the owserver
+extern const int OWPORT;
+extern const char *OWHOST;
+
+// Data for each sensor
 struct ownet {
     std::string family;
     std::string id;
@@ -44,140 +42,59 @@ struct ownet {
     std::string device;
 } typedef ownet_t;
 
-class Ownet {
+class Ownet
+{
 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::mutex _mutex;
-    int poll_sleep = 60;
-    char _scale = 'F';
+    std::map<std::string, boost::shared_ptr<ownet_t>> _sensors;
+    bool        _owserver;
+    std::mutex  _mutex;
+    int         _poll_sleep;
+    char        _scale;
 public:
     Ownet(void);
-    Ownet(const std::string &host);
+    Ownet(std::string &host);
     ~Ownet(void) {
-        OW_finish();
+        DEBUGLOG_REPORT_FUNCTION;
+        if (_owserver) {
+            OW_finish();
+        }
     };
 
-    char setScale(char scale) { OW_put("/settings/units/temperature_scale", 
&_scale, 1); };
+    void 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) {
-        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 we're connected to the owserver
+    bool isConnected(void) { return _owserver; };
 
-    // see if we're connected to the owserver
-    bool isConnected(void) {
-        return _owserver;
-    }
-
-    // see if any 1 wire sensors were found during scanning
-    bool hasSensors(void) {
-        if (_sensors.size() >0) {
-            return true;
-        } else {
-            return false;
-        }
-    }
+    // See if any 1 wire sensors were found during scanning
+    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) {
-//        DEBUGLOG_REPORT_FUNCTION;
-        char * buf;
-        size_t s  = 0;
-
-        std::string data = device + file;
-        //std::cout << "Looking for: " << data;
-        int ret = OW_get(data.c_str(), &buf, &s);
-        if (ret <= 0) {
-            return std::string();
-            //} else {
-            //std::cout << ", Got(" << s << "): " <<  buf << std::endl;
-        }
-
-        std::string value = (buf);
-        free(buf);
-
-        return value;
-    }
+    std::string getValue(const std::string &device, std::string file);
 
     // return a handle to all the sensors
-    ownet_t *getSensor(const std::string &device) {
+    boost::shared_ptr<ownet_t> &getSensor(const std::string &device) {
         return _sensors[device];
-    }
+    };
 
-    std::map<std::string, ownet_t *> &getSensors(void) {
+    std::map<std::string, boost::shared_ptr<ownet_t>> &getSensors(void) {
         return _sensors;
-    }
-
+    };
+    
     // get all the temperature fields for a 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");
-
-        if (family == "10" | family == "28") {
-            // dbglogfile << device << " is a thermometer" << std::endl;
-            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"));
-            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;
-    }
-
+    boost::shared_ptr<temperature_t> &getTemperature(const std::string 
&device);
+    
     void dump(void);
-#if 0
-        {
-        DEBUGLOG_REPORT_FUNCTION;
-
-        std::map<std::string, ownet_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::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;
-        }
-    }
-#endif
     
     std::vector<std::string> &
-    listDevices(std::vector<std::string> &list) {
-        DEBUGLOG_REPORT_FUNCTION;
-
-        std::map<std::string, ownet_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);
-        }
-        return list;
-    }
-
+    listDevices(std::vector<std::string> &list);
 };
 
 // __OWNET_H__

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


commit 65387678abcd3f41ce8c6812ea92e989c372b69c
Author: Rob Savoye <address@hidden>
Date:   Fri Dec 28 11:01:39 2018 -0700

    Move old code for outback and xantrex to a thread

diff --git a/daemon/main.cc b/daemon/main.cc
index 6d53852..ffd1481 100644
--- a/daemon/main.cc
+++ b/daemon/main.cc
@@ -63,29 +63,26 @@ include "xantrex-trace.h"
 #include "commands.h"
 #include "onewire.h"
 
-using namespace std;
 using namespace rcinit;
 
-static void usage (const char *);
 extern LogFile dbglogfile;
-const int INBUFSIZE = 1024;
-
-void
-alarm_handler2 (int sig);
 
-int curses = 0;
+static void usage (const char *);
 
+// Protoypes for the threads entry point
 extern void onewire_handler(Onewire &ow);
 extern void client_handler(Tcpip &net);
 extern void ownet_handler(Ownet &);
 extern void outback_handler(Ownet &);
 extern void xantrex_handler(Ownet &);
 
+// This queue is used to pass data between the threads.
 std::mutex queue_lock;
 std::queue <XML> tqueue;
 std::condition_variable queue_cond;
 
-const char DEFAULT_ARGV[] = "-s 192.168.0.50:4304";
+// Note that an entry for 'pi' needs to be in /etc/hosts.
+const char DEFAULT_ARGV[] = "-s pi:4304";
 
 int
 main(int argc, char *argv[])
@@ -93,61 +90,31 @@ main(int argc, char *argv[])
     int c, i;
     std::string item, str;
     const char *filespec;
-    MenuItem ti;
     std::string hostname;
     std::string owserver;
-    bool poll;
-    bool use_db;
     bool snmp;
     bool daemon;
     bool client;
-    bool echo;
-#if 0
-    bool setitem;
-    bool getitem;
-    bool monitor;
-    bool outbackmode;
-    bool xantrexmode;
-    bool background;
-#endif
     retcode_t   ret;
     std::condition_variable alldone;
-#if defined(HAVE_MARIADB) || defined(HAVE_POSTGRESQL)
-    Database pdb;
-#endif
-    if (argc == 1) {
-        //usage(argv[0]);
-    }
 
     // scan for the two main standard GNU options
-    for (c=0; c<argc; c++) {
+    for (c = 0; c < argc; c++) {
         if (strcmp("--help", argv[c]) == 0) {
             usage(argv[0]);
             exit(0);
         }
         if (strcmp("--version", argv[c]) == 0) {
-            cerr << "PowerGuru version: " << VERSION << endl;
+            std::cerr << "PowerGuru version: " << VERSION << std::endl;
             exit(0);
         }
     }
 
     // Set the option flags to default values. We do it this way to
     // shut up GCC complaining they're not used.
-    poll = false;
     daemon = true;
     client = false;
-    echo = false;
-    use_db = true;
     snmp = false;
-#if 0
-    setitem = false;
-    getitem = false;
-    monitor = false;
-    outbackmode = false;
-    xantrexmode = false;
-    background = false;
-    hostname = "localhost";
-#endif
     // Load the database config variable so they can be overridden by
     // the command line arguments.
     RCinitFile config;
@@ -160,11 +127,6 @@ main(int argc, char *argv[])
     // Process the command line arguments.
     while ((c = getopt (argc, argv, "d:ahvw:s:")) != -1) {
         switch (c) {
-          case 'p':
-              poll = true;
-              //xantrexmode = true;     // FIXME: force xantrex mode for now
-              break;
-
           case 'd':
               filespec = strdup(optarg);
               break;
@@ -208,7 +170,7 @@ main(int argc, char *argv[])
           case 'v':
               // verbosity++;
               dbglogfile.set_verbosity();
-              dbglogfile << "Verbose output turned on" << endl;
+              dbglogfile << "Verbose output turned on" << std::endl;
               break;
        
           default:
@@ -237,7 +199,7 @@ main(int argc, char *argv[])
 
     std::thread client_thread (client_handler, std::ref(net));
 #ifdef BUILD_OWNET
-    Ownet ownet(DEFAULT_ARGV);
+    Ownet ownet(owserver);
     std::thread ownet_thread (ownet_handler, std::ref(ownet));
 #endif
 #ifdef BUILD_XANTREX
@@ -248,73 +210,6 @@ main(int argc, char *argv[])
 //    std::thread forth (msg_handler, std::ref(pdb));
 #endif
     
-#ifdef BUILD_OUTBACK
-    // Network daemon/client mode. Normally we're a network daemon that
-    // responses to requests by a remote client. Many house networks
-    // are behind a firewall, so the daemon can also connect to a
-    // publically accessible host to establish the connection the
-    // other direction.
-    if (daemon || client) {
-      
-        Msgs msg;
-        msg.toggleDebug(true);
-        // Make a client connection
-        if (client == true) {
-            msg.init(hostname);
-        }
-      
-        // Start as a daemon
-        if (daemon == true) {
-            msg.init(true);
-        }
-        //msg.methodsDump();          // FIXME: debugging crap
-      
-        //msg.print_msg(msg.status((meter_data_t *)0));
-      
-        if (client) {
-            msg.writeNet(msg.metersRequestCreate(Msgs::BATTERY_VOLTS));
-        }
-      
-        //      msg.cacheDump();
-      
-        XML xml;
-        unsigned int i;
-
-        vector<const xmlChar *> messages;        
-        bool loop = true;
-        while (loop) {
-            ret = msg.anydata(messages);
-            if (ret == ERROR) {
-                dbglogfile << "ERROR: Got error from socket " << endl;
-                msg.closeNet();
-                // wait for the next connection
-                if ((ret = msg.newNetConnection(true))) {
-                    dbglogfile << "New connection started for remote client."
-                               << msg.remoteIP().c_str()
-                               << msg.remoteName().c_str() << endl;
-                    ret = SUCCESS;        // the error has been handled
-                    continue;
-                }
-            }
-            if (messages.size() == 0) {
-                dbglogfile << "ERROR: client socket shutdown! " << endl;
-            }
-            for (i=0; i < messages.size(); i++) {
-                cerr << "Got (" << messages.size() << ") messages " << 
messages[i] << endl;
-                string str = (const char *)messages[i];
-                delete messages[i];
-                if (msg.findTag("command")) {
-                    cerr << "Got command message!" << endl;
-                }
-                if (xml.parseMem(str) == ERROR) {
-                    continue;
-                }
-            }
-            messages.clear();
-        }
-    }
-#endif
-
     // Commands from the client via the client_handler get processed here
     // so messages can be passed between threads.
     while (true) {
@@ -349,79 +244,41 @@ main(int argc, char *argv[])
     exit(0);
 }
 
-
-// signal handler for displaying item values
-void
-alarm_handler2 (int sig)
-{
-    DEBUGLOG_REPORT_FUNCTION;
-    ostringstream oss;
-    struct sigaction  act;
-#if 0
-    int ch;
-  
-#if 1
-    // If there is keyboard input, stop looking for the old
-    // output.
-    ch = con.Getc();
-    if (ch > 0) {
-        alarm(0);
-        con.Ungetc(ch);
-        return;
-    }
-#else
-    datasrc.RecvPacket((unsigned char *)&ch, 1);
-    dbglogfile << " CH is " << ch << endl;
-  
-    if (ch > 0) {
-        alarm(0);
-        con.Ungetc(ch);
-        return;
-    }
-#endif
-#endif
-  
-    act.sa_handler = alarm_handler2;
-    sigaction (SIGALRM, &act, NULL);
-  
-    alarm(1);
-}
-
 static void
 usage (const char *prog)
 {
-    cerr <<"This program implements a command line interface" << endl; 
-    cerr << "for an inverter or charge controller" << endl;
-    cerr << "Usage: " << prog << " [sglvphmdcx]" << endl;
+    std::cerr <<"This program implements a command line interface" << 
std::endl; 
+    std::cerr << "for an inverter or charge controller" << std::endl;
+    std::cerr << "Usage: " << prog << " [sglvphmdcx]" << std::endl;
 
 #if 0
     // enable SNMP daemon mode
-    cerr << "SNMP Mode:" << endl;
-    cerr << "\t-j\t\t\t\tEnable SNMP agent mode" << endl;
-    cerr << "\t-r\t\t\t\trun in the background as a daemon." << endl;
+    std::cerr << "SNMP Mode:" << std::endl;
+    std::cerr << "\t-j\t\t\t\tEnable SNMP agent mode" << std::endl;
+    std::cerr << "\t-r\t\t\t\trun in the background as a daemon." << std::endl;
     // Display the End User options
-    cerr << "User Options:" << endl;
-    // cerr << "\t-s [heading:item or name]\tSet Item value" << endl;
-    // cerr << "\t-g [heading:item or name]\tGet Item value" << endl;
-    cerr << "\t-p\t\t\t\tPoll the Meters" << endl;
-    cerr << "\t-l\t\t\t\tLogfile name" << endl;
-    cerr << "\t-v\t\t\t\tVerbose mode" << endl;
-    cerr << "\t-d [filespec]\t\t\tSpecify Serial Port" << endl;
-    cerr << "\t-h\t\t\t\tHelp (this display)" << endl;
-    cerr << "\t-a\t\t\t\tDisplay Command names" << endl;
+    std::cerr << "User Options:" << std::endl;
+    // cerr << "\t-s [heading:item or name]\tSet Item value" << std::endl;
+    // cerr << "\t-g [heading:item or name]\tGet Item value" << std::endl;
+    std::cerr << "\t-p\t\t\t\tPoll the Meters" << std::endl;
+    std::cerr << "\t-l\t\t\t\tLogfile name" << std::endl;
+    std::cerr << "\t-v\t\t\t\tVerbose mode" << std::endl;
+    std::cerr << "\t-d [filespec]\t\t\tSpecify Serial Port" << std::endl;
+    std::cerr << "\t-h\t\t\t\tHelp (this display)" << std::endl;
+    std::cerr << "\t-a\t\t\t\tDisplay Command names" << std::endl;
 
     // Display the Maintainer options
-    cerr << "Maintainer Options:" << endl;
-    cerr << "\t-m head:item\t\t\tMenu Item index" << endl;
-    cerr << "\t-d\t\t\t\tDump internal data" << endl;
-    cerr << "\t-x\t\t\t\tXantrex Console mode" << endl;
-    cerr << "\t-o\t\t\t\tOutback Console mode" << endl;
-    cerr << "\t-e\t\t\t\tEcho Input Mode" << endl;
+    std::cerr << "Maintainer Options:" << std::endl;
+    std::cerr << "\t-m head:item\t\t\tMenu Item index" << std::endl;
+    std::cerr << "\t-d\t\t\t\tDump internal data" << std::endl;
+    std::cerr << "\t-x\t\t\t\tXantrex Console mode" << std::endl;
+    std::cerr << "\t-o\t\t\t\tOutback Console mode" << std::endl;
+    std::cerr << "\t-e\t\t\t\tEcho Input Mode" << std::endl;
 #endif
 
     // Display the Database options
-    cerr << "Database Options:" << endl;
-    cerr << "\t-m hostname\t\t\tSpecify Database hostname or IP" << endl;
+    std::cerr << "Database Options:" << std::endl;
+    std::cerr << "\t-m hostname\t\t\tSpecify Database hostname or IP" << 
std::endl;
 
     exit (-1);
 }
diff --git a/daemon/threads.cc b/daemon/threads.cc
index d29b546..d57ce70 100644
--- a/daemon/threads.cc
+++ b/daemon/threads.cc
@@ -54,6 +54,7 @@ extern LogFile dbglogfile;
 
 using namespace std::chrono_literals;
 
+// This queue is used to pass data between the threads.
 extern std::mutex queue_lock;
 extern std::queue <XML> tqueue;
 extern std::condition_variable queue_cond;
@@ -63,7 +64,6 @@ onewire_handler(Onewire &onewire)
 {
     DEBUGLOG_REPORT_FUNCTION;
     dbglogfile << "PowerGuru - 1 Wire Mode" << std::endl;
-    bool poll = true;
 #ifdef HAVE_LIBPQ
     Database pdb;
     if (!pdb.openDB()) {
@@ -77,9 +77,9 @@ onewire_handler(Onewire &onewire)
     query += "";
     query += ");";
 
-    std::map<std::string, boost::shared_ptr<temperature_t>> temps = 
onewire.getTemperatures();
     std::map<std::string, boost::shared_ptr<temperature_t>>::iterator it;
     while (onewire.getPollSleep() > 0) {
+        std::map<std::string, boost::shared_ptr<temperature_t>> temps = 
onewire.getTemperatures();
         for (it = temps.begin(); it != temps.end(); it++) {
             if ((it->second->family == "10") | (it->second->family == "28")) {
 #ifdef HAVE_LIBPQ
@@ -204,6 +204,9 @@ ownet_handler(Ownet &ownet)
         for (it = sensors.begin(); it != sensors.end(); it++) {
             if ((it->second->family == "10") | (it->second->family == "28")) {
                 boost::shared_ptr<temperature_t> temp = 
ownet.getTemperature(it->first.c_str());
+                if (temp == 0) {
+                    continue;
+                }
 #ifdef HAVE_LIBPQ
                 std::string stamp;
                 stamp = pdb.gettime(stamp);
@@ -233,8 +236,84 @@ void
 outback_handler(Ownet &ownet)
 {
     DEBUGLOG_REPORT_FUNCTION;
+#if 0
+    setitem = false;
+    getitem = false;
+    monitor = false;
+    outbackmode = false;
+    xantrexmode = false;
+    background = false;
+    hostname = "localhost";
+#endif
+
+#ifdef BUILD_OUTBACK
+    // Network daemon/client mode. Normally we're a network daemon that
+    // responses to requests by a remote client. Many house networks
+    // are behind a firewall, so the daemon can also connect to a
+    // publically accessible host to establish the connection the
+    // other direction.
+    if (daemon || client) {
+      
+        Msgs msg;
+        msg.toggleDebug(true);
+        // Make a client connection
+        if (client == true) {
+            msg.init(hostname);
+        }
+      
+        // Start as a daemon
+        if (daemon == true) {
+            msg.init(true);
+        }
+        //msg.methodsDump();          // FIXME: debugging crap
+      
+        //msg.print_msg(msg.status((meter_data_t *)0));
+      
+        if (client) {
+            msg.writeNet(msg.metersRequestCreate(Msgs::BATTERY_VOLTS));
+        }
+      
+        //      msg.cacheDump();
+      
+        XML xml;
+        unsigned int i;
+
+        vector<const xmlChar *> messages;        
+        bool loop = true;
+        while (loop) {
+            ret = msg.anydata(messages);
+            if (ret == ERROR) {
+                dbglogfile << "ERROR: Got error from socket " << endl;
+                msg.closeNet();
+                // wait for the next connection
+                if ((ret = msg.newNetConnection(true))) {
+                    dbglogfile << "New connection started for remote client."
+                               << msg.remoteIP().c_str()
+                               << msg.remoteName().c_str() << endl;
+                    ret = SUCCESS;        // the error has been handled
+                    continue;
+                }
+            }
+            if (messages.size() == 0) {
+                dbglogfile << "ERROR: client socket shutdown! " << endl;
+            }
+            for (i=0; i < messages.size(); i++) {
+                cerr << "Got (" << messages.size() << ") messages " << 
messages[i] << endl;
+                string str = (const char *)messages[i];
+                delete messages[i];
+                if (msg.findTag("command")) {
+                    cerr << "Got command message!" << endl;
+                }
+                if (xml.parseMem(str) == ERROR) {
+                    continue;
+                }
+            }
+            messages.clear();
+        }
+    }
+#endif
 
-    dbglogfile << "FIXME: outback_handler() unimplementd"<< std::endl;
+    dbglogfile << "FIXME: outback_handler() unimplemented"<< std::endl;
     // Don't eat up all the cpu cycles!
     std::this_thread::sleep_for(std::chrono::seconds(ownet.getPollSleep()));
 }
@@ -245,6 +324,15 @@ void
 xantrex_handler(Ownet &ownet)
 {
     DEBUGLOG_REPORT_FUNCTION;
+#if 0
+    setitem = false;
+    getitem = false;
+    monitor = false;
+    outbackmode = false;
+    xantrexmode = false;
+    background = false;
+    hostname = "localhost";
+#endif
 
     dbglogfile << "FIXME: xantrext_handler() unimplemented"<< std::endl;
     // Don't eat up all the cpu cycles!

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


commit 89260cbe6325f01c5a087e111126bd210f60cce0
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:54:23 2018 -0700

    Add tests for the boost libraries

diff --git a/configure.ac b/configure.ac
index 1a82c2b..3bb4f71 100644
--- a/configure.ac
+++ b/configure.ac
@@ -354,6 +354,40 @@ if test x"${has_boost}" = x"no"; then
 fi
 AC_MSG_RESULT([${has_boost}])
 
+AC_MSG_CHECKING([For Boost filesystem development files])
+AC_TRY_COMPILE([#include <boost/filesystem.hpp>], [
+  boost::filesystem::path p("/tmp");
+  ],
+  has_boost_filesystem=yes,
+  has_boost_filesystem=no
+)
+AC_MSG_RESULT([${has_boost_filesystem}])
+
+AC_MSG_CHECKING([For Boost regex development files])
+AC_TRY_COMPILE([#include <boost/regex.hpp>], [
+  boost::regex re;
+  ],
+  has_boost_regex=yes,
+  has_boost_regex=no
+)
+AC_MSG_RESULT([${has_boost_regex}])
+
+AC_MSG_CHECKING([For Boost system development files])
+AC_TRY_COMPILE([#include <boost/system/error_code.hpp>], [
+  boost::system::error_code be;
+  ],
+  has_boost_system=yes,
+  has_boost_system=no
+)
+AC_MSG_RESULT([${has_boost_system}])
+
+dnl We need all of these boost libraries
+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"
+
 AC_MSG_CHECKING([For DejaGnu])
 AC_TRY_COMPILE([#include <dejagnu.h>], [
    TestState test;

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

Summary of changes:
 Makefile.am         |  10 +++
 configure.ac        |  34 +++++++++
 daemon/main.cc      | 207 ++++++++--------------------------------------------
 daemon/threads.cc   |  94 +++++++++++++++++++++++-
 devices/Makefile.am |   7 +-
 devices/onewire.cc  |  47 +++++++-----
 devices/onewire.h   |  17 ++---
 devices/ownet.cc    | 155 ++++++++++++++++++++++++++++-----------
 devices/ownet.h     | 159 ++++++++++------------------------------
 9 files changed, 358 insertions(+), 372 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

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