Skip to content

Commit

Permalink
Merge pull request #1801 from particle-iot/feature/ch33758
Browse files Browse the repository at this point in the history
System.disableUpdates() operates asynchronously
  • Loading branch information
technobly committed Jun 14, 2019
2 parents 48d7443 + ee50810 commit 5165c25
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ci/enumerate_build_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ for db in "${DEBUG_BUILD[@]}"
do
for p in "${MODULAR_PLATFORM[@]}"
do
# Gen 3 overflow with modular DEBUG_BUILD=y, so skip those
# Gen 3 and Photon overflow with modular DEBUG_BUILD=y, so skip those
if [[ "$db" = "y" ]]; then
if [[ "$p" = "xenon" ]] || [[ "$p" = "argon" ]] || [[ "$p" = "boron" ]] || [[ "$p" = "xsom" ]] || [[ "$p" = "asom" ]] || [[ "$p" = "bsom" ]]; then
if [[ "$p" = "photon" ]] || [[ "$p" = "p1" ]] || [[ "$p" = "xenon" ]] || [[ "$p" = "argon" ]] || [[ "$p" = "boron" ]] || [[ "$p" = "xsom" ]] || [[ "$p" = "asom" ]] || [[ "$p" = "bsom" ]]; then
continue
fi
fi
Expand Down
10 changes: 6 additions & 4 deletions communication/src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ namespace EventType {
};

/**
* These flags are encoded into the same 32-bit integer that alredy holds EventType::Enum
* These flags are encoded into the same 32-bit integer that already holds EventType::Enum
*/
enum Flags {
EMPTY_FLAGS = 0,
NO_ACK = 0x2,
WITH_ACK = 0x8,

ALL_FLAGS = NO_ACK | WITH_ACK
ASYNC = 0x10, // not used here, but reserved since it's used in the system layer. Makes conversion simpler.
ALL_FLAGS = NO_ACK | WITH_ACK | ASYNC
};

static_assert((PUBLIC & NO_ACK)==0 &&
(PRIVATE & NO_ACK)==0 &&
(PUBLIC & WITH_ACK)==0 &&
(PRIVATE & WITH_ACK)==0, "flags should be distinct from event type");
(PRIVATE & WITH_ACK)==0 &&
(PRIVATE & ASYNC)==0 &&
(PUBLIC & ASYNC)==0, "flags should be distinct from event type");

/**
* The flags are encoded in with the event type.
Expand Down
5 changes: 5 additions & 0 deletions system/inc/system_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ const uint32_t PUBLISH_EVENT_FLAG_PUBLIC = 0x0;
const uint32_t PUBLISH_EVENT_FLAG_PRIVATE = 0x1;
const uint32_t PUBLISH_EVENT_FLAG_NO_ACK = 0x2;
const uint32_t PUBLISH_EVENT_FLAG_WITH_ACK = 0x8;
/**
* This is a stop-gap solution until all synchronous APIs return futures, allowing asynchronous operation.
*/
const uint32_t PUBLISH_EVENT_FLAG_ASYNC = EventType::ASYNC;


PARTICLE_STATIC_ASSERT(publish_no_ack_flag_matches, PUBLISH_EVENT_FLAG_NO_ACK==EventType::NO_ACK);

Expand Down
5 changes: 5 additions & 0 deletions system/src/system_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ inline uint32_t convert(uint32_t flags) {

bool spark_send_event(const char* name, const char* data, int ttl, uint32_t flags, void* reserved)
{
if (flags & PUBLISH_EVENT_FLAG_ASYNC) {
SYSTEM_THREAD_CONTEXT_ASYNC_RESULT(spark_send_event(name, data, ttl, flags, reserved), true);
}
else {
SYSTEM_THREAD_CONTEXT_SYNC(spark_send_event(name, data, ttl, flags, reserved));
}

spark_protocol_send_event_data d = { sizeof(spark_protocol_send_event_data) };
if (reserved) {
Expand Down
4 changes: 2 additions & 2 deletions system/src/system_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ void system_flag_changed(system_flag_t flag, uint8_t oldValue, uint8_t newValue)
else if (flag == SYSTEM_FLAG_OTA_UPDATE_ENABLED)
{
// publish the firmware enabled event
spark_send_event(UPDATES_ENABLED_EVENT, flag_to_string(newValue), 60, PUBLISH_EVENT_FLAG_PRIVATE, nullptr);
spark_send_event(UPDATES_ENABLED_EVENT, flag_to_string(newValue), 60, PUBLISH_EVENT_FLAG_ASYNC|PUBLISH_EVENT_FLAG_PRIVATE, nullptr);
}
else if (flag == SYSTEM_FLAG_OTA_UPDATE_FORCED)
{
// acknowledge to the cloud that system updates are forced. It helps avoid a race condition where we might try sending firmware before the event has been received.
spark_send_event(UPDATES_FORCED_EVENT, flag_to_string(newValue), 60, PUBLISH_EVENT_FLAG_PRIVATE, nullptr);
spark_send_event(UPDATES_FORCED_EVENT, flag_to_string(newValue), 60, PUBLISH_EVENT_FLAG_ASYNC|PUBLISH_EVENT_FLAG_PRIVATE, nullptr);
}
else if (flag == SYSTEM_FLAG_OTA_UPDATE_PENDING)
{
Expand Down

0 comments on commit 5165c25

Please sign in to comment.