30static std::unique_ptr<NFocus> nFocus(
new NFocus());
43 IUFillNumber(&TemperatureN[0],
"TEMPERATURE",
"Celsius",
"%6.2f", -100, 100, 0, 0);
48 IUFillNumber(&SettingsN[SETTING_ON_TIME],
"ON time",
"ON waiting time",
"%6.0f", 10., 250., 0., 73.);
49 IUFillNumber(&SettingsN[SETTING_OFF_TIME],
"OFF time",
"OFF waiting time",
"%6.0f", 1., 250., 0., 15.);
50 IUFillNumber(&SettingsN[SETTING_MODE_DELAY],
"Fast Mode Delay",
"Fast Mode Delay",
"%6.0f", 0., 255., 0., 9.);
71 if (readTemperature())
75 if (getStartupValues())
94 char cmd[NFOCUS_LEN] = {0}, res[NFOCUS_LEN] = {0};
99 bool rc = sendCommand(
cmd, res, 1, 1);
103 return res[0] ==
'n';
106bool NFocus::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
108 int nbytes_written = 0, nbytes_read = 0, rc = -1;
110 tcflush(
PortFD, TCIOFLUSH);
114 char hex_cmd[NFOCUS_LEN * 3] = {0};
115 hexDump(hex_cmd,
cmd, cmd_len);
129 LOGF_ERROR(
"Serial write error: %s.", errstr);
137 rc =
tty_read(
PortFD, res, res_len, NFOCUS_TIMEOUT, &nbytes_read);
151 char hex_res[NFOCUS_LEN * 3] = {0};
152 hexDump(hex_res, res, res_len);
160 tcflush(
PortFD, TCIOFLUSH);
165void NFocus::hexDump(
char * buf,
const char * data,
int size)
167 for (
int i = 0; i < size; i++)
168 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
171 buf[3 * size - 1] =
'\0';
174bool NFocus::readTemperature()
176 char res[NFOCUS_LEN] = {0};
178 if (sendCommand(
":RT", res, 3, 4) ==
false)
195bool NFocus::setMotorSettings(
double onTime,
double offTime,
double fastDelay)
197 char on_cmd[NFOCUS_LEN] = {0}, off_cmd[NFOCUS_LEN] = {0}, fast_cmd[NFOCUS_LEN] = {0};
199 snprintf(on_cmd, NFOCUS_LEN,
":CO%03d#",
static_cast<int>(onTime));
200 snprintf(off_cmd, NFOCUS_LEN,
":CF%03d#",
static_cast<int>(offTime));
201 snprintf(fast_cmd, NFOCUS_LEN,
":CS%03d#",
static_cast<int>(fastDelay));
203 bool on_rc = sendCommand(on_cmd);
204 bool off_rc = sendCommand(off_cmd);
205 bool fast_rc = sendCommand(fast_cmd);
207 return (on_rc && off_rc && fast_rc);
210bool NFocus::readMotorSettings()
212 char on_res[NFOCUS_LEN] = {0}, off_res[NFOCUS_LEN] = {0}, fast_res[NFOCUS_LEN] = {0};
214 bool on_rc = sendCommand(
":RO", on_res, 3, 3);
215 bool off_rc = sendCommand(
":RF", off_res, 3, 3);
216 bool fast_rc = sendCommand(
":RS", fast_res, 3, 3);
218 if (on_rc && off_rc && fast_rc)
220 SettingsN[SETTING_ON_TIME].value = std::stoi(on_res);
221 SettingsN[SETTING_OFF_TIME].value = std::stoi(off_res);
222 SettingsN[SETTING_MODE_DELAY].value = std::stoi(fast_res);
236 if (strcmp(name, SettingsNP.
name) == 0)
239 double new_onTime = 0;
240 double new_offTime = 0;
241 double new_fastDelay = 0;
243 for (nset = i = 0; i < n; i++)
249 if (eqp == &SettingsN[SETTING_ON_TIME])
251 new_onTime = (values[i]);
252 nset +=
static_cast<int>(new_onTime >= 10 && new_onTime <= 250);
254 else if (eqp == &SettingsN[SETTING_OFF_TIME])
256 new_offTime = (values[i]);
257 nset +=
static_cast<int>(new_offTime >= 1 && new_offTime <= 250);
259 else if (eqp == &SettingsN[SETTING_MODE_DELAY])
261 new_fastDelay = (values[i]);
262 nset +=
static_cast<int>(new_fastDelay >= 1 && new_fastDelay <= 9);
269 if (setMotorSettings(new_onTime, new_offTime, new_fastDelay) ==
false)
271 LOG_ERROR(
"Changing to new settings failed");
296bool NFocus::getStartupValues()
298 if (readMotorSettings())
310 m_TargetPosition = ticks;
316 return sendCommand(
"F00000#");
329 if (m_TargetPosition == 0)
339 int nextMotion = (m_TargetPosition > 999) ? 999 : m_TargetPosition;
341 char cmd[NFOCUS_LEN] = {0};
342 snprintf(
cmd, NFOCUS_LEN,
":F%d0%03d#", direction, nextMotion);
343 if (sendCommand(
cmd) ==
false)
346 LOG_ERROR(
"Failed to issue motion command.");
350 m_TargetPosition -= nextMotion;
355 if (TemperatureNP.
s ==
IPS_OK && m_TemperatureCounter++ == NFOCUS_TEMPERATURE_FREQ)
357 m_TemperatureCounter = 0;
358 if (readTemperature())
365bool NFocus::isMoving()
367 char res[NFOCUS_LEN] = {0};
369 bool rc = sendCommand(
"S", res, 1, 1);
371 if (rc && res[0] ==
'1')
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
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.
INDI::PropertyNumber FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertySwitch FocusMotionSP
virtual bool saveConfigItems(FILE *fp) override
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...
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
int findOnSwitchIndex() const
The NFocus class Handles communication and control with nFocus DC focuser.
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 IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
bool saveConfigItems(FILE *fp) override
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
const char * getDefaultName() override
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
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.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
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,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)