37static std::unique_ptr<astromechanics_foc> Astromechanics_foc(
new astromechanics_foc());
40#define FOC_POSMAX_HARDWARE 32767
41#define FOC_POSMIN_HARDWARE 0
51 Astromechanics_foc->ISSnoopDevice(root);
68 return "Astromechanics FOC";
94 AppertureNP[0].
fill(
"LENS_APP",
"Index",
"%.f", 0, 22, 1, 0);
129 char res[DRIVER_LEN] = {0};
131 for (
int i = 0; i < 3; i++)
133 if (!sendCommand(
"P#", res))
134 std::this_thread::sleep_for(std::chrono::milliseconds(100));
137 sscanf(res,
"%d", &position);
155 if (strcmp(name,
"LENS_APP_SETTING") == 0)
157 AppertureNP.
update(values, names, n);
160 SetApperture(AppertureNP[0].getValue());
173 char cmd[DRIVER_LEN] = {0};
174 snprintf(
cmd, DRIVER_LEN,
"M%u#", targetTicks);
175 if (sendCommand(
cmd))
190 int32_t offset = ((dir ==
FOCUS_INWARD) ? -1 : 1) *
static_cast<int32_t
>(ticks);
192 newPosition = std::max(
static_cast<int32_t
>(
FocusAbsPosNP[0].getMin()),
205bool astromechanics_foc::SetApperture(uint32_t index)
207 char cmd[DRIVER_LEN] = {0};
208 snprintf(
cmd, DRIVER_LEN,
"A%u#", index);
209 return sendCommand(
cmd);
215uint32_t astromechanics_foc::GetAbsFocuserPosition()
217 char res[DRIVER_LEN] = {0};
220 if (!sendCommand(
"P#", res))
221 std::this_thread::sleep_for(std::chrono::milliseconds(100));
224 sscanf(res,
"%d", &position);
234bool astromechanics_foc::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
236 int nbytes_written = 0, nbytes_read = 0, rc = -1;
237 tcflush(
PortFD, TCIOFLUSH);
241 char hex_cmd[DRIVER_LEN * 3] = {0};
242 hexDump(hex_cmd,
cmd, cmd_len);
256 LOGF_ERROR(
"Serial write error: %s.", errstr);
264 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
281 char hex_res[DRIVER_LEN * 3] = {0};
282 hexDump(hex_res, res, res_len);
288 res[nbytes_read - 1] = 0;
292 tcflush(
PortFD, TCIOFLUSH);
300void astromechanics_foc::hexDump(
char * buf,
const char * data,
int size)
302 for (
int i = 0; i < size; i++)
303 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
306 buf[3 * size - 1] =
'\0';
312std::vector<std::string> astromechanics_foc::split(
const std::string &input,
const std::string ®ex)
315 std::regex re(regex);
316 std::sregex_token_iterator
317 first{input.begin(), input.end(), re, -1},
319 return {first, last};
#define FOC_POSMAX_HARDWARE
#define FOC_POSMIN_HARDWARE
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
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)
INDI::PropertyNumber FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusMaxPosNP
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,...
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 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)
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...
const char * getDefaultName() override
bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool Disconnect() override
Disconnect from device.
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
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_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)