Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_upb.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2018 Jasem Mutlaq. All rights reserved.
3
4 Pegasus Ultimate Power Box (v1 and v2)
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" // Include the new power interface
31#include <stdint.h>
32
33namespace Connection
34{
35class Serial;
36}
37
40{
41 public:
42 PegasusUPB();
43
44 enum
45 {
47 UPB_V2
48 };
49
50 virtual bool initProperties() override;
51 virtual bool updateProperties() override;
52
53 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
54 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
55 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
56
57 protected:
58 const char *getDefaultName() override;
59 virtual bool saveConfigItems(FILE *fp) override;
60
61 // Event loop
62 virtual void TimerHit() override;
63
64 // Focuser Overrides
65 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
66 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
67 virtual bool AbortFocuser() override;
68 virtual bool ReverseFocuser(bool enabled) override;
69 virtual bool SyncFocuser(uint32_t ticks) override;
70
71 virtual bool SetFocuserBacklash(int32_t steps) override;
72 virtual bool SetFocuserBacklashEnabled(bool enabled) override;
73
74 // Weather Overrides
75 virtual IPState updateWeather() override
76 {
77 return IPS_OK;
78 }
79
80 // Power Interface Overrides
81 virtual bool SetPowerPort(size_t port, bool enabled) override;
82 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
83 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
84 virtual bool SetLEDEnabled(bool enabled) override;
85 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
86 virtual bool CyclePower() override;
87 virtual bool SetUSBPort(size_t port, bool enabled) override;
88
89 private:
90 bool Handshake();
91
92 // Get Data
93 bool setupParams();
94 bool sendFirmware();
95 bool getSensorData();
96 bool getPowerData();
97 bool getStepperData();
98 bool getDewAggData();
99 std::vector<std::string> split(const std::string &input, const std::string &regex);
100
101 // Device Control
102 bool reboot();
103
104 // Power
105 bool setPowerEnabled(uint8_t port, bool enabled);
106 bool setPowerLEDEnabled(bool enabled);
107 bool setPowerOnBoot();
108 bool getPowerOnBoot();
109 bool setAdjustableOutput(uint8_t voltage);
110
111 // Dew
112 bool setAutoDewEnabled(bool enabled);
113 bool toggleAutoDewV2(size_t port, bool enabled);
114 bool setAutoDewAgg(uint8_t value);
115 bool setDewPWM(uint8_t id, uint8_t value);
116
117 // USB
118 bool setUSBHubEnabled(bool enabled);
119 bool setUSBPortEnabled(uint8_t port, bool enabled);
120
121 // Focuser
122 bool setFocuserMaxSpeed(uint16_t maxSpeed);
123 // bool setFocuserBacklash(uint16_t value);
124 // bool setFocuserBacklashEnabled(bool enabled);
125
132 bool sendCommand(const char *cmd, char *res);
133
138 void cleanupResponse(char *response);
139
146 bool sensorUpdated(const std::vector<std::string> &result, uint8_t start, uint8_t end);
147
154 bool stepperUpdated(const std::vector<std::string> &result, uint8_t index);
155
156 int PortFD { -1 };
157 bool setupComplete { false };
158
159 Connection::Serial *serialConnection { nullptr };
160
165 INDI::PropertySwitch RebootSP {1};
166
167 // Power Consumption
168 INDI::PropertyNumber PowerConsumptionNP {3};
169 enum
170 {
171 CONSUMPTION_AVG_AMPS,
172 CONSUMPTION_AMP_HOURS,
173 CONSUMPTION_WATT_HOURS,
174 };
175
176 // Select which power is ON on bootup
177 INDI::PropertySwitch PowerOnBootSP {4};
178 enum
179 {
180 POWER_PORT_1,
181 POWER_PORT_2,
182 POWER_PORT_3,
183 POWER_PORT_4
184 };
185
186 // Overcurrent status
187 INDI::PropertyLight OverCurrentLP {7};
188 enum
189 {
190 DEW_A,
191 DEW_B,
192 DEW_C
193 };
194
198
199 // Auto Dew v2 Aggressiveness
200 enum
201 {
202 AUTO_DEW_AGG,
203 };
204 INDI::PropertyNumber AutoDewAggNP {1};
205
209
210 // Focuser speed
211 INDI::PropertyNumber FocuserSettingsNP {1};
212 enum
213 {
214 SETTING_MAX_SPEED,
215 };
216
220 INDI::PropertyText FirmwareTP {2};
221 enum
222 {
223 FIRMWARE_VERSION,
224 FIRMWARE_UPTIME
225 };
226
227
228 std::vector<std::string> lastSensorData, lastPowerData, lastStepperData, lastDewAggData;
229 bool focusMotorRunning { false };
230 char stopChar { 0xD };
231 uint8_t version { UPB_V1 };
232
233 static constexpr const uint8_t PEGASUS_TIMEOUT {3};
234 static constexpr const uint8_t PEGASUS_LEN {128};
235 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
236 static constexpr const char *POWER_TAB {"Power"};
237 static constexpr const char *FIRMWARE_TAB {"Firmware"};
238};
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 void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
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 bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool SetPowerPort(size_t port, bool enabled) override
Power Interface Implementations.
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
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 AbortFocuser() override
AbortFocuser all focus motion.
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
const char * getDefaultName() override
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition pegasus_upb.h:75
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
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
@ 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