Instrument Neutral Distributed Interface INDI 2.2.5
alpaca_dome.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2026 Philippe Bazart, Jérémie Klein. All rights reserved.
3
4 ASCOM Alpaca Dome INDI Driver
5
6 Based on Protocol extracted from https://github.com/rpineau/RigelDome
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 The full GNU General Public License is included in this distribution in the
24 file called LICENSE.
25*******************************************************************************/
26
27#pragma once
28
29#include "indidome.h"
30
31#include <httplib.h>
32#include <string>
33#include <functional>
34
35// Add these includes
36#ifdef _USE_SYSTEM_JSONLIB
37#include <nlohmann/json.hpp>
38#else
39#include <indijson.hpp>
40#endif
41
42class AlpacaDome : public INDI::Dome
43{
44 public:
45 AlpacaDome();
46 virtual ~AlpacaDome() = default;
47
49 virtual void TimerHit() override;
50
64 virtual void ISGetProperties(const char *dev) override;
65
71 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
72
78 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
79
85 virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n) override;
86
91 {
92 return m_CanFindHome;
93 }
94
99 {
100 return m_CanCalibrate;
101 }
102
106 bool CanPark()
107 {
108 return m_CanPark;
109 }
110
115 {
116 return m_CanSetAltitude;
117 }
118
123 {
124 return m_CanSetAzimuth;
125 }
126
131 {
132 return m_CanSetPark;
133 }
134
139 {
140 return m_CanSetShutter;
141 }
142
146 bool CanSlave()
147 {
148 return m_CanSlave;
149 }
150
155 {
156 return m_CanSyncAzimuth;
157 }
158
159 protected:
161 virtual const char *getDefaultName() override;
162
167 virtual bool initProperties() override;
168
175 virtual bool updateProperties() override;
176
184 virtual bool saveConfigItems(FILE *fp) override;
185
193 virtual bool Connect() override;
194
199 virtual bool Disconnect() override;
200
206 virtual bool SetSpeed(double rpm) override;
207
213 virtual IPState MoveRel(double azDiff) override;
214
220 virtual IPState MoveAbs(double az) override;
221
227 virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override;
228
233 virtual bool Sync(double az) override;
234
239 virtual bool Abort() override;
240
245 virtual IPState Park() override;
246
256 virtual IPState UnPark() override;
257
263 virtual IPState ControlShutter(ShutterOperation operation) override;
264
269 virtual bool SetCurrentPark() override;
270
276 virtual bool SetDefaultPark() override;
277
285 virtual IPState FindHome();
286
293 virtual IPState Calibrate();
294
295 // Alpaca customization hooks for derived drivers.
296 virtual std::string getAlpacaURL(const std::string &endpoint);
297 virtual std::string buildAlpacaFormData(const nlohmann::json &request);
298 virtual void setDefaultServerAddress(const char *host, const char *port, bool force = false);
299 virtual uint32_t getTransactionId();
300
305 enum
306 {
308 PORT
309 };
310
311 INDI::PropertyNumber DeviceNumberNP {1}; // Alpaca device number (remplace l'ancien int)
312
314 enum
315 {
318 };
319
321 enum
322 {
325 };
326
327 // Info
329 enum
330 {
336 };
337
338 private:
339 struct AlapacaDomeState
340 {
341 double altitude;
342 double azimuth;
343 int shutterStatus;
344 bool slewing;
345 bool atHome;
346 bool atPark;
347 };
348
349 void updateStatus();
350 void updateDomeStatus(AlapacaDomeState &state);
351 void updateShutterStatus(AlapacaDomeState &state);
352
356 bool sendAlpacaGET(const std::string &endpoint, nlohmann::json &response);
357 bool sendAlpacaPUT(const std::string &endpoint, const nlohmann::json &request, nlohmann::json &response);
358
362 bool alpacaConnect();
363 bool alpacaDisconnect();
364
368 bool alpacaGetBool(const std::string &endpoint, bool& value, bool defaultValue = false);
369 bool alpacaGetInt(const std::string &endpoint, int& value, int defaultValue = 0);
370 bool alpacaGetDouble(const std::string &endpoint, double& value, double defaultValue = 0.0);
371 bool alpacaGetString(const std::string &endpoint, std::string& value, const std::string& defaultValue = "");
372 bool alpacaGetDeviceState(AlapacaDomeState &value, double defaultAz = 0.0, double defaultAlt = 0.0);
373
377 // bool alpacaDomeSetSlaved(bool slaved);
378 bool alpacaDomeAbortSlew();
379 bool alpacaDomeCloseShutter();
380 bool alpacaDomeFindHome();
381 bool alpacaDomeOpenShutter();
382 bool alpacaDomePark();
383 bool alpacaDomeSetPark();
384 bool alpacaDomeSlewToAltitude(double alt);
385 bool alpacaDomeSlewToAzimuth(double az);
386 bool alpacaDomeSyncToAzimuth(double az);
387
391 bool m_CanFindHome {false};
392 bool m_CanCalibrate {false};
393 bool m_CanPark {false};
394 bool m_CanSetAltitude {false};
395 bool m_CanSetAzimuth {false};
396 bool m_CanSetPark {false};
397 bool m_CanSetShutter {true};
398 bool m_CanSlave {false};
399 bool m_CanSyncAzimuth {false};
400
401 // Internal state variables
402 std::string m_DeviceName, m_Description, m_DriverInfo, m_DriverVersion;
403 int m_InterfaceVersion {1};
404
408 std::unique_ptr<httplib::Client> httpClient;
409 uint32_t m_ClientTransactionID {1};
410
411 // Config-loaded values (empty = no saved config, mirrors TCP plugin pattern)
412 std::string m_ConfigHost;
413 std::string m_ConfigPort;
414};
INDI::PropertySwitch OperationSP
bool CanFindHome()
Definition alpaca_dome.h:90
virtual bool saveConfigItems(FILE *fp) override
Save all dome parameters in the configuration file. This overridden method adds the HTTP connection i...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool CanSlave()
virtual bool Abort() override
Abort all dome motion (spinning and shutter).
virtual IPState FindHome()
Request the dome for moving and finding its Home position. The method is asynchronous and the dome sh...
bool CanSetPark()
virtual bool SetCurrentPark() override
Set parking position of the dome with the current position.
bool CanSetShutter()
virtual IPState Park() override
Park the dome.
virtual bool SetSpeed(double rpm) override
Set Dome speed. This does not initiate motion, it sets the speed for the next motion command....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
@ OPERATION_CALIBRATE
@ OPERATION_FIND_HOME
virtual bool Disconnect() override
Disconnect from the remote dome device.
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
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...
virtual uint32_t getTransactionId()
INDI::PropertyText ServerAddressTP
Additional properties.
bool CanCalibrate()
Definition alpaca_dome.h:98
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
INDI::PropertyNumber DeviceNumberNP
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close the shutter.
@ INFO_INTERFACE_VERSION
@ INFO_DRIVER_VERSION
virtual bool updateProperties() override
Called whenever there is a change in the CONNECTION status of the driver. This will enable the driver...
INDI::PropertyText InfoTP
bool CanSetAzimuth()
bool CanSetAltitude()
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual std::string buildAlpacaFormData(const nlohmann::json &request)
INDI::PropertyNumber ConnectionSettingsNP
bool CanSyncAzimuth()
virtual bool initProperties() override
Initialize properties state and value for Alpaca dome device.
bool CanPark()
virtual const char * getDefaultName() override
virtual void setDefaultServerAddress(const char *host, const char *port, bool force=false)
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState Calibrate()
Request the dome for moving in order to calibrate itself. The calibration is an asynchronous process ...
virtual bool Sync(double az) override
Set the dome current azimuth with the supplied azimuth position.
virtual bool Connect() override
Connect to the remote dome device. For Alpaca drivers, this method tries to connect to the device usi...
virtual IPState UnPark() override
UnPark the dome. The action of the Unpark command is dome specific, but it may include opening the sh...
virtual ~AlpacaDome()=default
virtual bool SetDefaultPark() override
Set parking position of the dome with the current position.
virtual std::string getAlpacaURL(const std::string &endpoint)
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
a class to store JSON values
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158