29 #include <libnova/transform.h>
36 #define MOUNT_TAB "Mount"
41 setLX200Capability(LX200_HAS_PULSE_GUIDING);
42 SetTelescopeCapability(GetTelescopeCapability() | TELESCOPE_HAS_PIER_SIDE | TELESCOPE_HAS_PEC | TELESCOPE_CAN_CONTROL_TRACK
43 | TELESCOPE_HAS_TRACK_RATE, 4);
45 sendLocationOnStartup =
false;
46 sendTimeOnStartup =
false;
51 return (
const char *)
"AstroPhysics";
100 IUFillSwitchVector(&
SwapSP,
SwapS, 2,
getDeviceName(),
"SWAP",
"Swap buttons",
MOTION_TAB,
IP_RW,
ISR_1OFMANY, 0,
105 IUFillSwitchVector(&
SyncCMRSP,
SyncCMRS, 2,
getDeviceName(),
"SYNCCMR",
"Sync",
MOTION_TAB,
IP_RW,
ISR_1OFMANY, 0,
175 LOG_INFO(
"Please initialize the mount before issuing any command.");
211 if (timeUpdated ==
false || locationUpdated ==
false)
214 LOG_ERROR(
"Time and location must be set before mount initialization is invoked.");
221 if (setBasicDataPart1() ==
false)
256 LOGF_ERROR(
"StartUpSP: Error setting tracking mode (%d).", err);
270 LOGF_ERROR(
"StartUpSP: Error setting move rate (%d).", err);
281 LOGF_ERROR(
"StartUpSP: Error setting slew to rate (%d).", err);
296 char versionString[64];
333 LOGF_ERROR(
"Error swapping buttons (%d).", err);
354 LOGF_ERROR(
"Error setting move to rate (%d).", err);
373 LOGF_ERROR(
"Error setting guiding to rate (%d).", err);
408 LOGF_ERROR(
"Error setting PEC state (%d).", err);
447 bool LX200AstroPhysics::isMountInit()
479 LOG_INFO(
"Slew is complete. Tracking...");
484 double currentAlt, currentAz;
495 LOGF_DEBUG(
"Parking... targetAz: %g currentAz: %g dx: %g targetAlt: %g currentAlt: %g dy: %g",
GetAxis1Park(),
500 LOG_DEBUG(
"Parking slew is complete. Asking astrophysics mount to park...");
519 bool LX200AstroPhysics::setBasicDataPart0()
527 LOG_INFO(
"setBasicDataPart0 simulation complete.");
533 LOGF_ERROR(
"Error clearing the buffer (%d): %s", err, strerror(err));
537 if ((err = setAPLongFormat(
PortFD)) < 0)
539 LOGF_ERROR(
"Error setting long format failed (%d): %s", err, strerror(err));
548 LOGF_ERROR(
"Error setting back lash compensation (%d): %s.", err, strerror(err));
559 bool LX200AstroPhysics::setBasicDataPart1()
585 LOGF_ERROR(
"Stop motion (:Q#) failed, check the mount (%d): %s", err, strerror(err));
597 const struct timespec timeout = {0, 100000000L};
601 char RAStr[64], DecStr[64];
633 nanosleep(&timeout,
nullptr);
651 IDSetNumber(&
EqNP,
"Error Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
660 LOGF_INFO(
"Slewing to RA: %s - DEC: %s", RAStr, DecStr);
673 return setBasicDataPart0();
679 locationUpdated =
false;
686 char syncString[256];
730 LOG_INFO(
"Synchronization successful.");
741 struct ln_zonedate ltm;
749 ln_date_to_zonedate(utc, <m, utc_offset * 3600.0);
751 JD = ln_get_julian_day(utc);
762 LOGF_DEBUG(
"Set Local Time %02d:%02d:%02d is successful.", ltm.hours, ltm.minutes,
771 LOGF_DEBUG(
"Set Local Date %02d/%02d/%02d is successful.", ltm.days, ltm.months, ltm.years);
779 LOGF_DEBUG(
"Set UTC Offset %g (always positive for AP) is successful.", fabs(utc_offset));
794 locationUpdated =
true;
800 LOG_ERROR(
"Error setting site longitude coordinates");
806 LOG_ERROR(
"Error setting site latitude coordinates");
812 fs_sexa(L, longitude, 4, 3600);
814 LOGF_INFO(
"Site location updated to Lat %.32s - Long %.32s", l, L);
816 locationUpdated =
true;
850 LOG_WARN(
"You must initialize the mount before parking.");
857 char AzStr[16], AltStr[16];
858 fs_sexa(AzStr, parkAz, 2, 3600);
859 fs_sexa(AltStr, parkAlt, 2, 3600);
860 LOGF_DEBUG(
"Parking to Az (%s) Alt (%s)...", AzStr, AltStr);
867 Goto(equatorialCoords.rightascension, equatorialCoords.declination);
882 LOGF_ERROR(
"Error Slewing to Az %s - Alt %s", AzStr, AltStr);
890 LOG_INFO(
"Parking is in progress...");
911 char AzStr[16], AltStr[16];
912 fs_sexa(AzStr, parkAz, 2, 3600);
913 fs_sexa(AltStr, parkAlt, 2, 3600);
914 LOGF_DEBUG(
"Syncing to parked coordinates Az (%s) Alt (%s)...", AzStr, AltStr);
922 currentRA = equatorialCoords.rightascension;
933 char syncString[256];
950 double parkAZ = horizontalCoords.azimuth;
951 double parkAlt = horizontalCoords.altitude;
953 char AzStr[16], AltStr[16];
954 fs_sexa(AzStr, parkAZ, 2, 3600);
955 fs_sexa(AltStr, parkAlt, 2, 3600);
957 LOGF_DEBUG(
"Setting current parking position to coordinates Az (%s) Alt (%s)...", AzStr,
977 void LX200AstroPhysics::syncSideOfPier()
979 const char *
cmd =
":pS#";
981 char response[16] = { 0 };
982 int rc = 0, nbytes_read = 0, nbytes_written = 0;
986 tcflush(
PortFD, TCIOFLUSH);
992 LOGF_ERROR(
"Error writing to device %s (%d)", errmsg, rc);
1001 LOGF_ERROR(
"Error reading from device %s (%d)", errmsg, rc);
1005 response[nbytes_read - 1] =
'\0';
1007 tcflush(
PortFD, TCIOFLUSH);
1011 if (!strcmp(response,
"East"))
1013 else if (!strcmp(response,
"West"))
1016 LOGF_ERROR(
"Invalid pier side response from device-> %s", response);
1039 LOGF_ERROR(
"Error setting tracking mode (%d).", err);
1048 LOGF_ERROR(
"Error setting tracking mode (%d).", err);
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.
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
IGeographicCoordinates m_Location
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 bool initProperties() override
Called to initialize basic properties required all the time.
ISwitchVectorProperty StartUpSP
ISwitchVectorProperty APSlewSpeedSP
virtual bool UnPark() override
Unpark the telescope if already parked.
ISwitchVectorProperty APGuideSpeedSP
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
INumber HorizontalCoordsN[2]
ISwitchVectorProperty SwapSP
virtual bool Park() override
Park the telescope to its home position.
virtual const char * getDefaultName() override
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
INumberVectorProperty SlewAccuracyNP
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual int SendPulseCmd(int8_t direction, uint32_t duration_msec) override
IText DeclinationAxisT[1]
ITextVectorProperty VersionTP
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool Handshake() override
perform handshake with device to check communication
INumberVectorProperty HorizontalCoordsNP
virtual bool getUTFOffset(double *offset) override
virtual bool Disconnect() override
Disconnect from device.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
INumber HourangleCoordsN[2]
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
ISwitchVectorProperty SyncCMRSP
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
INumberVectorProperty HourangleCoordsNP
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
ITextVectorProperty DeclinationAxisTP
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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 ReadScopeStatus() override
Read telescope status.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual void slewError(int slewCode)
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.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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.
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 IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector 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,...)
#define MOUNTNOTINITIALIZED
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 APSyncCM(int fd, char *matchedObject)
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.