Instrument Neutral Distributed Interface INDI 2.2.5
scopedome_dome.h
Go to the documentation of this file.
1/*******************************************************************************
2 ScopeDome Dome INDI Driver
3
4 Copyright(c) 2017-2024 Jarno Paananen. All rights reserved.
5
6 based on:
7
8 ScopeDome Windows ASCOM driver version 5.1.30
9
10 and
11
12 Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
13
14 Baader Planetarium Dome INDI Driver
15
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License version 2 as published by the Free Software Foundation.
19 .
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Library General Public License for more details.
24 .
25 You should have received a copy of the GNU Library General Public License
26 along with this library; see the file COPYING.LIB. If not, write to
27 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.
29*******************************************************************************/
30
31#pragma once
32
33#include "indidome.h"
34#include "indipropertyswitch.h"
35#include "indipropertynumber.h"
36#include "indipropertytext.h"
37
38#include <string>
39#include <vector>
40
46{
47 public:
48
62
72
74 {
78 };
79
86
88 {
89 std::string propName;
90 std::string label;
91 std::string format;
92 float minValue;
93 float maxValue;
94 };
95
96 struct RelayInfo
97 {
98 std::string propName;
99 std::string label;
100 };
101
103 {
104 std::string propName;
105 std::string label;
106 };
107
113
115 virtual ~ScopeDomeCard() = default;
116
117 virtual bool detect() = 0;
118 const char *getDeviceName()
119 {
120 return (const char *)"ScopeDome Dome";
121 };
122 virtual void setPortFD(int fd) = 0;
123
124 // State polling
125 virtual int updateState() = 0;
126 virtual uint32_t getStatus() = 0;
127 virtual int getRotationCounter() = 0;
128 virtual int getRotationCounterExt() = 0;
129
130 // Information
131 virtual void getFirmwareVersions(double &main, double &rotary) = 0;
132 virtual uint32_t getStepsPerRevolution() = 0;
133 virtual bool isCalibrationNeeded() = 0;
134
135 // Commands
136 virtual void abort() = 0;
137 virtual void calibrate() = 0;
138 virtual void findHome() = 0;
139 virtual void controlShutter(ShutterOperation operation) = 0;
140
141 virtual void resetCounter() = 0;
142
143 // negative means CCW, positive CW steps
144 virtual void move(int steps) = 0;
145
146 // Input/Output management
147 virtual size_t getNumberOfSensors() = 0;
148 virtual SensorInfo getSensorInfo(size_t index) = 0;
149 virtual double getSensorValue(size_t index) = 0;
150
151 virtual size_t getNumberOfRelays() = 0;
152 virtual RelayInfo getRelayInfo(size_t index) = 0;
153 virtual ISState getRelayState(size_t index) = 0;
154 virtual void setRelayState(size_t index, ISState state) = 0;
155
156 virtual size_t getNumberOfInputs() = 0;
157 virtual InputInfo getInputInfo(size_t index) = 0;
158 virtual ISState getInputValue(size_t index) = 0;
159
161 virtual int setOutputState(AbstractOutput output, ISState state) = 0;
162
163 virtual void setHomeSensorPolarity(HomeSensorPolarity polarity) = 0;
164
165 protected:
167 ScopeDomeCard() = default;
168
169 private:
171 ScopeDomeCard(const ScopeDomeCard &rhs) = delete;
173 ScopeDomeCard &operator=(const ScopeDomeCard &rhs) = delete;
174};
175
176class ScopeDome : public INDI::Dome
177{
178 public:
187
188 ScopeDome();
189 virtual ~ScopeDome() = default;
190
191 virtual const char *getDefaultName() override;
192 virtual bool initProperties() override;
193 virtual bool updateProperties() override;
194 virtual bool saveConfigItems(FILE *fp) override;
195
196 virtual bool Handshake() override;
197
198 virtual void TimerHit() override;
199
200 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
201 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
202 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
203
204 virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override;
205 virtual IPState MoveRel(double azDiff) override;
206 virtual IPState MoveAbs(double az) override;
207 virtual IPState ControlShutter(ShutterOperation operation) override;
208 virtual bool Abort() override;
209
210 // Parking
211 virtual IPState Park() override;
212 virtual IPState UnPark() override;
213 virtual bool SetCurrentPark() override;
214 virtual bool SetDefaultPark() override;
215
216 protected:
217 // Commands
218 bool UpdatePosition();
219 bool UpdateShutterStatus();
220 bool UpdateSensorStatus();
221 bool UpdateRelayStatus();
222
223 // Misc
224 bool SetupParms();
225
227 double targetAz{ 0 };
228 bool refineMove{ false };
230 bool sim{ false };
231 double simShutterTimer{ 0 };
233
240
242
244
246
248
250
252
254
256
258
259 // Dynamic properties initialized based on card type
263
264 private:
265 uint16_t currentStatus;
266 int32_t currentRotation;
267 int32_t rotationCounter;
268
269 uint32_t stepsPerRevolution;
270
271 std::unique_ptr<ScopeDomeCard> interface;
272
273 IPState sendMove(double azDiff);
274
275 // Dome inertia compensation
276 std::vector<uint16_t> inertiaTable;
277 int compensateInertia(int steps);
278
279 // Needed to access reconnect function
280 friend class ScopeDomeUSB21;
281 friend class ScopeDomeArduino;
282
283 void reconnect();
284 bool reconnecting{false};
285 bool reconnected{false};
286
287 const INDI::PropertyText &getCredentials() const
288 {
289 return CredentialsTP;
290 };
291
292 // Dew point calculation
293 float getDewPoint(float RH, float T);
294
295 ISState rotaryLinkEstablished {ISS_OFF};
296};
Class to provide general functionality of a Dome device.
Definition indidome.h:75
ShutterOperation
Shutter operation command.
Definition indidome.h:114
DomeMotionCommand
Definition indidome.h:97
@ SHUTTER_OPENED
Definition indidome.h:147
virtual void abort()=0
virtual bool isCalibrationNeeded()=0
virtual void getFirmwareVersions(double &main, double &rotary)=0
virtual void findHome()=0
virtual InputInfo getInputInfo(size_t index)=0
virtual double getSensorValue(size_t index)=0
virtual ISState getRelayState(size_t index)=0
virtual int getRotationCounter()=0
virtual RelayInfo getRelayInfo(size_t index)=0
virtual size_t getNumberOfRelays()=0
virtual uint32_t getStepsPerRevolution()=0
virtual ISState getInputState(AbstractInput input)=0
virtual bool detect()=0
virtual int getRotationCounterExt()=0
virtual ISState getInputValue(size_t index)=0
virtual void setRelayState(size_t index, ISState state)=0
virtual void resetCounter()=0
ScopeDomeCard()=default
virtual uint32_t getStatus()=0
virtual void setHomeSensorPolarity(HomeSensorPolarity polarity)=0
virtual size_t getNumberOfSensors()=0
virtual void controlShutter(ShutterOperation operation)=0
virtual void move(int steps)=0
const char * getDeviceName()
virtual int updateState()=0
virtual size_t getNumberOfInputs()=0
virtual SensorInfo getSensorInfo(size_t index)=0
virtual int setOutputState(AbstractOutput output, ISState state)=0
virtual void setPortFD(int fd)=0
virtual void calibrate()=0
virtual ~ScopeDomeCard()=default
virtual ~ScopeDome()=default
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
INDI::PropertySwitch DerotateSP
virtual const char * getDefaultName() override
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
INDI::PropertyText CredentialsTP
ShutterState simShutterStatus
INDI::PropertySwitch FindHomeSP
ShutterOperation targetShutter
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
double targetAz
INDI::PropertyNumber DomeHomePositionNP
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
DomeStatus status
bool UpdateSensorStatus()
INDI::PropertyNumber FirmwareVersionsNP
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool Abort() override
Abort all dome motion.
INDI::PropertySwitch CardTypeSP
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool UpdateShutterStatus()
virtual bool Handshake() override
perform handshake with device to check communication
INDI::PropertySwitch StartCalibrationSP
INDI::PropertySwitch HomeSensorPolaritySP
INDI::PropertySwitch InputsSP
INDI::PropertySwitch RelaysSP
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
INDI::PropertyNumber SensorsNP
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
INDI::PropertyNumber StepsPerRevolutionNP
INDI::PropertySwitch CalibrationNeededSP
double simShutterTimer
bool UpdateRelayStatus()
bool UpdatePosition()
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
int main()
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
IPState
Property state.
Definition indiapi.h:158
int fd