38#define FOCUS_SETTINGS_TAB "Settings"
39#define TEMPERATURE_THRESHOLD 0.1
60 IUFillSwitchVector(&LEDSP, LEDS, 2,
getDeviceName(),
"LED",
"",
FOCUS_SETTINGS_TAB,
IP_RW,
ISR_1OFMANY, 0,
IPS_IDLE);
63 IUFillText(&FirmwareVersionT[0],
"Version",
"Version",
"");
126 "Error retrieving data from %s, please ensure device is powered and the port is correct.", this->
getDeviceName());
133 return "Pegasus ScopsOAG";
136bool PegasusScopsOAG::ack()
138 int nbytes_written = 0, nbytes_read = 0, rc = -1;
148 tcflush(
PortFD, TCIOFLUSH);
165 res[nbytes_read - 1] = 0;
168 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
172 tcflush(
PortFD, TCIOFLUSH);
176 if((strstr(res,
"OK_SCOPS") !=
nullptr))
185 int nbytes_written = 0, rc = -1;
188 snprintf(
cmd, 16,
"W:%ud", ticks);
202 this->ignoreResponse();
207bool PegasusScopsOAG::move(uint32_t newPosition)
209 int nbytes_written = 0, rc = -1;
212 snprintf(
cmd, 16,
"M:%ud", newPosition);
226 this->ignoreResponse();
236 if (!strcmp(name, LEDSP.
name))
239 bool rc = setLedEnabled(LEDS[LED_ON].s ==
ISS_ON);
248void PegasusScopsOAG::ignoreResponse()
255bool PegasusScopsOAG::updateFocusParams()
257 int nbytes_written = 0, nbytes_read = 0, rc = -1;
266 tcflush(
PortFD, TCIOFLUSH);
271 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
279 LOGF_ERROR(
"GetFocusParams error: %s.", errstr);
283 res[nbytes_read - 1] = 0;
286 if( res[nbytes_read - 2] ==
'\r') res[nbytes_read - 2] = 0;
290 tcflush(
PortFD, TCIOFLUSH);
292 char *token = std::strtok(res,
":");
296 if (token ==
nullptr || ((strstr(token,
"OK_SCOPS") ==
nullptr)))
298 LOGF_ERROR(
"Invalid status response. %s", res);
303 token = std::strtok(
nullptr,
":");
305 if (token ==
nullptr)
311 if (FirmwareVersionT[0].text ==
nullptr || strcmp(FirmwareVersionT[0].text, token))
319 token = std::strtok(
nullptr,
":");
322 token = std::strtok(
nullptr,
":");
325 token = std::strtok(
nullptr,
":");
327 if (token ==
nullptr)
333 currentPosition = atoi(token);
341 token = std::strtok(
nullptr,
":");
343 if (token ==
nullptr)
345 LOG_ERROR(
"Invalid moving status response.");
349 isMoving = (token[0] ==
'1');
352 token = std::strtok(
nullptr,
":");
354 if (token ==
nullptr)
360 int ledStatus = atoi(token);
361 if (ledStatus >= 0 && ledStatus <= 1)
364 LEDS[ledStatus].s =
ISS_ON;
370 token = std::strtok(
nullptr,
":");
373 token = std::strtok(
nullptr,
":");
376 token = std::strtok(
nullptr,
":");
378 if (token ==
nullptr)
384 int backlash = atoi(token);
388 LOG_WARN(
"Backlash value is zero, disabling backlash switch...");
417bool PegasusScopsOAG::setLedEnabled(
bool enable)
419 int nbytes_written = 0, rc = -1;
422 snprintf(
cmd, 16,
"L:%d", enable ? 2 : 1);
427 tcflush(
PortFD, TCIOFLUSH);
438 this->ignoreResponse();
444 targetPosition = targetTicks;
446 bool rc = move(targetPosition);
458 double newPosition = 0;
466 rc = move(newPosition);
485 bool rc = updateFocusParams();
491 if (isMoving ==
false)
497 LOG_INFO(
"Focuser reached requested position.");
508 char cmd[2] = {
'H', 0xA };
516 this->ignoreResponse();
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::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,...
Connection::Serial * serialConnection
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
const char * getDefaultName() 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 AbortFocuser() override
AbortFocuser all focus motion.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
virtual bool saveConfigItems(FILE *fp) override
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
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 SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
#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 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 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 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 IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
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,...)