Instrument Neutral Distributed Interface INDI  1.9.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"
28 #include "indiweatherinterface.h"
29 #include "indifocuserinterface.h"
30 
31 #include <vector>
32 #include <stdint.h>
33 
34 namespace Connection
35 {
36 class Serial;
37 }
38 
40 {
41  public:
42  PegasusPPBA();
43 
44  virtual bool initProperties() override;
45  virtual bool updateProperties() override;
46 
47  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
48  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
49 
50  protected:
51  const char *getDefaultName() override;
52  virtual bool saveConfigItems(FILE *fp) override;
53 
54  // Event loop
55  virtual void TimerHit() override;
56 
57  // Focuser Overrides
58  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
59  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
60  virtual bool AbortFocuser() override;
61  virtual bool ReverseFocuser(bool enabled) override;
62  virtual bool SyncFocuser(uint32_t ticks) override;
63 
64  virtual bool SetFocuserBacklash(int32_t steps) override;
65  virtual bool SetFocuserBacklashEnabled(bool enabled) override;
66 
67  // Weather Overrides
68  virtual IPState updateWeather() override
69  {
70  return IPS_OK;
71  }
72 
73 
74  private:
75  bool Handshake();
76 
77  // Get Data
78  bool sendFirmware();
79  bool getSensorData();
80  bool getConsumptionData();
81  bool getMetricsData();
82  bool findExternalMotorController();
83  bool getXMCStartupData();
84  std::vector<std::string> split(const std::string &input, const std::string &regex);
85  enum
86  {
87  PA_NAME,
88  PA_VOLTAGE,
89  PA_CURRENT,
90  PA_TEMPERATURE,
91  PA_HUMIDITY,
92  PA_DEW_POINT,
93  PA_PORT_STATUS,
94  PA_ADJ_STATUS,
95  PA_DEW_1,
96  PA_DEW_2,
97  PA_AUTO_DEW,
98  PA_PWR_WARN,
99  PA_PWRADJ,
100  PA_N,
101  };
102  enum
103  {
104  PS_NAME,
105  PS_AVG_AMPS,
106  PS_AMP_HOURS,
107  PS_WATT_HOURS,
108  PS_UPTIME,
109  PS_N,
110  };
111  enum
112  {
113  PC_NAME,
114  PC_TOTAL_CURRENT,
115  PC_12V_CURRENT,
116  PC_DEWA_CURRENT,
117  PC_DEWB_CURRENT,
118  PC_UPTIME,
119  PC_N,
120  };
121 
122  // Device Control
123  bool reboot();
124 
125  // Power
126  bool setPowerEnabled(uint8_t port, bool enabled);
127  bool setPowerOnBoot();
128 
129  // Dew
130  bool setAutoDewEnabled(bool enabled);
131  bool setDewPWM(uint8_t id, uint8_t value);
132 
133  // Focuser
134  void queryXMC();
135  bool setFocuserMaxSpeed(uint16_t maxSpeed);
136  bool setFocuserMicrosteps(int value);
137 
144  bool sendCommand(const char *cmd, char *res);
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[9];
160  INumberVectorProperty PowerSensorsNP;
161  enum
162  {
163  SENSOR_VOLTAGE,
164  SENSOR_CURRENT,
165  SENSOR_AVG_AMPS,
166  SENSOR_AMP_HOURS,
167  SENSOR_WATT_HOURS,
168  SENSOR_TOTAL_CURRENT,
169  SENSOR_12V_CURRENT,
170  SENSOR_DEWA_CURRENT,
171  SENSOR_DEWB_CURRENT
172  };
173 
177 
178  ISwitch QuadOutS[2];
179  ISwitchVectorProperty QuadOutSP;
180 
181  // ISwitch AdjOutS[2];
182  // ISwitchVectorProperty AdjOutSP;
183 
184  ISwitch AdjOutVoltS[6];
185  ISwitchVectorProperty AdjOutVoltSP;
186  enum
187  {
188  ADJOUT_OFF,
189  ADJOUT_3V,
190  ADJOUT_5V,
191  ADJOUT_8V,
192  ADJOUT_9V,
193  ADJOUT_12V,
194  };
195 
196  // Select which power is ON on bootup
197  ISwitch PowerOnBootS[4];
198  ISwitchVectorProperty PowerOnBootSP;
199 
200  // Short circuit warn
201  ILight PowerWarnL[1];
202  ILightVectorProperty PowerWarnLP;
203 
204  ISwitch LedIndicatorS[2];
205  ISwitchVectorProperty LedIndicatorSP;
206 
210 
211  // Auto Dew
212  ISwitch AutoDewS[2];
213  ISwitchVectorProperty AutoDewSP;
214 
215  // Dew PWM
216  INumber DewPWMN[2];
217  INumberVectorProperty DewPWMNP;
218  enum
219  {
220  DEW_PWM_A,
221  DEW_PWM_B,
222  };
223 
227 
228  // Focuser speed
229  INumber FocuserSettingsN[1];
230  INumberVectorProperty FocuserSettingsNP;
231  enum
232  {
233  SETTING_MAX_SPEED,
234  };
235 
236  // Microstepping
237  ISwitchVectorProperty FocuserDriveSP;
238  ISwitch FocuserDriveS[4];
239  enum
240  {
241  STEP_FULL,
242  STEP_HALF,
243  STEP_FORTH,
244  STEP_EIGHTH
245  };
246 
247 
248 
252 
253  ITextVectorProperty FirmwareTP;
254  IText FirmwareT[2] {};
255  enum
256  {
257  FIRMWARE_VERSION,
258  FIRMWARE_UPTIME,
259  };
260 
261  std::vector<std::string> lastSensorData;
262  std::vector<std::string> lastConsumptionData;
263  std::vector<std::string> lastMetricsData;
264  char stopChar { 0xD };
265  bool m_HasExternalMotor { false };
266 
267  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
268  static constexpr const uint8_t PEGASUS_LEN {128};
269  static constexpr const char *DEW_TAB {"Dew"};
270  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
271  static constexpr const char *FIRMWARE_TAB {"Firmware"};
272 };
PegasusPPBA::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: pegasus_ppba.cpp:844
PegasusPPBA::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: pegasus_ppba.cpp:870
PegasusPPBA::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: pegasus_ppba.cpp:854
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
IPState
IPState
Property state.
Definition: indiapi.h:158
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
INDI::FocuserInterface
Provides interface to implement focuser functionality.
Definition: indifocuserinterface.h:63
PegasusPPBA::updateWeather
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: pegasus_ppba.h:68
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
ILight
One light descriptor.
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
indifocuserinterface.h
IText
One text descriptor.
PegasusPPBA
Definition: pegasus_ppba.h:39
PegasusPPBA::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: pegasus_ppba.cpp:880
PegasusPPBA::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: pegasus_ppba.cpp:638
defaultdevice.h
PegasusPPBA::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: pegasus_ppba.cpp:862
PegasusPPBA::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: pegasus_ppba.cpp:624
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
indiweatherinterface.h
PegasusPPBA::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: pegasus_ppba.cpp:45
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
PegasusPPBA::PegasusPPBA
PegasusPPBA()
Definition: pegasus_ppba.cpp:37
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::WeatherInterface
Provides interface to implement weather reporting functionality.
Definition: indiweatherinterface.h:55
PegasusPPBA::getDefaultName
const char * getDefaultName() override
Definition: pegasus_ppba.cpp:266
PegasusPPBA::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: pegasus_ppba.cpp:320
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
PegasusPPBA::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: pegasus_ppba.cpp:189
PegasusPPBA::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: pegasus_ppba.cpp:486
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
PegasusPPBA::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: pegasus_ppba.cpp:890
PegasusPPBA::SetFocuserBacklashEnabled
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
Definition: pegasus_ppba.cpp:917