42 #define USBDEWPOINT_TIMEOUT 3
55 DefaultDevice::initProperties();
58 ChannelPowerNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%3.0f", 0., 100., 0., 0.);
59 ChannelPowerNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%3.0f", 0., 100., 0., 0.);
60 ChannelPowerNP[2].
fill(
"CHANNEL3",
"Channel 3",
"%3.0f", 0., 100., 0., 0.);
61 ChannelPowerNP[3].
fill(
"CHANNEL4",
"Channel 4",
"%3.0f", 0., 100., 0., 0.);
65 TempProbeFoundSP[0].
fill(
"PROBE1",
"Probe 1",
ISS_OFF);
66 TempProbeFoundSP[1].
fill(
"PROBE2",
"Probe 2",
ISS_OFF);
67 TempProbeFoundSP[2].
fill(
"PROBE3",
"Probe 3",
ISS_OFF);
68 TempProbeFoundSP[3].
fill(
"PROBE4",
"Probe 4",
ISS_OFF);
72 TemperatureNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%3.2f", -50., 120., 0., 0.);
73 TemperatureNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%3.2f", -50., 120., 0., 0.);
74 TemperatureNP[2].
fill(
"CHANNEL3",
"Channel 3",
"%3.2f", -50., 120., 0., 0.);
75 TemperatureNP[3].
fill(
"CHANNEL4",
"Channel 4",
"%3.2f", -50., 120., 0., 0.);
79 AmbientTemperatureNP[0].
fill(
"AMBIENT",
"Ambient",
"%3.2f", 0., 100., 0., 0.);
83 HumidityNP[0].
fill(
"HUMIDITY",
"Humidity",
"%3.2f", 0., 100., 0., 0.);
87 DewpointNP[0].
fill(
"DEWPOINT",
"Dew point",
"%3.2f", -50., 120., 0., 0.);
91 ChannelOffsetNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%1.2f", -5., 5., 0.25, 0.);
92 ChannelOffsetNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%1.2f", -5., 5., 0.25, 0.);
93 ChannelOffsetNP[2].
fill(
"CHANNEL3",
"Channel 3",
"%1.2f", -5., 5., 0.25, 0.);
94 ChannelOffsetNP[3].
fill(
"CHANNEL4",
"Channel 4",
"%1.2f", -5., 5., 0.25, 0.);
98 AmbientOffsetNP[0].
fill(
"AMBIENT",
"Ambient",
"%1.2f", -4., 3., 0.25, 0.);
102 TrackingOffsetNP[0].
fill(
"TRACKING",
"Tracking",
"%1.0f", -4, 3, 1, 0);
106 TrackingModeSP[0].
fill(
"AMBIENT",
"Ambient",
ISS_ON);
107 TrackingModeSP[1].
fill(
"DEWPOINT",
"Dewpoint",
ISS_OFF);
108 TrackingModeSP[2].
fill(
"MIDPOINT",
"Midpoint",
ISS_OFF);
112 Ch3ModeSP[0].
fill(
"DISABLED",
"Disabled",
ISS_OFF);
113 Ch3ModeSP[1].
fill(
"CHANNEL1",
"Channel 1",
ISS_OFF);
114 Ch3ModeSP[2].
fill(
"CHANNEL2",
"Channel 2",
ISS_OFF);
116 Ch3ModeSP[4].
fill(
"CHANNEL3",
"Channel 3",
ISS_ON);
120 Ch3ManualPowerNP[0].
fill(
"CH3MANUAL",
"Power",
"%3.0f", 0, 100, 10, 0);
124 ChannelBoostSP[0].
fill(
"CHANNEL1",
"Channel 1",
ISS_OFF);
125 ChannelBoostSP[1].
fill(
"CHANNEL2",
"Channel 2",
ISS_OFF);
126 ChannelBoostSP[2].
fill(
"CHANNEL3",
"Channel 3",
ISS_OFF);
127 ChannelBoostSP[3].
fill(
"CHANNEL4",
"Channel 4",
ISS_OFF);
128 ChannelBoostSP[4].
fill(
"RESETALL",
"Reset All",
ISS_OFF);
136 FWversionNP[0].
fill(
"FIRMWARE",
"Firmware Version",
"%3.0f", 0, 999, 0, 0);
140 CheckCodeTP[0].
fill(
"CNTR_CODE",
"Handshake Code",
nullptr);
182 DefaultDevice::updateProperties();
187 if (myDCP4Firmware > 109)
197 if (myDCP4Firmware > 109)
203 ch3ManualPower =
false;
206 LOG_INFO(
"myDCP4ESP32 parameters updated, device ready for use.");
212 if (myDCP4Firmware > 109)
222 if (myDCP4Firmware > 109)
228 if (ch3ManualPower ==
true)
231 ch3ManualPower =
false;
240 return "MyDCP4ESP32";
244 int MyDCP4ESP::msleep(
long duration)
255 ts.tv_sec = duration / 1000;
256 ts.tv_nsec = (duration % 1000) * 1000000;
260 res = nanosleep(&ts, &ts);
262 while (res &&
errno == EINTR);
267 bool MyDCP4ESP::sendCommand(
const char *
cmd,
char *resp)
269 int nbytes_written = 0, nbytes_read = 0, rc = -1;
273 tcflush(PortFD, TCIOFLUSH);
282 msleep(MDCP_SMALL_DELAY);
289 LOGF_ERROR(
"Error reading response for command <%s>: %s.",
cmd, errstr);
295 LOGF_ERROR(
"Invalid response <%s> for command <%s>.", resp,
cmd);
300 resp[nbytes_read - 1] =
'\0';
309 bool MyDCP4ESP::getActiveChannels()
313 int output[4] = {0, 0, 0, 0};
315 unsigned int channel_boost = 0;
316 unsigned int currentCh3Mode = 0;
322 channelActive[i] = 1;
328 TempProbeFoundSP.
apply();
330 if (myDCP4Firmware > 109)
348 if ((output[i] == 0) || (i == 2))
359 if ((ok != 1) || (currentCh3Mode > 4))
362 if (currentCh3Mode != CH3MODE_CH3TEMP)
363 if (!setCh3Mode( CH3MODE_CH3TEMP ))
367 if (!setChannelBoost( i+1, 1))
374 if (!sendCommand(
cmd, resp))
379 if ((ok == 1) && (channel_boost == 0))
382 channelActive[i] = 0;
385 if (!setChannelBoost( i+1, 0))
388 if ((i == 2) && (currentCh3Mode != CH3MODE_CH3TEMP))
389 if (!setCh3Mode(currentCh3Mode))
404 TempProbeFoundSP.
apply();
408 bool MyDCP4ESP::Handshake()
424 LOG_INFO(
"myDCP4ESP32 is online. Getting device parameters...");
425 if (!getActiveChannels())
426 LOG_INFO(
"Could not determine active channels. Default to all active.");
429 LOG_INFO(
"Error retrieving data from myDCP4ESP32, retrying...");
431 while (--tries > 0 );
433 LOG_INFO(
"Error retrieving data from myDCP4ESP32, please ensure controller "
434 "is powered and the port is correct.");
439 bool MyDCP4ESP::Ack()
459 CheckCodeTP[0].setText(code);
463 tcflush(PortFD, TCIOFLUSH);
477 myDCP4Firmware = firmware;
478 FWversionNP[0].setValue(firmware);
485 bool MyDCP4ESP::setChannelOffset(
unsigned int channel,
float value)
510 return sendCommand(
cmd,
nullptr);
514 bool MyDCP4ESP::setAmbientOffset(
float value)
519 return sendCommand(
cmd,
nullptr);
523 bool MyDCP4ESP::setChannelBoost(
unsigned int channel,
unsigned int value)
526 if ((channel == 5) || (value == 0))
529 return sendCommand(
cmd,
nullptr);
531 else if (channel != 5)
534 return sendCommand(
cmd,
nullptr);
541 bool MyDCP4ESP::setTrackingMode(
unsigned int value)
546 return sendCommand(
cmd,
nullptr);
550 bool MyDCP4ESP::setCh3Mode(
unsigned int value)
555 return sendCommand(
cmd,
nullptr);
559 bool MyDCP4ESP::setCh3Output(
unsigned int value)
564 return sendCommand(
cmd,
nullptr);
568 bool MyDCP4ESP::setTrackingOffset(
int value)
573 return sendCommand(
cmd,
nullptr);
577 bool MyDCP4ESP::rebootController()
579 LOG_INFO(
"Rebooting Controller and Disconnecting.");
586 LOG_INFO(
"Waiting 10 seconds before attempting to reconnect.");
597 LOGF_INFO(
"Could not reconnect waiting 10 seconds before attempt %d of 5.", i);
600 LOGF_ERROR(
"Could not reconnect after %d attempts", i-1);
609 }
while ((i != 0) && (i <= 5));
624 setChannelBoost(5, 1);
628 for (
int i = 0; i < 4; i++)
630 if (ChannelBoostSP[i].getState() != states[i] )
631 setChannelBoost(i+1, states[i]);
635 ChannelBoostSP.
update(states, names, n);
637 ChannelBoostSP.
apply();
644 TrackingModeSP.
update(states, names, n);
646 TrackingModeSP.
apply();
654 Ch3ModeSP.
update(states, names, n);
666 if (rebootController())
690 ChannelOffsetNP.
update(values, names, n);
692 ChannelOffsetNP.
apply();
693 setChannelOffset(1, ChannelOffsetNP[0].getValue());
694 setChannelOffset(2, ChannelOffsetNP[1].getValue());
695 setChannelOffset(3, ChannelOffsetNP[2].getValue());
696 setChannelOffset(4, ChannelOffsetNP[3].getValue());
703 AmbientOffsetNP.
update(values, names, n);
705 AmbientOffsetNP.
apply();
706 setAmbientOffset(AmbientOffsetNP[0].getValue());
713 TrackingOffsetNP.
update(values, names, n);
715 TrackingOffsetNP.
apply();
716 setTrackingOffset(TrackingOffsetNP[0].getValue());
723 Ch3ManualPowerNP.
update(values, names, n);
725 Ch3ManualPowerNP.
apply();
726 setCh3Output(Ch3ManualPowerNP[0].getValue());
734 bool MyDCP4ESP::readSettings()
738 float temp1, temp2, temp3, temp4, temp_ambient, humidity, dewpoint;
739 unsigned int output1, output2, output3, output4;
740 float ambient_offset, offset1, offset2, offset3, offset4;
742 unsigned int tracking_mode, ch3_mode, channel_boost;
753 AmbientOffsetNP[0].setValue(ambient_offset);
755 AmbientOffsetNP.
apply();
771 AmbientTemperatureNP[0].setValue(temp_ambient + ambient_offset);
773 AmbientTemperatureNP.
apply();
788 HumidityNP[0].setValue(humidity);
805 DewpointNP[0].setValue(dewpoint);
822 ChannelPowerNP[0].setValue(output1);
823 ChannelPowerNP[1].setValue(output2);
824 ChannelPowerNP[2].setValue(output3);
825 ChannelPowerNP[3].setValue(output4);
827 ChannelPowerNP.
apply();
840 if ((ok == 1) && (ch3_mode <= 4))
843 if ((ch3_mode == CH3MODE_MANUAL) && (!ch3ManualPower))
846 ch3ManualPower =
true;
848 else if ((ch3_mode != CH3MODE_MANUAL) && ch3ManualPower)
851 ch3ManualPower =
false;
863 if (ch3ManualPower ==
true)
865 Ch3ManualPowerNP[0].setValue(ChannelPowerNP[2].getValue());
867 Ch3ManualPowerNP.
apply();
881 ChannelOffsetNP[0].setValue(offset1);
882 ChannelOffsetNP[1].setValue(offset2);
883 ChannelOffsetNP[2].setValue(offset3);
884 ChannelOffsetNP[3].setValue(offset4);
886 ChannelOffsetNP.
apply();
903 TemperatureNP[0].setValue(temp1 + (offset1 * channelActive[0]));
904 TemperatureNP[1].setValue(temp2 + (offset2 * channelActive[1]));
907 TemperatureNP[2].setValue(temp3 + (offset3 * channelActive[2]));
909 TemperatureNP[2].setValue( 0 );
911 TemperatureNP[3].setValue(temp4 + (offset4 * channelActive[3]));
913 TemperatureNP.
apply();
926 if ((ok == 1) && (tracking_mode > 0) && (tracking_mode <= 3))
928 TrackingModeSP.
reset();
931 TrackingModeSP.
apply();
937 if (myDCP4Firmware > 109)
948 TrackingOffsetNP[0].setValue(tracking_offset);
950 TrackingOffsetNP.
apply();
958 if (myDCP4Firmware > 109)
963 for (
int i = 1; i <= 4; i++)
971 if (!sendCommand(
cmd, resp))
976 if ((ok == 1) && (channel_boost <= 1))
980 ChannelBoostSP.
apply();
983 LOGF_ERROR(
"Get Channel Overrides: Response <%s> for Command <%s> not recognized.", resp,
cmd);
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
void setDefaultHost(const char *addressHost)
void setDefaultPort(uint32_t addressPort)
const char * getDeviceName() const
void addPollPeriodControl()
Add Polling period control to the driver.
void addConfigurationControl()
Add Configuration control to the driver.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual bool Disconnect()
Disconnect from device.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void RemoveTimer(int id)
Remove timer added with SetTimer.
Connection::Interface * getActiveConnection()
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
void addDebugControl()
Add Debug control to the driver.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool isNameMatch(const char *otherName) const
bool update(const double values[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
bool update(const ISState states[], const char *const names[], int n)
int findOnSwitchIndex() const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
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 initProperties() override
Initilize 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 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.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
std::unique_ptr< MyDCP4ESP > mydcp4esp(new MyDCP4ESP())
#define MDCP_SET_TRACKING_OFFSET_CMD
#define MDCP_SET_CH3_MANUAL_POWER_CMD
#define MDCP_GET_AMBIENT_OFFSET_RES
#define CDRIVER_VERSION_MAJOR
#define MDCP_GET_HUMIDITY_RES
#define MDCP_SET_TRACKING_MODE_CMD
#define MDCP_GET_VERSION_RES
#define MDCP_GET_TRACKING_OFFSET_CMD
#define CDRIVER_VERSION_MINOR
#define MDCP_GET_CHANNEL_TEMPS_RES
#define MDCP_GET_ALL_CH_OFFSET_CMD
#define MDCP_SET_CH2_OFFSET_CMD
#define MDCP_GET_ALL_CH_POWER_RES
#define MDCP_GET_AMBIENT_OFFSET_CMD
#define MDCP_GET_CH_OVERIDE_CMD
#define MDCP_SET_AMBIENT_OFFSET_CMD
#define MDCP_SET_CH3_OFFSET_CMD
#define MDCP_SET_CH_100_CMD
#define MDCP_RESET_CH_100_CMD
#define MDCP_GET_CH3_MODE_CMD
#define MDCP_GET_CH_OVERIDE_RES
#define MDCP_GET_TRACKING_OFFSET_RES
#define MDCP_GET_VERSION_CMD
#define MDCP_GET_ALL_CH_POWER_CMD
#define MDCP_GET_CH3_MODE_RES
#define MDCP_GET_CONTROLLER_CODE_RES
#define MDCP_GET_HUMIDITY_CMD
#define MDCP_GET_TRACKING_MODE_RES
#define MDCP_GET_TRACKING_MODE_CMD
#define MDCP_RESPONSE_LENGTH
#define MDCP_GET_AMBIENT_TEMPERATURE_RES
#define MDCP_GET_AMBIENT_TEMPERATURE_CMD
#define MDCP_GET_CHANNEL_TEMPS_CMD
#define MDCP_GET_DEWPOINT_RES
#define MDCP_SET_CH1_OFFSET_CMD
#define MDCP_GET_ALL_CH_OFFSET_RES
#define MDCP_GET_DEWPOINT_CMD
#define MDCP_GET_CONTROLLER_CODE_CMD
#define MDCP_SET_CH4_OFFSET_CMD
#define MDCP_SET_CH3_MODE_CMD
const char * CONNECTION_TAB