Instrument Neutral Distributed Interface INDI  1.9.2
pegasus_ppb.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3 
4  Pegasus Pocket Power Box
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 
30 #include <vector>
31 #include <stdint.h>
32 
33 namespace Connection
34 {
35 class Serial;
36 }
37 
39 {
40  public:
41  PegasusPPB();
42 
43  virtual bool initProperties() override;
44  virtual bool updateProperties() override;
45 
46  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
47  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
48 
49  protected:
50  const char *getDefaultName() override;
51  virtual bool saveConfigItems(FILE *fp) override;
52 
53  // Event loop
54  virtual void TimerHit() override;
55 
56  // Weather Overrides
57  virtual IPState updateWeather() override
58  {
59  return IPS_OK;
60  }
61 
62 
63  private:
64  bool Handshake();
65 
66  // Get Data
67  bool sendFirmware();
68  bool getSensorData();
69  std::vector<std::string> split(const std::string &input, const std::string &regex);
70  enum
71  {
72  PA_NAME,
73  PA_VOLTAGE,
74  PA_CURRENT,
75  PA_TEMPERATURE,
76  PA_HUMIDITY,
77  PA_DEW_POINT,
78  PA_PORT_STATUS,
79  PA_DSLR_STATUS,
80  PA_DEW_1,
81  PA_DEW_2,
82  PA_AUTO_DEW,
83  PA_N,
84  };
85 
86  // Device Control
87  bool reboot();
88 
89  // Power
90  bool setPowerEnabled(uint8_t port, bool enabled);
91  bool setPowerOnBoot();
92 
93  // Dew
94  bool setAutoDewEnabled(bool enabled);
95  bool setDewPWM(uint8_t id, uint8_t value);
96 
103  bool sendCommand(const char *cmd, char *res);
104 
105  int PortFD { -1 };
106  bool setupComplete { false };
107 
108  Connection::Serial *serialConnection { nullptr };
109 
114  ISwitch RebootS[1];
115  ISwitchVectorProperty RebootSP;
116 
117  // Power Sensors
118  INumber PowerSensorsN[2];
119  INumberVectorProperty PowerSensorsNP;
120  enum
121  {
122  SENSOR_VOLTAGE,
123  SENSOR_CURRENT,
124  };
125 
129 
130  // Cycle all power on/off
131  ISwitch PowerCycleAllS[2];
132  ISwitchVectorProperty PowerCycleAllSP;
133  enum
134  {
135  POWER_CYCLE_OFF,
136  POWER_CYCLE_ON,
137  };
138 
139  ISwitch DSLRPowerS[2];
140  ISwitchVectorProperty DSLRPowerSP;
141  enum
142  {
143  DSLR_OFF,
144  DSLR_ON,
145  };
146 
147  // Select which power is ON on bootup
148  ISwitch PowerOnBootS[4];
149  ISwitchVectorProperty PowerOnBootSP;
150 
154 
155  // Auto Dew
156  ISwitch AutoDewS[2];
157  ISwitchVectorProperty AutoDewSP;
158 
159  // Dew PWM
160  INumber DewPWMN[2];
161  INumberVectorProperty DewPWMNP;
162  enum
163  {
164  DEW_PWM_A,
165  DEW_PWM_B,
166  };
167 
168  std::vector<std::string> lastSensorData;
169  char stopChar { 0xD };
170 
171  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
172  static constexpr const uint8_t PEGASUS_LEN {128};
173  static constexpr const char *DEW_TAB {"Dew"};
174  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
175 };
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
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
PegasusPPB::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: pegasus_ppb.cpp:224
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
PegasusPPB
Definition: pegasus_ppb.h:38
PegasusPPB::PegasusPPB
PegasusPPB()
Definition: pegasus_ppb.cpp:38
PegasusPPB::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: pegasus_ppb.cpp:44
defaultdevice.h
PegasusPPB::updateWeather
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: pegasus_ppb.h:57
PegasusPPB::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: pegasus_ppb.cpp:415
PegasusPPB::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: pegasus_ppb.cpp:307
PegasusPPB::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: pegasus_ppb.cpp:128
Connection
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:33
PegasusPPB::getDefaultName
const char * getDefaultName() override
Definition: pegasus_ppb.cpp:170
indiweatherinterface.h
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::WeatherInterface
Provides interface to implement weather reporting functionality.
Definition: indiweatherinterface.h:55
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
PegasusPPB::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: pegasus_ppb.cpp:424