-
Notifications
You must be signed in to change notification settings - Fork 152
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
Enhance requestAddress by looping through poll responses #238
Conversation
- When beginning to request an address, the requesting node will gather poll responses. Utilize all poll responses: If an address request fails, continue looping through available poll responses until all address requests at that level have been exhausted
- Move gotResponse variable into loop so it defaults to 0
It's hard to believe we didn't pick up on this before. I can't think of any disadvantages. Maybe users might observe a slower mesh connecting performance when the mesh is well populated, but this feels like the proper approach regardless. |
Haha, I know right? The whole polling system was built on having multiple polls, so why we didn't exploit that fact before is beyond me. I think it should offer better performance in most situations, since one problem with a populated mesh is receiving polls from the wrong 'level' when poll responses are delayed. |
Looking at the whole function body, I think we can optimize the while loop that collects poll responses. Lines 325 to 356 in 7c30deb
#if defined(MESH_DEBUG)
bool goodSignal = radio.testRPD();
#endif
while (millis() - timr < 55 && pollCount < MESH_MAXPOLLS) {
if (network.update() == NETWORK_POLL) {
uint16_t contact = 0;
memcpy(&contact, &network.frame_buffer[0], sizeof(contact));
// Drop duplicate polls to help prevent duplicate requests
bool isDupe = false;
for (uint8_t i = 0; i < pollCount; ++i) {
if (contact == contactNode[i]) {
isDupe = true;
break;
}
}
if (!isDupe) {
contactNode[pollCount] = contact;
++pollCount;
}
IF_MESH_DEBUG(printf_P(PSTR("%u: MSH Poll %c -64dbm\n"), millis(), (goodSignal ? '>' : '<')));
} // end if
MESH_CALLBACK
} // end while
IF_MESH_DEBUG(printf_P(PSTR("%u: MSH Got poll from level %d count %d\n"), millis(), level, pollCount));
if (!pollCount) return 0; |
BTW, I think it is more performant to uint32_t timeout = millis() + 225;
while (millis() < timeout) { /* ... */ } instead of uint32_t timr = millis();
while (millis() - timr < 225) { /* ... */ } because the arithmetic for calculating the time diff is abstracted away from each iteration of the loop. |
Updated per your suggestions but slightly modified:
|
* Enhance request address - When beginning to request an address, the requesting node will gather poll responses. Utilize all poll responses: If an address request fails, continue looping through available poll responses until all address requests at that level have been exhausted * Move gotResponse variable - Move gotResponse variable into loop so it defaults to 0 * - Further improve requestAddress - Per @2bndy5 in #238 - Change debug prints: Remove millis calls and improve human readability - Adjust timeout calculations to be calculated out of loop - Change main polling loop per @2bndy5 * Mods per @2bndy5 in #238 - Use same timeout variable - Add return 0 if 0 polls received
FYI, I cherry picked the merge commit from this PR onto the 1.x branch. If I overstepped (or somehow screwed it up), then it can be reverted. |
I keep forgetting about the 1.x branch. Glad you remembered! @2bndy5 Are we about due for a release crusade? Its been around a year since the last release... |
Yeah, we probably should. Although, the only real changes that affect Arduino platform (which are directly influenced by our tagged commits/releases) are the network layers. The RF24 lib itself just has doc & example updates; the rest is specific to Linux (nRF24/RF24@v1.4.8...master). I gotta get back to investigating the piwheels' 32-bit build problem with pyRF24 deployments (nRF24/pyRF24#61)... |
Old Behaviour Example:
NETWORK_POLL
New Behaviour Example:
NETWORK_POLL
Still testing this new code, but it basically involves moving one bracket and changing some
return
statements tocontinue
s.