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
5d43fec1
Commit
5d43fec1
authored
Aug 13, 2018
by
Micha Mueller
Browse files
Adapt Sysfs plugin to new class structure
parent
d094ba1a
Changes
8
Show whitespace changes
Inline
Side-by-side
Makefile
View file @
5d43fec1
...
...
@@ -72,7 +72,7 @@ src/SensorGroup.o: CXXFLAGS+= $(PLUGINFLAGS)
src/sensors/%.o
:
CXXFLAGS+= $(PLUGINFLAGS) -I$(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/include -I$(DCDBDEPSPATH)/bacnet-stack-$(BACNET-STACK_VERSION)/ports/$(BACNET_PORT)
#src/sensors/*/%.o: %.cpp
libdcdbplugin_sysfs.$(LIBEXT)
:
src/Sensor.o
src/sensors/sysfs/SysfsSensor.o src/sensors/sysfs/SysfsConfigurator.o
libdcdbplugin_sysfs.$(LIBEXT)
:
src/sensors/sysfs/SysfsS
ingleS
ensor.o src/sensors/sysfs/SysfsConfigurator.o
$(CXX)
$(LIBFLAGS)$@
-o
$@
$^
-L
$(DCDBDEPLOYPATH)
/lib/
-lboost_log
-lboost_system
libdcdbplugin_perfevent.$(LIBEXT)
:
src/sensors/perfevent/PerfSingleSensor.o src/sensors/perfevent/PerfeventConfigurator.o src/sensors/perfevent/PerfSensorGroup.o
...
...
src/sensors/snmp/SNMPSensorBase.h
View file @
5d43fec1
...
...
@@ -18,7 +18,8 @@
class
SNMPSensorBase
:
virtual
public
SensorBase
{
public:
SNMPSensorBase
(
const
std
::
string
&
name
)
:
SensorBase
(
name
),
_oidLen
(
0
)
{
SensorBase
(
name
),
_oidLen
(
0
)
{
memset
(
_oid
,
0x0
,
sizeof
(
oid
)
*
MAX_OID_LEN
);
_connection
=
NULL
;
}
...
...
src/sensors/sysfs/SysfsConfigurator.cpp
View file @
5d43fec1
...
...
@@ -21,7 +21,7 @@ bool SysfsConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
if
(
STRCMP
(
sensor
,
"sensor"
))
{
LOG
(
debug
)
<<
"Sensor
\"
"
<<
sensor
.
second
.
data
()
<<
"
\"
"
;
if
(
!
sensor
.
second
.
empty
())
{
SysfsSensor
*
sysfsSensor
=
new
SysfsSensor
(
sensor
.
second
.
data
());
SysfsS
ingleS
ensor
*
sysfsSensor
=
new
SysfsS
ingleS
ensor
(
sensor
.
second
.
data
());
//first check if default sensor is given
boost
::
optional
<
boost
::
property_tree
::
iptree
&>
defaultS
=
sensor
.
second
.
get_child_optional
(
"default"
);
...
...
@@ -36,7 +36,7 @@ bool SysfsConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
}
}
//read remaining values
if
(
readSensor
(
*
sysfsSensor
,
sensor
.
second
))
{
if
(
readSensor
Base
(
*
sysfsSensor
,
sensor
.
second
))
{
_sensors
.
push_back
(
sysfsSensor
);
}
else
{
LOG
(
warning
)
<<
" Sensor
\"
"
<<
sensor
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
...
...
@@ -47,7 +47,7 @@ bool SysfsConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
return
true
;
}
bool
SysfsConfigurator
::
derivedReadSensor
(
SysfsSensor
&
sensor
,
boost
::
property_tree
::
iptree
&
config
)
{
bool
SysfsConfigurator
::
derivedReadSensor
Base
(
SysfsSensor
Base
&
sensor
,
boost
::
property_tree
::
iptree
&
config
)
{
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
if
(
STRCMP
(
val
,
"mqttsuffix"
))
{
sensor
.
setMqtt
(
_mqttPrefix
+
val
.
second
.
data
());
...
...
src/sensors/sysfs/SysfsConfigurator.h
View file @
5d43fec1
...
...
@@ -8,11 +8,11 @@
#ifndef SYSFSCONFIGURATOR_H_
#define SYSFSCONFIGURATOR_H_
#include
"SysfsSensor.h"
#include
"../../ConfiguratorTemplate.h"
class
SysfsConfigurator
:
public
ConfiguratorTemplate
<
SysfsSensor
>
{
#include
"SysfsSingleSensor.h"
class
SysfsConfigurator
:
public
ConfiguratorTemplate
<
SysfsSensorBase
,
SysfsSingleSensor
>
{
public:
SysfsConfigurator
();
...
...
@@ -21,9 +21,9 @@ public:
protected:
/* Overwritten from ConfiguratorTemplate */
bool
derivedReadConfig
(
boost
::
property_tree
::
iptree
&
cfg
)
override
;
void
derivedReReadConfig
()
override
{
/* nothing to overwrite */
}
void
derivedSetGlobalSettings
(
const
pluginSettings_t
&
pluginSettings
)
override
{
/* nothing to overwrite */
}
bool
derivedReadSensor
(
SysfsSensor
&
sensor
,
boost
::
property_tree
::
iptree
&
config
)
override
;
void
derivedReReadConfig
()
override
{
/* nothing to overwrite */
}
void
derivedSetGlobalSettings
(
const
pluginSettings_t
&
pluginSettings
)
override
{
/* nothing to overwrite */
}
bool
derivedReadSensor
Base
(
SysfsSensor
Base
&
sensor
,
boost
::
property_tree
::
iptree
&
config
)
override
;
};
extern
"C"
ConfiguratorInterface
*
create
()
{
...
...
src/sensors/sysfs/SysfsSensor.h
deleted
100644 → 0
View file @
d094ba1a
/*
* SYSFSSensor.h
*
* Created on: 18.11.2017
* Author: Michael Ott (original), Micha Mueller
*/
#ifndef SYSFSSENSOR_H_
#define SYSFSSENSOR_H_
#include
"../../Sensor.h"
#include
<regex>
class
SysfsSensor
:
public
Sensor
{
public:
SysfsSensor
(
const
std
::
string
&
name
);
virtual
~
SysfsSensor
();
const
std
::
string
&
getPath
()
const
{
return
_path
;
}
void
setPath
(
const
std
::
string
&
path
)
{
_path
=
path
;
}
FILE
*
getFile
()
const
{
return
_file
;
}
void
setFile
(
FILE
*
file
)
{
_file
=
file
;
}
bool
hasFilter
()
const
{
return
_filter
;
}
void
setFilter
(
bool
filter
)
{
_filter
=
filter
;
}
std
::
regex
getRegex
()
const
{
return
_regx
;
}
void
setRegex
(
std
::
regex
regx
)
{
_regx
=
regx
;
}
const
std
::
string
&
getSubstitution
()
const
{
return
_substitution
;
}
void
setSubstitution
(
const
std
::
string
&
substitution
)
{
_substitution
=
substitution
;
}
void
read
();
void
readAsync
();
void
startPolling
();
void
stopPolling
();
private:
std
::
string
_path
;
FILE
*
_file
;
bool
_filter
;
std
::
regex
_regx
;
std
::
string
_substitution
;
};
#endif
/* SYSFSSENSOR_H_ */
src/sensors/sysfs/SysfsSensorBase.h
0 → 100644
View file @
5d43fec1
/*
* SysfsSensorBase.h
*
* Created on: 13.08.2018
* Author: Micha Mueller
*/
#ifndef SYSFS_SYSFSSENSORBASE_H_
#define SYSFS_SYSFSSENSORBASE_H_
#include
"../../headers/SensorBase.h"
#include
<regex>
class
SysfsSensorBase
:
virtual
public
SensorBase
{
public:
SysfsSensorBase
(
const
std
::
string
&
name
)
:
SensorBase
(
name
),
_path
(
""
),
_filter
(
false
),
_substitution
(
""
)
{
_file
=
NULL
;
//_regx = "";
}
virtual
~
SysfsSensorBase
()
{}
const
std
::
string
&
getPath
()
const
{
return
_path
;
}
FILE
*
getFile
()
const
{
return
_file
;
}
bool
hasFilter
()
const
{
return
_filter
;
}
std
::
regex
getRegex
()
const
{
return
_regx
;
}
const
std
::
string
&
getSubstitution
()
const
{
return
_substitution
;
}
void
setPath
(
const
std
::
string
&
path
)
{
_path
=
path
;
}
void
setFile
(
FILE
*
file
)
{
_file
=
file
;
}
void
setFilter
(
bool
filter
)
{
_filter
=
filter
;
}
void
setRegex
(
std
::
regex
regx
)
{
_regx
=
regx
;
}
void
setSubstitution
(
const
std
::
string
&
substitution
)
{
_substitution
=
substitution
;
}
protected:
std
::
string
_path
;
FILE
*
_file
;
bool
_filter
;
std
::
regex
_regx
;
std
::
string
_substitution
;
};
#endif
/* SYSFS_SYSFSSENSORBASE_H_ */
src/sensors/sysfs/SysfsSensor.cpp
→
src/sensors/sysfs/SysfsS
ingleS
ensor.cpp
View file @
5d43fec1
/*
* S
YSFS
Sensor.cpp
* S
ysfsSingle
Sensor.cpp
*
* Created on: 18.11.2017
* Author: Michael Ott (original), Micha Mueller
*/
#include
"SysfsSensor.h"
#include
"SysfsSingleSensor.h"
#include
"timestamp.h"
#include
<functional>
using
namespace
std
;
SysfsSensor
::
SysfsSensor
(
const
std
::
string
&
name
)
:
Sensor
(
name
)
{
_path
=
""
;
_file
=
NULL
;
_filter
=
false
;
//_regx = "";
_substitution
=
""
;
SysfsSingleSensor
::
SysfsSingleSensor
(
const
std
::
string
&
name
)
:
SensorBase
(
name
),
SysfsSensorBase
(
name
),
SingleSensor
(
name
)
{}
SysfsSingleSensor
::~
SysfsSingleSensor
()
{}
void
SysfsSingleSensor
::
start
()
{
if
(
_keepRunning
)
{
//we have been started already
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" already running."
;
return
;
}
if
(
_file
==
NULL
)
{
_file
=
fopen
(
_path
.
c_str
(),
"r"
);
if
(
_file
==
NULL
)
{
LOG
(
error
)
<<
"Error starting sensor
\"
"
<<
_name
<<
"
\"
: "
<<
strerror
(
errno
);
return
;
}
}
_keepRunning
=
1
;
_pendingTasks
++
;
_timer
->
async_wait
(
std
::
bind
(
&
SysfsSingleSensor
::
readAsync
,
this
));
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" started."
;
}
SysfsSensor
::~
SysfsSensor
()
{
// TODO Auto-generated destructor stub
void
SysfsSingleSensor
::
stop
()
{
_keepRunning
=
0
;
//wait before closing _file
wait
();
if
(
_file
!=
NULL
)
{
fclose
(
_file
);
_file
=
NULL
;
}
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" stopped."
;
}
void
SysfsSensor
::
read
()
{
void
SysfsS
ingleS
ensor
::
read
()
{
reading_t
reading
;
char
buf
[
1024
];
...
...
@@ -56,49 +81,18 @@ void SysfsSensor::read() {
LOG
(
debug
)
<<
_name
<<
":
\"
"
<<
reading
.
value
<<
"
\"
"
;
#endif
}
storeReading
(
reading
);
storeReading
(
reading
,
_cacheIndex
);
_cacheIndex
=
(
_cacheIndex
+
1
)
%
_cacheSize
;
}
void
SysfsSensor
::
readAsync
()
{
void
SysfsS
ingleS
ensor
::
readAsync
()
{
uint64_t
now
=
getTimestamp
();
read
();
if
(
_timer
!=
NULL
&&
_keepRunning
)
{
uint64_t
next
=
now
+
MS_TO_NS
(
_interval
);
_timer
->
expires_at
(
timestamp2ptime
(
next
));
_pendingTasks
++
;
_timer
->
async_wait
(
std
::
bind
(
&
SysfsSensor
::
readAsync
,
this
));
_timer
->
async_wait
(
std
::
bind
(
&
SysfsS
ingleS
ensor
::
readAsync
,
this
));
}
_pendingTasks
--
;
}
void
SysfsSensor
::
startPolling
()
{
if
(
_keepRunning
)
{
//we have been started already
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" already running."
;
return
;
}
if
(
_file
==
NULL
)
{
_file
=
fopen
(
_path
.
c_str
(),
"r"
);
if
(
_file
==
NULL
)
{
LOG
(
error
)
<<
"Error starting sensor
\"
"
<<
_name
<<
"
\"
: "
<<
strerror
(
errno
);
return
;
}
}
_keepRunning
=
1
;
_pendingTasks
++
;
_timer
->
async_wait
(
std
::
bind
(
&
SysfsSensor
::
readAsync
,
this
));
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" started."
;
}
void
SysfsSensor
::
stopPolling
()
{
_keepRunning
=
0
;
//wait before closing _file
wait
();
if
(
_file
!=
NULL
)
{
fclose
(
_file
);
_file
=
NULL
;
}
LOG
(
info
)
<<
"Sensor "
<<
_name
<<
" stopped."
;
}
src/sensors/sysfs/SysfsSingleSensor.h
0 → 100644
View file @
5d43fec1
/*
* SysfsSingleSensor.h
*
* Created on: 18.11.2017
* Author: Michael Ott (original), Micha Mueller
*/
#ifndef SYSFSSINGLESENSOR_H_
#define SYSFSSINGLESENSOR_H_
#include
"SysfsSensorBase.h"
#include
"../../headers/SingleSensor.h"
class
SysfsSingleSensor
:
public
SysfsSensorBase
,
public
SingleSensor
{
public:
SysfsSingleSensor
(
const
std
::
string
&
name
);
virtual
~
SysfsSingleSensor
();
void
start
()
override
;
void
stop
()
override
;
private:
void
read
()
override
;
void
readAsync
()
override
;
};
#endif
/* SYSFSSINGLESENSOR_H_ */
Write
Preview
Supports
Markdown
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