Instrument Neutral Distributed Interface INDI 2.2.5
indi_alpaca_filterwheel.h
Go to the documentation of this file.
1/*
2 INDI alpaca FilterWheel 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 <indifilterwheel.h>
24#include <memory>
25#include <string>
26
27#define HTTPLIB_NO_EXCEPTIONS
28#include "httplib.h"
29
30#ifdef _USE_SYSTEM_JSONLIB
31#include <nlohmann/json.hpp>
32#else
33#include <indijson.hpp>
34#endif
35
37{
38public:
40 virtual ~AlpacaFilterWheel() = default;
41
42 virtual const char *getDefaultName() override;
43 virtual bool initProperties() override;
44 virtual void ISGetProperties(const char *dev) override;
45 virtual bool updateProperties() override;
46
47 virtual bool Connect() override;
48 virtual bool Disconnect() override;
49
50 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
51
52 virtual bool saveConfigItems(FILE *fp) override;
53
54protected:
55 // FilterWheel interface
56 virtual bool SelectFilter(int position) override;
57 virtual int QueryFilter() override;
58
59private:
60 // Connection properties
61 INDI::PropertyText ServerAddressTP {2};
62 enum { HOST_INDEX, PORT_INDEX };
63
64 // Device info properties
65 INDI::PropertyText DeviceInfoTP {4};
66 enum { DESCRIPTION, DRIVER_INFO, DRIVER_VERSION, INTERFACE_VERSION };
67
68 // Filter properties
69 INDI::PropertyNumber FocusOffsetsNP {3};
70
71 // Alpaca communication
72 std::unique_ptr<httplib::Client> m_AlpacaClient;
73 std::string m_Host = "alpaca.local";
74 int m_Port = 32323;
75 int m_DeviceNumber = 0;
76 uint32_t m_ClientID = 1;
77 uint32_t m_TransactionID = 0;
78
79 // Helper methods
80 bool setupFilterWheel();
81 bool sendAlpacaGET(const std::string &endpoint, nlohmann::json &response);
82 bool sendAlpacaPUT(const std::string &endpoint, const std::string &data, nlohmann::json &response);
83};
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool Disconnect() override
Disconnect from device.
virtual ~AlpacaFilterWheel()=default
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual const char * getDefaultName() override
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 bool SelectFilter(int position) override
Select a new filter position.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual int QueryFilter() override
Return current filter position.
a class to store JSON values