Skip to content

Commit

Permalink
#90: Support sharing same PDA ID between control panel and physical PDA
Browse files Browse the repository at this point in the history
  • Loading branch information
ballle98 committed May 2, 2024
1 parent 2880006 commit 42e1af5
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions pda.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,57 @@ bool pda_shouldSleep() {
//LOG(PDA_LOG,LOG_DEBUG, "PDA loop count %d, will sleep at %d\n",_pda_loop_cnt,PDA_LOOP_COUNT);
struct timespec now;
struct timespec elapsed;
static bool probeRecvdAfterActive = false;
static bool activate = false;

// If aqualinkd was restarted and a probe has not been received force a sleep
if (! _pda_first_probe_recvd) {
return true;
} else if (! _config_parameters->pda_sleep_mode) {
return false;
}

if (activate) {
LOG(PDA_LOG,LOG_DEBUG, "PDA received probe after activate\n");
probeRecvdAfterActive = true;
}

// NSF NEED TO CHECK ACTIVE THREADS.
if (_aqualink_data->active_thread.thread_id != 0) {
LOG(PDA_LOG,LOG_DEBUG, "PDA can't sleep as thread %s(%d),%p is active\n",
ptypeName(_aqualink_data->active_thread.ptype),
_aqualink_data->active_thread.ptype,
_aqualink_data->active_thread.thread_id);
return false;
}
activate = true;

// Last see if there are any open websockets. (don't sleep if the web UI is open)
if ((! _config_parameters->pda_sleep_with_websock) &&
} else if ((! _config_parameters->pda_sleep_with_websock) &&
( _aqualink_data->open_websockets > 0 )) {
LOG(PDA_LOG,LOG_DEBUG, "PDA can't sleep as websocket is active\n");
return false;
activate = true;
} else {
clock_gettime(CLOCK_REALTIME, &now);
timespec_subtract(&elapsed, &now, &(_aqualink_data->last_active_time));
if (elapsed.tv_sec >= PDA_SLEEP_FOR) {
if (!activate) {
LOG(PDA_LOG,LOG_DEBUG, "PDA Slept for %ld sec\n", elapsed.tv_sec);
}
activate = true;
} else {
activate = false;
probeRecvdAfterActive = false;
}
}

clock_gettime(CLOCK_REALTIME, &now);
timespec_subtract(&elapsed, &now, &(_aqualink_data->last_active_time));
if (elapsed.tv_sec > PDA_SLEEP_FOR) {
return false;
if (activate) {
if (probeRecvdAfterActive) {
return false;
} else {
LOG(PDA_LOG,LOG_DEBUG, "Wait for probe to activate\n");
probeRecvdAfterActive = false;
_pda_first_probe_recvd = false;
return true;
}
}

return true;
Expand Down

0 comments on commit 42e1af5

Please sign in to comment.