Instrument Neutral Distributed Interface INDI 2.2.5
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 ([email protected])
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
38
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)
64
65
68
69 // Sync
72
73
74 private:
75
79 bool setParam(const std::string &param, uint32_t value);
80 bool getParam(const std::string &param, uint32_t &value);
81 bool gotoTarget(uint32_t position);
82 // bool setSpeedRange(uint32_t min, uint32_t max);
83 bool syncSettings();
84 bool echo();
85 double calculateAngle(uint32_t steps);
86
90 bool sendCommand(const char * cmd, int32_t &res);
91 void hexDump(char * buf, const char * data, int size);
92 std::vector<std::string> split(const std::string &input, const std::string &regex);
93
97
98 // Settings
99 INDI::PropertyNumber SettingNP {1};
100 enum { PARAM_STEPS_DEGREE };
101
102 // Rotator Steps
103 INDI::PropertyNumber RotatorAbsPosNP {1};
104
105
109 bool m_IsMoving {false};
110 uint32_t m_ZeroPosition {0};
111
115 static constexpr const char * SETTINGS_TAB = "Settings";
116 // '#' is the stop char
117 static const char DRIVER_STOP_CHAR { 0x23 };
118 // Wait up to a maximum of 3 seconds for serial input
119 static constexpr const uint8_t DRIVER_TIMEOUT {3};
120 // Maximum buffer for sending/receiving.
121 static constexpr const uint8_t DRIVER_LEN {128};
122 // Operatives
123 static constexpr const uint8_t DRIVER_OPERATIVES {2};
124 // Models
125 static constexpr const uint8_t DRIVER_MODELS {4};
126
127 INDI::PropertySwitch SteppingModeSP {3};
128 enum
129 {
130 STEPPING_WAVE,
131 STEPPING_HALF,
132 STEPPING_FULL,
133 };
134
135 INDI::PropertySwitch CoilStatusSP {2};
136 enum
137 {
138 COIL_ENERGIZED_OFF,
139 COIL_ENERGIZED_ON,
140 };
141
142 INDI::PropertyNumber SteppingPhaseNP{3};
143
144 INDI::PropertyNumber MaxSpeedNP {1};
145
146 bool readPosition();
147 bool readCompensationInfo();
148 bool readSpeedInfo();
149 bool readSteppingInfo();
150 bool readCoilStatus();
151 bool setSteppingPhase(uint8_t phase);
152 bool setCoilStatus(uint8_t status);
153 bool setMaxSpeed(uint8_t maxSpeed);
154
155 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
156 bool getStartupValues();
157 bool isMoving();
158
159 int32_t m_TargetDiff { 0 };
160 double requestedAngle = -1.0;
161 bool wantAbort = false;
162
163
164 static constexpr const char * STEPPING_TAB = "Stepping";
165 // '#' is the stop char
166 static const char NFRAME_STOP_CHAR { 0x23 };
167 // Wait up to a maximum of 3 seconds for serial input
168 static constexpr const uint8_t NFRAME_TIMEOUT {3};
169 // Maximum buffer for sending/receiving.
170 static constexpr const uint8_t NFRAME_LEN {64};
171
172
173};
@ 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:71
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the reverse direction property in the configuration file
Definition nframe.cpp:636
virtual ~nFrameRotator() override=default
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
INDI::PropertyNumber RotatorSpeedNP
Definition nframe.h:63
INumber ROtateMaxPosN[1]
Definition nframe.h:67
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:70
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
Initialize properties initial state and value. The child class must implement this function.
Definition nframe.cpp:45
INumberVectorProperty RotateMaxPosNP
Definition nframe.h:66
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
Number vector property descriptor.
Definition indiapi.h:317