Instrument Neutral Distributed Interface INDI 2.2.5
scopedome_usb21.h
Go to the documentation of this file.
1/*******************************************************************************
2 ScopeDome Dome INDI Driver
3
4 Copyright(c) 2017-2021 Jarno Paananen. All rights reserved.
5
6 based on:
7
8 ScopeDome Windows ASCOM driver version 5.1.30
9
10 and
11
12 Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
13
14 Baader Planetarium Dome INDI Driver
15
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License version 2 as published by the Free Software Foundation.
19 .
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Library General Public License for more details.
24 .
25 You should have received a copy of the GNU Library General Public License
26 along with this library; see the file COPYING.LIB. If not, write to
27 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.
29*******************************************************************************/
30
31#pragma once
32
33#include "scopedome_dome.h"
34
38class ScopeDomeUSB21 final: public ScopeDomeCard
39{
40 public:
42 ScopeDomeUSB21(ScopeDome *driver, int fd) : parent(driver), PortFD(fd) {}
43
45 virtual ~ScopeDomeUSB21() = default;
46
47 ScopeDomeUSB21(const ScopeDomeUSB21 &) = delete;
49
50 virtual bool detect() override;
51 virtual void setPortFD(int fd) override
52 {
53 PortFD = fd;
54 };
55
56 // State polling
57 virtual int updateState() override;
58 virtual uint32_t getStatus() override;
59 virtual int getRotationCounter() override;
60 virtual int getRotationCounterExt() override;
61
62 // Information
63 virtual void getFirmwareVersions(double &main, double &rotary) override;
64 virtual uint32_t getStepsPerRevolution() override;
65 virtual bool isCalibrationNeeded() override;
66
67 // Commands
68 virtual void abort() override;
69 virtual void calibrate() override;
70 virtual void findHome() override;
71 virtual void controlShutter(ShutterOperation operation) override;
72
73 virtual void resetCounter() override;
74
75 // negative means CCW, positive CW steps
76 virtual void move(int steps) override;
77
78 // Input/Output management
79 virtual size_t getNumberOfSensors() override;
80 virtual SensorInfo getSensorInfo(size_t index) override;
81 virtual double getSensorValue(size_t index) override;
82
83 virtual size_t getNumberOfRelays() override;
84 virtual RelayInfo getRelayInfo(size_t index) override;
85 virtual ISState getRelayState(size_t index) override;
86 virtual void setRelayState(size_t index, ISState state) override;
87
88 virtual size_t getNumberOfInputs() override;
89 virtual InputInfo getInputInfo(size_t index) override;
90 virtual ISState getInputValue(size_t index) override;
91
92 virtual ISState getInputState(AbstractInput input) override;
93 virtual int setOutputState(AbstractOutput output, ISState state) override;
94
95 virtual void setHomeSensorPolarity(HomeSensorPolarity polarity) override;
96 private:
97 // Commands
98 typedef enum
99 {
100 ACK_c = 1,
101 FunctionNotSupported,
102 MotionConflict,
103 ParamError,
104 FuncBufferError,
105 ConnectionTest = 15,
106 SetAllDigital,
107 ClearDigitalChannel,
108 ClearAllDigital,
109 SetDigitalChannel,
110 GetDigitalChannel,
111 GetAllDigital,
112
113 GetCounter,
114 ResetCounter,
115 SetCounterDebounceTime,
116 SetCounterMax,
117 GetCounterMax,
118 SetCounterMin,
119 GetCounterMin,
120 CCWRotation,
121 CWRotation,
122
123 GetAnalogChannel,
124 OutputAnalogChannel1,
125 OutputAnalogChannel2,
126 OutputAllAnalog,
127 ClearAnalogChannel,
128 SetAllAnalog,
129 ClearAllAnalog,
130 SetAnalogChannel,
131 GetVersionFirmware,
132
133 SetAllRelays,
134 ClearRelay,
135 SetRelay,
136
137 GetStatus,
138 GetTemp1,
139 GetTemp2,
140 GetTemp3,
141 GetTemp4,
142 GetTemp5,
143 GetDscnt,
144 GetHum,
145 GetTempHum,
146 GetAnalog1,
147 GetAnalog2,
148 Get230,
149 EnableAutoClose,
150 DisableAutoClose,
151 GetAutoClose,
152
153 EnablePosSave,
154 DisablePosSave,
155 GetPosSave,
156
157 GetCounterExt,
158 ResetCounterExt,
159 SetCounterDebounceTimeExt,
160 SetCounterMaxExt,
161 GetCounterMaxExt,
162
163 SetCounterMinExt,
164 GetCounterMinExt,
165
166 GetAllDigitalExt,
167 StandbyOff,
168 StandbyOn,
169 GetPowerState,
170 SetImpPerTurn,
171
172 UpdateFirmware,
173 UpdateRotaryFirmwareSerial,
174 UpdateRotaryFirmwareRf,
175
176 GoHome,
177
178 GetMainAnalog1,
179 GetMainAnalog2,
180
181 GetPressure,
182 GetTempIn,
183 GetTempOut,
184
185 GetRotaryCounter1,
186 GetRotaryCounter2,
187 ResetRotaryCounter1,
188 ResetRotaryCounter2,
189
190 RotaryAutoOpen1,
191 RotaryAutoOpen2,
192
193 RotaryAutoClose1,
194 RotaryAutoClose2,
195
196 GetLinkStrength,
197
198 GetLowVoltageMain,
199 SetLowVoltageMain,
200 GetLowVoltageRotary,
201 SetLowVoltageRotary,
202
203 GetHomeSensorPosition,
204 SetHomeSensorPosition,
205
206 GetImpPerTurn,
207 Stop,
208
209 GetStartCnt,
210 Ready,
211
212 SetStopTime,
213 GetStopTime,
214
215 GetCounterDebounceTimeExt,
216
217 SetDebounceTimeInputs,
218 GetDebounceTimeInputs,
219
220 FindHome,
221 NegHomeSensorActiveState,
222
223 // PowerOnlyAtHome,
224
225 SetAutoCloseEvents,
226 GetAutoCloseEvents,
227 SetAutoCloseTime,
228 GetAutoCloseTime,
229
230 SetShutterConfig,
231 GetShutterConfig,
232
233 GetVersionFirmwareRotary,
234 GetCommunicationMode,
235 SetCommunicationMode,
236
237 SetTherm1Mode,
238 SetTherm1Out1,
239 SetTherm1Out2,
240 SetTherm1Hist,
241 SetTherm1VAL,
242
243 GetTherm1Mode,
244 GetTherm1Out1,
245 GetTherm1Out2,
246 GetTherm1Hist,
247 GetTherm1VAL,
248
249 SetTherm2Mode,
250 SetTherm2Out1,
251 SetTherm2Out2,
252 SetTherm2Hist,
253 SetTherm2VAL,
254
255 GetTherm2Mode,
256 GetTherm2Out1,
257 GetTherm2Out2,
258 GetTherm2Hist,
259 GetTherm2VAL,
260
261 SetTherm3Mode,
262 SetTherm3Out1,
263 SetTherm3Out2,
264 SetTherm3Hist,
265 SetTherm3VAL,
266
267 GetTherm3Mode,
268 GetTherm3Out1,
269 GetTherm3Out2,
270 GetTherm3Hist,
271 GetTherm3VAL,
272 StartSafeCommunication,
273 StopSafeCommunication,
274 SetAutoCloseOrder,
275 GetAutoCloseOrder,
276
277 FullSystemCal,
278 IsFullSystemCalReq
279 } Command;
280
281 typedef struct
282 {
283 Command cmd;
284 const char* str;
285 } CmdStr;
286 const char* cmdToString(Command cmd) const;
287
288 typedef enum
289 {
290 NO_ERROR = 0,
291 FT_INVALID_HANDLE = 1,
292 FT_DEVICE_NOT_FOUND = 2,
293 FT_DEVICE_NOT_OPENED = 3,
294 FT_IO_ERROR = 4,
295 FT_INSUFFICIENT_RESOURCES = 5,
296 FT_INVALID_PARAMETER = 6,
297 FT_INVALID_BAUD_RATE = 7,
298 FT_DEVICE_NOT_OPENED_FOR_ERASE = 8,
299 FT_DEVICE_NOT_OPENED_FOR_WRITE = 9,
300 FT_FAILED_TO_WRITE_DEVICE = 10,
301 FT_EEPROM_READ_FAILED = 11,
302 FT_EEPROM_WRITE_FAILED = 12,
303 FT_EEPROM_ERASE_FAILED = 13,
304 FT_EEPROM_NOT_PRESENT = 14,
305 FT_EEPROM_NOT_PROGRAMMED = 15,
306 FT_INVALID_ARGS = 16,
307 FT_NOT_SUPPORTED = 17,
308 FT_OTHER_ERROR = 18,
309 NO_CONNECTION = 100,
310 READ_TIMEOUT_ERROR,
311 WRITE_TIMEOUT_ERROR,
312 CHECKSUM_ERROR,
313 PACKET_LENGTH_ERROR,
314 FUNCTION_NOT_SUPPORTED_BY_FIRMWARE,
315 PARAM_ERROR,
316 BUSY_ERROR,
317 AUTHORISATION_ERROR,
318 MOTION_CONFLICT,
319 FUNCTION_NOT_SUPPORTED,
320 COMMAND_SYNC_ERROR,
321 CARD_REOPEN,
322 } ErrorCode;
323
324 typedef enum
325 {
326 OUT_CCW = 0,
327 OUT_CW = 1,
328 OUT_OPEN1 = 2,
329 OUT_CLOSE1 = 3,
330 OUT_FAN = 4,
331 OUT_LIGHT = 5,
332 OUT_CCD = 6,
333 OUT_SCOPE = 7,
334 IN_REMOTE1 = 8,
335 IN_REMOTE2 = 9,
336 IN_REMOTE3 = 10,
337 IN_REMOTE4 = 11,
338 IN_ENCODER = 12,
339 IN_HOME = 13,
340 IN_OPEN1 = 14,
341 IN_CLOSED1 = 15,
342 IN_FREE = 16,
343 IN_S_HOME = 17,
344 IN_SAFE = 18,
345 IN_CLOUD = 19,
346 OUT_RELAY1 = 20,
347 OUT_RELAY2 = 21,
348 OUT_RELAY3 = 22,
349 OUT_RELAY4 = 23,
350 OUT_OPEN2 = 24,
351 OUT_CLOSE2 = 25,
352 IN_OPEN2 = 26,
353 IN_CLOSED2 = 27,
354 IN_SHIFT = 28,
355 IN_SCOPE_SYNC = 29,
356 IN_WIND_SYNC = 30,
357 IN_WEATHER_PROTECT = 31,
358 IN_CLOUDS = 32,
359 IN_ENCODER_ROT = 33,
360 IN_HOME_ROT = 34,
361 IN_ROT_LINK = 35
362 } DigitalIO;
363
364 typedef enum
365 {
366 STATUS_RESET = 1,
367 STATUS_MOVING = 2,
368 STATUS_HOMING = 4,
369 STATUS_OPEN1 = 8,
370 STATUS_OPEN2 = 0x10,
371 STATUS_AUTO_CLOSE1 = 0x20,
372 STATUS_AUTO_CLOSE2 = 0x40,
373 STATUS_CALIBRATING = 0x80,
374 STATUS_FINDING_POWER = 0x100,
375 STATUS_CALIBRATION_STOP = 0x200
376 } StatusBits;
377
378 // I/O helper functions
379 bool readFloat(Command cmd, float &dst);
380 bool readU8(Command cmd, uint8_t &dst);
381 bool readS8(Command cmd, int8_t &dst);
382 bool readU16(Command cmd, uint16_t &dst);
383 bool readS16(Command cmd, int16_t &dst);
384 bool readU32(Command cmd, uint32_t &dst);
385 bool readS32(Command cmd, int32_t &dst);
386 int readBuffer(Command cmd, int len, uint8_t *cbuf);
387
388 int writeCmd(Command cmd);
389 int writeU8(Command cmd, uint8_t value);
390 int writeU16(Command cmd, uint16_t value);
391 int writeU32(Command cmd, uint32_t value);
392 int writeBuffer(Command cmd, int len, uint8_t *cbuf);
393
394 int writeBuf(Command Command, uint8_t len, uint8_t *buff);
395 int write(Command cmd);
396 int readBuf(Command &cmd, uint8_t len, uint8_t *buff);
397 int read(Command &cmd);
398
399 ISState getInputState(DigitalIO channel);
400 int setOutputState(DigitalIO channel, ISState state);
401
402 void reconnect();
403 uint8_t CRC(uint8_t crc, uint8_t data);
404
405 ScopeDome *parent;
406 int PortFD;
407
408 // Shadowed card state
409 Command prevcmd;
410 uint8_t digitalSensorState[5];
411
412 uint8_t linkStrength {0};
413
414 uint16_t status {0};
415
416 int16_t counter {0};
417
418 int32_t counterExt {0};
419
420 float sensors[10];
421};
virtual void calibrate() override
virtual void abort() override
virtual void getFirmwareVersions(double &main, double &rotary) override
virtual double getSensorValue(size_t index) override
virtual ISState getInputValue(size_t index) override
virtual int updateState() override
virtual int getRotationCounterExt() override
virtual uint32_t getStepsPerRevolution() override
virtual ~ScopeDomeUSB21()=default
virtual size_t getNumberOfRelays() override
virtual void setPortFD(int fd) override
virtual size_t getNumberOfInputs() override
virtual ISState getRelayState(size_t index) override
virtual int setOutputState(AbstractOutput output, ISState state) override
ScopeDomeUSB21(const ScopeDomeUSB21 &)=delete
virtual void resetCounter() override
virtual uint32_t getStatus() override
virtual ISState getInputState(AbstractInput input) override
virtual void findHome() override
virtual bool detect() override
virtual size_t getNumberOfSensors() override
virtual int getRotationCounter() override
virtual RelayInfo getRelayInfo(size_t index) override
virtual bool isCalibrationNeeded() override
virtual SensorInfo getSensorInfo(size_t index) override
virtual void setRelayState(size_t index, ISState state) override
virtual void controlShutter(ShutterOperation operation) override
virtual void setHomeSensorPolarity(HomeSensorPolarity polarity) override
virtual InputInfo getInputInfo(size_t index) override
ScopeDomeUSB21 & operator=(const ScopeDomeUSB21 &)=delete
virtual void move(int steps) override
ScopeDomeUSB21(ScopeDome *driver, int fd)
int main()
ISState
Switch state.
Definition indiapi.h:148
int fd
uint8_t cmd[4]
Definition pwc-ioctl.h:2