Instrument Neutral Distributed Interface INDI  1.9.5
sestosenso2.h
Go to the documentation of this file.
1 /*
2  SestoSenso 2 Focuser
3  Copyright (C) 2020 Piotr Zyziuk
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #pragma once
22 
23 #include "indifocuser.h"
24 #include "inditimer.h"
25 
27 {
28 
29  public:
30  CommandSet(int Port, const char *deviceName)
31  {
32  PortFD = Port;
33  this->deviceName = deviceName;
34  }
35  int PortFD;
36  bool stop();
37  bool getSerialNumber(char *res);
38  bool getFirmwareVersion(char *res);
39  bool abort();
40  bool go(uint32_t targetTicks, char *res);
41  bool goHome(char *res);
42  bool fastMoveOut(char *res);
43  bool fastMoveIn(char *res);
44  bool getMaxPosition(char *res);
45  bool getHallSensor(char *res);
46  bool storeAsMaxPosition(char *res);
47  bool goOutToFindMaxPos();
48  bool storeAsMinPosition();
49  bool initCalibration();
50  bool getAbsolutePosition(char *res);
51  bool getCurrentSpeed(char *res);
52  bool applyMotorPreset(const char *name);
53  bool applyMotorUserPreset(uint32_t index);
54  bool saveMotorUserPreset(uint32_t index, struct MotorRates &mr, struct MotorCurrents &mc);
55  bool getMotorTemp(char *res);
56  bool getExternalTemp(char *res);
57  bool getVoltageIn(char *res);
58  bool getMotorSettings(struct MotorRates &ms, struct MotorCurrents &mc, bool &motorHoldActive);
59  bool setMotorRates(struct MotorRates &ms);
60  bool setMotorCurrents(struct MotorCurrents &mc);
61  bool setMotorHold(bool hold);
62  std::string deviceName;
63 
64  const char *getDeviceName() const
65  {
66  return deviceName.c_str();
67  }
68 
69  private:
70 
71  // Send request and return full response
72  bool send(const std::string &request, std::string &response) const;
73  // Send command and parse response looking for value of property
74  bool sendCmd(const std::string &cmd, std::string property = "", char *res = nullptr) const;
75  bool sendCmd(const std::string &cmd, std::string property, std::string &res) const;
76  bool getValueFromResponse(const std::string &response, const std::string &property, char *value) const;
77  bool parseUIntFromResponse(const std::string &response, const std::string &property, uint32_t &result) const;
78 
79  // Maximum buffer for sending/receving.
80  static constexpr const int SESTO_LEN {1024};
81  enum
82  {
83  CMD_OK = true,
84  CMD_FALSE = false
85  };
86 
87 };
88 
89 class SestoSenso2 : public INDI::Focuser
90 {
91  public:
92  SestoSenso2();
93  virtual ~SestoSenso2() override = default;
94 
95  const char *getDefaultName() override;
96  virtual bool initProperties() override;
97  virtual bool updateProperties() override;
98  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
99  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
100 
101  // static void checkMotionProgressHelper(void *context);
102  // static void checkHallSensorHelper(void *context);
103 
104  protected:
105  virtual bool Handshake() override;
106  virtual bool Disconnect() override;
107  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
108  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
109  virtual bool ReverseFocuser(bool enabled) override;
110  virtual bool AbortFocuser() override;
111  virtual void TimerHit() override;
112  virtual bool SetFocuserBacklash(int32_t steps) override;
113 
114  virtual bool saveConfigItems(FILE *fp) override;
115 
116  private:
117  bool Ack();
118  bool setMinLimit(uint32_t limit);
119  bool setMaxLimit(uint32_t limit);
120  bool updateMaxLimit();
121 
122  bool updateTemperature();
123  bool updatePosition();
124  bool updateVoltageIn();
125  bool fetchMotorSettings();
126  bool applyMotorRates();
127  bool applyMotorCurrents();
128  void setConnectionParams();
129  bool initCommandSet();
130  void checkMotionProgressCallback();
131  void checkHallSensorCallback();
132 
133  CommandSet *command {nullptr};
134 
135  bool getStartupValues();
136  void hexDump(char * buf, const char * data, int size);
137  bool isMotionComplete();
138 
139  FocusDirection backlashDirection { FOCUS_INWARD };
140  FocusDirection oldbacklashDirection { FOCUS_INWARD };
141  int32_t startPos { 0 };
142  uint32_t backlashTicks { 0 };
143  uint32_t targetPos { 0 };
144  uint32_t lastPos { 0 };
145  int32_t previousPos { 0 };
146  double lastVoltageIn { 0 };
147  double lastTemperature { 0 };
148  uint16_t m_TemperatureCounter { 0 };
149 
150  INumberVectorProperty TemperatureNP;
151  INumber TemperatureN[2];
152  enum
153  {
154  TEMPERATURE_EXTERNAL,
155  TEMPERATURE_MOTOR,
156  };
157 
158  INumber SpeedN[1];
159  INumberVectorProperty SpeedNP;
160 
161  ITextVectorProperty FirmwareTP;
162  IText FirmwareT[2];
163  enum
164  {
165  FIRMWARE_SN,
166  FIRMWARE_VERSION,
167  };
168 
169  INumber VoltageInN[1] {};
170  INumberVectorProperty VoltageInNP;
171 
172  ISwitch CalibrationS[2];
173  ISwitchVectorProperty CalibrationSP;
174  enum
175  {
176  CALIBRATION_START,
177  CALIBRATION_NEXT
178  };
179 
180  ISwitch FastMoveS[3];
181  ISwitchVectorProperty FastMoveSP;
182  enum
183  {
184  FASTMOVE_IN,
185  FASTMOVE_OUT,
186  FASTMOVE_STOP
187  };
188 
189  enum
190  {
191  CMD_OK = true,
192  CMD_FALSE = false
193  };
194 
195  INumberVectorProperty MotorRateNP;
196  INumber MotorRateN[3];
197  enum
198  {
199  MOTOR_RATE_ACC,
200  MOTOR_RATE_RUN,
201  MOTOR_RATE_DEC
202  };
203 
204  INumberVectorProperty MotorCurrentNP;
205  INumber MotorCurrentN[4];
206  enum
207  {
208  MOTOR_CURR_ACC,
209  MOTOR_CURR_RUN,
210  MOTOR_CURR_DEC,
211  MOTOR_CURR_HOLD
212  };
213 
214  ISwitchVectorProperty MotorHoldSP;
215  ISwitch MotorHoldS[2];
216  enum
217  {
218  MOTOR_HOLD_ON,
219  MOTOR_HOLD_OFF
220  };
221 
222  ISwitchVectorProperty MotorApplyPresetSP;
223  ISwitch MotorApplyPresetS[3];
224  enum
225  {
226  MOTOR_APPLY_LIGHT,
227  MOTOR_APPLY_MEDIUM,
228  MOTOR_APPLY_HEAVY,
229  };
230 
231  ISwitchVectorProperty MotorApplyUserPresetSP;
232  ISwitch MotorApplyUserPresetS[3];
233  enum
234  {
235  MOTOR_APPLY_USER1,
236  MOTOR_APPLY_USER2,
237  MOTOR_APPLY_USER3
238  };
239 
240  ISwitchVectorProperty MotorSaveUserPresetSP;
241  ISwitch MotorSaveUserPresetS[3];
242  enum
243  {
244  MOTOR_SAVE_USER1,
245  MOTOR_SAVE_USER2,
246  MOTOR_SAVE_USER3
247  };
248 
249  ISwitchVectorProperty HomeSP;
250  ISwitch HomeS[1];
251 
252  IText CalibrationMessageT[1] {};
253  ITextVectorProperty CalibrationMessageTP;
254 
255  typedef enum { Idle, GoToMiddle, GoMinimum, GoDupa, GoMaximum, Complete } CalibrationStage;
256  CalibrationStage cStage { Idle };
257 
258  ISwitch BacklashS[2];
259  ISwitchVectorProperty BacklashSP;
260  enum
261  {
262  BACKLASH_START,
263  BACKLASH_NEXT
264  };
265  IText BacklashMessageT[1] {};
266  ITextVectorProperty BacklashMessageTP;
267 
268  typedef enum { BacklashIdle, BacklashMinimum, BacklashMaximum, BacklashComplete } BacklashStage;
269  BacklashStage bStage { BacklashIdle };
270 
271  // int m_MotionProgressTimerID {-1};
272  // int m_HallSensorTimerID {-1};
273  INDI::Timer m_MotionProgressTimer;
274  INDI::Timer m_HallSensorTimer;
275  bool m_IsSestoSenso2 { true };
279  // CR is the stop char
280  static const char SESTO_STOP_CHAR { 0xD };
281  // Update temperature every 10x POLLMS. For 500ms, we would
282  // update the temperature one every 5 seconds.
283  static constexpr const uint8_t SESTO_TEMPERATURE_FREQ {10};
284  // Wait up to a maximum of 3 seconds for serial input
285  static constexpr const uint8_t SESTO_TIMEOUT {5};
286  // Maximum buffer for sending/receving.
287  static constexpr const int SESTO_LEN {1024};
288 
289 };
CommandSet::getMotorTemp
bool getMotorTemp(char *res)
Definition: sestosenso2.cpp:1647
CommandSet::stop
bool stop()
Definition: sestosenso2.cpp:1500
CommandSet::getMaxPosition
bool getMaxPosition(char *res)
Definition: sestosenso2.cpp:1520
CommandSet::abort
bool abort()
Definition: sestosenso2.cpp:1488
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
SestoSenso2::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: sestosenso2.cpp:1044
CommandSet::storeAsMinPosition
bool storeAsMinPosition()
Definition: sestosenso2.cpp:1540
CommandSet::CommandSet
CommandSet(int Port, const char *deviceName)
Definition: sestosenso2.h:30
IPState
IPState
Property state.
Definition: indiapi.h:158
SestoSenso2::Disconnect
virtual bool Disconnect() override
Disconnect from device.
Definition: sestosenso2.cpp:279
ISwitch
One switch descriptor.
CommandSet::goOutToFindMaxPos
bool goOutToFindMaxPos()
Definition: sestosenso2.cpp:1535
CommandSet::getMotorSettings
bool getMotorSettings(struct MotorRates &ms, struct MotorCurrents &mc, bool &motorHoldActive)
Definition: sestosenso2.cpp:1662
CommandSet::getSerialNumber
bool getSerialNumber(char *res)
Definition: sestosenso2.cpp:1478
INumber
One number descriptor.
inditimer.h
CommandSet::getCurrentSpeed
bool getCurrentSpeed(char *res)
Definition: sestosenso2.cpp:1555
CommandSet::setMotorHold
bool setMotorHold(bool hold)
Definition: sestosenso2.cpp:1719
SestoSenso2::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: sestosenso2.cpp:1069
SestoSenso2::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: sestosenso2.cpp:73
SestoSenso2::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: sestosenso2.cpp:1107
INDI::Timer
The Timer class provides repetitive and single-shot timers.
Definition: inditimer.h:40
CommandSet::getFirmwareVersion
bool getFirmwareVersion(char *res)
Definition: sestosenso2.cpp:1483
CommandSet::setMotorRates
bool setMotorRates(struct MotorRates &ms)
Definition: sestosenso2.cpp:1693
indifocuser.h
SestoSenso2::getDefaultName
const char * getDefaultName() override
Definition: sestosenso2.cpp:295
SestoSenso2::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: sestosenso2.cpp:1219
CommandSet::getVoltageIn
bool getVoltageIn(char *res)
Definition: sestosenso2.cpp:1657
CommandSet::saveMotorUserPreset
bool saveMotorUserPreset(uint32_t index, struct MotorRates &mr, struct MotorCurrents &mc)
Definition: sestosenso2.cpp:1627
CommandSet::deviceName
std::string deviceName
Definition: sestosenso2.h:62
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
CommandSet::getAbsolutePosition
bool getAbsolutePosition(char *res)
Definition: sestosenso2.cpp:1550
SestoSenso2
Definition: sestosenso2.h:89
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
SestoSenso2::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: sestosenso2.cpp:1286
SestoSenso2::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: sestosenso2.cpp:1096
CommandSet::applyMotorUserPreset
bool applyMotorUserPreset(uint32_t index)
Definition: sestosenso2.cpp:1576
IText
One text descriptor.
MotorRates
Definition: sestosenso2.cpp:42
INDI::FocuserInterface::FOCUS_INWARD
@ FOCUS_INWARD
Definition: indifocuserinterface.h:68
CommandSet::storeAsMaxPosition
bool storeAsMaxPosition(char *res)
Definition: sestosenso2.cpp:1530
CommandSet::getExternalTemp
bool getExternalTemp(char *res)
Definition: sestosenso2.cpp:1652
CommandSet::setMotorCurrents
bool setMotorCurrents(struct MotorCurrents &mc)
Definition: sestosenso2.cpp:1710
SestoSenso2::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: sestosenso2.cpp:630
CommandSet::getHallSensor
bool getHallSensor(char *res)
Definition: sestosenso2.cpp:1525
CommandSet::applyMotorPreset
bool applyMotorPreset(const char *name)
Definition: sestosenso2.cpp:1560
name
const char * name
Definition: indiserver.c:116
SestoSenso2::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: sestosenso2.cpp:1359
CommandSet::go
bool go(uint32_t targetTicks, char *res)
Definition: sestosenso2.cpp:1493
CommandSet::fastMoveIn
bool fastMoveIn(char *res)
Definition: sestosenso2.cpp:1515
SestoSenso2::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: sestosenso2.cpp:287
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
SestoSenso2::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: sestosenso2.cpp:267
CommandSet::PortFD
int PortFD
Definition: sestosenso2.h:35
ISState
ISState
Switch state.
Definition: indiapi.h:148
CommandSet::getDeviceName
const char * getDeviceName() const
Definition: sestosenso2.h:64
CommandSet::fastMoveOut
bool fastMoveOut(char *res)
Definition: sestosenso2.cpp:1510
CommandSet
Definition: sestosenso2.h:26
INDI::Focuser
Definition: indifocuser.h:43
SestoSenso2::SestoSenso2
SestoSenso2()
Definition: sestosenso2.cpp:59
SestoSenso2::~SestoSenso2
virtual ~SestoSenso2() override=default
MotorCurrents
Definition: sestosenso2.cpp:48
SestoSenso2::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: sestosenso2.cpp:209
CommandSet::goHome
bool goHome(char *res)
Definition: sestosenso2.cpp:1505
CommandSet::initCalibration
bool initCalibration()
Definition: sestosenso2.cpp:1545
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365