mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
WMBUS: avoid CRC errors when used with a culfw that does not support RSSI/LQI
git-svn-id: https://svn.fhem.de/fhem/trunk@6562 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2b5d30b786
commit
56327bf3d3
@ -40,6 +40,7 @@ use WMBus;
|
|||||||
sub WMBUS_Parse($$);
|
sub WMBUS_Parse($$);
|
||||||
sub WMBUS_SetReadings($$$);
|
sub WMBUS_SetReadings($$$);
|
||||||
sub WMBUS_SetRSSI($$$);
|
sub WMBUS_SetRSSI($$$);
|
||||||
|
sub WMBUS_RSSIAsRaw($);
|
||||||
|
|
||||||
sub WMBUS_Initialize($) {
|
sub WMBUS_Initialize($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
@ -80,6 +81,8 @@ WMBUS_Define($$)
|
|||||||
|
|
||||||
($msg, $rssi) = split(/::/,$msg);
|
($msg, $rssi) = split(/::/,$msg);
|
||||||
|
|
||||||
|
$msg .= WMBUS_RSSIAsRaw($rssi);
|
||||||
|
|
||||||
return "a WMBus message must be a least 12 bytes long" if $msg !~ m/b[a-zA-Z0-9]{24,}/;
|
return "a WMBus message must be a least 12 bytes long" if $msg !~ m/b[a-zA-Z0-9]{24,}/;
|
||||||
|
|
||||||
$mb = new WMBus;
|
$mb = new WMBus;
|
||||||
@ -212,6 +215,7 @@ WMBUS_Parse($$)
|
|||||||
my $mb = new WMBus;
|
my $mb = new WMBus;
|
||||||
|
|
||||||
($msg, $rssi) = split(/::/,$msg);
|
($msg, $rssi) = split(/::/,$msg);
|
||||||
|
$msg .= WMBUS_RSSIAsRaw($rssi);
|
||||||
|
|
||||||
if ($mb->parseLinkLayer(pack('H*',substr($msg,1)))) {
|
if ($mb->parseLinkLayer(pack('H*',substr($msg,1)))) {
|
||||||
$addr = join("_", $mb->{manufacturer}, $mb->{afield_id}, $mb->{afield_ver}, $mb->{afield_type});
|
$addr = join("_", $mb->{manufacturer}, $mb->{afield_id}, $mb->{afield_ver}, $mb->{afield_type});
|
||||||
@ -252,18 +256,41 @@ WMBUS_Parse($$)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# if the culfw doesn't send the RSSI value (because it an old version that doesn't implement this) but 00_CUL.pm already expects it
|
||||||
|
# one byte is missing from the data which leads to CRC errors
|
||||||
|
# To avoid this calculate the raw data byte from the RSSI and append it to the data.
|
||||||
|
# If it is a valid RSSI it will be ignored by the WMBus parser (the data contains the length of the data itself
|
||||||
|
# and only that much is parsed).
|
||||||
|
sub WMBUS_RSSIAsRaw($) {
|
||||||
|
my $rssi = shift;
|
||||||
|
|
||||||
|
if (defined $rssi) {
|
||||||
|
if ($rssi < -74) {
|
||||||
|
$b = ($rssi+74)*2+256;
|
||||||
|
} else {
|
||||||
|
$b = ($rssi+74)*2;
|
||||||
|
}
|
||||||
|
return sprintf("%02X", $b);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub WMBUS_SetRSSI($$$) {
|
sub WMBUS_SetRSSI($$$) {
|
||||||
my ($hash, $mb, $rssi) = @_;
|
my ($hash, $mb, $rssi) = @_;
|
||||||
|
|
||||||
|
if (defined $mb->{remainingData} && length($mb->{remainingData}) >= 2) {
|
||||||
|
# if there are trailing bytes after the WMBUS message it is the LQI and the RSSI
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
# RSSI is decoded by 00_CUL.pm from the last byte of the message
|
my ($lqi, $rssi) = unpack("CC", $mb->{remainingData});
|
||||||
readingsBulkUpdate($hash, "RSSI", $rssi ? $rssi : 'unknown');
|
$rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74));
|
||||||
if (defined $mb->{remainingData} && length($mb->{remainingData}) >= 1) {
|
|
||||||
# if there is a trailing byte after the WMBUS message it is the LQI
|
readingsBulkUpdate($hash, "RSSI", $rssi);
|
||||||
readingsBulkUpdate($hash, "LQI", unpack("C", $mb->{remainingData}));
|
readingsBulkUpdate($hash, "LQI", unpack("C", $mb->{remainingData}));
|
||||||
}
|
|
||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub WMBUS_SetReadings($$$)
|
sub WMBUS_SetReadings($$$)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user