Instrument Neutral Distributed Interface INDI  2.0.2
esattoarco.h
Go to the documentation of this file.
1 /*
2  Primaluca Labs Essato-Arco Focuser+Rotator Driver
3 
4  Copyright (C) 2020 Piotr Zyziuk
5  Copyright (C) 2020-2022 Jasem Mutlaq
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  JM 2022.07.16: Major refactor to using json.h and update to Essato Arco
22  Document protocol revision 3.3 (8th July 2022).
23 */
24 
25 #pragma once
26 
27 #include "indifocuser.h"
28 #include "inditimer.h"
29 #include "indirotatorinterface.h"
30 #include "primalucacommandset.h"
31 #include "indipropertytext.h"
32 #include "indipropertynumber.h"
33 
35 {
36  public:
37  EsattoArco();
38  virtual ~EsattoArco() override = default;
39 
40  const char *getDefaultName() override;
41  virtual bool initProperties() override;
42  virtual bool updateProperties() override;
43  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
44  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
45 
46  protected:
47  // Common
48  virtual bool Handshake() override;
49  virtual void TimerHit() override;
50  virtual bool saveConfigItems(FILE *fp) override;
51 
52  // Focuser
53  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
54  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
55  virtual bool AbortFocuser() override;
56  virtual bool SetFocuserBacklash(int32_t steps) override;
57 
58  // Rotator
59  virtual IPState MoveRotator(double angle) override;
60  virtual bool SyncRotator(double angle) override;
61  virtual bool AbortRotator() override;
62  virtual bool ReverseRotator(bool enabled) override;
63 
64  private:
65  bool Ack();
66  bool setMinLimit(uint32_t limit);
67  bool setMaxLimit(uint32_t limit);
68  bool updateMaxLimit();
69 
70  bool updateTemperature();
71  bool updatePosition();
72  bool updateVoltageIn();
73 
74  void setConnectionParams();
75  bool initCommandSet();
76 
77  bool getStartupValues();
78  void hexDump(char * buf, const char * data, int size);
79  bool isMotionComplete();
80 
81  uint16_t m_TemperatureCounter { 0 };
82 
83  INumberVectorProperty TemperatureNP;
84  INumber TemperatureN[2];
85  enum
86  {
87  TEMPERATURE_EXTERNAL,
88  TEMPERATURE_MOTOR,
89  };
90 
91  INumber SpeedN[1];
92  INumberVectorProperty SpeedNP;
93 
94  INDI::PropertyText FirmwareTP {4};
95  enum
96  {
97  ESATTO_FIRMWARE_SN,
98  ESATTO_FIRMWARE_VERSION,
99  ARCO_FIRMWARE_SN,
100  ARCO_FIRMWARE_VERSION,
101  };
102 
103  INDI::PropertyNumber VoltageNP {2};
104  enum
105  {
106  VOLTAGE_12V,
107  VOLTAGE_USB
108  };
109 
110 
111  ISwitch FastMoveS[3];
112  ISwitchVectorProperty FastMoveSP;
113  enum
114  {
115  FASTMOVE_IN,
116  FASTMOVE_OUT,
117  FASTMOVE_STOP
118  };
119 
120  ISwitch BacklashMeasurementS[2];
121  ISwitchVectorProperty BacklashMeasurementSP;
122  enum
123  {
124  BACKLASH_START,
125  BACKLASH_NEXT
126  };
127  IText BacklashMessageT[1] {};
128  ITextVectorProperty BacklashMessageTP;
129  typedef enum { BacklashIdle, BacklashMinimum, BacklashMaximum, BacklashComplete } BacklashStage;
130  BacklashStage bStage { BacklashIdle };
131 
132  //Rotator
133  INumber RotatorAbsPosN[1];
134  INumberVectorProperty RotatorAbsPosNP;
135  enum
136  {
137  ROTATOR_ABSOLUTE_POSITION
138  };
139 
140  //ROTATOR CALIBRATION
141  IText RotCalibrationMessageT[1] {};
142  ITextVectorProperty RotCalibrationMessageTP;
143 
144  typedef enum { RotCalIdle, RotCalComplete } RotCalibrationStage;
145  RotCalibrationStage rcStage { RotCalIdle };
146 
147  ISwitch RotCalibrationS[1];
148  ISwitchVectorProperty RotatorCalibrationSP;
149  enum
150  {
151  ARCO_CALIBRATION_START
152  };
153 
154  std::unique_ptr<PrimalucaLabs::Esatto> m_Esatto;
155  std::unique_ptr<PrimalucaLabs::Arco> m_Arco;
156 
157  static constexpr uint8_t TEMPERATURE_FREQUENCY {10};
158 };
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: esattoarco.cpp:388
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: esattoarco.cpp:593
const char * getDefaultName() override
Definition: esattoarco.cpp:249
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: esattoarco.cpp:557
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: esattoarco.cpp:175
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: esattoarco.cpp:571
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: esattoarco.cpp:59
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: esattoarco.cpp:585
virtual IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
Definition: esattoarco.cpp:799
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: esattoarco.cpp:527
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: esattoarco.cpp:789
virtual bool ReverseRotator(bool enabled) override
ReverseRotator Reverse the direction of the rotator. CW is usually the normal direction,...
Definition: esattoarco.cpp:836
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: esattoarco.cpp:319
virtual bool SyncRotator(double angle) override
SyncRotator Set current angle as the supplied angle without moving the rotator.
Definition: esattoarco.cpp:848
virtual bool AbortRotator() override
AbortRotator Abort all motion.
Definition: esattoarco.cpp:819
virtual bool Handshake() override
perform handshake with device to check communication
Definition: esattoarco.cpp:234
virtual ~EsattoArco() override=default
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
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