Instrument Neutral Distributed Interface INDI 2.2.5
synscandriverlegacy.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2010 Gerry Rozema. All rights reserved.
3 Copyright(c) 2018 Jasem Mutlaq. All rights reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*******************************************************************************/
19
20#include "synscandriverlegacy.h"
23#include "indicom.h"
24#include "libastro.h"
25
26#include <libnova/transform.h>
27#include <libnova/precession.h>
28// libnova specifies round() on old systems and it collides with the new gcc 5.x/6.x headers
29#define HAVE_ROUND
30#include <libnova/utility.h>
31
32#include <cmath>
33#include <memory>
34#include <cstring>
35
36#define SYNSCAN_SLEW_RATES 9
37
38constexpr uint16_t SynscanLegacyDriver::SLEW_RATE[];
39
47
49{
50 if (isConnected())
51 return true;
52
53 bool rc = INDI::Telescope::Connect();
54
55 if (rc)
56 return AnalyzeMount();
57
58 return rc;
59}
60
62{
63 return "SynScan Legacy";
64}
65
67{
69
74
75 // Slew Rates
76 SlewRateSP[0].setLabel("1x");
77 SlewRateSP[1].setLabel("8x");
78 SlewRateSP[2].setLabel("16x");
79 SlewRateSP[3].setLabel("32x");
80 SlewRateSP[4].setLabel("64x");
81 SlewRateSP[5].setLabel("128x");
82 SlewRateSP[6].setLabel("400x");
83 SlewRateSP[7].setLabel("600x");
84 SlewRateSP[8].setLabel("MAX");
85 SlewRateSP.reset();
86 // Max is the default
87 SlewRateSP[8].setState(ISS_ON);
88
92 IUFillText(&BasicMountInfoT[MI_FW_VERSION], "FW_VERSION", "Firmware version", "-");
93 IUFillText(&BasicMountInfoT[MI_MOUNT_CODE], "MOUNT_CODE", "Mount code", "-");
94 IUFillText(&BasicMountInfoT[MI_ALIGN_STATUS], "ALIGNMENT_STATUS", "Alignment status", "-");
95 IUFillText(&BasicMountInfoT[MI_GOTO_STATUS], "GOTO_STATUS", "Goto status", "-");
96 IUFillText(&BasicMountInfoT[MI_POINT_STATUS], "MOUNT_POINTING_STATUS",
97 "Mount pointing status", "-");
98 IUFillText(&BasicMountInfoT[MI_TRACK_MODE], "TRACKING_MODE", "Tracking mode", "-");
99 IUFillTextVector(&BasicMountInfoTP, BasicMountInfoT, 6, getDeviceName(), "BASIC_MOUNT_INFO",
100 "Mount information", MountInfoPage, IP_RO, 60, IPS_IDLE);
101
105 // IUFillSwitch(&UseWiFiS[WIFI_ENABLED], "Enabled", "Enabled", ISS_OFF);
106 // IUFillSwitch(&UseWiFiS[WIFI_DISABLED], "Disabled", "Disabled", ISS_ON);
107 // IUFillSwitchVector(&UseWiFiSP, UseWiFiS, 2, getDeviceName(), "WIFI_SELECT", "Use WiFi?", CONNECTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
108
110
112
113 return true;
114}
115
116bool SynscanLegacyDriver::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
117{
118 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
119}
120
121bool SynscanLegacyDriver::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
122{
123#if 0
124 if (!strcmp(dev, getDeviceName()))
125 {
126 if (!strcmp(name, UseWiFiSP.name))
127 {
128 if (isConnected())
129 {
130 UseWiFiSP.s = IPS_ALERT;
131 IDSetSwitch(&UseWiFiSP, nullptr);
132 LOG_ERROR("Cannot select WiFi mode while already connected. It must be selected when when disconnected.");
133 return true;
134 }
135
136 IUUpdateSwitch(&UseWiFiSP, states, names, n);
137
138 if (UseWiFiS[WIFI_ENABLED].s == ISS_ON)
139 {
141 tcpConnection->setDefaultHost("192.168.4.2");
142 tcpConnection->setDefaultPort(11882);
143
144 LOG_INFO("Driver is configured for WiFi connection to 192.168.4.2 at TCP port 11882");
145
146 saveConfig(true, "WIFI_SELECT");
147 UseWiFiSP.s = IPS_OK;
148 IDSetSwitch(&UseWiFiSP, nullptr);
149
150 ISState newStates[] = { ISS_OFF, ISS_ON };
151 const char *newNames[] = { "CONNECTION_SERIAL", "CONNECTION_TCP" };
152 ISNewSwitch(getDeviceName(), "CONNECTION_MODE", newStates, const_cast<char **>(newNames), 2);
153 }
154 else
155 {
157 LOG_INFO("Driver is configured for serial connection to the hand controller.");
158
159 UseWiFiSP.s = IPS_OK;
160 IDSetSwitch(&UseWiFiSP, nullptr);
161
162 ISState newStates[] = { ISS_ON, ISS_OFF };
163 const char *newNames[] = { "CONNECTION_SERIAL", "CONNECTION_TCP" };
164 ISNewSwitch(getDeviceName(), "CONNECTION_MODE", newStates, const_cast<char **>(newNames), 2);
165 }
166
167 return true;
168 }
169 }
170#endif
171 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
172}
173
174bool SynscanLegacyDriver::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
175 char *formats[], char *names[], int n)
176{
177 return INDI::Telescope::ISNewBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
178}
179
180bool SynscanLegacyDriver::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
181{
182 return INDI::Telescope::ISNewText(dev, name, texts, names, n);
183}
184
186{
188
189 if (isConnected())
190 {
191 UpdateMountInformation(false);
192 defineProperty(&BasicMountInfoTP);
193 }
194 else
195 {
196 deleteProperty(BasicMountInfoTP.name);
197 }
198
199 return true;
200}
201
202int SynscanLegacyDriver::HexStrToInteger(const std::string &res)
203{
204 int result = 0;
205
206 try
207 {
208 result = std::stoi(res, nullptr, 16);
209 }
210 catch (std::invalid_argument &)
211 {
212 LOGF_ERROR("Failed to parse %s to integer.", res.c_str());
213 }
214
215 return result;
216}
217
219{
220 LOG_DEBUG("Analyzing Mount...");
221
222 bool rc = true;
223 int tmp = 0;
224 int bytesWritten = 0;
225 int bytesRead;
226 char res[MAX_SYN_BUF] = {0};
227
228 // JM 2018-08-15 Why are we reading caps here? Looks like it serves no purpose
229 //caps = GetTelescopeCapability();
230
231 rc = ReadLocation();
232 if (rc)
233 {
234 CanSetLocation = true;
235 ReadTime();
236 }
237
238 if (isSimulation() == false)
239 {
240 bytesRead = 0;
241 memset(res, 0, MAX_SYN_BUF);
242 LOG_DEBUG("CMD <J>");
243 tty_write(PortFD, "J", 1, &bytesWritten);
244 tty_read(PortFD, res, 2, 2, &bytesRead);
245 LOGF_DEBUG("RES <%s>", res);
246
247 if (res[0] == 0)
248 {
249 LOG_ERROR("Mount is not aligned. Please align the mount first and connection again.");
250 return false;
251 }
252
254 {
255 // Read the handset version
256 bytesRead = 0;
257 memset(res, 0, MAX_SYN_BUF);
258 LOG_DEBUG("Getting Firmware version...");
259 LOG_DEBUG("CMD <V>");
260 tty_write(PortFD, "V", 1, &bytesWritten);
261
262 tty_read(PortFD, res, 7, 2, &bytesRead);
263 LOGF_DEBUG("RES <%s>", res);
264
265 if (bytesRead == 3)
266 {
267 int tmp1 { 0 }, tmp2 { 0 };
268
269 tmp = res[0];
270 tmp1 = res[1];
271 tmp2 = res[2];
272 FirmwareVersion = tmp2;
273 FirmwareVersion /= 100;
274 FirmwareVersion += tmp1;
275 FirmwareVersion /= 100;
276 FirmwareVersion += tmp;
277 }
278 else
279 {
280 FirmwareVersion = (double)HexStrToInteger(std::string(&res[0], 2));
281 FirmwareVersion += (double)HexStrToInteger(std::string(&res[2], 2)) / 100;
282 FirmwareVersion += (double)HexStrToInteger(std::string(&res[4], 2)) / 10000;
283 }
284
285 LOGF_INFO("Firmware version: %lf", FirmwareVersion);
286
287 if (FirmwareVersion < 3.38 || (FirmwareVersion >= 4.0 && FirmwareVersion < 4.38))
288 {
289 LOG_WARN("Firmware version is too old. Update Synscan firmware to v4.38+");
290 }
291 else
292 {
293 NewFirmware = true;
294 }
295
296 HandsetFwVersion = std::to_string(FirmwareVersion);
297
298 // Mount Model
299 memset(res, 0, MAX_SYN_BUF);
300 LOG_DEBUG("CMD <m>");
301 tty_write(PortFD, "m", 1, &bytesWritten);
302 tty_read(PortFD, res, 2, 2, &bytesRead);
303 LOGF_DEBUG("RES <%s>", res);
304
305 if (bytesRead == 2)
306 {
307 // This workaround is needed because the firmware 3.39 sends these bytes swapped.
308 if (res[1] == '#')
309 MountCode = static_cast<int>(*reinterpret_cast<unsigned char * >(&res[0]));
310 else
311 MountCode = static_cast<int>(*reinterpret_cast<unsigned char*>(&res[1]));
312 }
313 }
314
315 // Check the tracking status
316 LOG_DEBUG("Getting Tracking status...");
317 memset(res, 0, MAX_SYN_BUF);
318 LOG_DEBUG("CMD <t>");
319 tty_write(PortFD, "t", 1, &bytesWritten);
320 tty_read(PortFD, res, 2, 2, &bytesRead);
321 LOGF_DEBUG("RES <%s>", res);
322
323 if (res[1] == '#' && static_cast<int>(res[0]) != 0)
324 {
326 }
327 }
328
329 initParking();
330
331 LOG_DEBUG("Analyzing mount complete.");
332
333 return true;
334}
335
337{
338 LOG_DEBUG("Initializing parking...");
339 if (InitPark())
340 {
343 }
344 else
345 {
346 SetAxis1Park(0);
347 SetAxis2Park(90);
350 }
351}
352
354{
355 if (isSimulation())
356 {
357 MountSim();
358 return true;
359 }
360
361 char res[MAX_SYN_BUF] = {0};
362 int bytesWritten, bytesRead;
363 double ra, dec;
364 long unsigned int n1, n2;
365
366 LOG_DEBUG("CMD <Ka>");
367 tty_write(PortFD, "Ka", 2, &bytesWritten); // test for an echo
368
369 tty_read(PortFD, res, 2, 2, &bytesRead); // Read 2 bytes of response
370 LOGF_DEBUG("RES <%s>", res);
371
372 if (res[1] != '#')
373 {
374 LOG_WARN("Synscan Mount not responding");
375 // Usually, Abort() recovers the communication
376 RecoverTrials++;
377 Abort();
378 // HasFailed = true;
379 return false;
380 }
381 RecoverTrials = 0;
382
383 /*
384 // With 3.37 firmware, on the older line of eq6 mounts
385 // The handset does not always initialize the communication with the motors correctly
386 // We can check for this condition by querying the motors for firmware version
387 // and if it returns zero, it means we need to power cycle the handset
388 // and try again after it restarts again
389
390 if(HasFailed) {
391 int v1,v2;
392 v1=PassthruCommand(0xfe,0x11,1,0,2);
393 v2=PassthruCommand(0xfe,0x10,1,0,2);
394 fprintf(stderr,"Motor firmware versions %d %d\n",v1,v2);
395 if((v1==0)||(v2==0)) {
396 IDMessage(getDeviceName(),"Cannot proceed");
397 IDMessage(getDeviceName(),"Handset is responding, but Motors are Not Responding");
398 return false;
399 }
400 // if we get here, both motors are responding again
401 // so the problem is solved
402 HasFailed=false;
403 }
404 */
405
406 // on subsequent passes, we just need to read the time
407 // if (HasTime())
408 // {
409 // ReadTime();
410 // }
411 if (HasLocation())
412 {
413 // this flag is set when we get a new lat/long from the host
414 // so we should go thru the read routine once now, so things update
415 // correctly in the client displays
416 if (ReadLatLong)
417 {
418 ReadLocation();
419 }
420 }
421
422 // Query mount information
423 memset(res, 0, MAX_SYN_BUF);
424 LOG_DEBUG("CMD <J>");
425 tty_write(PortFD, "J", 1, &bytesWritten);
426 tty_read(PortFD, res, 2, 2, &bytesRead);
427 LOGF_DEBUG("RES <%s>", res);
428 if (res[1] == '#')
429 {
430 AlignmentStatus = std::to_string((int)res[0]);
431 }
432 memset(res, 0, MAX_SYN_BUF);
433 LOG_DEBUG("CMD <L>");
434 tty_write(PortFD, "L", 1, &bytesWritten);
435 tty_read(PortFD, res, 2, 2, &bytesRead);
436 LOGF_DEBUG("RES <%s>", res);
437 if (res[1] == '#')
438 {
439 GotoStatus = res[0];
440 }
441 memset(res, 0, MAX_SYN_BUF);
442 LOG_DEBUG("CMD <p>");
443 tty_write(PortFD, "p", 1, &bytesWritten);
444 tty_read(PortFD, res, 2, 2, &bytesRead);
445 LOGF_DEBUG("RES <%s>", res);
446 if (res[1] == '#')
447 {
448 PointingStatus = res[0];
449
450 // INDI and mount pier sides are opposite to each other
451 setPierSide(res[0] == 'W' ? PIER_EAST : PIER_WEST);
452 }
453 memset(res, 0, MAX_SYN_BUF);
454 LOG_DEBUG("CMD <t>");
455 tty_write(PortFD, "t", 1, &bytesWritten);
456 tty_read(PortFD, res, 2, 2, &bytesRead);
457 LOGF_DEBUG("RES <%s>", res);
458 if (res[1] == '#')
459 {
460 TrackingStatus = res[0];
461 switch((int)res[0])
462 {
463 case 0:
464 TrackingMode = "Tracking off";
465 break;
466 case 1:
467 TrackingMode = "Alt/Az tracking";
468 break;
469 case 2:
470 TrackingMode = "EQ tracking";
471 break;
472 case 3:
473 TrackingMode = "PEC mode";
474 break;
475 }
476 }
477
478 UpdateMountInformation(true);
479
481 {
482 // We have a slew in progress
483 // lets see if it's complete
484 // This only works for ra/dec goto commands
485 // The goto complete flag doesn't trip for ALT/AZ commands
486 if (GotoStatus != "0")
487 {
488 // Nothing to do here
489 }
490 else if (MountCode < 128)
491 {
492 if (TrackingStatus[0] != 0)
494 else
496 }
497 }
499 {
500 if (FirmwareVersion == 4.103500)
501 {
502 // With this firmware the correct way
503 // is to check the slewing flat
504 memset(res, 0, 3);
505 LOG_DEBUG("CMD <L>");
506 tty_write(PortFD, "L", 1, &bytesWritten);
507 tty_read(PortFD, res, 2, 3, &bytesRead);
508 LOGF_DEBUG("RES <%s>", res);
509 if (res[0] != 48)
510 {
511 // Nothing to do here
512 }
513 else
514 {
515 if (NumPark++ < 2)
516 {
517 Park();
518 }
519 else
520 {
522 SetParked(true);
523 }
524 }
525 }
526 else
527 {
528 // ok, lets try read where we are
529 // and see if we have reached the park position
530 // newer firmware versions dont read it back the same way
531 // so we watch now to see if we get the same read twice in a row
532 // to confirm that it has stopped moving
533 memset(res, 0, MAX_SYN_BUF);
534 LOG_DEBUG("CMD <z>");
535 tty_write(PortFD, "z", 1, &bytesWritten);
536 tty_read(PortFD, res, 18, 2, &bytesRead);
537 LOGF_DEBUG("RES <%s>", res);
538
539 //IDMessage(getDeviceName(),"Park Read %s %d",res,StopCount);
540
541 if (strncmp((char *)res, LastParkRead, 18) == 0)
542 {
543 // We find that often after it stops from park
544 // it's off the park position by a small amount
545 // issuing another park command gets a small movement and then
546 if (++StopCount > 2)
547 {
548 if (NumPark++ < 2)
549 {
550 StopCount = 0;
551 //IDMessage(getDeviceName(),"Sending park again");
552 Park();
553 }
554 else
555 {
557 //ParkSP.s=IPS_OK;
558 //IDSetSwitch(&ParkSP,nullptr);
559 //IDMessage(getDeviceName(),"Telescope is Parked.");
560 SetParked(true);
561 }
562 }
563 else
564 {
565 //StopCount=0;
566 }
567 }
568 else
569 {
570 StopCount = 0;
571 }
572 snprintf(LastParkRead, 20, "%.20s", res);
573 }
574 }
575
576 memset(res, 0, MAX_SYN_BUF);
577 LOG_DEBUG("CMD <e>");
578 tty_write(PortFD, "e", 1, &bytesWritten);
579 tty_read(PortFD, res, 18, 1, &bytesRead);
580 LOGF_DEBUG("RES <%s>", res);
581 if (bytesRead != 18)
582 {
583 LOG_DEBUG("Read current position failed");
584 return false;
585 }
586
587 sscanf(res, "%lx,%lx#", &n1, &n2);
588 ra = static_cast<double>(n1) / 0x100000000 * 24.0;
589 dec = static_cast<double>(n2) / 0x100000000 * 360.0;
590
591 INDI::IEquatorialCoordinates epochPos { 0, 0 }, J2000Pos { 0, 0 };
592 J2000Pos.rightascension = range24(ra);
593 J2000Pos.declination = rangeDec(dec);
594
595 // Synscan reports J2000 coordinates so we need to convert from J2000 to JNow
596 INDI::J2000toObserved(&J2000Pos, ln_get_julian_from_sys(), &epochPos);
597
598 CurrentRA = epochPos.rightascension;
599 CurrentDEC = epochPos.declination;
600
601 // Now feed the rest of the system with corrected data
603
604 if (TrackState == SCOPE_SLEWING && MountCode >= 128 && (SlewTargetAz != -1 || SlewTargetAlt != -1))
605 {
606 INDI::IHorizontalCoordinates CurrentAltAz { 0, 0 };
607 double DiffAlt { 0 };
608 double DiffAz { 0 };
609
610 INDI::EquatorialToHorizontal(&epochPos, &m_Location, ln_get_julian_from_sys(), &CurrentAltAz);
611 DiffAlt = CurrentAltAz.altitude - SlewTargetAlt;
612 if (SlewTargetAlt != -1 && std::abs(DiffAlt) > 0.01)
613 {
614 int NewRate = 2;
615
616 if (std::abs(DiffAlt) > 4)
617 {
618 NewRate = 9;
619 }
620 else if (std::abs(DiffAlt) > 1.2)
621 {
622 NewRate = 7;
623 }
624 else if (std::abs(DiffAlt) > 0.5)
625 {
626 NewRate = 5;
627 }
628 else if (std::abs(DiffAlt) > 0.2)
629 {
630 NewRate = 4;
631 }
632 else if (std::abs(DiffAlt) > 0.025)
633 {
634 NewRate = 3;
635 }
636 LOGF_DEBUG("Slewing Alt axis: %1.3f-%1.3f -> %1.3f (speed: %d)",
637 CurrentAltAz.altitude, SlewTargetAlt, CurrentAltAz.altitude - SlewTargetAlt, CustomNSSlewRate);
638 if (NewRate != CustomNSSlewRate)
639 {
640 if (DiffAlt < 0)
641 {
642 CustomNSSlewRate = NewRate;
644 }
645 else
646 {
647 CustomNSSlewRate = NewRate;
649 }
650 }
651 }
652 else if (SlewTargetAlt != -1 && std::abs(DiffAlt) < 0.01)
653 {
655 SlewTargetAlt = -1;
656 LOG_DEBUG("Slewing on Alt axis finished");
657 }
658 DiffAz = CurrentAltAz.azimuth - SlewTargetAz;
659 if (DiffAz < -180)
660 DiffAz = (DiffAz + 360) * 2;
661 else if (DiffAz > 180)
662 DiffAz = (DiffAz - 360) * 2;
663 if (SlewTargetAz != -1 && std::abs(DiffAz) > 0.01)
664 {
665 int NewRate = 2;
666
667 if (std::abs(DiffAz) > 4)
668 {
669 NewRate = 9;
670 }
671 else if (std::abs(DiffAz) > 1.2)
672 {
673 NewRate = 7;
674 }
675 else if (std::abs(DiffAz) > 0.5)
676 {
677 NewRate = 5;
678 }
679 else if (std::abs(DiffAz) > 0.2)
680 {
681 NewRate = 4;
682 }
683 else if (std::abs(DiffAz) > 0.025)
684 {
685 NewRate = 3;
686 }
687 LOGF_DEBUG("Slewing Az axis: %1.3f-%1.3f -> %1.3f (speed: %d)",
688 CurrentAltAz.azimuth, SlewTargetAz, CurrentAltAz.azimuth - SlewTargetAz, CustomWESlewRate);
689 if (NewRate != CustomWESlewRate)
690 {
691 if (DiffAz > 0)
692 {
693 CustomWESlewRate = NewRate;
695 }
696 else
697 {
698 CustomWESlewRate = NewRate;
700 }
701 }
702 }
703 else if (SlewTargetAz != -1 && std::abs(DiffAz) < 0.01)
704 {
706 SlewTargetAz = -1;
707 LOG_DEBUG("Slewing on Az axis finished");
708 }
709 if (SlewTargetAz == -1 && SlewTargetAlt == -1)
710 {
712 }
713 }
714 return true;
715}
716
718{
719 char res[MAX_SYN_BUF] = {0};
720 int bytesWritten, bytesRead;
721
723 LOG_INFO("Tracking started.");
724
725 if (isSimulation())
726 return true;
727
728 // Start tracking
729 res[0] = 'T';
730 // Check the mount type to choose tracking mode
731 if (MountCode >= 128)
732 {
733 // Alt/Az tracking mode
734 res[1] = 1;
735 }
736 else
737 {
738 // EQ tracking mode
739 res[1] = 2;
740 }
741 tty_write(PortFD, res, 2, &bytesWritten);
742 tty_read(PortFD, res, 1, 2, &bytesRead);
743 if (bytesRead != 1 || res[0] != '#')
744 {
745 LOG_DEBUG("Timeout waiting for scope to start tracking.");
746 return false;
747 }
748 return true;
749}
750
751bool SynscanLegacyDriver::Goto(double ra, double dec)
752{
753 char res[MAX_SYN_BUF] = {0};
754 int bytesWritten, bytesRead;
755 INDI::IHorizontalCoordinates TargetAltAz { 0, 0 };
756
757 if (isSimulation() == false)
758 {
759 LOG_DEBUG("CMD <Ka>");
760 tty_write(PortFD, "Ka", 2, &bytesWritten); // test for an echo
761 tty_read(PortFD, res, 2, 2, &bytesRead); // Read 2 bytes of response
762 LOGF_DEBUG("RES <%s>", res);
763 if (res[1] != '#')
764 {
765 LOG_WARN("Wrong answer from the mount");
766 // this is not a correct echo
767 // so we are not talking to a mount properly
768 return false;
769 }
770 }
771
773 // EQ mount has a different Goto mode
774 if (MountCode < 128 && isSimulation() == false)
775 {
776 INDI::IEquatorialCoordinates epochPos { 0, 0 }, J2000Pos { 0, 0 };
777 epochPos.rightascension = ra;
778 epochPos.declination = dec;
779
780 // Synscan accepts J2000 coordinates so we need to convert from JNow to J2000
781 INDI::ObservedToJ2000(&epochPos, ln_get_julian_from_sys(), &J2000Pos);
782
783 // Mount deals in J2000 coords.
784 int n1 = J2000Pos.rightascension * 0x1000000 / 24;
785 int n2 = J2000Pos.declination * 0x1000000 / 360;
786
787 LOGF_DEBUG("Goto - JNow RA: %g JNow DE: %g J2000 RA: %g J2000 DE: %g", ra, dec, J2000Pos.rightascension,
788 J2000Pos.declination);
789
790 n1 = n1 << 8;
791 n2 = n2 << 8;
792 LOGF_DEBUG("CMD <%s>", res);
793 snprintf(res, MAX_SYN_BUF, "r%08X,%08X", n1, n2);
794 tty_write(PortFD, res, 18, &bytesWritten);
795 memset(&res[18], 0, 1);
796
797 tty_read(PortFD, res, 1, 60, &bytesRead);
798 if (bytesRead != 1 || res[0] != '#')
799 {
800 LOG_DEBUG("Timeout waiting for scope to complete goto.");
801 return false;
802 }
803
804 return true;
805 }
806
807 INDI::IEquatorialCoordinates epochPos { ra, dec };
808 INDI::EquatorialToHorizontal(&epochPos, &m_Location, ln_get_julian_from_sys(), &TargetAltAz);
809 LOGF_DEBUG("Goto - JNow RA: %g JNow DE: %g (az: %g alt: %g)", ra, dec, TargetAltAz.azimuth, TargetAltAz.altitude);
810 char RAStr[MAX_SYN_BUF] = {0}, DEStr[MAX_SYN_BUF] = {0}, AZStr[MAX_SYN_BUF] = {0}, ATStr[MAX_SYN_BUF] = {0};
811 fs_sexa(RAStr, ra, 2, 3600);
812 fs_sexa(DEStr, dec, 2, 3600);
813 fs_sexa(AZStr, TargetAltAz.azimuth, 2, 3600);
814 fs_sexa(ATStr, TargetAltAz.altitude, 2, 3600);
815
816 LOGF_INFO("Goto RA: %s DE: %s AZ: %s ALT: %s", RAStr, DEStr, AZStr, ATStr);
817
818 SlewTargetAz = TargetAltAz.azimuth;
819 SlewTargetAlt = TargetAltAz.altitude;
820
821 TargetRA = ra;
822 TargetDEC = dec;
823
824 return true;
825}
826
828{
829 char res[MAX_SYN_BUF] = {0};
830 int bytesWritten, bytesRead;
831
832 if (isSimulation() == false)
833 {
834 strncpy(LastParkRead, "", 1);
835 memset(res, 0, 3);
836 tty_write(PortFD, "Ka", 2, &bytesWritten); // test for an echo
837 tty_read(PortFD, res, 2, 2, &bytesRead); // Read 2 bytes of response
838 if (res[1] != '#')
839 {
840 // this is not a correct echo
841 // so we are not talking to a mount properly
842 return false;
843 }
844 // Now we stop tracking
845 res[0] = 'T';
846 res[1] = 0;
847 tty_write(PortFD, res, 2, &bytesWritten);
848 tty_read(PortFD, res, 1, 60, &bytesRead);
849 if (bytesRead != 1 || res[0] != '#')
850 {
851 LOG_DEBUG("Timeout waiting for scope to stop tracking.");
852 return false;
853 }
854
855 //sprintf((char *)res,"b%08X,%08X",0x0,0x40000000);
856 tty_write(PortFD, "b00000000,40000000", 18, &bytesWritten);
857 tty_read(PortFD, res, 1, 60, &bytesRead);
858 if (bytesRead != 1 || res[0] != '#')
859 {
860 LOG_DEBUG("Timeout waiting for scope to respond to park.");
861 return false;
862 }
863 }
864
866 if (NumPark == 0)
867 {
868 LOG_INFO("Parking Mount...");
869 }
870 StopCount = 0;
871 return true;
872}
873
875{
876 SetParked(false);
877 NumPark = 0;
878 return true;
879}
880
882{
883 LOG_INFO("Setting arbitrary park positions is not supported yet.");
884 return false;
885}
886
888{
889 // By default az to north, and alt to pole
890 LOG_DEBUG("Setting Park Data to Default.");
891 SetAxis1Park(0);
892 SetAxis2Park(90);
893
894 return true;
895}
896
898{
899 if (TrackState == SCOPE_IDLE || RecoverTrials >= 3)
900 return true;
901
902 char res[MAX_SYN_BUF] = {0};
903 int bytesWritten, bytesRead;
904
905 LOG_DEBUG("Abort mount...");
907
908 if (isSimulation())
909 return true;
910
911 SlewTargetAlt = -1;
912 SlewTargetAz = -1;
913 CustomNSSlewRate = -1;
914 CustomWESlewRate = -1;
915 // Stop tracking
916 res[0] = 'T';
917 res[1] = 0;
918
919 LOGF_DEBUG("CMD <%s>", res);
920 tty_write(PortFD, res, 2, &bytesWritten);
921
922 tty_read(PortFD, res, 1, 2, &bytesRead);
923 LOGF_DEBUG("RES <%s>", res);
924
925 if (bytesRead != 1 || res[0] != '#')
926 {
927 LOG_DEBUG("Timeout waiting for scope to stop tracking.");
928 return false;
929 }
930
931 // Hmmm twice only stops it
932 LOG_DEBUG("CMD <M>");
933 tty_write(PortFD, "M", 1, &bytesWritten);
934 tty_read(PortFD, res, 1, 1, &bytesRead);
935 LOGF_DEBUG("RES <%c>", res[0]);
936
937 LOG_DEBUG("CMD <M>");
938 tty_write(PortFD, "M", 1, &bytesWritten);
939 tty_read(PortFD, res, 1, 1, &bytesRead);
940 LOGF_DEBUG("RES <%c>", res[0]);
941
942 return true;
943}
944
946{
947 if (isSimulation())
948 return true;
949
950 if (command != MOTION_START)
951 {
952 PassthruCommand(37, 17, 2, 0, 0);
953 }
954 else
955 {
956 int tt = (CustomNSSlewRate == -1 ? SlewRate : CustomNSSlewRate);
957
958 tt = tt << 16;
959 if (dir != DIRECTION_NORTH)
960 {
961 PassthruCommand(37, 17, 2, tt, 0);
962 }
963 else
964 {
965 PassthruCommand(36, 17, 2, tt, 0);
966 }
967 }
968
969 return true;
970}
971
973{
974 if (isSimulation())
975 return true;
976
977 if (command != MOTION_START)
978 {
979 PassthruCommand(37, 16, 2, 0, 0);
980 }
981 else
982 {
983 int tt = (CustomWESlewRate == -1 ? SlewRate : CustomWESlewRate);
984
985 tt = tt << 16;
986 if (dir != DIRECTION_WEST)
987 {
988 PassthruCommand(36, 16, 2, tt, 0);
989 }
990 else
991 {
992 PassthruCommand(37, 16, 2, tt, 0);
993 }
994 }
995
996 return true;
997}
998
1000{
1001 SlewRate = s + 1;
1002 return true;
1003}
1004
1005int SynscanLegacyDriver::PassthruCommand(int cmd, int target, int msgsize, int data, int numReturn)
1006{
1007 char test[20] = {0};
1008 int bytesRead, bytesWritten;
1009 char a, b, c;
1010 int tt = data;
1011
1012 a = tt % 256;
1013 tt = tt >> 8;
1014 b = tt % 256;
1015 tt = tt >> 8;
1016 c = tt % 256;
1017
1018 // format up a passthru command
1019 memset(test, 0, 20);
1020 test[0] = 80; // passhtru
1021 test[1] = msgsize; // set message size
1022 test[2] = target; // set the target
1023 test[3] = cmd; // set the command
1024 test[4] = c; // set data bytes
1025 test[5] = b;
1026 test[6] = a;
1027 test[7] = numReturn;
1028
1029 LOGF_DEBUG("CMD <%s>", test);
1030 tty_write(PortFD, test, 8, &bytesWritten);
1031 memset(test, 0, 20);
1032 tty_read(PortFD, test, numReturn + 1, 2, &bytesRead);
1033 LOGF_DEBUG("RES <%s>", test);
1034 if (numReturn > 0)
1035 {
1036 int retval = 0;
1037 retval = test[0];
1038 if (numReturn > 1)
1039 {
1040 retval = retval << 8;
1041 retval += test[1];
1042 }
1043 if (numReturn > 2)
1044 {
1045 retval = retval << 8;
1046 retval += test[2];
1047 }
1048 return retval;
1049 }
1050
1051 return 0;
1052}
1053
1055{
1056 LOG_DEBUG("Reading time...");
1057
1058 if (isSimulation())
1059 {
1060 char timeString[MAXINDINAME] = {0};
1061 time_t now = time (nullptr);
1062 strftime(timeString, MAXINDINAME, "%T", gmtime(&now));
1063 TimeTP[UTC].setText("3");
1064 TimeTP[OFFSET].setText(timeString);
1065 TimeTP.setState(IPS_OK);
1066 TimeTP.apply();
1067 return true;
1068 }
1069
1070 char res[MAX_SYN_BUF] = {0};
1071 int bytesWritten = 0, bytesRead = 0;
1072
1073 // lets see if this hand controller responds to a time request
1074 bytesRead = 0;
1075 LOG_DEBUG("CMD <h>");
1076 tty_write(PortFD, "h", 1, &bytesWritten);
1077
1078 tty_read(PortFD, res, 9, 2, &bytesRead);
1079 LOGF_DEBUG("RES <%s>", res);
1080
1081 if (res[8] == '#')
1082 {
1083 ln_zonedate localTime;
1084 ln_date utcTime;
1085 int offset, daylightflag;
1086
1087 localTime.hours = res[0];
1088 localTime.minutes = res[1];
1089 localTime.seconds = res[2];
1090 localTime.months = res[3];
1091 localTime.days = res[4];
1092 localTime.years = res[5];
1093 offset = (int)res[6];
1094 // Negative GMT offset is read. It needs special treatment
1095 if (offset > 200)
1096 offset -= 256;
1097 localTime.gmtoff = offset;
1098 // this is the daylight savings flag in the hand controller, needed if we did not set the time
1099 daylightflag = res[7];
1100 localTime.years += 2000;
1101 localTime.gmtoff *= 3600;
1102 // now convert to utc
1103 ln_zonedate_to_date(&localTime, &utcTime);
1104
1105 // now we have time from the hand controller, we need to set some variables
1106 int sec;
1107 char utc[100];
1108 char ofs[16] = {0};
1109 sec = (int)utcTime.seconds;
1110 sprintf(utc, "%04d-%02d-%dT%d:%02d:%02d", utcTime.years, utcTime.months, utcTime.days, utcTime.hours,
1111 utcTime.minutes, sec);
1112 if (daylightflag == 1)
1113 offset = offset + 1;
1114 snprintf(ofs, 16, "%d", offset);
1115
1116 TimeTP[UTC].setText(utc);
1117 TimeTP[OFFSET].setText(ofs);
1118 TimeTP.setState(IPS_OK);
1119 TimeTP.apply(nullptr);
1120
1121 LOGF_INFO("Mount UTC Time %s Offset %d", utc, offset);
1122
1123 return true;
1124 }
1125 return false;
1126}
1127
1129{
1130 LOG_DEBUG("Reading Location...");
1131
1132 if (isSimulation())
1133 {
1134 LocationNP[LOCATION_LATITUDE].setValue(29.5);
1135 LocationNP[LOCATION_LONGITUDE].setValue(48);
1136 LocationNP.apply();
1137 ReadLatLong = false;
1138 return true;
1139 }
1140
1141 char res[MAX_SYN_BUF] = {0};
1142 int bytesWritten = 0, bytesRead = 0;
1143
1144 LOG_DEBUG("CMD <Ka>");
1145 // test for an echo
1146 tty_write(PortFD, "Ka", 2, &bytesWritten);
1147 // Read 2 bytes of response
1148 tty_read(PortFD, res, 2, 2, &bytesRead);
1149 LOGF_DEBUG("RES <%s>", res);
1150
1151 if (res[1] != '#')
1152 {
1153 LOG_WARN("Bad echo in ReadLocation");
1154 }
1155 else
1156 {
1157 // lets see if this hand controller responds to a location request
1158 bytesRead = 0;
1159 LOG_DEBUG("CMD <w>");
1160 tty_write(PortFD, "w", 1, &bytesWritten);
1161
1162 tty_read(PortFD, res, 9, 2, &bytesRead);
1163 LOGF_DEBUG("RES <%s>", res);
1164
1165 if (res[8] == '#')
1166 {
1167 double lat, lon;
1168 // lets parse this data now
1169 int a, b, c, d, e, f, g, h;
1170 a = res[0];
1171 b = res[1];
1172 c = res[2];
1173 d = res[3];
1174 e = res[4];
1175 f = res[5];
1176 g = res[6];
1177 h = res[7];
1178
1179 LOGF_DEBUG("Pos %d:%d:%d %d:%d:%d", a, b, c, e, f, g);
1180
1181 double t1, t2, t3;
1182
1183 t1 = c;
1184 t2 = b;
1185 t3 = a;
1186 t1 = t1 / 3600.0;
1187 t2 = t2 / 60.0;
1188 lat = t1 + t2 + t3;
1189
1190 t1 = g;
1191 t2 = f;
1192 t3 = e;
1193 t1 = t1 / 3600.0;
1194 t2 = t2 / 60.0;
1195 lon = t1 + t2 + t3;
1196
1197 if (d == 1)
1198 lat = lat * -1;
1199 if (h == 1)
1200 lon = 360 - lon;
1201 LocationNP[LOCATION_LATITUDE].setValue(lat);
1202 LocationNP[LOCATION_LONGITUDE].setValue(lon);
1203 LocationNP.apply();
1204
1205 saveConfig(true, "GEOGRAPHIC_COORD");
1206
1207 char LongitudeStr[32] = {0}, LatitudeStr[32] = {0};
1208 fs_sexa(LongitudeStr, lon, 2, 3600);
1209 fs_sexa(LatitudeStr, lat, 2, 3600);
1210 LOGF_INFO("Mount Longitude %s Latitude %s", LongitudeStr, LatitudeStr);
1211
1212 // We dont need to keep reading this one on every cycle
1213 // only need to read it when it's been changed
1214 ReadLatLong = false;
1215 return true;
1216 }
1217 else
1218 {
1219 LOG_INFO("Mount does not support setting location.");
1220 }
1221 }
1222 return false;
1223}
1224
1225bool SynscanLegacyDriver::updateTime(ln_date *utc, double utc_offset)
1226{
1227 char res[MAX_SYN_BUF] = {0};
1228 int bytesWritten = 0, bytesRead = 0;
1229
1230 // start by formatting a time for the hand controller
1231 // we are going to set controller to local time
1232 struct ln_zonedate ltm;
1233
1234 ln_date_to_zonedate(utc, &ltm, (long)utc_offset * 3600.0);
1235
1236 int yr = ltm.years;
1237
1238 yr = yr % 100;
1239
1240 res[0] = 'H';
1241 res[1] = ltm.hours;
1242 res[2] = ltm.minutes;
1243 res[3] = (char)(int)ltm.seconds;
1244 res[4] = ltm.months;
1245 res[5] = ltm.days;
1246 res[6] = yr;
1247 // Strangely enough static_cast<int>(double) results 0 for negative values on arm
1248 // We need to use old C-like casts in this case.
1249 res[7] = (char)(int)utc_offset; // offset from utc so hand controller is running in local time
1250 res[8] = 0; // and no daylight savings adjustments, it's already included in the offset
1251 // lets write a time to the hand controller
1252 bytesRead = 0;
1253
1254 LOGF_INFO("Setting mount date/time to %04d-%02d-%02d %d:%02d:%02d UTC Offset: %d",
1255 ltm.years, ltm.months, ltm.days, ltm.hours, ltm.minutes, ltm.seconds, utc_offset);
1256
1257 if (isSimulation())
1258 return true;
1259
1260 LOGF_DEBUG("CMD <%s>", res);
1261 tty_write(PortFD, res, 9, &bytesWritten);
1262
1263 tty_read(PortFD, res, 1, 2, &bytesRead);
1264 LOGF_DEBUG("RES <%c>", res[0]);
1265
1266 if (res[0] != '#')
1267 {
1268 LOG_INFO("Invalid return from set time");
1269 }
1270 return true;
1271}
1272
1273bool SynscanLegacyDriver::updateLocation(double latitude, double longitude, double elevation)
1274{
1275 INDI_UNUSED(elevation);
1276
1277 char res[MAX_SYN_BUF] = {0};
1278 int bytesWritten = 0, bytesRead = 0;
1279 int s = 0;
1280 bool IsWest = false;
1281 double tmp = 0;
1282
1283 ln_lnlat_posn p1 { 0, 0 };
1284 lnh_lnlat_posn p2;
1285
1286 if (isSimulation())
1287 {
1288 if (CurrentDEC == 0)
1289 {
1290 CurrentDEC = latitude > 0 ? 90 : -90;
1292 }
1293 return true;
1294 }
1295
1296 if (!CanSetLocation)
1297 {
1298 return true;
1299 }
1300 else
1301 {
1302 if (longitude > 180)
1303 {
1304 p1.lng = 360.0 - longitude;
1305 IsWest = true;
1306 }
1307 else
1308 {
1309 p1.lng = longitude;
1310 }
1311 p1.lat = latitude;
1312 ln_lnlat_to_hlnlat(&p1, &p2);
1313 LOGF_INFO("Update location to latitude %d:%d:%1.2f longitude %d:%d:%1.2f",
1314 p2.lat.degrees, p2.lat.minutes, p2.lat.seconds, p2.lng.degrees, p2.lng.minutes, p2.lng.seconds);
1315
1316 res[0] = 'W';
1317 res[1] = p2.lat.degrees;
1318 res[2] = p2.lat.minutes;
1319 tmp = p2.lat.seconds + 0.5;
1320 s = (int)tmp; // put in an int that's rounded
1321 res[3] = s;
1322 if (p2.lat.neg == 0)
1323 {
1324 res[4] = 0;
1325 }
1326 else
1327 {
1328 res[4] = 1;
1329 }
1330
1331 res[5] = p2.lng.degrees;
1332 res[6] = p2.lng.minutes;
1333 s = (int)(p2.lng.seconds + 0.5); // make an int, that's rounded
1334 res[7] = s;
1335 if (IsWest)
1336 res[8] = 1;
1337 else
1338 res[8] = 0;
1339 // All formatted, now send to the hand controller;
1340 bytesRead = 0;
1341
1342 LOGF_DEBUG("CMD <%s>", res);
1343 tty_write(PortFD, res, 9, &bytesWritten);
1344
1345 tty_read(PortFD, res, 1, 2, &bytesRead);
1346 LOGF_DEBUG("RES <%c>", res[0]);
1347
1348 if (res[0] != '#')
1349 {
1350 LOG_INFO("Invalid response for location setting");
1351 }
1352 // want to read it on the next cycle, so we update the fields in the client
1353 ReadLatLong = true;
1354
1355 return true;
1356 }
1357}
1358
1360{
1361 /*
1362 * Frank Liu, R&D Engineer for Skywatcher, says to only issue a Sync
1363 * command, and not to use the Position Reset command, when syncing. I
1364 * removed the position reset code for EQ mounts, but left it in for
1365 * Alt/Az mounts, since it seems to be working, at least for the person
1366 * (@kecsap) who put it in there in the first place. :)
1367 *
1368 * The code prior to kecsap's recent fix would always send a position
1369 * reset command, but it would send Alt/Az coordinates, even to an EQ
1370 * mount. This would really screw up EQ mount alignment.
1371 *
1372 * The reason a lone Sync command appeared to not work before, is because
1373 * it will only accept a Sync command if the offset is relatively small,
1374 * within 6-7 degrees or so. So you must already have done an alignment
1375 * through the handset (a 1-star alignment would suffice), and only use
1376 * the Sync command to "touch-up" the alignment. You can't take a scope,
1377 * power it on, point it to a random place in the sky, do a plate-solve,
1378 * and sync. That won't work.
1379 */
1380
1381 bool IsTrackingBeforeSync = (TrackState == SCOPE_TRACKING);
1382
1383 // Abort any motion before syncing
1384 Abort();
1385
1386 LOGF_INFO("Sync JNow %g %g -> %g %g", CurrentRA, CurrentDEC, ra, dec);
1387 char res[MAX_SYN_BUF] = {0};
1388 int bytesWritten, bytesRead;
1389
1390 if (isSimulation())
1391 {
1392 CurrentRA = ra;
1393 CurrentDEC = dec;
1394 return true;
1395 }
1396
1397 // Alt/Az sync mode
1398 if (MountCode >= 128)
1399 {
1400 INDI::IHorizontalCoordinates TargetAltAz { 0, 0 };
1402 INDI::EquatorialToHorizontal(&epochPos, &m_Location, ln_get_julian_from_sys(), &TargetAltAz);
1403 LOGF_DEBUG("Sync - ra: %g de: %g to az: %g alt: %g", ra, dec, TargetAltAz.azimuth, TargetAltAz.altitude);
1404 // Assemble the Reset Position command for Az axis
1405 int Az = (int)(TargetAltAz.azimuth * 16777216 / 360);
1406
1407 res[0] = 'P';
1408 res[1] = 4;
1409 res[2] = 16;
1410 res[3] = 4;
1411 *reinterpret_cast<unsigned char*>(&res[4]) = (unsigned char)(Az / 65536);
1412 Az -= (Az / 65536) * 65536;
1413 *reinterpret_cast<unsigned char*>(&res[5]) = (unsigned char)(Az / 256);
1414 Az -= (Az / 256) * 256;
1415 *reinterpret_cast<unsigned char*>(&res[6]) = (unsigned char)Az;
1416 res[7] = 0;
1417 tty_write(PortFD, res, 8, &bytesWritten);
1418 tty_read(PortFD, res, 1, 3, &bytesRead);
1419 // Assemble the Reset Position command for Alt axis
1420 int Alt = (int)(TargetAltAz.altitude * 16777216 / 360);
1421
1422 res[0] = 'P';
1423 res[1] = 4;
1424 res[2] = 17;
1425 res[3] = 4;
1426 *reinterpret_cast<unsigned char*>(&res[4]) = (unsigned char)(Alt / 65536);
1427 Alt -= (Alt / 65536) * 65536;
1428 *reinterpret_cast<unsigned char*>(&res[5]) = (unsigned char)(Alt / 256);
1429 Alt -= (Alt / 256) * 256;
1430 *reinterpret_cast<unsigned char*>(&res[6]) = (unsigned char)Alt;
1431 res[7] = 0;
1432 LOGF_DEBUG("CMD <%s>", res);
1433 tty_write(PortFD, res, 8, &bytesWritten);
1434
1435 tty_read(PortFD, res, 1, 2, &bytesRead);
1436 LOGF_DEBUG("CMD <%c>", res[0]);
1437 }
1438
1439 INDI::IEquatorialCoordinates epochPos { 0, 0 }, J2000Pos { 0, 0 };
1440
1441 epochPos.rightascension = ra;
1442 epochPos.declination = dec;
1443
1444 // Synscan accepts J2000 coordinates so we need to convert from JNow to J2000
1445 //ln_get_equ_prec2(&epochPos, ln_get_julian_from_sys(), JD2000, &J2000Pos);
1446 INDI::ObservedToJ2000(&epochPos, ln_get_julian_from_sys(), &J2000Pos);
1447
1448 // Pass the sync command to the handset
1449 int n1 = J2000Pos.rightascension * 0x1000000 / 24;
1450 int n2 = J2000Pos.declination * 0x1000000 / 360;
1451
1452 n1 = n1 << 8;
1453 n2 = n2 << 8;
1454 snprintf(res, MAX_SYN_BUF, "s%08X,%08X", n1, n2);
1455 memset(&res[18], 0, 1);
1456
1457 LOGF_DEBUG("CMD <%s>", res);
1458 tty_write(PortFD, res, 18, &bytesWritten);
1459
1460 tty_read(PortFD, res, 1, 60, &bytesRead);
1461 LOGF_DEBUG("RES <%c>", res[0]);
1462
1463 if (bytesRead != 1 || res[0] != '#')
1464 {
1465 LOG_DEBUG("Timeout waiting for scope to complete syncing.");
1466 return false;
1467 }
1468
1469 // Start tracking again
1470 if (IsTrackingBeforeSync)
1472
1473 return true;
1474}
1475
1476void SynscanLegacyDriver::UpdateMountInformation(bool inform_client)
1477{
1478 bool BasicMountInfoHasChanged = false;
1479 std::string MountCodeStr = std::to_string(MountCode);
1480
1481 if (std::string(BasicMountInfoT[MI_FW_VERSION].text) != HandsetFwVersion)
1482 {
1483 IUSaveText(&BasicMountInfoT[MI_FW_VERSION], HandsetFwVersion.c_str());
1484 BasicMountInfoHasChanged = true;
1485 }
1486 if (std::string(BasicMountInfoT[MI_MOUNT_CODE].text) != MountCodeStr)
1487 {
1488 IUSaveText(&BasicMountInfoT[MI_MOUNT_CODE], MountCodeStr.c_str());
1489 BasicMountInfoHasChanged = true;
1490 }
1491
1492 if (std::string(BasicMountInfoT[MI_ALIGN_STATUS].text) != AlignmentStatus)
1493 {
1494 IUSaveText(&BasicMountInfoT[MI_ALIGN_STATUS], AlignmentStatus.c_str());
1495 BasicMountInfoHasChanged = true;
1496 }
1497 if (std::string(BasicMountInfoT[MI_GOTO_STATUS].text) != GotoStatus)
1498 {
1499 IUSaveText(&BasicMountInfoT[MI_GOTO_STATUS], GotoStatus.c_str());
1500 BasicMountInfoHasChanged = true;
1501 }
1502 if (std::string(BasicMountInfoT[MI_POINT_STATUS].text) != PointingStatus)
1503 {
1504 IUSaveText(&BasicMountInfoT[MI_POINT_STATUS], PointingStatus.c_str());
1505 BasicMountInfoHasChanged = true;
1506 }
1507 if (std::string(BasicMountInfoT[MI_TRACK_MODE].text) != TrackingMode)
1508 {
1509 IUSaveText(&BasicMountInfoT[MI_TRACK_MODE], TrackingMode.c_str());
1510 BasicMountInfoHasChanged = true;
1511 }
1512
1513 if (BasicMountInfoHasChanged && inform_client)
1514 IDSetText(&BasicMountInfoTP, nullptr);
1515}
1516
1517void SynscanLegacyDriver::MountSim()
1518{
1519 static struct timeval ltv;
1520 struct timeval tv;
1521 double dt, da, dx;
1522 int nlocked;
1523
1524 /* update elapsed time since last poll, don't presume exactly POLLMS */
1525 gettimeofday(&tv, nullptr);
1526
1527 if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
1528 ltv = tv;
1529
1530 dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
1531 ltv = tv;
1532 double currentSlewRate = SLEW_RATE[SlewRateSP.findOnSwitchIndex()] * TRACKRATE_SIDEREAL / 3600.0;
1533 da = currentSlewRate * dt;
1534
1535 /* Process per current state. We check the state of EQUATORIAL_COORDS and act accordingly */
1536 switch (TrackState)
1537 {
1538 case SCOPE_IDLE:
1539 CurrentRA += (TrackRateNP[AXIS_RA].getValue() / 3600.0 * dt) / 15.0;
1541 break;
1542
1543 case SCOPE_TRACKING:
1544 break;
1545
1546 case SCOPE_SLEWING:
1547 case SCOPE_PARKING:
1548 /* slewing - nail it when both within one pulse @ SLEWRATE */
1549 nlocked = 0;
1550
1551 dx = TargetRA - CurrentRA;
1552
1553 // Take shortest path
1554 if (fabs(dx) > 12)
1555 dx *= -1;
1556
1557 if (fabs(dx) <= da)
1558 {
1560 nlocked++;
1561 }
1562 else if (dx > 0)
1563 CurrentRA += da / 15.;
1564 else
1565 CurrentRA -= da / 15.;
1566
1567 if (CurrentRA < 0)
1568 CurrentRA += 24;
1569 else if (CurrentRA > 24)
1570 CurrentRA -= 24;
1571
1572 dx = TargetDEC - CurrentDEC;
1573 if (fabs(dx) <= da)
1574 {
1576 nlocked++;
1577 }
1578 else if (dx > 0)
1579 CurrentDEC += da;
1580 else
1581 CurrentDEC -= da;
1582
1583 if (nlocked == 2)
1584 {
1587 else
1589 }
1590
1591 break;
1592
1593 default:
1594 break;
1595 }
1596
1598}
bool isConnected() const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
Connection::Interface * getActiveConnection()
virtual bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void setTelescopeConnection(const uint8_t &value)
setTelescopeConnection Set telescope connection mode. Child class should call this in the constructor...
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
Connection::TCP * tcpConnection
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
IGeographicCoordinates m_Location
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual const char * getDefaultName() override
int HexStrToInteger(const std::string &str)
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool Park() override
Park the telescope to its home position.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch SlewRateSP
INDI::PropertyText TimeTP
INDI::PropertyNumber LocationNP
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RO
Definition indiapi.h:182
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
#define MAXINDINAME
Definition indiapi.h:189
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_EAST
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_SOUTH
@ DIRECTION_NORTH
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition indicom.c:418
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition indicom.c:1311
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
Definition indicom.c:1341
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.
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sidereal time given longitude and system clock.
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 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
#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 IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#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 TRACKRATE_SIDEREAL
Definition indimacros.h:39
#define getDeviceName
void J2000toObserved(IEquatorialCoordinates *J2000pos, double jd, IEquatorialCoordinates *observed)
*J2000toObserved converts catalogue to observed
Definition libastro.cpp:81
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
void ObservedToJ2000(IEquatorialCoordinates *observed, double jd, IEquatorialCoordinates *J2000pos)
ObservedToJ2000 converts an observed position to a J2000 catalogue position removes aberration,...
Definition libastro.cpp:51
*brief create JSON pointer *sa reference_tokens const string_t & a
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
uint16_t type
Definition pwc-ioctl.h:0
uint8_t cmd[4]
Definition pwc-ioctl.h:2
#define SYNSCAN_SLEW_RATES