32#define USBDEWPOINT_TIMEOUT 3
43 DefaultDevice::initProperties();
57 TemperaturesNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%3.2f", -50., 70., 0., 0.);
58 TemperaturesNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%3.2f", -50., 70., 0., 0.);
59 TemperaturesNP[2].
fill(
"AMBIENT",
"Ambient",
"%3.2f", -50., 70., 0., 0.);
63 HumidityNP[0].
fill(
"HUMIDITY",
"Humidity",
"%3.2f", 0., 100., 0., 0.);
67 DewpointNP[0].
fill(
"DEWPOINT",
"Dew point",
"%3.2f", -50., 70., 0., 0.);
71 CalibrationsNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%1.0f", 0., 9., 1., 0.);
72 CalibrationsNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%1.0f", 0., 9., 1., 0.);
73 CalibrationsNP[2].
fill(
"AMBIENT",
"Ambient",
"%1.0f", 0., 9., 1., 0.);
77 ThresholdsNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%1.0f", 0., 9., 1., 0.);
78 ThresholdsNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%1.0f", 0., 9., 1., 0.);
82 AggressivityNP[0].
fill(
"AGGRESSIVITY",
"Aggressivity",
"%1.0f", 1., 4., 1., 1.);
91 LinkOut23SP[0].
fill(
"INDEPENDENT",
"Independent",
ISS_ON);
100 FWversionNP[0].
fill(
"FIRMWARE",
"Firmware Version",
"%4.0f", 0., 65535., 1., 0.);
124 DefaultDevice::updateProperties();
143 LOG_INFO(
"USB_Dewpoint parameters updated, device ready for use.");
166 return "USB_Dewpoint";
169bool USBDewpoint::sendCommand(
const char *
cmd,
char *resp)
171 int nbytes_written = 0, nbytes_read = 0, rc = -1;
175 tcflush(PortFD, TCIOFLUSH);
188 LOGF_ERROR(
"Error reading response for command %s: %s.",
cmd, errstr);
194 LOGF_ERROR(
"Invalid response for command %s: %s.",
cmd, resp);
197 resp[nbytes_read - 2] =
'\0';
203bool USBDewpoint::Resync()
206 int nbytes_written = 0, nbytes_read = 0, rc = -1;
213 tcflush(PortFD, TCIOFLUSH);
215 for (
int resync = 0; resync <
UDP_CMD_LEN; resync++)
222 LOGF_ERROR(
"Error writing resync: %s.", errstr);
227 if (rc ==
TTY_OK && nbytes_read > 0)
238bool USBDewpoint::Handshake()
247 LOG_INFO(
"USB_Dewpoint is online. Getting device parameters...");
250 LOG_INFO(
"Error retrieving data from USB_Dewpoint, trying resync...");
252 while (--tries > 0 && Resync());
254 LOG_INFO(
"Error retrieving data from USB_Dewpoint, please ensure controller "
255 "is powered and the port is correct.");
259bool USBDewpoint::Ack()
262 tcflush(PortFD, TCIOFLUSH);
273 LOGF_ERROR(
"USB_Dewpoint not properly identified! Answer was: %s.", resp);
277 FWversionNP[0].setValue(firmware);
283bool USBDewpoint::setOutput(
unsigned int channel,
unsigned int value)
289 return sendCommand(
cmd, resp);
292bool USBDewpoint::setCalibrations(
unsigned int ch1,
unsigned int ch2,
unsigned int ambient)
298 return sendCommand(
cmd, resp);
301bool USBDewpoint::setThresholds(
unsigned int ch1,
unsigned int ch2)
307 return sendCommand(
cmd, resp);
310bool USBDewpoint::setAggressivity(
unsigned int aggressivity)
316 return sendCommand(
cmd, resp);
319bool USBDewpoint::reset()
325bool USBDewpoint::setAutoMode(
bool enable)
331 return sendCommand(
cmd, resp);
337 return setAutoMode(enabled);
343 return setOutput(port + 1,
static_cast<unsigned int>(dutyCycle));
346bool USBDewpoint::setLinkMode(
bool enable)
352 return sendCommand(
cmd, resp);
359 LOG_DEBUG(
"SetPowerPort not supported by USB_Dewpoint.");
368 LOG_DEBUG(
"SetVariablePort not supported by USB_Dewpoint.");
375 LOG_DEBUG(
"SetLEDEnabled not supported by USB_Dewpoint.");
381 LOG_DEBUG(
"CyclePower not supported by USB_Dewpoint.");
389 LOG_DEBUG(
"SetUSBPort not supported by USB_Dewpoint.");
414 LinkOut23SP.
update(states, names, n);
418 setLinkMode(target_mode == 1);
482 CalibrationsNP.
update(values, names, n);
484 CalibrationsNP.
apply();
485 setCalibrations(CalibrationsNP[0].getValue(), CalibrationsNP[1].getValue(), CalibrationsNP[2].getValue());
491 ThresholdsNP.
update(values, names, n);
493 ThresholdsNP.
apply();
494 setThresholds(ThresholdsNP[0].getValue(), ThresholdsNP[1].getValue());
500 AggressivityNP.
update(values, names, n);
502 AggressivityNP.
apply();
503 setAggressivity(AggressivityNP[0].getValue());
509 FWversionNP.
update(values, names, n);
518bool USBDewpoint::readSettings()
528 float temp1, temp2, temp_ambient,
humidity, dewpoint;
529 unsigned int output1, output2, output3;
530 unsigned int calibration1, calibration2, calibration_ambient;
531 unsigned int threshold1, threshold2;
532 unsigned int automode, linkout23, aggressivity;
535 &output2,&output3, &calibration1, &calibration2, &calibration_ambient, &threshold1, &threshold2,
536 &automode, &linkout23, &aggressivity);
540 TemperaturesNP[0].setValue(temp1);
541 TemperaturesNP[1].setValue(temp2);
542 TemperaturesNP[2].setValue(temp_ambient);
544 TemperaturesNP.
apply();
550 DewpointNP[0].setValue(dewpoint);
574 if (
DewChannelsSP[2].getState() && LinkOut23SP[1].getState())
582 CalibrationsNP[0].setValue(calibration1);
583 CalibrationsNP[1].setValue(calibration2);
584 CalibrationsNP[2].setValue(calibration_ambient);
586 CalibrationsNP.
apply();
588 ThresholdsNP[0].setValue(threshold1);
589 ThresholdsNP[1].setValue(threshold2);
591 ThresholdsNP.
apply();
605 AggressivityNP[0].setValue(aggressivity);
607 AggressivityNP.
apply();
628 LinkOut23SP.
save(fp);
629 AggressivityNP.
save(fp);
630 CalibrationsNP.
save(fp);
631 ThresholdsNP.
save(fp);
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
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.
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.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
INDI::PropertySwitch DewChannelsSP
bool saveConfigItems(FILE *fp)
saveConfigItems Save power properties in config file
INDI::PropertySwitch AutoDewSP
void SetCapability(uint32_t cap)
SetPowerCapability sets the Power capabilities. All capabilities must be initialized.
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process Power number properties.
void initProperties(const char *groupName, size_t nPowerPorts=0, size_t nDewPorts=0, size_t nVariablePorts=0, size_t nAutoDewPorts=0, size_t nUSBPorts=0)
Initialize Power properties. It is recommended to call this function within initProperties() of your ...
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process Power text properties.
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process Power switch properties.
INDI::PropertyNumber DewChannelDutyCycleNP
bool updateProperties()
updateProperties Define or Delete Power properties based on the connection status of the base device
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
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)
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 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....
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(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer 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 LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
#define USBDEWPOINT_TIMEOUT
Namespace to encapsulate INDI client, drivers, and mediator classes.
std::unique_ptr< USBDewpoint > usbDewpoint(new USBDewpoint())
#define UDP_CALIBRATION_CMD
#define UDP_IDENTIFY_RESPONSE
#define UDP_AGGRESSIVITY_CMD
#define UDP_STATUS_RESPONSE
#define UDP_THRESHOLD_CMD