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",
"");
147 "Error retrieving data from %s, please ensure device is powered and the port is correct.", this->
getDeviceName());
153 return "Pegasus FocusCube";
156bool PegasusFocusCube::ack()
158 int nbytes_written = 0, nbytes_read = 0, rc = -1;
168 tcflush(
PortFD, TCIOFLUSH);
185 res[nbytes_read - 1] = 0;
188 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
192 tcflush(
PortFD, TCIOFLUSH);
194 if(strstr(res,
"OK_FC") !=
nullptr)
203 int nbytes_written = 0, rc = -1;
206 snprintf(
cmd, 16,
"W:%ud", ticks);
220 this->ignoreResponse();
225bool PegasusFocusCube::move(uint32_t newPosition)
227 int nbytes_written = 0, rc = -1;
230 snprintf(
cmd, 16,
"M:%ud", newPosition);
244 this->ignoreResponse();
255 if (!strcmp(name, EncoderSP.
name))
258 bool rc = setEncodersEnabled(EncoderS[ENCODERS_ON].s ==
ISS_ON);
265 if (!strcmp(name, LEDSP.
name))
268 bool rc = setLedEnabled(LEDS[LED_ON].s ==
ISS_ON);
282 if (strcmp(name, MaxSpeedNP.
name) == 0)
285 bool rc = setMaxSpeed(MaxSpeedN[0].value);
296void PegasusFocusCube::ignoreResponse()
303bool PegasusFocusCube::updateFocusParams()
305 int nbytes_written = 0, nbytes_read = 0, rc = -1;
314 tcflush(
PortFD, TCIOFLUSH);
319 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
327 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
331 res[nbytes_read - 1] = 0;
334 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
338 tcflush(
PortFD, TCIOFLUSH);
340 char *token = std::strtok(res,
":");
343 if (token ==
nullptr || (strstr(token,
"OK_FC") ==
nullptr))
345 LOGF_ERROR(
"Invalid status response. %s", res);
350 token = std::strtok(
nullptr,
":");
352 if (token ==
nullptr)
358 if (FirmwareVersionT[0].text ==
nullptr || strcmp(FirmwareVersionT[0].text, token))
366 token = std::strtok(
nullptr,
":");
369 token = std::strtok(
nullptr,
":");
371 if (token ==
nullptr)
373 LOG_ERROR(
"Invalid temperature response.");
394 token = std::strtok(
nullptr,
":");
396 if (token ==
nullptr)
402 currentPosition = atoi(token);
410 token = std::strtok(
nullptr,
":");
412 if (token ==
nullptr)
414 LOG_ERROR(
"Invalid moving status response.");
418 isMoving = (token[0] ==
'1');
421 token = std::strtok(
nullptr,
":");
423 if (token ==
nullptr)
429 int ledStatus = atoi(token);
430 if (ledStatus >= 0 && ledStatus <= 1)
433 LEDS[ledStatus].s =
ISS_ON;
439 token = std::strtok(
nullptr,
":");
441 if (token ==
nullptr)
447 int reverseStatus = atoi(token);
448 if (reverseStatus >= 0 && reverseStatus <= 1)
458 token = std::strtok(
nullptr,
":");
460 if (token ==
nullptr)
466 int encoderStatus = atoi(token);
467 if (encoderStatus >= 0 && encoderStatus <= 1)
470 EncoderS[encoderStatus].s =
ISS_ON;
476 token = std::strtok(
nullptr,
":");
478 if (token ==
nullptr)
484 int backlash = atoi(token);
488 LOG_WARN(
"Backlash value is zero, disabling backlash switch...");
516bool PegasusFocusCube::setMaxSpeed(uint16_t speed)
518 int nbytes_written = 0, rc = -1;
521 snprintf(
cmd, 16,
"S:%d", speed);
526 tcflush(
PortFD, TCIOFLUSH);
537 this->ignoreResponse();
543 int nbytes_written = 0, rc = -1;
546 snprintf(
cmd, 16,
"N:%d", enabled ? 1 : 0);
551 tcflush(
PortFD, TCIOFLUSH);
562 this->ignoreResponse();
567bool PegasusFocusCube::setLedEnabled(
bool enable)
569 int nbytes_written = 0, rc = -1;
572 snprintf(
cmd, 16,
"L:%d", enable ? 2 : 1);
577 tcflush(
PortFD, TCIOFLUSH);
588 this->ignoreResponse();
592bool PegasusFocusCube::setEncodersEnabled(
bool enable)
594 int nbytes_written = 0, rc = -1;
597 snprintf(
cmd, 16,
"E:%d", enable ? 0 : 1);
602 tcflush(
PortFD, TCIOFLUSH);
613 this->ignoreResponse();
619 int nbytes_written = 0, rc = -1;
622 snprintf(
cmd, 16,
"C:%d", steps);
627 tcflush(
PortFD, TCIOFLUSH);
638 this->ignoreResponse();
653 targetPosition = targetTicks;
655 bool rc = move(targetPosition);
667 double newPosition = 0;
675 rc = move(newPosition);
694 bool rc = updateFocusParams();
700 if (isMoving ==
false)
706 LOG_INFO(
"Focuser reached requested position.");
717 char cmd[2] = {
'H', 0xA };
725 this->ignoreResponse();
void setPortMatchPattern(const std::string &pattern)
setPortMatchPattern Set a regex pattern used to automatically select a serial port from the discovere...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
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.
INDI::PropertyNumber FocusRelPosNP
INDI::PropertySwitch FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusMaxPosNP
INDI::PropertySwitch FocusBacklashSP
INDI::PropertyNumber FocusBacklashNP
INDI::PropertyNumber FocusAbsPosNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual bool saveConfigItems(FILE *fp) override
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
Connection::Serial * serialConnection
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
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
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
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
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
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
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
#define TEMPERATURE_THRESHOLD
#define FOCUS_SETTINGS_TAB
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,...)