Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
56a6de46
Commit
56a6de46
authored
Oct 02, 2018
by
Micha Mueller
Browse files
First running version (sysfs only)
parent
b175e2f9
Changes
5
Hide whitespace changes
Inline
Side-by-side
config/sysfs.conf
View file @
56a6de46
...
...
@@ -2,43 +2,47 @@ global {
mqttPrefix
/
FF112233445566778899AABBFFFF
}
sensorTemplates
{
sensor
def1
{
path
/
home
/
micha
/
LRZ
/
dcdbOwnFork
/
sysfspusher
/
temp
interval
1000
mqttsuffix
0000
filter
"s/Temperature ([[:digit:]]+)\\.([[:digit:]]+)°C/\\1\\200/"
minValues
3
}
template_group
def1
{
interval
1000
minValues
3
mqttPart
00
sensor
temp0
{
path
/
home
/
micha
/
LRZ
/
dcdbOwnFork
/
sysfspusher
/
temp
mqttsuffix
00
filter
"s/Temperature ([[:digit:]]+)\\.([[:digit:]]+)°C/\\1\\200/"
}
}
template_group
def2
{
interval
2000
}
sensor
def2
{
interval
2000
}
group
temp
{
default
def1
sensor
temp1
{
path
/
sys
/
devices
/
virtual
/
thermal
/
thermal_zone1
/
temp
mqttsuffix
01
}
}
sensors
{
sensor
temp0
{
default
def1
}
sensor
temp1
{
path
/
sys
/
devices
/
virtual
/
thermal
/
thermal_zone1
/
temp
interval
1000
mqttsuffix
0001
}
sensor
freq0
{
path
/
home
/
micha
/
LRZ
/
dcdbOwnFork
/
sysfspusher
/
freq
interval
1000
mqttsuffix
0010
minValues
10
filter
s
/
Frequency
=([[:
digit
:]]+)/\\
1
/
}
sensor
freq1
{
path
/
sys
/
devices
/
system
/
cpu
/
cpu1
/
cpufreq
/
scaling_cur_freq
default
def2
mqttsuffix
0011
}
group
freq
{
interval
1000
minValues
10
sensor
freq0
{
path
/
home
/
micha
/
LRZ
/
dcdbOwnFork
/
sysfspusher
/
freq
mqttsuffix
0010
filter
s
/
Frequency
=([[:
digit
:]]+)/\\
1
/
}
}
group
freq
{
default
def2
sensor
freq1
{
path
/
sys
/
devices
/
system
/
cpu
/
cpu1
/
cpufreq
/
scaling_cur_freq
mqttsuffix
0011
}
}
src/includes/ConfiguratorTemplate.h
View file @
56a6de46
...
...
@@ -31,7 +31,7 @@ template <class SBase, class SGroup, class SEntity = nullptr_t>
class
ConfiguratorTemplate
:
public
ConfiguratorInterface
{
//the template shall only be instantiated for classes which derive from SensorBase/SensorGroup
static_assert
(
std
::
is_base_of
<
SensorBase
,
SBase
>::
value
,
"SBase must derive from SensorBase!"
);
static_assert
(
std
::
is_base_of
<
SensorGroup
Templat
e
,
SGroup
>::
value
,
"SGroup must derive from SensorGroup
Templat
e!"
);
static_assert
(
std
::
is_base_of
<
SensorGroup
Interfac
e
,
SGroup
>::
value
,
"SGroup must derive from SensorGroup
Interfac
e!"
);
protected:
typedef
std
::
map
<
std
::
string
,
SGroup
*>
sGroupMap_t
;
...
...
@@ -88,19 +88,24 @@ public:
//read groups and templates for groups. If present also entity/-template stuff
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
cfg
)
{
//TODO allow for template sensors?
//TODO allow single sensors for convenience?
//template entity
if
(
boost
::
iequals
(
val
.
first
,
"template_"
+
_entityName
))
{
LOG
(
debug
)
<<
"Template "
<<
_entityName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
//TODO how to handle Entity at compile time?
//possible solutions: preprocessor defines (ugly), partial template specialization(code duplication), inheritance (complicated structure)
#if 0
SEntity* entity = new SEntity(val.second.data());
if (readSensorEntity(*entity, val.second)) {
auto
ret
=
_templateSensorEntitys
.
insert
(
std
::
pair
<
std
::
string
,
SEntity
*>
(
entity
->
getName
(),
entity
));
auto ret = _templateSensorEntitys.insert(std::pair<std::string, SEntity*>(
val.second.data
(), entity));
if(!ret.second) {
LOG
(
warning
)
<<
"Template "
<<
_entityName
<<
" "
<<
entity
->
getName
()
<<
" already exists! Omitting..."
;
LOG(warning) << "Template " << _entityName << " " <<
val.second.data
() << " already exists! Omitting...";
}
} else {
LOG(warning) << "Template " << _entityName << " \"" << val.second.data() << "\" has bad values! Ignoring...";
}
#endif
}
//template group
}
else
if
(
boost
::
iequals
(
val
.
first
,
"template_"
+
_groupName
))
{
...
...
@@ -108,9 +113,9 @@ public:
if
(
!
val
.
second
.
empty
())
{
SGroup
*
group
=
new
SGroup
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
))
{
auto
ret
=
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
SGroup
*>
(
group
->
getName
(),
group
));
auto
ret
=
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
SGroup
*>
(
val
.
second
.
data
(),
group
));
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
" "
<<
group
->
getName
()
<<
" already exists! Omitting..."
;
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
" "
<<
val
.
second
.
data
()
<<
" already exists! Omitting..."
;
}
}
else
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
...
...
@@ -120,12 +125,14 @@ public:
}
else
if
(
boost
::
iequals
(
val
.
first
,
_entityName
))
{
LOG
(
debug
)
<<
_entityName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
#if 0
SEntity* entity = new SEntity(val.second.data());
if (readSensorEntity(*entity, val.second)) {
_sensorEntitys.push_back(entity);
} else {
LOG(warning) << _entityName << " \"" << val.second.data() << "\" has bad values! Ignoring...";
}
#endif
}
//group
}
else
if
(
boost
::
iequals
(
val
.
first
,
_groupName
))
{
...
...
@@ -140,6 +147,12 @@ public:
}
}
}
//read of config finished. Now we build the mqtt-topic for every sensor
for
(
auto
g
:
_sensorGroups
)
{
for
(
auto
s
:
g
->
getSensors
())
{
s
->
setMqtt
(
_mqttPrefix
+
g
->
getMqttPart
()
+
s
->
getMqtt
());
}
}
return
true
;
}
...
...
@@ -217,7 +230,6 @@ protected:
* @return True on success, false otherwise
*/
bool
readSensorBase
(
SBase
&
sBase
,
boost
::
property_tree
::
iptree
&
config
)
{
//TODO set full mqtt-topic if reading config finished!
//TODO default templates useful?
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
if
(
boost
::
iequals
(
val
.
first
,
"mqttsuffix"
))
{
...
...
@@ -248,8 +260,8 @@ protected:
LOG
(
debug
)
<<
" Using
\"
"
<<
def
.
get
().
data
()
<<
"
\"
as default."
;
auto
it
=
_templateSensorGroups
.
find
(
def
.
get
().
data
());
if
(
it
!=
_templateSensorGroups
.
end
())
{
sGroup
=
it
->
second
;
sGroup
->
setName
(
config
.
data
());
sGroup
=
*
(
it
->
second
)
;
sGroup
.
set
Group
Name
(
config
.
data
());
}
else
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
"
\"
"
<<
def
.
get
().
data
()
<<
"
\"
not found! Using standard values."
;
}
...
...
@@ -263,7 +275,8 @@ protected:
sGroup
.
setMinValues
(
stoull
(
val
.
second
.
data
()));
}
else
if
(
boost
::
iequals
(
val
.
first
,
"mqttPart"
))
{
sGroup
.
setMqttPart
(
val
.
second
.
data
());
}
else
if
(
boost
::
iequals
(
val
.
first
,
"sensor"
))
{
}
else
if
(
boost
::
iequals
(
val
.
first
,
_baseName
))
{
LOG
(
debug
)
<<
" "
<<
_baseName
<<
" "
<<
val
.
second
.
data
();
SBase
*
sensor
=
new
SBase
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
sGroup
.
pushBackSensor
(
sensor
);
...
...
@@ -299,8 +312,8 @@ protected:
LOG
(
debug
)
<<
" Using
\"
"
<<
def
.
get
().
data
()
<<
"
\"
as default."
;
auto
it
=
_templateSensorEntitys
.
find
(
def
.
get
().
data
());
if
(
it
!=
_templateSensorEntitys
.
end
())
{
sEntity
=
it
->
second
;
sEntity
->
setName
(
config
.
data
());
sEntity
=
*
(
it
->
second
)
;
//
sEntity
.
setName(config.data());
}
else
{
LOG
(
warning
)
<<
"Template "
<<
_entityName
<<
"
\"
"
<<
def
.
get
().
data
()
<<
"
\"
not found! Using standard values."
;
}
...
...
src/includes/SensorGroupTemplate.h
View file @
56a6de46
...
...
@@ -44,7 +44,7 @@ public:
_baseSensors
.
clear
();
for
(
auto
s
:
other
.
_sensors
)
{
S
*
sensor
=
new
S
(
s
);
S
*
sensor
=
new
S
(
*
s
);
_sensors
.
push_back
(
sensor
);
_baseSensors
.
push_back
(
sensor
);
}
...
...
src/sensors/sysfs/SysfsSensorBase.h
View file @
56a6de46
...
...
@@ -43,11 +43,11 @@ public:
if
(
regex_match
(
filter
,
matchResults
,
checkSubstitute
))
{
//input has substitute format
setRegex
(
regex
(
matchResults
[
2
].
str
(),
std
::
regex_constants
::
extended
));
setRegex
(
std
::
regex
(
matchResults
[
2
].
str
(),
std
::
regex_constants
::
extended
));
setSubstitution
(
matchResults
[
3
].
str
());
}
else
{
//input is only a regex
setRegex
(
regex
(
filter
,
std
::
regex_constants
::
extended
));
setRegex
(
std
::
regex
(
filter
,
std
::
regex_constants
::
extended
));
setSubstitution
(
"&"
);
}
}
...
...
src/sensors/sysfs/SysfsSensorGroup.cpp
View file @
56a6de46
...
...
@@ -28,6 +28,7 @@ void SysfsSensorGroup::start() {
s
->
setFile
(
fopen
(
s
->
getPath
().
c_str
(),
"r"
));
if
(
s
->
getFile
()
==
NULL
)
{
LOG
(
error
)
<<
"Error starting sensor
\"
"
<<
s
->
getName
()
<<
"
\"
: "
<<
strerror
(
errno
);
LOG
(
warning
)
<<
"Group "
<<
_groupName
<<
" not started due to problematic sensor"
;
return
;
}
}
...
...
@@ -77,13 +78,13 @@ void SysfsSensorGroup::read() {
}
}
catch
(
const
std
::
exception
&
e
)
{
#ifdef DEBUG
LOG
(
warning
)
<<
"SysfsSensor "
<<
_
n
ame
<<
" could not read value!"
;
LOG
(
warning
)
<<
"SysfsSensor "
<<
_
groupName
<<
"::"
<<
s
->
getN
ame
()
<<
" could not read value!"
;
#endif
return
;
}
#ifdef DEBUG
LOG
(
debug
)
<<
_
n
ame
<<
":
\"
"
<<
reading
.
value
<<
"
\"
"
;
LOG
(
debug
)
<<
_
groupName
<<
"::"
<<
s
->
getN
ame
()
<<
":
\"
"
<<
reading
.
value
<<
"
\"
"
;
#endif
}
s
->
storeReading
(
reading
,
_cacheIndex
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment