33 static std::unique_ptr<AAF2> aaf2(
new AAF2());
48 IUFillNumber(&TemperatureN[0],
"TEMPERATURE",
"Celsius",
"%6.2f", -50, 70., 0., 0.);
97 LOG_INFO(
"Error retrieving data from AAF2, please ensure AAF2 controller is powered and the port is correct.");
108 int nbytes_written = 0, nbytes_read = 0, rc = -1;
112 tcflush(
PortFD, TCIOFLUSH);
115 bool success =
false;
116 while (numChecks < 3 && !success)
123 if(!transmissionSuccess)
126 LOGF_ERROR(
"Handshake Attempt %i, tty transmission error: %s.", numChecks, errstr);
129 bool responseSuccess = (rc =
tty_read(
PortFD, resp, 4, DRIVER_TIMEOUT, &nbytes_read)) ==
TTY_OK;
133 LOGF_ERROR(
"Handshake Attempt %i, updatePosition response error: %s.", numChecks, errstr);
136 success = transmissionSuccess && responseSuccess;
141 LOG_INFO(
"Handshake failed after 3 attempts");
145 tcflush(
PortFD, TCIOFLUSH);
147 return !strcmp(resp,
"OK!#");
151 bool AAF2::readTemperature()
153 char res[DRIVER_RES] = {0};
155 if (sendCommand(
"C#", res) ==
false)
159 int rc = sscanf(res,
"C%d:OK", &temp);
162 TemperatureN[0].value = temp / 100.0;
165 LOGF_ERROR(
"Unknown error: focuser temperature value (%s)", res);
172 bool AAF2::readVersion()
174 char res[DRIVER_RES] = {0};
176 if (sendCommand(
"V#", res) ==
false)
184 bool AAF2::readPosition()
186 char res[DRIVER_RES] = {0};
188 if (sendCommand(
"P#", res) ==
false)
192 int rc = sscanf(res,
"P%d:OK", &pos);
198 LOGF_ERROR(
"Unknown error: focuser position value (%s)", res);
205 bool AAF2::isMoving()
207 char res[DRIVER_RES] = {0};
209 if (sendCommand(
"M#", res) ==
false)
212 if (strcmp(res,
"M1:OK") == 0)
214 else if (strcmp(res,
"M0:OK") == 0)
217 LOGF_ERROR(
"Unknown error: isMoving value (%s)", res);
224 char cmd[DRIVER_RES] = {0};
225 snprintf(
cmd, DRIVER_RES,
"I%d#", ticks);
226 return sendCommand(
cmd);
231 char cmd[DRIVER_RES] = {0}, res[DRIVER_RES] = {0}, expected[DRIVER_RES] = {0};
232 snprintf(
cmd, DRIVER_RES,
"T%d#", targetTicks);
233 snprintf(expected, DRIVER_RES,
"T%d:OK", targetTicks);
234 if (sendCommand(
cmd, res) ==
false)
237 targetPos = targetTicks;
239 if (!strcmp(res, expected))
247 int32_t newPosition = 0;
273 bool rc = readPosition();
283 rc = readTemperature();
286 if (fabs(lastTemperature - TemperatureN[0].value) >= 0.5)
289 lastTemperature = TemperatureN[0].value;
302 LOG_INFO(
"Focuser reached requested position.");
311 return sendCommand(
"H#");
315 bool AAF2::sendCommand(
const char *
cmd,
char * res)
317 int nbytes_written = 0, nbytes_read = 0, rc = -1;
319 tcflush(
PortFD, TCIOFLUSH);
327 LOGF_ERROR(
"Serial write error: %s.", errstr);
343 res[nbytes_read - 1] = 0;
347 tcflush(
PortFD, TCIOFLUSH);
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set the supplied position as the current focuser position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
const char * getDefaultName() override
const char * getDeviceName() const
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.
INumberVectorProperty FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
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.
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 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 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 IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)