34#define iEAFFOCUS_TIMEOUT 10
35#define TEMPERATURE_THRESHOLD 0.1
36#define ROTATOR_TAB "Rotator"
71 TemperatureNP[0].
fill(
"TEMPERATURE",
"Celsius",
"%2.2f", 0., 50., 0., 50.);
74 SetZeroSP[0].
fill(
"SETZERO",
"Sync Focuser Position To 0",
ISS_OFF);
92 FirmwareTP[0].
fill(
"VERSION",
"Version",
"NA");
95 StatusTP[0].
fill(
"STATUS",
"CAA Status",
"NA");
100 RotatorSize[0].
fill(
"CAASIZE",
"CAA Size (inch)",
"%.1f", 2.0, 4.0, 1.0, 0);
163 return "iAFSRotator";
170bool iAFSRotator::Ack()
172 int nbytes_written = 0, nbytes_read = 0, rc = -1;
174 int ieafpos, ieafmodel, ieaflast;
176 tcflush(
PortFD, TCIOFLUSH);
192 tcflush(
PortFD, TCIOFLUSH);
193 resp[nbytes_read] =
'\0';
194 sscanf(resp,
"%6d%2d%4d", &ieafpos, &ieafmodel, &ieaflast);
212bool iAFSRotator::getFirmware()
214 int nbytes_written = 0, nbytes_read = 0, rc = -1;
217 char joefirmwareinfo[16] = {0};
218 char iafsfirm[7] = {0};
219 char caafirm[7] = {0};
220 tcflush(
PortFD, TCIOFLUSH);
233 tcflush(
PortFD, TCIOFLUSH);
234 resp[nbytes_read] =
'\0';
235 sscanf(resp,
"%12s", joefirmwareinfo);
236 rc = sscanf(resp,
"%6s%6s", iafsfirm, caafirm);
237 FirmwareTP[0].setText(caafirm);
246bool iAFSRotator::updateInfo()
248 int nbytes_written = 0, nbytes_read = 0, rc = -1;
251 char joedeviceinfo[16] = {0};
252 int ieafpos, ieafmove, ieaftemp, ieafdir;
254 tcflush(
PortFD, TCIOFLUSH);
268 tcflush(
PortFD, TCIOFLUSH);
270 resp[nbytes_read] =
'\0';
272 sscanf(resp,
"%14s", joedeviceinfo);
273 rc = sscanf(resp,
"%7d%1d%5d%1d", &ieafpos, &ieafmove, &ieaftemp, &ieafdir);
278 LOGF_ERROR(
"Could not parse response %s", resp);
282 m_isMoving = ieafmove == 1;
284 m_Reversed = (ieafdir == 0);
291 TemperatureNP.
apply();
296 if (m_Reversed != currentlyReversed)
333bool iAFSRotator::updateInforotator()
335 int nbytes_written = 0, nbytes_read = 0, rc = -1;
338 char joedeviceinfo[25] = {0};
339 int ieafposdelta, ieafmove, ieafcurrpos, ieafdir,ieafsize;
340 double ieafcurrangle;
342 tcflush(
PortFD, TCIOFLUSH);
356 tcflush(
PortFD, TCIOFLUSH);
358 resp[nbytes_read] =
'\0';
360 sscanf(resp,
"%23s", joedeviceinfo);
361 rc = sscanf(resp,
"%10d%1d%9d%1d%2d", &ieafposdelta, &ieafmove, &ieafcurrpos, &ieafdir,&ieafsize);
366 LOGF_ERROR(
"Could not parse response %s", resp);
370 mr_isMoving = ieafmove == 1;
371 StatusTP[0].setText(mr_isMoving ?
"Move" :
"Stop");
373 mr_Reversed = (ieafdir == 0);
375 fieafsize = ieafsize/10.0;
376 if (fieafsize != RotatorSize[0].getValue())
378 RotatorSize[0].setValue(fieafsize);
386 if (mr_Reversed != currentlyReversed)
395 ieafcurrangle=ieafcurrpos/360000.0;
396 if ( ieafcurrangle>=360.0)
398 ieafcurrangle= ieafcurrangle-360;
400 if ( ieafcurrangle<0.0)
402 ieafcurrangle= ieafcurrangle+360;
443bool iAFSRotator::MoveMyFocuser(uint32_t position)
445 int nbytes_written = 0, rc = -1;
448 snprintf(
cmd, 12,
":FM%07u#", position);
450 tcflush(
PortFD, TCIOFLUSH);
468 int nbytes_written = 0, rc = -1;
471 if (enabled == m_Reversed)
477 tcflush(
PortFD, TCIOFLUSH);
493void iAFSRotator::setZero()
495 int nbytes_written = 0, rc = -1;
497 tcflush(
PortFD, TCIOFLUSH);
551void iAFSRotator::GetFocusParams ()
563 uint32_t targetPos = targetTicks;
567 rc = MoveMyFocuser(targetPos);
583 int relativeTicks = ((dir ==
FOCUS_INWARD) ? -ticks : ticks) * (m_Reversed ? -1 : 1);
584 uint32_t newPosition =
FocusAbsPosNP[0].getValue() + relativeTicks;
585 newPosition = std::max(0u, std::min(
static_cast<uint32_t
>(
FocusAbsPosNP[0].getMax()), newPosition));
587 auto rc = MoveMyFocuser(newPosition);
619 tcflush(
PortFD, TCIOFLUSH);
640 tcflush(
PortFD, TCIOFLUSH);
658 int nbytes_written = 0, rc = -1;
660 int position=
round(angle*3600*100);
661 snprintf(
cmd, 14,
":RY%09u#", position);
663 tcflush(
PortFD, TCIOFLUSH);
684 int nbytes_written = 0, rc = -1;
689 tcflush(
PortFD, TCIOFLUSH);
705 tcflush(
PortFD, TCIOFLUSH);
724bool iAFSRotator::MoveMyRotator(
double angle)
726 int nbytes_written = 0, rc = -1;
728 int position=(angle*3600*100);
729 snprintf(
cmd, 14,
":RM%09u#", position);
730 tcflush(
PortFD, TCIOFLUSH);
742 tcflush(
PortFD, TCIFLUSH);
752 IPState state = MoveAbsRotatorAngle(angle);
764IPState iAFSRotator::MoveAbsRotatorAngle(
double angle)
766 int nbytes_written = 0, rc = -1;
768 int position=(angle*3600*100);
769 snprintf(
cmd, 14,
":RM%09u#", position);
770 tcflush(
PortFD, TCIOFLUSH);
782 tcflush(
PortFD, TCIFLUSH);
791bool iAFSRotator::setCaaSize(
double caasize)
793 int nbytes_written = 0, rc = -1;
795 int position=
round(caasize*10);
796 snprintf(
cmd, 14,
":RS%02u#", position);
797 tcflush(
PortFD, TCIOFLUSH);
802 LOGF_ERROR(
"set CAA Size error: %s.", errstr);
842 RotatorSize.
update(values, names, n);
843 if (setCaaSize(RotatorSize[0].getValue()))
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 setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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.
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
void defineProperty(INumberVectorProperty *property)
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
uint32_t getDriverInterface() const
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
INDI::PropertyNumber FocusRelPosNP
INDI::PropertySwitch FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
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 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, ISRule rule, double timeout, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
INDI::PropertySwitch AbortRotatorSP
void initProperties(const char *groupName)
Initialize Rotator properties. It is recommended to call this function within initProperties() of you...
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
INDI::PropertyNumber SyncRotatorNP
INDI::PropertySwitch ReverseRotatorSP
INDI::PropertyNumber GotoRotatorNP
Provides interface to implement Rotator functionality.
virtual bool SyncRotator(double angle) override
SyncRotator Set current angle as the supplied angle without moving the rotator.
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...
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 ticks) override
MoveFocuser the focuser to an absolute position.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool AbortRotator() override
AbortRotator Abort all motion.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
const char * getDefaultName() override
virtual bool ReverseRotator(bool enabled) override
ReverseRotator Reverse the direction of the rotator. CW is usually the normal direction,...
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
virtual IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
#define TEMPERATURE_THRESHOLD
std::unique_ptr< iAFSRotator > iafsRotator(new iAFSRotator())
#define iEAFFOCUS_TIMEOUT
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.
#define DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
#define LOGF_ERROR(fmt,...)
#define DEBUGF(priority, msg,...)
double round(double value, int decimal_places)