Instrument Neutral Distributed Interface INDI  1.9.2
focuslynxbase.h
Go to the documentation of this file.
1 /*
2  Focus Lynx INDI driver
3  Copyright (C) 2015 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 
25 #include <indifocuser.h>
26 #include <indicom.h>
29 
30 #include <map>
31 #include <termios.h>
32 #include <unistd.h>
33 #include <memory>
34 #include <cmath>
35 #include <cstring>
36 
37 #define LYNXFOCUS_MAX_RETRIES 1
38 #define LYNXFOCUS_TIMEOUT 3
39 #define LYNXFOCUS_MAXBUF 16
40 #define LYNXFOCUS_TEMPERATURE_FREQ 20 /* Update every 20 POLLMS cycles. For POLLMS 500ms = 10 seconds freq */
41 #define LYNXFOCUS_POSITION_THRESHOLD 5 /* Only send position updates to client if the diff exceeds 5 steps */
42 
43 #define FOCUS_SETTINGS_TAB "Settings"
44 #define FOCUS_STATUS_TAB "Status"
45 #define HUB_SETTINGS_TAB "Device"
46 
47 #define VERSION 1
48 #define SUBVERSION 44
49 
51 {
52  public:
53  FocusLynxBase();
54  FocusLynxBase(const char *target);
55 
56  enum
57  {
64  };
65  typedef enum
66  {
76  } LYNX_STATUS;
77  enum
78  {
81  };
82 
83  virtual bool Handshake() override;
84  virtual const char *getDefaultName() override;
85  virtual bool initProperties() override;
86  virtual void ISGetProperties(const char *dev) override;
87  virtual bool updateProperties() override;
88  virtual bool saveConfigItems(FILE *fp) override;
89  virtual bool loadConfig(bool silent, const char *property) override;
90 
91  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
92  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
93  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
94 
95  virtual IPState MoveAbsFocuser(uint32_t targetPosition) override;
96  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
97  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
98  virtual bool AbortFocuser() override;
99  virtual void TimerHit() override;
100  virtual int getVersion(int *major, int *minor, int *sub);
101 
102  void setFocusTarget(const char *target);
103  const char *getFocusTarget();
104  bool checkIfAbsoluteFocuser();
105  bool SyncMandatory(bool enable);
106  virtual void debugTriggered(bool enable) override;
107 
108  // Device
109  bool setDeviceType(int index);
110  uint32_t DBG_FOCUS;
111 
112  // Misc functions
113  bool ack();
114  bool isResponseOK();
115 
116  protected:
117  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
118  virtual bool ReverseFocuser(bool enabled) override;
119  virtual bool SyncFocuser(uint32_t ticks) override;
120 
121  virtual bool SetFocuserBacklash(int32_t steps) override;
122  virtual bool SetFocuserBacklashEnabled(bool enabled) override;
123 
124  // Move from private to public to validate
126 
127  // List all supported models
130 
131  // Led Intensity Value
134 
135  // Store version of the firmware from the HUB
136  char version[16];
137 
138  private:
139  uint32_t simPosition;
140  uint32_t targetPosition;
141 
142  ISState simStatus[8];
143  bool simCompensationOn;
144  char focusTarget[8];
145 
146  std::map<std::string, std::string> lynxModels;
147 
148  struct timeval focusMoveStart;
149  float focusMoveRequest;
150 
151  // Get functions
152  bool getFocusConfig();
153  bool getFocusStatus();
154  bool getFocusTemp();
155 
156  // Set functions
157 
158  // Position
159  bool setStepSize(u_int16_t stepsize);
160 
161  // Temperature
162  bool setTemperatureCompensation(bool enable);
163  bool setTemperatureCompensationMode(char mode);
164  bool setTemperatureCompensationCoeff(char mode, int16_t coeff);
165  bool setTemperatureInceptions(char mode, int32_t inter);
166  bool setTemperatureCompensationOnStart(bool enable);
167 
168  // Motion functions
169  bool stop();
170  bool home();
171  bool center();
172 
173  // Led level
174  bool setLedLevel(int level);
175 
176  // Device Nickname
177  bool setDeviceNickname(const char *nickname);
178 
179  // Misc functions
180  bool resetFactory();
181  float calcTimeLeft(timeval, float);
182 
183  // Properties
184 
185  // Set/Get Temperature
186  INumber TemperatureN[1];
187  INumberVectorProperty TemperatureNP;
188 
189  // Enable/Disable temperature compensation
190  ISwitch TemperatureCompensateS[2];
191  ISwitchVectorProperty TemperatureCompensateSP;
192 
193  // Enable/Disable temperature compensation on start
194  ISwitch TemperatureCompensateOnStartS[2];
195  ISwitchVectorProperty TemperatureCompensateOnStartSP;
196 
197  // Temperature Coefficient Mode
198  ISwitch TemperatureCompensateModeS[5];
199  ISwitchVectorProperty TemperatureCompensateModeSP;
200 
201  // Temperature coefficient and Intercept for selected mode
202  INumber TemperatureParamN[2];
203  INumberVectorProperty TemperatureParamNP;
204 
205  // Reset to Factory setting
206  ISwitch ResetS[1];
207  ISwitchVectorProperty ResetSP;
208 
209  // Go to home/center
210  ISwitch GotoS[2];
211  ISwitchVectorProperty GotoSP;
212 
213  // Status indicators
214  ILight StatusL[8];
215  ILightVectorProperty StatusLP;
216 
217  // Max Travel for relative focusers
218  // INumber MaxTravelN[1];
219  // INumberVectorProperty MaxTravelNP;
220 
221  // Focuser Step Size
222  INumber StepSizeN[1];
223  INumberVectorProperty StepSizeNP;
224 
225  // Focus name configure in the HUB
226  IText HFocusNameT[1] {};
227  ITextVectorProperty HFocusNameTP;
228 
229  // Request mandatory action of sync from user
230  ISwitch SyncMandatoryS[2];
231  ISwitchVectorProperty SyncMandatorySP;
232 
233  bool isAbsolute;
234  bool isSynced;
235  bool isHoming;
236  // TODO add property for this.
237  bool m_HomeOnStart {false};
238 
239  static const uint8_t LYNX_MAX { 64 };
240 };
FocusLynxBase::DBG_FOCUS
uint32_t DBG_FOCUS
Definition: focuslynxbase.h:110
FocusLynxBase::STATUS_HNDCTRL
@ STATUS_HNDCTRL
Definition: focuslynxbase.h:73
FocusLynxBase::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: focuslynxbase.cpp:312
FocusLynxBase::getFocusTarget
const char * getFocusTarget()
Definition: focuslynxbase.cpp:3494
IPState
IPState
Property state.
Definition: indiapi.h:158
FocusLynxBase::ISGetProperties
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: focuslynxbase.cpp:205
FocusLynxBase::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: focuslynxbase.cpp:287
FocusLynxBase::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetPosition) override
MoveFocuser the focuser to an absolute position.
Definition: focuslynxbase.cpp:3126
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
ISwitch
One switch descriptor.
FocusLynxBase::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: focuslynxbase.cpp:3218
indicom.h
Implementations for common driver routines.
connectiontcp.h
FocusLynxBase::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: focuslynxbase.cpp:95
INumber
One number descriptor.
FocusLynxBase::LedN
INumber LedN[1]
Definition: focuslynxbase.h:132
FocusLynxBase::version
char version[16]
Definition: focuslynxbase.h:136
FocusLynxBase::LedNP
INumberVectorProperty LedNP
Definition: focuslynxbase.h:133
FocusLynxBase::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: focuslynxbase.cpp:2808
FocusLynxBase::loadConfig
virtual bool loadConfig(bool silent, const char *property) override
Load the last saved configuration file.
Definition: focuslynxbase.cpp:3442
FocusLynxBase::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: focuslynxbase.cpp:3418
FocusLynxBase::FOCUS_A_COEFF
@ FOCUS_A_COEFF
Definition: focuslynxbase.h:58
indifocuser.h
FocusLynxBase::getVersion
virtual int getVersion(int *major, int *minor, int *sub)
Definition: focuslynxbase.cpp:3503
FocusLynxBase::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: focuslynxbase.cpp:2685
FocusLynxBase::STATUS_REMOTEIO
@ STATUS_REMOTEIO
Definition: focuslynxbase.h:72
FocusLynxBase::FOCUS_F_COEFF
@ FOCUS_F_COEFF
Definition: focuslynxbase.h:63
FocusLynxBase::STATUS_REVERSE
@ STATUS_REVERSE
Definition: focuslynxbase.h:74
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
FocusLynxBase::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: focuslynxbase.cpp:2744
FocusLynxBase::MoveFocuser
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
Definition: focuslynxbase.cpp:3051
ILight
One light descriptor.
FocusLynxBase::SetFocuserBacklashEnabled
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
Definition: focuslynxbase.cpp:2568
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
FocusLynxBase::setFocusTarget
void setFocusTarget(const char *target)
Definition: focuslynxbase.cpp:3485
FocusLynxBase::FOCUS_E_COEFF
@ FOCUS_E_COEFF
Definition: focuslynxbase.h:62
IText
One text descriptor.
connectionserial.h
FocusLynxBase::STATUS_HOMED
@ STATUS_HOMED
Definition: focuslynxbase.h:69
FocusLynxBase::STATUS_MOVING
@ STATUS_MOVING
Definition: focuslynxbase.h:67
FocusLynxBase::debugTriggered
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition: focuslynxbase.cpp:3476
FocusLynxBase::ModelS
ISwitch * ModelS
Definition: focuslynxbase.h:128
FocusLynxBase::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: focuslynxbase.cpp:2627
FocusLynxBase::SyncMandatory
bool SyncMandatory(bool enable)
Definition: focuslynxbase.cpp:3576
FocusLynxBase::GOTO_HOME
@ GOTO_HOME
Definition: focuslynxbase.h:80
FocusLynxBase::LYNX_STATUS
LYNX_STATUS
Definition: focuslynxbase.h:65
FocusLynxBase::STATUS_HOMING
@ STATUS_HOMING
Definition: focuslynxbase.h:68
FocusLynxBase::setDeviceType
bool setDeviceType(int index)
Definition: focuslynxbase.cpp:1947
FocusLynxBase::FOCUS_C_COEFF
@ FOCUS_C_COEFF
Definition: focuslynxbase.h:60
FocusLynxBase::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: focuslynxbase.cpp:512
FocusLynxBase::getDefaultName
virtual const char * getDefaultName() override
Definition: focuslynxbase.cpp:303
FocusLynxBase::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: focuslynxbase.cpp:490
FocusLynxBase::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: focuslynxbase.cpp:220
FocusLynxBase
Definition: focuslynxbase.h:50
FocusLynxBase::FOCUS_B_COEFF
@ FOCUS_B_COEFF
Definition: focuslynxbase.h:59
FocusLynxBase::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: focuslynxbase.cpp:3196
FocusLynxBase::FocusLynxBase
FocusLynxBase()
Definition: focuslynxbase.cpp:33
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
FocusLynxBase::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: focuslynxbase.cpp:3325
ISState
ISState
Switch state.
Definition: indiapi.h:148
FocusLynxBase::isResponseOK
bool isResponseOK()
Definition: focuslynxbase.cpp:2996
FocusLynxBase::GOTO_CENTER
@ GOTO_CENTER
Definition: focuslynxbase.h:79
FocusLynxBase::configurationComplete
bool configurationComplete
Definition: focuslynxbase.h:125
FocusLynxBase::STATUS_UNKNOWN
@ STATUS_UNKNOWN
Definition: focuslynxbase.h:75
FocusLynxBase::ack
bool ack()
Definition: focuslynxbase.cpp:634
INDI::Focuser
Definition: indifocuser.h:43
FocusLynxBase::STATUS_TMPPROBE
@ STATUS_TMPPROBE
Definition: focuslynxbase.h:71
FocusLynxBase::checkIfAbsoluteFocuser
bool checkIfAbsoluteFocuser()
Definition: focuslynxbase.cpp:3528
FocusLynxBase::STATUS_FFDETECT
@ STATUS_FFDETECT
Definition: focuslynxbase.h:70
FocusLynxBase::FOCUS_D_COEFF
@ FOCUS_D_COEFF
Definition: focuslynxbase.h:61
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
FocusLynxBase::ModelSP
ISwitchVectorProperty ModelSP
Definition: focuslynxbase.h:129