Instrument Neutral Distributed Interface INDI  2.0.2
domepro2.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2020 Jasem Mutlaq. All rights reserved.
3 
4  Astrometric Solutions DomePro2 INDI Driver
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9  .
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14  .
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 
21 #pragma once
22 
23 #include "indidome.h"
24 #include <map>
25 
26 class DomePro2 : public INDI::Dome
27 {
28  public:
29  DomePro2();
30  virtual ~DomePro2() override = default;
31 
32  virtual const char *getDefaultName() override;
33  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
34  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
35  virtual bool saveConfigItems(FILE *fp) override;
36 
37 
38  protected:
39  virtual bool initProperties() override;
40  virtual bool updateProperties() override;
41 
42  virtual bool Handshake() override;
43  virtual void TimerHit() override;
44 
45  virtual IPState MoveRel(double azDiff) override;
46  virtual IPState MoveAbs(double az) override;
47  virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override;
48  virtual IPState ControlShutter(ShutterOperation operation) override;
49  virtual bool Abort() override;
50  virtual bool Sync(double az) override;
51 
52  // Parking
53  virtual IPState Park() override;
54  virtual IPState UnPark() override;
55  virtual bool SetCurrentPark() override;
56  virtual bool SetDefaultPark() override;
57 
58  private:
59 
60  // ShutterOperation m_TargetShutter { SHUTTER_OPEN }; // #PS: unused
61  double targetAz {0};
62 
66  bool setupInitialParameters();
67  uint8_t processShutterStatus();
68 
69 
73  bool getFirmwareVersion();
74  bool getHardwareConfig();
75  bool getDomeStatus();
76  bool getShutterStatus();
77  bool getDomeAzCPR();
78  bool getDomeAzCoast();
79  bool getDomeAzPos();
80  bool getDomeHomeAz();
81  bool getDomeParkAz();
82  bool getDomeAzStallCount();
83 
84 
88  bool setDomeAzCPR(uint32_t cpr);
89  bool gotoDomeAz(uint32_t az);
90  bool setDomeAzCoast(uint32_t coast);
91  bool killDomeAzMovement();
92  bool killDomeShutterMovement();
93  bool setDomeHomeAz(uint32_t az);
94  bool setDomeParkAz(uint32_t az);
95  bool setDomeAzStallCount(uint32_t steps);
96  bool calibrateDomeAz(double az);
97  bool gotoDomePark();
98  bool openDomeShutters();
99  bool closeDomeShutters();
100  bool gotoHomeDomeAz();
101  bool discoverHomeDomeAz();
102  bool setDomeLeftOn();
103  bool setDomeRightOn();
104 
105 
109 
110 
114 
126  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
127  void hexDump(char * buf, const char * data, int size);
128  std::vector<std::string> split(const std::string &input, const std::string &regex);
129 
133  ITextVectorProperty VersionTP;
134  IText VersionT[2] {};
135  enum
136  {
137  VERSION_FIRMWARE,
138  VERSION_HARDWARE
139  };
140 
141  ISwitchVectorProperty HomeSP;
142  ISwitch HomeS[2] {};
143  enum
144  {
145  HOME_DISCOVER,
146  HOME_GOTO
147  };
148 
149  ITextVectorProperty StatusTP;
150  IText StatusT[2] {};
151  enum
152  {
153  STATUS_DOME,
154  STATUS_SHUTTER
155  };
156 
157  INumberVectorProperty SettingsNP;
158  INumber SettingsN[5];
159  enum
160  {
161  SETTINGS_AZ_CPR,
162  SETTINGS_AZ_COAST,
163  SETTINGS_AZ_HOME,
164  SETTINGS_AZ_PARK,
165  SETTINGS_AZ_STALL_COUNT
166  };
167 
171  static constexpr const char * INFO_TAB = "Info";
172  static constexpr const char * SETTINGS_TAB = "Settings";
173  // 0x3B is the stop char
174  static const char DRIVER_STOP_CHAR { 0x3B };
175  // Wait up to a maximum of 3 seconds for serial input
176  static constexpr const uint8_t DRIVER_TIMEOUT {3};
177  // Maximum buffer for sending/receving.
178  static constexpr const uint8_t DRIVER_LEN {64};
179  // Dome AZ Threshold
180  static constexpr const double DOME_AZ_THRESHOLD {0.01};
181  // Dome hardware types
182  const std::map<uint8_t, std::string> DomeHardware =
183  {
184  {0x0D, "DomePro2-d for classic domes"},
185  {0x0E, "DomePro2-c for clamcshell domes"},
186  {0x0F, "DomePro2-r for roll-off roof"}
187  };
188  // Shutter statuses
189  const std::map<uint8_t, std::string> ShutterStatus =
190  {
191  {0x00, "Opened"},
192  {0x01, "Closed"},
193  {0x02, "Opening"},
194  {0x03, "Closing"},
195  {0x04, "ShutterError"},
196  {0x05, "shutter module is not communicating to the azimuth module"},
197  {0x06, "shutter 1 opposite direction timeout error on open occurred"},
198  {0x07, "shutter 1 opposite direction timeout error on close occurred"},
199  {0x08, "shutter 2 opposite direction timeout error on open occurred"},
200  {0x09, "shutter 2 opposite direction timeout error on close occurred"},
201  {0x0A, "shutter 1 completion timeout error on open occurred"},
202  {0x0B, "shutter 1 completion timeout error on close occurred"},
203  {0x0C, "shutter 2 completion timeout error on open occurred"},
204  {0x0D, "shutter 2 completion timeout error on close occurred"},
205  {0x0E, "shutter 1 limit fault on open occurred"},
206  {0x0F, "shutter 1 limit fault on close occurred"},
207  {0x10, "shutter 2 limit fault on open occurred"},
208  {0x11, "shutter 2 limit fault on close occurred"},
209  {0x12, "Shutter disabled (Shutter Enable input is not asserted)"},
210  {0x13, "Intermediate"},
211  {0x14, "GoTo"},
212  {0x15, "shutter 1 OCP trip on open occurred"},
213  {0x16, "shutter 1 OCP trip on close occurred"},
214  {0x17, "shutter 2 OCP trip on open occurred"},
215  {0x18, "shutter 2 OCP trip on close occurred"}
216  };
217  // Dome statuses
218  const std::map<std::string, std::string> DomeStatus =
219  {
220  {"Fixed", "Idle"},
221  {"Left", "Moving Left"},
222  {"Right", "Moving Right"},
223  {"Goto", "GoTo"},
224  {"Homing", "Homing"},
225  {"Parking", "Parking"},
226  {"Gauging", "Gauging"},
227  {"Timeout", "Azimuth movement timeout"},
228  {"Stall", "Azimuth encoder registering insufficent counts… motor stalled"},
229  {"OCP", "Over Current Protection was tripped"}
230  };
231 
232 
233 
234 };
DomePro2()
Definition: domepro2.cpp:35
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: domepro2.cpp:291
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
Definition: domepro2.cpp:421
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
Definition: domepro2.cpp:429
virtual bool Sync(double az) override
Sync sets the dome current azimuth as the supplied azimuth position.
Definition: domepro2.cpp:374
virtual const char * getDefaultName() override
Definition: domepro2.cpp:125
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: domepro2.cpp:160
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition: domepro2.cpp:485
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
Definition: domepro2.cpp:358
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
Definition: domepro2.cpp:346
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: domepro2.cpp:47
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition: domepro2.cpp:494
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
Definition: domepro2.cpp:385
virtual bool Handshake() override
perform handshake with device to check communication
Definition: domepro2.cpp:117
virtual bool Abort() override
Abort all dome motion.
Definition: domepro2.cpp:447
virtual ~DomePro2() override=default
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
Definition: domepro2.cpp:475
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
Definition: domepro2.cpp:411
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: domepro2.cpp:214
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: domepro2.cpp:133
Class to provide general functionality of a Dome device.
Definition: indidome.h:75
ShutterOperation
Shutter operation command.
Definition: indidome.h:114
DomeMotionCommand
Definition: indidome.h:97
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246