Instrument Neutral Distributed Interface INDI 2.2.5
svbony_powerbox.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 Tetsuya Kakura. All rights reserved.
3
4 SVBONYPowerBox
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 "indipowerinterface.h"
29
30#include <vector>
31#include <stdint.h>
32
33#include "basedevice.h"
34
35namespace Connection
36{
37class Serial;
38}
39
41{
42 public:
44 public:
45 virtual ~SVBONYPowerBox() = default;
46 virtual bool initProperties() override;
47 virtual bool updateProperties() override;
48 virtual void TimerHit() 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 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
52
53 protected:
54 virtual const char *getDefaultName() override;
55 virtual bool saveConfigItems(FILE *fp) override;
56
57 // Implement virtual methods from INDI::PowerInterface
58 virtual bool SetPowerPort(size_t port, bool enabled) override;
59 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
60 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
61 virtual bool SetLEDEnabled(bool enabled) override;
62 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
63 virtual bool CyclePower() override;
64 virtual bool SetUSBPort(size_t port, bool enabled) override;
65
66 private:
67 bool Handshake();
68 bool sendCommand(const unsigned char* cmd, unsigned int cmd_len, unsigned char* res, int res_len);
69 int PortFD{-1};
70
71 bool setupComplete { false };
72 bool processButtonSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
73
74 void Get_State();
75
76 static double convert4BytesToDouble(const unsigned char* data, double scale);
77
78 // Dew point calculation helpers
79 static double CalculateSVP(double temperature);
80 static double CalculateVP(double humidity, double svp);
81 static double CalculateDewPointFromVP(double vp);
82
83 // Weather Sensors Indices
84 enum
85 {
86 SVB_SENSOR_DS18B20_TEMP,
87 SVB_SENSOR_SHT40_TEMP,
88 SVB_SENSOR_SHT40_HUMIDITY,
89 SVB_SENSOR_DEW_POINT,
90 N_SVB_WEATHER_SENSORS
91 };
92 // Main Control - Overall Weather Sensors
93 INDI::PropertyNumber WeatherSVBSensorsNP {N_SVB_WEATHER_SENSORS};
94
95 Connection::Serial *serialConnection { nullptr };
96};
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...
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual ~SVBONYPowerBox()=default
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
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 void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual const char * getDefaultName() override
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.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool SetPowerPort(size_t port, bool enabled) override
SetPowerPort Set power port on/off.
ISState
Switch state.
Definition indiapi.h:148
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