-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for Gridstream RF protocol from Landis & Gyr meters #2616
base: master
Are you sure you want to change the base?
Conversation
Can you add relevant information from here: |
src/devices/gridstream.c
Outdated
NULL, | ||
}; | ||
|
||
r_device const gridstream = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate this for the other rates and change the name to match the rate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the other rates, and they appear to work, at least with my saved samples. However, I cannot determine a way to output the bitrate in the data table.
Looks good, make sure to run the maintainer update script also. |
There are changes to README and man page that seem like they have crept in vs being intended. |
@@ -254,7 +254,9 @@ | |||
DECL(fineoffset_ws90) \ | |||
DECL(thermopro_tx2c) \ | |||
DECL(tfa_303151) \ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line should be left. While it doesn't matter if it's there or not in the grand scheme of things, commits should not make unintended changes.
src/devices/gridstream.c
Outdated
{0x142A, "Washington", "Puget Sound Energy"}, | ||
{0x47F7, "Pennsylvania", "PPL Electric"}, | ||
{0x22c6, "Long Island, NY", "PSEG Long Island"}}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to have a comment explaining if you have to search, or what the grand plan is. Looks like search, but there is wisdom in somebody's head not in comments right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decoder attempts all of the known CRC init values until it finds one that works. If they all fail, either the data is actually bad, or the CRC init is not known. In the case of the latter, using the reveng program with several fixed length bytestreams with CRC terminated values can output a previously unknown CRC init value, which is how the current values in the struct were derived. This struct would continue to be expanded (through PRs) as new ones are identified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's irregular, but makes sense. What I was asking for was for the PR to be amended so that this wisdom would be in the code, so that people reading it, long after the pull request is closed, would see it. (My review is that when we merge, there should be no reason for anyone to look at the PR history.)
src/devices/gridstream.c
Outdated
0x7F, | ||
0xF8, | ||
}; | ||
uint8_t *b = malloc(bitbuffer->bits_per_row[0] / 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is normal, but I'm nervous about not storing b's length for bounds checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the maximum size of the gridstream data stream is not known (to my knowledge), and the bitbuffer length can be arbitrarily sized, there was no way to set a maximum size of b without the possibility of overflow issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but needs to be explained in comments in the code to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last offset you are reading seems b[37]
? Then clamp the input length from bitbuffer->bits_per_row[0] - offset - 37
to 38*8
and use a fixed 38 byte buffer. Or any sane upper length really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CRC location is based on an offset value that is stored in the datastream and there have been some discovered streams that were much longer than 38 bytes, but are still unknown at this time on how to interpret. Arbitrarily limiting the size would reduce the streams that would captured and/or potentially cause memory exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume a sane upper bound, say 50(?) bytes, and abort with a warning if a longer message is encountered. That will additionally gain insight into the protocol. Potentially accepting multiple kB of message does not sound proper. If length is a byte then it's bounded anyway ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know for certain, but it is believed length is a double byte, as the byte before has always been 0x00. But then again, if it is always 0x00, that is effectively a single byte.
src/devices/gridstream.c
Outdated
|
||
decoder_output_data(decoder, data); | ||
break; | ||
case 0xD2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing is odd here, and that makes it a tiny bit harder to read.
src/devices/gridstream.c
Outdated
free(b); | ||
return DECODE_FAIL_MIC; | ||
} | ||
sprintf(found_crc, "%04x", known_crc_init[crcidx].value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what's happening here, but given that location/provider are not precomputed it made me think there was a bug. I would prefer to see all three handled the same way so that the reader is led to the right conclusion the first time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found_crc is the only one that needs a transform to string from the struct in order to be displayed properly in the output data. The location/provider is already in a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would still be nice to regularize and/or comment, to make a reader who is competent but not expert quickly come to the right conclusion.
src/devices/gridstream.c
Outdated
case 0xD5: | ||
sprintf(destaddress_str, "%02x%02x%02x%02x", b[5], b[6], b[7], b[8]); | ||
sprintf(srcaddress_str, "%02x%02x%02x%02x", b[9], b[10], b[11], b[12]); | ||
if (stream_len == 0x47) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are conditional "include this item if this condition is true" constructs. That would perhaps make this easier to understand, if that fits the situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would conditional items be handled with the data output? I've not found any example of conditional constructs with data make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See fineoffset_ws80.c and look for DATA_COND. There is a way to have what is basically an if statement and if true, the item is added, and if not, it isn't. At least that's my understanding.
conf/rtl_433.example.conf
Outdated
# protocol 245 # ThermoPro TX-2C Thermometer | ||
# protocol 245 # ThermoPro TX-2C Thermometer and Humidity sensor | ||
protocol 246 # TFA 30.3151 Weather Station | ||
protocol 247 # Gridstream decoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"decoder" has no content . Perhaps
protocol 247 # Gridstream (power meters)
if that's fair.
I think this might solve my need -- my water company just swapped out the previous meter for a Landis + Gyr GridLinx Interpreter which supposedly connects to the GridStream network. Is there anything I can do to help get this out of development and into production? It looks like it maybe just failed a single test on code style... |
The CRLF problems need to be fixed, indentation fixed, some comments added, style updated (as per the review) and then it should be in good shape to merge. Maybe we need to manually merge with those fixes added? |
I had made most of the recommendations to a separate branch here, but I have not had time to move forward with finishing it up. |
Reset and repushed, but the maintainer_update changed a bunch of other stuff in the README. I'm not sure why. |
Should be good to go now. |
What's the status of this? I'm looking at #2531 and it sort of seems like if this were merged we could close the issue and be down two items. |
LGTM, we need some samples though and a rebase. |
What do you need for samples? There are some in the issue discussion #2531. |
Trouble is that this decoder uses extra headers of |
stdlib.h is described at https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html It is surprising to me that use of it in rtl_433 is novel. But
|
Decoders (src/devices) should not use stdlib because alloc() should not be used. It appears you don't alloc, why do you need stdlib? |
I guess it's easy enough to remove it and see if there is a warning. |
Good catch. It was leftover from the initial attempt using a dynamic bitbuffer size. |
Any chance this could be merged? I'd love to use this functionality! Thanks |
This PR is to add initial support for the Gridstream RF protocol as discussed in #2531.