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

Process system tasks while cloud handshake is in progress #2745

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions system/inc/system_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern volatile uint8_t SPARK_WLAN_CONNECT_RESTORE;
extern volatile uint8_t SPARK_WLAN_STARTED;
extern volatile uint8_t SPARK_CLOUD_SOCKETED;
extern volatile uint8_t SPARK_CLOUD_CONNECTED;
extern volatile uint8_t SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS;
extern volatile uint8_t SPARK_CLOUD_HANDSHAKE_PENDING;
extern volatile uint8_t SPARK_CLOUD_HANDSHAKE_NOTIFY_DONE;
extern volatile uint8_t SPARK_FLASH_UPDATE;
Expand Down
8 changes: 7 additions & 1 deletion system/src/system_cloud_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "system_cloud_connection.h"
#include "system_cloud_internal.h"
#include "system_cloud.h"
#include "system_threading.h"
#include "core_hal.h"
#include "service_debug.h"
#include "system_task.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ static volatile int s_ipv4_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIV
static volatile int s_ipv6_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL;
#endif

using namespace particle;
using namespace particle::system::cloud;

#if HAL_PLATFORM_CLOUD_UDP
Expand Down Expand Up @@ -250,7 +252,11 @@ int Spark_Receive_UDP(unsigned char *buf, uint32_t buflen, void* reserved)
return -1;
}

return system_cloud_recv(buf, buflen, 0);
int r = system_cloud_recv(buf, buflen, 0);
if (r == 0 && SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS) {
SystemISRTaskQueue.process();
}
return r;
}

#endif /* HAL_PLATFORM_CLOUD_UDP */
Expand Down
3 changes: 3 additions & 0 deletions system/src/system_cloud_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,10 @@ int Spark_Handshake(bool presence_announce)
cloud_socket_aborted = false; // Clear cancellation flag for socket operations
LOG(INFO,"Starting handshake: presense_announce=%d", presence_announce);
bool session_resumed = false;
// TODO: Perform the DTLS handshake and receive a response for the Hello message asynchronously
SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 1;
int err = spark_protocol_handshake(sp);
SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 0;

#if HAL_PLATFORM_MUXER_MAY_NEED_DELAY_IN_TX
// XXX: Adding a delay only for platforms Boron and BSoM, because older cell versions of
Expand Down
1 change: 1 addition & 0 deletions system/src/system_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ymodem_serial_flash_update_handler Ymodem_Serial_Flash_Update_Handler = NULL;
// TODO: Use a single state variable instead of SPARK_CLOUD_XXX flags
volatile uint8_t SPARK_CLOUD_SOCKETED;
volatile uint8_t SPARK_CLOUD_CONNECTED;
volatile uint8_t SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 0;
volatile uint8_t SPARK_CLOUD_HANDSHAKE_PENDING = 0;
volatile uint8_t SPARK_CLOUD_HANDSHAKE_NOTIFY_DONE = 0;
volatile uint8_t SPARK_FLASH_UPDATE;
Expand Down