supla-device
Loading...
Searching...
No Matches
element_with_channel_actions.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
5#define SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
6
7#include <stdint.h>
8#include <supla-common/proto.h>
9#include <supla/apply_config_result.h>
10#include <supla/element.h>
11#include <supla/local_action.h>
12
13namespace Supla {
14
15enum class ChannelConfigState : uint8_t {
16 None = 0,
17 LocalChangePending = 1,
18 SetChannelConfigSend = 2,
19 SetChannelConfigFailed = 3,
20 WaitForConfigFinished = 4,
21 ResendConfig = 5,
22 LocalChangeSent = 6,
23 LAST_STATE_MAX // Sentinel: one past the last valid state.
24};
25
26static_assert(static_cast<uint8_t>(ChannelConfigState::LAST_STATE_MAX) <= 16,
27 "ChannelConfigState does not fit in 4 bits");
28
29#pragma pack(push, 1)
31 private:
32 // This is a runtime-only bitmap. The local-change storage keeps the raw
33 // value as uint32_t, so the bit assignments must remain compatible with
34 // SUPLA_CONFIG_TYPE_* values used by legacy devices.
35 uint8_t all = 0;
36
37 public:
38 bool isSet(int configType) const;
39 void clear(int configType);
40 void clearAll();
41 void setAll(uint8_t values);
42 uint8_t getAll() const;
43 void set(int configType, bool value = true);
44 bool operator!=(const ConfigTypesBitmap &other) const;
45};
46#pragma pack(pop)
47
48static_assert(sizeof(ConfigTypesBitmap) == 1,
49 "ConfigTypesBitmap must remain one byte");
50
51class Condition;
52class ActionHandler;
53namespace Protocol {
54class SuplaSrpc;
55} // namespace Protocol
57 public:
59 ElementMode mode = ElementMode::Registered);
61
62 // Override local action methods in order to delegate execution to Channel
63 void addAction(uint16_t action,
64 ActionHandler &client, // NOLINT(runtime/references)
65 uint16_t event,
66 bool alwaysEnabled = false) override;
67 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
68 bool alwaysEnabled = false) override;
76 virtual void addAction(uint16_t action,
77 ActionHandler &client, // NOLINT(runtime/references)
78 uint16_t event,
79 Supla::Condition *condition,
80 bool alwaysEnabled = false);
84 virtual void addAction(uint16_t action, ActionHandler *client,
85 uint16_t event,
86 Supla::Condition *condition,
87 bool alwaysEnabled = false);
88 virtual void addAction(uint16_t action,
89 ActionHandler &client, // NOLINT(runtime/references)
90 Supla::Condition *condition,
91 bool alwaysEnabled = false);
92 virtual void addAction(uint16_t action, ActionHandler *client,
93 Supla::Condition *condition,
94 bool alwaysEnabled = false);
95
96 bool isEventAlreadyUsed(uint16_t event, bool ignoreAlwaysEnabled) override;
97 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
98 bool iterateConnected() override;
99 // Keep the deprecated Element overload visible for source compatibility.
101 void handleChannelConfigFinished() override;
102 void handleChannelConfigFinished(int channelNumber) override;
104 bool local = false) override;
106 bool altSchedule = false,
107 bool local = false) override;
109 TSDS_SetChannelConfigResult *result) override;
110 void purgeConfig() override;
111
112
113 void runAction(uint16_t event) const override;
114 void runAction(
115 uint16_t event,
116 const ActionAllowList &allowOnlyActions) const override;
117
118 bool isAnyUpdatePending() const override;
119
120 // methods to override for channels with runtime config support
121 virtual ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
122 bool local);
123 virtual void fillChannelConfig(void *channelConfig, int *size, uint8_t index);
124
125 void triggerSetChannelConfig(
126 int configType = SUPLA_CONFIG_TYPE_DEFAULT,
127 bool localChange = false);
128
129 protected:
130 // returns true if function was changed (previous one was different)
131 virtual bool setAndSaveFunction(uint32_t channelFunction);
132 virtual bool loadFunctionFromConfig();
133 virtual bool shouldProcessChannelFunctionFromConfig() const;
134 bool setAndSaveConfigChangeFlag(bool value);
135 virtual bool saveConfigChangeFlag() const;
136 virtual bool loadConfigChangeFlag();
137 void clearChannelConfigChangedFlag();
138 void markChannelConfigReceived(int configType);
139 void markAllChannelConfigsReceived();
140 bool isChannelConfigFinishedReceived() const;
141 bool isLocalChannelConfigChangePending(int configType) const;
142 bool iterateConfigExchange();
148 int getNextConfigType() const;
149 int getNextLocalConfigType() const;
150 bool setLocalConfigChange(int configType, bool value = true);
151 void clearLocalConfigChanges(int configType, int secondConfigType = -1);
152 uint8_t getUsedLocalConfigTypes() const;
153 // Keep exchange state in one byte. The retry counter must stay in 2 bits.
154 ChannelConfigState channelConfigState : 4;
155 uint8_t setChannelConfigAttempts : 2;
156 uint8_t configFinishedReceived : 1;
157 uint8_t reserved : 1;
158 ConfigTypesBitmap locallyChangedConfigTypes;
159 ConfigTypesBitmap usedConfigTypes;
160 ConfigTypesBitmap receivedConfigTypes;
161
162 private:
163 uint8_t finishChannelConfig(
164 TSD_ChannelConfig *result, Supla::ApplyConfigResult applyResult);
165};
166
167}; // namespace Supla
168
169#endif // SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
Definition local_action.h:15
Definition action_handler.h:8
Definition condition.h:14
Definition element_with_channel_actions.h:56
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition element_with_channel_actions.cpp:697
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition element_with_channel_actions.cpp:438
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local=false) override
Handles "set channel config" request from server.
Definition element_with_channel_actions.cpp:514
bool isAnyUpdatePending() const override
Returns true if any update is pending.
Definition element_with_channel_actions.cpp:375
void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result) override
Handles "set channel config" reply from server.
Definition element_with_channel_actions.cpp:643
int getNextConfigType() const
Returns the next config type to be sent.
Definition element_with_channel_actions.cpp:914
void handleChannelConfigFinished() override
Handles "channel config finished" message from server.
Definition element_with_channel_actions.cpp:472
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition element_with_channel_actions.cpp:502
uint8_t handleWeeklySchedule(TSD_ChannelConfig *result, bool altSchedule=false, bool local=false) override
Handles "set channel config" with "weekly schedule" type request from server.
Definition element_with_channel_actions.cpp:568
Base class for all elements of SuplaDevice.
Definition element.h:30
virtual bool iterateConnected()
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition element.cpp:143
Definition local_action.h:87
Definition supla_srpc.h:47
Definition element_with_channel_actions.h:30
Definition proto.h:3192
Definition proto.h:3176