29 #include <libnova/transform.h>
49 return (
const char *)
"AstroPhysics GTOCP2";
93 IUFillSwitchVector(&
SwapSP,
SwapS, 2,
getDeviceName(),
"SWAP",
"Swap buttons",
MOTION_TAB,
IP_RW,
ISR_1OFMANY, 0,
98 IUFillSwitchVector(&
SyncCMRSP,
SyncCMRS, 2,
getDeviceName(),
"SYNCCMR",
"Sync",
MOTION_TAB,
IP_RW,
ISR_1OFMANY, 0,
162 double longitude = -1000, latitude = -1000;
166 if (longitude != -1000 && latitude != -1000)
181 bool LX200AstroPhysicsGTOCP2::initMount()
186 bool raOK =
false, deOK =
false;
201 LOG_DEBUG(
"Mount is not yet initialized. Initializing it...");
218 mountInitialized =
true;
234 LOGF_ERROR(
"Error setting move rate (%d).", err);
244 LOGF_ERROR(
"Error setting slew to rate (%d).", err);
251 char versionString[128];
253 strncpy(versionString,
"E", 128);
261 if (strlen(versionString) != 1)
263 LOGF_ERROR(
"Version not supported GTOCP2 driver: %s", versionString);
267 int typeIndex =
VersionT[0].text[0] -
'E';
271 LOGF_DEBUG(
"Firmware version index: %d", typeIndex);
276 LOGF_ERROR(
"Invalid version: %s", versionString);
304 LOGF_ERROR(
"Error swapping buttons (%d).", err);
325 LOGF_ERROR(
"Error setting move to rate (%d).", err);
344 LOGF_ERROR(
"Error setting guiding to 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);
524 IDSetNumber(&
EqNP,
"Error Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
529 motionCommanded =
true;
537 LOGF_INFO(
"Slewing to RA: %s - DEC: %s", RAStr, DecStr);
544 if (firmwareVersion ==
MCV_E)
554 LOG_INFO(
"Simulated Astrophysics is online. Retrieving basic data...");
562 LOGF_ERROR(
"Error clearing the buffer (%d): %s", err, strerror(err));
571 LOGF_ERROR(
"Error setting back lash compensation (%d): %s.", err, strerror(err));
584 mountInitialized =
false;
591 char syncString[256];
635 LOG_INFO(
"Synchronization successful.");
646 struct ln_zonedate ltm;
648 ln_date_to_zonedate(utc, <m, utc_offset * 3600.0);
650 JD = ln_get_julian_day(utc);
661 LOGF_DEBUG(
"Set Local Time %02d:%02d:%02d is successful.", ltm.hours, ltm.minutes,
670 LOGF_DEBUG(
"Set Local Date %02d/%02d/%02d is successful.", ltm.days, ltm.months, ltm.years);
678 LOGF_DEBUG(
"Set UTC Offset %g (always positive for AP) is successful.", fabs(utc_offset));
684 if (locationUpdated && timeUpdated && mountInitialized ==
false)
696 LOG_ERROR(
"Error setting site longitude coordinates");
702 LOG_ERROR(
"Error setting site latitude coordinates");
708 fs_sexa(L, longitude, 4, 3600);
710 LOGF_INFO(
"Site location updated to Lat %.32s - Long %.32s", l, L);
712 locationUpdated =
true;
714 if (locationUpdated && timeUpdated && mountInitialized ==
false)
748 char AzStr[16], AltStr[16];
749 fs_sexa(AzStr, parkAz, 2, 3600);
750 fs_sexa(AltStr, parkAlt, 2, 3600);
751 LOGF_DEBUG(
"Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
758 Goto(equatorialCoords.rightascension, equatorialCoords.declination);
773 LOGF_ERROR(
"Error Slewing to Az %s - Alt %s", AzStr, AltStr);
778 motionCommanded =
true;
785 LOG_INFO(
"Parking is in progress...");
808 double parkAZ = horizontalPos.
azimuth;
809 double parkAlt = horizontalPos.
altitude;
811 char AzStr[16], AltStr[16];
812 fs_sexa(AzStr, parkAZ, 2, 3600);
813 fs_sexa(AltStr, parkAlt, 2, 3600);
815 LOGF_DEBUG(
"Setting current parking position to coordinates Az (%s) Alt (%s)", AzStr, AltStr);
834 void LX200AstroPhysicsGTOCP2::syncSideOfPier()
836 const char *
cmd =
":pS#";
838 char response[16] = { 0 };
839 int rc = 0, nbytes_read = 0, nbytes_written = 0;
843 tcflush(
PortFD, TCIOFLUSH);
849 LOGF_ERROR(
"Error writing to device %s (%d)", errmsg, rc);
858 LOGF_ERROR(
"Error reading from device %s (%d)", errmsg, rc);
862 response[nbytes_read - 1] =
'\0';
864 tcflush(
PortFD, TCIOFLUSH);
868 if (!strcmp(response,
"East"))
870 else if (!strcmp(response,
"West"))
873 LOGF_ERROR(
"Invalid pier side response from device-> %s", response);
896 LOGF_ERROR(
"Error setting tracking mode (%d).", err);
905 LOGF_ERROR(
"Error setting tracking mode (%d).", err);
954 motionCommanded =
true;
964 motionCommanded =
true;
971 LOGF_DEBUG(
"%s: Motion commanded? %s", __FUNCTION__, motionCommanded ?
"True" :
"False");
979 motionCommanded =
false;
const char * getDeviceName() 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
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
ISwitchVectorProperty MovementNSSP
ISwitchVectorProperty AbortSP
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
ISwitchVectorProperty PECStateSP
ISwitchVectorProperty TrackModeSP
ISwitchVectorProperty SlewRateSP
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
INumberVectorProperty EqNP
@ TELESCOPE_HAS_TRACK_RATE
@ TELESCOPE_HAS_PIER_SIDE
@ TELESCOPE_CAN_CONTROL_TRACK
IGeographicCoordinates m_Location
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...
ISwitchVectorProperty MovementWESP
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
virtual const char * getDefaultName() override
ITextVectorProperty VersionTP
ISwitchVectorProperty APSlewSpeedSP
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
ISwitchVectorProperty APGuideSpeedSP
INumberVectorProperty HourangleCoordsNP
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.
INumber HourangleCoordsN[2]
void handleGTOCP2MotionBug()
virtual bool Disconnect() override
Disconnect from device.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
LX200AstroPhysicsGTOCP2()
ISwitchVectorProperty SyncCMRSP
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...
INumberVectorProperty HorizontalCoordsNP
virtual bool getUTFOffset(double *offset) override
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.
INumber HorizontalCoordsN[2]
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
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.
ISwitchVectorProperty SwapSP
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.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
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...
@ 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 * 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.
#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 TRACKRATE_SIDEREAL
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
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.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
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 IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
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 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.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUGetConfigNumber(const char *dev, const char *property, const char *member, double *value)
IUGetConfigNumber Opens configuration file and reads single number property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#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,...)
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.