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

smart beaconing: fix #92

Closed
dl9sau opened this issue Oct 17, 2021 · 1 comment
Closed

smart beaconing: fix #92

dl9sau opened this issue Oct 17, 2021 · 1 comment

Comments

@dl9sau
Copy link

dl9sau commented Oct 17, 2021

Someone said, smart-beaconing implementation is not so smooth.
I looked in the code and found situations where the result is negative. The negative result is assigned to unsigned long, which gives us a very high variable -> the next beacon is either in a few weeks, or user drops speed, or drives a curve.
Concrete: sb_max_speed-sb_min_speed is negative i.e. in 100max-120current

Current code

   nextTX = (sb_max_interval-sb_min_interval)/(sb_max_speed-sb_min_speed)*(sb_max_speed-average_speed_final)+sb_min_interval;
   if (nextTX < sb_min_interval) {nextTX=sb_min_interval;}
   if (nextTX > sb_max_interval) {nextTX=sb_max_interval;}

Solution:
either work with signed long variable, do the checks, and afterwards assign the result to nextTX.
Or test it inline.

-> My suggestion:

nextTX = ((sb_max_speed > average_speed_final) ? ((sb_max_interval-sb_min_interval)/(sb_max_speed-sb_min_speed)*(sb_max_speed-average_speed_final)+sb_min_interval) : sb_min_interval);
//if (nextTX < sb_min_interval) {nextTX=sb_min_interval;}   // already assured (  (sb_max_speed <= average_speed_final) -> sb_min_interval)
if (nextTX > sb_max_interval) {nextTX=sb_max_interval;}

Also to consider:
If user configures sb_max_speed equal to sb_min_speed, the division
(sb_max_interval-sb_min_interval)/(sb_max_speed-sb_min_speed)
may lead to division by zero.
boot code and / webinterface should check that sb_max_speed-sb_min_speed is >= 0, and sb_max_interval-sb_max_interval is > sb_max_speed-sb_min_speed.

@dl9sau dl9sau changed the title smrt beaconing: fix smart beaconing: fix Oct 17, 2021
mi-gri added a commit to mi-gri/TTGO-T-Beam-LoRa-APRS that referenced this issue Oct 21, 2021
@dl9sau
Copy link
Author

dl9sau commented Dec 18, 2021

Feature is stable in my development version

@dl9sau dl9sau closed this as completed Dec 18, 2021
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

No branches or pull requests

1 participant