48 IUFillSwitchVector(&HomeSP, HomeS, 1,
getDeviceName(),
"SetHome",
"Set Home",
MAIN_CONTROL_TAB,
IP_RW,
ISR_ATMOST1, 5,
78 if (!strcmp(name, HomeSP.
name))
107 return "WandererRotatorLite";
113 bool WandererRotatorLite::Handshake()
115 tcflush(
PortFD, TCIOFLUSH);
116 int nbytes_read1 = 0, nbytes_written = 0, rc = -1;
117 int nbytes_read2 = 0;
118 int nbytes_read3 = 0;
127 LOGF_ERROR(
"Serial write error: %s", errorMessage);
135 LOGF_ERROR(
"Device read error: %s", errorMessage);
142 LOGF_ERROR(
"Firmware read error: %s", errorMessage);
149 LOGF_ERROR(
"Position read error: %s", errorMessage);
152 if(atof(res3) >= 100000)
160 res1[nbytes_read1 - 1] =
'\0';
161 res2[nbytes_read2 - 1] =
'\0';
162 res3[nbytes_read3 - 1] =
'\0';
164 LOGF_INFO(
"Handshake successful:%s", res1);
166 tcflush(
PortFD, TCIOFLUSH);
178 backlashcompensation = 0;
180 if (angle * positionhistory < 0 && angle > 0)
182 angle = angle + backlash;
183 backlashcompensation = -1 * backlash;
185 if (angle * positionhistory < 0 && angle < 0)
187 angle = angle - backlash;
188 backlashcompensation = backlash;
191 int position = (int)(reversecoefficient * angle * 1155);
192 positionhistory = angle;
193 snprintf(
cmd, 16,
"%d", position);
208 int nbytes_read1 = 0, nbytes_written = 0, rc = -1;
209 int nbytes_read2 = 0;
212 tcflush(
PortFD, TCIOFLUSH);
217 LOGF_ERROR(
"Serial write error: %s", errorMessage);
225 LOGF_ERROR(
"Relative position read error: %s", errorMessage);
232 LOGF_ERROR(
"Mechanical position read error: %s", errorMessage);
240 res1[nbytes_read1 - 1] =
'\0';
241 res2[nbytes_read2 - 1] =
'\0';
244 tcflush(
PortFD, TCIOFLUSH);
255 double angle = -1 * reversecoefficient *
GotoRotatorN[0].value;
256 positionhistory = angle;
258 int position = (int)(angle * 1155);
259 snprintf(
cmd, 16,
"%d", position);
274 reversecoefficient = -1;
281 reversecoefficient = 1;
282 ReverseState =
false;
304 if(positioncount > 0)
306 GotoRotatorN[0].value += reversecoefficient * abs(positionhistory) / positionhistory;
315 int nbytes_read1 = 0, rc = -1;
316 int nbytes_read2 = 0;
324 LOGF_ERROR(
"Relative position read error: %s", errorMessage);
331 LOGF_ERROR(
"Mechanical position read error: %s", errorMessage);
334 GotoRotatorN[0].value = positiontemp + reversecoefficient * atof(res1) + backlashcompensation;
350 bool WandererRotatorLite::Move(
const char *
cmd)
353 int nbytes_written = 0, rc = -1;
355 positioncount = abs(atoi(
cmd) / 1155);
360 LOGF_ERROR(
"Serial write error: %s", errorMessage);
375 bool WandererRotatorLite::sendCommand(
const char *
cmd)
377 int nbytes_read = 0, nbytes_written = 0, rc = -1;
381 tcflush(
PortFD, TCIOFLUSH);
386 LOGF_ERROR(
"Serial write error: %s", errorMessage);
395 LOGF_ERROR(
"Serial read error: %s", errorMessage);
398 tcflush(
PortFD, TCIOFLUSH);
399 res[nbytes_read - 1] =
'\0';
409 bool WandererRotatorLite::SetHomePosition()
411 int nbytes_written = 0, rc = -1;
414 tcflush(
PortFD, TCIOFLUSH);
419 LOGF_ERROR(
"Serial write error: %s", errorMessage);
423 tcflush(
PortFD, TCIOFLUSH);
434 backlash = (double)(steps / 1155);
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
const char * getDeviceName() const
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.
INumberVectorProperty GotoRotatorNP
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
INumber RotatorBacklashN[1]
ISwitchVectorProperty HomeRotatorSP
Connection::Serial * serialConnection
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
INumberVectorProperty PresetNP
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
ISwitchVectorProperty PresetGotoSP
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
const char * getDefaultName() override
virtual void TimerHit() override
WandererRotatorLite::TimerHit.
virtual bool ReverseRotator(bool enabled) override
WandererRotatorLite::ReverseRotator.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual IPState MoveRotator(double angle) override
WandererRotatorLite::MoveRotator.
virtual bool SetRotatorBacklashEnabled(bool enabled) override
WandererRotatorLite::SetRotatorBacklashEnabled.
virtual bool AbortRotator() override
WandererRotatorLite::AbortRotator.
virtual IPState HomeRotator() override
WandererRotatorLite::HomeRotator.
virtual bool SetRotatorBacklash(int32_t steps) override
WandererRotatorLite::SetRotatorBacklash.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
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_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.
Implementations for common driver routines.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)