Instrument Neutral Distributed Interface INDI  1.9.5
steeldrive2.h
Go to the documentation of this file.
1 /*
2  Baader SteelDriveII Focuser
3 
4  Copyright (C) 2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 
22 #pragma once
23 
24 #include "indifocuser.h"
25 
26 #include <map>
27 
29 {
30  public:
31  SteelDriveII();
32 
33  typedef enum { GOING_UP, GOING_DOWN, STOPPED, ZEROED } State;
35 
36  virtual bool Handshake() override;
37  const char *getDefaultName() override;
38  virtual bool initProperties() override;
39  virtual bool updateProperties() override;
40 
41  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
42  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
43 
44  protected:
45  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
46  virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override;
47  virtual bool SyncFocuser(uint32_t ticks) override;
48  virtual bool ReverseFocuser(bool enabled) override;
49  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
50  virtual bool AbortFocuser() override;
51  virtual void TimerHit() override;
52 
53  virtual bool saveConfigItems(FILE *fp) override;
54 
55  private:
59  bool getParameter(const std::string &parameter, std::string &value);
60 
64  bool setParameter(const std::string &parameter, const std::string &value);
65 
69  bool getSummary();
70  bool sendCommandOK(const char * cmd);
71  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
72  void hexDump(char * buf, const char * data, int size);
73  std::vector<std::string> split(const std::string &input, const std::string &regex);
74 
78  void getStartupValues();
79  template <typename T> std::string to_string(const T a_value, const int n = 2);
80 
84 
85  // Focuser Informatin
86  ITextVectorProperty InfoTP;
87  IText InfoT[2] {};
88  enum
89  {
90  INFO_NAME,
91  INFO_VERSION
92  };
93 
94  // Focuser Operations
95  ISwitchVectorProperty OperationSP;
96  ISwitch OperationS[3];
97  enum
98  {
99  OPERATION_REBOOT,
100  OPERATION_RESET,
101  OPERATION_ZEROING,
102  };
103 
104  // Temperature Compensation
105  ISwitchVectorProperty TemperatureCompensationSP;
106  ISwitch TemperatureCompensationS[2];
107  enum
108  {
109  TC_ENABLED,
110  TC_DISABLED
111  };
112 
113  // TC State
114  ISwitchVectorProperty TemperatureStateSP;
115  ISwitch TemperatureStateS[2];
116  enum
117  {
118  TC_ACTIVE,
119  TC_PAUSED
120  };
121 
122  // Temperature Compensation Settings
123  INumberVectorProperty TemperatureSettingsNP;
124  INumber TemperatureSettingsN[3];
125  enum
126  {
127  TC_FACTOR,
128  TC_PERIOD,
129  TC_DELTA
130  };
131 
132  // Temperature Sensors
133  INumberVectorProperty TemperatureSensorNP;
134  INumber TemperatureSensorN[3];
135  enum
136  {
137  TEMP_0,
138  TEMP_1,
139  TEMP_AVG
140  };
141 
142  // Stepper Drive
143  INumberVectorProperty StepperDriveNP;
144  INumber StepperDriveN[2];
145  enum
146  {
147  CURRENT_MOVE,
148  CURRENT_HOLD
149  };
150 
154  State m_State { STOPPED };
155  std::map<Summary, std::string> m_Summary;
156  bool m_ConfirmFactoryReset { false };
157 
161  static constexpr const char * SETTINGS_TAB = "Settings";
162  static constexpr const char * COMPENSATION_TAB = "Compensation";
163  // 0xA is the stop char
164  static const char DRIVER_STOP_CHAR { 0x0A };
165  // Wait up to a maximum of 3 seconds for serial input
166  static constexpr const uint8_t DRIVER_TIMEOUT {3};
167  // Maximum buffer for sending/receving.
168  static constexpr const uint8_t DRIVER_LEN {192};
169 };
SteelDriveII::NAME
@ NAME
Definition: steeldrive2.h:34
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
SteelDriveII::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: steeldrive2.cpp:468
SteelDriveII::GOING_UP
@ GOING_UP
Definition: steeldrive2.h:33
IPState
IPState
Property state.
Definition: indiapi.h:158
ISwitch
One switch descriptor.
SteelDriveII::TEMP0
@ TEMP0
Definition: steeldrive2.h:34
SteelDriveII::POSITION
@ POSITION
Definition: steeldrive2.h:34
SteelDriveII::PWM
@ PWM
Definition: steeldrive2.h:34
SteelDriveII::getDefaultName
const char * getDefaultName() override
Definition: steeldrive2.cpp:155
INumber
One number descriptor.
SteelDriveII::FOCUS
@ FOCUS
Definition: steeldrive2.h:34
SteelDriveII::TCOMP
@ TCOMP
Definition: steeldrive2.h:34
SteelDriveII::ZEROED
@ ZEROED
Definition: steeldrive2.h:33
SteelDriveII::TEMP1
@ TEMP1
Definition: steeldrive2.h:34
SteelDriveII::State
State
Definition: steeldrive2.h:33
SteelDriveII::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
Reverse Focuser Motion.
Definition: steeldrive2.cpp:476
SteelDriveII::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: steeldrive2.cpp:140
indifocuser.h
SteelDriveII::Summary
Summary
Definition: steeldrive2.h:34
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
SteelDriveII::GOING_DOWN
@ GOING_DOWN
Definition: steeldrive2.h:33
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
IText
One text descriptor.
SteelDriveII
Definition: steeldrive2.h:28
SteelDriveII::STOPPED
@ STOPPED
Definition: steeldrive2.h:33
SteelDriveII::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Definition: steeldrive2.cpp:369
SteelDriveII::TEMPAVG
@ TEMPAVG
Definition: steeldrive2.h:34
SteelDriveII::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: steeldrive2.cpp:105
SteelDriveII::LIMIT
@ LIMIT
Definition: steeldrive2.h:34
SteelDriveII::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: steeldrive2.cpp:495
SteelDriveII::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: steeldrive2.cpp:285
name
const char * name
Definition: indiserver.c:116
SteelDriveII::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: steeldrive2.cpp:163
SteelDriveII::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: steeldrive2.cpp:351
SteelDriveII::STATE
@ STATE
Definition: steeldrive2.h:34
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
ISState
ISState
Switch state.
Definition: indiapi.h:148
SteelDriveII::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
Reverse Focuser Motion.
Definition: steeldrive2.cpp:486
State
State
Definition: lilxml.c:72
INDI::Focuser
Definition: indifocuser.h:43
SteelDriveII::SteelDriveII
SteelDriveII()
Definition: steeldrive2.cpp:38
SteelDriveII::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
Sync focuser.
Definition: steeldrive2.cpp:341
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
SteelDriveII::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: steeldrive2.cpp:50
SteelDriveII::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: steeldrive2.cpp:386