Instrument Neutral Distributed Interface INDI  2.0.2
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 
38 class 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 enum
282  {
283  NO_ERROR = 0,
284  FT_INVALID_HANDLE = 1,
285  FT_DEVICE_NOT_FOUND = 2,
286  FT_DEVICE_NOT_OPENED = 3,
287  FT_IO_ERROR = 4,
288  FT_INSUFFICIENT_RESOURCES = 5,
289  FT_INVALID_PARAMETER = 6,
290  FT_INVALID_BAUD_RATE = 7,
291  FT_DEVICE_NOT_OPENED_FOR_ERASE = 8,
292  FT_DEVICE_NOT_OPENED_FOR_WRITE = 9,
293  FT_FAILED_TO_WRITE_DEVICE = 10,
294  FT_EEPROM_READ_FAILED = 11,
295  FT_EEPROM_WRITE_FAILED = 12,
296  FT_EEPROM_ERASE_FAILED = 13,
297  FT_EEPROM_NOT_PRESENT = 14,
298  FT_EEPROM_NOT_PROGRAMMED = 15,
299  FT_INVALID_ARGS = 16,
300  FT_NOT_SUPPORTED = 17,
301  FT_OTHER_ERROR = 18,
302  NO_CONNECTION = 100,
303  READ_TIMEOUT_ERROR,
304  WRITE_TIMEOUT_ERROR,
305  CHECKSUM_ERROR,
306  PACKET_LENGTH_ERROR,
307  FUNCTION_NOT_SUPPORTED_BY_FIRMWARE,
308  PARAM_ERROR,
309  BUSY_ERROR,
310  AUTHORISATION_ERROR,
311  MOTION_CONFLICT,
312  FUNCTION_NOT_SUPPORTED,
313  COMMAND_SYNC_ERROR,
314  CARD_REOPEN,
315  } ErrorCode;
316 
317  typedef enum
318  {
319  OUT_CCW = 0,
320  OUT_CW = 1,
321  OUT_OPEN1 = 2,
322  OUT_CLOSE1 = 3,
323  OUT_FAN = 4,
324  OUT_LIGHT = 5,
325  OUT_CCD = 6,
326  OUT_SCOPE = 7,
327  IN_REMOTE1 = 8,
328  IN_REMOTE2 = 9,
329  IN_REMOTE3 = 10,
330  IN_REMOTE4 = 11,
331  IN_ENCODER = 12,
332  IN_HOME = 13,
333  IN_OPEN1 = 14,
334  IN_CLOSED1 = 15,
335  IN_FREE = 16,
336  IN_S_HOME = 17,
337  IN_SAFE = 18,
338  IN_CLOUD = 19,
339  OUT_RELAY1 = 20,
340  OUT_RELAY2 = 21,
341  OUT_RELAY3 = 22,
342  OUT_RELAY4 = 23,
343  OUT_OPEN2 = 24,
344  OUT_CLOSE2 = 25,
345  IN_OPEN2 = 26,
346  IN_CLOSED2 = 27,
347  IN_SHIFT = 28,
348  IN_SCOPE_SYNC = 29,
349  IN_WIND_SYNC = 30,
350  IN_WEATHER_PROTECT = 31,
351  IN_CLOUDS = 32,
352  IN_ENCODER_ROT = 33,
353  IN_HOME_ROT = 34,
354  IN_ROT_LINK = 35
355  } DigitalIO;
356 
357  typedef enum
358  {
359  STATUS_RESET = 1,
360  STATUS_MOVING = 2,
361  STATUS_HOMING = 4,
362  STATUS_OPEN1 = 8,
363  STATUS_OPEN2 = 0x10,
364  STATUS_AUTO_CLOSE1 = 0x20,
365  STATUS_AUTO_CLOSE2 = 0x40,
366  STATUS_CALIBRATING = 0x80,
367  STATUS_FINDING_POWER = 0x100,
368  STATUS_CALIBRATION_STOP = 0x200
369  } StatusBits;
370 
371  // I/O helper functions
372  bool readFloat(Command cmd, float &dst);
373  bool readU8(Command cmd, uint8_t &dst);
374  bool readS8(Command cmd, int8_t &dst);
375  bool readU16(Command cmd, uint16_t &dst);
376  bool readS16(Command cmd, int16_t &dst);
377  bool readU32(Command cmd, uint32_t &dst);
378  bool readS32(Command cmd, int32_t &dst);
379  int readBuffer(Command cmd, int len, uint8_t *cbuf);
380 
381  int writeCmd(Command cmd);
382  int writeU8(Command cmd, uint8_t value);
383  int writeU16(Command cmd, uint16_t value);
384  int writeU32(Command cmd, uint32_t value);
385  int writeBuffer(Command cmd, int len, uint8_t *cbuf);
386 
387  int writeBuf(Command Command, uint8_t len, uint8_t *buff);
388  int write(Command cmd);
389  int readBuf(Command &cmd, uint8_t len, uint8_t *buff);
390  int read(Command &cmd);
391 
392  ISState getInputState(DigitalIO channel);
393  int setOutputState(DigitalIO channel, ISState state);
394 
395  void reconnect();
396  uint8_t CRC(uint8_t crc, uint8_t data);
397 
398  ScopeDome *parent;
399  int PortFD;
400 
401  // Shadowed card state
402  Command prevcmd;
403  uint8_t digitalSensorState[5];
404 
405  uint8_t linkStrength {0};
406 
407  uint16_t status {0};
408 
409  int16_t counter {0};
410 
411  int32_t counterExt {0};
412 
413  float sensors[10];
414 };
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
ScopeDomeUSB21 & operator=(const ScopeDomeUSB21 &)=delete
virtual void setHomeSensorPolarity(HomeSensorPolarity polarity) override
virtual InputInfo getInputInfo(size_t index) override
virtual void move(int steps) override
ScopeDomeUSB21(ScopeDome *driver, int fd)
ISState
Switch state.
Definition: indiapi.h:150
int fd
Definition: intelliscope.c:43
__u8 cmd[4]
Definition: pwc-ioctl.h:2
int main(int, char *[])