Instrument Neutral Distributed Interface INDI 2.2.5
mydcp4esp32.h
Go to the documentation of this file.
1/*
2 myDCP4ESP32
3 Copyright (C) 2023 Stephen Hillier
4
5 Based on MyFocuserPro2 Focuser
6 Copyright (C) 2019 Alan Townshend
7
8 As well as USB_Dewpoint
9 Copyright (C) 2017-2023 Jarno Paananen
10
11 And INDI Sky Quality Meter Driver
12 Copyright(c) 2016 Jasem Mutlaq. All rights reserved.
13
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 2.1 of the License, or (at your option) any later version.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27
28*/
29
30#pragma once
31
32#include <defaultdevice.h>
33#include <indipowerinterface.h>
34
35#include <time.h> // for nsleep()
36#include <errno.h> // for nsleep()
37
38// Version 1.0 - First release.
39// Version 2.0 - Refactor for INDI::Power Interface
40
41#define CDRIVER_VERSION_MAJOR 2
42#define CDRIVER_VERSION_MINOR 0
43
44/***************************** myDCP4ESP32 Commands **************************/
45//
46// Commands and responses are string types
47// Commands start with a ':' and are terminated with a '#', for example, ':01#'
48// Commands are case sensitive
49// Responses have a lead character, then values – more than one value is separated with a comma [,] and the string is
50// terminated with a '#'
51
52#define MDCP_CMD_LENGTH 32 // Command buffer size
53#define MDCP_CMD_TERMINATOR "#"
54#define MDCP_GET_CONTROLLER_CODE_CMD ":00#" // Get controller code - Response: 0code#
55#define MDCP_GET_VERSION_CMD ":01#" // Get version number - Respnse: 1version#
56#define MDCP_REBOOT_CMD ":02#" // Reboot controller - Response: none
57#define MDCP_GET_TRACKING_MODE_CMD ":03#" // Get tracking mode (1=Ambient, 2=Dewpoint, 3=Midpoint) - Response: 3trackingmode#
58#define MDCP_SET_TRACKING_MODE_CMD ":04%1u#" // Set tracking mode (1=Ambient, 2=Dewpoint, 3=Midpoint) - Response: none
59#define MDCP_GET_TRACKING_OFFSET_CMD ":05#" // Get tracking mode offset value (-4 to +3) - Response: 5trackingmodeoffset#
60#define MDCP_ZERO_TRACKING_OFFSET_CMD ":06#" // Set tracking mode offset to 0 - Response: none
61#define MDCP_DECREASE_TRACKING_OFFSET_CMD ":07#" // Decrease tracking mode offset - Response: none
62#define MDCP_INCREASE_TRACKING_OFFSET_CMD ":08#" // Increase tracking mode offset - Response: none
63#define MDCP_GET_NUMBER_PROBES_CMD ":09#" // Get the number of temperature probes attached - Response: 9number_of_probes#
64#define MDCP_SAVE_CONTROLLER_SETTINGS_CMD ":10#" // Write variables immediately to SPIFFS - Response: none
65#define MDCP_SET_DEFAULT_SETTINGS_CMD ":11#" // controller settings to default values - Response: none
66#define MDCP_GET_AMBIENT_TEMPERATURE_CMD ":12#" // Get the Ambient temperature - Response: avalue#
67#define MDCP_GET_AMBIENT_OFFSET_CMD ":13#" // Get the Ambient offset - Response: bvalue$
68#define MDCP_SET_AMBIENT_OFFSET_CMD ":14%1.2f#" // Set the Ambient offset, Num is a value between +3 and -4 - Response: none
69#define MDCP_GET_HUMIDITY_CMD ":15#" // Get the Relative Humidity % - Resonse: cvalue#
70#define MDCP_GET_DEWPOINT_CMD ":16#" // Get the Dew Point - Response: dvalue#
71#define MDCP_GET_TEMP_MODE_CMD ":17#" // Get Temp Mode, 0=Celsius, 1=Fahrenheit - Response: eTempMode
72#define MDCP_SET_TEMP_MODE_C_CMD ":181#" // Display in Celsius - Response: none
73#define MDCP_SET_TEMP_MODE_F_CMD ":182#" // Display in Fahrenheit - Response: none
74#define MDCP_SET_TRACKING_OFFSET_CMD ":19%d#" // Set the tracking mode offset value [-4 to +3] - Response: none
75#define MDCP_GET_MAC_ADDRESS_CMD ":26#" // Get MAC address - Response: hString#
76#define MDCP_GET_IP_ADDRESS_CMD ":27#" // Get IP address - Response: iString#
77#define MDCP_GET_CHANNEL_TEMPS_CMD ":28#" // Get the temp in Celsius for Channel1-4 - Response: jch1temp,ch2temp,ch3temp,ch4temp#
78#define MDCP_SET_CH1_OFFSET_CMD ":29%01.2f#" // Set ch1offset value (expects a float) - Response: none
79#define MDCP_SET_CH2_OFFSET_CMD ":30%01.2f#" // Set ch2offset value (expects a float) - Response: none
80#define MDCP_SET_CH3_OFFSET_CMD ":31%01.2f#" // Set ch3offset value (expects a float) - Response: none
81#define MDCP_SET_CH4_OFFSET_CMD ":32%01.2f#" // Set ch4offset value (expects a float) - Response: none
82#define MDCP_ZERO_ALL_CH_OFFSET_CMD ":33#" // Clear ch1offset-ch4offset values to 0.0 - Response: none
83#define MDCP_GET_ALL_CH_OFFSET_CMD ":34#" // Get the ch1offset=ch4offset values - Response: kch1offset,ch2offset,ch3offset#
84#define MDCP_SET_CH_100_CMD ":35%d#" // Set boost 100% to channel x - Response: none
85#define MDCP_GET_CH_OVERIDE_CMD ":36%d#" // Get Override mode for channel x - Response: return value is 0 or 1
86#define MDCP_SET_CONTROLLER_MODE_CMD ":37%d#" // Set controller mode – controlledbyapp = 0 or 1 - Response: none
87#define MDCP_GET_CONTROLLER_MODE_CMD ":38#" // Get controlledbyapp setting - Response: ux#
88#define MDCP_RESET_CH_100_CMD ":39%d#" // Turn off 100% boost to channel number x [1-4, 5=all] - Response: none
89#define MDCP_GET_ALL_CH_POWER_CMD ":40#" // Get the power settings for ch1/ch2/ch3/ch4 - Response: lch1pwr,ch2pwr,ch3pwr,ch4pwr#
90#define MDCP_SET_CH3_MODE_CMD ":41%d#" // Set the Channel 3 mode (0=disabled, 1=dewstrap1, 2=dewstrap2, 3=Manual, 4=use temp probe3) - Response: none
91#define MDCP_GET_CH3_MODE_CMD ":42#" // Get the Channel 3 mode (0=disabled, 1=dewstrap1, 2=dewstrap2, 3=Manual, 4=use temp probe3) - Response: mmode#
92#define MDCP_SET_CH3_MANUAL_POWER_CMD ":43%d#" // Set the Channel 3 power to a manual setting of Num - Response: none
93
94/**************************** myDCP4ESP32 Command Responses **************************/
95
96#define MDCP_RESPONSE_LENGTH 64 // Response buffer size
97#define MDCP_GET_CONTROLLER_CODE_RES "0%s" // Get controller code - Response: 0code#
98#define MDCP_GET_VERSION_RES "1%d" // Get version number - Respnse: 1version#
99#define MDCP_REBOOT_RES "" // Reboot controller - Response: none
100#define MDCP_GET_TRACKING_MODE_RES "3%d" // Get tracking mode (1=Ambient, 2=Dewpoint, 3=Midpoint) - Response: 3trackingmode#
101#define MDCP_SET_TRACKING_MODE_RES "" // Set tracking mode (1=Ambient, 2=Dewpoint, 3=Midpoint) - Response: none
102#define MDCP_GET_TRACKING_OFFSET_RES "5%d" // Get tracking mode offset value (-4 to +3) - Response: 5trackingmodeoffset#
103#define MDCP_ZERO_TRACKING_OFFSET_RES "" // Set tracking mode offset to 0 - Response: none
104#define MDCP_DECREASE_TRACKING_OFFSET_RES "" // Decrease tracking mode offset - Response: none
105#define MDCP_INCREASE_TRACKING_OFFSET_RES "" // Increase tracking mode offset - Response: none
106#define MDCP_GET_NUMBER_PROBES_RES "9%d" // Get the number of temperature probes attached - Response: 9number_of_probes#
107#define MDCP_SAVE_CONTROLLER_SETTINGS_RES "" // Write variables immediately to SPIFFS - Response: none
108#define MDCP_SET_DEFAULT_SETTINGS_RES "" // controller settings to default values - Response: none
109#define MDCP_GET_AMBIENT_TEMPERATURE_RES "a%f" // Get the Ambient temperature - Response: avalue#
110#define MDCP_GET_AMBIENT_OFFSET_RES "b%f" // Get the Ambient offset - Response: bvalue#
111#define MDCP_SET_AMBIENT_OFFSET_RES "" // Set the Ambient offset, Num is a value between +3 and -4 - Response: none
112#define MDCP_GET_HUMIDITY_RES "c%f" // Get the Relative Humidity % - Resonse: cvalue#
113#define MDCP_GET_DEWPOINT_RES "d%f" // Get the Dew Point - Response: dvalue#
114#define MDCP_GET_TEMP_MODE_RES "e%d" // Get Temp Mode, 0=Celsius, 1=Fahrenheit - Response: eTempMode
115#define MDCP_SET_TEMP_MODE_C_RES "" // Display in Celsius - Response: none
116#define MDCP_SET_TEMP_MODE_F_RES "" // Display in Fahrenheit - Response: none
117#define MDCP_SET_TRACKING_OFFSET_RES "" // Set the tracking mode offset value [-4 to +3] - Response: none
118#define MDCP_GET_MAC_ADDRESS_RES "h%s" // Get MAC address - Response: hString#
119#define MDCP_GET_IP_ADDRESS_RES "i%s" // Get IP address - Response: iString#
120#define MDCP_GET_CHANNEL_TEMPS_RES "j%f,%f,%f,%f" // Get the temp in Celsius for Channel1-4 - Response: jch1temp,ch2temp,ch3temp,ch4temp#
121#define MDCP_SET_CH1_OFFSET_RES "" // Set ch1offset value (expects a float) - Response: none
122#define MDCP_SET_CH2_OFFSET_RES "" // Set ch2offset value (expects a float) - Response: none
123#define MDCP_SET_CH3_OFFSET_RES "" // Set ch3offset value (expects a float) - Response: none
124#define MDCP_SET_CH4_OFFSET_RES "" // Set ch4offset value (expects a float) - Response: none
125#define MDCP_ZERO_ALL_CH_OFFSET_RES "" // Clear ch1offset-ch4offset values to 0.0 - Response: none
126#define MDCP_GET_ALL_CH_OFFSET_RES "k%f,%f,%f,%f" // Get the ch1offset=ch4offset values - Response: kch1offset,ch2offset,ch3offset#
127#define MDCP_SET_CH_100_RES "" // Set boost 100% to channel x - Response: none
128#define MDCP_GET_CH_OVERIDE_RES "t%d" // Get Override mode for channel x - Response: return value is 0 or 1
129#define MDCP_SET_CONTROLLER_MODE_RES "" // Set controller mode – controlledbyapp = 0 or 1 - Response: none
130#define MDCP_GET_CONTROLLER_MODE_RES "u%d" // Get controlledbyapp setting - Response: ux#
131#define MDCP_RESET_CH_100_RES "" // Turn off 100% boost to channel number x [1-4, 5=all] - Response: none
132#define MDCP_GET_ALL_CH_POWER_RES "l%d,%d,%d,%d" // Get the power settings for ch1/ch2/ch3/ch4 - Response: lch1pwr,ch2pwr,ch3pwr,ch4pwr#
133#define MDCP_SET_CH3_MODE_RES "" // Set the Channel 3 mode (0=disabled, 1=dewstrap1, 2=dewstrap2, 3=Manual, 4=use temp probe3) - Response: none
134#define MDCP_GET_CH3_MODE_RES "m%d" // Get the Channel 3 mode (0=disabled, 1=dewstrap1, 2=dewstrap2, 3=Manual, 4=use temp probe3) - Response: mmode#
135#define MDCP_SET_CH3_MANUAL_POWER_RES "" // Set the Channel 3 power to a manual setting of Num - Response: none
136
137/******************************************************************************/
138
140{
141 public:
142 MyDCP4ESP();
143 virtual ~MyDCP4ESP() = default;
144
145 // Power Interface Implementations
146 virtual bool SetPowerPort(size_t port, bool enabled) override;
147 virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override;
148 virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override;
149 virtual bool SetLEDEnabled(bool enabled) override;
150 virtual bool SetAutoDewEnabled(size_t port, bool enabled) override;
151 virtual bool CyclePower() override;
152 virtual bool SetUSBPort(size_t port, bool enabled) override;
153
154 virtual const char *getDefaultName() override;
155 virtual bool initProperties() override;
156 virtual bool updateProperties() override;
157 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
158 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
159 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
160 virtual bool saveConfigItems(FILE *fp) override;
161 virtual void TimerHit() override;
162
167 typedef enum
168 {
171 CONNECTION_TCP = 1 << 2
173
174 private:
175 int timerIndex;
176 int myDCP4Firmware = 0;
177 float channelActive[4] = {1};
178 int msleep( long duration);
179 bool sendCommand(const char *cmd, char *response);
180 bool Handshake();
181 bool Ack();
182 bool rebootController();
183 bool readSettings();
184 bool setChannelOffset(unsigned int channel, float value);
185 bool setAmbientOffset(float value);
186 bool setTrackingMode(unsigned int value);
187 bool setTrackingOffset(int value);
188 bool setCh3Mode(unsigned int value);
189 bool setCh3Output(unsigned int value);
190 bool setChannelBoost(unsigned int channel, unsigned int value);
191 bool getActiveChannels();
192
193 Connection::Serial *serialConnection { nullptr };
194 Connection::TCP *tcpConnection { nullptr };
195
196 int PortFD { -1 };
197
198 uint8_t mdcpConnection { CONNECTION_SERIAL | CONNECTION_TCP };
199
200 // MyDCP4ESP Timeouts
201 static const uint8_t MDCP_READ_TIMEOUT { 10 }; // seconds
202 static const long MDCP_SMALL_DELAY { 50 }; // 50ms delay from send command to read response
203
204 enum
205 {
206 CH3MODE_DISABLED,
207 CH3MODE_CH1POWER,
208 CH3MODE_CH2POWER,
209 CH3MODE_MANUAL,
210 CH3MODE_CH3TEMP
211 };
212
213 INDI::PropertySwitch TempProbeFoundSP{4};
214 INDI::PropertyNumber TemperatureNP{4};
215 INDI::PropertyNumber ChannelOffsetNP{4};
216 INDI::PropertySwitch ChannelBoostSP{5};
217 INDI::PropertyNumber AmbientTemperatureNP{1};
218 INDI::PropertyNumber AmbientOffsetNP{1};
219 INDI::PropertyNumber HumidityNP{1};
220 INDI::PropertyNumber DewpointNP{1};
221 INDI::PropertySwitch TrackingModeSP{3};
222 INDI::PropertyNumber TrackingOffsetNP{1};
223 INDI::PropertySwitch Ch3ModeSP{5};
224 INDI::PropertyText CheckCodeTP{1};
225 INDI::PropertyNumber FWversionNP{1};
226
227};
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
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 const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, 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.
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 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 updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual ~MyDCP4ESP()=default
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 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 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.
@ CONNECTION_SERIAL
ISState
Switch state.
Definition indiapi.h:148
uint8_t cmd[4]
Definition pwc-ioctl.h:2