32 #define USBDEWPOINT_TIMEOUT 3
43 DefaultDevice::initProperties();
46 OutputsNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%3.0f", 0., 100., 10., 0.);
47 OutputsNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%3.0f", 0., 100., 10., 0.);
48 OutputsNP[2].
fill(
"CHANNEL3",
"Channel 3",
"%3.0f", 0., 100., 10., 0.);
52 TemperaturesNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%3.2f", -50., 70., 0., 0.);
53 TemperaturesNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%3.2f", -50., 70., 0., 0.);
54 TemperaturesNP[2].
fill(
"AMBIENT",
"Ambient",
"%3.2f", -50., 70., 0., 0.);
58 HumidityNP[0].
fill(
"HUMIDITY",
"Humidity",
"%3.2f", 0., 100., 0., 0.);
62 DewpointNP[0].
fill(
"DEWPOINT",
"Dew point",
"%3.2f", -50., 70., 0., 0.);
66 CalibrationsNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%1.0f", 0., 9., 1., 0.);
67 CalibrationsNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%1.0f", 0., 9., 1., 0.);
68 CalibrationsNP[2].
fill(
"AMBIENT",
"Ambient",
"%1.0f", 0., 9., 1., 0.);
72 ThresholdsNP[0].
fill(
"CHANNEL1",
"Channel 1",
"%1.0f", 0., 9., 1., 0.);
73 ThresholdsNP[1].
fill(
"CHANNEL2",
"Channel 2",
"%1.0f", 0., 9., 1., 0.);
77 AggressivityNP[0].
fill(
"AGGRESSIVITY",
"Aggressivity",
"%1.0f", 1., 4., 1., 1.);
82 AutoModeSP[1].
fill(
"AUTO",
"Automatic",
ISS_ON);
86 LinkOut23SP[0].
fill(
"INDEPENDENT",
"Independent",
ISS_ON);
95 FWversionNP[0].
fill(
"FIRMWARE",
"Firmware Version",
"%4.0f", 0., 65535., 1., 0.);
119 DefaultDevice::updateProperties();
137 LOG_INFO(
"USB_Dewpoint parameters updated, device ready for use.");
160 return "USB_Dewpoint";
163 bool USBDewpoint::sendCommand(
const char *
cmd,
char *resp)
165 int nbytes_written = 0, nbytes_read = 0, rc = -1;
169 tcflush(PortFD, TCIOFLUSH);
182 LOGF_ERROR(
"Error reading response for command %s: %s.",
cmd, errstr);
188 LOGF_ERROR(
"Invalid response for command %s: %s.",
cmd, resp);
191 resp[nbytes_read - 2] =
'\0';
197 bool USBDewpoint::Resync()
200 int nbytes_written = 0, nbytes_read = 0, rc = -1;
207 tcflush(PortFD, TCIOFLUSH);
209 for (
int resync = 0; resync <
UDP_CMD_LEN; resync++)
216 LOGF_ERROR(
"Error writing resync: %s.", errstr);
221 if (rc ==
TTY_OK && nbytes_read > 0)
232 bool USBDewpoint::Handshake()
241 LOG_INFO(
"USB_Dewpoint is online. Getting device parameters...");
244 LOG_INFO(
"Error retrieving data from USB_Dewpoint, trying resync...");
246 while (--tries > 0 && Resync());
248 LOG_INFO(
"Error retrieving data from USB_Dewpoint, please ensure controller "
249 "is powered and the port is correct.");
253 bool USBDewpoint::Ack()
256 tcflush(PortFD, TCIOFLUSH);
267 LOGF_ERROR(
"USB_Dewpoint not properly identified! Answer was: %s.", resp);
271 FWversionNP[0].setValue(firmware);
277 bool USBDewpoint::setOutput(
unsigned int channel,
unsigned int value)
283 return sendCommand(
cmd, resp);
286 bool USBDewpoint::setCalibrations(
unsigned int ch1,
unsigned int ch2,
unsigned int ambient)
292 return sendCommand(
cmd, resp);
295 bool USBDewpoint::setThresholds(
unsigned int ch1,
unsigned int ch2)
301 return sendCommand(
cmd, resp);
304 bool USBDewpoint::setAggressivity(
unsigned int aggressivity)
310 return sendCommand(
cmd, resp);
313 bool USBDewpoint::reset()
319 bool USBDewpoint::setAutoMode(
bool enable)
325 return sendCommand(
cmd, resp);
328 bool USBDewpoint::setLinkMode(
bool enable)
334 return sendCommand(
cmd, resp);
344 AutoModeSP.
update(states, names, n);
348 setAutoMode(target_mode == 1);
354 LinkOut23SP.
update(states, names, n);
358 setLinkMode(target_mode == 1);
393 LOG_WARN(
"Setting output power is ignored in auto mode!");
396 OutputsNP.
update(values, names, n);
399 setOutput(1, OutputsNP[0].getValue());
400 setOutput(2, OutputsNP[1].getValue());
401 setOutput(3, OutputsNP[2].getValue());
407 CalibrationsNP.
update(values, names, n);
409 CalibrationsNP.
apply();
410 setCalibrations(CalibrationsNP[0].getValue(), CalibrationsNP[1].getValue(), CalibrationsNP[2].getValue());
416 ThresholdsNP.
update(values, names, n);
418 ThresholdsNP.
apply();
419 setThresholds(ThresholdsNP[0].getValue(), ThresholdsNP[1].getValue());
425 AggressivityNP.
update(values, names, n);
427 AggressivityNP.
apply();
428 setAggressivity(AggressivityNP[0].getValue());
434 FWversionNP.
update(values, names, n);
443 bool USBDewpoint::readSettings()
453 float temp1, temp2, temp_ambient, humidity, dewpoint;
454 unsigned int output1, output2, output3;
455 unsigned int calibration1, calibration2, calibration_ambient;
456 unsigned int threshold1, threshold2;
457 unsigned int automode, linkout23, aggressivity;
459 int ok = sscanf(resp,
UDP_STATUS_RESPONSE, &temp1, &temp2, &temp_ambient, &humidity, &dewpoint, &output1, &output2,
460 &output3, &calibration1, &calibration2, &calibration_ambient, &threshold1, &threshold2, &automode,
461 &linkout23, &aggressivity);
465 TemperaturesNP[0].setValue(temp1);
466 TemperaturesNP[1].setValue(temp2);
467 TemperaturesNP[2].setValue(temp_ambient);
469 TemperaturesNP.
apply();
471 HumidityNP[0].setValue(humidity);
475 DewpointNP[0].setValue(dewpoint);
479 OutputsNP[0].setValue(output1);
480 OutputsNP[1].setValue(output2);
481 OutputsNP[2].setValue(output3);
485 CalibrationsNP[0].setValue(calibration1);
486 CalibrationsNP[1].setValue(calibration2);
487 CalibrationsNP[2].setValue(calibration_ambient);
489 CalibrationsNP.
apply();
491 ThresholdsNP[0].setValue(threshold1);
492 ThresholdsNP[1].setValue(threshold2);
494 ThresholdsNP.
apply();
506 AggressivityNP[0].setValue(aggressivity);
508 AggressivityNP.
apply();
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 ...
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 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....
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
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)
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....
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,...)
std::unique_ptr< USBDewpoint > usbDewpoint(new USBDewpoint())
#define USBDEWPOINT_TIMEOUT
#define UDP_CALIBRATION_CMD
#define UDP_IDENTIFY_RESPONSE
#define UDP_AGGRESSIVITY_CMD
#define UDP_STATUS_RESPONSE
#define UDP_THRESHOLD_CMD