Instrument Neutral Distributed Interface INDI 2.2.5
wanderer_cover_v4_pro_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 Pro-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, WandererCoverV4ProEC* 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 generateASIAIRControlCommand(bool enable) const = 0;
67 virtual std::string generateCustomBrightnessCommand(int brightness, int customNumber) const = 0;
68
69 // Status data structure
70 struct StatusData
71 {
72 int firmware = 0;
73 double closePositionSet = 0.0;
74 double openPositionSet = 0.0;
75 double currentPosition = 0.0;
76 double voltage = 0.0;
77 int flatPanelBrightness = 0;
78 bool asiairControlEnabled = false;
79 };
80};
81
82// Legacy protocol implementation (pre-20250405)
84{
85public:
86 std::string getProtocolName() const override { return "WandererCover V4 Pro-EC (Legacy < 20250405)"; }
87 int getProtocolVersion() const override { return 1; }
88 int getMinFirmwareVersion() const override { return 0; }
89
90 bool supportsFeature(const std::string& feature) const override;
91 bool parseDeviceData(const char* data, WandererCoverV4ProEC* device) override;
92 bool detectProtocol(const char* data) override;
93
94 std::string generateOpenCommand() const override;
95 std::string generateCloseCommand() const override;
96 std::string generateSetBrightnessCommand(uint16_t value) const override;
97 std::string generateTurnOffLightCommand() const override;
98 std::string generateSetOpenPositionCommand(double value) const override;
99 std::string generateSetClosePositionCommand(double value) const override;
100 std::string generateASIAIRControlCommand(bool enable) const override;
101 std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override;
102};
103
104// Modern protocol implementation (20250405+)
106{
107public:
108 std::string getProtocolName() const override { return "WandererCover V4 Pro-EC (Modern >= 20250405)"; }
109 int getProtocolVersion() const override { return 2; }
110 int getMinFirmwareVersion() const override { return 20250405; }
111
112 bool supportsFeature(const std::string& feature) const override;
113 bool parseDeviceData(const char* data, WandererCoverV4ProEC* device) override;
114 bool detectProtocol(const char* data) override;
115
116 std::string generateOpenCommand() const override;
117 std::string generateCloseCommand() const override;
118 std::string generateSetBrightnessCommand(uint16_t value) const override;
119 std::string generateTurnOffLightCommand() const override;
120 std::string generateSetOpenPositionCommand(double value) const override;
121 std::string generateSetClosePositionCommand(double value) const override;
122 std::string generateASIAIRControlCommand(bool enable) const override;
123 std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override;
124};
125
127{
128public:
130 virtual ~WandererCoverV4ProEC() = default;
131
132 virtual bool initProperties() override;
133 virtual void ISGetProperties(const char *dev) override;
134 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
135 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
136 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
137 virtual bool updateProperties() override;
138 virtual bool ISSnoopDevice(XMLEle *root) override;
139
140protected:
141
142 // From Dust Cap
143 virtual IPState ParkCap() override;
144 virtual IPState UnParkCap() override;
145
146 // From Light Box
147 virtual bool SetLightBoxBrightness(uint16_t value) override;
148 virtual bool EnableLightBox(bool enable) override;
149
150 const char *getDefaultName() override;
151 virtual bool saveConfigItems(FILE *fp) override;
152 virtual void TimerHit() override;
153
154 // Protocol handler access
158
159private:
160
161 int firmware=0;
162 bool toggleCover(bool open);
163 bool sendCommand(std::string command);
164 bool getData();
165 bool parseDeviceData(const char *data);
166 double closesetread=0;
167 double opensetread=0;
168 double positionread=0;
169 double voltageread=0;
170 double asiaircontrolenabledread=0;
171 double flatpanelbrightnessread=0;
172 bool setClose(double value);
173 bool setOpen(double value);
174 void updateData(double closesetread,double opensetread,double positionread,double voltageread,double flatpanelbrightnessread,double asiaircontrolenabledread);
175
176 // Protocol detection and management
177 bool detectProtocol();
178 void setProtocol(std::unique_ptr<IWandererCoverProtocol> protocol);
179 IWandererCoverProtocol* getCurrentProtocol() const { return currentProtocol.get(); }
180
181 // Protocol handler
182 std::unique_ptr<IWandererCoverProtocol> currentProtocol;
183
184 // Status data
186
187 // Properties for all protocol versions
188 INDI::PropertyNumber DataNP{7}; // Extended to support new protocol fields
189 enum
190 {
191 closeset_read,
192 openset_read,
193 position_read,
194 voltage_read,
195 flat_panel_brightness_read,
196 null,
197 asiair_control_enabled_read,
198 };
199
200
201 //Close Set///////////////////////////////////////////////////////////////
202 INDI::PropertyNumber CloseSetNP{1};
203 enum
204 {
205 CloseSet,
206 };
207 //Open Set///////////////////////////////////////////////////////////////
208 INDI::PropertyNumber OpenSetNP{1};
209 enum
210 {
211 OpenSet,
212 };
213
214 // Firmware information
215 INDI::PropertyText FirmwareTP{1};
216 enum
217 {
218 FIRMWARE_VERSION,
219 };
220
221 // New protocol features
222 INDI::PropertySwitch ASIAIRControlSP{2};
223 enum
224 {
225 ASIAIR_ENABLE,
226 ASIAIR_DISABLE,
227 };
228
229 INDI::PropertyNumber CustomBrightnessNP{3};
230 enum
231 {
232 CUSTOM_BRIGHTNESS_1,
233 CUSTOM_BRIGHTNESS_2,
234 CUSTOM_BRIGHTNESS_3,
235 };
236
237
238
239 int PortFD{ -1 };
240
241 Connection::Serial *serialConnection{ nullptr };
242
243 // Mutex for thread safety
244 std::timed_mutex serialPortMutex;
245};
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 generateASIAIRControlCommand(bool enable) const =0
virtual ~IWandererCoverProtocol()=default
virtual bool parseDeviceData(const char *data, WandererCoverV4ProEC *device)=0
virtual std::string generateCloseCommand() const =0
virtual std::string generateOpenCommand() const =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
std::string getProtocolName() const override
std::string generateSetClosePositionCommand(double value) const override
bool supportsFeature(const std::string &feature) const override
std::string generateSetOpenPositionCommand(double value) const override
std::string generateOpenCommand() const override
std::string generateTurnOffLightCommand() const override
bool parseDeviceData(const char *data, WandererCoverV4EC *device) override
std::string generateASIAIRControlCommand(bool enable) const override
std::string generateTurnOffLightCommand() 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
std::string generateSetOpenPositionCommand(double value) const override
std::string generateCustomBrightnessCommand(int brightness, int customNumber) const override
std::string generateOpenCommand() const override
std::string generateSetClosePositionCommand(double value) const override
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
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....
const char * getDefaultName() override
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
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...
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 IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
virtual ~WandererCoverV4ProEC()=default
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
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