Instrument Neutral Distributed Interface INDI 2.2.5
synscandriver.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#pragma once
20
21#include "inditelescope.h"
22#include "indiguiderinterface.h"
23#include "libastro.h"
24
26{
27 public:
29
30 typedef enum { SYN_N, SYN_S, SYN_E, SYN_W } SynscanDirection;
31
32 virtual bool initProperties() override;
33 virtual bool updateProperties() override;
34 virtual const char * getDefaultName() override;
35
36 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
37 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
38
39 static void guideTimeoutHelperNS(void *context);
40 static void guideTimeoutHelperWE(void *context);
41
42 protected:
43 virtual bool Handshake() override;
44
45 // Get RA/DE and status
46 virtual bool ReadScopeStatus() override;
47
48 // Time & Location
49 virtual bool updateLocation(double latitude, double longitude, double elevation) override;
50 virtual bool updateTime(ln_date * utc, double utc_offset) override;
51
52 // Parking
53 virtual bool Park() override;
54 virtual bool UnPark() override;
55 virtual bool SetCurrentPark() override;
56 virtual bool SetDefaultPark() override;
57
58 // Motion
59 virtual bool Sync(double ra, double dec) override;
60 virtual bool Goto(double, double) override;
61 virtual bool GotoAzAlt(double az, double alt);
62 virtual bool Abort() override;
63 virtual bool SetSlewRate(int index) override;
64 virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
65 virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
66
67 // Tracking
68 virtual bool SetTrackEnabled(bool enabled) override;
69 virtual bool SetTrackMode(uint8_t mode) override;
70
71 // Guiding
72 virtual IPState GuideNorth(uint32_t ms) override;
73 virtual IPState GuideSouth(uint32_t ms) override;
74 virtual IPState GuideEast(uint32_t ms) override;
75 virtual IPState GuideWest(uint32_t ms) override;
76
77 private:
88 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
89 // Check if mount is responding
90 virtual bool echo();
91
92 // Initial Params
93 void setupParams();
94 // Send
95 void sendStatus();
96 bool sendTime();
97 bool sendLocation();
98 // Read
99 bool readFirmware();
100 bool readModel();
101 bool readTracking();
102 // Goto mode
103 bool SetAltAzMode(bool);
104
105 // Slew
106 bool slewFixedRate(SynscanDirection direction, uint8_t rate);
107 bool isSlewComplete();
108
109 // Guiding
110 void guideTimeoutCallbackNS();
111 void guideTimeoutCallbackWE();
112
119 bool slewVariableRate(SynscanDirection direction, double rate);
120
121 // Simulation
122 void mountSim();
123
124 double CurrentRA { 0 }, CurrentDE { 0 };
125 double TargetRA {0}, TargetDE {0};
126 uint8_t m_MountModel { 0 };
127 int m_TargetSlewRate { 5 };
128 uint8_t m_TrackingFlag { 0 };
129 double m_FirmwareVersion { 0 };
130 double m_CustomGuideRA { 0 }, m_CustomGuideDE { 0 };
131 int m_GuideNSTID { 0 }, m_GuideWETID { 0 };
132
133 // Utility
134 int hexStrToInteger(const std::string &str);
135 void hexDump(char *buf, const char *data, int size);
136
137 // Is mount type Alt-Az?
138 bool m_isAltAz { false };
139 // Use Alt-Az Goto?
140 bool goto_AltAz { false };
141
145
146 // Mount Status
147 IText StatusT[5] = {};
148 ITextVectorProperty StatusTP;
149
150 // Custom Slew Rate
151 INumber CustomSlewRateN[2];
152 INumberVectorProperty CustomSlewRateNP;
153
154 // Guide Rate
155 INumber GuideRateN[2];
156 INumberVectorProperty GuideRateNP;
157
158 // Horizontal Coords
159 INumber HorizontalCoordsN[2];
160 INumberVectorProperty HorizontalCoordsNP;
161
162 // Goto mode
163 ISwitch GotoModeS[2];
164 ISwitchVectorProperty GotoModeSP;
165
166 // Mount Info
167 enum MountInfo
168 {
169 MI_FW_VERSION,
170 MI_MOUNT_MODEL,
171 MI_GOTO_STATUS,
172 MI_POINT_STATUS,
173 MI_TRACK_MODE
174 };
175 std::vector<std::string> m_MountInfo;
176
180
181 // Simulated Slew Rates
182 static constexpr uint16_t SIM_SLEW_RATE[] = {1, 8, 16, 32, 64, 128, 400, 600, 800, 900};
183 // Maximum buffer for reading from Synscan
184 static const uint8_t SYN_RES = 64;
185 // Timeout
186 static const uint8_t SYN_TIMEOUT = 3;
187 // Delimiter
188 static const char SYN_DEL = {'#'};
189 // Mount Information Tab
190 static constexpr const char * MOUNT_TAB = "Mount Information";
191};
int SetSlewRate(void)
virtual bool Park() override
Park the telescope to its home position.
static void guideTimeoutHelperWE(void *context)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
static void guideTimeoutHelperNS(void *context)
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual const char * getDefaultName() override
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool Handshake() override
perform handshake with device to check communication
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual bool GotoAzAlt(double az, double alt)
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
INDI_DIR_WE
INDI_DIR_NS
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244