36 #define DMFC_TIMEOUT 3
37 #define FOCUS_SETTINGS_TAB "Settings"
38 #define TEMPERATURE_THRESHOLD 0.1
58 IUFillNumber(&TemperatureN[0],
"TEMPERATURE",
"Celsius",
"%6.2f", -50, 70., 0., 0.);
63 IUFillNumber(&MaxSpeedN[0],
"Value",
"",
"%6.2f", 100, 1000., 100., 400.);
69 IUFillSwitchVector(&EncoderSP, EncoderS, 2,
getDeviceName(),
"Encoders",
"",
FOCUS_SETTINGS_TAB,
IP_RW,
ISR_1OFMANY, 0,
75 IUFillSwitchVector(&LEDSP, LEDS, 2,
getDeviceName(),
"LED",
"",
FOCUS_SETTINGS_TAB,
IP_RW,
ISR_1OFMANY, 0,
IPS_IDLE);
78 IUFillText(&FirmwareVersionT[0],
"Version",
"Version",
"");
146 "Error retrieving data from %s, please ensure device is powered and the port is correct.", this->
getDeviceName());
152 return "Pegasus FocusCube";
155 bool PegasusFocusCube::ack()
157 int nbytes_written = 0, nbytes_read = 0, rc = -1;
167 tcflush(
PortFD, TCIOFLUSH);
184 res[nbytes_read - 1] = 0;
187 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
191 tcflush(
PortFD, TCIOFLUSH);
193 if(strstr(res,
"OK_FC") !=
nullptr)
202 int nbytes_written = 0, rc = -1;
205 snprintf(
cmd, 16,
"W:%ud", ticks);
219 this->ignoreResponse();
224 bool PegasusFocusCube::move(uint32_t newPosition)
226 int nbytes_written = 0, rc = -1;
229 snprintf(
cmd, 16,
"M:%ud", newPosition);
243 this->ignoreResponse();
254 if (!strcmp(name, EncoderSP.
name))
257 bool rc = setEncodersEnabled(EncoderS[ENCODERS_ON].s ==
ISS_ON);
264 if (!strcmp(name, LEDSP.
name))
267 bool rc = setLedEnabled(LEDS[LED_ON].s ==
ISS_ON);
281 if (strcmp(name, MaxSpeedNP.
name) == 0)
284 bool rc = setMaxSpeed(MaxSpeedN[0].value);
295 void PegasusFocusCube::ignoreResponse()
302 bool PegasusFocusCube::updateFocusParams()
304 int nbytes_written = 0, nbytes_read = 0, rc = -1;
313 tcflush(
PortFD, TCIOFLUSH);
318 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
326 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
330 res[nbytes_read - 1] = 0;
333 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
337 tcflush(
PortFD, TCIOFLUSH);
339 char *token = std::strtok(res,
":");
342 if (token ==
nullptr || (strstr(token,
"OK_FC") ==
nullptr))
344 LOGF_ERROR(
"Invalid status response. %s", res);
349 token = std::strtok(
nullptr,
":");
351 if (token ==
nullptr)
357 if (FirmwareVersionT[0].text ==
nullptr || strcmp(FirmwareVersionT[0].text, token))
365 token = std::strtok(
nullptr,
":");
368 token = std::strtok(
nullptr,
":");
370 if (token ==
nullptr)
372 LOG_ERROR(
"Invalid temperature response.");
376 double temperature = atof(token);
377 if (temperature == -127)
386 TemperatureN[0].value = temperature;
393 token = std::strtok(
nullptr,
":");
395 if (token ==
nullptr)
401 currentPosition = atoi(token);
409 token = std::strtok(
nullptr,
":");
411 if (token ==
nullptr)
413 LOG_ERROR(
"Invalid moving status response.");
417 isMoving = (token[0] ==
'1');
420 token = std::strtok(
nullptr,
":");
422 if (token ==
nullptr)
428 int ledStatus = atoi(token);
429 if (ledStatus >= 0 && ledStatus <= 1)
432 LEDS[ledStatus].s =
ISS_ON;
438 token = std::strtok(
nullptr,
":");
440 if (token ==
nullptr)
446 int reverseStatus = atoi(token);
447 if (reverseStatus >= 0 && reverseStatus <= 1)
457 token = std::strtok(
nullptr,
":");
459 if (token ==
nullptr)
465 int encoderStatus = atoi(token);
466 if (encoderStatus >= 0 && encoderStatus <= 1)
469 EncoderS[encoderStatus].s =
ISS_ON;
475 token = std::strtok(
nullptr,
":");
477 if (token ==
nullptr)
483 int backlash = atoi(token);
487 LOG_WARN(
"Backlash value is zero, disabling backlash switch...");
515 bool PegasusFocusCube::setMaxSpeed(uint16_t speed)
517 int nbytes_written = 0, rc = -1;
520 snprintf(
cmd, 16,
"S:%d", speed);
525 tcflush(
PortFD, TCIOFLUSH);
536 this->ignoreResponse();
542 int nbytes_written = 0, rc = -1;
545 snprintf(
cmd, 16,
"N:%d", enabled ? 1 : 0);
550 tcflush(
PortFD, TCIOFLUSH);
561 this->ignoreResponse();
566 bool PegasusFocusCube::setLedEnabled(
bool enable)
568 int nbytes_written = 0, rc = -1;
571 snprintf(
cmd, 16,
"L:%d", enable ? 2 : 1);
576 tcflush(
PortFD, TCIOFLUSH);
587 this->ignoreResponse();
591 bool PegasusFocusCube::setEncodersEnabled(
bool enable)
593 int nbytes_written = 0, rc = -1;
596 snprintf(
cmd, 16,
"E:%d", enable ? 0 : 1);
601 tcflush(
PortFD, TCIOFLUSH);
612 this->ignoreResponse();
618 int nbytes_written = 0, rc = -1;
621 snprintf(
cmd, 16,
"C:%d", steps);
626 tcflush(
PortFD, TCIOFLUSH);
637 this->ignoreResponse();
652 targetPosition = targetTicks;
654 bool rc = move(targetPosition);
666 double newPosition = 0;
674 rc = move(newPosition);
693 bool rc = updateFocusParams();
699 if (isMoving ==
false)
705 LOG_INFO(
"Focuser reached requested position.");
716 char cmd[2] = {
'H', 0xA };
724 this->ignoreResponse();
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
const char * getDeviceName() const
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
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.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
INumberVectorProperty FocusBacklashNP
ISwitchVectorProperty FocusBacklashSP
INumberVectorProperty FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
ISwitchVectorProperty FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INumber FocusBacklashN[1]
ISwitch FocusBacklashS[2]
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Connection::Serial * serialConnection
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
const char * getDefaultName() override
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool Handshake() override
perform handshake with device to check communication
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
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.
Implementations for common driver routines.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#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 TEMPERATURE_THRESHOLD
#define FOCUS_SETTINGS_TAB