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


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. c0c819e26cf34406d741033bfdd32e5932b36eff
Date: Sun, 23 Dec 2018 15:17:41 -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  c0c819e26cf34406d741033bfdd32e5932b36eff (commit)
       via  53105405788461170b8ea44022676b98ee73469b (commit)
       via  140850dc89315faa7a3bdbb763e0d526366a68d3 (commit)
       via  0cd0ea9f015ccd7c549c5405b084bfe7ef81ce5c (commit)
       via  c6db90273bda0143608077bcecc026bc7c89e967 (commit)
       via  c391b7becf56b3614d08fa16bb2ac7b7d449aac3 (commit)
       via  727e86ca495206d4779801e533242c409506bff2 (commit)
      from  d7254cf34cea36e0553c2f63da2a29a1d12f431a (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=c0c819e26cf34406d741033bfdd32e5932b36eff


commit c0c819e26cf34406d741033bfdd32e5932b36eff
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:17:32 2018 -0700

    Add support for owfs, ie... /mnt/1wire

diff --git a/daemon/main.cc b/daemon/main.cc
index 07e2d83..6d53852 100644
--- a/daemon/main.cc
+++ b/daemon/main.cc
@@ -61,6 +61,7 @@ include "xantrex-trace.h"
 #include "xml.h"
 #include "serial.h"
 #include "commands.h"
+#include "onewire.h"
 
 using namespace std;
 using namespace rcinit;
@@ -74,6 +75,7 @@ alarm_handler2 (int sig);
 
 int curses = 0;
 
+extern void onewire_handler(Onewire &ow);
 extern void client_handler(Tcpip &net);
 extern void ownet_handler(Ownet &);
 extern void outback_handler(Ownet &);
@@ -230,6 +232,9 @@ main(int argc, char *argv[])
         exit(-1);
     }
 
+    Onewire ow;
+    std::thread onewire_thread (onewire_handler, std::ref(ow));
+
     std::thread client_thread (client_handler, std::ref(net));
 #ifdef BUILD_OWNET
     Ownet ownet(DEFAULT_ARGV);
@@ -329,15 +334,16 @@ main(int argc, char *argv[])
 
     // synchronize threads:
     dbglogfile << "Killing all threads..." << std::endl;
-    client_thread.join();                // pauses until first finishes
+    onewire_thread.join();      // pauses until first finishes
+    client_thread.join();       // pauses until first finishes
 #ifdef BUILD_OWNET
-    ownet_thread.join();                // pauses until second finishes
+    ownet_thread.join();        // pauses until second finishes
 #endif
 #ifdef BUILD_XANTREX
-    xantrex_thread.join();               // pauses until third finishes
+    xantrex_thread.join();      // pauses until third finishes
 #endif
 #ifdef BUILD_OUTBACK
-    outback_thread.join();               // pauses until second finishes
+    outback_thread.join();      // pauses until second finishes
 #endif
 
     exit(0);
diff --git a/daemon/threads.cc b/daemon/threads.cc
index 8c6e01b..d29b546 100644
--- a/daemon/threads.cc
+++ b/daemon/threads.cc
@@ -33,7 +33,7 @@
 #include <mutex>
 #include <chrono>
 #include <queue>
-
+#include <boost/shared_ptr.hpp>
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #else
@@ -59,6 +59,52 @@ extern std::queue <XML> tqueue;
 extern std::condition_variable queue_cond;
 
 void
