Improve handling of needsHardReset flag and add method to check valid module connected to serial port #282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is related to #280 . I believe the handling of the
needsHardReset
flag could be improved, by not setting it tofalse
with each call toreset()
.Additionally, I added a function called
checkValidModuleConnected()
to address #216 (comment) . In this manner, the user application can callcheckValidModuleConnected()
in thesetup()
function of the Arduino code, and make sure a valid module is connected before any join attempt. This is especially important, because we need a function that returns as fast as possible when a module is not connected or incorrectly wired. For example, a call toreset()
takes several minutes to return if a module is not connected, because of the many instructions carried out within it and the innate timeout given inreadLine()
. ThecheckValidModuleConnected()
function returns in ~30s ifautobaud_first
is set tofalse
, and ~60s if set totrue
.I also added an example CheckModule.ino to showcase the usage of the
checkValidModuleConnected()
function.Additionally, I added a
bool reset_first
topersonalize()
andprovision()
, so the user application can tell the library if they want a soft reset to be performed when calling these functions. For example, if a user performs:checkValidModuleConnected()
Before calling
personalize()
, it would make sense to go directly into the ABP join, without a soft reset first, as the hard reset was already performed. Anyways, I set these paramstrue
by default so that prior behaviour is not broken.Finally, I also updated the documentation.
Help wanted:
Broken: The only caveat with this PR is that the module validation in
checkValidModuleConnected()
is not working as expected. This section in particular:For example, if
model = "RN2903AX"
(impossible, I know, but for the sake of the example), the function will think that this is a valid module, becausepgmstrcmp(model, CMP_RN2903) == 0
returnstrue
. I am not so familiar with the c string functions. Could anyone help me by suggesting how to make the verification work correctly?I went ahead and submitted the PR with this caveat, so that it may be reviewed and a fix to this small issue could be suggested.