Instrument Neutral Distributed Interface INDI 2.2.5
indi_alpaca_focuser.h
Go to the documentation of this file.
1/*
2 INDI alpaca Focuser Driver
3
4 Copyright (C) 2024 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 <indifocuser.h>
25#include <memory>
26#include <string>
27
28#define HTTPLIB_NO_EXCEPTIONS
29#include "httplib.h"
30
31#ifdef _USE_SYSTEM_JSONLIB
32#include <nlohmann/json.hpp>
33#else
34#include <indijson.hpp>
35#endif
36
38{
39 public:
41 virtual ~AlpacaFocuser();
42
43 virtual const char *getDefaultName() override;
44 virtual bool initProperties() override;
45 virtual bool updateProperties() override;
46
47 virtual bool Connect() override;
48 virtual bool Disconnect() override;
49 virtual bool Handshake() override;
50
51 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
52 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
53
54 protected:
55 // Focuser interface
56 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
57 virtual bool AbortFocuser() override;
58 virtual void TimerHit() override;
59
60 private:
61 // Device info properties
62 INDI::PropertyText DeviceInfoTP {4};
63 enum { DESCRIPTION, DRIVER_INFO, DRIVER_VERSION, INTERFACE_VERSION };
64
65 // Temperature property
66 INDI::PropertyNumber TemperatureNP {1};
67
68 // Temperature compensation switch (only defined if the device reports tempcompavailable=true)
69 INDI::PropertySwitch TempCompSP {2};
70 enum { TEMP_COMP_ENABLE, TEMP_COMP_DISABLE };
71 bool m_TempCompAvailable = false;
72
73 // Alpaca communication
74 std::unique_ptr<httplib::Client> m_AlpacaClient;
75 std::string m_Host = "alpaca.local";
76 int m_Port = 32323;
77 int m_DeviceNumber = 0;
78 uint32_t m_ClientID = 1;
79 uint32_t m_TransactionID = 0;
80
81 // Movement state
82 uint32_t m_TargetPosition = 0;
83 bool m_Moving = false;
84
85 // Helper methods
86 bool setupFocuser();
87 bool isMoving();
88 int getPosition();
89 bool sendAlpacaGET(const std::string &endpoint, nlohmann::json &response);
90 bool sendAlpacaPUT(const std::string &endpoint, const std::string &data, nlohmann::json &response);
91};
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual const char * getDefaultName() override
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Processes incoming new text values from the client for this device. Delegates processing to the contr...
virtual bool Disconnect() override
Disconnect from device.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
a class to store JSON values
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158