Instrument Neutral Distributed Interface INDI  2.0.2
nframe.h
Go to the documentation of this file.
1 /*
2  nFrame Rotator by Gene N
3  Based on:
4  nstep focuser driver and
5  Seletek Rotator Driver
6 
7  Copyright (C) 2020 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 <indirotator.h>
28 
30 {
31  public:
32 
34  {
37  };
38 
39  nFrameRotator();
40  virtual ~nFrameRotator() override = default;
41 
42  virtual bool Handshake() override;
43  const char *getDefaultName() override;
44  virtual void ISGetProperties(const char *dev) override;
45  virtual bool initProperties() override;
46  virtual bool updateProperties() override;
47  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
48  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
49 
50  protected:
51  virtual IPState MoveRotator(double angle) override;
52  virtual bool AbortRotator() override;
53  virtual bool SyncRotator(double angle) override;
54  bool SetRotatorSpeed(uint8_t speed) ;
55  bool SyncRotator(uint32_t ticks) ;
56 
57  virtual bool saveConfigItems(FILE *fp) override;
58 
59  virtual void TimerHit() override;
60 
61  // GeneN hack
62  // Rotator Speed (if variable speeds are supported)
65 
66 
69 
70  // Sync
73 
74 
75  private:
76 
80  bool setParam(const std::string &param, uint32_t value);
81  bool getParam(const std::string &param, uint32_t &value);
82  bool gotoTarget(uint32_t position);
83  // bool setSpeedRange(uint32_t min, uint32_t max);
84  bool syncSettings();
85  bool echo();
86  double calculateAngle(uint32_t steps);
87 
91  bool sendCommand(const char * cmd, int32_t &res);
92  void hexDump(char * buf, const char * data, int size);
93  std::vector<std::string> split(const std::string &input, const std::string &regex);
94 
98 
99  // Settings
100  INumberVectorProperty SettingNP;
101  INumber SettingN[1];
102  enum { PARAM_STEPS_DEGREE };
103 
104  // Rotator Steps
105  INumber RotatorAbsPosN[1];
106  INumberVectorProperty RotatorAbsPosNP;
107 
108 
112  bool m_IsMoving {false};
113  uint32_t m_ZeroPosition {0};
114 
118  static constexpr const char * SETTINGS_TAB = "Settings";
119  // '#' is the stop char
120  static const char DRIVER_STOP_CHAR { 0x23 };
121  // Wait up to a maximum of 3 seconds for serial input
122  static constexpr const uint8_t DRIVER_TIMEOUT {3};
123  // Maximum buffer for sending/receving.
124  static constexpr const uint8_t DRIVER_LEN {128};
125  // Operatives
126  static constexpr const uint8_t DRIVER_OPERATIVES {2};
127  // Models
128  static constexpr const uint8_t DRIVER_MODELS {4};
129 
130  ISwitch SteppingModeS[3];
131  ISwitchVectorProperty SteppingModeSP;
132  enum
133  {
134  STEPPING_WAVE,
135  STEPPING_HALF,
136  STEPPING_FULL,
137  };
138 
139  ISwitch CoilStatusS[2];
140  ISwitchVectorProperty CoilStatusSP;
141  enum
142  {
143  COIL_ENERGIZED_OFF,
144  COIL_ENERGIZED_ON,
145  };
146 
147  INumber SteppingPhaseN[1];
148  INumberVectorProperty SteppingPhaseNP;
149 
150  INumber MaxSpeedN[1];
151  INumberVectorProperty MaxSpeedNP;
152 
153  bool readPosition();
154  bool readCompensationInfo();
155  bool readSpeedInfo();
156  bool readSteppingInfo();
157  bool readCoilStatus();
158  bool setSteppingPhase(uint8_t phase);
159  bool setCoilStatus(uint8_t status);
160  bool setMaxSpeed(uint8_t maxSpeed);
161 
162  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
163  bool getStartupValues();
164  bool isMoving();
165 
166  int32_t m_TargetDiff { 0 };
167  double requestedAngle = -1.0;
168  bool wantAbort = false;
169 
170 
171  static constexpr const char * STEPPING_TAB = "Stepping";
172  // '#' is the stop char
173  static const char NFRAME_STOP_CHAR { 0x23 };
174  // Wait up to a maximum of 3 seconds for serial input
175  static constexpr const uint8_t NFRAME_TIMEOUT {3};
176  // Maximum buffer for sending/receving.
177  static constexpr const uint8_t NFRAME_LEN {64};
178 
179 
180 };
@ ROTATE_OUTWARD
Definition: nframe.h:36
@ ROTATE_INWARD
Definition: nframe.h:35
virtual bool SyncRotator(double angle) override
SyncRotator Set current angle as the supplied angle without moving the rotator.
Definition: nframe.cpp:579
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: nframe.cpp:107
virtual IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
Definition: nframe.cpp:377
bool SyncRotator(uint32_t ticks)
INumber RotateSyncN[1]
Definition: nframe.h:72
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the reverse direction property in the configuration file
Definition: nframe.cpp:636
virtual ~nFrameRotator() override=default
INumber RotatorSpeedN[1]
Definition: nframe.h:64
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: nframe.cpp:408
virtual bool Handshake() override
perform handshake with device to check communication
Definition: nframe.cpp:153
INumberVectorProperty RotatorSpeedNP
Definition: nframe.h:63
INumber ROtateMaxPosN[1]
Definition: nframe.h:68
bool SetRotatorSpeed(uint8_t speed)
Definition: nframe.cpp:599
const char * getDefaultName() override
Definition: nframe.cpp:102
virtual bool AbortRotator() override
AbortRotator Abort all motion.
Definition: nframe.cpp:397
INumberVectorProperty RotateSyncNP
Definition: nframe.h:71
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: nframe.cpp:324
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: nframe.cpp:662
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: nframe.cpp:235
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: nframe.cpp:45
INumberVectorProperty RotateMaxPosNP
Definition: nframe.h:67
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367