forked from indilib/indi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pegasus_upb.h
322 lines (258 loc) · 9.96 KB
/
pegasus_upb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*******************************************************************************
Copyright(c) 2018 Jasem Mutlaq. All rights reserved.
Pegasus Ultimate Power Box (v1 and v2)
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
The full GNU General Public License is included in this distribution in the
file called LICENSE.
*******************************************************************************/
#pragma once
#include "defaultdevice.h"
#include "indifocuserinterface.h"
#include "indiweatherinterface.h"
#include <stdint.h>
namespace Connection
{
class Serial;
}
class PegasusUPB : public INDI::DefaultDevice, public INDI::FocuserInterface, public INDI::WeatherInterface
{
public:
PegasusUPB();
enum
{
UPB_V1,
UPB_V2
};
virtual bool initProperties() override;
virtual bool updateProperties() override;
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
protected:
const char *getDefaultName() override;
virtual bool saveConfigItems(FILE *fp) override;
// Event loop
virtual void TimerHit() override;
// Focuser Overrides
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
virtual bool AbortFocuser() override;
virtual bool ReverseFocuser(bool enabled) override;
virtual bool SyncFocuser(uint32_t ticks) override;
virtual bool SetFocuserBacklash(int32_t steps) override;
virtual bool SetFocuserBacklashEnabled(bool enabled) override;
// Weather Overrides
virtual IPState updateWeather() override
{
return IPS_OK;
}
private:
bool Handshake();
// Get Data
bool setupParams();
bool sendFirmware();
bool getSensorData();
bool getPowerData();
bool getStepperData();
bool getDewAggData();
std::vector<std::string> split(const std::string &input, const std::string ®ex);
// Device Control
bool reboot();
// Power
bool setPowerEnabled(uint8_t port, bool enabled);
bool setPowerLEDEnabled(bool enabled);
bool setPowerOnBoot();
bool getPowerOnBoot();
bool setAdjustableOutput(uint8_t voltage);
// Dew
bool setAutoDewEnabled(bool enabled);
bool toggleAutoDewV2();
bool setAutoDewAgg(uint8_t value);
bool setDewPWM(uint8_t id, uint8_t value);
// USB
bool setUSBHubEnabled(bool enabled);
bool setUSBPortEnabled(uint8_t port, bool enabled);
// Focuser
bool setFocuserMaxSpeed(uint16_t maxSpeed);
// bool setFocuserBacklash(uint16_t value);
// bool setFocuserBacklashEnabled(bool enabled);
/**
* @brief sendCommand Send command to unit.
* @param cmd Command
* @param res if nullptr, respones is ignored, otherwise read response and store it in the buffer.
* @return
*/
bool sendCommand(const char *cmd, char *res);
/**
* @brief cleanupResponse Removes all spaces
* @param response buffer
*/
void cleanupResponse(char *response);
/**
* @return Return true if sensor data different from last data
*
* If the previous sensor data is empty then this will always
* return true.
*/
bool sensorUpdated(const std::vector<std::string> &result, uint8_t start, uint8_t end);
/**
* @return Return true if stepper data different from last data.
*
* If the previous stepper data is empty then this will always
* return true.
*/
bool stepperUpdated(const std::vector<std::string> &result, uint8_t index);
int PortFD { -1 };
bool setupComplete { false };
Connection::Serial *serialConnection { nullptr };
////////////////////////////////////////////////////////////////////////////////////
/// Main Control
////////////////////////////////////////////////////////////////////////////////////
/// Reboot Device
ISwitch RebootS[1];
ISwitchVectorProperty RebootSP;
// Power Sensors
INumber PowerSensorsN[3];
INumberVectorProperty PowerSensorsNP;
enum
{
SENSOR_VOLTAGE,
SENSOR_CURRENT,
SENSOR_POWER,
};
// Power Consumption
INumber PowerConsumptionN[3];
INumberVectorProperty PowerConsumptionNP;
enum
{
CONSUMPTION_AVG_AMPS,
CONSUMPTION_AMP_HOURS,
CONSUMPTION_WATT_HOURS,
};
////////////////////////////////////////////////////////////////////////////////////
/// Power Group
////////////////////////////////////////////////////////////////////////////////////
// Cycle all power on/off
ISwitch PowerCycleAllS[2];
ISwitchVectorProperty PowerCycleAllSP;
enum
{
POWER_CYCLE_OFF,
POWER_CYCLE_ON,
};
// Turn on/off power
ISwitch PowerControlS[4];
ISwitchVectorProperty PowerControlSP;
// Rename the power controls above
IText PowerControlsLabelsT[4] = {};
ITextVectorProperty PowerControlsLabelsTP;
// Current Draw
INumber PowerCurrentN[4];
INumberVectorProperty PowerCurrentNP;
// Select which power is ON on bootup
ISwitch PowerOnBootS[4];
ISwitchVectorProperty PowerOnBootSP;
// Overcurrent status
ILight OverCurrentL[7];
ILightVectorProperty OverCurrentLP;
// Power LED
ISwitch PowerLEDS[2];
ISwitchVectorProperty PowerLEDSP;
enum
{
POWER_LED_ON,
POWER_LED_OFF,
};
// Adjustable Output
INumber AdjustableOutputN[1];
INumberVectorProperty AdjustableOutputNP;
////////////////////////////////////////////////////////////////////////////////////
/// Dew Group
////////////////////////////////////////////////////////////////////////////////////
// Auto Dew v1
ISwitch AutoDewS[2];
ISwitchVectorProperty AutoDewSP;
enum
{
DEW_PWM_A,
DEW_PWM_B,
DEW_PWM_C,
};
// Auto Dew v2
ISwitch AutoDewV2S[3];
ISwitchVectorProperty AutoDewV2SP;
// Rename the power controls above
IText DewControlsLabelsT[3] = {};
ITextVectorProperty DewControlsLabelsTP;
// Auto Dew v2 Aggressiveness
enum
{
AUTO_DEW_AGG,
};
INumber AutoDewAggN[1];
INumberVectorProperty AutoDewAggNP;
// Dew PWM
INumber DewPWMN[3];
INumberVectorProperty DewPWMNP;
// Current Draw
INumber DewCurrentDrawN[3];
INumberVectorProperty DewCurrentDrawNP;
////////////////////////////////////////////////////////////////////////////////////
/// USB
////////////////////////////////////////////////////////////////////////////////////
// Turn on/off usb ports 1-5 (v1)
ISwitch USBControlS[2];
ISwitchVectorProperty USBControlSP;
// Turn on/off usb ports 1-6 (v2)
ISwitch USBControlV2S[6];
ISwitchVectorProperty USBControlV2SP;
// USB Port Status (1-6)
ILight USBStatusL[6];
ILightVectorProperty USBStatusLP;
// Rename the USB controls above
IText USBControlsLabelsT[6] = {};
ITextVectorProperty USBControlsLabelsTP;
////////////////////////////////////////////////////////////////////////////////////
/// Focuser
////////////////////////////////////////////////////////////////////////////////////
// Focuser speed
INumber FocuserSettingsN[1];
INumberVectorProperty FocuserSettingsNP;
enum
{
//SETTING_BACKLASH,
SETTING_MAX_SPEED,
};
////////////////////////////////////////////////////////////////////////////////////
/// USB
////////////////////////////////////////////////////////////////////////////////////
ITextVectorProperty FirmwareTP;
IText FirmwareT[2] {};
enum
{
FIRMWARE_VERSION,
FIRMWARE_UPTIME
};
std::vector<std::string> lastSensorData, lastPowerData, lastStepperData, lastDewAggData;
bool focusMotorRunning { false };
char stopChar { 0xD };
uint8_t version { UPB_V1 };
static constexpr const uint8_t PEGASUS_TIMEOUT {3};
static constexpr const uint8_t PEGASUS_LEN {128};
static constexpr const char *DEW_TAB {"Dew"};
static constexpr const char *USB_TAB {"USB"};
static constexpr const char *ENVIRONMENT_TAB {"Environment"};
static constexpr const char *POWER_TAB {"Power"};
static constexpr const char *FIRMWARE_TAB {"Firmware"};
};