Instrument Neutral Distributed Interface INDI 2.2.5
lx200_10micron.cpp
Go to the documentation of this file.
1/*
2 10micron INDI driver
3 GM1000HPS GM2000QCI GM2000HPS GM3000HPS GM4000QCI GM4000HPS AZ2000
4 Mount Command Protocol 3.1.16, needs firmware 2.14.9 or newer (:Ginfo#)
5
6 Copyright (C) 2017-2026 Hans Lambermont
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
29
30#include "lx200_10micron.h"
31#include "indicom.h"
32#include "lx200driver.h"
33
34#include <cmath>
35#include <cstring>
36#include <string>
37#include <strings.h>
38#include <termios.h>
39#include <math.h>
40#include <libnova/libnova.h>
41
42#define PRODUCT_TAB "Product"
43#define ALIGNMENT_TAB "Alignment"
44#define LX200_TIMEOUT 5 /* FD timeout in seconds */
45
46// INDI Number and Text names
47#define REFRACTION_MODEL_TEMPERATURE "REFRACTION_MODEL_TEMPERATURE"
48#define REFRACTION_MODEL_PRESSURE "REFRACTION_MODEL_PRESSURE"
49#define MODEL_COUNT "MODEL_COUNT"
50#define ALIGNMENT_POINTS "ALIGNMENT_POINTS"
51#define ALIGNMENT_STATE "Alignment"
52#define MINIMAL_NEW_ALIGNMENT_POINT_RO "MINIMAL_NEW_ALIGNMENT_POINT_RO"
53#define MINIMAL_NEW_ALIGNMENT_POINT "MINIMAL_NEW_ALIGNMENT_POINT"
54#define NEW_ALIGNMENT_POINT "NEW_ALIGNMENT_POINT"
55#define NEW_ALIGNMENT_POINTS "NEW_ALIGNMENT_POINTS"
56#define NEW_MODEL_NAME "NEW_MODEL_NAME"
57#define PRODUCT_INFO "PRODUCT_INFO"
58#define TLE_TEXT "TLE_TEXT"
59#define TLE_NUMBER "TLE_NUMBER"
60#define TRAJECTORY_TIME "TRAJECTORY_TIME"
61#define SAT_TRACKING_STAT "SAT_TRACKING_STAT"
62#define UNATTENDED_FLIP "UNATTENDED_FLIP"
63#define WAKE_ON_LAN_MAC "WAKE_ON_LAN_MAC"
64#define WAKE_ON_LAN_SEND "WAKE_ON_LAN_SEND"
65#define MOUNT_SHUTDOWN "MOUNT_SHUTDOWN"
66#define MERIDIAN_LIMITS "MERIDIAN_LIMITS"
67#define TRACKING_END "TRACKING_END"
68#define ALLOWED_MERIDIAN_SIDE "ALLOWED_MERIDIAN_SIDE"
69#define TARGET_PIER_SIDE "TARGET_PIER_SIDE"
70#define SLEW_SETTLE_TIME "SLEW_SETTLE_TIME"
71// The protocol allows 0 to 99999 s; writes above this are refused, values above it set elsewhere are shown
72#define SLEW_SETTLE_TIME_MAX_IN_S 60
73
96
97// Called by INDI::DefaultDevice::ISGetProperties
98// Note that getDriverName calls ::getDefaultName which returns LX200 Generic
100{
101 return "10micron";
102}
103
104// Called by INDI::Telescope::callHandshake, either TCP Connect or Serial Port Connect
106{
107 fd = PortFD;
108
109 if (isSimulation() == true)
110 {
111 LOG_INFO("Simulate Connect.");
112 return true;
113 }
114
115 // Set Ultra Precision Mode #:U2# , replies like 15:58:19.49 instead of 15:21.2
116 LOG_INFO("Setting Ultra Precision Mode.");
117 // #:U2#
118 // Set ultra precision mode. In ultra precision mode, extra decimal digits are returned for
119 // some commands, and there is no more difference between different emulation modes.
120 // Returns: nothing
121 // Available from version 2.10.
122 if (setCommandInt(fd, 2, "#:U") < 0)
123 {
124 LOG_ERROR("Failed to set Ultra Precision Mode.");
125 return false;
126 }
127
128 return true;
129}
130
131// Called only once by DefaultDevice::ISGetProperties
132// Initialize basic properties that are required all the time
134{
135 const bool result = LX200Generic::initProperties();
136 if (result)
137 {
138 // TODO initialize properties additional to INDI::Telescope
142 UNATTENDED_FLIP, "Unattended Flip", MOTION_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
143
144 IUFillNumber(&RefractionModelTemperatureN[0], "TEMPERATURE", "Celsius", "%+6.1f", -999.9, 999.9, 0, 0.);
147
148 IUFillNumber(&RefractionModelPressureN[0], "PRESSURE", "hPa", "%6.1f", 0.0, 9999.9, 0, 0.);
151
152 IUFillNumber(&ModelCountN[0], "COUNT", "#", "%.0f", 0, 999, 0, 0);
154 MODEL_COUNT, "Models", ALIGNMENT_TAB, IP_RO, 60, IPS_IDLE);
155
156 IUFillNumber(&AlignmentPointsN[0], "COUNT", "#", "%.0f", 0, 100, 0, 0);
159
160 IUFillSwitch(&AlignmentStateS[ALIGN_IDLE], "Idle", "Idle", ISS_ON);
161 IUFillSwitch(&AlignmentStateS[ALIGN_START], "Start", "Start new model", ISS_OFF);
162 IUFillSwitch(&AlignmentStateS[ALIGN_END], "End", "End new model", ISS_OFF);
163 IUFillSwitch(&AlignmentStateS[ALIGN_DELETE_CURRENT], "Del", "Delete current model", ISS_OFF);
166
167 IUFillNumber(&MiniNewAlpRON[MALPRO_MRA], "MRA", "Mount RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
168 IUFillNumber(&MiniNewAlpRON[MALPRO_MDEC], "MDEC", "Mount DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
169 IUFillNumber(&MiniNewAlpRON[MALPRO_MSIDE], "MSIDE", "Pier Side (0=E 1=W)", "%.0f", 0, 1, 0, 0);
170 IUFillNumber(&MiniNewAlpRON[MALPRO_SIDTIME], "SIDTIME", "Sidereal Time (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
173
174 IUFillNumber(&MiniNewAlpN[MALP_PRA], "PRA", "Solved RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
175 IUFillNumber(&MiniNewAlpN[MALP_PDEC], "PDEC", "Solved DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
178
179 IUFillNumber(&NewAlpN[ALP_MRA], "MRA", "Mount RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
180 IUFillNumber(&NewAlpN[ALP_MDEC], "MDEC", "Mount DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
181 IUFillNumber(&NewAlpN[ALP_MSIDE], "MSIDE", "Pier Side (0=E 1=W)", "%.0f", 0, 1, 0, 0);
182 IUFillNumber(&NewAlpN[ALP_SIDTIME], "SIDTIME", "Sidereal Time (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
183 IUFillNumber(&NewAlpN[ALP_PRA], "PRA", "Solved RA (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
184 IUFillNumber(&NewAlpN[ALP_PDEC], "PDEC", "Solved DEC (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
186 NEW_ALIGNMENT_POINT, "New Point", ALIGNMENT_TAB, IP_RW, 60, IPS_IDLE);
187
188 IUFillNumber(&NewAlignmentPointsN[0], "COUNT", "#", "%.0f", 0, 100, 1, 0);
190 NEW_ALIGNMENT_POINTS, "New Points", ALIGNMENT_TAB, IP_RO, 60, IPS_IDLE);
191
192 // Set saves the current model in the mount under this name, see saveModel
193 IUFillText(&NewModelNameT[0], "NAME", "Model name, at most 15 characters", "newmodel");
195 NEW_MODEL_NAME, "Save Model As", ALIGNMENT_TAB, IP_RW, 60, IPS_IDLE);
196
197 IUFillNumber(&TLEfromDatabaseN[0], "NUMBER", "#", "%.0f", 1, 999, 1, 1);
199 "TLE_NUMBER", "Database TLE ", SATELLITE_TAB, IP_RW, 60, IPS_IDLE);
200
201
202 IUFillText(&WoLMacT[0], "MAC", "MAC Address (XX:XX:XX:XX:XX:XX)", "");
204 IPS_IDLE);
205 char wolMacBuf[128] = {};
206 if (IUGetConfigText(getDeviceName(), WoLMacTP.name, WoLMacT[0].name, wolMacBuf, sizeof(wolMacBuf)) == 0)
207 IUSaveText(&WoLMacT[0], wolMacBuf);
208
209 IUFillSwitch(&WoLSendS[0], "SEND", "Wake Mount", ISS_OFF);
211 ISR_ATMOST1, 60, IPS_IDLE);
212
213 MountShutdownSP[0].fill("SHUTDOWN", "Shutdown Mount", ISS_OFF);
215 IPS_IDLE);
216
217 // Meridian. The limits and allowed side are mount settings,
218 // the time to tracking end and target pier side are computed by the mount and read-only.
219 // Ranges from the manual (firmware 3.1.4) 6.3.11 Flip Slew Tol. and 6.3.12 Flip Guide Tol.
220 MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].fill("SLEW_LIMIT_IN_DEG", "Slew limit (deg), Flip Slew Tolerance",
221 "%.0f", 0, 30, 1, 0);
222 MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].fill("TRACK_LIMIT_IN_DEG",
223 "Tracking limit (deg), Flip Guide Tolerance, >= slew limit", "%.0f", 2, 30, 1, 2);
224 MeridianLimitsNP.fill(getDeviceName(), MERIDIAN_LIMITS, "Meridian Limits", MOTION_TAB, IP_RW, 60, IPS_IDLE);
225
226 TrackingEndNP[0].fill("TIME_TO_END_IN_S", "Time to tracking end (s), estimate in whole minutes",
227 "%.0f", 0, 999999, 0, 0);
228 TrackingEndNP.fill(getDeviceName(), TRACKING_END, "Tracking End", MOTION_TAB, IP_RO, 60, IPS_IDLE);
229
230 // Labels (TELESCOPE_PIER_SIDE style): the pier side the mount is allowed to use.
231 // The manual names the choices by the objects allowed.
232 // This results in "West" in 10Micron = "East (pointing west)" in INDI, and vice versa.
233 AllowedMeridianSideSP[MERIDIAN_SIDE_BOTH].fill("BOTH", "Both", ISS_ON);
234 AllowedMeridianSideSP[MERIDIAN_SIDE_WEST_ONLY].fill("WEST_ONLY", "East (pointing west)", ISS_OFF);
235 AllowedMeridianSideSP[MERIDIAN_SIDE_EAST_ONLY].fill("EAST_ONLY", "West (pointing east)", ISS_OFF);
237 ISR_1OFMANY, 60, IPS_IDLE);
238
239 TargetPierSideSP[TARGET_PIER_WEST].fill("PIER_WEST", "West (pointing east)", ISS_OFF);
240 TargetPierSideSP[TARGET_PIER_EAST].fill("PIER_EAST", "East (pointing west)", ISS_OFF);
241 TargetPierSideSP[TARGET_PIER_NONE].fill("NONE", "None (no target or unreachable)", ISS_ON);
243 IPS_IDLE);
244
245 // Slew settle time, a mount setting that only the protocol manual describes, see getSlewSettleTime
246 SlewSettleTimeNP[0].fill("SETTLE_TIME_IN_S", "Slew settle time (s)", "%.3f", 0, SLEW_SETTLE_TIME_MAX_IN_S, 1, 0);
247 SlewSettleTimeNP.fill(getDeviceName(), SLEW_SETTLE_TIME, "Slew Settle Time", MOTION_TAB, IP_RW, 60, IPS_IDLE);
248 }
249 return result;
250}
251
259
261{
265 // The driver owns the mount settings: saved values are written to the mount when the config is loaded
266 SlewSettleTimeNP.save(fp);
267 MeridianLimitsNP.save(fp);
268 AllowedMeridianSideSP.save(fp);
269 return true;
270}
271
272// Called by INDI::Telescope when connected state changes to add/remove properties
274{
275 // Define MountShutdownSP before the parent call so it appears immediately on connect,
276 // not after the slow getBasicData() mount queries inside LX200Generic::updateProperties().
277 if (isConnected())
279
280 bool result = LX200Generic::updateProperties();
281
282 if (isConnected())
283 {
285 // getMountInfo defines ProductTP
297 // Read the values before defining the properties: clients such as KStars fill their edit fields
298 // (sliders) from the definition, so pressing Set without changes then writes the mount's own values.
299 updateMeridianValues(true);
305
306 // read UnAttendedFlip setting from config and apply if available
307 int readit = 0;
308 for (int i = 0; readit == 0 && i < UnattendedFlipSP.nsp; i++)
309 {
311 &(UnattendedFlipS[i].s));
312 }
313 if (readit == 0)
314 {
316 {
317 LOGF_INFO("Unattended Flip from config and mount are %s",
318 (UnattendedFlipS[UNATTENDED_FLIP_ENABLED].s == ISS_ON) ? "enabled" : "disabled");
319 }
320 else
321 {
322 if (UnattendedFlip < 0)
323 LOGF_INFO("Could not read Unattended Flip from the mount, applying %s from config",
324 (UnattendedFlipS[UNATTENDED_FLIP_ENABLED].s == ISS_ON) ? "enabled" : "disabled");
325 else
326 LOGF_INFO("Read Unattended Flip %s from config while mount has %s, updating mount",
327 (UnattendedFlipS[UNATTENDED_FLIP_ENABLED].s == ISS_ON) ? "enabled" : "disabled",
328 (UnattendedFlip == UNATTENDED_FLIP_ENABLED) ? "enabled" : "disabled");
332 // Show what the mount uses now, clients still show the value read before the update
334 }
335 }
336 else
337 {
338 LOG_INFO("Did not find an Unattended Flip setting in the config file. "
339 "Specify desired behaviour in Motion Control tab and save config in Options tab.");
340 }
341 }
342 else
343 {
363 }
364
365 return result;
366}
367
368// Called by LX200Generic::updateProperties
370{
371 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
372
373 // cannot call LX200Generic::getBasicData(); as getTimeFormat :Gc# (and getSiteName :GM#) are not implemented
374 // on 10Micron
375 if (!isSimulation())
376 {
377 getMountInfo();
378
379 getAlignment();
382
383 if (getTrackFreq(PortFD, &TrackFreqN[0].value) < 0)
384 {
385 LOG_WARN("Failed to get tracking frequency from device.");
386 }
387 else
388 {
389 LOGF_INFO("Tracking frequency is %.1f Hz", TrackFreqN[0].value);
390 IDSetNumber(&TrackFreqNP, nullptr);
391 }
392
393 // A failed read shows 0 with the property in Alert, instead of whatever was in memory
394 char RefractionModelTemperature[80] = {0};
395 float rmtemp = 0;
396 if (getCommandString(PortFD, RefractionModelTemperature, "#:GRTMP#") == 0
397 && sscanf(RefractionModelTemperature, "%f", &rmtemp) == 1)
398 {
400 LOGF_INFO("RefractionModelTemperature is %0+6.1f degrees C", rmtemp);
401 }
402 else
403 {
405 LOG_WARN("Failed to read the refraction model temperature.");
406 }
407 RefractionModelTemperatureN[0].value = rmtemp;
409
410 char RefractionModelPressure[80] = {0};
411 float rmpres = 0;
412 if (getCommandString(PortFD, RefractionModelPressure, "#:GRPRS#") == 0
413 && sscanf(RefractionModelPressure, "%f", &rmpres) == 1)
414 {
416 LOGF_INFO("RefractionModelPressure is %06.1f hPa", rmpres);
417 }
418 else
419 {
421 LOG_WARN("Failed to read the refraction model pressure.");
422 }
423 RefractionModelPressureN[0].value = rmpres;
425
426 int ModelCount = 0;
427 if (getCommandInt(PortFD, &ModelCount, "#:modelcnt#") == 0)
428 {
430 LOGF_INFO("%d Alignment Models", ModelCount);
431 }
432 else
433 {
434 ModelCount = 0;
436 LOG_WARN("Failed to read the number of alignment models.");
437 }
438 ModelCountN[0].value = ModelCount;
439 IDSetNumber(&ModelCountNP, nullptr);
440
441 int AlignmentPoints = 0;
442 if (getCommandInt(PortFD, &AlignmentPoints, "#:getalst#") == 0)
443 {
445 LOGF_INFO("%d Alignment Stars in active model", AlignmentPoints);
446 }
447 else
448 {
449 AlignmentPoints = 0;
451 LOG_WARN("Failed to read the number of alignment stars in the active model.");
452 }
453 AlignmentPointsN[0].value = AlignmentPoints;
455
457 }
458
460 {
461 LOG_INFO("sendLocationOnStartup is enabled, call sendScopeLocation.");
463 }
464 else
465 {
466 LOG_INFO("sendLocationOnStartup is disabled, do not call sendScopeLocation.");
467 }
469 {
470 LOG_INFO("sendTimeOnStartup is enabled, call sendScopeTime.");
472 }
473 else
474 {
475 LOG_INFO("sendTimeOnStartup is disabled, do not call sendScopeTime.");
476 }
477}
478
479// Called by our getBasicData
480bool LX200_10MICRON::getMountInfo()
481{
482 // A failed read leaves the text empty, a date that does not parse is shown as the mount sent it
483 char ProductName[80] = {0};
484 getCommandString(PortFD, ProductName, "#:GVP#");
485 char ControlBox[80] = {0};
486 getCommandString(PortFD, ControlBox, "#:GVZ#");
487 char FirmwareVersion[80] = {0};
488 getCommandString(PortFD, FirmwareVersion, "#:GVN#");
489 char FirmwareDate1[80] = {0};
490 getCommandString(PortFD, FirmwareDate1, "#:GVD#");
491 char FirmwareDate2[80] = {0};
492 getCommandString(PortFD, FirmwareDate2, "#:GVT#");
493 // :GVD# returns e.g. "Jun 10 2026", :GVT# "17:10:10"
494 char mon[4] = {0};
495 int dd = 0, yyyy = 0;
496 char FirmwareDate[80] = {0};
497 if (sscanf(FirmwareDate1, "%3s %2d %4d", mon, &dd, &yyyy) == 3 && monthToNumber(mon) > 0)
498 snprintf(FirmwareDate, sizeof(FirmwareDate), "%04d-%02d-%02dT%s", yyyy, monthToNumber(mon), dd, FirmwareDate2);
499 else
500 snprintf(FirmwareDate, sizeof(FirmwareDate), "%s %s", FirmwareDate1, FirmwareDate2);
501
502 LOGF_INFO("Product:%s Control box:%s Firmware:%s of %s", ProductName, ControlBox, FirmwareVersion, FirmwareDate);
503
504 IUFillText(&ProductT[PRODUCT_NAME], "NAME", "Product Name", ProductName);
505 IUFillText(&ProductT[PRODUCT_CONTROL_BOX], "CONTROL_BOX", "Control Box", ControlBox);
506 IUFillText(&ProductT[PRODUCT_FIRMWARE_VERSION], "FIRMWARE_VERSION", "Firmware Version", FirmwareVersion);
507 IUFillText(&ProductT[PRODUCT_FIRMWARE_DATE], "FIRMWARE_DATE", "Firmware Date", FirmwareDate);
509 PRODUCT_INFO, "Product", PRODUCT_TAB, IP_RO, 60, IPS_IDLE);
510
512
513 return true;
514}
515
516// INDI::Telescope calls ReadScopeStatus() every POLLMS to check the link to the telescope and update its state and
517// position.
518// The child class should call newRaDec() whenever a new value is read from the telescope.
520{
521 if (!isConnected())
522 {
523 return false;
524 }
525 if (isSimulation())
526 {
527 mountSim();
528 return true;
529 }
530
531 // Read scope status, based loosely on LX200_GENERIC::getCommandString
532 // #:Ginfo#
533 // Get multiple information. Returns a string where multiple data are encoded, separated
534 // by commas ',', and terminated by '#'. Data are recognized by their position in the string.
535 // The data are the following:
536 // Position Datum
537 // 1 The telescope right ascension in hours and decimals (from 000.00000 to 23.99999),
538 // true equinox and equator of date of observation (i.e. Jnow).
539 // 2 The telescope declination in degrees and decimals (from –90.0000 to +90.0000),
540 // true equinox and equator of date of observation (i.e. Jnow).
541 // 3 A flag indicating the side of the pier on which the telescope is currently positioned
542 // ("E" or "W").
543 // 4 The telescope azimuth in degrees and decimals (from 000.0000 to 359.9999).
544 // 5 The telescope altitude in degrees and decimals (from -90.0000 to +90.0000).
545 // 6 The julian date (JJJJJJJ.JJJJJJJJ), UTC, with leap second flag (see command
546 // :GJD2# for the description of this datum).
547 // 7 A number encoding the status of the mount as in the :Gstat command.
548 // 8 A number returning the slew status (0 if :D# would return no slew, 1 otherwise).
549 // The string is terminated by '#'. Other parameters may be added in future at the end of
550 // the string: do not assume that the number of parameters will stay the same.
551 // Available from version 2.14.9 (previous versions may have this command but it was
552 // experimental and possibly with a different format).
553 char cmd[] = "#:Ginfo#";
554 char data[80];
555 char *term;
556 int error_type;
557 int nbytes_write = 0, nbytes_read = 0;
558 // DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s>", cmd);
559 if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
560 {
561 return false;
562 }
563 error_type = tty_read_section(fd, data, '#', LX200_TIMEOUT, &nbytes_read);
564 tcflush(fd, TCIFLUSH);
565 if (error_type != TTY_OK)
566 {
567 return false;
568 }
569 term = strchr(data, '#');
570 if (term)
571 {
572 *(term + 1) = '\0';
573 }
574 else
575 {
576 return false;
577 }
578 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s> RES <%s>", cmd, data);
579
580 // TODO: check if this needs changing when satellite tracking
581 // Now parse the data. This format may consist of more parts some day
582 nbytes_read = sscanf(data, "%g,%g,%c,%g,%g,%g,%d,%d#", &Ginfo.RA_JNOW, &Ginfo.DEC_JNOW, &Ginfo.SideOfPier,
583 &Ginfo.AZ, &Ginfo.ALT, &Ginfo.Jdate, &Ginfo.Gstat, &Ginfo.SlewStatus);
584 if (nbytes_read < 0)
585 {
586 return false;
587 }
588
589 if (Ginfo.Gstat != OldGstat)
590 {
591 if (OldGstat != GSTAT_UNSET)
592 {
593 LOGF_INFO("Gstat changed from %d to %d", OldGstat, Ginfo.Gstat);
594 }
595 else
596 {
597 LOGF_INFO("Gstat initialized at %d", Ginfo.Gstat);
598 }
599 }
600 // The mount can be unparked by another client or the hand pad.
601 // Clear our parked state only when Gstat clearly says the mount is not parked, and leave it
602 // alone for conditions that say nothing about the position (motors too cold, user OK
603 // needed, unknown, error). Done before the switch below, as SetParked(false) also resets TrackState.
604 if (isParked())
605 {
606 switch (Ginfo.Gstat)
607 {
608 case GSTAT_TRACKING:
609 case GSTAT_STOPPED:
610 case GSTAT_PARKING:
611 case GSTAT_UNPARKING:
617 LOGF_INFO("Gstat %d means the mount is no longer parked.", Ginfo.Gstat);
618 SetParked(false);
619 break;
620 default:
621 break;
622 }
623 }
624 switch (Ginfo.Gstat)
625 {
626 case GSTAT_TRACKING:
627 // Settling is the last part of a slew. The protocol manual says that after a slew the :D# command
628 // (Ginfo field 8) "will return a slewing status for the time duration set in" :Sstm, while
629 // "the :Gstat# command is not affected by this setting". Gstat is already 0 then, so only the
630 // slew flag tells that the mount is still settling. Clients must not start exposures before that.
631 // On a GM2000HPS the settle time starts when Gstat leaves 6, not when the motors stop.
632 TrackState = (Ginfo.SlewStatus == 1) ? SCOPE_SLEWING : SCOPE_TRACKING;
633 break;
634 case GSTAT_STOPPED:
636 break;
637 case GSTAT_PARKING:
639 break;
640 case GSTAT_UNPARKING:
641 // "The mount is unparking": not tracking yet. Not seen on a GM2000HPS, where unparking goes from Gstat 5 to 0.
643 break;
646 break;
647 case GSTAT_PARKED:
649 if (!isParked())
650 SetParked(true);
651 break;
654 break;
656 // A slew that ends without tracking (e.g. :MaX#, slew to axis positions and stop) settles in Gstat 7:
657 // the slew flag stays 1 for the settle time here too.
658 TrackState = (Ginfo.SlewStatus == 1) ? SCOPE_SLEWING : SCOPE_IDLE;
659 break;
662 break;
665 break;
668 break;
671 break;
674 break;
675 case GSTAT_ERROR:
677 break;
678 default:
679 return false;
680 }
681 setPierSide((toupper(Ginfo.SideOfPier) == 'E') ? INDI::Telescope::PIER_EAST : INDI::Telescope::PIER_WEST);
682
683 OldGstat = Ginfo.Gstat;
684 NewRaDec(Ginfo.RA_JNOW, Ginfo.DEC_JNOW);
685
686 const bool slewing = (TrackState == SCOPE_SLEWING);
687 if (slewing != MountSlewing)
688 {
689 MountSlewing = slewing;
690 updateSlewDependentValues();
691 }
692
693 // Update alignment Mini new alignment point Read-Only fields
694 char LocalSiderealTimeS[80];
695 getCommandString(fd, LocalSiderealTimeS, "#:GS#");
696 f_scansexa(LocalSiderealTimeS, &Ginfo.SiderealTime);
697 MiniNewAlpRON[MALPRO_MRA].value = Ginfo.RA_JNOW;
698 MiniNewAlpRON[MALPRO_MDEC].value = Ginfo.DEC_JNOW;
699 MiniNewAlpRON[MALPRO_MSIDE].value = (toupper(Ginfo.SideOfPier) == 'E') ? 0 : 1;
700 MiniNewAlpRON[MALPRO_SIDTIME].value = Ginfo.SiderealTime;
701 IDSetNumber(&MiniNewAlpRONP, nullptr);
702
703 updateMeridianValues(false);
704
705 return true;
706}
707
709{
710 // #:KA#
711 // Slew to park position
712 // Returns: nothing
713 LOG_INFO("Parking.");
714 if (setStandardProcedureWithoutRead(fd, "#:KA#") < 0)
715 {
716 ParkSP.setState(IPS_ALERT);
717 LOG_ERROR("Park command failed.");
718 ParkSP.apply();
719 return false;
720 }
721
722 ParkSP.setState(IPS_BUSY);
724 ParkSP.apply();
725 // postpone SetParked(true) for ReadScopeStatus so that we know it is actually correct
726 return true;
727}
728
730{
731 // #:PO#
732 // Unpark
733 // Returns:nothing
734 LOG_INFO("Unparking.");
735 if (setStandardProcedureWithoutRead(fd, "#:PO#") < 0)
736 {
737 ParkSP.setState(IPS_ALERT);
738 LOG_ERROR("Unpark command failed.");
739 ParkSP.apply();
740 return false;
741 }
742
743 ParkSP.setState(IPS_OK);
745 SetParked(false);
746 ParkSP.apply();
747 return true;
748}
749
751{
752 // :AL#
753 // Stops tracking.
754 // Returns: nothing
755 // :AP#
756 // Starts tracking.
757 // Returns: nothing
758 if (enabled)
759 {
760 LOG_INFO("Start tracking.");
761 if (setStandardProcedureWithoutRead(fd, "#:AP#") < 0)
762 {
763 LOG_ERROR("Start tracking command failed");
764 return false;
765 }
766 }
767 else
768 {
769 LOG_INFO("Stop tracking.");
770 if (setStandardProcedureWithoutRead(fd, "#:AL#") < 0)
771 {
772 LOG_ERROR("Stop tracking command failed");
773 return false;
774 }
775 }
776 return true;
777}
778
780{
781 // #:Guaf#
782 // Returns the unattended flip setting.
783 // Returns:
784 // 0 disabled
785 // 1 enabled
786 // Available from version 2.11.
787 // Note: unattended flip didn't work properly in firmware versions up to 2.13.8 included.
788 // The reply is a single digit without a '#' terminator, so read exactly one character instead of
789 // waiting for a '#' that never comes (that cost a 5 second timeout on every connect).
790 // When the setting cannot be read, UnattendedFlip is set to -1 (unknown) and false is returned.
791 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
792 char guaf[2] = {0};
793 if (0 != setStandardProcedureAndReturnResponse(fd, "#:Guaf#", guaf, 1) || (guaf[0] != '0' && guaf[0] != '1'))
794 {
795 UnattendedFlip = -1;
796 return false;
797 }
798 if ('1' == guaf[0])
799 {
801 }
802 else
803 {
805 }
806 return '1' == guaf[0];
807}
808
809// Read the unattended flip setting back from the mount and show it. The mount resets it to disabled at
810// every power up, so this also runs periodically, see updateMeridianValues. What is logged and sent to
811// clients depends on the context: at connect always, periodically only on change, and after a write
812// nothing, as the caller reports the result of the write.
814{
815 const bool enabled = getUnattendedFlipSetting();
816 if (UnattendedFlip < 0)
817 {
818 if (context == READ_AFTER_WRITE)
819 {
821 }
822 else if (context == READ_AT_CONNECT || UnattendedFlipSP.s != IPS_ALERT)
823 {
824 LOG_WARN("Failed to read the Unattended Flip setting.");
826 IDSetSwitch(&UnattendedFlipSP, nullptr);
827 }
828 return;
829 }
830 const ISState enabledState = enabled ? ISS_ON : ISS_OFF;
831 const bool changed = UnattendedFlipS[UNATTENDED_FLIP_ENABLED].s != enabledState || UnattendedFlipSP.s != IPS_OK;
835 if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
836 {
837 if (context == READ_AT_CONNECT)
838 LOGF_INFO("Unattended Flip is %s.", enabled ? "enabled" : "disabled");
839 else
840 LOGF_INFO("Unattended Flip changed on the mount: %s.", enabled ? "enabled" : "disabled");
841 IDSetSwitch(&UnattendedFlipSP, nullptr);
842 }
843}
844
845// After writing the unattended flip setting (:SuafN# returns nothing), read it back to confirm what the
846// mount actually uses, then report the result in one log line and one property update.
848{
850 bool result = false;
851 if (UnattendedFlip < 0)
852 {
853 LOG_WARN("Unattended Flip was written, but could not be read back.");
854 }
855 else if (UnattendedFlip != wanted)
856 {
857 LOGF_ERROR("The mount did not take Unattended Flip %s.",
858 (wanted == UNATTENDED_FLIP_ENABLED) ? "enabled" : "disabled");
860 }
861 else
862 {
863 LOGF_INFO("Unattended Flip set: %s.", (wanted == UNATTENDED_FLIP_ENABLED) ? "enabled" : "disabled");
864 result = true;
865 }
866 IDSetSwitch(&UnattendedFlipSP, nullptr);
867 return result;
868}
869
871{
872 // #:SuafN#
873 // Enables or disables the unattended flip. Use N=1 to enable, N=0 to disable. This is set always to 0 after power up.
874 // Returns: nothing
875 // Available from version 2.11.
876 // unattended flip didn't work properly in firmware versions up to 2.13.8 included.
877 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
878 char data[64];
879 snprintf(data, sizeof(data), "#:Suaf%d#", (setting == false) ? 0 : 1);
880 if (0 == setStandardProcedureWithoutRead(fd, data))
881 {
882 if (setting == false)
883 {
885 }
886 else
887 {
889 }
890 return true;
891 }
892 return false;
893}
894
895// Called by ReadScopeStatus when the mount starts or stops slewing (settling included).
896// The time to tracking end and the target pier side depend on the position and the target.
897// While the mount slews they are Busy: the last values belong to the previous position.
898// When the slew has ended they are read again and become Ok, also when the value did not change,
899// so clients get an event telling them the values now belong to the new position.
900// Slews started outside INDI (keypad, other clients) are handled the same way, as this follows the mount state.
901void LX200_10MICRON::updateSlewDependentValues()
902{
903 if (isSimulation())
904 return;
905
906 if (MountSlewing)
907 {
912 }
913 else
914 {
915 // Whether the slew completed or was aborted is not known here, hence the neutral wording
916 LOG_INFO("Slew ended, mount settled.");
919 lastMeridianFastPoll = std::chrono::steady_clock::now();
920 }
921}
922
923// Called at connect with all=true, and by ReadScopeStatus with all=false.
924
925// The time to tracking end and the target pier side change while the mount
926// tracks, so they are read every 10 seconds (not while slewing, see
927// updateSlewDependentValues).
928// The unattended flip setting is read every 60 seconds because the mount
929// resets it when it powers up.
930// The meridian limits, meridian side, slew settle time and track mode are read
931// every 60 seconds only to show changes made outside this driver. That is not
932// the intended mode of operation: this driver owns these mount settings and
933// writes the saved ones when the config is loaded.
934
935// Properties are only sent when they change.
936void LX200_10MICRON::updateMeridianValues(bool all)
937{
938 if (isSimulation())
939 return;
940
941 if (all)
942 MountSlewing = false;
943
944 const auto now = std::chrono::steady_clock::now();
945 // While slewing the slew dependent values stay Busy, see updateSlewDependentValues
946 if (all || (!MountSlewing && now - lastMeridianFastPoll >= std::chrono::seconds(10)))
947 {
950 lastMeridianFastPoll = now;
951 }
952 if (all || now - lastMeridianSlowPoll >= std::chrono::seconds(60))
953 {
955 getMeridianLimits(context);
956 getAllowedMeridianSide(context);
957 getSlewSettleTime(context);
958 getTrackMode(context);
959 // At connect this is already done by getBasicData
960 if (!all)
962 lastMeridianSlowPoll = now;
963 }
964}
965
967{
968 // #:Glms#
969 // Returns the meridian limit for slews in degrees.
970 // Returns: NN#
971 // The meridian limit for slews in degrees.
972 // Available from version 2.11.
973 // #:Glmt#
974 // Returns the meridian limit for tracking in degrees.
975 // Returns: NN#
976 // The meridian limit for tracking in degrees.
977 // Available from version 2.11.
978 // The manual (firmware 3.1.4) calls these Flip Slew Tol. and Flip Guide Tol.:
979 // 6.3.11 Flip Slew Tol.
980 // Normally, the mount will point an object going to the "correct" side of the meridian; i.e. the telescope
981 // will be to the east of the mount when observing an object in the western sky and vice versa. This option
982 // allows you to "anticipate" an object that has not yet crossed the meridian, if the object is nearer than the
983 // specified value to the meridian. The user movements are blocked after they have gone through the meridian
984 // the "wrong way" more than this value. The value can vary from 0 to 30 degrees. Since this feature allows
985 // the telescope to go to the "wrong" side of the meridian, check that the value you enter here does not allow
986 // collisions between the instrumentation and the mount or the mount's support.
987 // 6.3.12 Flip Guide Tol.
988 // This option allows you to track an object through the meridian for up to 30 degrees on the "wrong" side.
989 // The value can vary from 2 to 30 degrees, and must be greater than the Flip Slew Tol. value. Since this
990 // feature allows the telescope to go to the "wrong" side of the meridian, check that the value you enter here
991 // does not allow collisions between the instrumentation and the mount or the mount's support.
992 // What is logged and sent to clients depends on the context: at connect always, periodically only on
993 // change, and after a write nothing, as the caller reports the result of the write.
994 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
995 char slewLimitString[80] = {0}, trackLimitString[80] = {0};
996 int slewLimit = 0, trackLimit = 0;
997 if (getCommandString(PortFD, slewLimitString, "#:Glms#") != 0 || sscanf(slewLimitString, "%d", &slewLimit) != 1 ||
998 getCommandString(PortFD, trackLimitString, "#:Glmt#") != 0 || sscanf(trackLimitString, "%d", &trackLimit) != 1)
999 {
1000 if (context == READ_AFTER_WRITE)
1001 {
1002 MeridianLimitsNP.setState(IPS_ALERT);
1003 }
1004 else if (context == READ_AT_CONNECT || MeridianLimitsNP.getState() != IPS_ALERT)
1005 {
1006 LOG_WARN("Failed to read the meridian limits.");
1007 MeridianLimitsNP.setState(IPS_ALERT);
1008 MeridianLimitsNP.apply();
1009 }
1010 return false;
1011 }
1012 const bool changed = MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].getValue() != slewLimit ||
1013 MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].getValue() != trackLimit ||
1014 MeridianLimitsNP.getState() != IPS_OK;
1015 MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].setValue(slewLimit);
1016 MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].setValue(trackLimit);
1017 MeridianLimitsNP.setState(IPS_OK);
1018 if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
1019 {
1020 if (context == READ_AT_CONNECT)
1021 LOGF_INFO("Meridian limits are: slew %d, tracking %d degrees.", slewLimit, trackLimit);
1022 else
1023 LOGF_INFO("Meridian limits changed on the mount: slew %d, tracking %d degrees.", slewLimit, trackLimit);
1024 MeridianLimitsNP.apply();
1025 }
1026 return true;
1027}
1028
1029bool LX200_10MICRON::setMeridianLimits(int slewLimit, int trackLimit)
1030{
1031 // #:SlmsNN#
1032 // Sets the meridian limit for slews in degrees. Setting a meridian limit for slews greater
1033 // than the meridian limit for tracking will increase the meridian limit for tracking to the same value.
1034 // Returns:
1035 // 0 invalid
1036 // 1 valid
1037 // Available from version 2.11.
1038 // Note: on AZ2000HPS and AZ4000HPS mounts the meridian limit cannot be set. This command returns always 0.
1039 // #:SlmtNN#
1040 // Sets the meridian limit for tracking in degrees. The minimum value is the same as the
1041 // meridian limit for slews.
1042 // Returns:
1043 // 0 invalid
1044 // 1 valid
1045 // Available from version 2.11.
1046 // Note: on AZ2000HPS and AZ4000HPS mounts the meridian limit cannot be set. This command returns always 0.
1047 // See getMeridianLimits for the manual's description (Flip Slew Tol. and Flip Guide Tol.). The manual says the
1048 // tracking limit must be greater than the slew limit, this protocol description says at least the same, so
1049 // the caller checks >= and the mount has the final say.
1050 // The slew limit is set first, so that any tracking limit at or above the new slew limit is valid.
1051 // Afterwards the limits are read back, so clients see what the mount actually uses. Returns false when
1052 // the mount refused a value; a failed read back leaves MeridianLimitsNP in Alert for the caller to report.
1053 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1054 char data[64];
1055 snprintf(data, sizeof(data), "#:Slms%02d#", slewLimit);
1056 bool result = (0 == setStandardProcedureAndExpectChar(fd, data, "1"));
1057 if (result)
1058 {
1059 snprintf(data, sizeof(data), "#:Slmt%02d#", trackLimit);
1060 result = (0 == setStandardProcedureAndExpectChar(fd, data, "1"));
1061 }
1063 return result;
1064}
1065
1067{
1068 // #:Gmte#
1069 // Returns the estimated time to tracking end due to horizon / flip limits reached.
1070 // Returns: NNNN#
1071 // The estimated time to tracking end in minutes of time.
1072 // Available from version 2.11.
1073 // The mount reports whole minutes, the property is in seconds.
1074 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1075 char timeToEndString[80] = {0};
1076 int minutes = 0;
1077 if (getCommandString(PortFD, timeToEndString, "#:Gmte#") != 0 || sscanf(timeToEndString, "%d", &minutes) != 1)
1078 {
1079 if (TrackingEndNP.getState() != IPS_ALERT)
1080 {
1081 LOG_WARN("Failed to read the time to tracking end.");
1082 TrackingEndNP.setState(IPS_ALERT);
1083 TrackingEndNP.apply();
1084 }
1085 return false;
1086 }
1087 if (TrackingEndNP[0].getValue() != minutes * 60 || TrackingEndNP.getState() != IPS_OK)
1088 {
1089 TrackingEndNP[0].setValue(minutes * 60);
1090 TrackingEndNP.setState(IPS_OK);
1091 TrackingEndNP.apply();
1092 }
1093 return true;
1094}
1095
1097{
1098 // #:GMF#
1099 // Get meridian side behaviour.
1100 // Returns: n#
1101 // A number with the following interpretation:
1102 // 1 both sides of the meridian allowed;
1103 // 2 only objects west of the meridian allowed (plus slew flip tolerance) – all
1104 // slews are done so that after the slew the ":pS#" command would return "East#";
1105 // 3 only objects east of the meridian allowed (plus slew flip tolerance) – all slews
1106 // are done so that after the slew the ":pS#" command would return "West#".
1107 // Available from version 2.7.7.
1108 // The manual (firmware 3.1.4) describes this as:
1109 // 6.3.16 Meridian side
1110 // This function controls the side of the meridian you can observe. As a security feature, you may restrict the
1111 // motion of the mount to only one side of the meridian. Select Both if you want to allow the mount to slew
1112 // to both sides of the meridian (east and west). This is the normal operation, and is required for alignment
1113 // and balance functions.
1114 // Select West or East if you want to restrict the mount so that the scope may point only at objects on one
1115 // side of the meridian (west or east, respectively).
1116 // [...]
1117 // When pointing an object with the command protocol (i.e. from a planetarium software), the mount will fail
1118 // the slew if the object is on the forbidden side of the meridian.
1119 // The INDI labels follow TELESCOPE_PIER_SIDE: West (objects west only) is shown as East (pointing west).
1120 // What is logged and sent to clients depends on the context: at connect always, periodically only on
1121 // change, and after a write nothing, as the caller reports the result of the write.
1122 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1123 char sideString[80] = {0};
1124 int side = 0;
1125 if (getCommandString(PortFD, sideString, "#:GMF#") != 0 || sscanf(sideString, "%d", &side) != 1 || side < 1
1126 || side > MERIDIAN_SIDE_COUNT)
1127 {
1128 if (context == READ_AFTER_WRITE)
1129 {
1131 }
1132 else if (context == READ_AT_CONNECT || AllowedMeridianSideSP.getState() != IPS_ALERT)
1133 {
1134 LOG_WARN("Failed to read the allowed meridian side.");
1136 AllowedMeridianSideSP.apply();
1137 }
1138 return false;
1139 }
1140 const int index = side - 1;
1141 const bool changed = AllowedMeridianSideSP.findOnSwitchIndex() != index || AllowedMeridianSideSP.getState() != IPS_OK;
1142 AllowedMeridianSideSP.reset();
1143 AllowedMeridianSideSP[index].setState(ISS_ON);
1144 AllowedMeridianSideSP.setState(IPS_OK);
1145 if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
1146 {
1147 if (context == READ_AT_CONNECT)
1148 LOGF_INFO("Allowed meridian side is %s.", AllowedMeridianSideSP[index].getLabel());
1149 else
1150 LOGF_INFO("Allowed meridian side changed on the mount: %s.", AllowedMeridianSideSP[index].getLabel());
1151 AllowedMeridianSideSP.apply();
1152 }
1153 return true;
1154}
1155
1157{
1158 // #:SMFn#
1159 // Set meridian side behaviour, where n is an ASCII digit (1..3) with the following
1160 // interpretation:
1161 // 1 both sides of the meridian allowed;
1162 // 2 only objects west of the meridian allowed (plus slew flip tolerance) – all slews
1163 // are done so that after the slew the ":pS#" command would return "East#";
1164 // 3 only objects east of the meridian allowed (plus slew flip tolerance) – all slews
1165 // are done so that after the slew the ":pS#" command would return "West#".
1166 // Returns:
1167 // 0 invalid
1168 // 1 valid
1169 // See getAllowedMeridianSide for the manual's description (6.3.16 Meridian side).
1170 // Afterwards the side is read back, so clients see what the mount actually uses. Returns false when the
1171 // mount refused; a failed read back leaves AllowedMeridianSideSP in Alert for the caller to report.
1172 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1173 char data[64];
1174 snprintf(data, sizeof(data), "#:SMF%d#", side + 1);
1175 const bool result = (0 == setStandardProcedureAndExpectChar(fd, data, "1"));
1177 return result;
1178}
1179
1181{
1182 // #:GTsid#
1183 // Get the destination side of the target object
1184 // Returns:
1185 // 0 no target defined, or the target object is located in a position where it is not
1186 // possible to go
1187 // 2 the target is located in a position where the mount would slew the telescope to
1188 // the west side so that after the slew the ":pS#" command would return "West#".
1189 // 3 the target is located in a position where the mount would slew the telescope to
1190 // the east side so that after the slew the ":pS#" command would return "East#".
1191 // Available from version 2.9.9.
1192 // Notes
1193 // See the :MSfs command.
1194 // Up to version 2.15.31 included, return values 2 and 3 were reversed in the southern hemisphere.
1195 // The reply is a single digit without a '#' terminator, so read exactly one character.
1196 // The target is the last one set, normally by the last goto. This is the pier side a new slew to it
1197 // would end on, which can change while the target moves across the meridian.
1198 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1199 char sideString[2] = {0};
1200 int index = -1;
1201 if (0 == setStandardProcedureAndReturnResponse(fd, "#:GTsid#", sideString, 1))
1202 {
1203 switch (sideString[0])
1204 {
1205 case '0':
1206 index = TARGET_PIER_NONE;
1207 break;
1208 case '2':
1209 index = TARGET_PIER_WEST;
1210 break;
1211 case '3':
1212 index = TARGET_PIER_EAST;
1213 break;
1214 }
1215 }
1216 if (index < 0)
1217 {
1218 if (TargetPierSideSP.getState() != IPS_ALERT)
1219 {
1220 LOG_WARN("Failed to read the target pier side.");
1221 TargetPierSideSP.setState(IPS_ALERT);
1222 TargetPierSideSP.apply();
1223 }
1224 return false;
1225 }
1226 if (TargetPierSideSP.findOnSwitchIndex() != index || TargetPierSideSP.getState() != IPS_OK)
1227 {
1228 TargetPierSideSP.reset();
1229 TargetPierSideSP[index].setState(ISS_ON);
1230 TargetPierSideSP.setState(IPS_OK);
1231 TargetPierSideSP.apply();
1232 }
1233 return true;
1234}
1235
1237{
1238 // #:Gstm#
1239 // Returns the slew settle time. After a slew has been completed, the :D# and :GDW#
1240 // commands will return a slewing status for the time duration set in this command.
1241 // Note: the :Gstat# command is not affected by this setting.
1242 // Returns: NNNNN.NNN#
1243 // The mount settle time in seconds.
1244 // Available from version 2.9.14.
1245 // The user manual (firmware 3.1.4) has no such setting. The driver treats settling as part of the slew, see
1246 // ReadScopeStatus. The panel range is 0 to SLEW_SETTLE_TIME_MAX_IN_S; a larger value set outside INDI is
1247 // still shown as it is, by raising the maximum.
1248 // What is logged and sent to clients depends on the context, as in getMeridianLimits.
1249 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1250 char settleTimeString[80] = {0};
1251 double seconds = 0;
1252 if (getCommandString(PortFD, settleTimeString, "#:Gstm#") != 0 || sscanf(settleTimeString, "%lf", &seconds) != 1)
1253 {
1254 if (context == READ_AFTER_WRITE)
1255 {
1256 SlewSettleTimeNP.setState(IPS_ALERT);
1257 }
1258 else if (context == READ_AT_CONNECT || SlewSettleTimeNP.getState() != IPS_ALERT)
1259 {
1260 LOG_WARN("Failed to read the slew settle time.");
1261 SlewSettleTimeNP.setState(IPS_ALERT);
1262 SlewSettleTimeNP.apply();
1263 }
1264 return false;
1265 }
1266 const bool changed = SlewSettleTimeNP[0].getValue() != seconds || SlewSettleTimeNP.getState() != IPS_OK;
1267 const double max = std::max(static_cast<double>(SLEW_SETTLE_TIME_MAX_IN_S), seconds);
1268 const bool maxChanged = SlewSettleTimeNP[0].getMax() != max;
1269 SlewSettleTimeNP[0].setMax(max);
1270 SlewSettleTimeNP[0].setValue(seconds);
1271 SlewSettleTimeNP.setState(IPS_OK);
1272 if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
1273 {
1274 const char *range = (seconds > SLEW_SETTLE_TIME_MAX_IN_S) ? "above the usual range" : "range";
1275 if (context == READ_AT_CONNECT)
1276 LOGF_INFO("Slew settle time is %.3f s, %s 0-%d s.", seconds, range, SLEW_SETTLE_TIME_MAX_IN_S);
1277 else
1278 LOGF_INFO("Slew settle time changed on the mount: %.3f s, %s 0-%d s.", seconds, range,
1280 }
1281 // A changed maximum must reach the clients (KStars refreshes its edit field from it); that update also carries
1282 // the value. At connect the definition carries both. After a write the caller sends the update.
1283 if (maxChanged && context == READ_PERIODIC)
1284 SlewSettleTimeNP.updateMinMax();
1285 else if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
1286 SlewSettleTimeNP.apply();
1287 return true;
1288}
1289
1291{
1292 // #:SstmNNNNN.NNN#
1293 // Sets the slew settle time to NNNNN.NNN seconds (from 0 to 99999 s). After a slew of
1294 // the mount has been completed, the :D# and :GDW# commands will return a slewing
1295 // status for the time duration set in this command.
1296 // Note: the :Gstat# command is not affected by this setting.
1297 // Returns:
1298 // 0 invalid
1299 // 1 valid
1300 // Available from version 2.9.14.
1301 // The reply is a bare digit without '#'. The caller checks the range 0 to SLEW_SETTLE_TIME_MAX_IN_S.
1302 // Afterwards the settle time is read back, so clients see what the mount actually uses.
1303 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1304 char data[64];
1305 snprintf(data, sizeof(data), "#:Sstm%09.3f#", seconds);
1306 const bool result = (0 == setStandardProcedureAndExpectChar(fd, data, "1"));
1308 return result;
1309}
1310
1312{
1313 // #:TQ# Set default (sidereal) tracking rate
1314 // #:TSOLAR# Set solar tracking rate
1315 // #:TL# Set lunar tracking rate
1316 // #:TM# Set custom tracking rate
1317 // Returns: nothing
1318 // The shared LX200 code sends :TS# for solar, which no 10Micron manual lists. It comes from the Meade
1319 // Telescope Serial Command Protocol 2010.10: "Select Solar tracking rate. [LS Only]", i.e. only Meade's
1320 // LightSwitch telescopes. The Meade 2002 LX200 command set has no solar command at all.
1321 // The mount takes these in any state, also parked or not tracking.
1322 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1323 if (isSimulation())
1324 return true;
1325 const char *cmd = nullptr;
1326 switch (mode)
1327 {
1328 case TRACK_SIDEREAL:
1329 cmd = "#:TQ#";
1330 break;
1331 case TRACK_SOLAR:
1332 cmd = "#:TSOLAR#";
1333 break;
1334 case TRACK_LUNAR:
1335 cmd = "#:TL#";
1336 break;
1337 case TRACK_CUSTOM:
1338 cmd = "#:TM#";
1339 break;
1340 default:
1341 return false;
1342 }
1343 return setStandardProcedureWithoutRead(fd, cmd) == 0;
1344}
1345
1347{
1348 // #:GT#
1349 // Get tracking rate.
1350 // Returns: TT.T#
1351 // This value is computed in order to emulate the corresponding LX200 command. This corresponds to the
1352 // equivalent frequency expressed in hertz assuming a synchronous motor design where a 60.0 Hz motor clock
1353 // would produce 1 revolution of the mount in 24 hours. So, in order to obtain the tracking rate in arcseconds
1354 // per second of time, this value should be divided by four.
1355 // Why four: 1 revolution in 24 hours is 360 * 3600 arcseconds in 86400 seconds, 15 arcseconds per second,
1356 // so 60.0 Hz stands for 15 arcseconds per second. Sidereal (15.041) gives 60.2, solar (15.000) 60.0 and
1357 // lunar (about 14.49) about 58.0.
1358 // The values do not follow that formula: a GM2000HPS with firmware 3.1.16 returns 60.2 for sidereal, 60.3 for
1359 // solar and 62.4 for lunar, so a slower rate gives a higher value (MountWizzard4 uses the same three values).
1360 // They still tell the modes apart. Any other value is a custom rate. A custom rate equal to one of the three
1361 // cannot be told apart, so Custom stays selected then.
1362 // What is logged and sent to clients depends on the context, as in getAllowedMeridianSide.
1363 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1364 if (isSimulation())
1365 {
1366 TrackModeSP.setState(IPS_OK);
1367 return true;
1368 }
1369 char rateString[80] = {0};
1370 double value = 0;
1371 if (getCommandString(PortFD, rateString, "#:GT#") != 0 || sscanf(rateString, "%lf", &value) != 1)
1372 {
1373 if (context == READ_AFTER_WRITE)
1374 {
1375 TrackModeSP.setState(IPS_ALERT);
1376 }
1377 else if (context == READ_AT_CONNECT || TrackModeSP.getState() != IPS_ALERT)
1378 {
1379 LOG_WARN("Failed to read the track mode.");
1380 TrackModeSP.setState(IPS_ALERT);
1381 TrackModeSP.apply();
1382 }
1383 return false;
1384 }
1385 int index = TRACK_CUSTOM;
1386 if (std::fabs(value - 60.2) < 0.05)
1387 index = TRACK_SIDEREAL;
1388 else if (std::fabs(value - 60.3) < 0.05)
1389 index = TRACK_SOLAR;
1390 else if (std::fabs(value - 62.4) < 0.05)
1391 index = TRACK_LUNAR;
1392 if (TrackModeSP.findOnSwitchIndex() == TRACK_CUSTOM)
1393 index = TRACK_CUSTOM;
1394 const bool changed = TrackModeSP.findOnSwitchIndex() != index || TrackModeSP.getState() != IPS_OK;
1395 TrackModeSP.reset();
1396 TrackModeSP[index].setState(ISS_ON);
1397 TrackModeSP.setState(IPS_OK);
1398 // TRACK_FREQ shows the same reading
1399 if (TrackFreqN[0].value != value)
1400 {
1401 TrackFreqN[0].value = value;
1402 IDSetNumber(&TrackFreqNP, nullptr);
1403 }
1404 if (context == READ_AT_CONNECT || (context == READ_PERIODIC && changed))
1405 {
1406 if (context == READ_AT_CONNECT)
1407 LOGF_INFO("Track mode is %s.", TrackModeSP[index].getLabel());
1408 else
1409 LOGF_INFO("Track mode changed on the mount: %s.", TrackModeSP[index].getLabel());
1410 TrackModeSP.apply();
1411 }
1412 return true;
1413}
1414
1415// Model names are escaped: '$' as "$$", '#' as "$23", ',' as "$2C", and any character below 0x20 or above 0x7E
1416// as '$' with its two-digit hexadecimal code (protocol manual 3.1.16, section "Escaped strings", page 78).
1417static std::string escapeMountString(const std::string &text)
1418{
1419 std::string escaped;
1420 for (unsigned char c : text)
1421 {
1422 if (c == '$')
1423 escaped += "$$";
1424 else if (c == '#' || c == ',' || c < 0x20 || c > 0x7E)
1425 {
1426 char hex[4];
1427 snprintf(hex, sizeof(hex), "$%02X", c);
1428 escaped += hex;
1429 }
1430 else
1431 escaped += static_cast<char>(c);
1432 }
1433 return escaped;
1434}
1435
1436bool LX200_10MICRON::saveModel(const char *name)
1437{
1438 // #:modelsv0NAME#
1439 // Saves in the mount the current model with the given NAME.
1440 // The model names are escaped as explained at page 77. Model names are case-sensitive
1441 // and have a maximum length of 15 characters. Spaces at the end are ignored.
1442 // Returns:
1443 // the string "1#" if the model has been saved correctly;
1444 // the string "0#" if there was an error.
1445 // Available from version 2.13.3.
1446 // (Text of the protocol manual 3.1.16; its section "Escaped strings" is on page 78, see escapeMountString.)
1447 // A GM2000HPS (firmware 3.1.16) refuses an existing name ("0#"), so a model is never overwritten.
1448 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1449 std::string modelName(name);
1450 while (!modelName.empty() && modelName.back() == ' ')
1451 modelName.pop_back();
1452 if (modelName.empty())
1453 {
1454 LOG_ERROR("Model not saved: the name is empty.");
1455 return false;
1456 }
1457 if (modelName.size() > 15)
1458 {
1459 LOGF_ERROR("Model not saved: the name %s is longer than 15 characters.", modelName.c_str());
1460 return false;
1461 }
1462 const std::string escaped = escapeMountString(modelName);
1463 const std::string cmd = "#:modelsv0" + escaped + "#";
1464 char reply[80] = {0};
1465 if (getCommandString(PortFD, reply, cmd.c_str()) != 0)
1466 {
1467 LOGF_ERROR("Model %s: no reply from the mount to the save command.", modelName.c_str());
1468 return false;
1469 }
1470 if (reply[0] == '1')
1471 {
1472 LOGF_INFO("Model saved as %s.", modelName.c_str());
1473 }
1474 else
1475 {
1476 // Find out why: the only documented reason is a name that already exists
1477 bool exists = false;
1478 int count = 0;
1479 if (getCommandInt(PortFD, &count, "#:modelcnt#") == 0)
1480 {
1481 for (int i = 1; i <= count && !exists; i++)
1482 {
1483 char listCmd[32];
1484 char listName[80] = {0};
1485 snprintf(listCmd, sizeof(listCmd), "#:modelnam%d#", i);
1486 exists = getCommandString(PortFD, listName, listCmd) == 0 && escaped == listName;
1487 }
1488 }
1489 if (exists)
1490 LOGF_ERROR("Model not saved: the mount already has a model named %s.", modelName.c_str());
1491 else
1492 LOGF_ERROR("The mount could not save the model as %s.", modelName.c_str());
1493 return false;
1494 }
1495 // The number of models changed
1496 int count = 0;
1497 if (getCommandInt(PortFD, &count, "#:modelcnt#") == 0)
1498 {
1499 ModelCountN[0].value = count;
1500 IDSetNumber(&ModelCountNP, nullptr);
1501 }
1502 return true;
1503}
1504
1505bool LX200_10MICRON::Flip(double ra, double dec)
1506{
1507 INDI_UNUSED(ra);
1509 return flip();
1510}
1511
1512bool LX200_10MICRON::flip()
1513{
1514 // #:FLIP#
1515 // This command acts in different ways on the AZ2000 and german equatorial (GM1000 – GM4000) mounts.
1516 // On an AZ2000 mount: When observing an object near the lowest culmination, requests to make a 360° turn of the
1517 // azimuth axis and point the object again.
1518 // On a german equatorial mount: When observing an object near the meridian, requests to make a 180° turn of the RA
1519 // axis and move the declination axis in order to point the object with the telescope on the other side of the
1520 // mount.
1521 // Returns:
1522 // 1 if successful
1523 // 0 if the movement cannot be done
1524 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1525 char data[64];
1526 snprintf(data, sizeof(data), "#:FLIP#");
1527 return 0 == setStandardProcedureAndExpectChar(fd, data, "1");
1528}
1529
1531{
1532 // #:CMCFGn#
1533 // Configures the behaviour of the :CM# and :CMR# commands depending on the value
1534 // of n. If n=0, :the commands :CM# and :CMR# work in the default mode, i.e. they
1535 // synchronize the position to the mount with the coordinates of the currently selected
1536 // target by correcting the axis offset values. If n=1, the commands :CM# and :CMR#
1537 // work by using the synchronization position as an additional alignment star for refining
1538 // the alignment model.
1539 // Returns:
1540 // the string "0#" if the value 0 has been passed
1541 // the string "1#" if the value 1 has been passed
1542 // Available from version 2.8.15.
1543 LOG_INFO("SyncConfig.");
1544 if (setCommandInt(fd, cmcfg, "#:CMCFG") < 0)
1545 {
1546 return false;
1547 }
1548 return true;
1549}
1550
1551bool LX200_10MICRON::setLocalDate(uint8_t days, uint8_t months, uint16_t years)
1552{
1553 // #:SCYYYY-MM-DD#
1554 // Set date to YYYY-MM-DD (year, month, day). The date is expressed in local time.
1555 // Returns:
1556 // 0 if the date is invalid
1557 // The character "1" without additional strings in ultra-precision mode (regardless of
1558 // emulation).
1559 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "<%s>", __FUNCTION__);
1560 char data[64];
1561 snprintf(data, sizeof(data), ":SC%04d-%02d-%02d#", years, months, days);
1562 return 0 == setStandardProcedureAndExpectChar(fd, data, "1");
1563}
1564
1566{
1567 // #:TLEL0<two line element>#
1568 // Loads satellite orbital elements in two-line format directly from the command protocol.
1569 // <two line element> is a string containing the two line elements. Each lines can be
1570 // terminated by escaped newline (ASCII code 10), carriage return (ASCII code 13) or a
1571 // combination of both. The first line may contain the satellite name. The entire string is
1572 // escaped with the mechanism described in the "escaped strings" section below.
1573 // The TLE format is described here:
1574 // https://www.celestrak.com/NORAD/documentation/tle-fmt.asp
1575 // For example, loading the NOAA 14 element set of that page can be accomplished with:
1576 // :TLEL0NOAA·14·················$0a
1577 // 1·23455U·94089A···97320.90946019··.00000140··00000-0··10191-3·0··2621$0a
1578 // 2·23455··99.0090·272.6745·0008546·223.1686·136.8816·14.11711747148495#
1579 // Returns:
1580 // E# invalid format
1581 // V# valid format
1582 // Available from version 2.13.20.
1583 LOGF_INFO("The function is called with TLE %s", tle);
1584 if (strlen(tle) > 230)
1585 {
1586 LOG_WARN("TLE is too long");
1587 }
1588
1589 std::string tle_str;
1590 std::string sep = "$0a";
1591 std::string search = "\n";
1592 tle_str = (std::string) tle;
1593 for( size_t pos = 0; ; pos += sep.length() )
1594 {
1595 // Locate the substring to replace
1596 pos = tle_str.find( search, pos );
1597 if( pos == std::string::npos ) break;
1598 // Replace by erasing and inserting
1599 tle_str.erase( pos, search.length() );
1600 tle_str.insert( pos, sep );
1601 }
1602 char command[250];
1603 snprintf(command, sizeof(command), ":TLEL0%s#", tle_str.c_str());
1604
1605 if ( !isSimulation() )
1606 {
1607 LOG_INFO(command);
1608 char response[2];
1609 if (0 != setStandardProcedureAndReturnResponse(fd, command, response, 2) )
1610 {
1611 LOG_ERROR("TLE set error");
1612 return 1;
1613 }
1614 if (response[0] == 'E')
1615 {
1616 LOG_ERROR("Invalid formatting of TLE, trying to split:");
1617 char *pch = strtok ((char*) tle, "\n");
1618 while (pch != nullptr)
1619 {
1620 LOGF_INFO("%s\n", pch);
1621 pch = strtok (nullptr, "\n");
1622 }
1623 return 1;
1624 }
1625 }
1626 else
1627 {
1628 char *pch = strtok ((char*) tle, "\n");
1629 while (pch != nullptr)
1630 {
1631 LOGF_INFO("%s\n", pch);
1632 pch = strtok (nullptr, "\n");
1633 }
1634 }
1635 return 0;
1636}
1637
1639{
1640 // #:TLEDLn#
1641 // Loads orbital elements for a satellite from the TLE database in the mount. n is the index of the
1642 // orbital elements in the database, starting from 1 to the number returned by the TLEDN command.
1643 // Returns:
1644 // E# the mount database doesn't contain a TLE with the given index.
1645 // <two line elements># an escaped string containing the TLE data from the mount
1646 // database which has been loaded. Lines are terminated by ASCII newline (ASCII code 10).
1647 // Available from version 2.13.20.
1648 char command[12];
1649 snprintf(command, sizeof(command), ":TLEDL%d#", tleN);
1650
1651 LOG_INFO("Setting TLE from Database");
1652 if ( !isSimulation() )
1653 {
1654 LOG_INFO(command);
1655 char response[210];
1656 if (0 != setStandardProcedureAndReturnResponse(fd, command, response, 210) )
1657 {
1658 LOG_ERROR("TLE set error");
1659 return 1;
1660 }
1661 if (response[0] == 'E')
1662 {
1663 LOG_ERROR("TLE number not in mount");
1664 return 1;
1665 }
1666 }
1667 return 0;
1668}
1669
1670bool LX200_10MICRON::CalculateSatTrajectory(std::string start_pass_isodatetime, std::string end_pass_isodatetime)
1671{
1672 // #:TLEPJD,min#
1673 // Precalculates the first transit of the satellite with the currently loaded orbital elements,
1674 // starting from Julian Date JD and for a period of min minutes, where min is from 1 to 1440.
1675 // Two-line elements have to be loaded with the :TLEL command.
1676 // Returns:
1677 // E# no TLE loaded or invalid command
1678 // N# no passes in the given amount of time
1679 // JDstart,JDend,flags# data for the first pass in the given interval. JDstart and JDend
1680 // mark the beginning and the end of the given transit. Flags is a string which can be
1681 // empty or contain the letter F – meaning that mount will flip during the transit.
1682 // Available from version 2.13.20.
1683 struct ln_date start_pass;
1684 if (extractISOTime(start_pass_isodatetime.c_str(), &start_pass) == -1)
1685 {
1686 LOGF_ERROR("Date/Time is invalid: %s.", start_pass_isodatetime.c_str());
1687 return 1;
1688 }
1689
1690 struct ln_date end_pass;
1691 if (extractISOTime(end_pass_isodatetime.c_str(), &end_pass) == -1)
1692 {
1693 LOGF_ERROR("Date/Time is invalid: %s.", end_pass_isodatetime.c_str());
1694 return 1;
1695 }
1696
1697 double JD_start;
1698 double JD_end;
1699 JD_start = ln_get_julian_day(&start_pass);
1700 JD_end = ln_get_julian_day(&end_pass);
1701 int nextPassInMinutes = static_cast<int>(ceil((JD_end - JD_start) * 24 * 60));
1702 int nextPassinMinutesUpTo1440 = std::min(nextPassInMinutes, 1440);
1703 int nextPassinMinutesBetween1and1440 = std::max(nextPassinMinutesUpTo1440, 1);
1704
1705 char command[28];
1706 snprintf(command, sizeof(command), ":TLEP%7.8f,%01d#", JD_start, nextPassinMinutesBetween1and1440);
1707 LOGF_INFO("Julian day %7.8f", JD_start);
1708 LOGF_INFO("For the next %01d minutes", nextPassinMinutesBetween1and1440);
1709 LOGF_INFO("Command: %s", command);
1710 if ( !isSimulation() )
1711 {
1712 LOG_INFO(command);
1713 char response[36];
1714 if (0 != setStandardProcedureAndReturnResponse(fd, command, response, 36) )
1715 {
1716 LOG_ERROR("TLE calculate error");
1717 return 1;
1718 }
1719 if (response[0] == 'E')
1720 {
1721 LOG_ERROR("TLE not loaded or invalid command");
1722 return 1;
1723 }
1724 if (response[0] == 'N')
1725 {
1726 LOG_ERROR("No passes loaded");
1727 return 1;
1728 }
1729 }
1730 return 0;
1731}
1732
1734{
1735 // #:TLES#
1736 // Slews to the start of the satellite transit that has been precalculated with the :TLEP command.
1737 // Returns:
1738 // E# no transit has been precalculated
1739 // F# slew failed due to mount parked or other status blocking slews
1740 // V# slewing to the start of the transit, the mount will automatically start tracking the satellite.
1741 // S# the transit has already started, slewing to catch the satellite
1742 // Q# the transit has already ended, no slew occurs
1743 // Available from version 2.13.20.
1744 char command[7];
1745 snprintf(command, sizeof(command), ":TLES#");
1746 if ( !isSimulation() )
1747 {
1748 LOG_INFO(command);
1749 char response[2];
1750 if (0 != setStandardProcedureAndReturnResponse(fd, command, response, 2) )
1751 {
1752 LOG_ERROR("TLE track error");
1753 return 1;
1754 }
1755 if (response[0] == 'E')
1756 {
1757 LOG_ERROR("TLE transit not calculated");
1758 return 2;
1759 }
1760 if (response[0] == 'F')
1761 {
1762 LOG_ERROR("Slew failed");
1763 return 3;
1764 }
1765 if (response[0] == 'V')
1766 {
1767 LOG_INFO("Slewing to start of transit");
1768 return 0;
1769 }
1770 if (response[0] == 'S')
1771 {
1772 LOG_INFO("Slewing to transiting satellite");
1773 return 0;
1774 }
1775 if (response[0] == 'Q')
1776 {
1777 LOG_ERROR("Transit is already over");
1778 return 4;
1779 }
1780 }
1781 return 0;
1782}
1783
1785{
1786 // #:SRTMPsTTT.T#
1787 // Sets the temperature used in the refraction model to sTTT.T degrees Celsius (°C).
1788 // Returns:
1789 // 0 invalid
1790 // 1 valid
1791 // Available from version 2.3.0.
1792 char data[16];
1793 snprintf(data, 16, "#:SRTMP%0+6.1f#", temperature);
1794 return setStandardProcedure(fd, data);
1795}
1796
1798{
1799 // #:SRPRSPPPP.P#
1800 // Sets the atmospheric pressure used in the refraction model to PPPP.P hPa. Note
1801 // that this is the pressure at the location of the telescope, and not the pressure at sea level.
1802 // Returns:
1803 // 0 invalid
1804 // 1 valid
1805 // Available from version 2.3.0.
1806 char data[16];
1807 snprintf(data, 16, "#:SRPRS%06.1f#", pressure);
1808 return setStandardProcedure(fd, data);
1809}
1810
1811int LX200_10MICRON::AddSyncPoint(double MRa, double MDec, double MSide, double PRa, double PDec, double SidTime)
1812{
1813 // #:newalptMRA,MDEC,MSIDE,PRA,PDEC,SIDTIME#
1814 // Add a new point to the alignment specification. The parameters are:
1815 // MRA – the mount-reported right ascension, expressed as HH:MM:SS.S
1816 // MDEC – the mount-reported declination, expressed as sDD:MM:SS
1817 // MSIDE – the mount-reported pier side (the letter 'E' or 'W', as reported by the :pS# command)
1818 // PRA – the plate-solved right ascension (i.e. the right ascension the telescope was
1819 // effectively pointing to), expressed as HH:MM:SS.S
1820 // PDEC – the plate-solved declination (i.e. the declination the telescope was effectively
1821 // pointing to), expressed as sDD:MM:SS
1822 // SIDTIME – the local sidereal time at the time of the measurement of the point,
1823 // expressed as HH:MM:SS.S
1824 // Returns:
1825 // the string "nnn#" if the point is valid, where nnn is the current number of points in the
1826 // alignment specification (including this one)
1827 // the string "E#" if the point is not valid
1828 // See also the paragraph Entering an alignment model.
1829 // Available from version 2.8.15.
1830 char MRa_str[32], MDec_str[32];
1831 fs_sexa(MRa_str, MRa, 0, 36000);
1832 fs_sexa(MDec_str, MDec, 0, 3600);
1833
1834 char MSide_char;
1835 (static_cast<int>(MSide) == 0) ? MSide_char = 'E' : MSide_char = 'W';
1836
1837 char PRa_str[32], PDec_str[32];
1838 fs_sexa(PRa_str, PRa, 0, 36000);
1839 fs_sexa(PDec_str, PDec, 0, 3600);
1840
1841 char SidTime_str[32];
1842 fs_sexa(SidTime_str, SidTime, 0, 36000);
1843
1844 char command[80];
1845 snprintf(command, 80, "#:newalpt%s,%s,%c,%s,%s,%s#", MRa_str, MDec_str, MSide_char, PRa_str, PDec_str, SidTime_str);
1846 LOGF_INFO("AddSyncPoint %s", command);
1847
1848 char response[6];
1849 if (0 != setStandardProcedureAndReturnResponse(fd, command, response, 5) || response[0] == 'E')
1850 {
1851 LOG_ERROR("AddSyncPoint error");
1852 return 1;
1853 }
1854 response[4] = 0;
1855 int points;
1856 int nbytes_read = sscanf(response, "%3d#", &points);
1857 if (nbytes_read < 0)
1858 {
1859 LOGF_ERROR("AddSyncPoint response error %d", nbytes_read);
1860 return 1;
1861 }
1862 LOGF_INFO("AddSyncPoint responded [%4s], there are now %d new alignment points", response, points);
1863 NewAlignmentPointsN[0].value = points;
1865
1866 return 0;
1867}
1868
1869int LX200_10MICRON::AddSyncPointHere(double PRa, double PDec)
1870{
1871 double MSide = (toupper(Ginfo.SideOfPier) == 'E') ? 0 : 1;
1872 return AddSyncPoint(Ginfo.RA_JNOW, Ginfo.DEC_JNOW, MSide, PRa, PDec, Ginfo.SiderealTime);
1873}
1874
1875bool LX200_10MICRON::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
1876{
1877 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
1878 {
1879 if (MeridianLimitsNP.isNameMatch(name))
1880 {
1881 int slewLimit = static_cast<int>(MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].getValue());
1882 int trackLimit = static_cast<int>(MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].getValue());
1883 for (int i = 0; i < n; i++)
1884 {
1885 if (MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].isNameMatch(names[i]))
1886 slewLimit = static_cast<int>(std::lround(values[i]));
1887 else if (MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].isNameMatch(names[i]))
1888 trackLimit = static_cast<int>(std::lround(values[i]));
1889 }
1890 if (trackLimit < slewLimit)
1891 {
1892 LOGF_ERROR("Tracking limit (Flip Guide Tolerance) %d must be >= slew limit (Flip Slew Tolerance) %d, "
1893 "nothing written to the mount.", trackLimit, slewLimit);
1894 MeridianLimitsNP.setState(IPS_ALERT);
1895 MeridianLimitsNP.apply();
1896 return false;
1897 }
1898 // One log line and one property update, showing what the mount reports after the write
1899 bool result = false;
1900 if (!setMeridianLimits(slewLimit, trackLimit))
1901 {
1902 LOGF_ERROR("The mount refused tracking limit %d with slew limit %d.", trackLimit, slewLimit);
1903 MeridianLimitsNP.setState(IPS_ALERT);
1904 }
1905 else if (MeridianLimitsNP.getState() == IPS_ALERT)
1906 {
1907 LOG_WARN("Meridian limits were written, but could not be read back.");
1908 }
1909 else
1910 {
1911 LOGF_INFO("Meridian limits set: slew %d, tracking %d degrees.",
1912 static_cast<int>(MeridianLimitsNP[MERIDIAN_LIMIT_SLEW].getValue()),
1913 static_cast<int>(MeridianLimitsNP[MERIDIAN_LIMIT_TRACK].getValue()));
1914 result = true;
1915 }
1916 MeridianLimitsNP.apply();
1917 return result;
1918 }
1919 if (SlewSettleTimeNP.isNameMatch(name))
1920 {
1921 double seconds = SlewSettleTimeNP[0].getValue();
1922 for (int i = 0; i < n; i++)
1923 {
1924 if (SlewSettleTimeNP[0].isNameMatch(names[i]))
1925 seconds = values[i];
1926 }
1927 if (seconds < 0 || seconds > SLEW_SETTLE_TIME_MAX_IN_S)
1928 {
1929 LOGF_ERROR("Slew settle time %.3f s is outside the range 0-%d s, nothing written to the mount.", seconds,
1931 SlewSettleTimeNP.setState(IPS_ALERT);
1932 SlewSettleTimeNP.apply();
1933 return false;
1934 }
1935 // One log line and one property update, showing what the mount reports after the write
1936 bool result = false;
1937 if (!setSlewSettleTime(seconds))
1938 {
1939 LOGF_ERROR("The mount refused slew settle time %.3f s.", seconds);
1940 SlewSettleTimeNP.setState(IPS_ALERT);
1941 }
1942 else if (SlewSettleTimeNP.getState() == IPS_ALERT)
1943 {
1944 LOG_WARN("Slew settle time was written, but could not be read back.");
1945 }
1946 else
1947 {
1948 LOGF_INFO("Slew settle time set: %.3f s.", SlewSettleTimeNP[0].getValue());
1949 result = true;
1950 }
1951 SlewSettleTimeNP.updateMinMax();
1952 return result;
1953 }
1954 if (strcmp(name, REFRACTION_MODEL_TEMPERATURE) == 0)
1955 {
1958 {
1959 LOG_ERROR("SetRefractionModelTemperature error");
1962 return false;
1963 }
1966 LOGF_INFO("RefractionModelTemperature set to %0+6.1f degrees C", RefractionModelTemperatureN[0].value);
1967 return true;
1968 }
1969 if (strcmp(name, REFRACTION_MODEL_PRESSURE) == 0)
1970 {
1971 IUUpdateNumber(&RefractionModelPressureNP, values, names, n);
1973 {
1974 LOG_ERROR("SetRefractionModelPressure error");
1977 return false;
1978 }
1981 LOGF_INFO("RefractionModelPressure set to %06.1f hPa", RefractionModelPressureN[0].value);
1982 return true;
1983 }
1984 if (strcmp(name, MODEL_COUNT) == 0)
1985 {
1986 IUUpdateNumber(&ModelCountNP, values, names, n);
1987 ModelCountNP.s = IPS_OK;
1988 IDSetNumber(&ModelCountNP, nullptr);
1989 LOGF_INFO("ModelCount %d", ModelCountN[0].value);
1990 return true;
1991 }
1992 if (strcmp(name, MINIMAL_NEW_ALIGNMENT_POINT_RO) == 0)
1993 {
1994 IUUpdateNumber(&MiniNewAlpNP, values, names, n);
1996 IDSetNumber(&MiniNewAlpRONP, nullptr);
1997 return true;
1998 }
1999 if (strcmp(name, MINIMAL_NEW_ALIGNMENT_POINT) == 0)
2000 {
2001 if (AlignmentState != ALIGN_START)
2002 {
2003 LOG_ERROR("Cannot add alignment points yet, need to start a new alignment first");
2004 return false;
2005 }
2006
2007 IUUpdateNumber(&MiniNewAlpNP, values, names, n);
2009 {
2010 LOG_ERROR("AddSyncPointHere error");
2012 IDSetNumber(&MiniNewAlpNP, nullptr);
2013 return false;
2014 }
2015 MiniNewAlpNP.s = IPS_OK;
2016 IDSetNumber(&MiniNewAlpNP, nullptr);
2017 return true;
2018 }
2019 if (strcmp(name, NEW_ALIGNMENT_POINT) == 0)
2020 {
2021 if (AlignmentState != ALIGN_START)
2022 {
2023 LOG_ERROR("Cannot add alignment points yet, need to start a new alignment first");
2024 return false;
2025 }
2026
2027 IUUpdateNumber(&NewAlpNP, values, names, n);
2028 if (0 != AddSyncPoint(NewAlpN[ALP_MRA].value, NewAlpN[ALP_MDEC].value, NewAlpN[ALP_MSIDE].value,
2029 NewAlpN[ALP_PRA].value, NewAlpN[ALP_PDEC].value, NewAlpN[ALP_SIDTIME].value))
2030 {
2031 LOG_ERROR("AddSyncPoint error");
2032 NewAlpNP.s = IPS_ALERT;
2033 IDSetNumber(&NewAlpNP, nullptr);
2034 return false;
2035 }
2036 NewAlpNP.s = IPS_OK;
2037 IDSetNumber(&NewAlpNP, nullptr);
2038 return true;
2039 }
2040 if (strcmp(name, NEW_ALIGNMENT_POINTS) == 0)
2041 {
2042 IUUpdateNumber(&NewAlignmentPointsNP, values, names, n);
2045 LOGF_INFO("New unnamed Model now has %d alignment points", NewAlignmentPointsN[0].value);
2046 return true;
2047 }
2048 if (strcmp(name, "TLE_NUMBER") == 0)
2049 {
2050 LOG_INFO("I am trying to set from Database");
2051
2052 IUUpdateNumber(&TLEfromDatabaseNP, values, names, n);
2053 if ( 0 != SetTLEfromDatabase(TLEfromDatabaseN[0].value) )
2054 {
2056 IDSetNumber(&TLEfromDatabaseNP, nullptr);
2057 return false;
2058 }
2060 TLEtoTrackTP.setState(IPS_IDLE);
2061 TLEtoTrackTP.apply();
2062 IDSetNumber(&TLEfromDatabaseNP, nullptr);
2063 LOGF_INFO("Selected TLE nr %.0f from database", TLEfromDatabaseN[0].value);
2064
2065 return true;
2066 }
2067 }
2068
2069 // Let INDI::LX200Generic handle any other number properties
2070 return LX200Generic::ISNewNumber(dev, name, values, names, n);
2071}
2072
2073bool LX200_10MICRON::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
2074{
2075 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
2076 {
2077 if (AllowedMeridianSideSP.isNameMatch(name))
2078 {
2079 AllowedMeridianSideSP.update(states, names, n);
2080 const int index = AllowedMeridianSideSP.findOnSwitchIndex();
2081 if (index < 0)
2082 {
2084 AllowedMeridianSideSP.apply();
2085 return false;
2086 }
2087 // One log line and one property update, showing what the mount reports after the write
2088 const char *label = AllowedMeridianSideSP[index].getLabel();
2089 bool result = false;
2090 if (!setAllowedMeridianSide(index))
2091 {
2092 LOGF_ERROR("The mount refused allowed meridian side %s.", label);
2094 }
2095 else if (AllowedMeridianSideSP.getState() == IPS_ALERT)
2096 {
2097 LOG_WARN("Allowed meridian side was written, but could not be read back.");
2098 }
2099 else if (AllowedMeridianSideSP.findOnSwitchIndex() != index)
2100 {
2101 LOGF_ERROR("The mount did not take allowed meridian side %s.", label);
2103 }
2104 else
2105 {
2106 LOGF_INFO("Allowed meridian side set: %s.", label);
2107 result = true;
2108 }
2109 AllowedMeridianSideSP.apply();
2110 return result;
2111 }
2112 // Handled here instead of in INDI::Telescope, which sends nothing while the mount is not tracking and
2113 // refuses while it is parked. The mount takes the track mode in any state.
2114 if (TrackModeSP.isNameMatch(name))
2115 {
2116 const int previousIndex = TrackModeSP.findOnSwitchIndex();
2117 TrackModeSP.update(states, names, n);
2118 const int index = TrackModeSP.findOnSwitchIndex();
2119 if (index < 0)
2120 {
2121 TrackModeSP.setState(IPS_ALERT);
2122 TrackModeSP.apply();
2123 return false;
2124 }
2125 // Nothing to send when the mount already uses this mode, e.g. when the config is loaded at connect.
2126 // Read it again first, it may have been changed elsewhere since the last read.
2127 if (index == previousIndex && getTrackMode(READ_AFTER_WRITE) && TrackModeSP.findOnSwitchIndex() == index)
2128 {
2129 TrackModeSP.apply();
2130 return true;
2131 }
2132 TrackModeSP.reset();
2133 TrackModeSP[index].setState(ISS_ON);
2134 // One log line and one property update, showing what the mount reports after the write
2135 const char *label = TrackModeSP[index].getLabel();
2136 bool result = false;
2137 if (!SetTrackMode(index))
2138 {
2139 LOGF_ERROR("Failed to send track mode %s.", label);
2140 TrackModeSP.setState(IPS_ALERT);
2141 }
2142 else if (!getTrackMode(READ_AFTER_WRITE))
2143 {
2144 LOG_WARN("Track mode was written, but could not be read back.");
2145 }
2146 else if (TrackModeSP.findOnSwitchIndex() != index)
2147 {
2148 LOGF_ERROR("The mount did not take track mode %s.", label);
2149 TrackModeSP.setState(IPS_ALERT);
2150 }
2151 else
2152 {
2153 LOGF_INFO("Track mode set: %s.", label);
2154 result = true;
2155 }
2156 TrackModeSP.apply();
2157 return result;
2158 }
2159 if (strcmp(AlignmentStateSP.name, name) == 0)
2160 {
2161 IUUpdateSwitch(&AlignmentStateSP, states, names, n);
2163
2164 switch (index)
2165 {
2166 case ALIGN_IDLE:
2167 AlignmentState = ALIGN_IDLE;
2168 LOG_INFO("Alignment state is IDLE");
2169 break;
2170
2171 case ALIGN_START:
2172 // #:newalig#
2173 // Start creating a new alignment specification, that will be entered with the :newalpt command.
2174 // Returns:
2175 // the string "V#" (this is always successful).
2176 // Available from version 2.8.15.
2177 if (0 != setStandardProcedureAndExpectChar(fd, "#:newalig#", "V"))
2178 {
2179 LOG_ERROR("New alignment start error");
2181 IDSetSwitch(&AlignmentStateSP, nullptr);
2182 return false;
2183 }
2184 LOG_INFO("New Alignment started");
2185 AlignmentState = ALIGN_START;
2186 break;
2187
2188 case ALIGN_END:
2189 // #:endalig#
2190 // Completes the alignment specification and computes a new alignment from the given
2191 // alignment points.
2192 // Returns:
2193 // the string "V#" if the alignment has been computed successfully
2194 // the string "E#" if the alignment couldn't be computed successfully with the current
2195 // alignment specification. In this case the previous alignment is retained.
2196 // Available from version 2.8.15.
2197 if (0 != setStandardProcedureAndExpectChar(fd, "#:endalig#", "V"))
2198 {
2199 LOG_ERROR("New alignment end error");
2201 IDSetSwitch(&AlignmentStateSP, nullptr);
2202 return false;
2203 }
2204 LOG_INFO("New Alignment ended");
2205 AlignmentState = ALIGN_END;
2206 break;
2207
2209 // #:delalig#
2210 // Deletes the current alignment model and stars.
2211 // Returns: an empty string terminated by '#'.
2212 // Available from version 2.8.15.
2213 if (0 != setStandardProcedureAndExpectChar(fd, "#:delalig#", "#"))
2214 {
2215 LOG_ERROR("Delete current alignment error");
2217 IDSetSwitch(&AlignmentStateSP, nullptr);
2218 return false;
2219 }
2220 LOG_INFO("Current Alignment deleted");
2221 AlignmentState = ALIGN_DELETE_CURRENT;
2222 break;
2223
2224 default:
2226 IDSetSwitch(&AlignmentStateSP, "Unknown alignment index %d", index);
2227 AlignmentState = ALIGN_IDLE;
2228 return false;
2229 }
2230
2232 IDSetSwitch(&AlignmentStateSP, nullptr);
2233 return true;
2234 }
2235 if (TrackSatSP.isNameMatch(name))
2236 {
2237
2238 TrackSatSP.update(states, names, n);
2239 int index = TrackSatSP.findOnSwitchIndex();
2240
2241 switch (index)
2242 {
2243 case SAT_TRACK:
2244 if ( 0 != TrackSat() )
2245 {
2246 TrackSatSP.setState(IPS_ALERT);
2247 TrackSatSP.apply();
2248 LOG_ERROR("Tracking failed");
2249 return false;
2250 }
2251 TrackSatSP.setState(IPS_OK);
2252 TrackSatSP.apply();
2253 LOG_INFO("Tracking satellite");
2254 return true;
2255 case SAT_HALT:
2256 if ( !Abort() )
2257 {
2258 TrackSatSP.setState(IPS_ALERT);
2259 TrackSatSP.apply();
2260 LOG_ERROR("Halt failed");
2261 return false;
2262 }
2263 TrackSatSP.setState(IPS_OK);
2264 TrackSatSP.apply();
2265 LOG_INFO("Halt tracking");
2266 return true;
2267 default:
2268 TrackSatSP.setState(IPS_ALERT);
2269 LOGF_ERROR("Unknown tracking modus %d", index);
2270 return false;
2271 }
2272 }
2273
2274 if (strcmp(UnattendedFlipSP.name, name) == 0)
2275 {
2276 IUUpdateSwitch(&UnattendedFlipSP, states, names, n);
2278 switch (index)
2279 {
2281 if (false == setUnattendedFlipSetting(false))
2282 {
2283 LOG_ERROR("Setting unattended flip failed");
2285 IDSetSwitch(&UnattendedFlipSP, nullptr);
2286 return false;
2287 }
2288 break;
2290 if (false == setUnattendedFlipSetting(true))
2291 {
2292 LOG_ERROR("Setting unattended flip failed");
2294 IDSetSwitch(&UnattendedFlipSP, nullptr);
2295 return false;
2296 }
2297 break;
2298 default:
2300 IDSetSwitch(&UnattendedFlipSP, "Unknown unattended flip setting %d", index);
2301 return false;
2302 }
2303 // :SuafN# returns nothing, so read the setting back to confirm what the mount actually uses
2304 return confirmUnattendedFlipSetting(index);
2305 }
2306 if (strcmp(WoLSendSP.name, name) == 0)
2307 {
2309 if (sendWakeOnLanPacket())
2310 {
2311 WoLSendSP.s = IPS_OK;
2312 LOG_INFO("Wake on LAN packet sent successfully.");
2313 }
2314 else
2315 {
2316 WoLSendSP.s = IPS_ALERT;
2317 LOG_ERROR("Failed to send Wake on LAN packet.");
2318 }
2319 IDSetSwitch(&WoLSendSP, nullptr);
2320 return true;
2321 }
2322 if (MountShutdownSP.isNameMatch(name))
2323 {
2324 MountShutdownSP.reset();
2325 if (!isParked())
2326 {
2327 MountShutdownSP.setState(IPS_ALERT);
2328 LOG_WARN("Mount must be parked before shutdown.");
2329 MountShutdownSP.apply();
2330 return false;
2331 }
2332 // :shutdown# — returns '1' on success, '0' on failure; ~20 s until power-off
2333 if (0 != setStandardProcedureAndExpectChar(fd, ":shutdown#", "1"))
2334 {
2335 MountShutdownSP.setState(IPS_ALERT);
2336 LOG_ERROR("Mount shutdown command failed.");
2337 MountShutdownSP.apply();
2338 return false;
2339 }
2340 MountShutdownSP.setState(IPS_OK);
2341 LOG_INFO("Mount shutdown initiated. Disconnecting before mount powers off.");
2342 MountShutdownSP.apply();
2343 // Defer disconnect so ISNewSwitch returns cleanly before we tear down the property list
2344 m_ShutdownPending = true;
2345 SetTimer(100);
2346 return true;
2347 }
2348 }
2349
2350 return LX200Generic::ISNewSwitch(dev, name, states, names, n);
2351}
2352
2353bool LX200_10MICRON::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
2354{
2355 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
2356 {
2357 if (strcmp(name, NEW_MODEL_NAME) == 0)
2358 {
2359 IUUpdateText(&NewModelNameTP, texts, names, n);
2360 const bool result = saveModel(NewModelNameT[0].text);
2361 NewModelNameTP.s = result ? IPS_OK : IPS_ALERT;
2362 IDSetText(&NewModelNameTP, nullptr);
2363 return result;
2364 }
2365 if (strcmp(name, "SAT_TLE_TEXT") == 0)
2366 {
2367
2368 TLEtoTrackTP.update(texts, names, n);
2369 if (0 == SetTLEtoFollow(TLEtoTrackTP[0].getText()))
2370 {
2371 TLEtoTrackTP.setState(IPS_OK);
2373 TLEtoTrackTP.apply();
2374 IDSetNumber(&TLEfromDatabaseNP, nullptr);
2375 LOGF_INFO("Selected TLE %s", TLEtoTrackTP[0].getText());
2376 return true;
2377 }
2378 else
2379 {
2380 TLEtoTrackTP.setState(IPS_ALERT);
2382 TLEtoTrackTP.apply();
2383 IDSetNumber(&TLEfromDatabaseNP, nullptr);
2384 LOG_ERROR("TLE was not correctly uploaded");
2385 return false;
2386 }
2387 }
2388 if (strcmp(name, "SAT_PASS_WINDOW") == 0)
2389 {
2390 SatPassWindowTP.update(texts, names, n);
2393 {
2394 SatPassWindowTP.setState(IPS_OK);
2395 SatPassWindowTP.apply();
2396 LOG_INFO("Trajectory set");
2397 return true;
2398 }
2399 else
2400 {
2401 SatPassWindowTP.setState(IPS_ALERT);
2402 SatPassWindowTP.apply();
2403 LOG_ERROR("Trajectory could not be calculated");
2404 return false;
2405 }
2406 }
2407 if (strcmp(name, WAKE_ON_LAN_MAC) == 0)
2408 {
2409 IUUpdateText(&WoLMacTP, texts, names, n);
2410 WoLMacTP.s = IPS_OK;
2411 IDSetText(&WoLMacTP, nullptr);
2412 LOGF_INFO("WoL MAC address set to %s", WoLMacT[0].text);
2413 return true;
2414 }
2415 }
2416 return LX200Generic::ISNewText(dev, name, texts, names, n);
2417}
2418
2419// this should move to some generic library
2420int LX200_10MICRON::monthToNumber(const char *monthName)
2421{
2422 struct entry
2423 {
2424 const char *name;
2425 int id;
2426 };
2427 entry month_table[] = { { "Jan", 1 }, { "Feb", 2 }, { "Mar", 3 }, { "Apr", 4 }, { "May", 5 },
2428 { "Jun", 6 }, { "Jul", 7 }, { "Aug", 8 }, { "Sep", 9 }, { "Oct", 10 },
2429 { "Nov", 11 }, { "Dec", 12 }, { nullptr, 0 }
2430 };
2431 entry *p = month_table;
2432 while (p->name != nullptr)
2433 {
2434 if (strcasecmp(p->name, monthName) == 0)
2435 return p->id;
2436 ++p;
2437 }
2438 return 0;
2439}
2440
2442{
2443 int error_type;
2444 int nbytes_write = 0;
2445
2446 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s>", data);
2447 tcflush(fd, TCIFLUSH);
2448 if ((error_type = tty_write_string(fd, data, &nbytes_write)) != TTY_OK)
2449 {
2450 LOGF_ERROR("CMD <%s> write ERROR %d", data, error_type);
2451 return error_type;
2452 }
2453 tcflush(fd, TCIFLUSH);
2454 return 0;
2455}
2456
2457int LX200_10MICRON::setStandardProcedureAndExpectChar(int fd, const char *data, const char *expect)
2458{
2459 char bool_return[2];
2460 int error_type;
2461 int nbytes_write = 0, nbytes_read = 0;
2462
2463 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s>", data);
2464 tcflush(fd, TCIFLUSH);
2465 if ((error_type = tty_write_string(fd, data, &nbytes_write)) != TTY_OK)
2466 {
2467 LOGF_ERROR("CMD <%s> write ERROR %d", data, error_type);
2468 return error_type;
2469 }
2470 error_type = tty_read(fd, bool_return, 1, LX200_TIMEOUT, &nbytes_read);
2471 tcflush(fd, TCIFLUSH);
2472
2473 if (nbytes_read < 1)
2474 {
2475 LOGF_ERROR("CMD <%s> read ERROR %d", data, error_type);
2476 return error_type;
2477 }
2478
2479 if (bool_return[0] != expect[0])
2480 {
2481 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s> failed.", data);
2482 return -1;
2483 }
2484
2485 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s> successful.", data);
2486
2487 return 0;
2488}
2489
2490int LX200_10MICRON::setStandardProcedureAndReturnResponse(int fd, const char *data, char *response, int max_response_length)
2491{
2492 int error_type;
2493 int nbytes_write = 0, nbytes_read = 0;
2494
2495 DEBUGFDEVICE(getDefaultName(), DBG_SCOPE, "CMD <%s>", data);
2496 tcflush(fd, TCIFLUSH);
2497 if ((error_type = tty_write_string(fd, data, &nbytes_write)) != TTY_OK)
2498 {
2499 LOGF_ERROR("CMD <%s> write ERROR %d", data, error_type);
2500 return error_type;
2501 }
2502 error_type = tty_read(fd, response, max_response_length, LX200_TIMEOUT, &nbytes_read);
2503 tcflush(fd, TCIFLUSH);
2504
2505 if (nbytes_read < 1)
2506 {
2507 LOGF_ERROR("CMD <%s> read ERROR %d", data, error_type);
2508 return error_type;
2509 }
2510
2511 return 0;
2512}
2513
2515{
2516 if (m_ShutdownPending)
2517 {
2518 m_ShutdownPending = false;
2519 // Standard INDI disconnect sequence — same as clicking Disconnect in the UI
2520 Disconnect();
2521 setConnected(false, IPS_IDLE);
2523 return; // do not reschedule polling
2524 }
2526}
2527
2528bool LX200_10MICRON::sendWakeOnLanPacket()
2529{
2530 const char *macStr = WoLMacT[0].text;
2531 if (!macStr || macStr[0] == '\0')
2532 {
2533 LOG_ERROR("WoL: MAC address not configured.");
2534 return false;
2535 }
2536
2537 std::string cmd = "wakeonlan " + std::string(macStr);
2538 int ret = system(cmd.c_str());
2539 if (ret == 0)
2540 {
2541 LOGF_INFO("WoL: magic packet sent to %s", macStr);
2542 return true;
2543 }
2544 if (ret == 127)
2545 {
2546 LOG_ERROR("WoL: wakeonlan tool not found. Please install it on your system.");
2547 return false;
2548 }
2549 LOG_ERROR("WoL: wakeonlan failed to send the packet.");
2550 return false;
2551}
double temperature
bool isConnected() const
INDI::PropertyText getText(const char *name) const
virtual bool Disconnect()
Disconnect from device.
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
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)
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
bool isSimulation() const
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
TelescopeStatus TrackState
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
bool isParked()
isParked is mount currently parked?
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties() override
Called to initialize basic properties required all the time.
INumber TrackFreqN[1]
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool sendScopeLocation()
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
INumberVectorProperty TrackFreqNP
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 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 sendScopeTime()
void setLX200Capability(uint32_t cap)
INDI::PropertyNumber MeridianLimitsNP
INumber RefractionModelTemperatureN[1]
INDI::PropertySwitch AllowedMeridianSideSP
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
void getBasicData() override
bool Handshake() override
perform handshake with device to check communication
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
INumberVectorProperty ModelCountNP
INumberVectorProperty NewAlignmentPointsNP
ISwitchVectorProperty AlignmentStateSP
ITextVectorProperty NewModelNameTP
bool CalculateSatTrajectory(std::string start_pass_isodatetime, std::string end_pass_isodatetime)
INumberVectorProperty NewAlpNP
INumber NewAlignmentPointsN[1]
bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
int setStandardProcedureAndExpectChar(int fd, const char *data, const char *expect)
ITextVectorProperty WoLMacTP
bool getSlewSettleTime(LX200_10MICRON_READ_CONTEXT context)
bool UnPark() override
Unpark the telescope if already parked.
void updateUnattendedFlipSetting(LX200_10MICRON_READ_CONTEXT context)
int monthToNumber(const char *monthName)
INumberVectorProperty RefractionModelPressureNP
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool getAllowedMeridianSide(LX200_10MICRON_READ_CONTEXT context)
int setStandardProcedureWithoutRead(int fd, const char *data)
bool setAllowedMeridianSide(int side)
INumberVectorProperty RefractionModelTemperatureNP
bool SetTLEtoFollow(const char *tle)
ISwitchVectorProperty WoLSendSP
bool getUnattendedFlipSetting()
INDI::PropertyNumber SlewSettleTimeNP
bool getTrackMode(LX200_10MICRON_READ_CONTEXT context)
IText NewModelNameT[1]
INDI::PropertyNumber TrackingEndNP
ITextVectorProperty ProductTP
bool setLocalDate(uint8_t days, uint8_t months, uint16_t years) override
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
INDI::PropertySwitch TargetPierSideSP
const char * getDefaultName() override
virtual int SetRefractionModelPressure(double pressure)
INumber MiniNewAlpN[MALP_COUNT]
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
bool getMeridianLimits(LX200_10MICRON_READ_CONTEXT context)
bool setSlewSettleTime(double seconds)
INumberVectorProperty TLEfromDatabaseNP
INumber NewAlpN[ALP_COUNT]
int setStandardProcedureAndReturnResponse(int fd, const char *data, char *response, int max_response_length)
@ GSTAT_NOT_TRACKING_AND_NOT_MOVING
bool ReadScopeStatus() override
Read telescope status.
ISwitch UnattendedFlipS[UNATTENDED_FLIP_COUNT]
bool initProperties() override
Called to initialize basic properties required all the time.
INDI::PropertySwitch MountShutdownSP
INumber MiniNewAlpRON[MALPRO_COUNT]
INumber ModelCountN[1]
bool setMeridianLimits(int slewLimit, int trackLimit)
bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual int SetRefractionModelTemperature(double temperature)
ISwitch WoLSendS[1]
bool saveModel(const char *name)
bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
bool Park() override
Park the telescope to its home position.
bool SyncConfigBehaviour(bool cmcfg)
INumberVectorProperty MiniNewAlpRONP
ISwitchVectorProperty UnattendedFlipSP
bool Flip(double ra, double dec) override
Move and flip the scope to the supplied RA and DEC coordinates.
INumber TLEfromDatabaseN[1]
INumber AlignmentPointsN[1]
int AddSyncPoint(double MRa, double MDec, double MSide, double PRa, double PDec, double SidTime)
INumberVectorProperty MiniNewAlpNP
ISwitch AlignmentStateS[ALIGN_COUNT]
bool confirmUnattendedFlipSetting(int wanted)
INumberVectorProperty AlignmentPointsNP
bool SetTLEfromDatabase(int tleN)
int AddSyncPointHere(double PRa, double PDec)
bool setUnattendedFlipSetting(bool setting)
INumber RefractionModelPressureN[1]
const char * CONNECTION_TAB
CONNECTION_TAB Where all device connection settings (serial, usb, ethernet) are defined and controlle...
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * SATELLITE_TAB
SATELLITE_TAB.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
double max(void)
INDI::PropertySwitch ParkSP
INDI::PropertyText TLEtoTrackTP
Text Vector property defining the orbital elements of an artificial satellite (TLE)....
INDI::PropertyText SatPassWindowTP
Text Vector property defining the start and end of a satellite pass (window contains pass)....
INDI::PropertySwitch TrackSatSP
Switch Vector property defining the state of the satellite tracking of the mount. Example implementat...
INDI::PropertySwitch TrackModeSP
@ SAT_TRACK
Track signal.
@ SAT_HALT
Halt signal (abort).
@ SAT_PASS_WINDOW_END
Index for end of the window.
@ SAT_PASS_WINDOW_START
Index for start of the window.
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_ATMOST1
Definition indiapi.h:172
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:653
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Definition indicom.c:194
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
Definition indicom.c:473
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[].
Definition indicom.c:130
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
int extractISOTime(const char *timestr, struct ln_date *iso_date)
Extract ISO 8601 time and store it in a tm struct.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
Definition indidevapi.c:33
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.
Definition indidevapi.c:490
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition indidevapi.c:337
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition indidevapi.c:366
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.
Definition indidevapi.c:509
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
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.
Definition indidevapi.c:376
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.
Definition indidevapi.c:416
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.
Definition indidevapi.c:398
void IUSaveConfigText(FILE *fp, const ITextVectorProperty *tvp)
Add a text vector property value to the configuration file.
Definition indidevapi.c:28
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.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
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 IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
int IUGetConfigText(const char *dev, const char *property, const char *member, char *value, int len)
IUGetConfigText Opens configuration file and reads single text property.
Definition indidriver.c:908
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,...)
int IUGetConfigSwitch(const char *dev, const char *property, const char *member, ISState *value)
IUGetConfigSwitch Opens configuration file and reads single switch property.
Definition indidriver.c:657
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#define DEBUGFDEVICE(device, priority, msg,...)
Definition indilogger.h:61
#define getDeviceName
int fd
#define WAKE_ON_LAN_SEND
#define ALIGNMENT_POINTS
#define WAKE_ON_LAN_MAC
#define MERIDIAN_LIMITS
#define NEW_ALIGNMENT_POINT
#define MINIMAL_NEW_ALIGNMENT_POINT
#define REFRACTION_MODEL_PRESSURE
#define ALIGNMENT_TAB
#define NEW_ALIGNMENT_POINTS
#define ALLOWED_MERIDIAN_SIDE
#define MOUNT_SHUTDOWN
#define SLEW_SETTLE_TIME
#define PRODUCT_TAB
#define MINIMAL_NEW_ALIGNMENT_POINT_RO
#define MODEL_COUNT
#define SLEW_SETTLE_TIME_MAX_IN_S
#define NEW_MODEL_NAME
#define TRACKING_END
#define PRODUCT_INFO
#define REFRACTION_MODEL_TEMPERATURE
#define ALIGNMENT_STATE
#define UNATTENDED_FLIP
#define LX200_TIMEOUT
#define TARGET_PIER_SIDE
int getCommandInt(int fd, int *value, const char *cmd)
int setStandardProcedure(int fd, const char *data)
int checkLX200EquatorialFormat(int fd)
unsigned int DBG_SCOPE
int setCommandInt(int fd, int data, const char *cmd)
int getTrackFreq(int fd, double *value)
int getCommandString(int fd, char *data, const char *cmd)
@ LX200_24
Definition lx200driver.h:64
uint8_t cmd[4]
Definition pwc-ioctl.h:2