Instrument Neutral Distributed Interface INDI  1.9.5
deepskydad_af2.h
Go to the documentation of this file.
1 /*
2  Deep Sky Dad AF2
3 
4  Copyright (C) 2019 Pavle Gartner
5 
6  Based on Moonline driver.
7  Copyright (C) 2013-2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 */
24 
25 #pragma once
26 
27 #include "indifocuser.h"
28 
29 #include <chrono>
30 
32 {
33  public:
34  DeepSkyDadAF2();
35  virtual ~DeepSkyDadAF2() override = default;
36 
37  typedef enum { FULL, HALF, QUARTER, EIGHT } FocusStepMode;
38 
41 
42  const char * getDefaultName() override;
43  virtual bool initProperties() override;
44  virtual bool updateProperties() override;
45  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
46  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
47 
48  static void timedMoveHelper(void * context);
49  protected:
50  /*
51  * @brief Handshake Try to communicate with Focuser and see if there is a valid response.
52  * @return True if communication is successful, false otherwise.
53  */
54  virtual bool Handshake() override;
55 
63  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
64 
70  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
71 
78  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
79 
80  virtual bool SyncFocuser(uint32_t ticks) override;
81  virtual bool ReverseFocuser(bool enabled) override;
82  virtual bool AbortFocuser() override;
83  virtual void TimerHit() override;
84  virtual bool saveConfigItems(FILE * fp) override;
85 
86  private:
87  bool Ack();
95  bool sendCommand(const char * cmd, char * res = nullptr);
96  bool sendCommandSet(const char * cmd);
97 
98  // Get initial focuser parameter when we first connect
99  void GetFocusParams();
100  bool readStepMode();
101  bool readPosition();
102  bool readMaxPosition();
103  bool readMaxMovement();
104  bool readSettleBuffer();
105  bool readIdleCoilsTimeout();
106  bool readCoilsMode();
107  bool readCurrentMove();
108  bool readCurrentHold();
109  bool isMoving();
110  bool readTemperature();
111 
112  void timedMoveCallback();
113 
114  bool MoveFocuser(uint32_t position);
115 
116  double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 };
117 
118  // Step modes
119  ISwitch StepModeS[4];
120  ISwitchVectorProperty StepModeSP;
121 
122  // Coils mode
123  ISwitch CoilsModeS[3];
124  ISwitchVectorProperty CoilsModeSP;
125 
126  //Current move
127  ISwitch CurrentMoveS[4];
128  ISwitchVectorProperty CurrentMoveSP;
129 
130  //Current hold
131  ISwitch CurrentHoldS[4];
132  ISwitchVectorProperty CurrentHoldSP;
133 
134  // Max movement
135  INumber FocusMaxMoveN[1];
136  INumberVectorProperty FocusMaxMoveNP;
137 
138  // Settle buffer
139  INumber SettleBufferN[1];
140  INumberVectorProperty SettleBufferNP;
141 
142  // Idle coils timeout (ms)
143  INumber IdleCoilsTimeoutN[1];
144  INumberVectorProperty IdleCoilsTimeoutNP;
145 
146  INumber TemperatureN[1];
147  INumberVectorProperty TemperatureNP;
148 
149  // Response Buffer
150 
151  static const uint8_t DSD_RES { 32 };
152  static const char DSD_DEL { ')' };
153  static const uint8_t DSD_TIMEOUT { 3 };
154 };
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
DeepSkyDadAF2::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: deepskydad_af2.cpp:43
IPState
IPState
Property state.
Definition: indiapi.h:158
DeepSkyDadAF2::CURRENT_100
@ CURRENT_100
Definition: deepskydad_af2.h:40
ISwitch
One switch descriptor.
INumber
One number descriptor.
DeepSkyDadAF2::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: deepskydad_af2.cpp:930
DeepSkyDadAF2::getDefaultName
const char * getDefaultName() override
Definition: deepskydad_af2.cpp:164
DeepSkyDadAF2::CURRENT_50
@ CURRENT_50
Definition: deepskydad_af2.h:40
DeepSkyDadAF2::CURRENT_25
@ CURRENT_25
Definition: deepskydad_af2.h:40
DeepSkyDadAF2
Definition: deepskydad_af2.h:31
DeepSkyDadAF2::FULL
@ FULL
Definition: deepskydad_af2.h:37
DeepSkyDadAF2::Current
Current
Definition: deepskydad_af2.h:40
indifocuser.h
DeepSkyDadAF2::HALF
@ HALF
Definition: deepskydad_af2.h:37
DeepSkyDadAF2::~DeepSkyDadAF2
virtual ~DeepSkyDadAF2() override=default
DeepSkyDadAF2::DeepSkyDadAF2
DeepSkyDadAF2()
Definition: deepskydad_af2.cpp:38
DeepSkyDadAF2::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: deepskydad_af2.cpp:925
DeepSkyDadAF2::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: deepskydad_af2.cpp:508
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
DeepSkyDadAF2::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: deepskydad_af2.cpp:116
DeepSkyDadAF2::ALWAYS_ON
@ ALWAYS_ON
Definition: deepskydad_af2.h:39
DeepSkyDadAF2::QUARTER
@ QUARTER
Definition: deepskydad_af2.h:37
DeepSkyDadAF2::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: deepskydad_af2.cpp:479
DeepSkyDadAF2::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: deepskydad_af2.cpp:472
DeepSkyDadAF2::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: deepskydad_af2.cpp:699
DeepSkyDadAF2::IDLE_OFF
@ IDLE_OFF
Definition: deepskydad_af2.h:39
name
const char * name
Definition: indiserver.c:116
DeepSkyDadAF2::MoveFocuser
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser Move focuser in a specific direction and speed for period of time.
Definition: deepskydad_af2.cpp:818
DeepSkyDadAF2::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: deepskydad_af2.cpp:881
DeepSkyDadAF2::IDLE_COILS_TIMEOUT
@ IDLE_COILS_TIMEOUT
Definition: deepskydad_af2.h:39
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
DeepSkyDadAF2::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
Definition: deepskydad_af2.cpp:860
DeepSkyDadAF2::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
Definition: deepskydad_af2.cpp:850
ISState
ISState
Switch state.
Definition: indiapi.h:148
DeepSkyDadAF2::FocusStepMode
FocusStepMode
Definition: deepskydad_af2.h:37
INDI::Focuser
Definition: indifocuser.h:43
DeepSkyDadAF2::timedMoveHelper
static void timedMoveHelper(void *context)
Definition: deepskydad_af2.cpp:832
DeepSkyDadAF2::CoilsMode
CoilsMode
Definition: deepskydad_af2.h:39
DeepSkyDadAF2::CURRENT_75
@ CURRENT_75
Definition: deepskydad_af2.h:40
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
DeepSkyDadAF2::EIGHT
@ EIGHT
Definition: deepskydad_af2.h:37
DeepSkyDadAF2::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: deepskydad_af2.cpp:151