From 12beae5c622c81847cbdc26a9c464ed65a5251fa Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Jul 2024 10:45:28 +0200 Subject: [PATCH 1/2] CloudDevice: unify update and handleMessage --- src/ArduinoIoTCloudDevice.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ArduinoIoTCloudDevice.cpp b/src/ArduinoIoTCloudDevice.cpp index 53fcb74d..43d3a361 100644 --- a/src/ArduinoIoTCloudDevice.cpp +++ b/src/ArduinoIoTCloudDevice.cpp @@ -38,6 +38,19 @@ void ArduinoCloudDevice::begin() { } void ArduinoCloudDevice::update() { + handleMessage(nullptr); +} + +int ArduinoCloudDevice::connected() { + return _state != State::Disconnected ? 1 : 0; +} + +void ArduinoCloudDevice::handleMessage(Message *m) { + _command = UnknownCmdId; + if (m != nullptr) { + _command = m->id; + } + /* Run through the state machine. */ State nextState = _state; switch (_state) { @@ -80,17 +93,6 @@ void ArduinoCloudDevice::update() { _state = nextState; } -int ArduinoCloudDevice::connected() { - return _state != State::Disconnected ? 1 : 0; -} - -void ArduinoCloudDevice::handleMessage(Message *m) { - _command = UnknownCmdId; - if (m != nullptr) { - _command = m->id; - } -} - ArduinoCloudDevice::State ArduinoCloudDevice::handleInit() { /* Reset attempt struct for the nex retry after disconnection */ _attachAttempt.begin(AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms, From 8196fbc634f4fd2bca0c0c92d312be3c010639fa Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Jul 2024 10:45:55 +0200 Subject: [PATCH 2/2] CloudThing: unify update and handleMessage --- src/ArduinoIoTCloudThing.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ArduinoIoTCloudThing.cpp b/src/ArduinoIoTCloudThing.cpp index 9b3656b0..98ebb0fb 100644 --- a/src/ArduinoIoTCloudThing.cpp +++ b/src/ArduinoIoTCloudThing.cpp @@ -59,6 +59,23 @@ void ArduinoCloudThing::begin() { } void ArduinoCloudThing::update() { + handleMessage(nullptr); +} + +int ArduinoCloudThing::connected() { + return _state > State::Disconnect ? 1 : 0; +} + +void ArduinoCloudThing::handleMessage(Message* m) { + _command = UnknownCmdId; + if (m != nullptr) { + _command = m->id; + if (_command == TimezoneCommandDownId) { + _utcOffset = reinterpret_cast(m)->params.offset; + _utcOffsetExpireTime = reinterpret_cast(m)->params.until; + } + } + /* Run through the state machine. */ State nextState = _state; switch (_state) { @@ -95,21 +112,6 @@ void ArduinoCloudThing::update() { _state = nextState; } -int ArduinoCloudThing::connected() { - return _state > State::Disconnect ? 1 : 0; -} - -void ArduinoCloudThing::handleMessage(Message* m) { - _command = UnknownCmdId; - if (m != nullptr) { - _command = m->id; - if (_command == TimezoneCommandDownId) { - _utcOffset = reinterpret_cast(m)->params.offset; - _utcOffsetExpireTime = reinterpret_cast(m)->params.until; - } - } -} - ArduinoCloudThing::State ArduinoCloudThing::handleInit() { _syncAttempt.begin(AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms); return State::RequestLastValues;