Leaf only starts hunting for a new slot after 3 timeouts. Makes the system more stable.
This commit is contained in:
parent
33edb1f18a
commit
e86c6b0f15
|
@ -165,9 +165,11 @@ void payload_printf(const char* name, const payload_t& pl)
|
||||||
|
|
||||||
static unsigned long last_ping_sent_at;
|
static unsigned long last_ping_sent_at;
|
||||||
static bool waiting_for_pong = false;
|
static bool waiting_for_pong = false;
|
||||||
|
static short consecutive_timeouts;
|
||||||
const unsigned long ping_delay = 2000; // ms
|
const unsigned long ping_delay = 2000; // ms
|
||||||
const unsigned long pong_timeout = 250; // ms
|
const unsigned long pong_timeout = 250; // ms
|
||||||
const unsigned long ping_phase_shift = 100; // ms
|
const unsigned long ping_phase_shift = 100; // ms
|
||||||
|
const short timeout_shift_threshold = 3;
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
|
@ -337,6 +339,7 @@ void loop(void)
|
||||||
{
|
{
|
||||||
// Not waiting anymore, got one.
|
// Not waiting anymore, got one.
|
||||||
waiting_for_pong = false;
|
waiting_for_pong = false;
|
||||||
|
consecutive_timeouts = 0;
|
||||||
|
|
||||||
// Dump the payloads until we've gotten everything
|
// Dump the payloads until we've gotten everything
|
||||||
payload_t payload;
|
payload_t payload;
|
||||||
|
@ -363,6 +366,10 @@ void loop(void)
|
||||||
// getting a pong just as we are trying to get a ping. The best thing
|
// getting a pong just as we are trying to get a ping. The best thing
|
||||||
// to do right now is offset our ping timing to search for a slot
|
// to do right now is offset our ping timing to search for a slot
|
||||||
// that's not occupied.
|
// that's not occupied.
|
||||||
|
//
|
||||||
|
// Only do this after getting a few timeouts, so we aren't always skittishly
|
||||||
|
// moving around the cycle.
|
||||||
|
if ( ++consecutive_timeouts > timeout_shift_threshold )
|
||||||
last_ping_sent_at += ping_phase_shift;
|
last_ping_sent_at += ping_phase_shift;
|
||||||
|
|
||||||
// Print details
|
// Print details
|
||||||
|
|
Loading…
Reference in New Issue