27 #include <libnova/transform.h>
70 int mountType = Equatorial;
72 MountTypeSP[Azimuth].
fill(
"Azimuth",
"Azimuth", mountType == Azimuth ?
ISS_ON :
ISS_OFF);
73 MountTypeSP[Equatorial].
fill(
"Equatorial",
"Equatorial", mountType == Equatorial ?
ISS_ON :
ISS_OFF);
76 if (mountType == Equatorial)
99 GuideRateNP[0].
fill(
"RATE",
"Rate",
"%.2f", 0.1, 0.9, 0.1, 0.5);
153 for (
int i = 0; i < 2; i++)
158 const struct timespec ms250_delay = {.tv_sec = 0, .tv_nsec = 250000000};
159 nanosleep(&ms250_delay, NULL);
168 void LX200AM5::setup()
207 MountTypeSP.
update(states, names, n);
214 if (state ==
IPS_OK && previousType != targetType)
215 LOG_WARN(
"You must restart mount for change to take effect.");
248 GuideRateNP.
update(values, names, n);
261 bool LX200AM5::setMountType(
int type)
263 return sendCommand((
type == Azimuth) ?
":AA#" :
":AP#");
269 bool LX200AM5::getMountType()
271 char response[DRIVER_LEN] = {0};
272 if (sendCommand(
":GU#", response))
292 char command[DRIVER_LEN] = {0};
293 snprintf(command, DRIVER_LEN,
":R%d#", index);
294 return sendCommand(command);
302 bool LX200AM5::setGuideRate(
double value)
304 char command[DRIVER_LEN] = {0};
305 snprintf(command, DRIVER_LEN,
":Rg%.2f", value);
306 return sendCommand(command);
312 bool LX200AM5::getGuideRate()
314 char response[DRIVER_LEN] = {0};
315 if (sendCommand(
":Ggr#", response))
318 int result = sscanf(response,
"%f", &rate);
321 GuideRateNP[0].setValue(rate);
334 bool LX200AM5::getTrackMode()
336 char response[DRIVER_LEN] = {0};
337 if (sendCommand(
":GT#", response))
340 auto onIndex = response[0] - 0x30;
353 bool LX200AM5::setBuzzer(
int value)
355 char command[DRIVER_LEN] = {0};
356 snprintf(command, DRIVER_LEN,
":SBu%d", value);
357 return sendCommand(command);
363 bool LX200AM5::getBuzzer()
365 char response[DRIVER_LEN] = {0};
366 if (sendCommand(
":GBu#", response))
369 auto onIndex = response[0] - 0x30;
386 int h {0}, m {0}, s {0};
387 char command[DRIVER_LEN] = {0};
391 snprintf(command, DRIVER_LEN,
":SG%c%02d:%02d#", offset >= 0 ?
'+' :
'-', std::abs(h), m);
397 char command[DRIVER_LEN] = {0};
398 snprintf(command, DRIVER_LEN,
":SC%02d/%02d/%02d#", months, days, years % 100);
407 char response[DRIVER_LEN] = {0};
408 bool rc = sendCommand(enabled ?
":Te#" :
":Td#", response, 4, 1);
409 return rc && response[0] ==
'1';
415 bool LX200AM5::isTracking()
417 char response[DRIVER_LEN] = {0};
418 bool rc = sendCommand(
":GAT#", response);
419 return rc && response[0] ==
'1';
425 bool LX200AM5::goHome()
427 return sendCommand(
":hC#");
436 int d{0}, m{0}, s{0};
441 longitude = longitude - 360;
443 char command[DRIVER_LEN] = {0};
447 snprintf(command, DRIVER_LEN,
":Sg%c%03d*%02d:%02d#", longitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
450 LOG_ERROR(
"Error setting site longitude coordinates");
455 snprintf(command, DRIVER_LEN,
":St%c%02d*%02d:%02d#", latitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
458 LOG_ERROR(
"Error setting site latitude coordinates");
484 bool slewComplete =
false, isHome =
false;
485 char status[DRIVER_LEN] = {0};
486 if (sendCommand(
":GU#", status))
488 slewComplete = strchr(status,
'N');
489 isHome = strchr(status,
'H');
506 LOG_INFO(
"Slew is complete. Tracking...");
520 auto nowTracking = isTracking();
521 if (wasTracking != nowTracking)
534 char response[DRIVER_LEN] = {0};
535 if (sendCommand(
":Gm#", response))
537 if (response[0] ==
'W')
539 else if (response[0] ==
'E')
554 bool LX200AM5::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
556 int nbytes_written = 0, nbytes_read = 0, rc = -1;
558 tcflush(
PortFD, TCIOFLUSH);
562 char hex_cmd[DRIVER_LEN * 3] = {0};
563 hexDump(hex_cmd,
cmd, cmd_len);
577 LOGF_ERROR(
"Serial write error: %s.", errstr);
588 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
602 char hex_res[DRIVER_LEN * 3] = {0};
603 hexDump(hex_res, res, res_len);
611 tcflush(
PortFD, TCIOFLUSH);
619 void LX200AM5::hexDump(
char * buf,
const char * data,
int size)
621 for (
int i = 0; i < size; i++)
622 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
625 buf[3 * size - 1] =
'\0';
631 std::vector<std::string> LX200AM5::split(
const std::string &input,
const std::string ®ex)
634 std::regex re(regex);
635 std::sregex_token_iterator
636 first{input.begin(), input.end(), re, -1},
638 return {first, last};
void setDefaultHost(const char *addressHost)
void setLANSearchEnabled(bool enabled)
void setDefaultPort(uint32_t addressPort)
const char * getDeviceName() const
void setActiveConnection(Connection::Interface *existingConnection)
setActiveConnection Switch the active connection to the passed connection plugin
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)
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool isNameMatch(const char *otherName) const
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)
bool update(const ISState states[], const char *const names[], int n)
int findOnSwitchIndex() const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
ISwitchVectorProperty TrackModeSP
ISwitchVectorProperty SlewRateSP
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
Connection::TCP * tcpConnection
INumberVectorProperty EqNP
@ TELESCOPE_HAS_PIER_SIDE
@ TELESCOPE_HAS_TRACK_MODE
@ TELESCOPE_CAN_CONTROL_TRACK
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool Park() override
Park the telescope to its home position.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual const char * getDefaultName() override
virtual bool checkConnection() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool setUTCOffset(double offset) override
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years) override
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
@ LX200_HAS_PULSE_GUIDING
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void setLX200Capability(uint32_t cap)
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
void getSexComponents(double value, int *d, int *m, int *s)
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 IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
int IUGetConfigOnSwitchIndex(const char *dev, const char *property, int *index)
IUGetConfigOnSwitchIndex Opens configuration file and reads single switch property to find ON switch ...
#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,...)
int setStandardProcedure(int fd, const char *data)
#define getLX200DEC(fd, x)
#define getLX200RA(fd, x)
MountType getMountType(const int fd)
bool setMountType(const int fd, Pulsar2Commands::MountType mtype)