Instrument Neutral Distributed Interface INDI  2.0.2
rigel_dome.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Rigel Systems Dome INDI Driver
3 
4  Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
5 
6  Based on Protocol extracted from https://github.com/rpineau/RigelDome
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 #pragma once
23 
24 #include "indidome.h"
25 
26 class RigelDome : public INDI::Dome
27 {
28  public:
33 
34  RigelDome();
35  virtual ~RigelDome() override = default;
36 
37  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
38  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
39  virtual const char *getDefaultName() override;
40 
41  protected:
42  virtual bool initProperties() override;
43  virtual bool updateProperties() override;
44 
45  virtual bool Handshake() override;
46  virtual void TimerHit() override;
47 
48  virtual IPState MoveRel(double azDiff) override;
49  virtual IPState MoveAbs(double az) override;
50  virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override;
51  virtual IPState ControlShutter(ShutterOperation operation) override;
52  virtual bool Abort() override;
53  virtual bool Sync(double az) override;
54 
55  // Parking
56  virtual IPState Park() override;
57  virtual IPState UnPark() override;
58  virtual bool SetCurrentPark() override;
59  virtual bool SetDefaultPark() override;
60 
61  private:
62  ShutterOperation m_TargetShutter { SHUTTER_OPEN };
63 
64  RigelShutterState m_rawShutterState {S_UnKnown};
65  RigelMotorState m_rawMotorState {M_Idle};
66  double targetAz { 0 };
67 
71  bool setShutterConnected(bool enabled);
72  bool isShutterConnected();
73  bool readShutterStatus();
74  ShutterState parseShutterState(int state);
75 
79  bool readFirmware();
80  bool readModel();
81  bool readPosition();
82  bool readHomePosition();
83  bool getStartupValues();
84  bool readState();
85  bool readBatteryLevels();
86  bool readStepsPerRevolution();
87 
91  bool setParkAz(double az);
92  bool home();
93  bool calibrate();
94  bool setHome(double az);
95 
99  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
100  void hexDump(char * buf, const char * data, int size);
101  std::vector<std::string> split(const std::string &input, const std::string &regex);
102 
106  ISwitchVectorProperty OperationSP;
107  ISwitch OperationS[2];
108  enum
109  {
110  OPERATION_FIND_HOME,
111  OPERATION_CALIBRATE,
112  };
113 
114  // Info
115  ITextVectorProperty InfoTP;
116  IText InfoT[4] {};
117  enum
118  {
119  INFO_FIRMWARE,
120  INFO_MODEL,
121  INFO_TICKS,
122  INFO_BATTERY,
123  };
124 
125  // Home angle
126  INumber HomePositionN[1];
127  INumberVectorProperty HomePositionNP;
128 
132  static constexpr const char * INFO_TAB = "Info";
133  // 0xD is the stop char
134  static const char DRIVER_STOP_CHAR { 0x0D };
135  // Wait up to a maximum of 3 seconds for serial input
136  static constexpr const uint8_t DRIVER_TIMEOUT {3};
137  // Maximum buffer for sending/receving.
138  static constexpr const uint8_t DRIVER_LEN {64};
139 };
Class to provide general functionality of a Dome device.
Definition: indidome.h:75
ShutterOperation
Shutter operation command.
Definition: indidome.h:114
@ SHUTTER_OPEN
Definition: indidome.h:115
DomeMotionCommand
Definition: indidome.h:97
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition: rigel_dome.cpp:471
@ M_MovingToVelocity
Definition: rigel_dome.h:30
@ M_MovingCW
Definition: rigel_dome.h:31
@ M_MovingAtSideral
Definition: rigel_dome.h:30
@ M_MovingCCW
Definition: rigel_dome.h:31
@ M_Calibrating
Definition: rigel_dome.h:31
@ M_MovingToTarget
Definition: rigel_dome.h:30
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition: rigel_dome.cpp:480
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
Definition: rigel_dome.cpp:419
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
Definition: rigel_dome.cpp:411
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: rigel_dome.cpp:174
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: rigel_dome.cpp:245
virtual bool Sync(double az) override
Sync sets the dome current azimuth as the supplied azimuth position.
Definition: rigel_dome.cpp:342
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: rigel_dome.cpp:56
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
Definition: rigel_dome.cpp:765
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
Definition: rigel_dome.cpp:312
virtual bool Abort() override
Abort all dome motion.
Definition: rigel_dome.cpp:440
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
Definition: rigel_dome.cpp:356
virtual ~RigelDome() override=default
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: rigel_dome.cpp:149
RigelShutterState
Definition: rigel_dome.h:29
@ S_NotFitted
Definition: rigel_dome.h:29
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: rigel_dome.cpp:223
virtual const char * getDefaultName() override
Definition: rigel_dome.cpp:141
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
Definition: rigel_dome.cpp:326
virtual bool Handshake() override
perform handshake with device to check communication
Definition: rigel_dome.cpp:123
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