Skip to content

Commit

Permalink
Add acknowledge switch for location publish acknowledgements
Browse files Browse the repository at this point in the history
  • Loading branch information
eberseth committed Nov 17, 2020
1 parent 2f48bc3 commit 3ea8292
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/tracker_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TrackerLocation *TrackerLocation::_instance = nullptr;
static constexpr system_tick_t LoopSampleRate = 1000; // milliseconds
static constexpr uint32_t EarlySleepSec = 2; // seconds
static constexpr uint32_t MiscSleepWakeSec = 3; // seconds - miscellaneous time spent by system entering and exiting sleep
static constexpr int32_t LockTimeoutSec = 10; // seconds - time to wait for GNSS lock (sleep disabled)
static constexpr uint32_t LockTimeoutSec = 10; // seconds - time to wait for GNSS lock (sleep disabled)

static int set_radius_cb(double value, const void *context)
{
Expand Down Expand Up @@ -100,7 +100,10 @@ void TrackerLocation::init()
&config_state.min_publish, &config_state_shadow.min_publish),
ConfigBool("lock_trigger",
config_get_bool_cb, config_set_bool_cb,
&config_state.lock_trigger, &config_state_shadow.lock_trigger)
&config_state.lock_trigger, &config_state_shadow.lock_trigger),
ConfigBool("loc_ack",
config_get_bool_cb, config_set_bool_cb,
&config_state.process_ack, &config_state_shadow.process_ack)
},
std::bind(&TrackerLocation::enter_location_config_cb, this, _1, _2),
std::bind(&TrackerLocation::exit_location_config_cb, this, _1, _2, _3)
Expand Down Expand Up @@ -230,20 +233,23 @@ void TrackerLocation::location_publish()
// the finalized loc publish to retry on failure
cloud_service.lock();

CloudServicePublishFlags cloud_flags =
(config_state.process_ack) ? CloudServicePublishFlags::FULL_ACK : CloudServicePublishFlags::NONE;

if(location_publish_retry_str)
{
// publish a retry loc
rval = cloud_service.send(location_publish_retry_str,
WITH_ACK,
CloudServicePublishFlags::FULL_ACK,
cloud_flags,
&TrackerLocation::location_publish_cb, this,
CLOUD_DEFAULT_TIMEOUT_MS, &_last_location_publish_sec);
}
else
{
// publish a new loc (contained in cloud_service buffer)
rval = cloud_service.send(WITH_ACK,
CloudServicePublishFlags::FULL_ACK,
cloud_flags,
&TrackerLocation::location_publish_cb, this,
CLOUD_DEFAULT_TIMEOUT_MS, &_last_location_publish_sec);
}
Expand Down Expand Up @@ -314,7 +320,7 @@ EvaluationResults TrackerLocation::evaluatePublish() {
if (_pending_immediate) {
// request for immediate publish overrides the default min/max interval checking
Log.trace("%s pending_immediate", __FUNCTION__);
return EvaluationResults {PublishReason::IMMEDIATE, true, 0};
return EvaluationResults {PublishReason::IMMEDIATE, true, false};
}

uint32_t interval = now - _last_location_publish_sec;
Expand Down Expand Up @@ -365,7 +371,7 @@ EvaluationResults TrackerLocation::evaluatePublish() {
}
}

return EvaluationResults {PublishReason::NONE, networkNeeded, 0};
return EvaluationResults {PublishReason::NONE, networkNeeded, false};
}

// The purpose of thhe sleep prepare callback is to allow each task to calculate
Expand Down
5 changes: 4 additions & 1 deletion src/tracker_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define TRACKER_LOCATION_INTERVAL_MAX_DEFAULT_SEC (3600)
#define TRACKER_LOCATION_MIN_PUBLISH_DEFAULT (false)
#define TRACKER_LOCATION_LOCK_TRIGGER (true)
#define TRACKER_LOCATION_PROCESS_ACK (true)

// wait at most this many seconds for a locked GPS location to become stable
// before publishing regardless
Expand All @@ -40,6 +41,7 @@ struct tracker_location_config_t {
int32_t interval_max_seconds; // 0 = no max
bool min_publish;
bool lock_trigger;
bool process_ack;
};

enum class Trigger {
Expand Down Expand Up @@ -138,7 +140,8 @@ class TrackerLocation
.interval_min_seconds = TRACKER_LOCATION_INTERVAL_MIN_DEFAULT_SEC,
.interval_max_seconds = TRACKER_LOCATION_INTERVAL_MAX_DEFAULT_SEC,
.min_publish = TRACKER_LOCATION_MIN_PUBLISH_DEFAULT,
.lock_trigger = TRACKER_LOCATION_LOCK_TRIGGER
.lock_trigger = TRACKER_LOCATION_LOCK_TRIGGER,
.process_ack = TRACKER_LOCATION_PROCESS_ACK
};
}
static TrackerLocation *_instance;
Expand Down

0 comments on commit 3ea8292

Please sign in to comment.