Improve flex decoder by enabling lua code for validation and/or decoding#3399
Improve flex decoder by enabling lua code for validation and/or decoding#3399pjsg wants to merge 16 commits intomerbanan:masterfrom
Conversation
|
Interesting proposal. We were thinking about some kind of DSL to improve the flex syntax for a long time now. Central would be easy syntax to address and extract (ranges of) bits from the bitbuffer. I'm not sure how well this fits Lua. A sketch of such an operator was: Single bit (e.g. bit 6): |
|
I was thinking about that -- my initial thought was to add support for an enhanced version of http://www.inf.puc-rio.br/~roberto/struct/ which added support for bit fields. For example, allow "I:n" and "i:n" to be unsinged and signed n bit integers, and "X:n" to be an n bit skip. All the existing format characters would (I think) trigger a skip to the next byte boundary. I.e. it would like like a C structure definition with bit fields and regular fields. I would need to think about reversed bit fields. |
|
I'm working on this -- but taking a slightly different approach -- adding some useful methods to extract a bitfield from consecutive bits in various little/big endian styles. |
…sor methods. See the docs for details.
|
The equivalent of your example function decode(packets)
-- assume we have validated checksum etc
local p = packets[1]
return {val=p[{0,4}] *10 + p[{4,4}] + p[{8,4}] * 0.1}
endThis assumes stuff about bit ordering, but that is easily settable. I think that I'll add support for negative widths and omitted widths. For negative widths: if the buffer is 01101010 11000101 then [13:-6] is 100011 => 35 (decimal). Does that align with your understanding? @zuckschwerdt |
the width now defaults to 1 bit.
Yes, the syntax looks clean and useable. Very nice! |
|
I think that we should use a cmake property for Lua to offer the same AUTO ON OFF options as for OPENSSL, RTLSDR, SOAPYSDR. |
|
Quick question -- which do you think is more natural -- starting with bot 0 as the least significant bit of the first byte, or bit 0 is the most significant bit of the first byte? I'd just set the default to the natural approach. |
|
That's an age old debate. Having been raised in a PDP-11 household, it's obvious that bit 0 is the least significant bit. My view is that computer instructions lean that way, even if IEEE networking specs lean the other. I think rtl_433 should have a global style rule about this, and I'd vote for "bit 0 is LSB" and "bit 7 is MSB" for 8-bit bytes. |
|
Yes, rtl_433 is special here: we fill the bits starting from "the left". I.e. the first decoded symbol goes to 0x80. |
|
Thanks -- I'll leave the default as the first bit is the 0x80 bit of the first byte. |
…he way that it is.
…es like the other ENABLE_* options.
|
Is there anything more that I need to do? |
|
How many different operating systems has this been tested on? |
|
I'd opt to keep it 7-bit ASCII and not add emoji's to CMakeLists.txt. |
Agreed. Sources should remain ASCII, with UTF-8 as needed for contributor's names. |
|
I've tested operation on linux (rpi). It builds on MacOS (and passes tests), and I'm trying to get a Windows box to figure out how to do the various build/install steps. |
2e725ca to
5e76779
Compare
This PR adds support in the flex decoder for using LUA code to validate received messages and/or improve decoding (for those cases where 'get' is insufficient). The LUA extension is only built if LUA 5.4 development libraries can be found when building rtl_433.
A document describing the structure and functionality of the LUA code is at LUA docs.
I needed this in order to validate the message integrity checks of a remote control. I also wanted the decoded message that gets sent over MQTT to include the name of the button that was pressed.