29#include <libnova/transform.h>
81 ElevationLimitNP[OVERHEAD].fill(
"ELEVATION_OVERHEAD",
"Overhead",
"%g", 60, 90, 1, 90);
82 ElevationLimitNP[HORIZON].fill(
"ELEVATION_HORIZON",
"Horizon",
"%g", -30, 0, 1, 0);
87 MeridianLimitNP[0].fill(
"VALUE",
"Degrees (+/- 120)",
"%.f", -120, 120, 1, 0);
91 FlipSP[0].fill(
"Flip",
"Flip",
ISS_OFF);
95 RefractSP[REFRACT_ON].fill(
"REFRACTION_ON",
"On",
ISS_OFF);
96 RefractSP[REFRACT_OFF].fill(
"REFRACTION_OFF",
"Off",
ISS_OFF);
101 SafetyLimitSP[SET_SAFETY_LIMIT].fill(
"SET_SAFETY_LIMIT",
"Set",
ISS_OFF);
102 SafetyLimitSP[CLEAR_SAFETY_LIMIT].fill(
"CLEAR_SAFETY_LIMIT",
"Clear",
ISS_OFF);
106 GuideRateNP[
AXIS_RA].fill(
"GUIDE_RATE_WE",
"W/E Rate",
"%.2f", 0.25, 1.0, 0.25, 0.5);
107 GuideRateNP[
AXIS_DE].fill(
"GUIDE_RATE_NS",
"N/S Rate",
"%.2f", 0.25, 1.0, 0.25, 0.5);
118 verboseReport =
false;
119 VerboseReportSP[0].fill(
"On",
"On",
ISS_OFF);
120 VerboseReportSP[1].fill(
"Off",
"Off",
ISS_ON);
123 Report[0].fill(
"Report",
"GU",
"-");
127 DebugCommandTP[0].fill(
"Command",
"",
"");
132 IsTracking[0].fill(
"IsTracking",
"n",
"-");
135 IsSlewCompleted[0].fill(
"IsSlewCompleted",
"N",
"-");
138 IsParked[0].fill(
"IsParked",
"p/P",
"-");
141 IsParkginInProgress[0].fill(
"IsParkginInProgress",
"I",
"-");
144 IsAtHomePosition[0].fill(
"IsAtHomePosition",
"H",
"-");
147 MountAltAz[0].fill(
"MountAltAz",
"A",
"-");
150 MountEquatorial[0].fill(
"MountEquatorial",
"E",
"-");
153 PierNone[0].fill(
"PierNone",
"",
"-");
156 PierEast[0].fill(
"PierEast",
"T",
"-");
159 PierWest[0].fill(
"PierWest",
"W",
"-");
162 DoesRefractionComp[0].fill(
"DoesRefractionComp",
"r",
"-");
165 WaitingAtHome[0].fill(
"WaitingAtHome",
"w",
"-");
168 IsHomePaused[0].fill(
"IsHomePaused",
"u",
"-");
171 ParkFailed[0].fill(
"ParkFailed",
"F",
"-");
174 SlewingHome[0].fill(
"SlewingHome",
"h",
"-");
178 RebootSP[0].fill(
"Reboot",
"Reboot",
ISS_OFF);
206 char status[DRIVER_LEN] = {0};
207 if (sendCommand(
":GU#", status))
209 if(strchr(status,
'P'))
214 if (strchr(status,
'A'))
216 else if (strchr(status,
'E'))
220 if(sendCommand(
":GX90#", status))
222 GuideRateNP[
AXIS_RA].setValue(GUIDE_RATES[nearestGuideRate(std::strtod(status,
nullptr))]);
224 GuideRateNP.setState(
IPS_OK);
227 if(sendCommand(
":Go#", status))
229 std::string c = status;
230 ElevationLimitNP[OVERHEAD].value = std::stoi(c);
233 if(sendCommand(
":Gh#", status))
235 std::string c = status;
236 ElevationLimitNP[HORIZON].value = std::stoi(c);
239 if(sendCommand(
":GXE9#", status))
241 std::string c = status;
242 MeridianLimitNP[0].setValue(std::stoi(c));
315 return "Pegasus NYX-101";
318const char *
ON =
"ON";
328 propertyTxt[0].setText(
ON);
332 propertyTxt[0].setText(
OFF);
336 propertyTxt[0].setText(
"-");
347 bool _IsTracking =
true;
348 SetPropertyText(IsTracking,
IPS_OK);
350 bool _IsSlewCompleted =
false;
351 SetPropertyText(IsSlewCompleted,
IPS_BUSY);
353 bool _IsParked =
false;
354 SetPropertyText(IsParked,
IPS_BUSY);
356 bool _IsParkingInProgress =
false;
357 SetPropertyText(IsParkginInProgress,
IPS_BUSY);
360 SetPropertyText(IsAtHomePosition,
IPS_BUSY);
362 NYXTelescopeTrackMode _TrackingMode = TRACK_SIDEREAL;
368 bool _DoesRefractionComp =
false;
369 SetPropertyText(DoesRefractionComp,
IPS_BUSY);
372 SetPropertyText(WaitingAtHome,
IPS_BUSY);
375 SetPropertyText(IsHomePaused,
IPS_BUSY);
377 bool _ParkFailed =
false;
378 SetPropertyText(ParkFailed,
IPS_BUSY);
381 SetPropertyText(SlewingHome,
IPS_BUSY);
383 char status[DRIVER_LEN] = {0};
384 const bool statusRead = sendCommand(
":GU#", status);
387 Report[0].text = status;
392 switch (status[index++])
396 SetPropertyText(IsTracking,
IPS_BUSY);
399 _IsSlewCompleted =
true;
400 SetPropertyText(IsSlewCompleted,
IPS_OK);
404 SetPropertyText(IsParked,
IPS_BUSY);
408 SetPropertyText(IsParked,
IPS_OK);
411 _IsParkingInProgress =
true;
412 SetPropertyText(IsParkginInProgress,
IPS_OK);
416 SetPropertyText(IsAtHomePosition,
IPS_OK);
419 _TrackingMode = TRACK_LUNAR;
422 _TrackingMode = TRACK_SOLAR;
425 _TrackingMode = TRACK_KING;
429 SetPropertyText(MountAltAz,
IPS_OK);
430 SetPropertyText(MountEquatorial,
IPS_BUSY);
434 SetPropertyText(MountEquatorial,
IPS_OK);
435 SetPropertyText(MountAltAz,
IPS_BUSY);
444 _DoesRefractionComp =
true;
445 SetPropertyText(DoesRefractionComp,
IPS_OK);
449 SetPropertyText(WaitingAtHome,
IPS_OK);
453 SetPropertyText(IsHomePaused,
IPS_OK);
457 SetPropertyText(ParkFailed,
IPS_OK);
461 SetPropertyText(SlewingHome,
IPS_OK);
474 if(_DoesRefractionComp )
476 RefractSP[REFRACT_ON].setState(
ISS_ON);
477 RefractSP[REFRACT_OFF].setState(
ISS_OFF);
478 RefractSP.setState(
IPS_OK);
483 RefractSP[REFRACT_ON].setState(
ISS_OFF);
484 RefractSP[REFRACT_OFF].setState(
ISS_ON);
485 RefractSP.setState(
IPS_OK);
499 SetPropertyText(PierNone,
IPS_OK);
500 SetPropertyText(PierEast,
IPS_BUSY);
501 SetPropertyText(PierWest,
IPS_BUSY);
504 SetPropertyText(PierEast,
IPS_OK);
505 SetPropertyText(PierNone,
IPS_BUSY);
506 SetPropertyText(PierWest,
IPS_BUSY);
509 SetPropertyText(PierWest,
IPS_OK);
510 SetPropertyText(PierEast,
IPS_BUSY);
511 SetPropertyText(PierNone,
IPS_BUSY);
524 if (!_IsSlewCompleted)
526 else if (m_SlewSeen || std::chrono::steady_clock::now() - m_SlewRequested > SLEW_START_TIMEOUT)
529 LOG_INFO(
"Slew is complete. Tracking...");
532 else if (m_UnparkPending)
536 m_UnparkPending =
false;
537 else if (std::chrono::steady_clock::now() - m_UnparkRequested > UNPARK_TIMEOUT)
539 m_UnparkPending =
false;
540 LOG_WARN(
"Mount is still parked after the unpark request.");
548 const char *reason =
nullptr;
550 reason =
"Mount reports that parking failed.";
551 else if (!_IsParkingInProgress && _IsSlewCompleted &&
552 std::chrono::steady_clock::now() - m_ParkRequested > PARK_START_TIMEOUT)
553 reason =
"Mount did not start parking. Check that it has received time and location, and has a park position.";
572 LOG_INFO(
"Mount reports unparked.");
578 if (wasTracking != _IsTracking)
593 char response[DRIVER_LEN] = {0};
594 if (sendCommand(
":Gm#", response))
596 if (response[0] ==
'W')
598 else if (response[0] ==
'E')
614 if (MeridianLimitNP.isNameMatch(name))
616 MeridianLimitNP.update(values, names,
n);
619 std::string command =
":SXE9," + std::to_string(MeridianLimitNP[0].getValue()) +
"#";;
620 sendCommand(command.c_str());
621 command =
":SXEA," + std::to_string(MeridianLimitNP[0].getValue()) +
"#";;
622 sendCommand(command.c_str());
623 if (MeridianLimitNP.getState() ==
IPS_OK)
625 LOGF_INFO(
"Meridian!: ", MeridianLimitNP[0].getValue());
631 MeridianLimitNP.setState(
IPS_OK);
634 MeridianLimitNP.apply();
638 if (GuideRateNP.isNameMatch(name))
641 double requested = values[0];
642 for (
int i = 0; i <
n; i++)
644 auto element = GuideRateNP.findWidgetByName(names[i]);
645 if (element && std::fabs(element->getValue() - values[i]) > 1e-6)
647 requested = values[i];
652 const int index = nearestGuideRate(requested);
660 if (std::fabs(GUIDE_RATES[index] - requested) > 1e-6)
661 LOGF_INFO(
"NYX-101 supports guide rates 0.25, 0.50 and 1.00 only, using %.2f.", GUIDE_RATES[index]);
662 if (std::fabs(GUIDE_RATES[index] - GuideRateNP[
AXIS_RA].getValue()) > 1e-6)
663 LOG_WARN(
"RA and DEC guide rate changed.");
665 setGuideRateValue(index);
669 if (ElevationLimitNP.isNameMatch(name))
671 if(ElevationLimitNP.update(values, names,
n))
673 for(
int i = 0; i <
n; ++i)
675 if(ElevationLimitNP[OVERHEAD].isNameMatch(names[i]))
677 std::string command =
":So" + std::to_string(
static_cast<int>(ElevationLimitNP[OVERHEAD].getValue())) +
"#";;
678 sendCommand(command.c_str());
680 else if(ElevationLimitNP[HORIZON].isNameMatch(names[i]))
682 std::string command =
":Sh" + std::to_string(
static_cast<int>(ElevationLimitNP[HORIZON].getValue())) +
"#";;
683 sendCommand(command.c_str());
686 ElevationLimitNP.apply();
699 if(FlipSP.isNameMatch(name))
701 FlipSP.update(states, names,
n);
708 FlipSP.setState(state);
712 else if(RebootSP.isNameMatch(name))
714 RebootSP.update(states, names,
n);
719 sendCommand(
":ERESET#");
721 RebootSP.setState(state);
725 else if(SafetyLimitSP.isNameMatch(name))
727 SafetyLimitSP.update(states, names,
n);
728 auto index = SafetyLimitSP.findOnSwitchIndex();
731 case SET_SAFETY_LIMIT:
732 sendCommand(
":Sc1#");
735 case CLEAR_SAFETY_LIMIT:
736 sendCommand(
":Sc0#");
740 SafetyLimitSP.apply();
743 else if(RefractSP.isNameMatch(name))
745 RefractSP.update(states, names,
n);
746 auto index = RefractSP.findOnSwitchIndex();
760 else if(VerboseReportSP.isNameMatch(name))
762 VerboseReportSP.update(states, names,
n);
763 int index = VerboseReportSP.findOnSwitchIndex();
764 VerboseReportSP[index].setState(
ISS_OFF);
767 verboseReport =
true;
771 SetPropertyText(IsTracking,
IPS_IDLE);
772 SetPropertyText(IsSlewCompleted,
IPS_IDLE);
773 SetPropertyText(IsParked,
IPS_IDLE);
774 SetPropertyText(IsParkginInProgress,
IPS_IDLE);
775 SetPropertyText(IsAtHomePosition,
IPS_IDLE);
776 SetPropertyText(MountAltAz,
IPS_IDLE);
777 SetPropertyText(MountEquatorial,
IPS_IDLE);
778 SetPropertyText(PierNone,
IPS_IDLE);
779 SetPropertyText(PierEast,
IPS_IDLE);
780 SetPropertyText(PierWest,
IPS_IDLE);
781 SetPropertyText(DoesRefractionComp,
IPS_IDLE);
782 SetPropertyText(WaitingAtHome,
IPS_IDLE);
783 SetPropertyText(IsHomePaused,
IPS_IDLE);
784 SetPropertyText(ParkFailed,
IPS_IDLE);
785 SetPropertyText(SlewingHome,
IPS_IDLE);
786 verboseReport =
false;
791 VerboseReportSP.apply();
803 if (DebugCommandTP.isNameMatch(name))
805 DebugCommandTP.update(texts, names,
n);
806 for(
int i = 0; i <
n; i++)
808 if(DebugCommandTP[0].isNameMatch(names[i]))
810 char status[DRIVER_LEN] = {0};
811 sendCommand(texts[i]);
828 m_SlewRequested = std::chrono::steady_clock::now();
870 char decCommand[DRIVER_LEN] = {0};
871 snprintf(decCommand, DRIVER_LEN,
":RE%f#", value);
873 char raCommand[DRIVER_LEN] = {0};
874 snprintf(raCommand, DRIVER_LEN,
":RA%f#", value);
876 return sendCommand(decCommand) && sendCommand(raCommand);
879bool LX200NYX101::setGuideRate(
int rate)
881 char command[DRIVER_LEN] = {0};
882 snprintf(command, DRIVER_LEN,
":R%d#", rate);
883 return sendCommand(command);
886int LX200NYX101::nearestGuideRate(
double rate)
889 for (
int i = 1; i < 3; i++)
890 if (std::fabs(GUIDE_RATES[i] - rate) < std::fabs(GUIDE_RATES[index] - rate))
895void LX200NYX101::setGuideRateValue(
int index)
897 GuideRateNP[
AXIS_RA].setValue(GUIDE_RATES[index]);
898 GuideRateNP[
AXIS_DE].setValue(GUIDE_RATES[index]);
899 GuideRateNP.setState(
IPS_OK);
908 return sendCommand(
":TQ#");
911 return sendCommand(
":TS#");
914 return sendCommand(
":TL#");
917 return sendCommand(
":TK#");
927 LOG_ERROR(
"NYX-101 supports Alt-Az and German equatorial modes only.");
937 LOG_WARN(
"Restart mount in order to apply changes to Mount Type.");
941bool LX200NYX101::goToPark()
944 return sendCommand(
":hP#");
947bool LX200NYX101::goToUnPark()
951 char response[DRIVER_LEN] = {0};
952 if (!sendCommand(
":hR#", response, -1, 1))
955 if (response[0] !=
'1')
956 LOG_DEBUG(
"Mount answered 0 to unpark, it was not parked.");
963 char response[DRIVER_LEN] = {0};
964 if (!sendCommand(
":hQ#", response, -1, 1))
966 LOG_ERROR(
"Failed to set the park position.");
970 if (response[0] !=
'1')
972 LOG_ERROR(
"Mount refused the park position. It must be unparked and stopped, and needs time and location.");
976 LOG_INFO(
"Current position is stored as the mount park position.");
982 LOG_WARN(
"The mount has no default park position. Move it to the park position and select Current.");
988 bool rc = goToPark();
991 m_UnparkPending =
false;
992 m_ParkRequested = std::chrono::steady_clock::now();
1001 bool rc = goToUnPark();
1005 m_UnparkRequested = std::chrono::steady_clock::now();
1006 m_UnparkPending =
true;
1015 char response[DRIVER_LEN] = {0};
1016 bool rc = sendCommand(enabled ?
":Te#" :
":Td#", response, 4, 1);
1017 return rc && response[0] ==
'1';
1022 int h {0}, m {0}, s {0};
1023 char command[DRIVER_LEN] = {0};
1027 snprintf(command, DRIVER_LEN,
":SG%c%02d:%02d#", offset >= 0 ?
'+' :
'-', std::abs(h), m);
1033 char command[DRIVER_LEN] = {0};
1034 snprintf(command, DRIVER_LEN,
":SC%02d/%02d/%02d#", months, days, years % 100);
1041 int d{0}, m{0}, s{0};
1045 if (longitude > 180)
1046 longitude = longitude - 360;
1048 char command[DRIVER_LEN] = {0};
1052 snprintf(command, DRIVER_LEN,
":Sg%c%03d*%02d:%02d#", longitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
1055 LOG_ERROR(
"Error setting site longitude coordinates");
1060 snprintf(command, DRIVER_LEN,
":St%c%02d*%02d:%02d#", latitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
1063 LOG_ERROR(
"Error setting site latitude coordinates");
1071bool LX200NYX101::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
1073 int nbytes_written = 0, nbytes_read = 0, rc = -1;
1075 tcflush(
PortFD, TCIOFLUSH);
1079 char hex_cmd[DRIVER_LEN * 3] = {0};
1080 hexDump(hex_cmd,
cmd, cmd_len);
1094 LOGF_ERROR(
"Serial write error: %s.", errstr);
1105 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
1113 LOGF_ERROR(
"Serial read error: %s.", errstr);
1119 char hex_res[DRIVER_LEN * 3] = {0};
1120 hexDump(hex_res, res, res_len);
1128 tcflush(
PortFD, TCIOFLUSH);
1133void LX200NYX101::hexDump(
char * buf,
const char * data,
int size)
1135 for (
int i = 0; i < size; i++)
1136 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
1139 buf[3 * size - 1] =
'\0';
1148 sendCommand(
":hC#");
1152 sendCommand(
":hF#");
1162std::vector<std::string> LX200NYX101::split(
const std::string &input,
const std::string ®ex)
1165 std::regex re(regex);
1166 std::sregex_token_iterator
1167 first{input.begin(), input.end(), re, -1},
1169 return {first, last};
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)
bool isSimulation() const
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
TelescopeStatus TrackState
TelescopeMountType getMountType() const
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
Connection::Serial * serialConnection
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
TelescopeMountType
Mount geometry reported in the standard TELESCOPE_MOUNT_TYPE property. The values are the indices of ...
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)
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
@ TELESCOPE_HAS_PIER_SIDE
@ TELESCOPE_CAN_SET_MOUNT_TYPE
@ TELESCOPE_HAS_TRACK_MODE
@ TELESCOPE_CAN_CONTROL_TRACK
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 SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool setUTCOffset(double offset) override
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool SetMountType(TelescopeMountType type) override
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years) override
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool Park() override
Park the telescope to its home position.
virtual const char * getDefaultName() override
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Execute a homing action.
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.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
void setLX200Capability(uint32_t cap)
@ LX200_HAS_PULSE_GUIDING
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
INDI::PropertySwitch ParkSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch TrackStateSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MountTypeSP
Standard TELESCOPE_MOUNT_TYPE property, indexed by TelescopeMountType. Writable if the driver sets TE...
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.
*brief user defined string literal for JSON values *sa std::size_t n
#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 setStandardProcedure(int fd, const char *data)
#define getLX200DEC(fd, x)
#define getLX200RA(fd, x)