supla-device
Loading...
Searching...
No Matches
element_with_channel_actions.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
20#define SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
21
22#include <stdint.h>
23#include <supla-common/proto.h>
24#include <supla/element.h>
25#include <supla/local_action.h>
26
27namespace Supla {
28
29enum class ChannelConfigState : uint8_t {
30 None = 0,
31 LocalChangePending = 1,
32 SetChannelConfigSend = 2,
33 SetChannelConfigFailed = 3,
34 WaitForConfigFinished = 4,
35 ResendConfig = 5,
36 LocalChangeSent = 6
37};
38
39enum class ApplyConfigResult : uint8_t {
40 NotSupported,
41 Success,
42 DataError,
43 SetChannelConfigNeeded,
44};
45
46#pragma pack(push, 1)
48 private:
49 union {
50 struct {
51 uint8_t configFinishedReceived: 1;
52 uint8_t defaultConfig: 1;
53 uint8_t weeklySchedule: 1;
54 uint8_t altWeeklySchedule: 1;
55 uint8_t ocrConfig: 1;
56 uint8_t extendedDefaultConfig: 1;
57 };
58 uint8_t all = 0;
59 };
60
61 public:
62 bool isSet(int configType) const;
63 void clear(int configType);
64 void clearAll();
65 void setAll(uint8_t values);
66 uint8_t getAll() const;
67 void setConfigFinishedReceived();
68 void clearConfigFinishedReceived();
69 bool isConfigFinishedReceived() const;
70 void set(int configType, bool value = true);
71 bool operator!=(const ConfigTypesBitmap &other) const;
72};
73#pragma pack(pop)
74
75class Condition;
76class ActionHandler;
77namespace Protocol {
78class SuplaSrpc;
79} // namespace Protocol
80
81class ElementWithChannelActions : public Element, public LocalAction {
82 public:
83 explicit ElementWithChannelActions(
84 ElementMode mode = ElementMode::Registered);
85
86 // Override local action methods in order to delegate execution to Channel
87 void addAction(uint16_t action,
88 ActionHandler &client, // NOLINT(runtime/references)
89 uint16_t event,
90 bool alwaysEnabled = false) override;
91 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
92 bool alwaysEnabled = false) override;
100 virtual void addAction(uint16_t action,
101 ActionHandler &client, // NOLINT(runtime/references)
102 uint16_t event,
103 Supla::Condition *condition,
104 bool alwaysEnabled = false);
108 virtual void addAction(uint16_t action, ActionHandler *client,
109 uint16_t event,
110 Supla::Condition *condition,
111 bool alwaysEnabled = false);
112 virtual void addAction(uint16_t action,
113 ActionHandler &client, // NOLINT(runtime/references)
114 Supla::Condition *condition,
115 bool alwaysEnabled = false);
116 virtual void addAction(uint16_t action, ActionHandler *client,
117 Supla::Condition *condition,
118 bool alwaysEnabled = false);
119
120 bool isEventAlreadyUsed(uint16_t event, bool ignoreAlwaysEnabled) override;
121 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
122 bool iterateConnected() override;
123 void handleChannelConfigFinished() override;
124 uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override;
126 TSDS_SetChannelConfigResult *result) override;
127 void purgeConfig() override;
128
129
130 void runAction(uint16_t event) const override;
131
132 bool isAnyUpdatePending() const override;
133
134 // methods to override for channels with runtime config support
135 virtual ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
136 bool local);
137 virtual void fillChannelConfig(void *channelConfig, int *size, uint8_t index);
138
139 void triggerSetChannelConfig(int configType = SUPLA_CONFIG_TYPE_DEFAULT);
140
141 protected:
142 // returns true if function was changed (previous one was different)
143 virtual bool setAndSaveFunction(uint32_t channelFunction);
144 virtual bool loadFunctionFromConfig();
145 virtual bool saveConfigChangeFlag() const;
146 virtual bool loadConfigChangeFlag();
147 void clearChannelConfigChangedFlag();
148 bool iterateConfigExchange();
154 int getNextConfigType() const;
155 Supla::ChannelConfigState channelConfigState =
156 Supla::ChannelConfigState::None;
157
158 uint8_t setChannelConfigAttempts = 0;
159 ConfigTypesBitmap usedConfigTypes;
160 ConfigTypesBitmap receivedConfigTypes;
161};
162
163}; // namespace Supla
164
165#endif // SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
Definition action_handler.h:21
Definition condition.h:27
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition element_with_channel_actions.cpp:502
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition element_with_channel_actions.cpp:317
bool isAnyUpdatePending() const override
Returns true if any update is pending.
Definition element_with_channel_actions.cpp:288
void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result) override
Handles "set channel config" reply from server.
Definition element_with_channel_actions.cpp:465
int getNextConfigType() const
Returns the next config type to be sent.
Definition element_with_channel_actions.cpp:605
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override
Handles "set channel config" request from server.
Definition element_with_channel_actions.cpp:367
void handleChannelConfigFinished() override
Handles "channel config finished" message from server.
Definition element_with_channel_actions.cpp:338
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:355
Definition local_action.h:52
Definition supla_srpc.h:61
Definition element_with_channel_actions.h:47
Definition proto.h:3427
Definition proto.h:3411