Debian Codegraph @

drivers/telescope/ieqdriverbase.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 IEQ Pro driver
3
4 Copyright (C) 2015 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 <vector>
25
26 namespace iEQ
27 {
28
29 typedef enum { GPS_OFF, GPS_ON, GPS_DATA_OK } GPSStatus;
30 typedef enum
31 {
32 ST_STOPPED,
33 ST_TRACKING_PEC_OFF,
34 ST_SLEWING,
35 ST_GUIDING,
36 ST_MERIDIAN_FLIPPING,
37 ST_TRACKING_PEC_ON,
38 ST_PARKED,
39 ST_HOME
40 } SystemStatus;
41
42 typedef enum { TR_SIDEREAL, TR_LUNAR, TR_SOLAR, TR_KING, TR_CUSTOM } TrackRate;
43 typedef enum { SR_1, SR_2, SR_3, SR_4, SR_5, SR_6, SR_7, SR_8, SR_MAX } SlewRate;
44 typedef enum { TS_RS232, TS_CONTROLLER, TS_GPS } TimeSource;
45 typedef enum { HEMI_SOUTH, HEMI_NORTH } Hemisphere;
46 typedef enum { FW_MODEL, FW_BOARD, FW_CONTROLLER, FW_RA, FW_DEC } FirmwareItem;
47 typedef enum { RA_AXIS, DEC_AXIS } Axis;
48 typedef enum { IEQ_N, IEQ_S, IEQ_W, IEQ_E } Direction;
49 typedef enum { IEQ_SET_HOME, IEQ_GOTO_HOME, IEQ_FIND_HOME } HomeOperation;
50
51 typedef enum { IEQ_PIER_UNKNOWN = -1, IEQ_PIER_WEST = 0, IEQ_PIER_EAST = 1, IEQ_PIER_UNCERTAIN = 2 } IEQ_PIER_SIDE;
52
53 /**
54 * @brief The BaseFirmware class provides control for iOptron version 2014 v2.0 protocol
55 */
56 class Base
57 {
58 public:
59
60 Base();
61 virtual ~Base() = default;
62
63 typedef struct
64 {
65 GPSStatus gpsStatus;
66 SystemStatus systemStatus;
67 SystemStatus rememberSystemStatus;
68 TrackRate trackRate;
69 SlewRate slewRate;
70 TimeSource timeSource;
71 Hemisphere hemisphere;
72 double longitude;
73 double latitude;
74 } Info;
75
76 typedef struct
77 {
78 std::string Model;
79 std::string MainBoardFirmware;
80 std::string ControllerFirmware;
81 std::string RAFirmware;
82 std::string DEFirmware;
83 } FirmwareInfo;
84
85 typedef struct
86 {
87 std::string code;
88 std::string model;
89 std::string firmware;
90 } MountInfo;
91
92 void setDebugEnabled(bool enable)
93 {
94 m_IsDebug = enable;
95 }
96 void setDeviceName(const std::string &name)
97 {
98 m_DeviceName = name;
99 }
100 const char *getDeviceName()
101 {
102 return m_DeviceName.c_str();
103 }
104
105 /**************************************************************************
106 Get Info
107 **************************************************************************/
108 /** Get iEQ current status info */
109 bool getStatus(Info *info);
110 /** Initilizes communication with the mount and gets mount model */
111 bool getModel();
112 /** Get mainboard and controller firmware only */
113 bool getMainFirmware();
114 /** Get RA and DEC firmware info */
115 bool getRADEFirmware();
116 /** Get RA/DEC */
117 bool getCoords(double *ra, double *dec);
118 /** Get UTC/Date/Time */
119 bool getUTCDateTime(double *utc_hours, int *yy, int *mm, int *dd, int *hh, int *minute, int *ss);
120 /** Get firmware information */
121 const FirmwareInfo &getFirmwareInfo() const
122 {
123 return m_FirmwareInfo;
124 }
125
126 bool getPierSide(IEQ_PIER_SIDE * pierSide);
127 private:
128 // read from mount using the GEA command
129 double haAxis; // not sure, try degrees to start with
130 double decAxis; // degrees, zero at 90 dec, sign determines pointing state
131 double Ra; // read from mount
132 double Dec;
133 Info info;
134 public:
135
136 /**************************************************************************
137 Communication
138 **************************************************************************/
139 /**
140 * @brief initCommunication Checks if communication with the mount is working
141 * @param fd file descriptor
142 * @param deviceName name of device used to log debugging messages.
143 * @return True if communication is successful, false otherwise.
144 */
145 bool initCommunication(int fd);
146
147 /**
148 * @brief sendCommand Send a string command to device.
149 * @param cmd Command to be sent. Can be either NULL TERMINATED or just byte buffer.
150 * @param res If not nullptr, the function will wait for a response from the device. If nullptr, it returns true immediately
151 * after the command is successfully sent.
152 * @param cmd_len if -1, it is assumed that the @a cmd is a null-terminated string. Otherwise, it would write @a cmd_len bytes from
153 * the @a cmd buffer.
154 * @param res_len if -1 and if @a res is not nullptr, the function will read until it detects the default delimeter DRIVER_STOP_CHAR
155 * up to DRIVER_LEN length. Otherwise, the function will read @a res_len from the device and store it in @a res.
156 * @return True if successful, false otherwise.
157 */
158 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
159
160 /**
161 * @brief hexDump Helper function to print non-string commands to the logger so it is easier to debug
162 * @param buf buffer to format the command into hex strings.
163 * @param data the command
164 * @param size length of the command in bytes.
165 * @note This is called internally by sendCommand, no need to call it directly.
166 */
167 void hexDump(char * buf, const char * data, int size);
168
169 /**
170 * @brief isCommandSupported Check if specific iOptron command is supported for this mount model
171 * @param command command code (e.g. MS)
172 * @param silent if false (default), it will report why command is not supported. If true, it will not print any messages.
173 * @return True if supported, false otherwise
174 */
175 bool isCommandSupported(const std::string &command, bool silent = false);
176
177
178 /**************************************************************************
179 Motion
180 **************************************************************************/
181 virtual bool startMotion(Direction dir);
182 virtual bool stopMotion(Direction dir);
183 virtual bool setSlewRate(SlewRate rate);
184 virtual bool setCustomRATrackRate(double rate);
185 virtual bool setTrackMode(TrackRate rate);
186 virtual bool setTrackEnabled(bool enabled);
187 virtual bool abort();
188 virtual bool slew();
189 virtual bool sync();
190 virtual bool setRA(double ra);
191 virtual bool setDE(double dec);
192 virtual bool setAz(double az);
193 virtual bool setAlt(double alt);
194
195 /**************************************************************************
196 Home
197 **************************************************************************/
198 virtual bool findHome();
199 virtual bool gotoHome();
200 virtual bool setCurrentHome();
201
202 /**************************************************************************
203 Park
204 **************************************************************************/
205 virtual bool park();
206 virtual bool unpark();
207 virtual bool setParkAz(double az);
208 virtual bool setParkAlt(double alt);
209
210 /**************************************************************************
211 Guide
212 **************************************************************************/
213 virtual bool setGuideRate(double raRate, double deRate);
214 virtual bool getGuideRate(double * raRate, double * deRate);
215 virtual bool startGuide(Direction dir, uint32_t ms);
216
217 /**************************************************************************
218 Time & Location
219 **************************************************************************/
220 virtual bool setLongitude(double longitude);
221 virtual bool setLatitude(double latitude);
222 virtual bool setLocalDate(int yy, int mm, int dd);
223 virtual bool setLocalTime(int hh, int mm, int ss);
224 virtual bool setUTCOffset(double offset_hours);
225 virtual bool setDST(bool enabled);
226
227 protected:
228
229 int m_PortFD {-1};
230 std::string m_DeviceName { "iEQ" };
231 bool m_IsDebug { false };
232 static const uint8_t DRIVER_TIMEOUT { 3 };
233 static const uint8_t DRIVER_LEN { 64 };
234 static const char DRIVER_STOP_CHAR { '#' };
235
236 FirmwareInfo m_FirmwareInfo;
237
238 const std::vector<MountInfo> m_MountList =
239 {
240 {"0010", "Cube II EQ", "160610"},
241 {"0011", "Smart EQ Pro+", "161028"},
242 {"0025", "CEM25", "170106"},
243 {"0026", "CEM25-EC", "170518"},
244 {"0030", "iEQ30 Pro", "161101"},
245 {"0040", "CEM40", "181018"},
246 {"0041", "CEM40-EC", "181018"},
247 {"0043", "GEM45", "191018"},
248 {"0044", "GEM45-EC", "191018"},
249 {"0045", "iEQ45 Pro EQ", "161101"},
250 {"0046", "iEQ45 Pro AA", "161101"},
251 {"0060", "CEM60", "161101"},
252 {"0061", "CEM60-EC", "161101"},
253 {"5010", "Cube II AA", "160610"},
254 {"5035", "AZ Mount Pro", "170410"},
255 };
256
257 ///
258 /// \brief DecodeString converts the string to a double by dividing by the factor
259 /// \param data
260 /// \param size
261 /// \param factor
262 /// \return
263 ///
264 double DecodeString(const char * data, size_t size, double factor);
265
266 ///
267 /// \brief DecodeString converts a string of defined size to an int
268 /// \param data
269 /// \param size
270 /// \return
271 ///
272 int DecodeString(const char * data, size_t size);
273
274 constexpr static const double ieqDegrees { 60.0 * 60.0 * 100.0 };
275 constexpr static const double ieqHours { 60.0 * 60.0 * 1000.0 };
276 };
277
278 class Simulator: public Base
279 {
280 Simulator();
281 virtual ~Simulator();
282
283
284 };
285
286 }