Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_flatmaster_neo.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2026 Dominik Merkel. All rights reserved.
3
4 Pegasus FlatMaster Neo
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
28#include "defaultdevice.h"
31#include "pegasus_wifi.h"
32
33#include <chrono>
34#include <vector>
35#include <string>
36
37
40{
41 public:
43 virtual ~PegasusFlatMasterNeo() override = default;
44
45 const char *getDefaultName() override;
46 void ISGetProperties(const char *dev) override;
47 virtual bool initProperties() override;
48 virtual bool updateProperties() override;
49
50 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
51 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
52 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
53 virtual bool ISSnoopDevice(XMLEle *root) override;
54
55 protected:
56 virtual bool SetLightBoxBrightness(uint16_t value) override;
57 virtual bool EnableLightBox(bool enable) override;
58 virtual bool saveConfigItems(FILE *fp) override;
59
60 virtual IPState ParkCap() override;
61 virtual IPState UnParkCap() override;
62 virtual IPState AbortCap() override;
63
64 virtual IPState updateWeather() override { return IPS_OK; }
65 virtual void TimerHit() override;
66
67 private:
68 bool Ack();
69 bool getStatusData();
70 bool getWeatherData();
71 bool getWeatherOffsets();
72 bool getUptime();
73 bool getThreshold();
74 bool getAutoClose();
75 bool setTemperatureOffset(double value);
76 bool setHumidityOffset(double value);
77 bool setDewHeater(uint8_t value);
78 bool setAutoDew(bool enable);
79 bool setDewAggressiveness(uint8_t level);
80 bool saveDewLevels();
81 bool setThreshold(uint8_t value);
82 bool setCapAngle(uint16_t angle);
83 bool setAutoClose(bool enable);
84 bool wifiFactoryReset();
85 std::vector<std::string> split(const std::string &input, const std::string &sep);
86
87 int PortFD{ -1 };
88 bool sendCommandBuffer(const char *cmd, char *response, int response_len, int timeout_sec);
89 // Reads at most N bytes into the response buffer.
90 template <int N>
91 bool sendCommand(const char *cmd, char (&response)[N], int timeout_sec = 3)
92 {
93 return sendCommandBuffer(cmd, response, N, timeout_sec);
94 }
95 // Sends a command that the device answers with an exact echo, e.g. FE:1 -> FE:1.
96 bool sendEchoCommand(const char *cmd);
97 static uint8_t aggressivenessLevel(double value);
98 // Settings the device stores itself; a configuration loaded from an older driver version must not send them back.
99 bool ignoredWhileLoadingConfig(const char *dev, const char *name) const;
100 void updateFirmwareVersion();
101
102 // Firmware version
103 ITextVectorProperty FirmwareTP;
104 IText FirmwareT[1] {};
105
106 // Dew Control
107 INDI::PropertyNumber DewHeaterNP {1};
108 INDI::PropertySwitch AutoDewSP {2};
109 INDI::PropertyNumber DewAggressivenessNP {1};
110 INDI::PropertyNumber ThresholdNP {1};
111 INDI::PropertySwitch SaveDewSP {1};
112
113 // Auto-close (DC command)
114 INDI::PropertySwitch AutoCloseSP {2};
115
116 // Cap angle
117 INDI::PropertyNumber CapAngleNP {1};
118
119 // Weather offsets (CT / CH / CR)
120 INDI::PropertyNumber WeatherOffsetNP {2};
121
122 // Device overview status (FA command)
123 INDI::PropertyNumber DeviceStatusNP {9};
124
125 // Uptime (FU command)
126 INDI::PropertyNumber UptimeNP {1};
127
128 // Reboot (FQ command)
129 INDI::PropertySwitch RebootSP {1};
130
131 // WiFi factory reset (WZ command)
132 INDI::PropertySwitch WifiFactoryResetSP {1};
133
134 Connection::Serial *serialConnection{ nullptr };
135 Connection::TCP *tcpConnection{ nullptr };
136
137 // Hotspot, WiFi client and the login on the TCP command socket, shared with other Pegasus devices.
138 PegasusAstro::WiFi wifi {this};
139 bool m_IsTCP{ false };
140
141 // Cap position requested by ParkCap()/UnParkCap(), to tell a finished move from one not started yet.
142 int m_CapTarget{ 0 };
143 std::chrono::steady_clock::time_point m_CapMoveStarted;
144 static constexpr std::chrono::seconds CAP_START_TIMEOUT{ 5 };
145
146 std::vector<std::string> lastWeatherData;
147 std::vector<std::string> lastStatusData;
148
149 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
150 static constexpr const char *LIGHTBOX_TAB {"Light Box"};
151 static constexpr const char *DUSTCAP_TAB {"Dust Cap"};
152 static constexpr const char *DEW_TAB {"Dew Control"};
153 static constexpr const char *STATUS_TAB {"Overview"};
154 static constexpr const char *NETWORK_TAB {"Network"};
155 static constexpr const uint8_t NEO_LEN {64};
156
157 // FA response field indices
158 // FA response: "FMNEO:lightIntensity:lightActive:capActual:capTarget:capStatus:v6:autoDew:v8:v9"
159 enum
160 {
161 FA_NAME = 0,
162 FA_LIGHT_INTENSITY,
163 FA_LIGHT_ACTIVE,
164 FA_CAP_ACTUAL_ANGLE,
165 FA_CAP_TARGET_ANGLE,
166 FA_CAP_STATUS,
167 FA_DEW_POWER,
168 FA_AUTO_DEW_STATUS,
169 FA_DEW_AGGRESSIVE,
170 FA_LIGHT_SENSOR,
171 FA_N,
172 };
173
174 enum CapMotionStatus
175 {
176 CAP_STATUS_UNKNOWN = 0,
177 CAP_STATUS_PARKED = 1,
178 CAP_STATUS_MOVING = 2,
179 CAP_STATUS_UNPARKED = 3,
180 };
181
182 // DeviceStatusNP indices (FA[1..9])
183 enum
184 {
185 STATUS_LIGHT_INTENSITY = 0,
186 STATUS_LIGHT_ACTIVE,
187 STATUS_CAP_ACTUAL_ANGLE,
188 STATUS_CAP_TARGET_ANGLE,
189 STATUS_CAP_STATUS,
190 STATUS_DEW_POWER,
191 STATUS_AUTO_DEW,
192 STATUS_DEW_AGGRESSIVE,
193 STATUS_LIGHT_SENSOR,
194 };
195
196 // ES response field indices
197 enum
198 {
199 WI_NAME = 0,
200 WI_TEMPERATURE,
201 WI_HUMIDITY,
202 WI_DEWPOINT,
203 WI_N,
204 };
205
206 // CR response field indices
207 enum
208 {
209 CR_PREFIX = 0,
210 CR_TEMP_OFFSET,
211 CR_HUM_OFFSET,
212 CR_N,
213 };
214
215 // WeatherOffsetNP indices
216 enum
217 {
218 OFFSET_TEMPERATURE = 0,
219 OFFSET_HUMIDITY,
220 };
221};
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Provides interface to implement weather reporting and safety monitoring functionality.
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
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 AbortCap() override
Abort motion. Must be implemented by child.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
virtual ~PegasusFlatMasterNeo() override=default
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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 updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_OK
Definition indiapi.h:160
struct _ITextVectorProperty ITextVectorProperty
struct _IText IText
*brief user defined string literal for JSON values *sa std::size_t n
struct xml_ele_ XMLEle
Definition lilxml.h:81
uint8_t cmd[4]
Definition pwc-ioctl.h:2