6#include <libnova/transform.h>
67 GuideRateNP[0].fill(
"RATE",
"Rate",
"%.2f", 0.1, 0.9, 0.1, 0.5);
72 BuzzerSP[BUZZER_OFF].fill(
"OFF",
"Off",
ISS_OFF);
73 BuzzerSP[BUZZER_LOW].fill(
"LOW",
"Low",
ISS_OFF);
74 BuzzerSP[BUZZER_HIGH].fill(
"HIGH",
"High",
ISS_ON);
76 BuzzerSP.onUpdate([
this]
78 if (setBuzzer(BuzzerSP.findOnSwitchIndex()))
93 MeridianFlipSP.load();
96 MeridianTrackSP[MERIDIAN_TRACK].fill(
"TRACK",
"Track",
ISS_ON);
97 MeridianTrackSP[MERIDIAN_STOP].fill(
"STOP",
"Stop",
ISS_OFF);
100 MeridianTrackSP.load();
103 MeridianLimitNP[0].fill(
"LIMIT",
"LIMIT (deg)",
"%.f", -15, 15, 1, 0);
105 MeridianLimitNP.load();
147 if (MeridianFlipSP.isNameMatch(name))
149 MeridianFlipSP.update(states, names,
n);
151 MeridianTrackSP[MERIDIAN_TRACK].getState() ==
ISS_ON,
152 MeridianLimitNP[0].getValue());
154 MeridianFlipSP.apply();
160 if (MeridianTrackSP.isNameMatch(name))
162 MeridianTrackSP.update(states, names,
n);
164 MeridianTrackSP[MERIDIAN_TRACK].getState() ==
ISS_ON,
165 MeridianLimitNP[0].getValue());
167 MeridianTrackSP.apply();
181 if (GuideRateNP.isNameMatch(name))
183 GuideRateNP.update(values, names,
n);
184 GuideRateNP.setState(setGuideRate(GuideRateNP[0].getValue()) ?
IPS_OK :
IPS_ALERT);
190 if (MeridianLimitNP.isNameMatch(name))
192 MeridianLimitNP.update(values, names,
n);
194 MeridianTrackSP[MERIDIAN_TRACK].getState() ==
ISS_ON,
195 MeridianLimitNP[0].getValue());
197 MeridianLimitNP.apply();
208 return "TOUPTEK SH20";
213 LOG_DEBUG(
"Checking SH20 connection...");
216 for (
int i = 0; i < 2; i++)
221 const struct timespec timeout = {0, 250000000L};
222 nanosleep(&timeout, NULL);
234 bool isNotMove =
true, isAtHome =
false;
236 char status[DRIVER_LEN] = {0};
237 if (sendCommand(
":GU#", status))
239 isNotMove = strchr(status,
'N');
240 isAtHome = strchr(status,
'H');
257 LOG_INFO(
"Slew is complete. Tracking...");
269 char response[DRIVER_LEN] = {0};
270 if (sendCommand(
":GTS#", response))
273 auto nowTracking = response[0] ==
'1';
274 if (wasTracking != nowTracking)
289 char response[DRIVER_LEN] = {0};
290 if (sendCommand(
":Gm#", response))
292 if (response[0] ==
'1')
294 else if (response[0] ==
'0')
312 int d = 0, m = 0, s = 0;
316 longitude = longitude - 360;
318 char command[DRIVER_LEN] = {0};
320 snprintf(command, DRIVER_LEN,
":Sg%c%03d*%02d:%02d#", longitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
323 LOG_ERROR(
"Error setting site longitude coordinates");
328 snprintf(command, DRIVER_LEN,
":St%c%02d*%02d:%02d#", latitude >= 0 ?
'+' :
'-', std::abs(d), m, s);
331 LOG_ERROR(
"Error setting site latitude coordinates");
343 int h = 0, m = 0, s = 0;
344 char command[DRIVER_LEN] = {0};
347 snprintf(command, DRIVER_LEN,
":SG%c%02d:%02d#", offset >= 0 ?
'+' :
'-', std::abs(h), m);
353 char command[DRIVER_LEN] = {0};
354 snprintf(command, DRIVER_LEN,
":SC%02d/%02d/%02d#", months, days, years % 100);
363 const struct timespec timeout = {0, 100000000L};
367 char RAStr[64] = {0}, DecStr[64] = {0};
414 nanosleep(&timeout,
nullptr);
432 LOGF_ERROR(
"Error Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
441 LOGF_INFO(
"Slewing to RA: %s - DEC: %s", RAStr, DecStr);
451 char command[DRIVER_LEN] = {0};
452 snprintf(command, DRIVER_LEN,
":R%d#", index);
453 return sendCommand(command);
461 char response[DRIVER_LEN] = {0};
462 bool rc = sendCommand(enabled ?
":Te#" :
":Td#", response, 4, 1);
463 return rc && response[0] ==
'1';
471 char response[DRIVER_LEN] = {0};
472 bool rc = sendCommand(
":SPc#", response, 5, 1);
473 return rc && response[0] ==
'1';
478 if (!sendCommand(
":MP1#"))
486 if (!sendCommand(
":MP0#"))
521bool ToupSH20::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
523 int nbytes_written = 0, nbytes_read = 0, rc = -1;
525 tcflush(
PortFD, TCIOFLUSH);
529 char hex_cmd[DRIVER_LEN * 3] = {0};
530 hexDump(hex_cmd,
cmd, cmd_len);
544 LOGF_ERROR(
"Serial write error: %s.", errstr);
555 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
569 char hex_res[DRIVER_LEN * 3] = {0};
570 hexDump(hex_res, res, res_len);
578 tcflush(
PortFD, TCIOFLUSH);
583void ToupSH20::hexDump(
char * buf,
const char * data,
int size)
585 for (
int i = 0; i < size; i++)
586 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
589 buf[3 * size - 1] =
'\0';
595void ToupSH20::getStartupData()
603 getMeridianFlipSettings();
613 LOG_ERROR(
"SH20 supports Alt-Az and German equatorial modes only.");
624 LOG_WARN(
"You must reconnect mount for change to take effect.");
628bool ToupSH20::readMountType()
630 char response[DRIVER_LEN] = {0};
631 if (!sendCommand(
":GU#", response))
634 if (strchr(response,
'Z'))
636 else if (strchr(response,
'G'))
644bool ToupSH20::goHome()
646 return sendCommand(
":MH#");
649bool ToupSH20::findHome()
651 const char cmd[] =
":MFH#";
653 return sendCommand(
cmd, &status, strlen(
cmd),
sizeof(status)) && status ==
'1';
659bool ToupSH20::getTrackMode()
661 char response[DRIVER_LEN] = {0};
662 if (sendCommand(
":GT#", response))
665 auto onIndex = response[0];
678bool ToupSH20::setGuideRate(
double value)
680 char command[DRIVER_LEN] = {0};
681 snprintf(command, DRIVER_LEN,
":Sgr%.2f#", value);
682 return sendCommand(command);
685bool ToupSH20::getGuideRate()
687 char response[DRIVER_LEN] = {0};
688 if (sendCommand(
":Ggr#", response))
691 if (sscanf(response,
"%lf", &value) == 1)
693 GuideRateNP[0].setValue(value);
704bool ToupSH20::setBuzzer(
int value)
706 char command[DRIVER_LEN] = {0};
707 snprintf(command, DRIVER_LEN,
":SBz%d#", value);
708 return sendCommand(command);
711bool ToupSH20::getBuzzer()
713 char response[DRIVER_LEN] = {0};
714 if (sendCommand(
":GBz#", response))
717 auto onIndex = response[0];
718 BuzzerSP[onIndex].setState(
ISS_ON);
719 BuzzerSP.setState(
IPS_OK);
732bool ToupSH20::setMeridianFlipSettings(
bool enabled,
bool track,
double limit)
734 char command[DRIVER_LEN] = {0};
735 snprintf(command, DRIVER_LEN,
":STa%d%d%c%02d#", enabled ? 1 : 0, track ? 1 : 0,
736 limit >= 0 ?
'+' :
'-',
static_cast<int>(std::abs(limit)));
737 char response[2] = {0};
738 auto rc = sendCommand(command, response, -1, 1);
739 return rc && response[0] ==
'1';
742bool ToupSH20::getMeridianFlipSettings()
744 char response[DRIVER_LEN] = {0};
745 if (sendCommand(
":GTa#", response))
747 if (strlen(response) >= 5)
749 MeridianFlipSP.reset();
751 MeridianFlipSP.setState(
IPS_OK);
753 MeridianTrackSP.reset();
754 MeridianTrackSP[response[1] ==
'1' ? MERIDIAN_TRACK : MERIDIAN_STOP].setState(
ISS_ON);
755 MeridianTrackSP.setState(
IPS_OK);
757 char *sign = &response[2];
758 char *limit = &response[3];
759 int limitValue = atoi(limit);
761 limitValue = -limitValue;
762 MeridianLimitNP[0].setValue(limitValue);
763 MeridianLimitNP.setState(
IPS_OK);
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
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
TelescopeStatus TrackState
TelescopeMountType getMountType() const
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
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)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
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_CAN_HOME_FIND
@ 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 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 ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void setLX200Capability(uint32_t cap)
@ LX200_HAS_PULSE_GUIDING
virtual bool ReadScopeStatus() override
Read telescope status.
virtual const char * getDefaultName() override
virtual bool Park() override
Park the telescope to its home position.
virtual bool checkConnection() override
virtual bool SetSlewRate(int index) override
Override - Slew rate.
virtual bool SetMountType(TelescopeMountType type) override
Mount Type.
virtual bool Goto(double ra, double dec) override
Override - Goto.
virtual bool SetCurrentPark() override
Override - Park.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Override - Location.
virtual bool setUTCOffset(double offset) override
Override - Date.
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years) override
virtual bool SetTrackEnabled(bool enabled) override
Override - Track enable.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Override - Home.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
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,...
INDI::PropertySwitch AbortSP
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch TrackStateSP
INDI::PropertySwitch HomeSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MountTypeSP
Standard TELESCOPE_MOUNT_TYPE property, indexed by TelescopeMountType. Writable if the driver sets TE...
INDI::PropertySwitch MovementWESP
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 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[].
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.
int IUGetConfigOnSwitchIndex(const char *dev, const char *property, int *index)
IUGetConfigOnSwitchIndex Opens configuration file and reads single switch property to find ON switch ...
*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 setObjectRA(int fd, double ra, bool addSpace)
int getLX200EquatorialFormat()
int setStandardProcedure(int fd, const char *data)
int setObjectDEC(int fd, double dec, bool addSpace)
#define getLX200DEC(fd, x)
#define getLX200RA(fd, x)