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 // Override local action methods in order to delegate execution to Channel
84 void addAction(uint16_t action,
85 ActionHandler &client, // NOLINT(runtime/references)
86 uint16_t event,
87 bool alwaysEnabled = false) override;
88 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
89 bool alwaysEnabled = false) override;
90 virtual void addAction(uint16_t action,
91 ActionHandler &client, // NOLINT(runtime/references)
92 Supla::Condition *condition,
93 bool alwaysEnabled = false);
94 virtual void addAction(uint16_t action, ActionHandler *client,
95 Supla::Condition *condition,
96 bool alwaysEnabled = false);
97
98 bool isEventAlreadyUsed(uint16_t event, bool ignoreAlwaysEnabled) override;
99 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
100 bool iterateConnected() override;
101 void handleChannelConfigFinished() override;
102 uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override;
104 TSDS_SetChannelConfigResult *result) override;
105 void purgeConfig() override;
106
107 void clearChannelConfigChangedFlag();
108
109 void runAction(uint16_t event) const override;
110
111 // returns true if function was changed (previous one was different)
112 virtual bool setAndSaveFunction(_supla_int_t channelFunction);
113 virtual bool loadFunctionFromConfig();
114 virtual bool saveConfigChangeFlag() const;
115 virtual bool loadConfigChangeFlag();
116 bool isAnyUpdatePending() override;
117
118 // methods to override for channels with runtime config support
119 virtual ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
120 bool local);
121 virtual void fillChannelConfig(void *channelConfig, int *size, uint8_t index);
122
123 void triggerSetChannelConfig(int configType = SUPLA_CONFIG_TYPE_DEFAULT);
124
125 protected:
126 bool iterateConfigExchange();
132 int getNextConfigType() const;
133 Supla::ChannelConfigState channelConfigState =
134 Supla::ChannelConfigState::None;
135
136 uint8_t setChannelConfigAttempts = 0;
137 ConfigTypesBitmap usedConfigTypes;
138 ConfigTypesBitmap receivedConfigTypes;
139};
140
141}; // namespace Supla
142
143#endif // SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
Definition action_handler.h:21
Definition condition.h:27
Definition element_with_channel_actions.h:81
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition element_with_channel_actions.cpp:485
bool isAnyUpdatePending() override
Returns true if any update is pending.
Definition element_with_channel_actions.cpp:271
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition element_with_channel_actions.cpp:300
void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result) override
Handles "set channel config" reply from server.
Definition element_with_channel_actions.cpp:448
int getNextConfigType() const
Returns the next config type to be sent.
Definition element_with_channel_actions.cpp:588
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override
Handles "set channel config" request from server.
Definition element_with_channel_actions.cpp:350
void handleChannelConfigFinished() override
Handles "channel config finished" message from server.
Definition element_with_channel_actions.cpp:321
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:338
Definition local_action.h:52
Definition supla_srpc.h:55
Definition element_with_channel_actions.h:47
Definition proto.h:3003
Definition proto.h:2987