[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Powerguru-commit] [SCM] powerguru branch, master, updated. 5a0b1a90b983
From: |
Rob Savoye |
Subject: |
[Powerguru-commit] [SCM] powerguru branch, master, updated. 5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8 |
Date: |
Wed, 2 Jan 2019 21:52:46 -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 5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8 (commit)
via 4935c1e211650f918d7a92f708c585d13550d9d6 (commit)
via 30d90cf31b64c6f7f1a32fbfaf49703cc606cbe4 (commit)
from 7b3cc6ff635345c5cd42109de3750376c37500de (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=5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8
commit 5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8
Author: Rob Savoye <address@hidden>
Date: Wed Jan 2 19:46:36 2019 -0700
set defaults for temp readings.
diff --git a/devices/onewire.cc b/devices/onewire.cc
index 2440c1c..4824590 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -69,11 +69,12 @@ Onewire::Onewire(void)
if (boost::regex_match(x.path().string(),
boost::regex(_rootdir + "/[a-z0-9-]*"))) {
_mounted = true;
boost::shared_ptr<onewire_t> owire(new onewire_t);
- owire->device = x.path().string();
+ std::cerr << x.path().string().size() << std::endl;
std::string result;
+ owire->device = x.path().filename().string();
getValue(owire->device, "name", result);
- owire->family = result.substr(0,2);
- owire->id = result.substr(3,result.size());
+ owire->family = owire->device.substr(0,2);
+ owire->id = owire->device.substr(3, owire->device.size());
owire->bus = true;
owire->type = _family[owire->family].chips;
std::cerr << "BUS path found: " << result << std::endl;
@@ -131,12 +132,10 @@ Onewire::getValue(const std::string &device, std::string
file, std::string &resu
}
filespec += file;
try {
- BOOST_LOG_SEV(lg, severity_level::debug) << "Opening " << filespec;
std::ifstream entry(filespec);
entry.rdbuf()->pubsetbuf(0, 0);
std::stringstream buffer;
buffer << entry.rdbuf();
- //entry >> result;
result = buffer.str();
entry.close();
} catch (const std::exception& e) {
@@ -163,15 +162,15 @@ Onewire::getTemperatures(void)
std::string result;
if (sit->second->bus == true) {
getValue(sit->first, "w1_slave", result);
- std::cerr << "POS: " << result.find('t=') << std::endl;
+ // FIXME: calculate the position value
std::string value = result.substr(69, result.size());
- //std::string value = result.substr(result.find('t='),
result.size());
temp->scale = _scale;
temp->temp = std::stof(value)/1000;
+ temp->lowtemp = 0;
+ temp->hightemp = 0;
if (_scale == 'F') {
temp->temp = convertScale(temp->temp);
}
-
_temps[sit->first] = temp;
} else {
getValue(sit->first, "temperature", result);
diff --git a/devices/ownet.cc b/devices/ownet.cc
index b726d7d..56eb217 100644
--- a/devices/ownet.cc
+++ b/devices/ownet.cc
@@ -27,7 +27,7 @@ const int OWPORT = 4304;
const char *OWHOST = "localhost";
Ownet::Ownet(void)
- : _poll_sleep(60),
+ : _poll_sleep(300),
_scale('F'),
_owserver(false)
{
@@ -52,7 +52,8 @@ Ownet::Ownet(std::string &host)
// but always does on the second.
while (retries-- > 0) {
if (OW_init(argv.c_str()) < 0) {
- BOOST_LOG_SEV(lg, severity_level::warning) << "Couldn't connect to
owserver with " << argv;
+ BOOST_LOG_SEV(lg, severity_level::warning)
+ << "Couldn't connect to owserver with " << argv;
//return;
} else {
BOOST_LOG(lg) << "Connected to owserver on host " << host;
@@ -103,6 +104,8 @@ Ownet::Ownet(std::string &host)
std::lock_guard<std::mutex> guard(_mutex);
_sensors[*it] = data;
}
+
+ dump();
}
const boost::shared_ptr<temperature_t>
@@ -121,9 +124,16 @@ Ownet::getTemperature(const std::string &device)
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"));
+ try {
+ temp->temp = std::stof(getValue(device, "temperature"));
+ temp->lowtemp =std::stof(getValue(device, "templow"));
+ temp->hightemp = std::stof(getValue(device, "temphigh"));
+ } catch (const std::exception& e) {
+ temp->temp = 0;
+ temp->lowtemp = 0;
+ temp->hightemp = 0;
+ }
+
char *buffer;
size_t blen;
OW_get("/settings/units/temperature_scale", &buffer, &blen);
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=4935c1e211650f918d7a92f708c585d13550d9d6
commit 4935c1e211650f918d7a92f708c585d13550d9d6
Author: Rob Savoye <address@hidden>
Date: Wed Jan 2 17:50:14 2019 -0700
Add support to read the w1_slave file
diff --git a/devices/onewire.cc b/devices/onewire.cc
index b0f0638..2440c1c 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -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
@@ -21,6 +21,7 @@
#include <boost/regex.hpp>
#include <iostream>
#include <cstdio>
+#include <streambuf>
#include "onewire.h"
#include "log.h"
@@ -32,18 +33,22 @@ Onewire::Onewire(void)
{
// DEBUGLOG_REPORT_FUNCTION;
+ // Initialize the table of family types
+ initTable();
+
+#if 0
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);
+ owire->bus = false;
_sensors[x.path().string()] = owire;
}
}
@@ -54,7 +59,31 @@ Onewire::Onewire(void)
} catch (const boost::filesystem::filesystem_error& ex) {
std::cout << ex.what() << std::endl;
}
-
+#endif
+
+ if (_sensors.size() == 0) {
+ _rootdir = "/sys/bus/w1/devices";
+ boost::filesystem::path p(_rootdir);
+ 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-]*"))) {
+ _mounted = true;
+ boost::shared_ptr<onewire_t> owire(new onewire_t);
+ owire->device = x.path().string();
+ std::string result;
+ getValue(owire->device, "name", result);
+ owire->family = result.substr(0,2);
+ owire->id = result.substr(3,result.size());
+ owire->bus = true;
+ owire->type = _family[owire->family].chips;
+ std::cerr << "BUS path found: " << result << std::endl;
+ _sensors[x.path().string()] = owire;
+ }
+ //readBus()
+ }
+ }
+ }
+
setValue("", "/settings/units/temperature_scale", "F");
dump();
}
@@ -79,7 +108,7 @@ Onewire::setValue(const std::string &device, const
std::string &file,
filespec += file;
std::ofstream entry(filespec);
entry << value;
- std::cerr << "Setting " << filespec << " to value: " << value <<
std::endl;
+
entry.close();
}
@@ -102,12 +131,17 @@ Onewire::getValue(const std::string &device, std::string
file, std::string &resu
}
filespec += file;
try {
+ BOOST_LOG_SEV(lg, severity_level::debug) << "Opening " << filespec;
std::ifstream entry(filespec);
entry.rdbuf()->pubsetbuf(0, 0);
- entry >> result;
+ std::stringstream buffer;
+ buffer << entry.rdbuf();
+ //entry >> result;
+ result = buffer.str();
entry.close();
} catch (const std::exception& e) {
- BOOST_LOG(lg) << "Warning: iostream failure! " << e.what();
+ BOOST_LOG_SEV(lg, severity_level::warning) << "Warning: iostream
failure! "
+ << e.what();
}
//std::cerr << "Getting " << filespec << ", value: " << result<< std::endl;
return result;
@@ -123,32 +157,155 @@ Onewire::getTemperatures(void)
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);
+ temp->family = sit->second->family;
+ temp->id = sit->second->id;
+ temp->type = sit->second->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;
+ if (sit->second->bus == true) {
+ getValue(sit->first, "w1_slave", result);
+ std::cerr << "POS: " << result.find('t=') << std::endl;
+ std::string value = result.substr(69, result.size());
+ //std::string value = result.substr(result.find('t='),
result.size());
+ temp->scale = _scale;
+ temp->temp = std::stof(value)/1000;
+ if (_scale == 'F') {
+ temp->temp = convertScale(temp->temp);
+ }
+
+ _temps[sit->first] = temp;
+ } else {
+ getValue(sit->first, "temperature", result);
+ if (result.size() == 0) {
+ temp->temp = 0;
+ } else {
+ temp->temp = std::stof(result);
+ }
+ getValue(sit->first, "temphigh", result);
+ if (result.size() == 0) {
+ temp->hightemp = 0;
+ } else {
+ temp->hightemp = std::stof(result);
+ }
+ getValue(sit->first, "templow", result);
+ if (result.size() == 0) {
+ temp->lowtemp = 0;
+ } else {
+ temp->lowtemp = std::stof(result);
+ }
+
+ getValue("", "/settings/units/temperature_scale", result);
+ temp->scale = result[0];
+ _temps[sit->first] = temp;
+ }
}
return _temps;
}
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};
+}
+
+std::string &
+Onewire::readBus(const std::string &device, std::string &data)
+{
+ DEBUGLOG_REPORT_FUNCTION;
+
+ ///sys/bus/w1/devices/28-021316a4d6aa/w1_slave
+
+ return data;
+}
+
+
+void
Onewire::dump(void)
{
// DEBUGLOG_REPORT_FUNCTION;
+ if (_sensors.size() == 0) {
+ BOOST_LOG(lg) << "No sensors found";
+ }
+ std::cerr << "Rootdir for sensors is: " << _rootdir << std::endl;
+
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;
+ std::cerr << "\tBus: " << (sit->second->bus ? "true" : "false") <<
std::endl;
}
}
diff --git a/devices/onewire.h b/devices/onewire.h
index 160eb29..ed33dd5 100644
--- a/devices/onewire.h
+++ b/devices/onewire.h
@@ -32,6 +32,7 @@ struct onewire {
std::string id;
std::string type;
std::string device;
+ bool bus;
} typedef onewire_t;
struct temperature {
@@ -44,17 +45,38 @@ struct temperature {
char scale;
} typedef temperature_t;
-enum family_t {CONTROL = 05, THERMOMETER = 10, THERMOMETER2 = 28};
+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;
class Onewire {
private:
- std::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
std::mutex _mutex;
+ // How long to delay between reading the sensor
int _poll_sleep;
- char _scale;
- std::string _rootdir;
+ 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::map<std::string, boost::shared_ptr<onewire_t>> _sensors;
public:
Onewire(void);
~Onewire(void) {};
@@ -81,6 +103,10 @@ public:
}
}
+ 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,
std::string &result);
@@ -90,7 +116,10 @@ public:
// 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);
+
void dump(void);
std::vector<std::string> &
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=30d90cf31b64c6f7f1a32fbfaf49703cc606cbe4
commit 30d90cf31b64c6f7f1a32fbfaf49703cc606cbe4
Author: Rob Savoye <address@hidden>
Date: Wed Jan 2 12:44:49 2019 -0700
Don't install useless headers
diff --git a/devices/Makefile.am b/devices/Makefile.am
index 1553520..7f61ae3 100644
--- a/devices/Makefile.am
+++ b/devices/Makefile.am
@@ -31,28 +31,28 @@ address@hidden@
# include_HEADERS = log.h err.h proc.h serial.h xantrex.h outback.h serial.h
libpdev_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I..
-libpdev_la_LIBDADD = -lboost_filesystem
+libpdev_la_LIBDADD =
libpdev_la_SOURCES = onewire.cc
if BUILD_XANTREX
-libpdev_la_SOURCES += xantrex-trace.cc xantrex-trace.h xanbus.cc xanbus.h
+libpdev_la_SOURCES += xantrex-trace.cc xanbus.cc
endif
if BUILD_OUTBACK
-libpdev_la_SOURCES += outbackpower.cc outbackpower.h
+libpdev_la_SOURCES += outbackpower.cc
endif
if BUILD_SERIAL
-SERIAL_FILES = serial.cc serial.h
+SERIAL_FILES = serial.cc
endif
if BUILD_SNMP
-SNMP_FILES = snmp.cc snmp.h
+SNMP_FILES = snmp.cc
libpdev_la_CPPFLAGS += -I$(top_srcdir)/snmp
libpdev_la_LIBDADD += $(SNMP_LIBS) ../snmp/libpgsnmp.la
endif
if BUILD_OWNET
-libpdev_la_SOURCES += ownet.cc ownet.h
+libpdev_la_SOURCES += ownet.cc
libpdev_la_LIBDADD += $(OWNET_LIBS)
endif
@@ -61,7 +61,7 @@ libpdev_la_CPPFLAGS += $(PQ_CPPFLAGS)
libpdev_la_LIBDADD += $(PQ_LIBS)
endif
-include_HEADERS = \
+noinst_HEADERS = \
xantrex-trace.h \
outbackpower.h \
xanbus.h \
diff --git a/lib/Makefile.am b/lib/Makefile.am
index bd97626..95f181a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -71,7 +71,7 @@ libpguru_la_CPPFLAGS += $(PQ_CPPFLAGS)
libpguru_la_LIBDADD += $(PQ_LIBS)
endif
-include_HEADERS = \
+noinst_HEADERS = \
proc.h \
menuitem.h \
database.h \
-----------------------------------------------------------------------
Summary of changes:
devices/Makefile.am | 14 ++--
devices/onewire.cc | 186 +++++++++++++++++++++++++++++++++++++++++++++++-----
devices/onewire.h | 39 +++++++++--
devices/ownet.cc | 20 ++++--
lib/Makefile.am | 2 +-
5 files changed, 228 insertions(+), 33 deletions(-)
hooks/post-receive
--
powerguru
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Powerguru-commit] [SCM] powerguru branch, master, updated. 5a0b1a90b9833787ad7d8d1898f06ec37ce5e4e8,
Rob Savoye <=