Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
b5278b79
Commit
b5278b79
authored
Aug 16, 2019
by
Michael Ott
Browse files
Add configuration parameter for entities and sensor groups to disable them
parent
22b41f9c
Changes
4
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/includes/ConfiguratorTemplate.h
View file @
b5278b79
...
...
@@ -435,6 +435,12 @@ protected:
}
else
{
sGroup
.
setSync
(
true
);
}
}
else
if
(
boost
::
iequals
(
val
.
first
,
"disabled"
))
{
if
(
boost
::
iequals
(
val
.
second
.
data
(),
"true"
))
{
sGroup
.
setDisabled
(
true
);
}
else
{
sGroup
.
setDisabled
(
false
);
}
}
else
if
(
boost
::
iequals
(
val
.
first
,
_baseName
))
{
if
(
!
isTemplate
)
{
LOG
(
debug
)
<<
" "
<<
_baseName
<<
" "
<<
val
.
second
.
data
();
...
...
@@ -491,11 +497,17 @@ protected:
}
//read in values inherited from EntityInterface
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
if
(
boost
::
iequals
(
val
.
first
,
"mqttPart"
))
{
sEntity
.
setMqttPart
(
val
.
second
.
data
());
}
}
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
if
(
boost
::
iequals
(
val
.
first
,
"mqttPart"
))
{
sEntity
.
setMqttPart
(
val
.
second
.
data
());
}
else
if
(
boost
::
iequals
(
val
.
first
,
"disabled"
))
{
if
(
boost
::
iequals
(
val
.
second
.
data
(),
"true"
))
{
sEntity
.
setDisabled
(
true
);
}
else
{
sEntity
.
setDisabled
(
false
);
}
}
}
sensorEntity
(
sEntity
,
config
);
...
...
dcdbpusher/includes/EntityInterface.h
View file @
b5278b79
...
...
@@ -57,6 +57,7 @@ public:
_name
(
name
),
_mqttPart
(
""
),
_initialized
(
false
),
_disabled
(
false
),
_strand
(
nullptr
)
{}
/**
...
...
@@ -70,6 +71,7 @@ public:
_name
(
other
.
_name
),
_mqttPart
(
other
.
_mqttPart
),
_initialized
(
false
),
_disabled
(
other
.
_disabled
),
_strand
(
nullptr
)
{}
/**
...
...
@@ -90,6 +92,7 @@ public:
_name
=
other
.
_name
;
_mqttPart
=
other
.
_mqttPart
;
_initialized
=
false
;
_disabled
=
other
.
_disabled
;
_strand
=
nullptr
;
return
*
this
;
...
...
@@ -99,6 +102,7 @@ public:
///@{
const
std
::
string
&
getName
()
const
{
return
_name
;
}
const
std
::
string
&
getMqttPart
()
const
{
return
_mqttPart
;
}
const
bool
&
isDisabled
()
const
{
return
_disabled
;
}
const
std
::
unique_ptr
<
strand
>&
getStrand
()
const
{
return
_strand
;
}
///@}
...
...
@@ -115,6 +119,7 @@ public:
_mqttPart
.
erase
(
_mqttPart
.
size
()
-
1
);
}
}
void
setDisabled
(
const
bool
disabled
)
{
_disabled
=
disabled
;
}
///@}
/**
...
...
@@ -145,6 +150,7 @@ public:
*/
void
printConfig
(
LOG_LEVEL
ll
)
{
LOG_VAR
(
ll
)
<<
" "
<<
"Entity "
<<
_name
;
LOG_VAR
(
ll
)
<<
eInd
<<
"Disabled: "
<<
(
_disabled
?
std
::
string
(
"true"
)
:
std
::
string
(
"false"
));
if
(
_mqttPart
!=
""
)
{
LOG_VAR
(
ll
)
<<
eInd
<<
"MQTT part: "
<<
_mqttPart
;
}
...
...
@@ -173,6 +179,7 @@ protected:
std
::
string
_mqttPart
;
///< Partial MQTT topic identifying this entity
bool
_initialized
;
///< An entity should only be initialized once
bool
_disabled
;
std
::
unique_ptr
<
strand
>
_strand
;
///< Provides serialized handler execution to avoid race conditions
LOGGER
lg
;
///< Logging instance
...
...
dcdbpusher/includes/SensorGroupInterface.h
View file @
b5278b79
...
...
@@ -59,6 +59,7 @@ public:
_mqttPart
(
""
),
_sync
(
true
),
_keepRunning
(
false
),
_disabled
(
false
),
_minValues
(
1
),
_interval
(
1000
),
_pendingTasks
(
0
),
...
...
@@ -70,6 +71,7 @@ public:
_mqttPart
(
other
.
_mqttPart
),
_sync
(
other
.
_sync
),
_keepRunning
(
false
),
_disabled
(
other
.
_disabled
),
_minValues
(
other
.
_minValues
),
_interval
(
other
.
_interval
),
_pendingTasks
(
0
),
...
...
@@ -83,6 +85,7 @@ public:
_mqttPart
=
other
.
_mqttPart
;
_sync
=
other
.
_sync
;
_keepRunning
=
false
;
_disabled
=
other
.
_disabled
;
_minValues
=
other
.
_minValues
;
_interval
=
other
.
_interval
;
_pendingTasks
.
store
(
0
);
...
...
@@ -96,6 +99,7 @@ public:
const
std
::
string
&
getGroupName
()
const
{
return
_groupName
;
}
const
std
::
string
&
getMqttPart
()
const
{
return
_mqttPart
;
}
bool
getSync
()
const
{
return
_sync
;
}
bool
isDisabled
()
const
{
return
_disabled
;
}
unsigned
getMinValues
()
const
{
return
_minValues
;
}
unsigned
getInterval
()
const
{
return
_interval
;
}
///@}
...
...
@@ -114,6 +118,7 @@ public:
}
}
void
setSync
(
bool
sync
)
{
_sync
=
sync
;
}
void
setDisabled
(
const
bool
disabled
)
{
_disabled
=
disabled
;
}
void
setMinValues
(
unsigned
minValues
)
{
_minValues
=
minValues
;
}
void
setInterval
(
unsigned
interval
)
{
_interval
=
interval
;
}
///@}
...
...
@@ -197,6 +202,7 @@ public:
*/
virtual
void
printConfig
(
LOG_LEVEL
ll
)
{
LOG_VAR
(
ll
)
<<
" Sensor Group: "
<<
_groupName
;
LOG_VAR
(
ll
)
<<
" Disabled: "
<<
(
_disabled
?
std
::
string
(
"true"
)
:
std
::
string
(
"false"
));
if
(
_mqttPart
!=
""
)
{
LOG_VAR
(
ll
)
<<
" MQTT part: "
<<
_mqttPart
;
}
...
...
@@ -296,6 +302,7 @@ protected:
std
::
string
_mqttPart
;
///< MQTT part identifying this group
bool
_sync
;
///< Should the timer (i.e. the read cycle of this groups) be synchronized with other groups?
bool
_keepRunning
;
///< Continue with next reading cycle (i.e. set timer again after reading)?
bool
_disabled
;
unsigned
int
_minValues
;
///< Minimum number of values a sensor should gather before they get pushed (to reduce MQTT overhead)
unsigned
int
_interval
;
///< Reading interval cycle in milliseconds
std
::
atomic_uint
_pendingTasks
;
///< Number of currently outstanding read operations
...
...
dcdbpusher/includes/SensorGroupTemplate.h
View file @
b5278b79
...
...
@@ -162,6 +162,10 @@ public:
* actions are required during startup.
*/
virtual
void
start
()
final
override
{
if
(
_disabled
)
{
return
;
}
if
(
_keepRunning
)
{
//we have been started already
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" already running."
;
...
...
@@ -174,10 +178,12 @@ public:
}
if
(
_entity
)
{
_keepRunning
=
true
;
_pendingTasks
++
;
_timer
->
async_wait
(
_entity
->
getStrand
()
->
wrap
(
std
::
bind
(
&
SensorGroupTemplate
::
readAsync
,
this
)));
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" started."
;
if
(
!
_entity
->
isDisabled
())
{
_keepRunning
=
true
;
_pendingTasks
++
;
_timer
->
async_wait
(
_entity
->
getStrand
()
->
wrap
(
std
::
bind
(
&
SensorGroupTemplate
::
readAsync
,
this
)));
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" started."
;
}
}
else
{
LOG
(
error
)
<<
"No entity set for group "
<<
_groupName
<<
"! Cannot start polling."
;
}
...
...
@@ -257,7 +263,7 @@ protected:
*/
void
readAsync
()
{
this
->
read
();
if
(
_timer
&&
_keepRunning
)
{
if
(
_timer
&&
_keepRunning
&&
!
_disabled
&&
!
_entity
->
isDisabled
()
)
{
_timer
->
expires_at
(
timestamp2ptime
(
nextReadingTime
()));
_pendingTasks
++
;
_timer
->
async_wait
(
_entity
->
getStrand
()
->
wrap
(
std
::
bind
(
&
SensorGroupTemplate
::
readAsync
,
this
)));
...
...
@@ -386,6 +392,10 @@ public:
* actions are required during startup.
*/
virtual
void
start
()
final
override
{
if
(
_disabled
)
{
return
;
}
if
(
_keepRunning
)
{
//we have been started already
LOG
(
info
)
<<
"Sensorgroup "
<<
_groupName
<<
" already running."
;
...
...
@@ -471,7 +481,7 @@ protected:
*/
void
readAsync
()
{
this
->
read
();
if
(
_timer
&&
_keepRunning
)
{
if
(
_timer
&&
_keepRunning
&&
!
_disabled
)
{
_timer
->
expires_at
(
timestamp2ptime
(
nextReadingTime
()));
_pendingTasks
++
;
_timer
->
async_wait
(
std
::
bind
(
&
SensorGroupTemplate
::
readAsync
,
this
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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