Instrument Neutral Distributed Interface INDI 2.2.5
indi_alpaca_telescope.h
Go to the documentation of this file.
1/*
2 INDI alpaca Driver
3
4 Copyright (C) 2026 Gord Tulloch
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#pragma once
22
23#include <inditelescope.h>
24#include <memory>
25#include <vector>
26#include <httplib.h>
27
28#ifdef _USE_SYSTEM_JSONLIB
29#include <nlohmann/json.hpp>
30#else
31#include <indijson.hpp>
32#endif
33
35{
36 public:
38 virtual ~alpacaTelescopeDriver() = default;
39
40 virtual const char *getDefaultName() override;
41 virtual bool initProperties() override;
42 virtual bool updateProperties() override;
43 virtual bool Connect() override;
44 virtual bool Disconnect() override;
45 virtual bool ReadScopeStatus() override;
46
47 protected:
48 // Connection
49 virtual bool Handshake() override;
50
51 // Telescope Operations
52 virtual bool Goto(double ra, double dec) override;
53 virtual bool Sync(double ra, double dec) override;
54 virtual bool Abort() override;
55
56 // Parking
57 virtual bool Park() override;
58 virtual bool UnPark() override;
59 virtual bool SetCurrentPark() override;
60
61 // Tracking
62 virtual bool SetTrackEnabled(bool enabled) override;
63 virtual bool SetTrackMode(uint8_t mode) override;
64 virtual bool SetTrackRate(double raRate, double deRate) override;
65
66 // Motion Control
67 virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
68 virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
69
70 // Save configuration
71 virtual bool saveConfigItems(FILE *fp) override;
72
73 // Site location
74 virtual bool updateLocation(double latitude, double longitude, double elevation) override;
75
76 // Time
77 virtual bool updateTime(ln_date *utc, double utc_offset) override;
78
79 private:
80 // State tracking
81 double m_currentRA { 0 };
82 double m_currentDEC { 90 };
83 double m_currentAz { 180 };
84 double m_currentAlt { 0 };
85 double m_targetRA { 0 };
86 double m_targetDEC { 0 };
87 double m_sinLat, m_cosLat;
88 bool isParked{false};
89 bool isSlewing{false};
90 bool isTracking{false};
91 double currentSlewRate{0.5}; // Current slew rate in deg/sec
92
93 // Async slew support: prefer /slewtotargetasync over the blocking /slewtotarget
94 bool m_CanSlewAsync{false};
95
96 // Track modes: maps an index in TrackModeSP to the corresponding Alpaca
97 // DriveRate value (0=Sidereal, 1=Lunar, 2=Solar, 3=King) reported by /trackingrates
98 std::vector<int> m_TrackModeAlpacaRates;
99
100 // Custom tracking rate support (TELESCOPE_HAS_TRACK_RATE)
101 bool m_CanSetRaRate{false};
102 bool m_CanSetDecRate{false};
103
104 // used by GoTo and Park
105 void StartSlew(double ra, double dec, TelescopeStatus status);
106
107 unsigned int DBG_SCOPE { 0 };
108
109 // Scope type and alignment
110 INDI::PropertySwitch mountTypeSP {2};
111 enum
112 {
113 ALTAZ,
114 EQ_FORK
115 };
116
117 // HTTP client for Alpaca communication
118 std::unique_ptr<httplib::Client> httpClient;
119 int m_DeviceNumber{0};
120 int m_ClientID;
121 int m_TransactionID{0};
122
123 // Device info properties
124 INDI::PropertyText DeviceInfoTP {4};
125 enum { DESCRIPTION, DRIVER_INFO, DRIVER_VERSION, INTERFACE_VERSION };
126
127 // Alpaca helper methods
128 std::string getAlpacaURL(const std::string& endpoint);
129 int getTransactionId()
130 {
131 return ++m_TransactionID;
132 }
133 bool sendAlpacaGET(const std::string& endpoint, nlohmann::json& response);
134 bool sendAlpacaPUT(const std::string& endpoint, const nlohmann::json& request, nlohmann::json& response);
135
136};
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool Disconnect() override
Disconnect from device.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual const char * getDefaultName() override
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual ~alpacaTelescopeDriver()=default
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool Park() override
Park the telescope to its home position.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
a class to store JSON values
double ra
double dec
INDI_DIR_WE
INDI_DIR_NS