Skip to content
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 new feature encodeRadioDetails and optimize sprintfPrettyDetails #825

Merged
merged 68 commits into from
Jan 30, 2022

Conversation

dstroy0
Copy link

@dstroy0 dstroy0 commented Jan 22, 2022

encodeRadioDetails will encode an array of 10 uint32_t (40 bytes) with the exact same information that is found in printPrettyDetails.

decodeRadioDetails works in the same manner as sprintfPrettyDetails, but you pass it the encoded array and it formats the output buffer for you

This is useful for anyone needing status information with no output and stringent memory use requirements.

encodeRadioDetails is meant to be tailored to your use case, you can output as much or as little as you want by adding new members or by commenting existing members out

Decode manually or with decodeRadioDetails.

Documentation needs updating to reflect behavior.

fix auto format, reinsert new functions
add bool packing method to encode_bit_manipulation_methods
update function documentation, work on adding default items to bit array
finish adding members to bit array, add partial debugging output to function
add methods needed to get/unpack interesting values from encoded_details
logic errors in decode_bit_manipulation_methods

fully decode encoded_details, ready for output logic
update encode order, fix logic errors in decode_bit_manipulation_methods
roughed in output for decodeRadioDetails
output is working, incorrectly but it's working.
bit array is indexing correctly and the correct amount of information is being encoded
getting expected output from decodeRadioDetails, we might be able to refactor some of this into sprintfPrettyDetails by giving it a default argument and switching to unpack if that argument is nonzero
update example code for doxygen
@2bndy5
Copy link
Member

2bndy5 commented Jan 23, 2022

@dstroy0 Please enable all workflows on your fork. Typically this can be done by going to https://github.com/dstroy0/RF24/actions, but I can't confirm this because I don't have admin privileges for your fork (and I do not want admin rights for your fork). Please also check the repo settings for your fork at https://github.com/dstroy0/RF24/settings/actions I just want to be sure that the changes you just submitted after opening the PR fixed the PicoSDK and Linux builds.

@dstroy0
Copy link
Author

dstroy0 commented Jan 23, 2022

@dstroy0 Please enable all workflows on your fork. Typically this can be done by going to https://github.com/dstroy0/RF24/actions, but I can't confirm this because I don't have admin privileges for your fork (and I do not want admin rights for your fork). Please also check the repo settings for your fork at https://github.com/dstroy0/RF24/settings/actions I just want to be sure that the changes you just submitted after opening the PR fixed the PicoSDK and Linux builds.

I enabled all of the workflows. I can see them but there's no run workflow button.

fixed a syntax error in the example code for decodeRadioDetails
@2bndy5
Copy link
Member

2bndy5 commented Jan 23, 2022

You can't trigger them manually because they're not setup for that (a rather advanced use case).

You should be able to trigger the Linux & PicoSDK workflows by making a commit that edits the lib source code somehow; I usually just add a bogus comment or new line somewhere to trigger them.

The Arduino CI and PlatformIO CI workflows are triggered by any commit involving the examples folder (not examples_linux or examples_pico folders). Again, I usually just add a bogus comment or new line somewhere to trigger them.

@2bndy5
Copy link
Member

2bndy5 commented Jan 23, 2022

Judging from the latest runs on your fork, the Linux builds and Pico SDK builds look ok again ✅

@2bndy5
Copy link
Member

2bndy5 commented Jan 23, 2022

Fun fact: I setup the docs CI to upload built docs (folder of HTML files) as workflow artifacts which you can download and open on your local machine for inspection.

comment out unused method encode_bit_manipulation_methods::put32BitValueIntoOutputArray()
@dstroy0
Copy link
Author

dstroy0 commented Jan 23, 2022

Judging from the latest runs on your fork, the Linux builds and Pico SDK builds look ok again ✅

Excellent, forgetting to remove that debug output before issuing the pr was a big oof.

create example using encodeRadioDetails(), can be used for testing to verify changes to bit array members before deployment
@dstroy0
Copy link
Author

dstroy0 commented Jan 23, 2022

