Native test suite (61 tests, 5 suites) with thin mock layer for Arduino/FreeRTOS/esp_timer enabling host-side testing without hardware. ASCOM Alpaca REST API on port 32323 with UDP discovery, implementing Telescope v3 interface for N.I.N.A., PHD2, and compatible software. Follows existing ST4WiFi conditional compilation pattern. README documents wiring, all three protocols (serial, WebSocket, Alpaca), pin/rate configuration, and build instructions.
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
// ST4-ESP32: ASCOM Alpaca REST API (optional)
|
|
// Enable by defining ST4_ALPACA_ENABLED before including ST4.h
|
|
// Implements ASCOM Alpaca Telescope interface v3
|
|
|
|
#pragma once
|
|
|
|
#ifdef ST4_ALPACA_ENABLED
|
|
|
|
#include <WiFi.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <AsyncUDP.h>
|
|
#include <ArduinoJson.h>
|
|
#include "ST4Controller.h"
|
|
|
|
struct ST4AlpacaConfig {
|
|
uint16_t httpPort = 32323;
|
|
uint16_t discoveryPort = 32227;
|
|
};
|
|
|
|
class ST4Alpaca {
|
|
ST4Controller* controller_;
|
|
AsyncWebServer* server_;
|
|
AsyncUDP udp_;
|
|
ST4AlpacaConfig config_;
|
|
uint32_t serverTransactionId_;
|
|
|
|
// Response helpers
|
|
void sendValue(AsyncWebServerRequest* req, JsonDocument& doc);
|
|
void sendBool(AsyncWebServerRequest* req, bool value);
|
|
void sendDouble(AsyncWebServerRequest* req, double value);
|
|
void sendString(AsyncWebServerRequest* req, const char* value);
|
|
void sendInt(AsyncWebServerRequest* req, int value);
|
|
void sendError(AsyncWebServerRequest* req, int errNum, const char* errMsg);
|
|
void addCors(AsyncWebServerResponse* resp);
|
|
|
|
// Parameter parsing (PUT uses form-encoded body)
|
|
int clientTransactionId(AsyncWebServerRequest* req);
|
|
bool paramBool(AsyncWebServerRequest* req, const char* name, bool& out);
|
|
bool paramInt(AsyncWebServerRequest* req, const char* name, int& out);
|
|
bool paramDouble(AsyncWebServerRequest* req, const char* name, double& out);
|
|
String paramString(AsyncWebServerRequest* req, const char* name);
|
|
|
|
// Route registration
|
|
void registerManagement();
|
|
void registerDiscovery();
|
|
void registerCapabilities();
|
|
void registerState();
|
|
void registerActions();
|
|
|
|
public:
|
|
ST4Alpaca();
|
|
~ST4Alpaca();
|
|
|
|
void begin(ST4Controller& controller, const ST4AlpacaConfig& config = {});
|
|
void update();
|
|
};
|
|
|
|
#endif // ST4_ALPACA_ENABLED
|