Instrument Neutral Distributed Interface INDI  2.0.2
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"
28 #include "indifocuserinterface.h"
29 #include "indiweatherinterface.h"
30 #include <stdint.h>
31 
32 namespace Connection
33 {
34 class Serial;
35 }
36 
38 {
39  public:
40  PegasusUPB();
41 
42  enum
43  {
45  UPB_V2
46  };
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 
69  virtual bool SetFocuserBacklash(int32_t steps) override;
70  virtual bool SetFocuserBacklashEnabled(bool enabled) override;
71 
72  // Weather Overrides
73  virtual IPState updateWeather() override
74  {
75  return IPS_OK;
76  }
77 
78 
79  private:
80  bool Handshake();
81 
82  // Get Data
83  bool setupParams();
84  bool sendFirmware();
85  bool getSensorData();
86  bool getPowerData();
87  bool getStepperData();
88  bool getDewAggData();
89  std::vector<std::string> split(const std::string &input, const std::string &regex);
90 
91  // Device Control
92  bool reboot();
93 
94  // Power
95  bool setPowerEnabled(uint8_t port, bool enabled);
96  bool setPowerLEDEnabled(bool enabled);
97  bool setPowerOnBoot();
98  bool getPowerOnBoot();
99  bool setAdjustableOutput(uint8_t voltage);
100 
101  // Dew
102  bool setAutoDewEnabled(bool enabled);
103  bool toggleAutoDewV2();
104  bool setAutoDewAgg(uint8_t value);
105  bool setDewPWM(uint8_t id, uint8_t value);
106 
107  // USB
108  bool setUSBHubEnabled(bool enabled);
109  bool setUSBPortEnabled(uint8_t port, bool enabled);
110 
111  // Focuser
112  bool setFocuserMaxSpeed(uint16_t maxSpeed);
113  // bool setFocuserBacklash(uint16_t value);
114  // bool setFocuserBacklashEnabled(bool enabled);
115 
122  bool sendCommand(const char *cmd, char *res);
123 
128  void cleanupResponse(char *response);
129 
136  bool sensorUpdated(const std::vector<std::string> &result, uint8_t start, uint8_t end);
137 
144  bool stepperUpdated(const std::vector<std::string> &result, u_int8_t index);
145 
146  int PortFD { -1 };
147  bool setupComplete { false };
148 
149  Connection::Serial *serialConnection { nullptr };
150 
155  ISwitch RebootS[1];
156  ISwitchVectorProperty RebootSP;
157 
158  // Power Sensors
159  INumber PowerSensorsN[3];
160  INumberVectorProperty PowerSensorsNP;
161  enum
162  {
163  SENSOR_VOLTAGE,
164  SENSOR_CURRENT,
165  SENSOR_POWER,
166  };
167 
168  // Power Consumption
169  INumber PowerConsumptionN[3];
170  INumberVectorProperty PowerConsumptionNP;
171  enum
172  {
173  CONSUMPTION_AVG_AMPS,
174  CONSUMPTION_AMP_HOURS,
175  CONSUMPTION_WATT_HOURS,
176  };
177 
181 
182  // Cycle all power on/off
183  ISwitch PowerCycleAllS[2];
184  ISwitchVectorProperty PowerCycleAllSP;
185  enum
186  {
187  POWER_CYCLE_OFF,
188  POWER_CYCLE_ON,
189  };
190 
191  // Turn on/off power
192  ISwitch PowerControlS[4];
193  ISwitchVectorProperty PowerControlSP;
194 
195  // Rename the power controls above
196  IText PowerControlsLabelsT[4] = {};
197  ITextVectorProperty PowerControlsLabelsTP;
198 
199  // Current Draw
200  INumber PowerCurrentN[4];
201  INumberVectorProperty PowerCurrentNP;
202 
203  // Select which power is ON on bootup
204  ISwitch PowerOnBootS[4];
205  ISwitchVectorProperty PowerOnBootSP;
206 
207  // Overcurrent status
208  ILight OverCurrentL[7];
209  ILightVectorProperty OverCurrentLP;
210 
211  // Power LED
212  ISwitch PowerLEDS[2];
213  ISwitchVectorProperty PowerLEDSP;
214  enum
215  {
216  POWER_LED_ON,
217  POWER_LED_OFF,
218  };
219 
220  // Adjustable Output
221  INumber AdjustableOutputN[1];
222  INumberVectorProperty AdjustableOutputNP;
223 
227 
228  // Auto Dew v1
229  ISwitch AutoDewS[2];
230  ISwitchVectorProperty AutoDewSP;
231 
232  enum
233  {
234  DEW_PWM_A,
235  DEW_PWM_B,
236  DEW_PWM_C,
237  };
238 
239  // Auto Dew v2
240  ISwitch AutoDewV2S[3];
241  ISwitchVectorProperty AutoDewV2SP;
242 
243  // Rename the power controls above
244  IText DewControlsLabelsT[3] = {};
245  ITextVectorProperty DewControlsLabelsTP;
246 
247  // Auto Dew v2 Aggressiveness
248 
249  enum
250  {
251  AUTO_DEW_AGG,
252  };
253 
254  INumber AutoDewAggN[1];
255  INumberVectorProperty AutoDewAggNP;
256 
257  // Dew PWM
258  INumber DewPWMN[3];
259  INumberVectorProperty DewPWMNP;
260 
261  // Current Draw
262  INumber DewCurrentDrawN[3];
263  INumberVectorProperty DewCurrentDrawNP;
264 
268 
269  // Turn on/off usb ports 1-5 (v1)
270  ISwitch USBControlS[2];
271  ISwitchVectorProperty USBControlSP;
272 
273  // Turn on/off usb ports 1-6 (v2)
274  ISwitch USBControlV2S[6];
275  ISwitchVectorProperty USBControlV2SP;
276 
277  // USB Port Status (1-6)
278  ILight USBStatusL[6];
279  ILightVectorProperty USBStatusLP;
280 
281  // Rename the USB controls above
282  IText USBControlsLabelsT[6] = {};
283  ITextVectorProperty USBControlsLabelsTP;
284 
288 
289  // Focuser speed
290  INumber FocuserSettingsN[1];
291  INumberVectorProperty FocuserSettingsNP;
292  enum
293  {
294  //SETTING_BACKLASH,
295  SETTING_MAX_SPEED,
296  };
297 
301  ITextVectorProperty FirmwareTP;
302  IText FirmwareT[2] {};
303  enum
304  {
305  FIRMWARE_VERSION,
306  FIRMWARE_UPTIME
307  };
308 
309 
310  std::vector<std::string> lastSensorData, lastPowerData, lastStepperData, lastDewAggData;
311  bool focusMotorRunning { false };
312  char stopChar { 0xD };
313  uint8_t version { UPB_V1 };
314 
315  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
316  static constexpr const uint8_t PEGASUS_LEN {128};
317  static constexpr const char *DEW_TAB {"Dew"};
318  static constexpr const char *USB_TAB {"USB"};
319  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
320  static constexpr const char *POWER_TAB {"Power"};
321  static constexpr const char *FIRMWARE_TAB {"Firmware"};
322 };
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 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
Initilize properties initial state and value. The child class must implement this function.
Definition: pegasus_upb.cpp:51
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 SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
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 IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: pegasus_upb.h:73
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:150
IPState
Property state.
Definition: indiapi.h:160
@ IPS_OK
Definition: indiapi.h:162
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One light descriptor.
One number descriptor.
One switch descriptor.
One text descriptor.
Light vector property descriptor.
Definition: indiapi.h:417
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246