Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_spb.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2023 Efstathios Chrysikos. 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"
29#include "indipowerinterface.h"
30
31#include <vector>
32#include <stdint.h>
33
34namespace Connection
35{
36class Serial;
37}
38
40{
41
42 public:
43 PegasusSPB();
44
45 virtual bool initProperties() override;
46 virtual bool updateProperties() override;
47
48 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
49 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
50 virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n) override;
51
53 {
54 DEW = 0,
56 };
57 enum
58 {
73 };
74 enum
75 {
82 };
83 enum
84 {
92 };
93 enum
94 {
99 };
100 protected:
101 const char *getDefaultName() override;
102 virtual bool saveConfigItems(FILE *fp) override;
103 virtual void TimerHit() override;
104
105 virtual bool SetPowerPort(size_t port, bool enabled) override;
106 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
107 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
108 virtual bool SetLEDEnabled(bool enabled) override;
109 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
110 virtual bool SetUSBPort(size_t port, bool enabled) override;
111
112 // Weather Overrides
113 virtual IPState updateWeather() override
114 {
115 return IPS_OK;
116 }
117
118 private:
119 bool Handshake();
120
121 bool sendCommand(const char *cmd, char *res);
122 bool setFixedPowerPortState(int portNumber, bool enabled);
123 bool setPowerDewPortMode(int portNumber, int mode);
124 int getPowerDewPortMode(int portNumber);
125 bool setDewPortPower(int portNumber, double power);
126 bool setDewAutoState(bool enabled);
127 bool setDewAggressiveness(uint8_t level);
128 bool getDewAggressiveness(int &level);
129 bool setHumdityOffset(int level);
130 bool getOffsets(int &temperature, int &humidity);
131 bool setTemperatureOffset(int level);
132 void updatePortMode(INDI::PropertySwitch &property, int mode);
133 bool getFirmware();
134 bool getSensorData();
135 bool getConsumptionData();
136 bool getMetricsData();
137
138 int PortFD { -1 };
139 bool setupComplete { false };
140 Connection::Serial *serialConnection { nullptr };
141
142 std::vector<std::string> split(const std::string &input, const std::string &regex);
143 std::vector<std::string> lastSensorData;
144 std::vector<std::string> lastConsumptionData;
145 std::vector<std::string> lastMetricsData;
146 // Duty cycles set before auto dew started, shown again when it is switched off.
147 double m_ManualDutyCycle[2] {0, 0};
148 bool m_AutoDewShown { false };
149 char stopChar { 0xD };
150 static constexpr const uint8_t PEGASUS_TIMEOUT {3};
151 static constexpr const uint8_t PEGASUS_LEN {128};
152 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
153 static constexpr const char *FIRMWARE_TAB {"Firmware"};
154 double map(double value, double from1, double to1, double from2, double to2);
155
159 // Power Statistics
160 INDI::PropertyNumber PowerStatisticsNP {4};
161 enum
162 {
163 STATS_AVG_AMPS,
164 STATS_AMP_HOURS,
165 STATS_WATT_HOURS,
166 STATS_TOTAL_CURRENT
167 };
168
172 INDI::PropertySwitch PowerDewSwitchASP {2};
173 INDI::PropertySwitch PowerDewSwitchBSP {2};
174 INDI::PropertyNumber DewAggressNP {1};
175
179 INDI::PropertyNumber HumidityOffsetNP {1};
180 INDI::PropertyNumber TemperatureOffsetNP {1};
181
185
186 INDI::PropertyText FirmwareTP {2};
187 enum
188 {
189 FIRMWARE_VERSION,
190 FIRMWARE_UPTIME,
191 };
192};
double humidity
double temperature
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 and safety monitoring functionality.
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
Initialize properties initial state and value. The child class must implement this function.
@ SENSOR_WATT_HOURS
Definition pegasus_spb.h:97
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool SetPowerPort(size_t port, bool enabled) override
Power Interface Implementations.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
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 SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_OK
Definition indiapi.h:160
*brief user defined string literal for JSON values *sa std::size_t n
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34
uint8_t cmd[4]
Definition pwc-ioctl.h:2