Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_ppba.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3
4 Pegasus Pocket Power Box Advance
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
32#include <vector>
33#include <stdint.h>
34
35namespace Connection
36{
37class Serial;
38}
39
41{
42 public:
44
45 virtual bool initProperties() override;
46 virtual bool updateProperties() override;
47
48 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
49 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
50 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
51
52 protected:
53 const char *getDefaultName() override;
54 virtual bool saveConfigItems(FILE *fp) override;
55
56 // Event loop
57 virtual void TimerHit() override;
58
59 // Focuser Overrides
60 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
61 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
62 virtual bool AbortFocuser() override;
63 virtual bool ReverseFocuser(bool enabled) override;
64 virtual bool SyncFocuser(uint32_t ticks) override;
65
66 virtual bool SetFocuserBacklash(int32_t steps) override;
67 virtual bool SetFocuserBacklashEnabled(bool enabled) override;
68
69 // Power Overrides
70 virtual bool SetPowerPort(size_t port, bool enabled) override;
71 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
72 virtual bool SetLEDEnabled(bool enabled) override;
73 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
74 virtual bool CyclePower() override;
75 virtual bool SetUSBPort(size_t port, bool enabled) override;
76
77 // Weather Overrides
78 virtual IPState updateWeather() override
79 {
80 return IPS_OK;
81 }
82
83
84 private:
85 bool Handshake();
86
87 // Get Data
88 bool sendFirmware();
89 bool getSensorData();
90 bool getConsumptionData();
91 bool getMetricsData();
92 bool findExternalMotorController();
93 bool getXMCStartupData();
94 std::vector<std::string> split(const std::string &input, const std::string &regex);
95 enum
96 {
97 PA_NAME,
98 PA_VOLTAGE,
99 PA_CURRENT,
100 PA_TEMPERATURE,
101 PA_HUMIDITY,
102 PA_DEW_POINT,
103 PA_PORT_STATUS,
104 PA_ADJ_STATUS,
105 PA_DEW_1,
106 PA_DEW_2,
107 PA_AUTO_DEW,
108 PA_PWR_WARN,
109 PA_PWRADJ,
110 PA_N,
111 };
112 enum
113 {
114 PS_NAME,
115 PS_AVG_AMPS,
116 PS_AMP_HOURS,
117 PS_WATT_HOURS,
118 PS_UPTIME,
119 PS_N,
120 };
121 enum
122 {
123 PC_NAME,
124 PC_TOTAL_CURRENT,
125 PC_12V_CURRENT,
126 PC_DEWA_CURRENT,
127 PC_DEWB_CURRENT,
128 PC_UPTIME,
129 PC_N,
130 };
131
132 // Device Control
133 bool reboot();
134
135 // Power
136 bool setPowerEnabled(uint8_t port, bool enabled);
137 bool setPowerOnBoot();
138 bool setLedIndicator(bool enabled);
139
140 // Dew
141 bool setAutoDewEnabled(bool enabled);
142 bool setAutoDewAggression(uint8_t value);
143 bool getAutoDewAggression();
144 bool setDewPWM(uint8_t id, uint8_t value);
145
146 // Focuser
147 void queryXMC();
148 bool setFocuserMaxSpeed(uint16_t maxSpeed);
149 bool setFocuserMicrosteps(int value);
150
157 bool sendCommand(const char *cmd, char *res);
158
159 int PortFD { -1 };
160 bool setupComplete { false };
161
162 Connection::Serial *serialConnection { nullptr };
163
167 // Power Statistics
168 INDI::PropertyNumber PowerStatisticsNP {4};
169 enum
170 {
171 STATS_AVG_AMPS,
172 STATS_AMP_HOURS,
173 STATS_WATT_HOURS,
174 STATS_TOTAL_CURRENT
175 };
176
178 INDI::PropertySwitch RebootSP {1};
179
180 // Short circuit warn
181 INDI::PropertyLight PowerWarnLP {1};
182
183 // Adjustable power port
184 INDI::PropertySwitch AdjOutVoltSP {6};
185 enum
186 {
187 ADJOUT_OFF,
188 ADJOUT_3V,
189 ADJOUT_5V,
190 ADJOUT_8V,
191 ADJOUT_9V,
192 ADJOUT_12V,
193 };
194
195 // Select which power is ON on bootup
196 INDI::PropertySwitch PowerOnBootSP {4};
197 enum
198 {
199 POWER_PORT_1,
200 POWER_PORT_2,
201 POWER_PORT_3,
202 POWER_PORT_4
203 };
204
208
209 INDI::PropertyNumber AutoDewSettingsNP {1};
210 enum
211 {
212 AUTO_DEW_AGGRESSION
213 };
214
218
219 // Focuser speed
220 INDI::PropertyNumber FocuserSettingsNP {1};
221 enum
222 {
223 SETTING_MAX_SPEED,
224 };
225
226 // Microstepping
227 INDI::PropertySwitch FocuserDriveSP {4};
228 enum
229 {
230 STEP_FULL,
231 STEP_HALF,
232 STEP_FORTH,
233 STEP_EIGHTH
234 };
235
236
237
241
242 INDI::PropertyText FirmwareTP {2};
243 enum
244 {
245 FIRMWARE_VERSION,
246 FIRMWARE_UPTIME,
247 };
248
249 std::vector<std::string> lastSensorData;
250 std::vector<std::string> lastConsumptionData;
251 std::vector<std::string> lastMetricsData;
252 char stopChar { 0xD };
253 bool m_HasExternalMotor { false };
254
255 static constexpr const uint8_t PEGASUS_TIMEOUT {3};
256 static constexpr const uint8_t PEGASUS_LEN {128};
257 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
258 static constexpr const char *FIRMWARE_TAB {"Firmware"};
259};
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 SetPowerPort(size_t port, bool enabled) override
Power Interface Implementations.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
const char * getDefaultName() override
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
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 IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
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 MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
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