Instrument Neutral Distributed Interface INDI  2.0.2
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 
25 /***************************** USB_Dewpoint Commands **************************/
26 
27 // All commands are exactly 6 bytes, no start/end markers
28 #define UDP_CMD_LEN 6
29 #define UDP_STATUS_CMD "SGETAL"
30 #define UDP_OUTPUT_CMD "S%1uO%03u" // channel 1-3, power 0-100
31 #define UDP_THRESHOLD_CMD "STHR%1u%1u" // channel 1-2, value 0-9
32 #define UDP_CALIBRATION_CMD "SCA%1u%1u%1u" // channel 1-2-A, value 0-9
33 #define UDP_LINK_CMD "SLINK%1u" // 0 or 1 to link channels 2 and 3
34 #define UDP_AUTO_CMD "SAUTO%1u" // 0 or 1 to enable auto mode
35 #define UDP_AGGRESSIVITY_CMD "SAGGR%1u" // 1-4 (1, 2, 5, 10)
36 #define UDP_IDENTIFY_CMD "SWHOIS"
37 #define UDP_RESET_CMD "SEERAZ"
38 
39 /**************************** USB_Dewpoint Constants **************************/
40 
41 // Responses also include "\n\r"
42 #define UDP_DONE_RESPONSE "DONE"
43 #define UDP_RES_LEN 80 // With some margin, maximum feasible seems to be around 70
44 
45 // Status response is like:
46 // ##22.37/22.62/23.35/50.77/12.55/0/0/0/0/0/0/2/2/0/0/4**
47 
48 // Fields are in order:
49 // temperature ch 1
50 // temperature ch 2
51 // temperature ambient
52 // relative humidity
53 // dew point
54 // output ch 1
55 // output ch 2
56 // output ch 3
57 // calibration ch 1
58 // calibration ch 2
59 // calibration ambient
60 // threshold ch 1
61 // threshold ch 2
62 // auto mode
63 // outputs ch 2 & 3 linked
64 // aggressivity
65 
66 #define UDP_STATUS_RESPONSE "##%f/%f/%f/%f/%f/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u**"
67 #define UDP_STATUS_START "##"
68 #define UDP_STATUS_SEPARATOR "/"
69 #define UDP_STATUS_END "**"
70 
71 #define UDP_IDENTIFY_RESPONSE "UDP2(%u)" // Firmware version? Mine is "UDP2(1446)"
72 
73 /******************************************************************************/
74 
75 namespace Connection
76 {
77 class Serial;
78 };
79 
81 {
82  public:
83  USBDewpoint();
84  virtual ~USBDewpoint() = default;
85 
86  virtual const char *getDefaultName() override;
87  virtual bool initProperties() override;
88  virtual bool updateProperties() override;
89  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
90  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
91  virtual void TimerHit() override;
92 
93  private:
94  bool sendCommand(const char *cmd, char *response);
95 
96  bool Handshake();
97  bool Ack();
98  bool Resync();
99 
100  bool reset();
101  bool readSettings();
102 
103  bool setOutput(unsigned int channel, unsigned int value);
104  bool setCalibrations(unsigned int ch1, unsigned int ch2, unsigned int ambient);
105  bool setThresholds(unsigned int ch1, unsigned int ch2);
106  bool setAutoMode(bool enable);
107  bool setLinkMode(bool enable);
108  bool setAggressivity(unsigned int aggressivity);
109 
110  Connection::Serial *serialConnection{ nullptr };
111  int PortFD{ -1 };
112 
113  INDI::PropertyNumber OutputsNP{3};
114  INDI::PropertyNumber TemperaturesNP{3};
115  INDI::PropertyNumber CalibrationsNP{3};
116  INDI::PropertyNumber ThresholdsNP{2};
117  INDI::PropertyNumber HumidityNP{1};
118  INDI::PropertyNumber DewpointNP{1};
119  INDI::PropertyNumber AggressivityNP{1};
120  INDI::PropertySwitch AutoModeSP{2};
121  INDI::PropertySwitch LinkOut23SP{2};
122  INDI::PropertySwitch ResetSP{1};
123  INDI::PropertyNumber FWversionNP{1};
124 };
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 ~USBDewpoint()=default
virtual bool initProperties() override
Initilize 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 const char * getDefaultName() override
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
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:150
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