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
e4db3ce6
Commit
e4db3ce6
authored
Oct 19, 2018
by
Michael Ott
Browse files
Switch to 112bit MQTT topics
parent
55d51d27
Changes
5
Hide whitespace changes
Inline
Side-by-side
CollectAgent/collectagent.cpp
View file @
e4db3ce6
...
...
@@ -167,7 +167,6 @@ int mqttCallback(SimpleMQTTMessage *msg)
<< " Raw: " << hex << setw(16) << setfill('0') << sid.getRaw()[0] << hex << setw(16) << setfill('0') << sid.getRaw()[1] << endl
<< " DeviceLocation: " << hex << setw(16) << setfill('0') << sid.getDeviceLocation() << endl
<< " device_id: " << hex << setw(8) << setfill('0') << sid.getDeviceSensorId().device_id << endl
<< " reserved: " << hex << setw(4) << setfill('0') << sid.getDeviceSensorId().rsvd << endl
<< " sensor_number: " << hex << setw(4) << setfill('0') << sid.getDeviceSensorId().sensor_number << endl << dec;
cout << "Payload (" << len/sizeof(mqttPayload) << " messages):"<< endl;
...
...
CollectAgent/sensorcache.cpp
View file @
e4db3ce6
...
...
@@ -125,7 +125,7 @@ uint64_t SensorCache::getSensor(std::string topic, uint64_t avg) {
return
getSensor
(
DCDB
::
SensorId
(
topic
),
avg
);
}
int
wl
=
33
-
topic
.
length
();
int
wl
=
29
-
topic
.
length
();
/* Create SensorIds with the lowest and highest values matching the wildcard */
DCDB
::
SensorId
sidLow
(
std
::
string
(
topic
).
replace
(
wp
,
1
,
std
::
string
(
wl
,
'0'
)));
...
...
lib/include/dcdb/sensorid.h
View file @
e4db3ce6
...
...
@@ -49,8 +49,8 @@ typedef uint64_t DeviceLocation;
* approach is, for example, to use MAC addresses as the device_id.
*/
typedef
struct
{
uint64_t
sensor_number
:
16
;
/**< The sensor_number of the sensor */
uint64_t
rsvd
:
16
;
/**< Reserved */
uint64_t
sensor_number
:
16
;
/**< The sensor_number of the sensor */
uint64_t
device_id
:
32
;
/**< The location-independent device_id */
}
DeviceSensorId
;
...
...
lib/src/sensorconfig.cpp
View file @
e4db3ce6
...
...
@@ -184,8 +184,8 @@ bool SensorConfigImpl::validateSensorPattern(const char* sensorPattern)
{
unsigned
int
wildcards
,
bits
;
/* 12
8
bits in HEX is at most
3
2 characters. Considering forward-slash separators, 6
4
is a reasonable maxmimum string length */
if
(
strlen
(
sensorPattern
)
>
6
4
)
{
/* 1
1
2 bits in HEX is at most 2
8
characters. Considering forward-slash separators,
5
6 is a reasonable maxmimum string length */
if
(
strlen
(
sensorPattern
)
>
5
6
)
{
return
false
;
}
...
...
@@ -241,7 +241,7 @@ bool SensorConfigImpl::validateSensorPattern(const char* sensorPattern)
return
false
;
/* In case of a wildcard, there should be some bits left for the wildcard to fill in */
if
(
wildcards
==
1
&&
bits
>=
12
8
)
if
(
wildcards
==
1
&&
bits
>=
1
1
2
)
return
false
;
/* Looks good */
...
...
@@ -903,10 +903,14 @@ SCError SensorConfigImpl::getSensorListForPattern(std::list<SensorId>& sensorIds
std
::
string
low
=
pattern
;
std
::
string
high
=
pattern
;
if
(
pattern
.
find
(
"*"
)
!=
std
::
string
::
npos
)
{
low
.
replace
(
pattern
.
find
(
"*"
),
1
,
33
-
pattern
.
length
(),
'0'
);
high
.
replace
(
pattern
.
find
(
"*"
),
1
,
33
-
pattern
.
length
(),
'F'
);
low
.
replace
(
pattern
.
find
(
"*"
),
1
,
29
-
pattern
.
length
(),
'0'
);
high
.
replace
(
pattern
.
find
(
"*"
),
1
,
29
-
pattern
.
length
(),
'F'
);
}
/* The week stamp is imprinted on the lower 4 bits */
low
.
append
(
"0000"
);
high
.
append
(
"FFFF"
);
SensorId
lowId
,
highId
;
if
(
!
lowId
.
mqttTopicConvert
(
low
))
{
return
SC_INVALIDPATTERN
;
...
...
lib/src/sensorid.cpp
View file @
e4db3ce6
...
...
@@ -119,7 +119,7 @@ bool SensorId::mqttTopicConvert(std::string mqttTopic)
const
char
*
buf
=
mqttTopic
.
c_str
();
data
.
raw
[
0
]
=
0
;
data
.
raw
[
1
]
=
0
;
while
(
*
buf
&&
pos
<
12
8
)
{
while
(
*
buf
&&
pos
<
1
1
2
)
{
if
(
*
buf
>=
'0'
&&
*
buf
<=
'9'
)
{
data
.
raw
[
pos
/
64
]
|=
(((
uint64_t
)(
*
buf
-
'0'
))
<<
(
60
-
(
pos
%
64
)));
pos
+=
4
;
...
...
@@ -134,7 +134,7 @@ bool SensorId::mqttTopicConvert(std::string mqttTopic)
}
buf
++
;
}
return
pos
==
12
8
;
return
pos
==
1
1
2
;
}
/**
...
...
@@ -154,13 +154,13 @@ std::string SensorId::serialize() const
/**
* @details
* This function returns a hex representation of a SensorId as a
*
3
2-character std::string.
* 2
8
-character std::string.
*/
std
::
string
SensorId
::
toString
()
const
{
char
buf
[
33
];
snprintf
(
buf
,
sizeof
(
buf
),
"%016"
PRIx64
"%016"
PRIx64
,
data
.
raw
[
0
],
data
.
raw
[
1
]);
return
std
::
string
(
buf
);
return
std
::
string
(
buf
)
.
substr
(
0
,
28
)
;
}
/**
...
...
@@ -178,12 +178,12 @@ bool SensorId::patternMatch(std::string pattern)
boost
::
algorithm
::
to_lower
(
pattern
);
/* Calculate the wildcard length */
int
wl
=
(
pattern
.
find
(
"*"
)
!=
std
::
string
::
npos
)
?
33
-
pattern
.
length
()
:
0
;
int
wl
=
(
pattern
.
find
(
"*"
)
!=
std
::
string
::
npos
)
?
29
-
pattern
.
length
()
:
0
;
/* Do a character by character comparison */
int
posP
=
0
;
int
posS
=
0
;
while
(
posS
<
3
2
)
{
while
(
posS
<
2
8
)
{
char
p
,
cs
[
2
];
uint64_t
s
;
p
=
pattern
.
c_str
()[
posP
];
...
...
@@ -198,7 +198,7 @@ bool SensorId::patternMatch(std::string pattern)
posP
++
;
continue
;
}
else
if
((
posS
>=
24
&&
posS
<=
27
)
||
(
p
==
cs
[
0
])
)
{
else
if
(
p
==
cs
[
0
])
{
posS
++
;
posP
++
;
continue
;
...
...
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