Instrument Neutral Distributed Interface INDI 2.2.5
weather_safety_alpaca.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 Jérémie Klein. All rights reserved.
3
4 ASCOM Alpaca Weather Safety INDI Driver
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 "indiweather.h"
28#include <string>
29#include <functional>
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 ~WeatherSafetyAlpaca() = default;
42
43 virtual bool initProperties() override;
44 const char *getDefaultName() override;
45 void ISGetProperties(const char *dev) override;
46 virtual bool updateProperties() override;
47 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
48 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
49 virtual bool saveConfigItems(FILE *fp) override;
50 virtual bool loadConfig(bool silent = false, const char *property = nullptr) override;
51
52 protected:
53 bool Connect() override;
54 bool Disconnect() override;
55 virtual IPState updateWeather() override;
56
57 private:
58 // HTTP helper methods
59 bool makeAlpacaRequest(const std::string& path, nlohmann::json& response, bool isPut = false);
60 bool retryRequest(const std::function<bool()>& request);
61
62 // Properties
63 INDI::PropertyText ServerAddressTP {2}; // Host and port
64 INDI::PropertyNumber DeviceNumberNP {1}; // Alpaca device number
65 INDI::PropertyNumber ConnectionSettingsNP {3}; // Timeout, retries, retry delay
66
67 // State variables
68 bool LastParseSuccess {false};
69};
bool Disconnect() override
Disconnect from device.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
const char * getDefaultName() override
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
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 ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual ~WeatherSafetyAlpaca()=default
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool loadConfig(bool silent=false, const char *property=nullptr) override
Load the last saved configuration file.
a class to store JSON values
IPState
Property state.
Definition indiapi.h:158