Skip to content

Commit

Permalink
Merge pull request #467 from pennam/message-fix
Browse files Browse the repository at this point in the history
Avoid using memcpy to store timezone data
  • Loading branch information
pennam authored May 27, 2024
2 parents 335daf8 + 3069915 commit 06613dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/ArduinoIoTCloudThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ArduinoCloudThing::update() {
}

/* Handle external events */
switch (_command.c.id) {
switch (_command) {
case LastValuesUpdateCmdId:
if (_state == State::RequestLastValues) {
DEBUG_VERBOSE("CloudThing::%s Thing is synced", __FUNCTION__);
Expand All @@ -79,8 +79,7 @@ void ArduinoCloudThing::update() {

/* We have received a timezone update */
case TimezoneCommandDownId:
TimeService.setTimeZoneData(_command.timezoneCommandDown.params.offset,
_command.timezoneCommandDown.params.until);
TimeService.setTimeZoneData(_utcOffset, _utcOffsetExpireTime);
break;

/* We have received a reset command */
Expand All @@ -92,7 +91,7 @@ void ArduinoCloudThing::update() {
break;
}

_command.c.id = UnknownCmdId;
_command = UnknownCmdId;
_state = nextState;
}

Expand All @@ -101,9 +100,13 @@ int ArduinoCloudThing::connected() {
}

void ArduinoCloudThing::handleMessage(Message* m) {
_command.c.id = UnknownCmdId;
_command = UnknownCmdId;
if (m != nullptr) {
memcpy(&_command, m, sizeof(CommandDown));
_command = m->id;
if (_command == TimezoneCommandDownId) {
_utcOffset = reinterpret_cast<TimezoneCommandDown*>(m)->params.offset;
_utcOffsetExpireTime = reinterpret_cast<TimezoneCommandDown*>(m)->params.until;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudThing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ArduinoCloudThing : public CloudProcess {
};

State _state;
CommandDown _command;
CommandId _command;
TimedAttempt _syncAttempt;
PropertyContainer _propertyContainer;
unsigned int _propertyContainerIndex;
Expand Down

0 comments on commit 06613dd

Please sign in to comment.