Instrument Neutral Distributed Interface INDI 2.2.5
indi_alpaca_server.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 Jasem Mutlaq. All rights reserved.
3
4 INDI Alpaca Server
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24
25#pragma once
26
27#include "defaultdevice.h"
28#include "indiproperty.h"
29#include <memory>
30#include <thread>
31#include <atomic>
32#include <httplib.h>
33
34class AlpacaClient;
35class DeviceManager;
36class AlpacaDiscovery;
37
39{
40 public:
42 virtual ~INDIAlpacaServer();
43
44 virtual bool initProperties() override;
45 const char *getDefaultName() override;
46 void ISGetProperties(const char *dev) override;
47 bool updateProperties() override;
48 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
49 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
50 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
51 virtual bool saveConfigItems(FILE *fp) override;
52
53 protected:
54 bool Connect() override;
55 bool Disconnect() override;
56
57 void TimerHit() override;
58
59 private:
60 // Start/stop the Alpaca server
61 bool startAlpacaServer();
62 bool stopAlpacaServer();
63
64 // HTTP server thread
65 void serverThreadFunc();
66
67 // Properties
68 INDI::PropertyText ServerSettingsTP {2}; // Host and port for Alpaca server
69 INDI::PropertyText INDIServerSettingsTP {2}; // Host and port for INDI server
70 INDI::PropertySwitch ServerControlSP {2}; // Start/stop server
71 INDI::PropertyNumber ConnectionSettingsNP {3}; // Timeout, retries, retry delay
72 INDI::PropertyNumber DiscoverySettingsNP {1}; // Discovery port
73 INDI::PropertyNumber StartupDelayNP {1}; // Delay before connecting to INDI server
74
75 // Components
76 std::shared_ptr<AlpacaClient> m_Client;
77 std::unique_ptr<httplib::Server> m_Server;
78 std::unique_ptr<AlpacaDiscovery> m_Discovery;
79 DeviceManager* m_DeviceManager;
80 std::thread m_ServerThread;
81 std::atomic<bool> m_ServerRunning {false};
82};
Implementation of the ASCOM Alpaca Discovery Protocol.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool Disconnect() override
Disconnect from device.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
const char * getDefaultName() override
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
ISState
Switch state.
Definition indiapi.h:148