From 864d50f2da13205f27b710f4fa6b29dd45390d14 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 5 Feb 2024 09:12:28 +0100 Subject: [PATCH 1/3] Add commands definitions --- src/message/Commands.h | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/message/Commands.h diff --git a/src/message/Commands.h b/src/message/Commands.h new file mode 100644 index 000000000..0f9cdac20 --- /dev/null +++ b/src/message/Commands.h @@ -0,0 +1,50 @@ +/* + This file is part of the ArduinoIoTCloud library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#include + +/****************************************************************************** + * TYPEDEF + ******************************************************************************/ + +enum CommandId : uint16_t { + + /* Device commands */ + DeviceBeginCmdId, + ThingBeginCmdId, + ThingUpdateCmdId, + DeviceRegisteredCmdId, + DeviceAttachedCmdId, + DeviceDetachedCmdId, + + /* Thing commands */ + LastValuesBeginCmdId, + LastValuesUpdateCmdId, + PropertiesUpdateCmdId, + + /* Generic commands */ + ResetCmdId, + + /* Unknown command id */ + UnknownCmdId +}; + +struct Command { + CommandId id; +}; + +typedef Command Message; From 4a9f01cf2e7bc1dbe5695569d1929006bb7460bb Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 7 Mar 2024 12:29:11 +0100 Subject: [PATCH 2/3] Add MessageStream interface --- src/interfaces/MessageStream.h | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/interfaces/MessageStream.h diff --git a/src/interfaces/MessageStream.h b/src/interfaces/MessageStream.h new file mode 100644 index 000000000..ac2b18ac9 --- /dev/null +++ b/src/interfaces/MessageStream.h @@ -0,0 +1,40 @@ +/* + This file is part of the ArduinoIoTCloud library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#include + +using upstreamFunction = std::function; + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class MessageStream { +public: + MessageStream(upstreamFunction upstream): upstream(upstream) {} + + /** + * Send message upstream + * @param m: message to send + */ + virtual inline void sendUpstream(Message* m) { + upstream(m); + } + +private: + upstreamFunction upstream; +}; From ad40ac8dad78641846e12778b8814e8c5704dc92 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 7 Mar 2024 12:27:26 +0100 Subject: [PATCH 3/3] Add CloudProcess interface --- src/interfaces/CloudProcess.h | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/interfaces/CloudProcess.h diff --git a/src/interfaces/CloudProcess.h b/src/interfaces/CloudProcess.h new file mode 100644 index 000000000..7462e867f --- /dev/null +++ b/src/interfaces/CloudProcess.h @@ -0,0 +1,56 @@ +/* + This file is part of the ArduinoIoTCloud library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef ARDUINO_IOT_CLOUD_PROCESS +#define ARDUINO_IOT_CLOUD_PROCESS + +/****************************************************************************** + * INCLUDES + ******************************************************************************/ + +#include +#include +#include +#include + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class CloudProcess { +public: + CloudProcess(MessageStream* stream): stream(stream) {} + + /** + * Abstract method that is called whenever a message comes from Message stream + * @param m: the incoming message + */ + virtual void handleMessage(Message* m) = 0; + + /** + * Abstract method that is called to update the FSM of the CloudProcess + */ + virtual void update() = 0; + +protected: + /** + * Used by a derived class to send a message to the underlying messageStream + * @param msg: the message to send + */ + void deliver(Message* msg) { + assert(stream != nullptr); + stream->sendUpstream(msg); + } + +private: + MessageStream* stream; +}; + +#endif /* ARDUINO_IOT_CLOUD_PROCESS */