33static std::unique_ptr<AAF2> aaf2(
new AAF2());
48 TemperatureNP[0].
fill(
"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!#");
151bool AAF2::readTemperature()
153 char res[DRIVER_RES] = {0};
155 if (sendCommand(
"C#", res) ==
false)
159 int rc = sscanf(res,
"C%d:OK", &temp);
162 TemperatureNP[0].setValue(temp / 100.0);
165 LOGF_ERROR(
"Unknown error: focuser temperature value (%s)", res);
172bool AAF2::readVersion()
174 char res[DRIVER_RES] = {0};
176 if (sendCommand(
"V#", res) ==
false)
184bool 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);
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;
255 newPosition = std::max(0, std::min(
static_cast<int32_t
>(
FocusAbsPosNP[0].getMax()), newPosition));
273 bool rc = readPosition();
283 rc = readTemperature();
286 if (fabs(lastTemperature - TemperatureNP[0].getValue()) >= 0.5)
288 TemperatureNP.
apply();
289 lastTemperature = TemperatureNP[0].getValue();
302 LOG_INFO(
"Focuser reached requested position.");
311 return sendCommand(
"H#");
315bool 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
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
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
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 FocusAbsPosNP
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
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
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.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)