Instrument Neutral Distributed Interface INDI 2.2.5
wanderer_cover_v4_ec.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2024 Frank Wang/Jérémie Klein. All rights reserved.
3
4 WandererCover V4-EC
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24
25#pragma once
26
27#include "defaultdevice.h"
30#include <mutex>
31#include <memory>
32#include <string>
33#include <vector>
34
35namespace Connection
36{
37class Serial;
38}
39
40// Forward declarations
42
43// Protocol handler interface
45{
46public:
47 virtual ~IWandererCoverProtocol() = default;
48
49 // Protocol identification
50 virtual std::string getProtocolName() const = 0;
51 virtual int getProtocolVersion() const = 0;
52 virtual int getMinFirmwareVersion() const = 0;
53 virtual bool supportsFeature(const std::string& feature) const = 0;
54
55 // Data parsing
56 virtual bool parseDeviceData(const char* data, WandererCoverV4EC* device) = 0;
57 virtual bool detectProtocol(const char* data) = 0;
58
59 // Command generation
60 virtual std::string generateOpenCommand() const = 0;
61 virtual std::string generateCloseCommand() const = 0;
62 virtual std::string generateSetBrightnessCommand(uint16_t value) const = 0;
63 virtual std::string generateTurnOffLightCommand() const = 0;
64 virtual std::string generateSetOpenPositionCommand(double value) const = 0;
65 virtual std::string generateSetClosePositionCommand(double value) const = 0;
66 virtual std::string generateAutoDetectOpenPositionCommand() const = 0;
67 virtual std::string generateAutoDetectClosePositionCommand() const = 0;
68 virtual std::string generateDewHeaterCommand(int value) const = 0;
69 virtual std::string generateASIAIRControlCommand(bool enable) const = 0;
70 virtual std::string generateCustomBrightnessCommand(int brightness, int customNumber) const = 0;
71
72 // Status data structure
74 {
75 int firmware = 0;
76 double closePositionSet = 0.0;
77 double openPositionSet = 0.0;
78 double currentPosition = 0.0;
79 double voltage = 0.0;
83 };
84};
85
86// Legacy protocol implementation (pre-20250404)
88{
89public:
90 std::string getProtocolName() const override { return "WandererCover V4-EC (Legacy < 20250404)"; }
91 int getProtocolVersion() const override { return 1; }
92 int getMinFirmwareVersion() const override { return 0; }
93
94 bool supportsFeature(const std::string& feature) const override;
95 bool parseDeviceData(const char* data, WandererCoverV4EC* device) override;
96 bool detectProtocol(const char* data) override;
97
98 std::string generateOpenCommand() const override;
99 std::string generateCloseCommand() const override;
100 std::string generateSetBrightnessCommand(uint16_t value) const override;
101 std::string generateTurnOffLightCommand() const override;
102 std::string generateSetOpenPositionCommand(double value) const override;
103 std::string generateSetClosePositionCommand(double value) const override;
104 std::string generateAutoDetectOpenPositionCommand() const override;
105 std::string generateAutoDetectClosePositionCommand() const override;
106 std::string generateDewHeaterCommand(int value) const override;
107 std::string generateASIAIRControlCommand(bool enable) const override;
108 std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override;
109};
110
111// Modern protocol implementation (20250404+)
113{
114public:
115 std::string getProtocolName() const override { return "WandererCover V4-EC (Modern >= 20250404)"; }
116 int getProtocolVersion() const override { return 2; }
117 int getMinFirmwareVersion() const override { return 20250404; }
118
119 bool supportsFeature(const std::string& feature) const override;
120 bool parseDeviceData(const char* data, WandererCoverV4EC* device) override;
121 bool detectProtocol(const char* data) override;
122
123 std::string generateOpenCommand() const override;
124 std::string generateCloseCommand() const override;
125 std::string generateSetBrightnessCommand(uint16_t value) const override;
126 std::string generateTurnOffLightCommand() const override;
127 std::string generateSetOpenPositionCommand(double value) const override;
128 std::string generateSetClosePositionCommand(double value) const override;
129 std::string generateAutoDetectOpenPositionCommand() const override;
130 std::string generateAutoDetectClosePositionCommand() const override;
131 std::string generateDewHeaterCommand(int value) const override;
132 std::string generateASIAIRControlCommand(bool enable) const override;
133 std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override;
134};
135
137{
138public:
140 virtual ~WandererCoverV4EC() = default;
141
142 virtual bool initProperties() override;
143 virtual void ISGetProperties(const char *dev) override;
144 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
145 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
146 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
147 virtual bool updateProperties() override;
148 virtual bool ISSnoopDevice(XMLEle *root) override;
149
150protected:
151
152 // From Dust Cap
153 virtual IPState ParkCap() override;
154 virtual IPState UnParkCap() override;
155
156 // From Light Box
157 virtual bool SetLightBoxBrightness(uint16_t value) override;
158 virtual bool EnableLightBox(bool enable) override;
159
160 const char *getDefaultName() override;
161 virtual bool saveConfigItems(FILE *fp) override;
162 virtual void TimerHit() override;
163
164 // Protocol handler access
168
169private:
170
171 int firmware=0;
172 bool toggleCover(bool open);
173 bool sendCommand(std::string command);
174 bool getData();
175 bool parseDeviceData(const char *data);
176 double closesetread=0;
177 double opensetread=0;
178 double positionread=0;
179 double voltageread=0;
180 double dewheaterpowerread=0;
181 double asiaircontrolenabledread=0;
182 double flatpanelbrightnessread=0;
183 bool setDewPWM(int id, int value);
184 bool setClose(double value);
185 bool setOpen(double value);
186 void updateData(double closesetread,double opensetread,double positionread,double voltageread,double flatpanelbrightnessread,double dewheaterpowerread,double asiaircontrolenabledread);
187
188 // Protocol detection and management
189 bool detectProtocol();
190 void setProtocol(std::unique_ptr<IWandererCoverProtocol> protocol);
191 IWandererCoverProtocol* getCurrentProtocol() const { return currentProtocol.get(); }
192
193 // Protocol handler
194 std::unique_ptr<IWandererCoverProtocol> currentProtocol;
195
196 // Status data
198
199 // Properties for all protocol versions
200 INDI::PropertyNumber DataNP{7}; // Extended to support new protocol fields
201 enum
202 {
203 closeset_read,
204 openset_read,
205 position_read,
206 voltage_read,
207 flat_panel_brightness_read,
208 dew_heater_power_read,
209 asiair_control_enabled_read,
210 };
211
212 //Dew heater///////////////////////////////////////////////////////////////
213 INDI::PropertyNumber SetHeaterNP{1};
214 enum
215 {
216 Heat,
217 };
218 //Close Set///////////////////////////////////////////////////////////////
219 INDI::PropertyNumber CloseSetNP{1};
220 enum
221 {
222 CloseSet,
223 };
224 //Open Set///////////////////////////////////////////////////////////////
225 INDI::PropertyNumber OpenSetNP{1};
226 enum
227 {
228 OpenSet,
229 };
230
231 // Firmware information
232 INDI::PropertyText FirmwareTP{1};
233 enum
234 {
235 FIRMWARE_VERSION,
236 };
237
238 // New protocol features
239 INDI::PropertySwitch ASIAIRControlSP{2};
240 enum
241 {
242 ASIAIR_ENABLE,
243 ASIAIR_DISABLE,
244 };
245
246 INDI::PropertyNumber CustomBrightnessNP{3};
247 enum
248 {
249 CUSTOM_BRIGHTNESS_1,
250 CUSTOM_BRIGHTNESS_2,
251 CUSTOM_BRIGHTNESS_3,
252 };
253
254 INDI::PropertySwitch AutoDetectSP{2};
255 enum
256 {
257 AUTO_DETECT_OPEN,
258 AUTO_DETECT_CLOSE,
259 };
260
261 int PortFD{ -1 };
262
263 Connection::Serial *serialConnection{ nullptr };
264
265 // Mutex for thread safety
266 std::timed_mutex serialPortMutex;
267};
hid_device * device
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual std::string generateSetClosePositionCommand(double value) const =0
virtual int getMinFirmwareVersion() const =0
virtual bool detectProtocol(const char *data)=0
virtual int getProtocolVersion() const =0
virtual std::string generateCustomBrightnessCommand(int brightness, int customNumber) const =0
virtual bool supportsFeature(const std::string &feature) const =0
virtual std::string generateAutoDetectOpenPositionCommand() const =0
virtual std::string generateASIAIRControlCommand(bool enable) const =0
virtual ~IWandererCoverProtocol()=default
virtual std::string generateDewHeaterCommand(int value) const =0
virtual std::string generateCloseCommand() const =0
virtual std::string generateAutoDetectClosePositionCommand() const =0
virtual std::string generateOpenCommand() const =0
virtual bool parseDeviceData(const char *data, WandererCoverV4EC *device)=0
virtual std::string generateSetOpenPositionCommand(double value) const =0
virtual std::string generateSetBrightnessCommand(uint16_t value) const =0
virtual std::string generateTurnOffLightCommand() const =0
virtual std::string getProtocolName() const =0
int getMinFirmwareVersion() const override
bool detectProtocol(const char *data) override
std::string generateSetBrightnessCommand(uint16_t value) const override
std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override
std::string generateCloseCommand() const override
int getProtocolVersion() const override
std::string getProtocolName() const override
std::string generateSetClosePositionCommand(double value) const override
std::string generateAutoDetectClosePositionCommand() const override
bool supportsFeature(const std::string &feature) const override
std::string generateSetOpenPositionCommand(double value) const override
std::string generateOpenCommand() const override
std::string generateDewHeaterCommand(int value) const override
std::string generateTurnOffLightCommand() const override
bool parseDeviceData(const char *data, WandererCoverV4EC *device) override
std::string generateAutoDetectOpenPositionCommand() const override
std::string generateASIAIRControlCommand(bool enable) const override
std::string generateTurnOffLightCommand() const override
std::string generateAutoDetectOpenPositionCommand() const override
bool supportsFeature(const std::string &feature) const override
std::string generateASIAIRControlCommand(bool enable) const override
std::string getProtocolName() const override
bool parseDeviceData(const char *data, WandererCoverV4EC *device) override
bool detectProtocol(const char *data) override
std::string generateCloseCommand() const override
std::string generateSetBrightnessCommand(uint16_t value) const override
int getProtocolVersion() const override
std::string generateDewHeaterCommand(int value) const override
std::string generateAutoDetectClosePositionCommand() const override
std::string generateSetOpenPositionCommand(double value) const override
std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override
std::string generateOpenCommand() const override
int getMinFirmwareVersion() const override
std::string generateSetClosePositionCommand(double value) const override
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
const char * getDefaultName() override
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
virtual ~WandererCoverV4EC()=default
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34