37#define FOCUS_SETTINGS_TAB "Settings"
38#define TEMPERATURE_THRESHOLD 0.1
58 int tty_rc = 0, nbytes_written = 0, nbytes_read = 0;
66 tcflush(
PortFD, TCIOFLUSH);
72 LOGF_ERROR(
"Serial write error: %s", errorMessage);
82 tcflush(
PortFD, TCIOFLUSH);
92 LOGF_ERROR(
"Serial read error: %s", errorMessage);
97 tcflush(
PortFD, TCIOFLUSH);
98 response[nbytes_read - 1] =
'\0';
103 return (strstr(response,
"FC3") !=
nullptr);
108 return "Pegasus FocusCube3";
115 TemperatureNP[0].
fill(
"TEMPERATURE",
"Level",
"%.0f", -40, 40, 1, 0);
118 FirmwareVersionTP[0].
fill(
"Version",
"Version",
"");
121 SpeedNP[0].
fill(
"Speed",
"Value",
"%6.2f", 100, 1000., 100., 400.);
161 std::string firmware = getFirmwareVersion();
162 FirmwareVersionTP[0].setText(firmware);
164 FirmwareVersionTP.
apply();
187 SpeedNP.
update(values, names, n);
191 if(!setSpeed(values[0]))
207 targetPosition = targetTicks;
209 bool rc = move(targetPosition);
221 double newPosition = 0;
229 rc = move(newPosition);
240bool PegasusFocusCube3::move(uint32_t newPosition)
243 snprintf(expectedResponse,
PEGASUS_LEN,
"%u", newPosition);
247 if(!strstr(expectedResponse, res))
255 LOGF_ERROR(
"Error on move [Position=%d]", newPosition);
264 int nbytes_read = 0, nbytes_written = 0, tty_rc = 0;
268 for (
int i = 0; i < 2; i++)
270 tcflush(
PortFD, TCIOFLUSH);
277 tcflush(
PortFD, TCIOFLUSH);
285 tcflush(
PortFD, TCIOFLUSH);
286 res[nbytes_read - 1] =
'\0';
301bool PegasusFocusCube3::setSpeed(uint16_t speed)
305 snprintf(expectedResponse,
PEGASUS_LEN,
"%u", speed);
309 if(!strstr(
cmd, res))
317 LOGF_ERROR(
"Error on set speed [Speed=%d]", speed);
323std::string PegasusFocusCube3::getFirmwareVersion()
341 std::regex re(regex);
342 std::sregex_token_iterator
343 first{input.begin(), input.end(), re, -1},
345 return {first, last};
373 snprintf(expectedResponse,
PEGASUS_LEN,
"%u", ticks);
377 if(!strstr(expectedResponse, res))
412 snprintf(expectedResponse,
PEGASUS_LEN,
"%u", steps);
416 if(!strstr(expectedResponse, res))
439 bool rc = updateFocusParams();
445 if (isMoving ==
false)
451 LOG_INFO(
"Focuser reached requested position.");
459bool PegasusFocusCube3::updateFocusParams()
473 std::vector<std::string> result =
split(res,
":");
476 if(result[0] !=
"FC3")
481 currentPosition = atoi(result[1].c_str());
489 isMoving = (result[2] ==
"1");
493 TemperatureNP[0].setValue(atof(result[3].c_str()));
495 TemperatureNP.
apply();
499 int reverseStatus = atoi(result[4].c_str());
500 if (reverseStatus >= 0 && reverseStatus <= 1)
512 int backlash = atoi(result[5].c_str());
516 LOG_WARN(
"Backlash value is zero, disabling backlash switch...");
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.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
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 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
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)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
static constexpr const uint8_t PEGASUS_LEN
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
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 SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
static constexpr const uint8_t PEGASUS_TIMEOUT
bool sendCommand(const char *cmd, char *res)
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
const char * getDefaultName() override
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
std::vector< std::string > split(const std::string &input, const std::string ®ex)
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 FOCUS_SETTINGS_TAB
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_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,...)