Instrument Neutral Distributed Interface INDI  1.9.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"
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  {
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 
133  bool sensorUpdated(const std::vector<std::string> &result, uint8_t start, uint8_t end);
134 
135  int PortFD { -1 };
136  bool setupComplete { false };
137 
138  Connection::Serial *serialConnection { nullptr };
139 
144  ISwitch RebootS[1];
145  ISwitchVectorProperty RebootSP;
146 
147  // Power Sensors
148  INumber PowerSensorsN[3];
149  INumberVectorProperty PowerSensorsNP;
150  enum
151  {
152  SENSOR_VOLTAGE,
153  SENSOR_CURRENT,
154  SENSOR_POWER,
155  };
156 
157  // Power Consumption
158  INumber PowerConsumptionN[3];
159  INumberVectorProperty PowerConsumptionNP;
160  enum
161  {
162  CONSUMPTION_AVG_AMPS,
163  CONSUMPTION_AMP_HOURS,
164  CONSUMPTION_WATT_HOURS,
165  };
166 
170 
171  // Cycle all power on/off
172  ISwitch PowerCycleAllS[2];
173  ISwitchVectorProperty PowerCycleAllSP;
174  enum
175  {
176  POWER_CYCLE_OFF,
177  POWER_CYCLE_ON,
178  };
179 
180  // Turn on/off power
181  ISwitch PowerControlS[4];
182  ISwitchVectorProperty PowerControlSP;
183 
184  // Rename the power controls above
185  IText PowerControlsLabelsT[4] = {};
186  ITextVectorProperty PowerControlsLabelsTP;
187 
188  // Current Draw
189  INumber PowerCurrentN[4];
190  INumberVectorProperty PowerCurrentNP;
191 
192  // Select which power is ON on bootup
193  ISwitch PowerOnBootS[4];
194  ISwitchVectorProperty PowerOnBootSP;
195 
196  // Overcurrent status
197  ILight OverCurrentL[7];
198  ILightVectorProperty OverCurrentLP;
199 
200  // Power LED
201  ISwitch PowerLEDS[2];
202  ISwitchVectorProperty PowerLEDSP;
203  enum
204  {
205  POWER_LED_ON,
206  POWER_LED_OFF,
207  };
208 
209  // Adjustable Output
210  INumber AdjustableOutputN[1];
211  INumberVectorProperty AdjustableOutputNP;
212 
216 
217  // Auto Dew v1
218  ISwitch AutoDewS[2];
219  ISwitchVectorProperty AutoDewSP;
220 
221  enum
222  {
223  DEW_PWM_A,
224  DEW_PWM_B,
225  DEW_PWM_C,
226  };
227 
228  // Auto Dew v2
229  ISwitch AutoDewV2S[3];
230  ISwitchVectorProperty AutoDewV2SP;
231 
232  // Rename the power controls above
233  IText DewControlsLabelsT[3] = {};
234  ITextVectorProperty DewControlsLabelsTP;
235 
236  // Auto Dew v2 Aggressiveness
237 
238  enum
239  {
240  AUTO_DEW_AGG,
241  };
242 
243  INumber AutoDewAggN[1];
244  INumberVectorProperty AutoDewAggNP;
245 
246  // Dew PWM
247  INumber DewPWMN[3];
248  INumberVectorProperty DewPWMNP;
249 
250  // Current Draw
251  INumber DewCurrentDrawN[3];
252  INumberVectorProperty DewCurrentDrawNP;
253 
257 
258  // Turn on/off usb ports 1-5 (v1)
259  ISwitch USBControlS[2];
260  ISwitchVectorProperty USBControlSP;
261 
262  // Turn on/off usb ports 1-6 (v2)
263  ISwitch USBControlV2S[6];
264  ISwitchVectorProperty USBControlV2SP;
265 
266  // USB Port Status (1-6)
267  ILight USBStatusL[6];
268  ILightVectorProperty USBStatusLP;
269 
270  // Rename the USB controls above
271  IText USBControlsLabelsT[6] = {};
272  ITextVectorProperty USBControlsLabelsTP;
273 
277 
278  // Focuser speed
279  INumber FocuserSettingsN[1];
280  INumberVectorProperty FocuserSettingsNP;
281  enum
282  {
283  //SETTING_BACKLASH,
284  SETTING_MAX_SPEED,
285  };
286 
290  ITextVectorProperty FirmwareTP;
291  IText FirmwareT[2] {};
292  enum
293  {
294  FIRMWARE_VERSION,
295  FIRMWARE_UPTIME
296  };
297 
298 
299  std::vector<std::string> lastSensorData, lastPowerData, lastStepperData, lastDewAggData;
300  bool focusMotorRunning { false };
301  char stopChar { 0xD };
302  uint8_t version { UPB_V1 };
303 
304  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
305  static constexpr const uint8_t PEGASUS_LEN {128};
306  static constexpr const char *DEW_TAB {"Dew"};
307  static constexpr const char *USB_TAB {"USB"};
308  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
309  static constexpr const char *POWER_TAB {"Power"};
310  static constexpr const char *FIRMWARE_TAB {"Firmware"};
311 };
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
PegasusUPB::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: pegasus_upb.cpp:1281
IPState
IPState
Property state.
Definition: indiapi.h:158
PegasusUPB::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: pegasus_upb.cpp:997
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
ISwitch
One switch descriptor.
INumber
One number descriptor.
Connection::Serial
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Definition: connectionserial.h:56
PegasusUPB::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: pegasus_upb.cpp:358
INDI::FocuserInterface
Provides interface to implement focuser functionality.
Definition: indifocuserinterface.h:63
PegasusUPB::getDefaultName
const char * getDefaultName() override
Definition: pegasus_upb.cpp:476
PegasusUPB::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: pegasus_upb.cpp:859
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
PegasusUPB::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: pegasus_upb.cpp:1302
ILight
One light descriptor.
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
PegasusUPB::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: pegasus_upb.cpp:1005
indifocuserinterface.h
PegasusUPB::UPB_V1
@ UPB_V1
Definition: pegasus_upb.h:44
IText
One text descriptor.
PegasusUPB
Definition: pegasus_upb.h:37
PegasusUPB::PegasusUPB
PegasusUPB()
Definition: pegasus_upb.cpp:41
defaultdevice.h
end
JsonIterator end(JsonValue)
Definition: gason.h:108
PegasusUPB::updateWeather
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: pegasus_upb.h:73
PegasusUPB::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: pegasus_upb.cpp:1034
Connection
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:33
name
const char * name
Definition: indiserver.c:116
PegasusUPB::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: pegasus_upb.cpp:982
indiweatherinterface.h
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
PegasusUPB::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: pegasus_upb.cpp:773
PegasusUPB::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: pegasus_upb.cpp:51
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::WeatherInterface
Provides interface to implement weather reporting functionality.
Definition: indiweatherinterface.h:55
PegasusUPB::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: pegasus_upb.cpp:1019
PegasusUPB::SetFocuserBacklashEnabled
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
Definition: pegasus_upb.cpp:1064
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
PegasusUPB::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: pegasus_upb.cpp:549
PegasusUPB::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: pegasus_upb.cpp:1044
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
PegasusUPB::UPB_V2
@ UPB_V2
Definition: pegasus_upb.h:45