Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_upb3.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2026 Jasem Mutlaq. All rights reserved.
3
4 Pegasus Ultimate Power Box V3 Driver.
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 "indipowerinterface.h"
31#include "indioutputinterface.h"
32#include <stdint.h>
33
34namespace Connection
35{
36class Serial;
37}
38
44{
45 public:
47
48 virtual bool initProperties() override;
49 virtual bool updateProperties() override;
50
51 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
52 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
53 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
54
55 protected:
56 const char *getDefaultName() override;
57 virtual bool saveConfigItems(FILE *fp) override;
58
59 // Event loop
60 virtual void TimerHit() override;
61
62 // Focuser Overrides
63 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
64 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
65 virtual bool AbortFocuser() override;
66 virtual bool ReverseFocuser(bool enabled) override;
67 virtual bool SyncFocuser(uint32_t ticks) override;
68 virtual bool SetFocuserBacklash(int32_t steps) override;
69 virtual bool SetFocuserBacklashEnabled(bool enabled) override;
70
71 // Weather Overrides
72 virtual IPState updateWeather() override
73 {
74 return IPS_OK;
75 }
76
77 // Power Interface Overrides
78 virtual bool SetPowerPort(size_t port, bool enabled) override;
79 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
80 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
81 virtual bool SetLEDEnabled(bool enabled) override;
82 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
83 virtual bool CyclePower() override;
84 virtual bool SetUSBPort(size_t port, bool enabled) override;
85
86 // Output Interface Overrides (Relay)
87 virtual bool UpdateDigitalOutputs() override;
88 virtual bool CommandOutput(uint32_t index, OutputState command) override;
89
90 private:
91 bool Handshake();
92
93 // Get Data
94 bool setupParams();
95 bool sendFirmware();
96 bool getSensorData();
97 bool getPowerData();
98 bool getStepperData();
99 bool getAutoDewData();
100 bool getUSBStatus();
101 bool getInputVoltageCurrentData();
102 bool getEnvironmentalData();
103 std::vector<std::string> split(const std::string &input, const std::string &regex);
104
105 // Device Control
106 bool reboot();
107
108 // Power
109 bool setPowerEnabled(uint8_t port, uint8_t value);
110 bool setPowerLEDEnabled(bool enabled);
111 bool setPowerOnBoot();
112 bool getPowerOnBoot();
113
114 // Adjustable Outputs (Buck and Boost)
115 bool setBuckVoltage(uint8_t voltage);
116 bool setBoostVoltage(uint8_t voltage);
117 bool setBuckEnabled(bool enabled);
118 bool setBoostEnabled(bool enabled);
119
120 // Dew
121 bool setAutoDewEnabled(uint8_t port, bool enabled);
122 bool setAutoDewAgg(uint8_t value);
123 bool setDewPWM(uint8_t id, uint8_t value);
124
125 // USB
126 bool setUSBPortEnabled(uint8_t port, bool enabled);
127
128 // Relay
129 bool setRelay(bool enabled);
130
131 // Focuser
132 bool setFocuserMaxSpeed(uint16_t maxSpeed);
133 bool setFocuserMicrostepping(uint8_t value);
134 bool setFocuserCurrentLimit(uint16_t value);
135 bool setFocuserHoldTorque(bool enabled);
136
143 bool sendCommand(const char *cmd, char *res);
144
149 void cleanupResponse(char *response);
150
154 bool sensorUpdated(const std::vector<std::string> &result, uint8_t start, uint8_t end);
155
159 bool stepperUpdated(const std::vector<std::string> &result, uint8_t index);
160
161 int PortFD { -1 };
162 bool setupComplete { false };
163
164 Connection::Serial *serialConnection { nullptr };
165
170 INDI::PropertySwitch RebootSP {1};
171
172 // Power Consumption
173 INDI::PropertyNumber PowerConsumptionNP {3};
174 enum
175 {
176 CONSUMPTION_AVG_AMPS,
177 CONSUMPTION_AMP_HOURS,
178 CONSUMPTION_WATT_HOURS,
179 };
180
181 // Select which power is ON on bootup
182 INDI::PropertySwitch PowerOnBootSP {6};
183 enum
184 {
185 POWER_PORT_1,
186 POWER_PORT_2,
187 POWER_PORT_3,
188 POWER_PORT_4,
189 POWER_PORT_5,
190 POWER_PORT_6
191 };
192
193 // Overcurrent status
194 INDI::PropertyLight OverCurrentLP {9};
195 enum
196 {
197 OC_POWER_1,
198 OC_POWER_2,
199 OC_POWER_3,
200 OC_POWER_4,
201 OC_POWER_5,
202 OC_POWER_6,
203 OC_DEW_1,
204 OC_DEW_2,
205 OC_DEW_3
206 };
207
211 // Auto Dew Aggressiveness (Global)
212 enum
213 {
214 AUTO_DEW_AGG,
215 };
216 INDI::PropertyNumber AutoDewAggNP {1};
217
218 // Auto Dew Aggressiveness per Port
219 INDI::PropertyNumber AutoDewAggPerPortNP {3};
220 enum
221 {
222 AUTO_DEW_AGG_1,
223 AUTO_DEW_AGG_2,
224 AUTO_DEW_AGG_3
225 };
226
230 // Focuser settings
231 INDI::PropertyNumber FocuserSettingsNP {4};
232 enum
233 {
234 SETTING_MAX_SPEED,
235 SETTING_MICROSTEPPING,
236 SETTING_CURRENT_LIMIT,
237 SETTING_HOLD_TORQUE
238 };
239
243 INDI::PropertyText FirmwareTP {2};
244 enum
245 {
246 FIRMWARE_VERSION,
247 FIRMWARE_UPTIME
248 };
249
250 std::vector<std::string> lastSensorData, lastPowerData, lastStepperData, lastAutoDewData, lastVRData, lastESData;
251 bool focusMotorRunning { false };
252 bool m_RelayState { false };
253 char stopChar { 0xD };
254
255 static constexpr const uint8_t PEGASUS_TIMEOUT {3};
256 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
257 static constexpr const char *POWER_TAB {"Power"};
258 static constexpr const char *DEW_TAB {"Dew"};
259 static constexpr const char *FIRMWARE_TAB {"Firmware"};
260 static constexpr const char *RELAY_TAB {"Relay"};
261};
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...
Provides interface to implement focuser functionality.
Provides interface to implement weather reporting and safety monitoring functionality.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool initProperties() override
Init Properties.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
virtual void TimerHit() override
Timer Hit.
const char * getDefaultName() override
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool UpdateDigitalOutputs() override
OutputInterface Implementation (Relay)
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool updateProperties() override
Update Properties.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool SetPowerPort(size_t port, bool enabled) override
PowerInterface Implementation.
virtual bool CommandOutput(uint32_t index, OutputState command) override
Send command to output.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
ISNewSwitch.
virtual bool saveConfigItems(FILE *fp) override
Save Config Items.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
FocuserInterface Implementation.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
ISNewText.
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
ISNewNumber.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_OK
Definition indiapi.h:160
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34
uint8_t cmd[4]
Definition pwc-ioctl.h:2