Instrument Neutral Distributed Interface INDI  2.0.2
ioptronv3driver.h
Go to the documentation of this file.
1 /*
2  INDI IOptron v3 Driver for firmware version 20171001 or later.
3 
4  Copyright (C) 2018 Jasem Mutlaq
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 #pragma once
22 
23 #include <string>
24 #include <map>
25 #include "indilogger.h"
26 
32 namespace IOPv3
33 {
34 
36 typedef enum
37 {
45  ST_HOME
48 typedef enum { SR_1 = 1, SR_2, SR_3, SR_4, SR_5, SR_6, SR_7, SR_8, SR_MAX } IOP_SLEW_RATE;
52 typedef enum { RA_AXIS, DEC_AXIS } IOP_AXIS;
53 typedef enum { IOP_N, IOP_S, IOP_W, IOP_E } IOP_DIRECTION;
58 
59 typedef struct
60 {
68  double longitude;
69  double latitude;
70 } IOPInfo;
71 
72 typedef struct
73 {
74  std::string Model;
75  std::string MainBoardFirmware;
76  std::string ControllerFirmware;
77  std::string RAFirmware;
78  std::string DEFirmware;
79 } FirmwareInfo;
80 
81 class Driver
82 {
83 
84  public:
85 
86  explicit Driver(const char *deviceName);
87  ~Driver() = default;
88 
89  static const std::map<std::string, std::string> models;
90  // Slew speeds. N.B. 1024 is arbitrary as the real max value different from
91  // one mount to another. It is used for simulation purposes only.
92  static const uint16_t IOP_SLEW_RATES[];
93 
94  /**************************************************************************
95  Communication
96  **************************************************************************/
97  bool sendCommand(const char *command, int count = 1, char *response = nullptr, uint8_t timeout = IOP_TIMEOUT,
98  uint8_t debugLog = INDI::Logger::DBG_DEBUG);
99  bool sendCommandOk(const char *command);
100  bool checkConnection(int fd);
101 
102  /**************************************************************************
103  Get Info
104  **************************************************************************/
106  bool getStatus(IOPInfo *info);
108  bool getFirmwareInfo(FirmwareInfo *info);
110  bool getCoords(double *ra, double *de, IOP_PIER_STATE *pierState, IOP_CW_STATE *cwState);
112  bool getUTCDateTime(double *JD, int *utcOffsetMinutes, bool *dayLightSaving);
113 
114  /**************************************************************************
115  Motion
116  **************************************************************************/
117  bool startMotion(IOP_DIRECTION dir);
118  bool stopMotion(IOP_DIRECTION dir);
119  bool setSlewRate(IOP_SLEW_RATE rate);
120  bool setCustomRATrackRate(double rate);
121  bool setTrackMode(IOP_TRACK_RATE rate);
122  bool setTrackEnabled(bool enabled);
123  /* v3.0 Add in PEC Control */
124  bool setPECEnabled(bool enabled); // start / stop PEC
125  bool setPETEnabled(bool enabled); // record / cancel PEC
126  bool getPETEnabled(bool enabled); // check data / recording status
127  // End Mod */
128  bool abort();
129  bool slewNormal();
130  bool slewCWUp();
131  bool sync();
132  bool setRA(double ra);
133  bool setDE(double de);
134 
135  /**************************************************************************
136  Home
137  **************************************************************************/
138  bool findHome();
139  bool gotoHome();
140  bool setCurrentHome();
141 
142  /**************************************************************************
143  Park
144  **************************************************************************/
145  bool park();
146  bool unpark();
147  bool setParkAz(double az);
148  bool setParkAlt(double alt);
149 
150  /**************************************************************************
151  Guide
152  **************************************************************************/
153  bool setGuideRate(double RARate, double DERate);
154  bool getGuideRate(double *RARate, double *DERate);
155  bool startGuide(IOP_DIRECTION dir, uint32_t ms);
156 
157  /**************************************************************************
158  Meridian Behavior
159  **************************************************************************/
160  bool setMeridianBehavior(IOP_MB_STATE action, uint8_t degrees);
161  bool getMeridianBehavior(IOP_MB_STATE &action, uint8_t &degrees);
162 
163  /**************************************************************************
164  Time & Location
165  **************************************************************************/
166  bool setLongitude(double longitude);
167  bool setLatitude(double latitude);
168  bool setUTCDateTime(double JD);
169  bool setUTCOffset(int offsetMinutes);
170  bool setDaylightSaving(bool enabled);
171 
172  /**************************************************************************
173  Misc.
174  **************************************************************************/
175  void setDebug(bool enable);
176  void setSimulation(bool enable);
177 
178  /**************************************************************************
179  Simulation
180  **************************************************************************/
181  void setSimGPSstatus(IOP_GPS_STATUS value);
183  void setSimTrackRate(IOP_TRACK_RATE value);
184  void setSimSlewRate(IOP_SLEW_RATE value);
185  void setSimTimeSource(IOP_TIME_SOURCE value);
186  void setSimHemisphere(IOP_HEMISPHERE value);
187  void setSimRA(double ra);
188  void setSimDE(double de);
189  void setSimLongLat(double longitude, double latitude);
190  void setSimGuideRate(double raRate, double deRate);
191 
192  protected:
193 
194  /**************************************************************************
195  Firmware Info
196  **************************************************************************/
198  bool getMainFirmware(std::string &mainFirmware, std::string &controllerFirmware);
200  bool getRADEFirmware(std::string &RAFirmware, std::string &DEFirmware);
202  bool getModel(std::string &model);
203 
204  struct
205  {
206  double ra;
207  double de;
210  double JD;
213  uint8_t mb_limit;
217 
220 
221  private:
222  int PortFD = { -1 };
223  bool m_Debug = {false};
224  bool m_Simulation = {false};
225  const char *m_DeviceName;
226 
227  // FD timeout in seconds
228  static const uint8_t IOP_TIMEOUT = 5;
229  // Buffer to store mount response
230  static const uint8_t IOP_BUFFER = 64;
231 };
232 
233 }
bool setTrackMode(IOP_TRACK_RATE rate)
void setSimulation(bool enable)
static const std::map< std::string, std::string > models
bool setPETEnabled(bool enabled)
bool setCustomRATrackRate(double rate)
IOP_CW_STATE cw_state
bool setDaylightSaving(bool enabled)
bool startGuide(IOP_DIRECTION dir, uint32_t ms)
bool setRA(double ra)
bool getUTCDateTime(double *JD, int *utcOffsetMinutes, bool *dayLightSaving)
bool setMeridianBehavior(IOP_MB_STATE action, uint8_t degrees)
void setSimGPSstatus(IOP_GPS_STATUS value)
void setSimSlewRate(IOP_SLEW_RATE value)
~Driver()=default
bool getPETEnabled(bool enabled)
bool getGuideRate(double *RARate, double *DERate)
bool getRADEFirmware(std::string &RAFirmware, std::string &DEFirmware)
bool sendCommand(const char *command, int count=1, char *response=nullptr, uint8_t timeout=IOP_TIMEOUT, uint8_t debugLog=INDI::Logger::DBG_DEBUG)
bool setGuideRate(double RARate, double DERate)
void setSimTrackRate(IOP_TRACK_RATE value)
bool getStatus(IOPInfo *info)
void setSimTimeSource(IOP_TIME_SOURCE value)
void setSimGuideRate(double raRate, double deRate)
bool setParkAz(double az)
bool setParkAlt(double alt)
bool setLatitude(double latitude)
Driver(const char *deviceName)
bool setLongitude(double longitude)
bool getCoords(double *ra, double *de, IOP_PIER_STATE *pierState, IOP_CW_STATE *cwState)
bool sendCommandOk(const char *command)
void setDebug(bool enable)
bool getMeridianBehavior(IOP_MB_STATE &action, uint8_t &degrees)
void setSimRA(double ra)
bool stopMotion(IOP_DIRECTION dir)
bool setTrackEnabled(bool enabled)
bool setSlewRate(IOP_SLEW_RATE rate)
bool checkConnection(int fd)
void setSimHemisphere(IOP_HEMISPHERE value)
IOP_MB_STATE mb_state
bool setDE(double de)
bool setUTCDateTime(double JD)
void setSimSytemStatus(IOP_SYSTEM_STATUS value)
void setSimLongLat(double longitude, double latitude)
bool setUTCOffset(int offsetMinutes)
struct IOPv3::Driver::@168 simData
void setSimDE(double de)
bool getFirmwareInfo(FirmwareInfo *info)
bool setPECEnabled(bool enabled)
bool startMotion(IOP_DIRECTION dir)
static const uint16_t IOP_SLEW_RATES[]
IOP_PIER_STATE pier_state
bool getMainFirmware(std::string &mainFirmware, std::string &controllerFirmware)
bool getModel(std::string &model)
int fd
Definition: intelliscope.c:43
Encapsulates classes and structures required for iOptron Command Set v3 implementation.
IOP_HOME_OPERATION
@ IOP_GOTO_HOME
@ IOP_FIND_HOME
@ IOP_SET_HOME
@ TS_CONTROLLER
@ FW_CONTROLLER
@ IOP_CW_NORMAL
@ IOP_PIER_EAST
@ IOP_PIER_WEST
@ IOP_PIER_UNKNOWN
@ ST_TRACKING_PEC_ON
@ ST_TRACKING_PEC_OFF
@ ST_MERIDIAN_FLIPPING
struct FirmwareInfo FirmwareInfo
std::string DEFirmware
std::string RAFirmware
std::string ControllerFirmware
std::string MainBoardFirmware
IOP_SYSTEM_STATUS rememberSystemStatus
IOP_GPS_STATUS gpsStatus
IOP_HEMISPHERE hemisphere
IOP_SYSTEM_STATUS systemStatus
IOP_TRACK_RATE trackRate
IOP_SLEW_RATE slewRate
IOP_TIME_SOURCE timeSource