-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve/refactor shared Acurite TXR decoder #2162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Looks really good! Thanks! |
Thanks. I'm not sure how to make the symbolizer happy or how to figure out what it is complaining about. I changed the |
Doc-comments attach to the next function definition. A block at the top with some helpers between then needs to specify the function, e.g. |
The process is this: for an |
Ok, I'll try to make those doc comments fit. Is there a way to see what function an error like |
Added I'm not sure why it is flagging an issue finding
|
I'll have a look. The messages need to be better anyway if possible. |
Ah, in the doc comment meant for |
In other words: Have |
Ok thanks for the tip about running ./tests/symbolizer.py locally. I'm tripping over a few things. So if I understand, I need
generates
|
EDITED/UPDATED
I think I've eliminated those, please let me know if not. There seem to be certain doc blocks that cause the But I still can't get past, I think you've indicated that one or more models should be attached to the callback I think you've indicated Based on what you wrote, I don't think I should need any Thank you for your help. |
One more quirk: we only consider function signatures of |
Ah thanks - glad to know it wasn't something I was doing wrong. Is there a workaround I should be doing to make the tests pass? |
The quick fix would be to use e.g.
Then each device decoder can be regcognized, has the proper doc-comment and is sa-linked, which should be enough. |
@deviantintegral - If you get a chance, can you test this PR against your 899 rain gauge? Two things to look at: The test to reject short messages from #2116 is much more general and I've added parity checking for the 899 (actually all devices that share this decoder except the 3n1). From the samples you have provided in merbanan/rtl_433_tests#428 I couldn't verify that parity checking was used on the data bytes. However I could see that parity checking was used on the message type byte. |
[...]
So does it only match the first two arguments or does it need an exact match for three? I converted one function (899) to the signature you suggested and |
Rebase to get the fixed symbolizer messages, then patch like this and it should work (but also fix calls and add diff --git a/src/devices/acurite.c b/src/devices/acurite.c
index 2de4710b..08c8f297 100644
--- a/src/devices/acurite.c
+++ b/src/devices/acurite.c
@@ -193,7 +193,7 @@ static int acurite_rain_896_decode(r_device *decoder, bitbuffer_t *bitbuffer)
return 1;
}
-/*
+/**
Acurite 609 Temperature and Humidity Sensor.
5 byte messages:
@@ -271,7 +271,7 @@ static int acurite_th_decode(r_device *decoder, bitbuffer_t *bitbuffer)
return result;
}
-/*
+/**
Acurite 06045m Lightning Sensor decoding.
Specs:
@@ -480,11 +480,11 @@ static int acurite_6045_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsign
}
-/*
+/**
Acurite 899 Rain Gauge decoder
*/
-static int acurite_899_decode(r_device* decoder, uint8_t* bb)
+static int acurite_899_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// MIC (checkum, parity) validated in calling function
@@ -530,11 +530,11 @@ static int acurite_899_decode(r_device* decoder, uint8_t* bb)
}
-/*
+/**
Acurite 3n1 Weather Station decoder
*/
-static int acurite_3n1_decode(r_device* decoder, uint8_t* bb)
+static int acurite_3n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// MIC (checkum, parity) validated in calling function
@@ -611,11 +611,11 @@ static int acurite_3n1_decode(r_device* decoder, uint8_t* bb)
}
-/*
+/**
Acurite 5n1 Weather Station decoder
*/
-static int acurite_5n1_decode(r_device* decoder, uint8_t* bb)
+static int acurite_5n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// MIC (checkum, parity) validated in calling function
@@ -959,7 +959,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
return 1; // one valid message decoded
}
-/*
+/**
Acurite 592TXR Temperature Humidity sensor decoder
Message Type 0x04, 7 bytes
@@ -987,7 +987,7 @@ Notes:
- @todo - check if high 3 bits ever used for anything else
*/
-static int acurite_tower_decode(r_device* decoder, uint8_t* bb)
+static int acurite_tower_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// MIC (checkum, parity) validated in calling function
@@ -1045,7 +1045,7 @@ static int acurite_tower_decode(r_device* decoder, uint8_t* bb)
return 1;
}
-/*
+/**
Acurite 1190/1192 leak detector
Note: it seems like Acurite has deleted this product and
@@ -1053,7 +1053,7 @@ related information from their website so specs, manual, etc.
aren't easy to find
*/
-static int acurite_1190_decode(r_device* decoder, uint8_t* bb)
+static int acurite_1190_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// Channel is the first two bits of the 0th byte
// but only 3 of the 4 possible values are valid
@@ -1101,7 +1101,7 @@ CCII IIII | IIII IIII | pBMM MMMM | bTTT TTTT | bTTT TTTT | KKKK KKKK
- p: Parity bit
*/
-static int acurite_515_decode(r_device* decoder, uint8_t* bb)
+static int acurite_515_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t* bb)
{
// length, MIC (checkum, parity) validated in calling function
@@ -1172,7 +1172,7 @@ static int acurite_515_decode(r_device* decoder, uint8_t* bb)
return 1;
}
-/*
+/**
Check Acurite TXR message integrity (length, checksum, parity)
Need to pass in expected length - correct number of bytes for
@@ -1232,16 +1232,16 @@ static int acurite_txr_check(r_device *decoder, uint8_t const bb[], unsigned bro
}
-/*
+/**
Process messages for Acurite weather stations, tower and related sensors
- sa acurite_1190_decode()
- sa acurite_515_decode()
- sa acurite_6045_decode()
- sa acurite_899_decode()
- sa acurite_3n1_decode()
- sa acurite_5n1_decode()
- sa acurite_atlas_decode()
- sa acurite_tower_decode()
+@sa acurite_1190_decode()
+@sa acurite_515_decode()
+@sa acurite_6045_decode()
+@sa acurite_899_decode()
+@sa acurite_3n1_decode()
+@sa acurite_5n1_decode()
+@sa acurite_atlas_decode()
+@sa acurite_tower_decode()
This callback is used for devices that use a very similar message format:
@@ -1489,7 +1489,7 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuffer)
return error_ret;
}
-/*
+/**
Acurite 00986 Refrigerator / Freezer Thermometer.
Includes two sensors and a display, labeled 1 and 2, |
Note, since it's easy to miss: you must attach the asterisk to the variable name, not the type. |
For reference:
Reason: we want to automatically generate documentation for each |
The acurite_txr_decode function that handles Atlas, 5n1, and 3n1 weather stations, TXR temperature/humidity, 6045 lightning, 515 refrigerator/freezer and1190/1192 water sensors, and 899 rain gauge has been refactored. Changes: * Refactor 5n1, 3n1, 515, 899 decoders into separate decoding function * The shared callback function should be easier to understand and add new devices * Fix: valid messages with checksum == 0 were being rejected * This was due to a bad check for an extra byte being added by demodulators * Test case `-y 3863187dbbc6f3d87bff` * Fix: Invalid short messages could be accepted resulting in bad data if last byte of message resulted in a valid checksum * Test case 9 byte Atlas message that should be rejected `-y 'f8 63 99 fc 7b af 3f 5f'` * See also PR merbanan#2116 * Improve rejection of invalid messages * Use message type, rather than message length as the primary identifier * Validate minimum message length by specific message type * Accept messages with one or more extra bytes (demodulator can add extra bits) * but only use correct number of bytes for the specific message type. * Add parity check to MIC for all devices except the 3n1 weather station * Parity was previously only being checked correctly for the tower and leak detector * (The 3n1's g001 sample in rtl_433_tests has odd parity on the 2nd to last byte of both message copies. It seems unlikely both repeats would have the same problem. However the g002 sample does use even parity on all bytes. * Note: the samples for the 899 range gauge do not have enough data to verify parity is used on the whole message. Need testing from someone with this device. * Reject messages if certain fields such as temperature, humidity, wind direction, and other fields have invalid values (such as humidity > 100). This helps when the MIC passes, but there is invalid data in the message. * Previously some sanity checks for humidity and temperature were added to a few devices like the tower sensor. Most devices now have humidity validated at a minimum.
2ca60ce
to
64be12b
Compare
@zuckschwerdt - thanks for your help. All passing now. I'm not sure if it is intentional or not, but now symbolizer seems to be exiting non-zero on warnings. So in order to get the test to pass I had to add doc blocks for the other decoders I didn't touch in order to get symbolizer to exit 0 (so the test would pass).
Yes, this was an important tip. I was scratching my head over this. |
I built this branch locally and it's showing my rain meter correctly. I still need to rebuild it in the home assistant addon so it can run for a few days and have a chance to pick up any short frames, but can hopefully do that this weekend. |
@deviantintegral - Thanks -- two ways to verify that parity checking isn't blocking any 899 messages:
|
Did the test and verification work out? Is this good for merge? |
@zuckschwerdt - I tested with my live devices (Atlas, Towers, 6045, 515) and samples for the 899, 1190, and 5n1 provided by @deviantintegral and @DAVe3283 Based on the samples from @DAVe3283 in #1953 (comment) I get the same decodes with the existing code and the new code, though I get one more successful decode of one of the towers. I was hoping to get confirmation from @deviantintegral or someone else with the 899 that the 899 does in fact use parity checking on the data bytes. I've been running the updated code for a number of weeks. The parity checking and sanity checking have eliminated a bunch of bad data. |
I’ve been running this for a week or two now with no issues. There’s been no incorrect readings or other issues. I’ve been unable to test manually tipping the bucket, but it did rain and appear to report correctly. |
The
acurite_txr_decode
function that handles Atlas, 5n1, and 3n1 weather stations, TXR temperature/humidity, 6045 lightning, 515 refrigerator/freezer and1190/1192 water sensors, and 899 rain gauge has been refactored. Changes:-y 3863187dbbc6f3d87bff
-y 'f8 63 99 fc 7b af 3f 5f'
These tests should work with both the old code and the new code: