Instrument Neutral Distributed Interface INDI  2.0.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 
142  // Select which power is ON on bootup
143  ISwitch PowerOnBootS[4];
144  ISwitchVectorProperty PowerOnBootSP;
145 
149 
150  // Auto Dew
151  ISwitch AutoDewS[2];
152  ISwitchVectorProperty AutoDewSP;
153 
154  // Dew PWM
155  INumber DewPWMN[2];
156  INumberVectorProperty DewPWMNP;
157  enum
158  {
159  DEW_PWM_A,
160  DEW_PWM_B,
161  };
162 
163  std::vector<std::string> lastSensorData;
164  char stopChar { 0xD };
165 
166  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
167  static constexpr const uint8_t PEGASUS_LEN {128};
168  static constexpr const char *DEW_TAB {"Dew"};
169  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
170 };
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 weather reporting functionality.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: pegasus_ppb.h:57
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
const char * getDefaultName() override
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, 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_ppb.cpp:44
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
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 number descriptor.
One switch descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367