Instrument Neutral Distributed Interface INDI 2.2.5
celestron_dewpower.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2026 Jasem Mutlaq. All rights reserved.
3
4 Celestron Smart Dew & Power Controller.
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 "indibase.h"
28#include "defaultdevice.h"
29#include "indipowerinterface.h"
32
34
35#include <vector>
36#include <termios.h>
37
39{
40public:
42
43 virtual const char *getDefaultName() override;
44 virtual bool initProperties() override;
45 virtual bool updateProperties() override;
46 virtual bool Handshake();
47 virtual void TimerHit() override;
48
49 // INDI::WeatherInterface overrides
50 virtual IPState updateWeather() override;
51
52 // INDI::PowerInterface overrides
53 virtual bool SetPowerPort(size_t port, bool enabled) override;
54 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
55 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
56 virtual bool SetLEDEnabled(bool enabled) override;
57 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
58
59protected:
60 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
61 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
62 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
63 virtual bool saveConfigItems(FILE *fp) override;
64
65private:
66 Connection::Serial *serialConnection;
67 int PortFD;
68 bool setupComplete {false};
69
70 // AUX Command communication
71 bool sendAUXCommand(AUXCommand &command);
72 bool readAUXResponse(AUXCommand &c);
73 bool serialReadResponse(AUXCommand &c);
74 int sendBuffer(AUXBuffer buf);
75 bool processResponse(AUXCommand &m); // Added processResponse
76
77 // Serial port specific functions
78 bool tty_set_speed(speed_t speed);
79 void hex_dump(char *buf, AUXBuffer data, size_t size);
80 int aux_tty_read(char *buf, int bufsiz, int timeout, int *n);
81 int aux_tty_write(char *buf, int bufsiz, int *n);
82
83 // Device specific commands
84 bool getDewPowerControllerVersion();
85 bool getNumberOfPorts();
86 bool getInputPower();
87 bool getPortInfo(uint8_t portNumber);
88 bool getDewHeaterPortInfo(uint8_t portNumber);
89 bool setPortEnabled(uint8_t portNumber, bool enabled);
90 bool setPortVoltage(uint8_t portNumber, uint16_t voltage_mV);
91 bool setDewHeaterAuto(uint8_t portNumber, uint8_t mode, uint8_t temp_C);
92 bool setDewHeaterManual(uint8_t portNumber, uint8_t powerLevel);
93 bool setLEDBrightness(uint8_t brightness);
94
95 // Internal properties
96 INDI::PropertyNumber PowerConsumptionNP {3}; // Avg. Amps, Amp Hours, Watt Hours
97 INDI::PropertySwitch RebootSP {1};
98 INDI::PropertyLight PowerStatusLP {3};
99 INDI::PropertySwitch AutoDewModeSP {2};
100 INDI::PropertyNumber AutoDewTempNP {1};
101
102 enum
103 {
104 POWER_STATUS_OVERCURRENT,
105 POWER_STATUS_UNDERVOLTAGE,
106 POWER_STATUS_OVERVOLTAGE
107 };
108
109 // Store last received data to avoid unnecessary updates
110 AUXBuffer lastInputPowerData;
111 std::vector<AUXBuffer> lastPortInfoData;
112 std::vector<AUXBuffer> lastDewHeaterPortInfoData;
113 AUXBuffer lastEnvironmentData;
114
115 std::vector<uint8_t> m_PortTypes;
116 uint8_t m_NumPorts {0};
117 uint8_t m_NumDCPorts {0};
118 uint8_t m_NumDewPorts {0};
119 uint8_t m_NumVariablePorts {0};
120 uint8_t m_NumUSBPorts {0};
121
122 // Debug
123 uint32_t DBG_CAUX;
124 uint32_t DBG_SERIAL;
125
126 // Constants
127 // seconds
128 static constexpr uint8_t READ_TIMEOUT {1};
129};
std::vector< uint8_t > AUXBuffer
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual const char * getDefaultName() override
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool SetPowerPort(size_t port, bool enabled) override
SetPowerPort Set power port on/off.
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.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158