Instrument Neutral Distributed Interface INDI 2.2.5
alpaca_discovery.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 Jasem Mutlaq. All rights reserved.
3
4 INDI Alpaca Discovery Protocol
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 <string>
28#include <thread>
29#include <atomic>
30#include <memory>
31#include <vector>
32#include <sys/socket.h>
33#include <netinet/in.h>
34
45{
46 public:
53 AlpacaDiscovery(int discoveryPort = 32227, int alpacaPort = 11111);
54
61
67 bool start();
68
74 bool stop();
75
81 bool isRunning() const;
82
89 void setDiscoveryPort(int port);
90
96 int getDiscoveryPort() const;
97
103 void setAlpacaPort(int port);
104
110 int getAlpacaPort() const;
111
112 private:
116 void discoveryThreadFunc();
117
123 int createIPv4Socket();
124
130 int createIPv6Socket();
131
141 void processDiscoveryRequest(int socket, const char* buffer, size_t length,
142 const struct sockaddr* senderAddr, socklen_t senderAddrLen);
143
151 void sendDiscoveryResponse(int socket, const struct sockaddr* senderAddr, socklen_t senderAddrLen);
152
158 std::string generateResponseMessage() const;
159
160 // Configuration
161 int m_DiscoveryPort;
162 int m_AlpacaPort;
163
164 // Thread management
165 std::thread m_DiscoveryThread;
166 std::atomic<bool> m_Running;
167 std::atomic<bool> m_StopRequested;
168
169 // Socket file descriptors
170 std::vector<int> m_Sockets;
171};
Implementation of the ASCOM Alpaca Discovery Protocol.
void setDiscoveryPort(int port)
Set the discovery port.
bool start()
Start the discovery server.
~AlpacaDiscovery()
Destructor.
bool stop()
Stop the discovery server.
bool isRunning() const
Check if the discovery server is running.
void setAlpacaPort(int port)
Set the Alpaca API port.
int getDiscoveryPort() const
Get the discovery port.
int getAlpacaPort() const
Get the Alpaca API port.