Instrument Neutral Distributed Interface INDI 2.2.5
indidome.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 INDI Dome Base Class
3 Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
4
5 The code used calculate dome target AZ and ZD is written by Ferran Casarramona, and adapted from code from Markus Wildi.
6 The transformations are based on the paper Matrix Method for Coordinates Transformation written by Toshimi Taki (http://www.asahi-net.or.jp/~zs3t-tk).
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License version 2 as published by the Free Software Foundation.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*******************************************************************************/
22
23#include "indidome.h"
24
25#include "indicom.h"
26#include "indicontroller.h"
27#include "inditimer.h"
30
31#include <libnova/julian_day.h>
32#include <libnova/sidereal_time.h>
33#include <libnova/transform.h>
34
35#include <cerrno>
36#include <cmath>
37#include <cstring>
38#include <wordexp.h>
39#include <pwd.h>
40#include <unistd.h>
41#include <limits>
42
43#define DOME_SLAVING_TAB "Slaving"
44#define DOME_COORD_THRESHOLD \
45 0.1 /* Only send debug messages if the differences between old and new values of Az/Alt excceds this value */
46
47namespace INDI
48{
49
53Dome::Dome() : ParkDataFileName(GetHomeDirectory() + "/.indi/ParkData.xml")
54{
55 controller = new Controller(this);
56
57 controller->setButtonCallback(buttonHelper);
58
60 mountEquatorialCoords.declination = mountEquatorialCoords.rightascension = -1;
62
63 capability = 0;
64
67
69 ParkdataXmlRoot = nullptr;
70
71 m_MountUpdateTimer.callOnTimeout(std::bind(&Dome::UpdateMountCoords, this));
72
73 m_ShutterParkTimer.setInterval(SHUTTER_PARK_POLL_INTERVAL);
74 m_ShutterParkTimer.callOnTimeout(std::bind(&Dome::checkShutterParkSequence, this));
75}
76
81{
82 delXMLEle(ParkdataXmlRoot);
83
84 delete controller;
85 delete serialConnection;
86 delete tcpConnection;
87}
88
92std::string Dome::GetHomeDirectory() const
93{
94 // Check first the HOME environmental variable
95 const char * HomeDir = getenv("HOME");
96
97 // ...otherwise get the home directory of the current user.
98 if (!HomeDir)
99 {
100 HomeDir = getpwuid(getuid())->pw_dir;
101 }
102 return (HomeDir ? std::string(HomeDir) : "");
103}
104
109{
110 DefaultDevice::initProperties(); // let the base class flesh in what it wants
111
112 // Presets
113 PresetNP[0].fill("Preset 1", "", "%6.2f", 0, 360.0, 1.0, 0);
114 PresetNP[1].fill("Preset 2", "", "%6.2f", 0, 360.0, 1.0, 0);
115 PresetNP[2].fill("Preset 3", "", "%6.2f", 0, 360.0, 1.0, 0);
116 PresetNP.fill(getDeviceName(), "Presets", "", "Presets", IP_RW, 0, IPS_IDLE);
117
118 //Preset GOTO
119 PresetGotoSP[0].fill("Preset 1", "", ISS_OFF);
120 PresetGotoSP[1].fill("Preset 2", "", ISS_OFF);
121 PresetGotoSP[2].fill("Preset 3", "", ISS_OFF);
122 PresetGotoSP.fill(getDeviceName(), "Goto", "", "Presets", IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
123
124 // Active Devices
125 ActiveDeviceTP[ACTIVE_MOUNT].fill("ACTIVE_TELESCOPE", "Telescope", "Telescope Simulator");
126 ActiveDeviceTP[ACTIVE_INPUT].fill("ACTIVE_INPUT", "Input", "");
127 ActiveDeviceTP[ACTIVE_OUTPUT].fill("ACTIVE_OUTPUT", "Output", "");
128 ActiveDeviceTP.fill(getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);
129 if (ActiveDeviceTP.load())
131
132 // Use locking if telescope is unparked
133 // @INDI_STANDARD_PROPERTY@
134 MountPolicySP[MOUNT_IGNORED].fill("MOUNT_IGNORED", "Mount ignored", ISS_ON);
135 MountPolicySP[MOUNT_LOCKS].fill("MOUNT_LOCKS", "Mount locks", ISS_OFF);
136 MountPolicySP.fill(getDeviceName(), "MOUNT_POLICY", "Mount Policy", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
137 MountPolicySP.load();
138
139 // Shutter Policy
140 // @INDI_STANDARD_PROPERTY@
141 ShutterParkPolicySP[SHUTTER_CLOSE_ON_PARK].fill("SHUTTER_CLOSE_ON_PARK", "Close On Park", ISS_OFF);
142 ShutterParkPolicySP[SHUTTER_OPEN_ON_UNPARK].fill("SHUTTER_OPEN_ON_UNPARK", "Open On UnPark", ISS_OFF);
143 ShutterParkPolicySP.fill(getDeviceName(), "DOME_SHUTTER_PARK_POLICY", "Shutter", OPTIONS_TAB, IP_RW, ISR_NOFMANY, 60,
144 IPS_IDLE);
145 ShutterParkPolicySP.load();
146
147 // Measurements
148 // @INDI_STANDARD_PROPERTY@
149 DomeMeasurementsNP[DM_DOME_RADIUS].fill("DM_DOME_RADIUS", "Radius (m)", "%6.2f", 0.0, 50.0, 1.0, 0.0);
150 DomeMeasurementsNP[DM_SHUTTER_WIDTH].fill("DM_SHUTTER_WIDTH", "Shutter width (m)", "%6.2f", 0.0, 10.0, 1.0, 0.0);
151 DomeMeasurementsNP[DM_NORTH_DISPLACEMENT].fill("DM_NORTH_DISPLACEMENT", "N displacement (m)", "%6.2f", -10.0, 10.0, 1.0,
152 0.0);
153 DomeMeasurementsNP[DM_EAST_DISPLACEMENT].fill("DM_EAST_DISPLACEMENT", "E displacement (m)", "%6.2f", -10.0, 10.0, 1.0, 0.0);
154 DomeMeasurementsNP[DM_UP_DISPLACEMENT].fill("DM_UP_DISPLACEMENT", "Up displacement (m)", "%6.2f", -10, 10.0, 1.0, 0.0);
155 DomeMeasurementsNP[DM_OTA_OFFSET].fill("DM_OTA_OFFSET", "OTA offset (m)", "%6.2f", -10.0, 10.0, 1.0, 0.0);
156 DomeMeasurementsNP.fill(getDeviceName(), "DOME_MEASUREMENTS", "Measurements", DOME_SLAVING_TAB, IP_RW, 60, IPS_OK);
157 DomeMeasurementsNP.load();
158
159 // @INDI_STANDARD_PROPERTY@
160 OTASideSP[DM_OTA_SIDE_EAST].fill("DM_OTA_SIDE_EAST", "East", ISS_OFF);
161 OTASideSP[DM_OTA_SIDE_WEST].fill("DM_OTA_SIDE_WEST", "West", ISS_OFF);
162 OTASideSP[DM_OTA_SIDE_MOUNT].fill("DM_OTA_SIDE_MOUNT", "Mount", ISS_ON);
163 OTASideSP[DM_OTA_SIDE_HA].fill("DM_OTA_SIDE_HA", "Hour Angle", ISS_OFF);
164 OTASideSP[DM_OTA_SIDE_IGNORE].fill("DM_OTA_SIDE_IGNORE", "Ignore", ISS_OFF);
165 OTASideSP.fill(getDeviceName(), "DM_OTA_SIDE", "Meridian side", DOME_SLAVING_TAB, IP_RW, ISR_ATMOST1, 60, IPS_OK);
166
167 // @INDI_STANDARD_PROPERTY@
168 DomeAutoSyncSP[INDI_ENABLED].fill("DOME_AUTOSYNC_ENABLE", "Enable", ISS_OFF);
169 DomeAutoSyncSP[INDI_DISABLED].fill("DOME_AUTOSYNC_DISABLE", "Disable", ISS_ON);
170 DomeAutoSyncSP.fill(getDeviceName(), "DOME_AUTOSYNC", "Slaving", DOME_SLAVING_TAB, IP_RW, ISR_1OFMANY, 60, IPS_OK);
171
172 // @INDI_STANDARD_PROPERTY@
173 DomeSpeedNP[0].fill("DOME_SPEED_VALUE", "RPM", "%6.2f", 0.0, 10, 0.1, 1.0);
174 DomeSpeedNP.fill(getDeviceName(), "DOME_SPEED", "Speed", MAIN_CONTROL_TAB, IP_RW, 60, IPS_OK);
175
176 // @INDI_STANDARD_PROPERTY@
177 DomeSyncNP[0].fill("DOME_SYNC_VALUE", "Az", "%.2f", 0.0, 360, 10, 0.0);
178 DomeSyncNP.fill(getDeviceName(), "DOME_SYNC", "Sync", MAIN_CONTROL_TAB, IP_RW, 60, IPS_OK);
179
180 // @INDI_STANDARD_PROPERTY@
181 DomeMotionSP[0].fill("DOME_CW", "Dome CW", ISS_OFF);
182 DomeMotionSP[1].fill("DOME_CCW", "Dome CCW", ISS_OFF);
183 DomeMotionSP.fill(getDeviceName(), "DOME_MOTION", "Motion", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_OK);
184
185 // Driver can define those to clients if there is support
186 // @INDI_STANDARD_PROPERTY@
187 DomeAbsPosNP[0].fill("DOME_ABSOLUTE_POSITION", "Degrees", "%6.2f", 0.0, 360.0, 1.0, 0.0);
188 DomeAbsPosNP.fill(getDeviceName(), "ABS_DOME_POSITION", "Absolute Position", MAIN_CONTROL_TAB, IP_RW, 60, IPS_OK);
189
190 // @INDI_STANDARD_PROPERTY@
191 DomeRelPosNP[0].fill("DOME_RELATIVE_POSITION", "Degrees", "%6.2f", -180, 180.0, 10.0, 0.0);
192 DomeRelPosNP.fill(getDeviceName(), "REL_DOME_POSITION", "Relative Position", MAIN_CONTROL_TAB, IP_RW, 60, IPS_OK);
193
194 // @INDI_STANDARD_PROPERTY@
195 AbortSP[0].fill("ABORT", "Abort", ISS_OFF);
196 AbortSP.fill(getDeviceName(), "DOME_ABORT_MOTION", "Abort Motion", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
197
198 // @INDI_STANDARD_PROPERTY@
199 DomeParamNP[0].fill("AUTOSYNC_THRESHOLD", "Autosync threshold (deg)", "%6.2f", 0.0, 360.0, 1.0, 0.5);
200 DomeParamNP.fill(getDeviceName(), "DOME_PARAMS", "Params", DOME_SLAVING_TAB, IP_RW, 60, IPS_OK);
201 DomeParamNP.load();
202
203 // @INDI_STANDARD_PROPERTY@
204 ParkSP[0].fill("PARK", "Park(ed)", ISS_OFF);
205 ParkSP[1].fill("UNPARK", "UnPark(ed)", ISS_OFF);
206 ParkSP.fill(getDeviceName(), "DOME_PARK", "Parking", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_OK);
207
208 // Backlash Compensation
209 // @INDI_STANDARD_PROPERTY@
210 DomeBacklashSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
211 DomeBacklashSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
212 DomeBacklashSP.fill(getDeviceName(), "DOME_BACKLASH_TOGGLE", "Backlash", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
213
214 // Backlash Compensation Value
215 // @INDI_STANDARD_PROPERTY@
216 DomeBacklashNP[0].fill("DOME_BACKLASH_VALUE", "Steps", "%.f", 0, 1e6, 100, 0);
217 DomeBacklashNP.fill(getDeviceName(), "DOME_BACKLASH_STEPS", "Backlash", OPTIONS_TAB, IP_RW, 60, IPS_OK);
218 DomeBacklashNP.load();
219
220 // @INDI_STANDARD_PROPERTY@
221 DomeShutterSP[0].fill("SHUTTER_OPEN", "Open", ISS_OFF);
222 DomeShutterSP[1].fill("SHUTTER_CLOSE", "Close", ISS_ON);
223 DomeShutterSP.fill(getDeviceName(), "DOME_SHUTTER", "Shutter", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_OK);
224
225 // @INDI_STANDARD_PROPERTY@
226 ParkOptionSP[0].fill("PARK_CURRENT", "Current", ISS_OFF);
227 ParkOptionSP[1].fill("PARK_DEFAULT", "Default", ISS_OFF);
228 ParkOptionSP[2].fill("PARK_WRITE_DATA", "Write Data", ISS_OFF);
229 ParkOptionSP.fill(getDeviceName(), "DOME_PARK_OPTION", "Park Options", SITE_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
230
232
233 controller->mapController("Dome CW", "CW/Open", Controller::CONTROLLER_BUTTON, "BUTTON_1");
234 controller->mapController("Dome CCW", "CCW/Close", Controller::CONTROLLER_BUTTON, "BUTTON_2");
235
236 controller->initProperties();
237
238 const auto scope = ActiveDeviceTP[0].getText();
239 IDSnoopDevice(scope, "EQUATORIAL_EOD_COORD");
240 IDSnoopDevice(scope, "GEOGRAPHIC_COORD");
241 IDSnoopDevice(scope, "TELESCOPE_PARK");
242 if (CanAbsMove())
243 IDSnoopDevice(scope, "TELESCOPE_PIER_SIDE");
244
246
247 if (domeConnection & CONNECTION_SERIAL)
248 {
250 serialConnection->registerHandshake([&]()
251 {
252 return callHandshake();
253 });
255 }
256
257 if (domeConnection & CONNECTION_TCP)
258 {
259 tcpConnection = new Connection::TCP(this);
260 tcpConnection->registerHandshake([&]()
261 {
262 return callHandshake();
263 });
265 }
266
267 return true;
268}
269
273void Dome::ISGetProperties(const char * dev)
274{
276
279
280 controller->ISGetProperties(dev);
281 return;
282}
283
288{
289 if (isConnected())
290 {
291 if (HasShutter())
292 {
295 }
296
297 // Now we add our Dome specific stuff
299
300 if (HasVariableSpeed())
301 {
303 }
304 if (CanRelMove())
306 if (CanAbsMove())
308 if (CanAbort())
310 if (CanAbsMove())
311 {
314
319 }
320 if (CanSync())
322
323 if (CanPark())
324 {
326 if (parkDataType != PARK_NONE)
327 {
330 }
331 }
332
333 if (HasBacklash())
334 {
337 }
338 }
339 else
340 {
341 cancelShutterParkSequence();
342
343 if (HasShutter())
344 {
347 }
348
350
351 if (HasVariableSpeed())
352 {
354 }
355 if (CanRelMove())
357 if (CanAbsMove())
359 if (CanAbort())
361 if (CanAbsMove())
362 {
365
370 }
371
372 if (CanSync())
374
375 if (CanPark())
376 {
378 if (parkDataType != PARK_NONE)
379 {
382 }
383 }
384
385 if (HasBacklash())
386 {
389 }
390 }
391
392 controller->updateProperties();
393 return true;
394}
395
399bool Dome::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n)
400{
401 // first check if it's for our device
402 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
403 {
404 if (PresetNP.isNameMatch(name))
405 {
406 PresetNP.update(values, names, n);
407 PresetNP.setState(IPS_OK);
408 PresetNP.apply(nullptr);
410 return true;
411 }
412 // Dome Sync
413 else if (DomeSyncNP.isNameMatch(name))
414 {
415 if (Sync(values[0]))
416 {
417 DomeSyncNP.update(values, names, n);
418 DomeSyncNP.setState(IPS_OK);
419 DomeAbsPosNP[0].setValue(values[0]);
420 DomeAbsPosNP.apply();
421 }
422 else
423 {
424 DomeSyncNP.setState(IPS_ALERT);
425 }
426
427 DomeSyncNP.apply();
428 return true;
429 }
430 else if (DomeParamNP.isNameMatch(name))
431 {
432 DomeParamNP.update(values, names, n);
433 DomeParamNP.setState(IPS_OK);
434 DomeParamNP.apply();
435 // If slaving is enabled, report the differential threshold update.
436 if (DomeAutoSyncSP[INDI_ENABLED].getState() == ISS_ON)
437 LOGF_INFO("Dome slaving differential threshold updated to %.2f degrees.", DomeParamNP[0].getValue());
439 return true;
440 }
441 else if (DomeSpeedNP.isNameMatch(name))
442 {
443 auto newSpeed = values[0];
444 Dome::SetSpeed(newSpeed);
445 return true;
446 }
447 else if (DomeAbsPosNP.isNameMatch(name))
448 {
449 auto newPos = values[0];
450 Dome::MoveAbs(newPos);
451 return true;
452 }
453 else if (DomeRelPosNP.isNameMatch(name))
454 {
455 auto newPos = values[0];
456 Dome::MoveRel(newPos);
457 return true;
458 }
459 else if (DomeMeasurementsNP.isNameMatch(name))
460 {
461 DomeMeasurementsNP.update(values, names, n);
462 DomeMeasurementsNP.setState(IPS_OK);
463 DomeMeasurementsNP.apply();
465 return true;
466 }
467 else if (ParkPositionNP.isNameMatch(name))
468 {
469 ParkPositionNP.update(values, names, n);
470 ParkPositionNP.setState(IPS_OK);
471 Axis1ParkPosition = ParkPositionNP[AXIS_RA].getValue();
472 ParkPositionNP.apply();
473 return true;
474 }
476 // Backlash value
478 else if (DomeBacklashNP.isNameMatch(name))
479 {
480 if (DomeBacklashSP[INDI_ENABLED].getState() != ISS_ON)
481 {
482 DomeBacklashNP.setState(IPS_IDLE);
483 LOG_WARN("Dome backlash must be enabled first.");
484 }
485 else
486 {
487 auto steps = static_cast<uint32_t>(values[0]);
488 if (SetBacklash(steps))
489 {
490 DomeBacklashNP[0].setValue(values[0]);
491 DomeBacklashNP.setState(IPS_OK);
492 }
493 else
494 DomeBacklashNP.setState(IPS_ALERT);
495 }
496 DomeBacklashNP.apply();
498 return true;
499 }
500 }
501
502 return DefaultDevice::ISNewNumber(dev, name, values, names, n);
503}
504
508bool Dome::ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n)
509{
510 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
511 {
513 // GOTO Presets
515 if (PresetGotoSP.isNameMatch(name))
516 {
518 {
519 LOG_ERROR("Please unpark before issuing any motion commands.");
520 PresetGotoSP.setState(IPS_ALERT);
521 PresetGotoSP.apply();
522 return false;
523 }
524
525 PresetGotoSP.update(states, names, n);
526 auto index = PresetGotoSP.findOnSwitchIndex();
527 IPState rc = Dome::MoveAbs(PresetNP[index].getValue());
528 if (rc == IPS_OK || rc == IPS_BUSY)
529 {
530 PresetGotoSP.setState(IPS_OK);
531 LOGF_INFO("Moving to Preset %d (%.2f degrees).", index + 1, PresetNP[index].getValue());
532 PresetGotoSP.apply();
533 return true;
534 }
535
536 PresetGotoSP.setState(IPS_ALERT);
537 PresetGotoSP.apply();
538 return false;
539 }
541 // Dome Auto Sync
543 else if (DomeAutoSyncSP.isNameMatch(name))
544 {
545 DomeAutoSyncSP.update(states, names, n);
546 DomeAutoSyncSP.setState(IPS_OK);
547
548 if (DomeAutoSyncSP[0].getState() == ISS_ON)
549 {
550 LOGF_WARN("Dome will now be synced to mount azimuth position if the differential threshold exceeds %.2f degrees.",
551 DomeParamNP[0].getValue());
552 DomeAutoSyncSP.apply();
554 m_MountUpdateTimer.start(HORZ_UPDATE_TIMER);
555 }
556 else
557 {
558 LOG_WARN("Dome is no longer synced to mount azimuth position.");
559 DomeAutoSyncSP.apply();
560 m_MountUpdateTimer.stop();
561 if (DomeAbsPosNP.getState() == IPS_BUSY || DomeRelPosNP.getState() == IPS_BUSY)
562 Dome::Abort();
563 }
564
565 return true;
566 }
568 // OTA Side
570 else if (OTASideSP.isNameMatch(name))
571 {
572 OTASideSP.update(states, names, n);
573 OTASideSP.setState(IPS_OK);
574
575 if (OTASideSP[DM_OTA_SIDE_EAST].getState() == ISS_ON)
576 {
577 LOG_WARN("Dome shall be synced assuming OTA situated east of the pier");
578 }
579 else if (OTASideSP[DM_OTA_SIDE_WEST].getState() == ISS_ON)
580 {
581 LOG_WARN("Dome shall be synced assuming OTA situated west of the pier");
582 }
583 else if (OTASideSP[DM_OTA_SIDE_MOUNT].getState() == ISS_ON)
584 {
585 LOG_WARN("Dome shall be synced from pier side as reported by the mount.");
586 }
587 else if (OTASideSP[DM_OTA_SIDE_HA].getState() == ISS_ON)
588 {
589 LOG_WARN("Dome shall be synced for OTA pier side derived from Hour Angle.");
590 }
591 else if (OTASideSP[DM_OTA_SIDE_IGNORE].getState() == ISS_ON)
592 {
593 LOG_WARN("Dome shall be synced by ignoring pier side as in a fork mount.");
594 }
595
597 OTASideSP.apply();
599 return true;
600 }
602 // Dome Motion
604 else if (DomeMotionSP.isNameMatch(name))
605 {
606 // Check if any switch is ON
607 for (int i = 0; i < n; i++)
608 {
609 if (states[i] == ISS_ON)
610 {
611 if (DomeMotionSP[DOME_CW].isNameMatch(names[i]))
613 else
615
616 return true;
617 }
618 }
619
620 // All switches are off, so let's turn off last motion
621 auto current_direction = DomeMotionSP.findOnSwitchIndex();
622 // Shouldn't happen
623 if (current_direction < 0)
624 {
625 DomeMotionSP.setState(IPS_IDLE);
626 DomeMotionSP.apply();
627 return false;
628 }
629
630 Dome::Move(static_cast<DomeDirection>(current_direction), MOTION_STOP);
631
632 return true;
633 }
635 // Abort Motion
637 else if (AbortSP.isNameMatch(name))
638 {
639 Dome::Abort();
640 return true;
641 }
643 // Shutter
645 else if (DomeShutterSP.isNameMatch(name))
646 {
647 // Check if any switch is ON
648 for (int i = 0; i < n; i++)
649 {
650 if (states[i] == ISS_ON)
651 {
652 auto operation = DomeShutterSP[SHUTTER_OPEN].isNameMatch(names[i]) ? SHUTTER_OPEN : SHUTTER_CLOSE;
653
654 // A manual shutter command that goes against an ongoing park or unpark wins: the park
655 // or unpark then completes on the dome motion alone instead of waiting for the shutter.
656 if (m_ShutterParkSequence != SHUTTER_SEQUENCE_NONE && !m_ShutterParkShutterDone)
657 {
658 auto sequenceOperation = (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK) ? SHUTTER_CLOSE : SHUTTER_OPEN;
659 if (operation != sequenceOperation)
660 {
661 LOGF_WARN("Manual shutter command overrides the shutter park policy. Dome %s will not wait for the shutter.",
662 m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK ? "parking" : "unparking");
663 m_ShutterParkShutterDone = true;
664 m_ShutterParkShutterFailed = false;
665 }
666 }
667
668 auto rc = Dome::ControlShutter(operation);
669 checkShutterParkSequence();
670 return (rc != IPS_ALERT);
671 }
672 }
673 }
675 // Parking Switch
677 else if (ParkSP.isNameMatch(name))
678 {
679 // Check if any switch is ON
680 for (int i = 0; i < n; i++)
681 {
682 if (states[i] == ISS_ON)
683 {
684 if (ParkSP[0].isNameMatch(names[i]))
685 {
687 return false;
688
689 return (Dome::Park() != IPS_ALERT);
690 }
691 else
692 {
694 return false;
695
696 return (Dome::UnPark() != IPS_ALERT);
697 }
698 }
699 }
700 }
702 // Parking Option
704 else if (ParkOptionSP.isNameMatch(name))
705 {
706 ParkOptionSP.update(states, names, n);
707 auto sp = ParkOptionSP.findOnSwitch();
708 if (!sp)
709 return false;
710
711 bool rc = false;
712
713 ParkOptionSP.reset();
714
715 if (sp->isNameMatch("PARK_CURRENT"))
716 {
717 rc = SetCurrentPark();
718 }
719 else if (sp->isNameMatch("PARK_DEFAULT"))
720 {
721 rc = SetDefaultPark();
722 }
723 else if (sp->isNameMatch( "PARK_WRITE_DATA"))
724 {
725 rc = WriteParkData();
726 if (rc)
727 LOG_INFO("Saved Park Status/Position.");
728 else
729 LOG_WARN( "Can not save Park Status/Position.");
730 }
731
732 ParkOptionSP.setState(rc ? IPS_OK : IPS_ALERT);
733 ParkOptionSP.apply();
734 return true;
735 }
737 // Auto Park
739#if 0
740 else if (!strcmp(name, AutoParkSP.name))
741 {
742 IUUpdateSwitch(&AutoParkSP, states, names, n);
743
744 AutoParkSP.s = IPS_OK;
745
746 if (AutoParkS[0].s == ISS_ON)
747 LOG_WARN( "Warning: Auto park is enabled. If weather conditions are in the "
748 "danger zone, the dome will be automatically parked. Only enable this "
749 "option is parking the dome at any time will not cause damage to any "
750 "equipment.");
751 else
752 DEBUG(Logger::DBG_SESSION, "Auto park is disabled.");
753
754 IDSetSwitch(&AutoParkSP, nullptr);
755
756 return true;
757 }
758#endif
760 // Telescope Parking Policy
762 else if (MountPolicySP.isNameMatch(name))
763 {
764 MountPolicySP.update(states, names, n);
765 MountPolicySP.setState(IPS_OK);
766 if (MountPolicySP[MOUNT_IGNORED].getState() == ISS_ON)
767 LOG_INFO("Mount Policy set to: Mount ignored. Dome can park regardless of mount parking state.");
768 else
769 LOG_WARN("Mount Policy set to: Mount locks. This prevents the dome from parking when mount is unparked.");
770 MountPolicySP.apply();
772 triggerSnoop(ActiveDeviceTP[0].getText(), "TELESCOPE_PARK");
773 return true;
774 }
776 // Shutter Parking Policy
778 else if (ShutterParkPolicySP.isNameMatch(name))
779 {
780 ShutterParkPolicySP.update(states, names, n);
781 ShutterParkPolicySP.setState(IPS_OK);
782 ShutterParkPolicySP.apply();
784 return true;
785 }
787 // Backlash enable/disable
789 else if (DomeBacklashSP.isNameMatch(name))
790 {
791 auto prevIndex = DomeBacklashSP.findOnSwitchIndex();
792 DomeBacklashSP.update(states, names, n);
793 auto enabled = DomeBacklashSP.findOnSwitchIndex() == INDI_ENABLED;
794
795 if (SetBacklashEnabled(enabled))
796 {
797 DomeBacklashSP.update(states, names, n);
798 DomeBacklashSP.setState(IPS_OK);
799 LOGF_INFO("Dome backlash is %s.", (enabled ? "enabled" : "disabled"));
800 }
801 else
802 {
803 DomeBacklashSP.reset();
804 DomeBacklashSP[prevIndex].setState(ISS_ON);
805 DomeBacklashSP.setState(IPS_ALERT);
806 LOG_ERROR("Failed to set trigger Dome backlash.");
807 }
808
809 DomeBacklashSP.apply();
811 return true;
812 }
813 }
814
815 controller->ISNewSwitch(dev, name, states, names, n);
816
817 // Nobody has claimed this, so, ignore it
818 return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
819}
820
824bool Dome::ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n)
825{
826 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
827 {
828 if (ActiveDeviceTP.isNameMatch(name))
829 {
830 ActiveDeviceTP.setState(IPS_OK);
831 ActiveDeviceTP.update(texts, names, n);
832 ActiveDeviceTP.apply();
833
834 auto mount = ActiveDeviceTP[ACTIVE_MOUNT].getText();
835 IDSnoopDevice(mount, "EQUATORIAL_EOD_COORD");
836 IDSnoopDevice(mount, "TARGET_EOD_COORD");
837 IDSnoopDevice(mount, "GEOGRAPHIC_COORD");
838 IDSnoopDevice(mount, "TELESCOPE_PARK");
839 if (CanAbsMove())
840 IDSnoopDevice(mount, "TELESCOPE_PIER_SIDE");
841
844 return true;
845 }
846 }
847
848 controller->ISNewText(dev, name, texts, names, n);
849
850 return DefaultDevice::ISNewText(dev, name, texts, names, n);
851}
852
857{
858 XMLEle * ep = nullptr;
859 const char * propName = findXMLAttValu(root, "name");
860 auto deviceName = std::string(findXMLAttValu(root, "device"));
861
862 // Check TARGET
863 if (!strcmp("TARGET_EOD_COORD", propName) && deviceName == ActiveDeviceTP[ACTIVE_MOUNT].getText())
864 {
865 int rc_ra = -1, rc_de = -1;
866 double ra = std::numeric_limits<double>::quiet_NaN(), de = std::numeric_limits<double>::quiet_NaN();
867
868 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
869 {
870 const char * elemName = findXMLAttValu(ep, "name");
871
872 LOGF_DEBUG("Snooped Target RA-DEC: %s", pcdataXMLEle(ep));
873 if (!strcmp(elemName, "RA"))
874 rc_ra = f_scansexa(pcdataXMLEle(ep), &ra);
875 else if (!strcmp(elemName, "DEC"))
876 rc_de = f_scansexa(pcdataXMLEle(ep), &de);
877 }
878 // Dont start moving the dome till the mount has initialized all the variables
879 if (HaveRaDec && CanAbsMove())
880 {
881 if (rc_ra == 0 && rc_de == 0 && !std::isnan(ra) && !std::isnan(de))
882 {
883 // Ignore empty/uninitialized target coordinates (e.g. default RA=0, DEC=0 broadcast on startup
884 // before any actual GOTO has been commanded). Without this guard the dome would spuriously
885 // slew to the position corresponding to RA=0/DEC=0 and then have to correct itself once the
886 // real mount coordinates arrive, mirroring the same protection already present in the
887 // EQUATORIAL_EOD_COORD handler.
888 if (ra == 0 && de == 0)
889 return true;
890
891 // everything parsed ok, so lets start the dome to moving
892 // If this slew involves a meridian flip, then the slaving calcs will end up using
893 // the wrong OTA side. Lets set things up so our slaving code will calculate the side
894 // for the target slew instead of using mount pier side info
895 // and see if we can get there at the same time as the mount
896 // TODO: see what happens in a meridian flip with OTASide
897 mountEquatorialCoords.rightascension = ra;
898 mountEquatorialCoords.declination = de;
899 LOGF_DEBUG("Calling Update mount to anticipate goto target: %g - DEC: %g",
900 mountEquatorialCoords.rightascension, mountEquatorialCoords.declination);
901 UseHourAngle = true;
903 UseHourAngle = false;
904 }
905 }
906
907 return true;
908 }
909 // Check EOD
910 if (!strcmp("EQUATORIAL_EOD_COORD", propName) && deviceName == ActiveDeviceTP[ACTIVE_MOUNT].getText())
911 {
912 int rc_ra = -1, rc_de = -1;
913 double ra = std::numeric_limits<double>::quiet_NaN(), de = std::numeric_limits<double>::quiet_NaN();
914
915 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
916 {
917 const char * elemName = findXMLAttValu(ep, "name");
918
919 if (!strcmp(elemName, "RA"))
920 rc_ra = f_scansexa(pcdataXMLEle(ep), &ra);
921 else if (!strcmp(elemName, "DEC"))
922 rc_de = f_scansexa(pcdataXMLEle(ep), &de);
923 }
924
925 if (rc_ra == 0 && rc_de == 0 && !std::isnan(ra) && !std::isnan(de))
926 {
927 // Do not spam log
928 if (std::fabs(mountEquatorialCoords.rightascension - ra) > 0.01
929 || std::fabs(mountEquatorialCoords.declination - de) > 0.01)
930 {
931 // Ignore empty coords.
932 if (ra == 0 && de == 0)
933 return true;
934
935 char RAStr[64] = {0}, DEStr[64] = {0};
936 fs_sexa(RAStr, ra, 2, 3600);
937 fs_sexa(DEStr, de, 2, 3600);
938
939 LOGF_DEBUG("Snooped RA %s DEC %s", RAStr, DEStr);
940 }
941
942 mountEquatorialCoords.rightascension = ra;
943 mountEquatorialCoords.declination = de;
944 }
945
947 crackIPState(findXMLAttValu(root, "state"), &m_MountState);
948
949 // If the diff > 0.1 then the mount is in motion, so let's wait until it settles before moving the doom
950 if (fabs(mountEquatorialCoords.rightascension - prev_ra) > DOME_COORD_THRESHOLD ||
952 {
953 prev_ra = mountEquatorialCoords.rightascension;
954 prev_dec = mountEquatorialCoords.declination;
955 //LOGF_DEBUG("Snooped RA: %g - DEC: %g", mountEquatorialCoords.rightascension, mountEquatorialCoords.declination);
956 // a mount still initializing will emit 0 and 0 on the first go
957 // we dont want to process 0/0
958 if ((mountEquatorialCoords.rightascension != 0) || (mountEquatorialCoords.declination != 0))
959 HaveRaDec = true;
960 }
961 // else mount stable, i.e. tracking, so let's update mount coords and check if we need to move
962 else if (m_MountState == IPS_OK || m_MountState == IPS_IDLE)
964
965 return true;
966 }
967
968 // Check Geographic coords
969 if (!strcmp("GEOGRAPHIC_COORD", propName) && deviceName == ActiveDeviceTP[ACTIVE_MOUNT].getText())
970 {
971 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
972 {
973 const char * elemName = findXMLAttValu(ep, "name");
974 if (!strcmp(elemName, "LONG"))
975 {
976 double indiLong;
977 f_scansexa(pcdataXMLEle(ep), &indiLong);
978 if (indiLong > 180)
979 indiLong -= 360;
980 observer.longitude = indiLong;
981 HaveLatLong = true;
982 }
983 else if (!strcmp(elemName, "LAT"))
984 f_scansexa(pcdataXMLEle(ep), &(observer.latitude));
985 }
986
987 LOGF_DEBUG("Snooped LONG: %g - LAT: %g", observer.longitude, observer.latitude);
988
990
991 return true;
992 }
993
994 // Check Telescope Park status
995 if (!strcmp("TELESCOPE_PARK", propName) && deviceName == ActiveDeviceTP[ACTIVE_MOUNT].getText())
996 {
997 if (!strcmp(findXMLAttValu(root, "state"), "Ok"))
998 {
999 bool prevState = IsLocked;
1000 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
1001 {
1002 const char * elemName = findXMLAttValu(ep, "name");
1003
1004 if ((!strcmp(elemName, "PARK") && !strcmp(pcdataXMLEle(ep), "On")))
1005 IsMountParked = true;
1006 else if ((!strcmp(elemName, "UNPARK") && !strcmp(pcdataXMLEle(ep), "On")))
1007 IsMountParked = false;
1008
1009 if (IsLocked && !strcmp(elemName, "PARK") && !strcmp(pcdataXMLEle(ep), "On"))
1010 IsLocked = false;
1011 else if (!IsLocked && !strcmp(elemName, "UNPARK") && !strcmp(pcdataXMLEle(ep), "On"))
1012 IsLocked = true;
1013 }
1014 if (prevState != IsLocked && MountPolicySP[1].getState() == ISS_ON)
1015 LOGF_INFO("Telescope status changed. Lock is set to: %s", IsLocked ? "locked" : "unlocked");
1016 }
1017 return true;
1018 }
1019
1020 // Weather Status
1021 // JM 2020-07-16: Weather handling moved to Watchdog driver
1022#if 0
1023 if (!strcmp("WEATHER_STATUS", propName))
1024 {
1025 weatherState = IPS_ALERT;
1026 crackIPState(findXMLAttValu(root, "state"), &weatherState);
1027
1028 if (weatherState == IPS_ALERT)
1029 {
1030 if (CanPark())
1031 {
1032 if (!isParked())
1033 {
1034 if (AutoParkS[0].s == ISS_ON)
1035 {
1036 LOG_WARN("Weather conditions in the danger zone! Parking dome...");
1037 Dome::Park();
1038 }
1039 else
1040 {
1041 LOG_WARN("Weather conditions in the danger zone! AutoPark is disabled. Please park the dome!");
1042 }
1043 }
1044 }
1045 else
1046 LOG_WARN("Weather conditions in the danger zone! Close the dome immediately!");
1047
1048 return true;
1049 }
1050 }
1051#endif
1052 if (!strcmp("TELESCOPE_PIER_SIDE", propName) && deviceName == ActiveDeviceTP[ACTIVE_MOUNT].getText())
1053 {
1054 // crack the message
1055 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
1056 {
1057 const char * elemName = findXMLAttValu(ep, "name");
1058
1059 if (!strcmp(elemName, "PIER_EAST") && !strcmp(pcdataXMLEle(ep), "On"))
1060 mountOTASide = -1;
1061 else if (!strcmp(elemName, "PIER_WEST") && !strcmp(pcdataXMLEle(ep), "On"))
1062 mountOTASide = 1;
1063 }
1064
1065 return true;
1066 }
1067
1068 controller->ISSnoopDevice(root);
1069
1070 return DefaultDevice::ISSnoopDevice(root);
1071}
1072
1076bool Dome::SetBacklash(int32_t steps)
1077{
1078 INDI_UNUSED(steps);
1079 LOG_ERROR("Dome does not support backlash compensation.");
1080 return false;
1081}
1082
1087{
1088 // If disabled, set the Domeer backlash to zero.
1089 if (enabled)
1090 return SetBacklash(static_cast<int32_t>(DomeBacklashNP[0].getValue()));
1091 else
1092 return SetBacklash(0);
1093}
1094
1099{
1101
1102 ActiveDeviceTP.save(fp);
1103 MountPolicySP.save(fp);
1104 PresetNP.save(fp);
1105 DomeParamNP.save(fp);
1106 DomeMeasurementsNP.save(fp);
1107 DomeAutoSyncSP.save(fp);
1108 OTASideSP.save(fp);
1109
1110 if (HasBacklash())
1111 {
1112 DomeBacklashSP.save(fp);
1113 DomeBacklashNP.save(fp);
1114 }
1115
1116 if (HasShutter())
1117 {
1118 ShutterParkPolicySP.save(fp);
1119 }
1120
1121 controller->saveConfigItems(fp);
1122
1123 return true;
1124}
1125
1129void Dome::triggerSnoop(const char * driverName, const char * snoopedProp)
1130{
1131 LOGF_DEBUG("Active Snoop, driver: %s, property: %s", driverName, snoopedProp);
1132 IDSnoopDevice(driverName, snoopedProp);
1133}
1134
1139{
1140 return MountPolicySP[1].getState() == ISS_ON && IsLocked;
1141}
1142
1146void Dome::buttonHelper(const char * button_n, ISState state, void * context)
1147{
1148 static_cast<Dome *>(context)->processButton(button_n, state);
1149}
1150
1154void Dome::processButton(const char * button_n, ISState state)
1155{
1156 //ignore OFF
1157 if (state == ISS_OFF)
1158 return;
1159
1160 // Dome In
1161 if (!strcmp(button_n, "Dome CW"))
1162 {
1165 else
1167 }
1168 else if (!strcmp(button_n, "Dome CCW"))
1169 {
1172 else
1174 }
1175 else if (!strcmp(button_n, "Dome Abort"))
1176 {
1177 Dome::Abort();
1178 }
1179}
1180
1185{
1186 return m_MountState;
1187}
1188
1193{
1194 switch (value)
1195 {
1196 case SHUTTER_OPENED:
1197 DomeShutterSP.reset();
1199 DomeShutterSP.setState(IPS_OK);
1200 break;
1201
1202 case SHUTTER_CLOSED:
1203 DomeShutterSP.reset();
1205 DomeShutterSP.setState(IPS_OK);
1206 break;
1207
1208
1209 case SHUTTER_MOVING:
1210 DomeShutterSP.setState(IPS_BUSY);
1211 break;
1212
1213 case SHUTTER_ERROR:
1214 DomeShutterSP.setState(IPS_ALERT);
1215 LOG_WARN("Shutter failure.");
1216 break;
1217
1218 case SHUTTER_UNKNOWN:
1219 DomeShutterSP.reset();
1220 DomeShutterSP.setState(IPS_IDLE);
1221 LOG_WARN("Unknown shutter status.");
1222 break;
1223 }
1224
1225 DomeShutterSP.apply();
1226 m_ShutterState = value;
1227
1228 checkShutterParkSequence();
1229}
1230
1235{
1236 if (m_ShutterParkSequence != SHUTTER_SEQUENCE_NONE)
1237 {
1238 // Dome motion of the park/unpark is complete, but the shutter may still be moving.
1239 if ((value == DOME_PARKED && m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK) ||
1240 (value == DOME_UNPARKED && m_ShutterParkSequence == SHUTTER_SEQUENCE_UNPARK))
1241 {
1242 shutterParkMotionDone();
1243 return;
1244 }
1245 // Anything that ends the park/unpark otherwise invalidates the sequence.
1246 else if (value == DOME_PARKED || value == DOME_UNPARKED || value == DOME_ERROR || value == DOME_UNKNOWN)
1247 cancelShutterParkSequence();
1248 }
1249
1250 switch (value)
1251 {
1252 case DOME_IDLE:
1253 if (DomeMotionSP.getState() == IPS_BUSY)
1254 {
1255 DomeMotionSP.reset();
1256 DomeMotionSP.setState(IPS_IDLE);
1257 DomeMotionSP.apply();
1258 }
1259 if (DomeAbsPosNP.getState() == IPS_BUSY)
1260 {
1261 DomeAbsPosNP.setState(IPS_IDLE);
1262 DomeAbsPosNP.apply();
1263 }
1264 if (DomeRelPosNP.getState() == IPS_BUSY)
1265 {
1266 DomeRelPosNP.setState(IPS_IDLE);
1267 DomeRelPosNP.apply();
1268 }
1269 break;
1270
1271 case DOME_SYNCED:
1272 if (DomeMotionSP.getState() == IPS_BUSY)
1273 {
1274 DomeMotionSP.reset();
1275 DomeMotionSP.setState(IPS_OK);
1276 DomeMotionSP.apply();
1277 }
1278 if (DomeAbsPosNP.getState() == IPS_BUSY)
1279 {
1280 DomeAbsPosNP.setState(IPS_OK);
1281 DomeAbsPosNP.apply();
1282 }
1283 if (DomeRelPosNP.getState() == IPS_BUSY)
1284 {
1285 DomeRelPosNP.setState(IPS_OK);
1286 DomeRelPosNP.apply();
1287 }
1288 break;
1289
1290 case DOME_PARKED:
1291 if (DomeMotionSP.getState() == IPS_BUSY)
1292 {
1293 DomeMotionSP.reset();
1294 DomeMotionSP.setState(IPS_IDLE);
1295 DomeMotionSP.apply();
1296 }
1297 if (DomeAbsPosNP.getState() == IPS_BUSY)
1298 {
1299 DomeAbsPosNP.setState(IPS_IDLE);
1300 DomeAbsPosNP.apply();
1301 }
1302 if (DomeRelPosNP.getState() == IPS_BUSY)
1303 {
1304 DomeRelPosNP.setState(IPS_IDLE);
1305 DomeRelPosNP.apply();
1306 }
1307 ParkSP.reset();
1308 ParkSP.setState(IPS_OK);
1309 ParkSP[0].setState(ISS_ON);
1310 ParkSP.apply();
1311 IsParked = true;
1312 break;
1313
1314 case DOME_PARKING:
1315 ParkSP.reset();
1316 ParkSP.setState(IPS_BUSY);
1317 ParkSP[0].setState(ISS_ON);
1318 ParkSP.apply();
1319 break;
1320
1321 case DOME_UNPARKING:
1322 ParkSP.reset();
1323 ParkSP.setState(IPS_BUSY);
1324 ParkSP[1].setState(ISS_ON);
1325 ParkSP.apply();
1326 break;
1327
1328 case DOME_UNPARKED:
1329 ParkSP.reset();
1330 ParkSP.setState(IPS_OK);
1331 ParkSP[1].setState(ISS_ON);
1332 ParkSP.apply();
1333 IsParked = false;
1334 break;
1335
1336 case DOME_UNKNOWN:
1337 ParkSP.reset();
1338 ParkSP.setState(IPS_IDLE);
1339 IsParked = false;
1340 ParkSP.apply();
1341 break;
1342
1343 case DOME_ERROR:
1344 ParkSP.setState(IPS_ALERT);
1345 ParkSP.apply();
1346 break;
1347
1348 case DOME_MOVING:
1349 break;
1350 }
1351
1352 m_DomeState = value;
1353}
1354
1366bool Dome::GetTargetAz(double &Az, double &Alt, double &minAz, double &maxAz)
1367{
1368 point3D MountCenter, OptCenter, OptVector, DomeIntersect;
1369 double hourAngle;
1370 double mu1, mu2;
1371
1372 if (HaveLatLong == false)
1373 {
1374 triggerSnoop(ActiveDeviceTP[0].getText(), "GEOGRAPHIC_COORD");
1375 LOG_WARN( "Geographic coordinates are not yet defined, triggering snoop...");
1376 return false;
1377 }
1378
1379 double JD = ln_get_julian_from_sys();
1380 double LST = get_local_sidereal_time(observer.longitude);
1381 char lstStr[64], latStr[64], lonStr[64];
1382 fs_sexa(lstStr, LST, 2, 3600);
1383 fs_sexa(latStr, observer.latitude, 2, 3600);
1384 fs_sexa(lonStr, observer.longitude, 2, 3600);
1385
1386 // Condensed Initial Coords Log
1387 LOGF_DEBUG("Coords - LST: %s, Lat: %s, Lon: %s", lstStr, latStr, lonStr);
1388
1389 MountCenter.x = DomeMeasurementsNP[DM_EAST_DISPLACEMENT].getValue(); // Positive to East
1390 MountCenter.y = DomeMeasurementsNP[DM_NORTH_DISPLACEMENT].getValue(); // Positive to North
1391 MountCenter.z = DomeMeasurementsNP[DM_UP_DISPLACEMENT].getValue(); // Positive Up
1392
1393 // Get hour angle in hours
1394 hourAngle = get_local_hour_angle(LST, mountEquatorialCoords.rightascension);
1395 char raStr[64], decStr[64], haStr[64];
1396 fs_sexa(raStr, mountEquatorialCoords.rightascension, 2, 3600);
1397 fs_sexa(decStr, mountEquatorialCoords.declination, 2, 3600);
1398 fs_sexa(haStr, hourAngle, 2, 3600);
1399
1400 // To be sure mountHoriztonalCoords is up to date before potentially using it.
1402 char mountAzStr[64], mountAltStr[64];
1403 fs_sexa(mountAzStr, mountHoriztonalCoords.azimuth, 2, 3600);
1404 fs_sexa(mountAltStr, mountHoriztonalCoords.altitude, 2, 3600);
1405
1406 // Condensed Mount Coords Log
1407 LOGF_DEBUG("Mount - RA: %s, Dec: %s, HA: %s --> Az: %s, Alt: %s", raStr, decStr, haStr, mountAzStr, mountAltStr);
1408
1409 // Near the celestial pole, HA calculated from RA can be unreliable for determining pier side.
1410 // Use Azimuth to infer a more reliable effective HA for the OpticalCenter calculation.
1411 double effectiveHourAngle = hourAngle; // Use original HA by default
1412 const double poleThresholdDec = 89.0; // Degrees
1413 bool nearPole = std::abs(mountEquatorialCoords.declination) > poleThresholdDec;
1414
1415 // Define a threshold for azimuth deviation when near the pole
1416 const double POLE_AZIMUTH_DEVIATION_THRESHOLD = 30.0; // Degrees
1417
1418 // Lambda function to perform the core calculations
1419 auto performCalculations = [&](double currentEffectiveHourAngle)
1420 {
1421 // Side of the telescope with respect of the mount, 1: west, -1: east, 0: use the mid point
1422 int OTASide = 0;
1423 int otaSideSelection = OTASideSP.findOnSwitchIndex(); // Get selected mode
1424
1425 if (OTASideSP.getState() == IPS_OK)
1426 {
1427 if(otaSideSelection == DM_OTA_SIDE_HA || (UseHourAngle && otaSideSelection == DM_OTA_SIDE_MOUNT))
1428 {
1429 // Note if the telescope points West (HA > 0), OTA is at east of the pier, and vice-versa.
1430 double haForSide = nearPole ? currentEffectiveHourAngle : hourAngle; // Use effective HA near pole
1431
1432 // Determine side based on HA. HA=0 means pointing East (OTA West), HA=12 means pointing West (OTA East)
1433 if (haForSide > 0.1 && haForSide < 11.9) // Pointing West
1434 OTASide = -1; // OTA East
1435 else // Pointing East (HA near 0 or 12)
1436 OTASide = 1; // OTA West
1437 }
1438 else if(otaSideSelection == DM_OTA_SIDE_EAST)
1439 OTASide = -1;
1440 else if(otaSideSelection == DM_OTA_SIDE_WEST)
1441 OTASide = 1;
1442 else if(otaSideSelection == DM_OTA_SIDE_MOUNT)
1443 OTASide = mountOTASide;
1444 // DM_OTA_SIDE_IGNORE results in OTASide = 0
1445 }
1446
1447 double otaOffset = OTASide * DomeMeasurementsNP[DM_OTA_OFFSET].getValue();
1448 OpticalCenter(MountCenter, otaOffset, observer.latitude, currentEffectiveHourAngle, OptCenter);
1449
1450 // Get optical axis point. This and the previous form the optical axis line
1451 OpticalVector(mountHoriztonalCoords.azimuth, mountHoriztonalCoords.altitude, OptVector);
1452
1453 // Condensed Geometry Log
1454 char effHaStr[64];
1455 fs_sexa(effHaStr, currentEffectiveHourAngle, 2, 3600);
1456 LOGF_DEBUG("Geom - Mount(E:%.2f,N:%.2f,Up:%.2f) OTA(SideSel:%d, SideUsed:%d, Off:%.2f, EffHA:%s) -> OptCenter(X:%.3f,Y:%.3f,Z:%.3f) OptVec(X:%.3f,Y:%.3f,Z:%.3f)",
1457 MountCenter.x, MountCenter.y, MountCenter.z,
1458 otaSideSelection, OTASide, DomeMeasurementsNP[DM_OTA_OFFSET].getValue(), effHaStr,
1459 OptCenter.x, OptCenter.y, OptCenter.z,
1460 OptVector.x, OptVector.y, OptVector.z);
1461
1462 if (Intersection(OptCenter, OptVector, DomeMeasurementsNP[DM_DOME_RADIUS].getValue(), mu1, mu2))
1463 {
1464 // If telescope is pointing over the horizon, the solution is mu1, else is mu2
1465 if (mu1 < 0)
1466 {
1467 LOGF_DEBUG("Intersection mu1 < 0, using mu2 (%.3f)", mu2); // Less critical
1468 mu1 = mu2;
1469 }
1470
1471 DomeIntersect.x = OptCenter.x + mu1 * (OptVector.x );
1472 DomeIntersect.y = OptCenter.y + mu1 * (OptVector.y );
1473 DomeIntersect.z = OptCenter.z + mu1 * (OptVector.z );
1474 LOGF_DEBUG("Intersection - Point(X:%.3f, Y:%.3f, Z:%.3f) Dist: %.3f", DomeIntersect.x, DomeIntersect.y, DomeIntersect.z,
1475 mu1);
1476
1477 // Calculate Azimuth using atan2(x, y) for robustness.
1478 Az = atan2(DomeIntersect.x, DomeIntersect.y) * 180.0 / M_PI;
1479
1480 // Normalize Az to [0, 360) range
1481 if (Az < 0)
1482 {
1483 Az += 360.0;
1484 }
1485 if (Az >= 360.0)
1486 {
1487 Az = 0.0;
1488 }
1489
1490 if ((std::abs(DomeIntersect.x) > 0.00001) || (std::abs(DomeIntersect.y) > 0.00001))
1491 Alt = 180 * atan(DomeIntersect.z / sqrt((DomeIntersect.x * DomeIntersect.x) + (DomeIntersect.y * DomeIntersect.y))) / M_PI;
1492 else
1493 Alt = 90; // Dome Zenith
1494
1495 double RadiusAtAlt = DomeMeasurementsNP[DM_DOME_RADIUS].getValue() * cos(M_PI * Alt / 180);
1496
1497 if (DomeMeasurementsNP[DM_SHUTTER_WIDTH].getValue() < (2 * RadiusAtAlt))
1498 {
1499 double HalfApertureChordAngle = 180 * asin(DomeMeasurementsNP[DM_SHUTTER_WIDTH].getValue() / (2 * RadiusAtAlt)) / M_PI;
1500 minAz = range360(Az - HalfApertureChordAngle);
1501 maxAz = range360(Az + HalfApertureChordAngle);
1502 }
1503 else
1504 {
1505 minAz = 0;
1506 maxAz = 360;
1507 }
1508 return true;
1509 }
1510 return false;
1511 };
1512
1513 // Initial calculation attempt
1514 bool success = performCalculations(effectiveHourAngle);
1515
1516 // If near pole and initial calculation deviates significantly, try the other effectiveHourAngle
1517 if (nearPole && success)
1518 {
1519 double initialAz = Az;
1520 double diff = std::abs(initialAz - mountHoriztonalCoords.azimuth);
1521 if (diff > 180.0) // Handle wrap-around for angular difference
1522 diff = 360.0 - diff;
1523
1524 if (diff > POLE_AZIMUTH_DEVIATION_THRESHOLD)
1525 {
1526 LOGF_DEBUG("Near pole, initial Az (%.2f) deviates from mount Az (%.2f) by %.2f degrees. Attempting alternative effectiveHourAngle.",
1527 initialAz, mountHoriztonalCoords.azimuth, diff);
1528
1529 // Flip effectiveHourAngle
1530 effectiveHourAngle = (effectiveHourAngle == 0.0) ? 12.0 : 0.0;
1531 success = performCalculations(effectiveHourAngle);
1532
1533 if (success)
1534 {
1535 LOGF_DEBUG("Re-calculated Az (%.2f) with alternative effectiveHourAngle (%.2f).", Az, effectiveHourAngle);
1536 }
1537 else
1538 {
1539 LOG_WARN("Re-calculation with alternative effectiveHourAngle failed.");
1540 }
1541 }
1542 }
1543
1544 if (success)
1545 {
1546 // Final Condensed Log
1547 char currentAzStr[64], targetAzStr[64], targetAltStr[64], minAzStr[64], maxAzStr[64];
1548 fs_sexa(currentAzStr, DomeAbsPosNP[0].getValue(), 2, 3600);
1549 fs_sexa(targetAzStr, Az, 2, 3600);
1550 fs_sexa(targetAltStr, Alt, 2, 3600);
1551 fs_sexa(minAzStr, minAz, 2, 3600);
1552 fs_sexa(maxAzStr, maxAz, 2, 3600);
1553 LOGF_DEBUG("Result - Current Az:%s , Target Az: %s, Alt: %s --> Range Min: %s, Max: %s", currentAzStr, targetAzStr,
1554 targetAltStr, minAzStr, maxAzStr);
1555 return true;
1556 }
1557 else
1558 {
1559 LOG_WARN("Optical axis does not intersect dome sphere.");
1560 return false;
1561 }
1562}
1563
1564bool Dome::Intersection(point3D p1, point3D dp, double r, double &mu1, double &mu2)
1565{
1566 double a, b, c;
1567 double bb4ac;
1568
1569 a = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z;
1570 b = 2 * (dp.x * p1.x + dp.y * p1.y + dp.z * p1.z);
1571 c = 0.0;
1572 c = c + p1.x * p1.x + p1.y * p1.y + p1.z * p1.z;
1573 c = c - r * r;
1574 bb4ac = b * b - 4 * a * c;
1575 if ((fabs(a) < 0.0000001) || (bb4ac < 0))
1576 {
1577 mu1 = 0;
1578 mu2 = 0;
1579 return false;
1580 }
1581
1582 mu1 = (-b + sqrt(bb4ac)) / (2 * a);
1583 mu2 = (-b - sqrt(bb4ac)) / (2 * a);
1584
1585 return true;
1586}
1587
1588bool Dome::OpticalCenter(point3D MountCenter, double dOpticalAxis, double Lat, double Ah, point3D &OP)
1589{
1590 double q, f;
1591 double cosf, sinf, cosq, sinq;
1592
1593 // Note: this transformation is a circle rotated around X axis -(90 - Lat) degrees
1594 q = M_PI * (90 - Lat) / 180;
1595 f = -M_PI * (180 + Ah * 15) / 180;
1596
1597 cosf = cos(f);
1598 sinf = sin(f);
1599 cosq = cos(q);
1600 sinq = sin(q);
1601
1602 // The sign of dOpticalAxis determines de side of the tube
1603 OP.x = (dOpticalAxis * cosf + MountCenter.x);
1604 OP.y = (dOpticalAxis * sinf * cosq + MountCenter.y);
1605 OP.z = (dOpticalAxis * sinf * sinq + MountCenter.z);
1606
1607 return true;
1608}
1609
1610bool Dome::OpticalVector(double Az, double Alt, point3D &OV)
1611{
1612 double q, f;
1613
1614 q = M_PI * Alt / 180;
1615 f = M_PI * Az / 180;
1616 OV.x = cos(q) * sin(f);
1617 OV.y = cos(q) * cos(f);
1618 OV.z = sin(q);
1619
1620 return true;
1621}
1622
1623double Dome::Csc(double x)
1624{
1625 return 1.0 / sin(x);
1626}
1627
1628double Dome::Sec(double x)
1629{
1630 return 1.0 / cos(x);
1631}
1632
1633bool Dome::CheckHorizon(double HA, double dec, double lat)
1634{
1635 double sinh_value;
1636
1637 sinh_value = cos(lat) * cos(HA) * cos(dec) + sin(lat) * sin(dec);
1638
1639 if (sinh_value >= 0.0)
1640 return true;
1641
1642 return false;
1643}
1644
1646{
1647 // If not initialized yet, return.
1648 if (mountEquatorialCoords.rightascension == -1)
1649 return;
1650
1651 // Dont do this if we haven't had co-ordinates from the mount yet
1652 if (!HaveLatLong)
1653 return;
1654 if (!HaveRaDec)
1655 return;
1656
1658
1659 // Control debug flooding
1660 if (fabs(mountHoriztonalCoords.azimuth - prev_az) > DOME_COORD_THRESHOLD ||
1662 {
1665 LOGF_DEBUG("Updated telescope Az: %g - Alt: %g", prev_az, prev_alt);
1666 }
1667
1668 // Check if we need to move if mount is unparked.
1669 if (IsMountParked == false)
1671}
1672
1674{
1675 if ((m_MountState == IPS_OK || m_MountState == IPS_IDLE) && DomeAbsPosNP.getState() != IPS_BUSY
1676 && DomeAutoSyncSP[0].getState() == ISS_ON)
1677 {
1678 if (CanPark())
1679 {
1680 if (isParked() == true)
1681 {
1682 if (AutoSyncWarning == false)
1683 {
1684 LOG_WARN("Cannot perform autosync with dome parked. Please unpark to enable autosync operation.");
1685 AutoSyncWarning = true;
1686 }
1687 return;
1688 }
1689 }
1690
1691 AutoSyncWarning = false;
1692 double targetAz = 0, targetAlt = 0, minAz = 0, maxAz = 0;
1693 bool res;
1694 res = GetTargetAz(targetAz, targetAlt, minAz, maxAz);
1695 if (!res)
1696 {
1697 LOGF_DEBUG("GetTargetAz failed %g", targetAz);
1698 return;
1699 }
1700
1701 double diff = std::abs(targetAz - DomeAbsPosNP[0].getValue());
1702 if (diff > 180.0)
1703 diff = 360.0 - diff;
1704 if (diff > DomeParamNP[0].getValue())
1705 {
1706 IPState ret = Dome::MoveAbs(targetAz);
1707 if (ret == IPS_OK)
1708 LOGF_DEBUG("Dome synced to position %.2f degrees.", targetAz);
1709 else if (ret == IPS_BUSY)
1710 LOGF_DEBUG("Dome is syncing to position %.2f degrees...", targetAz);
1711 else
1712 LOG_ERROR("Dome failed to sync to new requested position.");
1713
1714 DomeAbsPosNP.setState(ret);
1715 DomeAbsPosNP.apply();
1716 }
1717 }
1718}
1719
1720void Dome::SetDomeCapability(uint32_t cap)
1721{
1722 capability = cap;
1723
1724 if (CanAbort())
1725 controller->mapController("Dome Abort", "Dome Abort", Controller::CONTROLLER_BUTTON, "BUTTON_3");
1726}
1727
1729{
1730 switch (status)
1731 {
1732 case SHUTTER_OPENED:
1733 return "Shutter is open.";
1734 case SHUTTER_CLOSED:
1735 return "Shutter is closed.";
1736 case SHUTTER_MOVING:
1737 return "Shutter is moving.";
1738 case SHUTTER_ERROR:
1739 return "Shutter has errors.";
1740 case SHUTTER_UNKNOWN:
1741 default:
1742 return "Shutter status is unknown.";
1743 }
1744}
1745
1747{
1749
1750 switch (parkDataType)
1751 {
1752 case PARK_NONE:
1753 DomeMotionSP[DOME_CW].setLabel("Open");
1754 DomeMotionSP[DOME_CCW].setLabel("Close");
1755 break;
1756
1757 case PARK_AZ:
1758 ParkPositionNP[AXIS_AZ].fill("PARK_AZ", "AZ D:M:S", "%10.6m", 0.0, 360.0, 0.0, 0);
1759 ParkPositionNP.fill(getDeviceName(), "DOME_PARK_POSITION", "Park Position", SITE_TAB, IP_RW, 60, IPS_IDLE);
1760 break;
1761
1762 case PARK_AZ_ENCODER:
1763 ParkPositionNP[AXIS_AZ].fill("PARK_AZ", "AZ Encoder", "%.0f", 0, 16777215, 1, 0);
1764 ParkPositionNP.fill(getDeviceName(), "DOME_PARK_POSITION", "Park Position", SITE_TAB, IP_RW, 60, IPS_IDLE);
1765 break;
1766
1767 default:
1768 break;
1769 }
1770}
1771
1772void Dome::SyncParkStatus(bool isparked)
1773{
1774 IsParked = isparked;
1775
1777
1778 if (IsParked)
1779 {
1781 LOG_INFO("Dome is parked.");
1782 }
1783 else
1784 {
1786 LOG_INFO("Dome is unparked.");
1787 }
1788}
1789
1790void Dome::SetParked(bool isparked)
1791{
1792 if (m_ShutterParkSequence != SHUTTER_SEQUENCE_NONE)
1793 {
1794 // Dome motion of the park/unpark is complete, but the shutter may still be moving.
1795 if (isparked == (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK))
1796 {
1797 shutterParkMotionDone();
1798 return;
1799 }
1800
1801 // The driver reports the opposite outcome (e.g. after an abort): drop the sequence.
1802 cancelShutterParkSequence();
1803 }
1804
1805 SyncParkStatus(isparked);
1806 WriteParkData();
1807}
1808
1810{
1811 return IsParked;
1812}
1813
1815{
1816 const char * loadres = LoadParkData();
1817 if (loadres)
1818 {
1819 LOGF_INFO("InitPark: No Park data in file %s: %s", ParkDataFileName.c_str(), loadres);
1820 SyncParkStatus(false);
1821 return false;
1822 }
1823
1824 SyncParkStatus(isParked());
1825
1826 if (parkDataType != PARK_NONE)
1827 {
1828 LOGF_DEBUG("InitPark Axis1 %.2f", Axis1ParkPosition);
1829 ParkPositionNP[AXIS_AZ].setValue(Axis1ParkPosition);
1830 ParkPositionNP.apply();
1831
1832 // If parked, store the position as current azimuth angle or encoder ticks
1833 if (isParked() && CanAbsMove())
1834 {
1835 DomeAbsPosNP[0].setValue(ParkPositionNP[AXIS_AZ].getValue());
1836 DomeAbsPosNP.apply();
1837 }
1838 }
1839
1840 return true;
1841}
1842
1843const char * Dome::LoadParkXML()
1844{
1845 wordexp_t wexp;
1846 FILE * fp;
1847 LilXML * lp;
1848 static char errmsg[XML_ERROR_SIZE];
1849
1850 XMLEle * parkxml;
1851 XMLAtt * ap;
1852 bool devicefound = false;
1853
1854 ParkDeviceName = getDeviceName();
1855 ParkstatusXml = nullptr;
1856 ParkdeviceXml = nullptr;
1857 ParkpositionXml = nullptr;
1858 ParkpositionAxis1Xml = nullptr;
1859
1860 if (wordexp(ParkDataFileName.c_str(), &wexp, 0))
1861 {
1862 wordfree(&wexp);
1863 return "Badly formed filename.";
1864 }
1865
1866 if (!(fp = fopen(wexp.we_wordv[0], "r")))
1867 {
1868 wordfree(&wexp);
1869 return strerror(errno);
1870 }
1871 wordfree(&wexp);
1872
1873 lp = newLilXML();
1874
1875 if (ParkdataXmlRoot)
1876 delXMLEle(ParkdataXmlRoot);
1877
1878 ParkdataXmlRoot = readXMLFile(fp, lp, errmsg);
1879 fclose(fp);
1880
1881 delLilXML(lp);
1882 if (!ParkdataXmlRoot)
1883 return errmsg;
1884
1885 if (!strcmp(tagXMLEle(nextXMLEle(ParkdataXmlRoot, 1)), "parkdata"))
1886 return "Not a park data file";
1887
1888 parkxml = nextXMLEle(ParkdataXmlRoot, 1);
1889
1890 while (parkxml)
1891 {
1892 if (strcmp(tagXMLEle(parkxml), "device"))
1893 {
1894 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
1895 continue;
1896 }
1897 ap = findXMLAtt(parkxml, "name");
1898 if (ap && (!strcmp(valuXMLAtt(ap), ParkDeviceName)))
1899 {
1900 devicefound = true;
1901 break;
1902 }
1903 parkxml = nextXMLEle(ParkdataXmlRoot, 0);
1904 }
1905
1906 if (!devicefound)
1907 return "No park data found for this device";
1908
1909 ParkdeviceXml = parkxml;
1910 ParkstatusXml = findXMLEle(parkxml, "parkstatus");
1911
1912 if (parkDataType != PARK_NONE)
1913 {
1914 ParkpositionXml = findXMLEle(parkxml, "parkposition");
1915 ParkpositionAxis1Xml = findXMLEle(ParkpositionXml, "axis1position");
1916
1917 if (ParkpositionAxis1Xml == nullptr)
1918 {
1919 return "Park position invalid or missing.";
1920 }
1921 }
1922 else if (ParkstatusXml == nullptr)
1923 return "Park status invalid or missing.";
1924
1925 return nullptr;
1926}
1927
1929{
1930 IsParked = false;
1931
1932 const char * result = LoadParkXML();
1933 if (result != nullptr)
1934 return result;
1935
1936 if (!strcmp(pcdataXMLEle(ParkstatusXml), "true"))
1937 IsParked = true;
1938
1939 if (parkDataType == PARK_NONE)
1940 return nullptr;
1941
1942 double axis1Pos = std::numeric_limits<double>::quiet_NaN();
1943
1944 int rc = sscanf(pcdataXMLEle(ParkpositionAxis1Xml), "%lf", &axis1Pos);
1945 if (rc != 1)
1946 {
1947 return "Unable to parse Park Position Axis 1.";
1948 }
1949
1950 if (std::isnan(axis1Pos) == false)
1951 {
1952 Axis1ParkPosition = axis1Pos;
1953 return nullptr;
1954 }
1955
1956 return "Failed to parse Park Position.";
1957}
1958
1960{
1961 // We need to refresh parking data in case other devices parking states were updated since we
1962 // read the data the first time.
1963 if (LoadParkXML() != nullptr)
1964 LOG_DEBUG("Failed to refresh parking data.");
1965
1966 wordexp_t wexp;
1967 FILE * fp;
1968 char pcdata[30];
1969 ParkDeviceName = getDeviceName();
1970
1971 if (wordexp(ParkDataFileName.c_str(), &wexp, 0))
1972 {
1973 wordfree(&wexp);
1974 LOGF_INFO("WriteParkData: can not write file %s: Badly formed filename.",
1975 ParkDataFileName.c_str());
1976 return false;
1977 }
1978
1979 if (!(fp = fopen(wexp.we_wordv[0], "w")))
1980 {
1981 wordfree(&wexp);
1982 LOGF_INFO("WriteParkData: can not write file %s: %s", ParkDataFileName.c_str(),
1983 strerror(errno));
1984 return false;
1985 }
1986
1987 if (!ParkdataXmlRoot)
1988 ParkdataXmlRoot = addXMLEle(nullptr, "parkdata");
1989
1990 if (!ParkdeviceXml)
1991 {
1992 ParkdeviceXml = addXMLEle(ParkdataXmlRoot, "device");
1993 addXMLAtt(ParkdeviceXml, "name", ParkDeviceName);
1994 }
1995
1996 if (!ParkstatusXml)
1997 ParkstatusXml = addXMLEle(ParkdeviceXml, "parkstatus");
1998 if (parkDataType != PARK_NONE)
1999 {
2000 if (!ParkpositionXml)
2001 ParkpositionXml = addXMLEle(ParkdeviceXml, "parkposition");
2002 if (!ParkpositionAxis1Xml)
2003 ParkpositionAxis1Xml = addXMLEle(ParkpositionXml, "axis1position");
2004 }
2005
2006 editXMLEle(ParkstatusXml, (IsParked ? "true" : "false"));
2007
2008 if (parkDataType != PARK_NONE)
2009 {
2010 snprintf(pcdata, sizeof(pcdata), "%lf", Axis1ParkPosition);
2011 editXMLEle(ParkpositionAxis1Xml, pcdata);
2012 }
2013
2014 prXMLEle(fp, ParkdataXmlRoot, 0);
2015 fclose(fp);
2016 wordfree(&wexp);
2017
2018 return true;
2019}
2020
2022{
2023 return Axis1ParkPosition;
2024}
2025
2027{
2028 return Axis1DefaultParkPosition;
2029}
2030
2031void Dome::SetAxis1Park(double value)
2032{
2033 Axis1ParkPosition = value;
2034 ParkPositionNP[AXIS_RA].setValue(value);
2035 ParkPositionNP.apply();
2036}
2037
2039{
2040 Axis1DefaultParkPosition = value;
2041}
2042
2044{
2045 // Check if it is already parked.
2046 if (CanPark())
2047 {
2048 if (parkDataType != PARK_NONE && isParked())
2049 {
2050 LOG_WARN( "Please unpark the dome before issuing any motion commands.");
2051 return IPS_ALERT;
2052 }
2053 }
2054
2055 if ((DomeMotionSP.getState() != IPS_BUSY && (DomeAbsPosNP.getState() == IPS_BUSY || DomeRelPosNP.getState() == IPS_BUSY)) ||
2057 {
2058 LOG_WARN( "Please stop dome before issuing any further motion commands.");
2059 return IPS_ALERT;
2060 }
2061
2062 auto current_direction = DomeMotionSP.findOnSwitchIndex();
2063
2064 // if same move requested, return
2065 if (DomeMotionSP.getState() == IPS_BUSY && current_direction == dir && operation == MOTION_START)
2066 return IPS_BUSY;
2067
2068 DomeMotionSP.setState(Move(dir, operation));
2069
2070 if (DomeMotionSP.getState() == IPS_BUSY || DomeMotionSP.getState() == IPS_OK)
2071 {
2072 m_DomeState = (operation == MOTION_START) ? DOME_MOVING : DOME_IDLE;
2073 DomeMotionSP.reset();
2074 if (operation == MOTION_START)
2075 DomeMotionSP[dir].setState(ISS_ON);
2076 }
2077
2078 DomeMotionSP.apply();
2079
2080 return DomeMotionSP.getState();
2081}
2082
2084{
2085 if (CanRelMove() == false)
2086 {
2087 LOG_ERROR( "Dome does not support relative motion.");
2088 return IPS_ALERT;
2089 }
2090
2091 if (m_DomeState == DOME_PARKED)
2092 {
2093 LOG_ERROR( "Please unpark before issuing any motion commands.");
2094 DomeRelPosNP.setState(IPS_ALERT);
2095 DomeRelPosNP.apply();
2096 return IPS_ALERT;
2097 }
2098
2099 if ((DomeRelPosNP.getState() != IPS_BUSY && DomeMotionSP.getState() == IPS_BUSY) || (m_DomeState == DOME_PARKING))
2100 {
2101 LOG_WARN( "Please stop dome before issuing any further motion commands.");
2102 DomeRelPosNP.setState(IPS_IDLE);
2103 DomeRelPosNP.apply();
2104 return IPS_ALERT;
2105 }
2106
2107 IPState rc;
2108
2109 if ((rc = MoveRel(azDiff)) == IPS_OK)
2110 {
2112 DomeRelPosNP.setState(IPS_OK);
2113 DomeRelPosNP[0].setValue(azDiff);
2114 LOGF_INFO("Dome moved %.2f degrees %s.", azDiff, (azDiff > 0) ? "clockwise" : "counter clockwise");
2115 DomeRelPosNP.apply();
2116 if (CanAbsMove())
2117 {
2118 DomeAbsPosNP.setState(IPS_OK);
2119 DomeAbsPosNP.apply();
2120 }
2121 return IPS_OK;
2122 }
2123 else if (rc == IPS_BUSY)
2124 {
2126 DomeRelPosNP[0].setValue(azDiff);
2127 DomeRelPosNP.setState(IPS_BUSY);
2128 LOGF_INFO("Dome moved %.2f degrees %s.", azDiff, (azDiff > 0) ? "clockwise" : "counter clockwise");
2129 DomeRelPosNP.apply();
2130 if (CanAbsMove())
2131 {
2132 DomeAbsPosNP.setState(IPS_BUSY);
2133 DomeAbsPosNP.apply();
2134 }
2135
2136 DomeMotionSP.setState(IPS_BUSY);
2137 DomeMotionSP.reset();
2138 DomeMotionSP[DOME_CW].setState((azDiff > 0) ? ISS_ON : ISS_OFF);
2139 DomeMotionSP[DOME_CCW].setState((azDiff < 0) ? ISS_ON : ISS_OFF);
2140 DomeMotionSP.apply();
2141 return IPS_BUSY;
2142 }
2143
2145 DomeRelPosNP.setState(IPS_ALERT);
2146 LOG_WARN("Dome failed to move to new requested position.");
2147 DomeRelPosNP.apply();
2148 return IPS_ALERT;
2149}
2150
2152{
2153 if (CanAbsMove() == false)
2154 {
2155 LOG_ERROR("Dome does not support MoveAbs(). MoveAbs() must be implemented in the child class.");
2156 return IPS_ALERT;
2157 }
2158
2159 if (m_DomeState == DOME_PARKED)
2160 {
2161 LOG_ERROR( "Please unpark before issuing any motion commands.");
2162 DomeAbsPosNP.setState(IPS_ALERT);
2163 DomeAbsPosNP.apply();
2164 return IPS_ALERT;
2165 }
2166
2167 if ((DomeRelPosNP.getState() != IPS_BUSY && DomeMotionSP.getState() == IPS_BUSY) || (m_DomeState == DOME_PARKING))
2168 {
2169 LOG_WARN( "Please stop dome before issuing any further motion commands.");
2170 return IPS_ALERT;
2171 }
2172
2173 IPState rc;
2174
2175 if (az < DomeAbsPosNP[0].getMin() || az > DomeAbsPosNP[0].getMax())
2176 {
2177 LOGF_ERROR( "Error: requested azimuth angle %.2f is out of range.", az);
2178 DomeAbsPosNP.setState(IPS_ALERT);
2179 DomeAbsPosNP.apply();
2180 return IPS_ALERT;
2181 }
2182
2183 if ((rc = MoveAbs(az)) == IPS_OK)
2184 {
2186 DomeAbsPosNP.setState(IPS_OK);
2187 DomeAbsPosNP[0].setValue(az);
2188 LOGF_INFO("Dome moved to position %.2f degrees azimuth.", az);
2189 DomeAbsPosNP.apply();
2190
2191 return IPS_OK;
2192 }
2193 else if (rc == IPS_BUSY)
2194 {
2196 DomeAbsPosNP.setState(IPS_BUSY);
2197 LOGF_INFO("Dome is moving to position %.2f degrees azimuth...", az);
2198 DomeAbsPosNP.apply();
2199
2200 DomeMotionSP.setState(IPS_BUSY);
2201 DomeMotionSP.reset();
2202 DomeMotionSP[DOME_CW].setState((az > DomeAbsPosNP[0].getValue()) ? ISS_ON : ISS_OFF);
2203 DomeMotionSP[DOME_CCW].setState((az < DomeAbsPosNP[0].getValue()) ? ISS_ON : ISS_OFF);
2204 DomeMotionSP.apply();
2205
2206 return IPS_BUSY;
2207 }
2208
2210 DomeAbsPosNP.setState(IPS_ALERT);
2211 LOG_INFO("Dome failed to move to new requested position.");
2212 DomeAbsPosNP.apply();
2213 return IPS_ALERT;
2214}
2215
2216bool Dome::Sync(double az)
2217{
2218 INDI_UNUSED(az);
2219 LOG_WARN("Syncing is not supported.");
2220 return false;
2221}
2222
2224{
2225 if (CanAbort() == false)
2226 {
2227 LOG_ERROR( "Dome does not support abort.");
2228 return false;
2229 }
2230
2231 AbortSP.reset();
2232
2233 // Drop any shutter park sequence first so the driver's own park updates during abort take effect.
2234 // The park may still be busy waiting for the shutter even if the driver already left DOME_PARKING.
2235 const bool sequenceParking = (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK);
2236 const bool sequenceUnparking = (m_ShutterParkSequence == SHUTTER_SEQUENCE_UNPARK);
2237 const bool sequenceMotionDone = m_ShutterParkMotionDone;
2238 cancelShutterParkSequence();
2239
2240 if (Abort())
2241 {
2242 AbortSP.setState(IPS_OK);
2243
2244 const bool parkBusy = (ParkSP.getState() == IPS_BUSY);
2245 const bool parking = (m_DomeState == DOME_PARKING) || (sequenceParking && parkBusy);
2246 const bool unparking = (m_DomeState == DOME_UNPARKING) || (sequenceUnparking && parkBusy);
2247
2248 if (parking || unparking)
2249 {
2250 ParkSP.reset();
2251 if (parking)
2252 {
2253 DEBUG(Logger::DBG_SESSION, "Parking aborted.");
2254 // If parking was aborted then it was UNPARKED before
2255 ParkSP[1].setState(ISS_ON);
2256 }
2257 else
2258 {
2259 DEBUG(Logger::DBG_SESSION, "UnParking aborted.");
2260 // If unparking aborted then it was PARKED before
2261 ParkSP[0].setState(ISS_ON);
2262 }
2263
2264 ParkSP.setState(IPS_ALERT);
2265 ParkSP.apply();
2266 }
2267
2269 }
2270 else
2271 {
2272 AbortSP.setState(IPS_ALERT);
2273
2274 // If alert was aborted during parking or unparking, the parking state is unknown
2276 ((sequenceParking || sequenceUnparking) && ParkSP.getState() == IPS_BUSY))
2277 {
2278 ParkSP.reset();
2279 ParkSP.setState(IPS_IDLE);
2280 ParkSP.apply();
2281
2282 // The dome had already finished moving and was only waiting for the shutter: it is not
2283 // parking anymore, so do not leave it in a state where new park requests are refused.
2284 if (sequenceMotionDone && (m_DomeState == DOME_PARKING || m_DomeState == DOME_UNPARKING))
2286 }
2287 }
2288
2289 AbortSP.apply();
2290
2291 return (AbortSP.getState() == IPS_OK);
2292}
2293
2294bool Dome::SetSpeed(double speed)
2295{
2296 if (HasVariableSpeed() == false)
2297 {
2298 LOG_ERROR( "Dome does not support variable speed.");
2299 return false;
2300 }
2301
2302 if (SetSpeed(speed))
2303 {
2304 DomeSpeedNP.setState(IPS_OK);
2305 DomeSpeedNP[0].setValue(speed);
2306 }
2307 else
2308 DomeSpeedNP.setState(IPS_ALERT);
2309
2310 DomeSpeedNP.apply();
2311
2312 return (DomeSpeedNP.getState() == IPS_OK);
2313}
2314
2316{
2317 if (HasShutter() == false)
2318 {
2319 LOG_ERROR( "Dome does not have shutter control.");
2320 return IPS_ALERT;
2321 }
2322
2323 auto currentStatus = DomeShutterSP.findOnSwitchIndex();
2324
2325 // No change of status, let's return
2326 if (DomeShutterSP.getState() == IPS_BUSY && currentStatus == operation)
2327 {
2328 DomeShutterSP.apply();
2329 return DomeShutterSP.getState();
2330 }
2331
2332 DomeShutterSP.setState(ControlShutter(operation));
2333
2334 if (DomeShutterSP.getState() == IPS_OK)
2335 {
2336 LOGF_INFO("Shutter is %s.", (operation == SHUTTER_OPEN ? "open" : "closed"));
2337 DomeShutterSP.apply();
2339 return DomeShutterSP.getState();
2340 }
2341 else if (DomeShutterSP.getState() == IPS_BUSY)
2342 {
2343 DomeShutterSP.reset();
2344 DomeShutterSP[operation].setState(ISS_ON);
2345 LOGF_INFO("Shutter is %s...", (operation == 0 ? "opening" : "closing"));
2346 DomeShutterSP.apply();
2348 return DomeShutterSP.getState();
2349 }
2350
2351 LOGF_INFO("Shutter failed to %s.", (operation == 0 ? "open" : "close"));
2352 DomeShutterSP.apply();
2353 return IPS_ALERT;
2354}
2355
2357{
2358 // Not really supposed to get this at all, but just in case.
2359 if (CanPark() == false)
2360 {
2361 LOG_ERROR( "Dome does not support parking.");
2362 return IPS_ALERT;
2363 }
2364
2365 // No need to park if parked already.
2366 if (m_DomeState == DOME_PARKED)
2367 {
2368 ParkSP.reset();
2369 ParkSP[0].setState(ISS_ON);
2370 LOG_INFO("Dome already parked.");
2371 ParkSP.apply();
2372 return IPS_OK;
2373 }
2374
2375 // Check if dome is locked due to Mount Policy
2376 if (isLocked())
2377 {
2378 ParkSP.reset();
2379 ParkSP[1].s = ISS_ON;
2380 ParkSP.setState(IPS_ALERT);
2381 ParkSP.apply();
2382 LOG_INFO("Cannot Park Dome when mount is locking. See: Mount Policy in options tab.");
2383 return IPS_ALERT;
2384 }
2385
2386 // A park request supersedes any unpark still waiting on the shutter.
2387 cancelShutterParkSequence();
2388
2389 // Shutter park policy: close the shutter first, then park. The park only completes
2390 // once the dome reached the park position AND the shutter is closed.
2391 if (HasShutter() && !m_ShutterParkPolicyHandledByDriver &&
2392 ShutterParkPolicySP[SHUTTER_CLOSE_ON_PARK].getState() == ISS_ON && !isShutterKnownAt(SHUTTER_CLOSE))
2393 {
2394 LOG_INFO("Closing shutter on park...");
2395 m_ShutterParkSequence = SHUTTER_SEQUENCE_PARK;
2396 m_ShutterParkCommandSent = true;
2397
2399 {
2400 cancelShutterParkSequence();
2401 LOG_ERROR("Failed to close shutter. Dome park aborted.");
2402 ParkSP.setState(IPS_ALERT);
2403 ParkSP.apply();
2404 return IPS_ALERT;
2405 }
2406
2407 m_ShutterParkTimer.start();
2408 }
2409
2410 // Now ask child driver to start the actual parking process.
2411 ParkSP.setState(Park());
2412
2413 // IPS_OK is when it is immediately parked so realisticly this does not happen
2414 // unless dome is physically parked but just needed a state change.
2415 if (ParkSP.getState() == IPS_OK)
2416 {
2417 SetParked(true);
2418
2419 // Still waiting for the shutter to close.
2420 if (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK)
2421 {
2423 return IPS_BUSY;
2424 }
2425 }
2426 // Dome is moving to parking position
2427 else if (ParkSP.getState() == IPS_BUSY)
2428 {
2430
2431 if (CanAbsMove())
2432 DomeAbsPosNP.setState(IPS_BUSY);
2433
2434 ParkSP.reset();
2435 ParkSP[0].setState(ISS_ON);
2436 }
2437 else
2438 {
2439 cancelShutterParkSequence();
2440 ParkSP.apply();
2441 }
2442
2443 return ParkSP.getState();
2444}
2445
2447{
2448 if (CanPark() == false)
2449 {
2450 LOG_ERROR( "Dome does not support parking.");
2451 return IPS_ALERT;
2452 }
2453
2454 if (m_DomeState != DOME_PARKED)
2455 {
2456 ParkSP.reset();
2457 ParkSP[1].setState(ISS_ON);
2458 LOG_INFO("Dome already unparked.");
2459 ParkSP.apply();
2460 return IPS_OK;
2461 }
2462
2463 cancelShutterParkSequence();
2464
2465 // Shutter park policy: unpark first, then open the shutter, so the shutter is never opened when
2466 // the dome fails to unpark. The unpark only completes once the dome is unparked AND the shutter is open.
2467 // The sequence starts before calling the child UnPark() so that it also covers drivers that report the
2468 // unpark (SetParked(false)) from within UnPark() itself.
2469 const bool openShutter = HasShutter() && !m_ShutterParkPolicyHandledByDriver &&
2470 ShutterParkPolicySP[SHUTTER_OPEN_ON_UNPARK].getState() == ISS_ON && !isShutterKnownAt(SHUTTER_OPEN);
2471 if (openShutter)
2472 m_ShutterParkSequence = SHUTTER_SEQUENCE_UNPARK;
2473
2474 auto rc = UnPark();
2475
2476 if (rc == IPS_ALERT)
2477 {
2478 cancelShutterParkSequence();
2479 ParkSP.setState(IPS_ALERT);
2480 ParkSP.apply();
2481 return IPS_ALERT;
2482 }
2483
2484 // The sequence may have been dropped from within UnPark() (e.g. driver reported an error).
2485 if (openShutter && m_ShutterParkSequence == SHUTTER_SEQUENCE_UNPARK)
2486 {
2487 LOG_INFO("Opening shutter on unpark...");
2488 m_ShutterParkCommandSent = true;
2490 {
2491 LOG_ERROR("Failed to open shutter on unpark.");
2492 m_ShutterParkShutterFailed = true;
2493 }
2494 else
2495 m_ShutterParkTimer.start();
2496 }
2497
2498 if (rc == IPS_OK)
2499 SetParked(false);
2500 else if (rc == IPS_BUSY)
2502 else
2503 {
2504 cancelShutterParkSequence();
2505 ParkSP.setState(rc);
2506 ParkSP.apply();
2507 }
2508
2509 // Still waiting for the dome motion and/or the shutter.
2510 if (m_ShutterParkSequence == SHUTTER_SEQUENCE_UNPARK)
2511 {
2514 return IPS_BUSY;
2515 }
2516
2517 return ParkSP.getState();
2518}
2519
2520bool Dome::isShutterAt(ShutterOperation operation) const
2521{
2522 return DomeShutterSP.getState() == IPS_OK && DomeShutterSP[operation].getState() == ISS_ON;
2523}
2524
2525bool Dome::isShutterKnownAt(ShutterOperation operation) const
2526{
2527 // DomeShutterSP starts as "closed" before the driver ever reads the shutter, and some drivers only
2528 // update it while the shutter moves. Only skip a shutter command when the driver also reported the
2529 // shutter state: an unneeded close is harmless, a skipped one leaves the observatory open.
2530 return isShutterAt(operation) && m_ShutterState == (operation == SHUTTER_OPEN ? SHUTTER_OPENED : SHUTTER_CLOSED);
2531}
2532
2533void Dome::cancelShutterParkSequence()
2534{
2535 m_ShutterParkTimer.stop();
2536 m_ShutterParkSequence = SHUTTER_SEQUENCE_NONE;
2537 m_ShutterParkCommandSent = false;
2538 m_ShutterParkMotionDone = false;
2539 m_ShutterParkShutterDone = false;
2540 m_ShutterParkShutterFailed = false;
2541}
2542
2543void Dome::shutterParkMotionDone()
2544{
2545 if (m_ShutterParkMotionDone)
2546 return;
2547
2548 m_ShutterParkMotionDone = true;
2549
2550 // Settle the motion properties the way setDomeState(DOME_PARKED) would, but leave ParkSP busy.
2551 if (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK)
2552 {
2553 if (DomeMotionSP.getState() == IPS_BUSY)
2554 {
2555 DomeMotionSP.reset();
2556 DomeMotionSP.setState(IPS_IDLE);
2557 DomeMotionSP.apply();
2558 }
2559 if (DomeAbsPosNP.getState() == IPS_BUSY)
2560 {
2561 DomeAbsPosNP.setState(IPS_IDLE);
2562 DomeAbsPosNP.apply();
2563 }
2564 if (DomeRelPosNP.getState() == IPS_BUSY)
2565 {
2566 DomeRelPosNP.setState(IPS_IDLE);
2567 DomeRelPosNP.apply();
2568 }
2569 }
2570
2571 checkShutterParkSequence();
2572
2573 if (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK)
2574 LOG_INFO("Dome reached park position. Waiting for shutter to close...");
2575 else if (m_ShutterParkSequence == SHUTTER_SEQUENCE_UNPARK)
2576 LOG_INFO("Dome is unparked. Waiting for shutter to open...");
2577}
2578
2579void Dome::checkShutterParkSequence()
2580{
2581 if (m_ShutterParkSequence == SHUTTER_SEQUENCE_NONE)
2582 return;
2583
2584 const bool parking = (m_ShutterParkSequence == SHUTTER_SEQUENCE_PARK);
2585
2586 if (m_ShutterParkCommandSent && !m_ShutterParkShutterDone && !m_ShutterParkShutterFailed)
2587 {
2588 // Drivers report the shutter either through setShutterState() or directly through DomeShutterSP.
2589 if (isShutterAt(parking ? SHUTTER_CLOSE : SHUTTER_OPEN) ||
2591 m_ShutterParkShutterDone = true;
2592 else if (m_ShutterState == SHUTTER_ERROR)
2593 {
2594 LOGF_ERROR("Shutter failed to %s.", parking ? "close" : "open");
2595 m_ShutterParkShutterFailed = true;
2596 }
2597 }
2598
2599 if (!m_ShutterParkMotionDone || !(m_ShutterParkShutterDone || m_ShutterParkShutterFailed))
2600 return;
2601
2602 const bool failed = m_ShutterParkShutterFailed;
2603 cancelShutterParkSequence();
2604
2605 if (parking)
2606 {
2607 if (failed)
2608 {
2609 // Do not report the dome as parked: the observatory is not closed, and a new park request must retry.
2610 LOG_ERROR("Dome park failed: shutter is not closed.");
2612 }
2613 else
2614 SetParked(true);
2615 }
2616 else
2617 {
2618 SetParked(false);
2619 if (failed)
2620 {
2621 LOG_ERROR("Dome is unparked but shutter failed to open.");
2622 ParkSP.setState(IPS_ALERT);
2623 ParkSP.apply();
2624 }
2625 }
2626}
2627
2629{
2630 LOG_WARN( "Parking is not supported.");
2631 return false;
2632}
2633
2635{
2636 LOG_WARN( "Parking is not supported.");
2637 return false;
2638}
2639
2641{
2642 return false;
2643}
2644
2645bool Dome::callHandshake()
2646{
2647 if (domeConnection > 0)
2648 {
2651 else if (getActiveConnection() == tcpConnection)
2653 }
2654
2655 return Handshake();
2656}
2657
2659{
2660 return domeConnection;
2661}
2662
2663void Dome::setDomeConnection(const uint8_t &value)
2664{
2666
2667 if (value == 0 || (mask & value) == 0)
2668 {
2669 LOGF_ERROR( "Invalid connection mode %d", value);
2670 return;
2671 }
2672
2673 domeConnection = value;
2674}
2675
2676}
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
int getPortFD() const
bool isConnected() const
const char * getDeviceName() const
INDI::PropertyText getText(const char *name) const
The Controller class provides functionality to access a controller (e.g. joystick) input and send it ...
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Connection::Interface * getActiveConnection()
void addDebugControl()
Add Debug control to the driver.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
bool CanPark()
Definition indidome.h:242
INDI::PropertySwitch PresetGotoSP
Definition indidome.h:596
double prev_alt
Definition indidome.h:624
INDI::IHorizontalCoordinates mountHoriztonalCoords
Definition indidome.h:643
Connection::TCP * tcpConnection
Definition indidome.h:630
DomeState m_DomeState
Definition indidome.h:633
@ CONNECTION_SERIAL
Definition indidome.h:172
@ CONNECTION_TCP
Definition indidome.h:173
@ CONNECTION_NONE
Definition indidome.h:171
virtual IPState UnPark()
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
uint32_t capability
Definition indidome.h:621
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
void SetDomeCapability(uint32_t cap)
SetDomeCapability set the dome capabilities. All capabilities must be initialized.
void setDomeConnection(const uint8_t &value)
setDomeConnection Set Dome connection mode. Child class should call this in the constructor before Do...
INDI::PropertySwitch ShutterParkPolicySP
Definition indidome.h:588
INDI::PropertySwitch ParkOptionSP
Definition indidome.h:574
const char * GetShutterStatusString(ShutterState status)
getShutterStatusString
INDI::IEquatorialCoordinates mountEquatorialCoords
Definition indidome.h:644
@ DM_OTA_SIDE_EAST
Definition indidome.h:605
@ DM_OTA_SIDE_MOUNT
Definition indidome.h:607
@ DM_OTA_SIDE_IGNORE
Definition indidome.h:609
@ DM_OTA_SIDE_WEST
Definition indidome.h:606
@ DM_OTA_SIDE_HA
Definition indidome.h:608
bool CheckHorizon(double HA, double dec, double lat)
CheckHorizon Returns true if telescope points above horizon.
INDI::PropertyNumber DomeRelPosNP
Definition indidome.h:560
@ SHUTTER_OPEN_ON_UNPARK
Definition indidome.h:592
@ SHUTTER_CLOSE_ON_PARK
Definition indidome.h:591
bool isParked()
isParked is dome currently parked?
bool HaveRaDec
Definition indidome.h:646
INDI::PropertyNumber DomeParamNP
Definition indidome.h:564
bool OpticalCenter(point3D MountCenter, double dOpticalAxis, double Lat, double Ah, point3D &OP)
OpticalCenter This function calculates the distance from the optical axis to the Dome center.
DomeState
Dome status.
Definition indidome.h:130
@ DOME_UNPARKING
Definition indidome.h:135
@ DOME_UNPARKED
Definition indidome.h:137
INDI::PropertyNumber ParkPositionNP
Definition indidome.h:572
virtual bool SetSpeed(double rpm)
SetSpeed Set Dome speed. This does not initiate motion, it sets the speed for the next motion command...
virtual bool Sync(double az)
Sync sets the dome current azimuth as the supplied azimuth position.
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...
Definition indidome.cpp:273
ShutterState m_ShutterState
Definition indidome.h:634
double prev_dec
Definition indidome.h:624
bool CanRelMove()
Definition indidome.h:234
void SetAxis1Park(double value)
SetRAPark Set current AZ parking position. The data park file (stored in ~/.indi/ParkData....
double prev_ra
Definition indidome.h:624
void UpdateMountCoords()
updateCoords updates the horizontal coordinates (Az & Alt) of the mount from the snooped RA,...
ShutterOperation
Shutter operation command.
Definition indidome.h:114
@ SHUTTER_CLOSE
Definition indidome.h:116
IPState getMountState() const
void SetAxis1ParkDefault(double steps)
SetAxis1Park Set default AZ parking position.
INDI::PropertySwitch AbortSP
Definition indidome.h:562
INDI::PropertyNumber DomeSpeedNP
Definition indidome.h:554
DomeMotionCommand
Definition indidome.h:97
@ MOTION_STOP
Definition indidome.h:99
@ MOTION_START
Definition indidome.h:98
double Csc(double x)
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition indidome.cpp:108
double prev_az
Definition indidome.h:624
INDI::PropertyNumber DomeMeasurementsNP
Definition indidome.h:598
virtual void UpdateAutoSync()
UpdateAutoSync This function calculates the target dome azimuth from the mount's target coordinates g...
INDI::PropertyNumber DomeBacklashNP
Definition indidome.h:619
virtual IPState MoveRel(double azDiff)
Move the Dome to an relative position.
double GetAxis1Park()
bool CanSync()
Definition indidome.h:250
bool HasShutter()
Definition indidome.h:258
@ SHUTTER_ERROR
Definition indidome.h:151
@ SHUTTER_MOVING
Definition indidome.h:149
@ SHUTTER_UNKNOWN
Definition indidome.h:150
@ SHUTTER_OPENED
Definition indidome.h:147
@ SHUTTER_CLOSED
Definition indidome.h:148
bool isLocked()
isLocked, is the dome currently locked?
virtual void ActiveDevicesUpdated()
Definition indidome.h:549
INDI::PropertySwitch ParkSP
Definition indidome.h:570
int mountOTASide
Definition indidome.h:612
bool HasVariableSpeed()
Definition indidome.h:266
virtual bool SetBacklash(int32_t steps)
SetBacklash Set the dome backlash compensation value.
double GetAxis1ParkDefault()
virtual IPState Park()
Goto Park Position. The park position is an absolute azimuth value.
const char * LoadParkData()
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition indidome.cpp:287
INDI::PropertyNumber DomeAbsPosNP
Definition indidome.h:558
@ DM_NORTH_DISPLACEMENT
Definition indidome.h:85
@ DM_EAST_DISPLACEMENT
Definition indidome.h:86
@ DM_SHUTTER_WIDTH
Definition indidome.h:84
@ DM_DOME_RADIUS
Definition indidome.h:83
@ DM_OTA_OFFSET
Definition indidome.h:88
@ DM_UP_DISPLACEMENT
Definition indidome.h:87
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition indidome.cpp:508
IPState m_MountState
Definition indidome.h:635
virtual bool SetDefaultPark()
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
bool Intersection(point3D p1, point3D p2, double r, double &mu1, double &mu2)
Intersection Calculate the intersection of a ray and a sphere. The line segment is defined from p1 to...
virtual bool SetBacklashEnabled(bool enabled)
SetBacklashEnabled Enables or disables the dome backlash compensation.
double Sec(double x)
virtual IPState MoveAbs(double az)
Move the Dome to an absolute azimuth.
bool CanAbort()
Definition indidome.h:218
INDI::PropertySwitch DomeMotionSP
Definition indidome.h:556
IGeographicCoordinates observer
Definition indidome.h:638
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition indidome.cpp:856
@ ACTIVE_OUTPUT
Definition indidome.h:581
static void buttonHelper(const char *button_n, ISState state, void *context)
INDI::PropertySwitch DomeBacklashSP
Definition indidome.h:616
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
virtual bool SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
bool CanAbsMove()
Definition indidome.h:226
@ PARK_AZ_ENCODER
Definition indidome.h:107
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition indidome.cpp:824
void setShutterState(const ShutterState &value)
bool OpticalVector(double Az, double Alt, point3D &OV)
OpticalVector This function calculates a second point for determining the optical axis.
virtual ~Dome()
Definition indidome.cpp:80
bool HasBacklash()
Definition indidome.h:274
void setDomeState(const DomeState &value)
@ MOUNT_IGNORED
Definition indidome.h:122
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
Connection::Serial * serialConnection
Definition indidome.h:629
INDI::PropertySwitch MountPolicySP
Definition indidome.h:585
void SetParkDataType(DomeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
bool WriteParkData()
INDI::PropertySwitch DomeAutoSyncSP
Definition indidome.h:613
INDI::PropertySwitch DomeShutterSP
Definition indidome.h:568
DomeParkData parkDataType
Definition indidome.h:622
virtual bool Handshake()
perform handshake with device to check communication
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition indidome.cpp:399
bool HaveLatLong
Definition indidome.h:640
virtual IPState ControlShutter(ShutterOperation operation)
Open or Close shutter.
INDI::PropertyText ActiveDeviceTP
Definition indidome.h:576
INDI::PropertySwitch OTASideSP
Definition indidome.h:600
bool GetTargetAz(double &Az, double &Alt, double &minAz, double &maxAz)
GetTargetAz.
INDI::PropertyNumber DomeSyncNP
Definition indidome.h:566
uint8_t getDomeConnection() const
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation)
Move the Dome in a particular direction.
INDI::PropertyNumber PresetNP
Definition indidome.h:595
virtual bool Abort()
Abort all dome motion.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
#define M_PI
Definition dsp.h:52
int errno
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
IPState
Property state.
Definition indiapi.h:158
@ 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_NOFMANY
Definition indiapi.h:173
@ ISR_ATMOST1
Definition indiapi.h:172
@ AXIS_RA
@ AXIS_AZ
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
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition indicom.c:1321
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
double get_local_hour_angle(double sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
Definition indicom.c:1379
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.
int crackIPState(const char *str, IPState *ip)
Extract property state (Idle, OK, Busy, Alert) from the supplied string.
Definition indidevapi.c:793
#define INDI_UNUSED(x)
Definition indidevapi.h:132
#define DOME_COORD_THRESHOLD
Definition indidome.cpp:44
#define DOME_SLAVING_TAB
Definition indidome.cpp:43
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 IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
Definition indidriver.c:143
*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 DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
Definition indilogger.h:56
#define LOGF_WARN(fmt,...)
Definition indilogger.h:81
#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
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
Definition lilxml.cpp:644
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
Definition lilxml.cpp:555
XMLAtt * findXMLAtt(XMLEle *ep, const char *name)
Find an XML attribute within an XML element.
Definition lilxml.cpp:524
LilXML * newLilXML()
Create a new lilxml parser.
Definition lilxml.cpp:150
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
Definition lilxml.cpp:600
XMLEle * addXMLEle(XMLEle *parent, const char *tag)
add an element with the given tag to the given element. parent can be NULL to make a new root.
Definition lilxml.cpp:670
XMLEle * findXMLEle(XMLEle *ep, const char *tag)
Find an XML element within an XML element.
Definition lilxml.cpp:537
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
Definition lilxml.cpp:624
void editXMLEle(XMLEle *ep, const char *pcdata)
set the pcdata of the given element
Definition lilxml.cpp:698
void prXMLEle(FILE *fp, XMLEle *ep, int level)
Print an XML element.
Definition lilxml.cpp:844
void delXMLEle(XMLEle *ep)
delXMLEle Delete XML element.
Definition lilxml.cpp:167
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Definition lilxml.cpp:606
void delLilXML(LilXML *lp)
Delete a lilxml parser.
Definition lilxml.cpp:159
XMLAtt * addXMLAtt(XMLEle *ep, const char *name, const char *valu)
Add an XML attribute to an existing XML element.
Definition lilxml.cpp:706
XMLEle * readXMLFile(FILE *fp, LilXML *lp, char ynot[])
Handy wrapper to read one xml file.
Definition lilxml.cpp:653
struct LilXML_ LilXML
Definition lilxml.h:82
struct xml_att_ XMLAtt
Definition lilxml.h:80
#define XML_ERROR_SIZE
Definition lilxml.h:73
struct xml_ele_ XMLEle
Definition lilxml.h:81
Namespace to encapsulate INDI client, drivers, and mediator classes.
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
uint16_t type
Definition pwc-ioctl.h:0
double y
Definition indidome.h:34
double x
Definition indidome.h:34
double z
Definition indidome.h:34