27#ifdef _USE_SYSTEM_JSONLIB
28#include <nlohmann/json.hpp>
53 InputInterface::initProperties(
"Main Control", DIGITAL_INPUTS, ANALOG_INPUTS,
"Input",
"Analog");
56 OutputInterface::initProperties(
"Main Control", DIGITAL_OUTPUTS,
"Output");
74 APIKeyTP[0].fill(
"API_KEY",
"API Key",
"");
80 ModelVersionTP[0].fill(
"VERSION",
"Version",
"");
91 InputInterface::updateProperties();
92 OutputInterface::updateProperties();
115 httplib::Client cli(tcpConnection->host(), tcpConnection->port());
118 std::string endpoint =
"/api/xdevices.json?";
119 std::string apiKey = std::string(APIKeyTP[0].
getText());
120 if (!apiKey.empty()) {
121 endpoint +=
"key=" + apiKey +
"&" ;
124 auto result = cli.Get(endpoint);
128 LOG_ERROR(
"Failed to connect to device");
134 auto j = json::parse(result->body);
136 if (j.contains(
"product") && j.contains(
"status") && j[
"status"] ==
"Success")
138 std::string product = j[
"product"].get<std::string>();
140 size_t pos = product.find(
"_");
141 if (pos != std::string::npos)
143 ModelVersionTP[0].setText(product.substr(pos + 1).c_str());
144 ModelVersionTP.setState(
IPS_OK);
149 LOG_ERROR(
"Failed to connect to device");
176 httplib::Client cli(tcpConnection->host(), tcpConnection->port());
178 std::string endpoint =
"/api/xdevices.json?";
179 std::string apiKey = std::string(APIKeyTP[0].
getText());
180 if (!apiKey.empty()) {
181 endpoint +=
"key=" + apiKey +
"&" ;
184 auto result = cli.Get(endpoint);
187 LOG_ERROR(
"Failed to get digital inputs");
192 auto j = json::parse(result->body);
194 for (
size_t i = 0; i < DIGITAL_INPUTS ; i++)
197 std::string
key =
"D" + std::to_string(i + 1);
219 httplib::Client cli(tcpConnection->host(), tcpConnection->port());
220 std::string endpoint =
"/api/xdevices.json?";
221 std::string apiKey = std::string(APIKeyTP[0].
getText());
222 if (!apiKey.empty()) {
223 endpoint +=
"key=" + apiKey +
"&" ;
226 auto result = cli.Get(endpoint);
229 LOG_ERROR(
"Failed to get analog inputs");
235 auto j = json::parse(result->body);
237 for (
size_t i = 0; i < ANALOG_INPUTS; i++)
239 std::string
key =
"A" + std::to_string(i + 1);
242 double value = j[
key].get<
double>();
263 httplib::Client cli(tcpConnection->host(), tcpConnection->port());
265 std::string endpoint =
"/api/xdevices.json?";
266 std::string apiKey = std::string(APIKeyTP[0].
getText());
267 if (!apiKey.empty()) {
268 endpoint +=
"key=" + apiKey +
"&" ;
271 auto result = cli.Get(endpoint);
274 LOG_ERROR(
"Failed to get digital outputs");
280 auto j = json::parse(result->body);
283 for (
size_t i = 0; i < DIGITAL_OUTPUTS; i++)
285 std::string
key =
"R" + std::to_string(i + 1);
307 httplib::Client cli(tcpConnection->host(), tcpConnection->port());
310 std::string endpoint =
"/api/xdevices.json?";
311 std::string apiKey = std::string(APIKeyTP[0].
getText());
313 endpoint +=
"key=" + apiKey +
"&" ;
315 endpoint += std::string(command ==
OutputState::On ?
"SetR=" :
"ClearR=") + std::to_string(index + 1);
317 auto result = cli.Get(endpoint);
320 LOGF_ERROR(
"Failed to set output %d", index + 1);
324 return result->status == 200;
327bool IPX800::ISNewText(
const char *dev,
const char *name,
char *texts[],
char *names[],
int n)
331 if (APIKeyTP.isNameMatch(name))
333 APIKeyTP.update(texts, names,
n);
334 APIKeyTP.setState(
IPS_OK);
341 if (InputInterface::processText(dev, name, texts, names,
n))
343 if (OutputInterface::processText(dev, name, texts, names,
n))
351 if (OutputInterface::processSwitch(dev, name, states, names,
n))
357bool IPX800::ISNewNumber(
const char *dev,
const char *name,
double values[],
char *names[],
int n)
359 if (OutputInterface::processNumber(dev, name, values, names,
n))
368 InputInterface::saveConfigItems(fp);
369 OutputInterface::saveConfigItems(fp);
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
void setDefaultHost(const char *addressHost)
void setDefaultPort(uint32_t addressPort)
const char * getDeviceName() const
INDI::PropertyText getText(const char *name) const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
std::vector< INDI::PropertySwitch > DigitalOutputsSP
virtual bool CommandOutput(uint32_t index, OutputState command) override
Send command to output.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool UpdateDigitalOutputs() override
Update all digital outputs.
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 ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Provides interface to implement Digital Boolean Output (On/Off) functionality.
{ using exception=detail::exception detail::parse_error parse_error
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
*brief user defined string literal for JSON values *sa std::size_t n
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
basic_json<> json
default specialization