29#include <libnova/transform.h>
49 return "AstroPhysics GTOCP2";
170bool LX200AstroPhysicsGTOCP2::initMount()
175 bool raOK =
false, deOK =
false;
190 LOG_DEBUG(
"Mount is not yet initialized. Initializing it...");
207 mountInitialized =
true;
223 LOGF_ERROR(
"Error setting move rate (%d).", err);
234 LOGF_ERROR(
"Error setting slew to rate (%d).", err);
242 char versionString[128];
244 strncpy(versionString,
"E", 128);
252 if (strlen(versionString) != 1)
254 LOGF_ERROR(
"Version not supported GTOCP2 driver: %s", versionString);
263 LOGF_DEBUG(
"Firmware version index: %d", typeIndex);
268 LOGF_ERROR(
"Invalid version: %s", versionString);
295 LOGF_ERROR(
"Error swapping buttons (%d).", err);
319 LOGF_ERROR(
"Error setting GOTO rate (%d).", err);
342 LOGF_ERROR(
"Error setting guide rate (%d).", err);
379 LOGF_ERROR(
"Error setting PEC state (%d).", err);
415 if (dx == 0 && dy == 0)
418 LOG_INFO(
"Slew is complete. Tracking...");
434 double dx = lastAZ - currentAz;
435 double dy = lastAL - currentAlt;
437 LOGF_DEBUG(
"Parking... currentAz: %g dx: %g currentAlt: %g dy: %g", currentAz, dx, currentAlt, dy);
439 if (dx == 0 && dy == 0)
441 LOG_DEBUG(
"Parking slew is complete. Asking astrophysics mount to park...");
454 LOG_INFO(
"Please disconnect and power off the mount.");
470 const struct timespec timeout = {0, 100000000L};
475 char RAStr[64], DecStr[64];
506 nanosleep(&timeout,
nullptr);
514 LOG_ERROR(
"Error setting target RA/DEC.");
525 LOGF_ERROR(
"Error Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
531 motionCommanded =
true;
540 LOGF_INFO(
"Slewing to RA: %s - DEC: %s", RAStr, DecStr);
548 if (firmwareVersion ==
MCV_E)
558 LOG_INFO(
"Simulated Astrophysics is online. Retrieving basic data...");
566 LOGF_ERROR(
"Error clearing the buffer (%d): %s", err, strerror(err));
575 LOGF_ERROR(
"Error setting back lash compensation (%d): %s.", err, strerror(err));
588 mountInitialized =
false;
595 char syncString[256];
604 EqNP.
apply(
"Error setting sync RA/DEC.");
624 LOG_ERROR(
"Invalid sync type selected.");
642 LOG_INFO(
"Synchronization successful.");
653 struct ln_zonedate ltm;
655 ln_date_to_zonedate(utc, <m, utc_offset * 3600.0);
657 JD = ln_get_julian_day(utc);
668 LOGF_DEBUG(
"Set Local Time %02d:%02d:%02d is successful.", ltm.hours, ltm.minutes,
677 LOGF_DEBUG(
"Set Local Date %02d/%02d/%02d is successful.", ltm.days, ltm.months, ltm.years);
685 LOGF_DEBUG(
"Set UTC Offset %g (always positive for AP) is successful.", fabs(utc_offset));
691 if (locationUpdated && timeUpdated && mountInitialized ==
false)
703 LOG_ERROR(
"Error setting site longitude coordinates");
709 LOG_ERROR(
"Error setting site latitude coordinates");
715 fs_sexa(L, longitude, 4, 3600);
717 LOGF_INFO(
"Site location updated to Lat %.32s - Long %.32s", l, L);
719 locationUpdated =
true;
721 if (locationUpdated && timeUpdated && mountInitialized ==
false)
758 char AzStr[16], AltStr[16];
759 fs_sexa(AzStr, parkAz, 2, 3600);
760 fs_sexa(AltStr, parkAlt, 2, 3600);
761 LOGF_DEBUG(
"Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
768 Goto(equatorialCoords.rightascension, equatorialCoords.declination);
783 LOGF_ERROR(
"Error Slewing to Az %s - Alt %s", AzStr, AltStr);
788 motionCommanded =
true;
796 LOG_INFO(
"Parking is in progress...");
819 double parkAZ = horizontalPos.
azimuth;
820 double parkAlt = horizontalPos.
altitude;
822 char AzStr[16], AltStr[16];
823 fs_sexa(AzStr, parkAZ, 2, 3600);
824 fs_sexa(AltStr, parkAlt, 2, 3600);
826 LOGF_DEBUG(
"Setting current parking position to coordinates Az (%s) Alt (%s)", AzStr, AltStr);
851void LX200AstroPhysicsGTOCP2::syncSideOfPier()
853 const char *
cmd =
":pS#";
855 char response[16] = { 0 };
856 int rc = 0, nbytes_read = 0, nbytes_written = 0;
860 tcflush(
PortFD, TCIOFLUSH);
866 LOGF_ERROR(
"Error writing to device %s (%d)", errmsg, rc);
875 LOGF_ERROR(
"Error reading from device %s (%d)", errmsg, rc);
879 response[nbytes_read - 1] =
'\0';
881 tcflush(
PortFD, TCIOFLUSH);
885 if (!strcmp(response,
"East"))
887 else if (!strcmp(response,
"West"))
890 LOGF_ERROR(
"Invalid pier side response from device-> %s", response);
913 LOGF_ERROR(
"Error setting tracking mode to Sidereal for Custom Rate (%d).", err);
924 LOGF_ERROR(
"Error setting tracking mode (%d).", err);
966 motionCommanded =
true;
976 motionCommanded =
true;
983 LOGF_DEBUG(
"%s: Motion commanded? %s", __FUNCTION__, motionCommanded ?
"True" :
"False");
990 LOGF_DEBUG(
"%s: Issuing select guide rate index: %d", __FUNCTION__, guideRateIndex);
992 motionCommanded =
false;
INDI::PropertyText getText(const char *name) const
virtual bool Disconnect()
Disconnect from device.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool load()
load Attempt to load property values from configuration file.
void save(FILE *f) const
save Save property to configuration file.
void setLabel(const char *label)
bool isNameMatch(const char *otherName) const
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)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
INDI::PropertyViewText * getText() const
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.
double GetAxis1Park() const
double GetAxis2Park() const
double GetAxis1ParkDefault() const
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
IGeographicCoordinates m_Location
@ TELESCOPE_HAS_TRACK_RATE
@ TELESCOPE_HAS_PIER_SIDE
@ 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...
double GetAxis2ParkDefault() const
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 void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool Handshake() override
perform handshake with device to check communication
INDI::PropertySwitch SyncCMRSP
virtual const char * getDefaultName() override
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
INDI::PropertyNumber HorizontalCoordsNP
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
void handleGTOCP2MotionBug()
virtual bool Disconnect() override
Disconnect from device.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
LX200AstroPhysicsGTOCP2()
virtual int SendPulseCmd(int8_t direction, uint32_t duration_msec) override
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
INDI::PropertyNumber HourangleCoordsNP
virtual bool getUTFOffset(double *offset) override
INDI::PropertySwitch APGuideSpeedSP
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
INDI::PropertySwitch APSlewSpeedSP
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
INDI::PropertySwitch SwapSP
virtual bool Park() override
Park the telescope to its home position.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
INDI::PropertyText VersionTP
virtual bool initProperties() override
Called to initialize basic properties required all the time.
@ LX200_HAS_PULSE_GUIDING
virtual void slewError(int slewCode)
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
bool sendLocationOnStartup
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
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 * GUIDE_TAB
GUIDE_TAB Where all the properties for guiding are located.
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.
INDI::PropertySwitch AbortSP
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch PECStateSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MovementWESP
INDI::PropertyNumber LocationNP
#define setLocalTime(fd, x, y, z)
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(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Implementations for common driver routines.
#define LOGF_INFO(fmt,...)
#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,...)
#define TRACKRATE_SIDEREAL
int selectAPMoveToRate(int fd, int moveToIndex)
int setAPUTCOffset(int fd, double hours)
int setAPSiteLatitude(int fd, double Lat)
void set_lx200ap_name(const char *deviceName, unsigned int debug_level)
int setAPRATrackRate(int fd, double rate)
int setAPObjectRA(int fd, double ra)
int APSyncCMR(int fd, char *matchedObject)
int setAPObjectAlt(int fd, double alt)
int swapAPButtons(int fd, int currentSwap)
int setAPObjectDEC(int fd, double dec)
int APSendPulseCmd(int fd, int direction, int duration_msec)
int selectAPSlewRate(int fd, int slewIndex)
int selectAPPECState(int fd, int pecstate)
int selectAPGuideRate(int fd, int guideRate)
int setAPObjectAZ(int fd, double az)
int getAPUTCOffset(int fd, double *value)
int setAPDETrackRate(int fd, double rate)
int setAPSiteLongitude(int fd, double Long)
int selectAPTrackingMode(int fd, int trackMode)
#define setAPBackLashCompensation(fd, x, y, z)
#define getAPVersionNumber(fd, x)
#define setAPClearBuffer(fd)
#define AP_TRACKING_SIDEREAL
int checkLX200EquatorialFormat(int fd)
int setCalenderDate(int fd, int dd, int mm, int yy, bool addSpace)
#define getLX200DEC(fd, x)
#define getLX200RA(fd, x)
#define getLX200Alt(fd, x)
#define getLX200Az(fd, x)
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
void HorizontalToEquatorial(IHorizontalCoordinates *object, IGeographicCoordinates *observer, double JD, IEquatorialCoordinates *position)
HorizontalToEquatorial Calculate Equatorial EOD Coordinates from horizontal coordinates.