could maybe add the functions to KEYWORD 2 so the arduino ide highlights them in orange

@2bndy5
Copy link
Member

2bndy5 commented Jan 23, 2022

could maybe add the functions to KEYWORD 2 so the arduino ide highlights them in orange

No objections there. In fact, I didn't check if the same was applied to sprintfPrettyDetails().

Co-authored-by: Brendan <2bndy5@gmail.com>
@2bndy5
Copy link
Member

2bndy5 commented Jan 28, 2022

Ran a local test about my idea for sprintfDets using the new example encodeRadioDets.ino:

as is (without multiple calls to sprintf)

Sketch uses 8396 bytes (27%) of program storage space. Maximum is 30720 bytes.
Global variables use 275 bytes (13%) of dynamic memory, leaving 1773 bytes for local variables. 

with multiple calls to sprintf (& no additionally allocated local buffers)

Sketch uses 7958 bytes (25%) of program storage space. Maximum is 30720 bytes.
Global variables use 279 bytes (13%) of dynamic memory, leaving 1769 bytes for local variables. Maximum is 2048 bytes.

Looks like flash goes down by 438 bytes, but ram goes up by 4 bytes. This is an acceptable balance for me. I'll start cleaning up the tested code and commit, so you can play around a bit further (which might be better than me trying to explain what I did).

sprintfDets and sprintf_reg_addr now return the number of bytes that were altered in the given buffer (just like sprintf does). sprintf_reg_byte is now removed.

EDITED: During clean-up, I saw more reduction in flash 👍🏼 I also found inconsistent indentation in sprintfDets (I think this was overlooked in #821 ).

@dstroy0 When you run clang-format, do you have this .clang-format file located in the repo's root? If not then the formatting is following LLVM code style which is different (much stricter) than the rules I've setup for this repo (on the clang-format branch).

RF24.cpp Outdated Show resolved Hide resolved
RF24.cpp Outdated Show resolved Hide resolved
RF24.cpp Outdated Show resolved Hide resolved
@dstroy0
Copy link
Author

dstroy0 commented Jan 28, 2022

Everything looks great! I wont have a chance to test anything until this evening. I will figure out how to make the clang-format extension use that format specifier.

@dstroy0
Copy link
Author

dstroy0 commented Jan 29, 2022

I got clang-format to use the .clang-format file

4 bytes of ram saved on avr back down to 232 bytes global usage
@2bndy5
Copy link
Member

2bndy5 commented Jan 30, 2022

Sketch uses 7958 bytes (25%) of program storage space. Maximum is 30720 bytes.
Global variables use 275 bytes (13%) of dynamic memory, leaving 1773 bytes for local variables. Maximum is 2048 bytes.

YES! That's what I was going for: Reduced flash, and don't add to ram. @dstroy0 Thanks for fixing my mistakes.

@2bndy5 2bndy5 changed the title add new features encodeRadioDetails and decodeRadioDetails add new feature encodeRadioDetails and optimize sprintfPrettyDetails Jan 30, 2022
@2bndy5
Copy link
Member

2bndy5 commented Jan 30, 2022

I just had another itch to re-use the lib's private SPI buffers (spi_rxbuff or spi_txbuff) in *print*_address_register(). This idea would benefit all printDets methods...

@2bndy5
Copy link
Member

2bndy5 commented Jan 30, 2022

Nope nevermind. I forgot that those private SPI buffers only exist on platforms that have more memory

#if defined (RF24_LINUX) || defined (XMEGA_D3) || defined (RF24_RP2)

Copy link
Member

@2bndy5 2bndy5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ready to merge this unless you can think of more optimizations

@dstroy0
Copy link
Author

dstroy0 commented Jan 30, 2022 via email

@2bndy5 2bndy5 merged commit 1e4c4a3 into nRF24:master Jan 30, 2022
@2bndy5
Copy link
Member

2bndy5 commented Jan 30, 2022

I’ll be sure to open an issue in the future before doing a PR

Yes. Please do as that would provide a way to have separate discussions about ideas and code review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants