Instrument Neutral Distributed Interface INDI 2.2.5
usb_dewpoint.h
Go to the documentation of this file.
1/*
2 USB_Dewpoint
3 Copyright (C) 2017-2023 Jarno Paananen
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20
21#pragma once
22
23#include <defaultdevice.h>
24#include <indipowerinterface.h>
25
26/***************************** USB_Dewpoint Commands **************************/
27
28// All commands are exactly 6 bytes, no start/end markers
29#define UDP_CMD_LEN 6
30#define UDP_STATUS_CMD "SGETAL"
31#define UDP_OUTPUT_CMD "S%1uO%03u" // channel 1-3, power 0-100
32#define UDP_THRESHOLD_CMD "STHR%1u%1u" // channel 1-2, value 0-9
33#define UDP_CALIBRATION_CMD "SCA%1u%1u%1u" // channel 1-2-A, value 0-9
34#define UDP_LINK_CMD "SLINK%1u" // 0 or 1 to link channels 2 and 3
35#define UDP_AUTO_CMD "SAUTO%1u" // 0 or 1 to enable auto mode
36#define UDP_AGGRESSIVITY_CMD "SAGGR%1u" // 1-4 (1, 2, 5, 10)
37#define UDP_IDENTIFY_CMD "SWHOIS"
38#define UDP_RESET_CMD "SEERAZ"
39
40/**************************** USB_Dewpoint Constants **************************/
41
42// Responses also include "\n\r"
43#define UDP_DONE_RESPONSE "DONE"
44#define UDP_RES_LEN 80 // With some margin, maximum feasible seems to be around 70
45
46// Status response is like:
47// ##22.37/22.62/23.35/50.77/12.55/0/0/0/0/0/0/2/2/0/0/4**
48
49// Fields are in order:
50// temperature ch 1
51// temperature ch 2
52// temperature ambient
53// relative humidity
54// dew point
55// output ch 1
56// output ch 2
57// output ch 3
58// calibration ch 1
59// calibration ch 2
60// calibration ambient
61// threshold ch 1
62// threshold ch 2
63// auto mode
64// outputs ch 2 & 3 linked
65// aggressivity
66
67#define UDP_STATUS_RESPONSE "##%f/%f/%f/%f/%f/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u**"
68#define UDP_STATUS_START "##"
69#define UDP_STATUS_SEPARATOR "/"
70#define UDP_STATUS_END "**"
71
72#define UDP_IDENTIFY_RESPONSE "UDP2(%u)" // Firmware version? Mine is "UDP2(1446)"
73
74/******************************************************************************/
75
76namespace Connection
77{
78class Serial;
79};
80
82{
83 public:
85 virtual ~USBDewpoint() = default;
86
87 virtual const char *getDefaultName() override;
88 virtual bool initProperties() override;
89 virtual bool updateProperties() override;
90 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
91 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
92 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
93 virtual void TimerHit() override;
94
95 protected:
96 virtual bool SetPowerPort(size_t port, bool enabled) override;
97 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
98 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
99 virtual bool SetLEDEnabled(bool enabled) override;
100 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
101 virtual bool CyclePower() override;
102 virtual bool SetUSBPort(size_t port, bool enabled) override;
103 virtual bool saveConfigItems(FILE *fp) override;
104
105 private:
106 bool sendCommand(const char *cmd, char *response);
107
108 bool Handshake();
109 bool Ack();
110 bool Resync();
111
112 bool reset();
113 bool readSettings();
114
115 bool setOutput(unsigned int channel, unsigned int value);
116 bool setCalibrations(unsigned int ch1, unsigned int ch2, unsigned int ambient);
117 bool setThresholds(unsigned int ch1, unsigned int ch2);
118 bool setAutoMode(bool enable);
119 bool setLinkMode(bool enable);
120 bool setAggressivity(unsigned int aggressivity);
121
122 Connection::Serial *serialConnection{ nullptr };
123 int PortFD{ -1 };
124
125 // INDI::PropertyNumber OutputsNP{3}; handled by PowerInterface
126 INDI::PropertyNumber TemperaturesNP{3};
127 INDI::PropertyNumber CalibrationsNP{3};
128 INDI::PropertyNumber ThresholdsNP{2};
129 INDI::PropertyNumber HumidityNP{1};
130 INDI::PropertyNumber DewpointNP{1};
131 INDI::PropertyNumber AggressivityNP{1};
132 // INDI::PropertySwitch AutoModeSP{2}; handled by PowerInterface
133 INDI::PropertySwitch LinkOut23SP{2};
134 INDI::PropertySwitch ResetSP{1};
135 INDI::PropertyNumber FWversionNP{1};
136};
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 SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool SetPowerPort(size_t port, bool enabled) override
SetPowerPort Set power port on/off.
virtual ~USBDewpoint()=default
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
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 bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
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: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