31static std::unique_ptr<FocuserDriver> focuserDriver(
new FocuserDriver());
50 IUFillNumber(&TemperatureN[0],
"TEMPERATURE",
"Celsius",
"%6.2f", -100, 100, 0, 0);
81 return "Focuser Driver";
96 if (readTemperature())
99 bool rc = getStartupValues();
105 LOG_INFO(
"FocuserDriver is ready.");
107 LOG_WARN(
"Failed to query startup values.");
127 char cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0};
132 bool rc = sendCommand(
cmd, res, 1, 1);
136 return res[0] ==
'S';
139bool FocuserDriver::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
141 int nbytes_written = 0, nbytes_read = 0, rc = -1;
143 tcflush(
PortFD, TCIOFLUSH);
147 char hex_cmd[DRIVER_LEN * 3] = {0};
148 hexDump(hex_cmd,
cmd, cmd_len);
162 LOGF_ERROR(
"Serial write error: %s.", errstr);
170 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
184 char hex_res[DRIVER_LEN * 3] = {0};
185 hexDump(hex_res, res, res_len);
193 tcflush(
PortFD, TCIOFLUSH);
198void FocuserDriver::hexDump(
char * buf,
const char * data,
int size)
200 for (
int i = 0; i < size; i++)
201 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
204 buf[3 * size - 1] =
'\0';
212 if (!strcmp(name, SteppingModeSP.
name))
224bool FocuserDriver::getStartupValues()
226 bool rc1 = readStepping();
243 m_TargetDiff = ticks * ((dir ==
FOCUS_INWARD) ? -1 : 1);
249 return sendCommand(
"FOOBAR");
280 if (TemperatureNP.
s ==
IPS_OK && m_TemperatureCounter++ == DRIVER_TEMPERATURE_FREQ)
282 m_TemperatureCounter = 0;
283 if (readTemperature())
290bool FocuserDriver::isMoving()
292 char res[DRIVER_LEN] = {0};
294 bool rc = sendCommand(
"FOOBAR", res, 1, 1);
296 if (rc && !strcmp(res,
"STOPPED"))
302bool FocuserDriver::readTemperature()
304 char res[DRIVER_LEN] = {0};
309 if (sendCommand(
"FOOBAR", res, strlen(
"FOOBAR"), 4) ==
false)
324bool FocuserDriver::readPosition()
326 char cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0};
334 if (sendCommand(
cmd, res, 3, 7) ==
false)
342 sscanf(res,
"%d", &pos);
352bool FocuserDriver::readStepping()
354 char res[DRIVER_LEN] = {0};
356 if (sendCommand(
"FOOBAR", res, 3, 1) ==
false)
360 sscanf(res,
"%d", &mode);
367 SteppingModeS[STEPPING_FULL].s = (mode == 10) ?
ISS_ON :
ISS_OFF;
368 SteppingModeS[STEPPING_HALF].s = (mode == 10) ?
ISS_OFF :
ISS_ON;
377 char cmd[DRIVER_LEN] = {0};
378 snprintf(
cmd, DRIVER_LEN,
"#:SYNC+%06d#", ticks);
379 return sendCommand(
cmd);
382bool FocuserDriver::setStepping(SteppingMode mode)
384 char cmd[DRIVER_LEN] = {0};
385 snprintf(
cmd, DRIVER_LEN,
"#FOOBAR%01d#", mode);
386 return sendCommand(
cmd);
bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
const char * getDefaultName() override
bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
bool AbortFocuser() override
AbortFocuser all focus motion.
bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
bool saveConfigItems(FILE *fp) override
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
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...
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
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusSpeedNP
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,...
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
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.
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 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 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,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)