Instrument Neutral Distributed Interface INDI  2.0.2
rainbow.h
Go to the documentation of this file.
1 /*
2  Rainbow Mount Driver
3  Copyright (C) 2020 Jasem Mutlaq (mutlaqja@ikarustech.com)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
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  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #pragma once
22 
23 #include "inditelescope.h"
24 #include "indiguiderinterface.h"
25 
26 #define ALIGNMENT_TAB "Alignment"
27 #define GENERAL_INFO_TAB "General Info"
28 
29 
31 {
32  public:
33  Rainbow();
34 
35  const char *getDefaultName() override;
36  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
37  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
38 
39  typedef enum { Equatorial, Horizontal } GotoType;
40  typedef enum { North, South, West, East } Direction;
41 
42  protected:
43  virtual bool initProperties() override;
44  virtual bool updateProperties() override;
45  virtual bool Handshake() override;
46 
50  // Is slew over?
51  virtual bool isSlewComplete();
52  // Goto
53  virtual bool Goto(double ra, double dec) override;
54  // Read mount state
55  virtual bool ReadScopeStatus() override;
56  // Abort
57  virtual bool Abort() override;
58  // N/S manual motion
59  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
60  // W/E manual motion
61  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
62  // Slew Rate
63  virtual bool SetSlewRate(int index) override;
64  // Syncing
65  virtual bool Sync(double ra, double dec) override;
66 
67  // RA/DE
68  bool getRA();
69  bool getDE();
70  bool setRA(double ra);
71  bool setDE(double de);
72  // Slew to RA/DE
73  bool slewToEquatorialCoords(double ra, double de);
74 
75 
79  // Toggle Tracking
80  virtual bool SetTrackEnabled(bool enabled) override;
81  virtual bool SetTrackMode(uint8_t mode) override;
82  bool getTrackingState();
83 
87  void getStartupStatus();
88  bool getFirmwareVersion();
89 
93  virtual bool updateLocation(double latitude, double longitude, double elevation) override;
94  //virtual bool updateTime(ln_date *utc, double utc_offset) override;
95 
99  virtual IPState GuideNorth(uint32_t ms) override;
100  virtual IPState GuideSouth(uint32_t ms) override;
101  virtual IPState GuideEast(uint32_t ms) override;
102  virtual IPState GuideWest(uint32_t ms) override;
103 
104  static void guideTimeoutHelperN(void *p);
105  static void guideTimeoutHelperS(void *p);
106  static void guideTimeoutHelperW(void *p);
107  static void guideTimeoutHelperE(void *p);
108 
109  IPState guide(Direction direction, uint32_t ms);
110  void guideTimeout(Direction direction);
111  void addGuideTimer(Direction direction, uint32_t ms);
112  bool setGuideRate(double rate);
113  bool getGuideRate();
114 
118  // Parking
119  virtual bool Park() override;
120  virtual bool UnPark() override;
121  virtual bool SetCurrentPark() override;
122  virtual bool SetDefaultPark() override;
123  // Homing
124  bool findHome();
125  bool checkHoming();
126 
130  bool sendScopeTime();
131  bool sendScopeLocation();
132  bool getUTFOffset(double *offset);
133  bool getLocalDate(char *dateString);
134  bool getLocalTime(char *timeString);
135 
139  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
140  void hexDump(char * buf, const char * data, int size);
141  std::vector<std::string> split(const std::string &input, const std::string &regex);
142 
143  private:
144 
145  // Horizontal Coordinates functions.
146  bool getAZ();
147  bool getAL();
148  bool setAZ(double azimuth);
149  bool setAL(double altitude);
150  bool slewToHorizontalCoords(double azimuth, double altitude);
151 
152  // Set and get slew speeds
153  bool setSlewSpeedVal(int speedtype, double rate);
154  bool getSlewSpeedVal(int speedtype);
155 
159  ISwitchVectorProperty HomeSP;
160  ISwitch HomeS[1];
161 
162  ISwitchVectorProperty SaveAlignBeforeSyncSP;
163  ISwitch SaveAlignBeforeSyncS[2];
164  enum { STAR_ALIGNMENT_DISABLED, STAR_ALIGNMENT_ENABLED};
165 
166  IText RSTVersionsT[2];
167  ITextVectorProperty RSTVersionsTP;
168  enum { FIRMWARE, SERIALNUMBER };
169 
170  ISwitchVectorProperty PullVoltTempSP;
171  ISwitch PullVoltTempS[2];
172  enum { PULL_VOLTTEMP_DISABLED, PULL_VOLTTEMP_ENABLED};
173 
174  INumber RSTVoltTempN[4];
175  INumberVectorProperty RSTVoltTempNP;
176  enum { VOLTAGE, BOARD_TEMPERATURE, RA_M_TEMPERATURE, DE_M_TEMPERATURE };
177 
178  INumber RSTMotorPowN[2];
179  INumberVectorProperty RSTMotorPowNP;
180  enum { RA_M_POWER, DE_M_POWER };
181 
182  INumberVectorProperty HorizontalCoordsNP;
183  INumber HorizontalCoordsN[2];
184 
185  INumber GuideRateN[1];
186  INumberVectorProperty GuideRateNP;
187 
188  INumberVectorProperty SlewSpeedsNP;
189  INumber SlewSpeedsN[3];
190  enum { SLEW_SPEED_MAX, SLEW_SPEED_FIND, SLEW_SPEED_CENTERING };
191 
192  const std::string getSlewErrorString(uint8_t code);
193  uint8_t m_SlewErrorCode {0};
194 
195  GotoType m_GotoType { Equatorial };
196  double m_CurrentAZ {0}, m_CurrentAL {0};
197  double m_CurrentRA {0}, m_CurrentDE {0};
198  std::string m_Version;
199  int m_GuideNSTID {0};
200  int m_GuideWETID {0};
201 
205  static constexpr const char * INFO_TAB = "Info";
206  // '#' is the stop char
207  static const char DRIVER_STOP_CHAR { 0x23 };
208  // Wait up to a maximum of 3 seconds for serial input
209  static constexpr const uint8_t DRIVER_TIMEOUT {3};
210  // Maximum buffer for sending/receving.
211  static constexpr const uint8_t DRIVER_LEN {64};
212 };
virtual bool Sync(double ra, double dec) override
Sync.
Definition: rainbow.cpp:1117
virtual IPState GuideNorth(uint32_t ms) override
Guiding.
Definition: rainbow.cpp:1207
void guideTimeout(Direction direction)
Guide Timeout.
Definition: rainbow.cpp:1367
static void guideTimeoutHelperN(void *p)
Guide Timeout North.
Definition: rainbow.cpp:1335
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
Definition: rainbow.cpp:140
bool getTrackingState()
Definition: rainbow.cpp:479
virtual bool Goto(double ra, double dec) override
Slew RA/DE.
Definition: rainbow.cpp:798
bool checkHoming()
bool findHome()
Definition: rainbow.cpp:496
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: rainbow.cpp:185
virtual bool SetSlewRate(int index) override
Set Slew Rate.
Definition: rainbow.cpp:1166
virtual IPState GuideEast(uint32_t ms) override
Guide East.
Definition: rainbow.cpp:1223
virtual bool SetTrackMode(uint8_t mode) override
Set Track Mode.
Definition: rainbow.cpp:1145
virtual IPState GuideWest(uint32_t ms) override
Guide West.
Definition: rainbow.cpp:1231
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition: rainbow.cpp:60
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Abort.
Definition: rainbow.cpp:1022
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: rainbow.cpp:278
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Location & Time.
Definition: rainbow.cpp:389
virtual bool SetTrackEnabled(bool enabled) override
Tracking Functions.
Definition: rainbow.cpp:469
void getStartupStatus()
Query Functions.
Definition: rainbow.cpp:350
void hexDump(char *buf, const char *data, int size)
Definition: rainbow.cpp:1729
bool getFirmwareVersion()
Definition: rainbow.cpp:437
const char * getDefaultName() override
Definition: rainbow.cpp:52
virtual bool Park() override
Parking & Homing.
Definition: rainbow.cpp:586
virtual bool Handshake() override
perform handshake with device to check communication
Definition: rainbow.cpp:429
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition: rainbow.cpp:576
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition: rainbow.cpp:566
bool sendScopeLocation()
Get Location from mount.
Definition: rainbow.cpp:1592
bool sendScopeTime()
Location & Time.
Definition: rainbow.cpp:1517
Rainbow()
Definition: rainbow.cpp:34
static void guideTimeoutHelperS(void *p)
Guide Timeout South.
Definition: rainbow.cpp:1343
bool getLocalDate(char *dateString)
Get Date from mount.
Definition: rainbow.cpp:1452
bool sendCommand(const char *cmd, char *res=nullptr, int cmd_len=-1, int res_len=-1)
Communication Functions.
Definition: rainbow.cpp:1662
IPState guide(Direction direction, uint32_t ms)
Guide universal function.
Definition: rainbow.cpp:1239
static void guideTimeoutHelperW(void *p)
Guide Timeout West.
Definition: rainbow.cpp:1351
std::vector< std::string > split(const std::string &input, const std::string &regex)
Definition: rainbow.cpp:1741
static void guideTimeoutHelperE(void *p)
Guide Timeout East.
Definition: rainbow.cpp:1359
virtual bool UnPark() override
Unparking.
Definition: rainbow.cpp:607
bool setRA(double ra)
Set Target RA.
Definition: rainbow.cpp:882
bool getLocalTime(char *timeString)
Get Time from mount.
Definition: rainbow.cpp:1424
void addGuideTimer(Direction direction, uint32_t ms)
Add guide timer.
Definition: rainbow.cpp:1402
bool getUTFOffset(double *offset)
GET UTC offset from mount.
Definition: rainbow.cpp:1489
bool setDE(double de)
Set Target Altitude.
Definition: rainbow.cpp:902
bool getDE()
Get DE.
Definition: rainbow.cpp:868
virtual IPState GuideSouth(uint32_t ms) override
Guide South.
Definition: rainbow.cpp:1215
virtual bool Abort() override
Abort.
Definition: rainbow.cpp:1084
Direction
Definition: rainbow.h:40
@ West
Definition: rainbow.h:40
@ South
Definition: rainbow.h:40
@ East
Definition: rainbow.h:40
@ North
Definition: rainbow.h:40
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
W/E Motion.
Definition: rainbow.cpp:1053
bool slewToEquatorialCoords(double ra, double de)
Slew to Equatorial Coordinates.
Definition: rainbow.cpp:922
virtual bool isSlewComplete()
Motion Functions.
Definition: rainbow.cpp:626
bool setGuideRate(double rate)
Definition: rainbow.cpp:504
bool getGuideRate()
Definition: rainbow.cpp:514
virtual bool ReadScopeStatus() override
Read telescope status.
Definition: rainbow.cpp:667
bool getRA()
Get RA.
Definition: rainbow.cpp:855
GotoType
Definition: rainbow.h:39
@ Equatorial
Definition: rainbow.h:39
@ Horizontal
Definition: rainbow.h:39
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
INDI_DIR_WE
Definition: indibasetypes.h:55
INDI_DIR_NS
Definition: indibasetypes.h:48
__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