Skip to content

Commit

Permalink
CloudThing: unify update and handleMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Jul 18, 2024
1 parent 12beae5 commit 8196fbc
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/ArduinoIoTCloudThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimezoneCommandDown*>(m)->params.offset;
_utcOffsetExpireTime = reinterpret_cast<TimezoneCommandDown*>(m)->params.until;
}
}

/* Run through the state machine. */
State nextState = _state;
switch (_state) {
Expand Down Expand Up @@ -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<TimezoneCommandDown*>(m)->params.offset;
_utcOffsetExpireTime = reinterpret_cast<TimezoneCommandDown*>(m)->params.until;
}
}
}

ArduinoCloudThing::State ArduinoCloudThing::handleInit() {
_syncAttempt.begin(AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms);
return State::RequestLastValues;
Expand Down

0 comments on commit 8196fbc

Please # to comment.