Instrument Neutral Distributed Interface INDI  2.0.2
nexdome_beaver.h
Go to the documentation of this file.
1 /*
2  NexDome Beaver Controller
3 
4  Copyright (C) 2021 Jasem Mutlaq (mutlaqja@ikarustech.com)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include <memory>
25 #include <indidome.h>
26 #include <indipropertytext.h>
27 #include <indipropertyswitch.h>
28 #include <indipropertynumber.h>
29 
30 class Beaver : public INDI::Dome
31 {
32  public:
33  Beaver();
34  virtual ~Beaver() override = default;
35 
36  const char *getDefaultName() override;
37  virtual bool initProperties() override;
38  virtual bool updateProperties() override;
39  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
40  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
41 
42  protected:
43  bool Handshake() override;
44  virtual void TimerHit() override;
45 
46  // Rotator
47  virtual IPState MoveAbs(double az) override;
48  virtual IPState MoveRel(double azDiff) override;
49  virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override;
50  virtual bool SetCurrentPark() override;
51  virtual bool SetDefaultPark() override;
52 
53  // Shutter
54  virtual IPState ControlShutter(ShutterOperation operation) override;
55 
56  // Abort
57  virtual bool Abort() override;
58 
59  // Config
60  virtual bool saveConfigItems(FILE * fp) override;
61 
62  // Parking
63  virtual IPState Park() override;
64  virtual IPState UnPark() override;
65 
66  // Beaver status
67  enum
68  {
82  };
83 
84  private:
85 
89  bool echo();
90 
94  bool rotatorGotoAz(double az);
95  bool rotatorGetAz();
96  bool rotatorSyncAZ(double az);
97  bool rotatorSetHome(double az);
98  bool rotatorSetPark(double az);
99  bool rotatorGotoPark();
100  bool rotatorGotoHome();
101  bool rotatorMeasureHome();
102  bool rotatorFindHome();
103  bool rotatorIsHome();
104  bool rotatorIsParked();
105  bool rotatorUnPark();
106  bool rotatorSetPark();
107  bool abortAll();
108 
109  bool rotatorGetSettings();
110  bool rotatorSetSettings(double maxSpeed, double minSpeed, double acceleration, double timeout);
111 
115  //bool shutterSetSettings(double maxSpeed, double minSpeed, double acceleration, double timeout, double voltage);
116  bool shutterSetSettings(double maxSpeed, double minSpeed, double acceleration, double voltage);
117 
118  bool shutterGetSettings();
119  bool shutterFindHome();
120  bool shutterAbort();
121  bool shutterOnLine();
122 
126  bool sendCommand(const char * cmd, double &res);
127  bool sendRawCommand(const char * cmd, char *resString);
128  bool getDomeStatus(uint16_t &domeStatus);
129  void hexDump(char * buf, const char * data, int size);
130  std::vector<std::string> split(const std::string &input, const std::string &regex);
131 
135  // Beaver Firmware Version
136  INDI::PropertyText VersionTP {1};
137  // Home offset from north
138  INDI::PropertyNumber HomePositionNP {1};
139  // Home set options
140  INDI::PropertySwitch HomeOptionsSP {2};
141  enum
142  {
143  HOMECURRENT,
144  HOMEDEFAULT
145  };
146 
147  // Goto Home
148  INDI::PropertySwitch GotoHomeSP {1};
149  // Shutter voltage
150  INDI::PropertyNumber ShutterVoltsNP {1};
151  // Rotator Status
152  INDI::PropertyText RotatorStatusTP {1};
153  // Shutter Status
154  INDI::PropertyText ShutterStatusTP {1};
155  // Rotator Calibration
156  INDI::PropertySwitch RotatorCalibrationSP {2};
157  enum
158  {
159  ROTATOR_HOME_FIND,
160  ROTATOR_HOME_MEASURE
161  };
162  // Shutter Calibration
163  INDI::PropertySwitch ShutterCalibrationSP {1};
164  enum
165  {
166  SHUTTER_HOME_FIND
167  };
168  // Shutter Configuration
169  INDI::PropertyNumber ShutterSettingsNP {4};
170  enum
171  {
172  SHUTTER_MAX_SPEED,
173  SHUTTER_MIN_SPEED,
174  SHUTTER_ACCELERATION,
175  SHUTTER_SAFE_VOLTAGE
176  };
177  INDI::PropertyNumber ShutterSettingsTimeoutNP {1};
178 
179  // Rotator Configuration
180  INDI::PropertyNumber RotatorSettingsNP {4};
181  enum
182  {
183  ROTATOR_MAX_SPEED,
184  ROTATOR_MIN_SPEED,
185  ROTATOR_ACCELERATION,
186  ROTATOR_TIMEOUT
187  };
188 
192  double m_TargetRotatorAz {-1};
193 
197  static constexpr const char * ROTATOR_TAB = "Rotator";
198  static constexpr const char * SHUTTER_TAB = "Shutter";
199  // '#' is the stop char
200  static const char DRIVER_STOP_CHAR { 0x23 };
201  // Wait up to a maximum of 3 seconds for serial input
202  static constexpr const uint8_t DRIVER_TIMEOUT {3};
203  // Maximum buffer for sending/receving.
204  static constexpr const uint8_t DRIVER_LEN {128};
205  int domeDir = 1;
206  double lastAzDiff = 1;
207 };
virtual IPState UnPark() override
Rotator unpark.
virtual IPState ControlShutter(ShutterOperation operation) override
open or close the shutter (will not show if shutter is not present)
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Rotator move (calc's offset and calles abs move)
virtual IPState MoveRel(double azDiff) override
Rotator relative move (calc's offset and calles abs move)
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual ~Beaver() override=default
virtual IPState Park() override
Rotator park.
virtual bool SetCurrentPark() override
Rotator set park position to current.
virtual void TimerHit() override
Timer hit - update appropriate fields.
virtual bool SetDefaultPark() override
Rotator set park position to default (0 az)
virtual bool Abort() override
abort everything
const char * getDefaultName() override
Set default name.
bool Handshake() override
Handshake.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
@ DOME_STATUS_SHUTTER_CLOSING
@ DOME_STATUS_SHUTTER_COMM
@ DOME_STATUS_SHUTTER_OPENED
@ DOME_STATUS_UNSAFE_RG
@ DOME_STATUS_ROTATOR_PARKED
@ DOME_STATUS_SHUTTER_CLOSED
@ DOME_STATUS_ROTATOR_MOVING
@ DOME_STATUS_SHUTTER_MOVING
@ DOME_STATUS_SHUTTER_OPENING
@ DOME_STATUS_SHUTTER_ERROR
@ DOME_STATUS_ROTATOR_HOME
@ DOME_STATUS_ROTATOR_ERROR
@ DOME_STATUS_UNSAFE_CW
virtual IPState MoveAbs(double az) override
Rotator absolute move.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Number field updated.
virtual bool saveConfigItems(FILE *fp) override
INDI save config.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Switch field updated.
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