+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()) {
+        dbglogfile << "ERROR: Couldn't open database!" << std::endl;
+        exit(1);
+    }
+#endif
+
+    // Open the network connection to the database.
+    std::string query = "INSERT INTO onewire VALUES(";
+    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) {
+        for (it = temps.begin(); it != temps.end(); it++) {
+            if ((it->second->family == "10") | (it->second->family == "28")) {
+#ifdef HAVE_LIBPQ
+                std::string stamp;
+                stamp = pdb.gettime(stamp);
+                std::string query = it->second->family;
+                query += ",\'" + it->second->id + "\'";
+                query += ", \'" + it->second->type + "\'";
+                query += ", \'" + stamp + "\'";
+                query += ", " + std::to_string(it->second->lowtemp);
+                query +=  ", " + std::to_string(it->second->hightemp);
+                query += ", " + std::to_string(it->second->temp) + ", \'";
+                query += it->second->scale;
+                query += "\'";
+                pdb.queryInsert(query);
+#endif
+                //ownet.dump();
+            }
+            // Don't eat up all the cpu cycles!
+            
std::this_thread::sleep_for(std::chrono::seconds(onewire.getPollSleep()));
+        }
+    }
+}
+
+void
 client_handler(Tcpip &net)
 {
     DEBUGLOG_REPORT_FUNCTION;
@@ -156,7 +202,7 @@ ownet_handler(Ownet &ownet)
     std::map<std::string, ownet_t *>::iterator it;
     while (ownet.getPollSleep() > 0) {
         for (it = sensors.begin(); it != sensors.end(); it++) {
-            if (it->second->family == "10" | it->second->family == "28") {
+            if ((it->second->family == "10") | (it->second->family == "28")) {
                 boost::shared_ptr<temperature_t> temp = 
ownet.getTemperature(it->first.c_str());
 #ifdef HAVE_LIBPQ
                 std::string stamp;

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


commit 53105405788461170b8ea44022676b98ee73469b
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:16:55 2018 -0700

    Add boost libraries

diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 4795e1f..6aa7709 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -21,7 +21,8 @@
 AUTOMAKE_OPTIONS = # dejagnu
 
 pgd_CPPFLAGS = -Wall -I$(top_srcdir)/lib -I$(top_srcdir)/devices
-pgd_LDADD = ../devices/libpdev.la ../lib/libpguru.la -lpthread -lresolv
+pgd_LDADD = ../devices/libpdev.la ../lib/libpguru.la -lboost_filesystem \
+        -lboost_regex -lboost_system -lpthread -lresolv
 
 if BUILD_LIBXML
 pgd_CPPFLAGS += $(LIBXML_CPPFLAGS)

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


commit 140850dc89315faa7a3bdbb763e0d526366a68d3
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:16:10 2018 -0700

    Add boost libraries

diff --git a/client/Makefile.am b/client/Makefile.am
index 565a735..65868b8 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -24,7 +24,7 @@ bin_PROGRAMS = pguru
 pguru_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/devices
 
 pguru_SOURCES = cmd.cc threads.cc
-pguru_LDADD = ../lib/libpguru.la -lpthread -ldl
+pguru_LDADD = ../lib/libpguru.la -lboost_filesystem -lboost_system 
-lboost_regex -lpthread -ldl
 # Use a GCC specs file to add our configured sysroot path before the
 # one specified by GCC to work around a problem when trying to
 # link executables fot the Raspberry PI using the normal cross gcc

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


commit 0cd0ea9f015ccd7c549c5405b084bfe7ef81ce5c
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:15:36 2018 -0700

    temperature_t oved to onewire.h

diff --git a/devices/ownet.h b/devices/ownet.h
index 4d19b8c..2e644ac 100644
--- a/devices/ownet.h
+++ b/devices/ownet.h
@@ -33,6 +33,7 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
 #include "database.h"
+#include "onewire.h"
 
 extern LogFile dbglogfile;
 
@@ -43,16 +44,6 @@ struct ownet {
     std::string device;
 } typedef ownet_t;
 
-struct temperature {
-    std::string family;
-    std::string id;
-    std::string type;
-    float temp;
-    float lowtemp;
-    float hightemp;
-    char scale;
-} typedef temperature_t;
-
 class Ownet {
 private:
     enum family_t {CONTROL = 05, THERMOMETER = 10, THERMOMETER2 = 28};
@@ -76,6 +67,7 @@ public:
     int getPollSleep(void) {
         return poll_sleep;
     }
+
     void setPollSleep(int x) {
         poll_sleep = x;
     }

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


commit c6db90273bda0143608077bcecc026bc7c89e967
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 23 13:15:05 2018 -0700

    Implement support for /mnt/1wire

diff --git a/devices/onewire.cc b/devices/onewire.cc
new file mode 100644
index 0000000..2d8f454
--- /dev/null
+++ b/devices/onewire.cc
@@ -0,0 +1,146 @@
+// 
+// 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
+// the Free Software Foundation; either version 3 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
+
+#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>
+
+extern LogFile dbglogfile;
+
+Onewire::Onewire(void)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+
+    _rootdir = "/mnt/1wire";
+    boost::filesystem::path p(_rootdir);
+    try {
+        if (boost::filesystem::exists(p) & boost::filesystem::is_directory(p)) 
{
+            for (boost::filesystem::directory_entry & x : 
boost::filesystem::directory_iterator(p)) {
+                if (boost::regex_match(x.path().string(), 
boost::regex(_rootdir + "/[A-Z0-9.]*"))) {
+                    std::cout << x.path() << " is a device" << std::endl;
+                    boost::shared_ptr<onewire_t> owire(new onewire_t);
+                    owire->device = x.path().string();
+                    std::string result;
+                    owire->family = getValue(owire->device, "family", result);
+                    owire->type = getValue(owire->device, "type", result);
+                    owire->id = getValue(owire->device, "id", result);
+                    _sensors[x.path().string()] = owire;
+                }
+            }
+        } else {
+            std::cerr << "ERROR: " << _rootdir << " doesn't exist" << 
std::endl;
+        }
+    } catch (const boost::filesystem::filesystem_error& ex) {
+        std::cout << ex.what() << std::endl;
+    }
+
+    setValue("", "/settings/units/temperature_scale", "F");
+    dump();
+}
+
+void
+Onewire::setValue(const std::string &device, const std::string &file,
+                  const std::string &value)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+
+    std::string filespec;
+    if (!device.empty()) {
+        filespec = device +"/";
+    } else {
+        filespec = _rootdir; 
+    }
+    filespec += file;
+    std::ofstream entry(filespec);
+    entry << value;
+    std::cerr << "Setting " << filespec << " to value: " << value <<  
std::endl;
+    entry.close();
+}
+
+// extract a value from an owfs file
+std::string &
+Onewire::getValue(const std::string &device, std::string file, std::string 
&result)
+{
+//    DEBUGLOG_REPORT_FUNCTION;
+
+    std::string filespec;
+    if (!device.empty()) {
+        filespec = device +"/";
+    } else {
+        filespec = _rootdir; 
+    }
+    filespec += file;
+    std::ifstream entry(filespec);
+    entry >> result;
+    entry.close();
+    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;
+
+    _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);
+        getValue(sit->first, "family", temp->family);
+        getValue(sit->first, "id", temp->id);
+        getValue(sit->first, "type", temp->type);
+        std::string result;
+        temp->temp = std::stof(getValue(sit->first, "temperature", result));
+        temp->hightemp = std::stof(getValue(sit->first, "temphigh", result));
+        temp->lowtemp = std::stof(getValue(sit->first, "templow", result));
+        getValue("", "/settings/units/temperature_scale", result);
+        temp->scale = result[0];
+        _temps[sit->first] = temp;
+    }
+    
+    return _temps;
+}
+
+void
+Onewire::dump(void)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+
+    std::map<std::string, boost::shared_ptr<onewire_t>>::iterator sit;
+    for (sit = _sensors.begin(); sit != _sensors.end(); sit++) {
+        std::cerr << "Device: " << sit->first << std::endl;
+        std::cerr << "\tFamily: " << sit->second->family << std::endl;
+        std::cerr << "\tID: " << sit->second->id << std::endl;
+        std::cerr << "\tType: " << sit->second->type << std::endl;
+    }
+}
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: nil
+// End:
diff --git a/devices/onewire.h b/devices/onewire.h
new file mode 100644
index 0000000..f5435fe
--- /dev/null
+++ b/devices/onewire.h
@@ -0,0 +1,123 @@
+// 
+// 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
+// the Free Software Foundation; either version 3 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
+
+#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>
+
+extern LogFile dbglogfile;
+
+struct onewire {
+    std::string family;
+    std::string id;
+    std::string type;
+    std::string device;
+} 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 family_t {CONTROL = 05, THERMOMETER = 10, THERMOMETER2 = 28};
+
+class Onewire {
+private:
+    std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
+    std::mutex _mutex;
+    int _poll_sleep = 60;
+    char _scale = 'F';
+    std::string _rootdir;
+    std::map<std::string, boost::shared_ptr<temperature_t>> _temps;
+public:
+    Onewire(void);
+    ~Onewire(void) {};
+
+    char setScale(char scale);
+
+    // Thread have a polling frequency to avoid eating up all the cpu cycles
+    // by polling to quickly.
+    int getPollSleep(void) {
+        return _poll_sleep;
+    }
+
+    void setPollSleep(int x) {
+        _poll_sleep = x;
+    }
+
+    // see if any 1 wire sensors were found during scanning
+    bool hasSensors(void) {
+        if (_sensors.size() >0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    // extract a value from an owfs file
+    std::string &getValue(const std::string &device, std::string file,
+                          std::string &result);
+
+    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);
+    
+    void dump(void);
+    
+    std::vector<std::string> &
+    listDevices(std::vector<std::string> &list) {
+        DEBUGLOG_REPORT_FUNCTION;
+
+        std::map<std::string, boost::shared_ptr<onewire_t>>::iterator sit;
+        for (sit = _sensors.begin(); sit != _sensors.end(); sit++) {
+            std::string dev = sit->first.substr(sit->first.size()-1);
+            list.push_back(sit->first);
+        }
+        return list;
+    }
+
+};
+
+// __ONEWIRE_H__
+#endif
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: nil
+// End:

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


commit c391b7becf56b3614d08fa16bb2ac7b7d449aac3
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 19:28:18 2018 -0700

    Add support for owfs

diff --git a/devices/Makefile.am b/devices/Makefile.am
index 0cd287b..ec1e839 100644
--- a/devices/Makefile.am
+++ b/devices/Makefile.am
@@ -32,10 +32,9 @@ address@hidden@
 # include_HEADERS = log.h err.h proc.h serial.h xantrex.h outback.h
 
 libpdev_la_CPPFLAGS = -I$(top_srcdir)/lib -I..
+libpdev_la_LIBDADD = -lboost_filesystem
 
-libpdev_la_LIBDADD =
-
-libpdev_la_SOURCES =
+libpdev_la_SOURCES = onewire.cc
 if BUILD_XANTREX
 libpdev_la_SOURCES += xantrex-trace.cc xantrex-trace.h xanbus.cc xanbus.h
 endif
@@ -63,7 +62,8 @@ include_HEADERS = \
        xantrex-trace.h \
        outbackpower.h \
        xanbus.h \
-       ownet.h
+       ownet.h \
+       onewire.h
 
 #libpdev_la_LDFLAGS = -module -avoid-version -no-undefined
 

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


commit 727e86ca495206d4779801e533242c409506bff2
Author: Rob Savoye <address@hidden>
Date:   Sat Dec 22 15:45:54 2018 -0700

    Add submodule OneWire

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e7de490
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "OneWire"]
+       path = OneWire
+       url = https://github.com/PaulStoffregen/OneWire.git

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

Summary of changes:
 .gitmodules         |   3 ++
 client/Makefile.am  |   2 +-
 daemon/Makefile.am  |   3 +-
 daemon/main.cc      |  14 +++--
 daemon/threads.cc   |  50 +++++++++++++++++-
 devices/Makefile.am |   8 +--
 devices/onewire.cc  | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 devices/onewire.h   | 123 +++++++++++++++++++++++++++++++++++++++++++
 devices/ownet.h     |  12 +----
 9 files changed, 339 insertions(+), 22 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 devices/onewire.cc
 create mode 100644 devices/onewire.h


hooks/post-receive
-- 
powerguru



reply via email to

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