32 #define ONFOCUS_TIMEOUT 4
34 #define POLLMS_OVERRIDE 1500
53 IUFillSwitchVector(&SetZeroSP, SetZeroS, 1,
getDeviceName(),
"Zero Position",
"",
OPTIONS_TAB,
IP_RW,
ISR_1OFMANY, 0,
56 IUFillNumber(&MaxPosN[0],
"MAXPOS",
"Maximum Out Position",
"%8.0f", 1., 10000000., 0, 0);
116 int nbytes_written = 0, nbytes_read = 0, rc = -1;
120 tcflush(
PortFD, TCIOFLUSH);
134 tcflush(
PortFD, TCIOFLUSH);
135 resp[nbytes_read] =
'\0';
136 if (!strcmp(resp,
"On-Focus#"))
148 bool OnFocus::updatePosition()
150 int nbytes_written = 0, nbytes_read = 0, rc = -1;
155 tcflush(
PortFD, TCIOFLUSH);
171 tcflush(
PortFD, TCIOFLUSH);
173 resp[nbytes_read] =
'\0';
175 rc = sscanf(resp,
"%d#", &pos);
192 bool OnFocus::updateMaxPos()
194 int nbytes_written = 0, nbytes_read = 0, rc = -1;
199 tcflush(
PortFD, TCIOFLUSH);
215 tcflush(
PortFD, TCIOFLUSH);
216 resp[nbytes_read] =
'\0';
218 rc = sscanf(resp,
"%ld#", &maxposition);
223 MaxPosN[0].value = maxposition;
234 bool OnFocus::isMoving()
236 int nbytes_written = 0, nbytes_read = 0, rc = -1;
240 tcflush(
PortFD, TCIOFLUSH);
256 tcflush(
PortFD, TCIOFLUSH);
258 resp[nbytes_read] =
'\0';
259 if (!strcmp(resp,
"M#"))
261 else if (!strcmp(resp,
"S#"))
271 bool OnFocus::MoveMyFocuser(uint32_t position)
273 int nbytes_written = 0, rc = -1;
277 snprintf(
cmd, 24,
":MA%d#", position);
289 void OnFocus::setZero()
291 int nbytes_written = 0, rc = -1;
305 bool OnFocus::setMaxPos(uint32_t maxPos)
307 int nbytes_written = 0, rc = -1;
311 snprintf(
cmd, 24,
":SM%d#", maxPos);
328 if (!strcmp(SetZeroSP.
name, name))
346 if (!strcmp (name, MaxPosNP.
name))
356 setMaxPos(MaxPosN[0].value);
366 void OnFocus::GetFocusParams ()
375 uint32_t targetPos = targetTicks;
379 rc = MoveMyFocuser(targetPos);
391 uint32_t newPosition = 0;
399 rc = MoveMyFocuser(newPosition);
418 bool rc = updatePosition();
431 if (isMoving() ==
false)
const char * getDeviceName() const
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
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 FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
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.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState MoveAbsFocuser(uint32_t ticks) override
MoveFocuser the focuser to an absolute position.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
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.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
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.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
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 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 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.
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.
#define DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
#define DEBUGF(priority, msg,...)
std::unique_ptr< OnFocus > onFocus(new OnFocus())