27#ifdef _USE_SYSTEM_JSONLIB
28#include <nlohmann/json.hpp>
47 InputInterface::initProperties(
"Main Control", DIGITAL_INPUTS, ANALOG_INPUTS,
"Input",
"Analog");
50 OutputInterface::initProperties(
"Main Control", DIGITAL_OUTPUTS,
"Output");
68 APIKeyTP[0].
fill(
"API_KEY",
"API Key",
"");
73 ModelVersionTP[0].
fill(
"VERSION",
"Version",
"");
84 InputInterface::updateProperties();
85 OutputInterface::updateProperties();
109 if (strlen(APIKeyTP[0].
getText()) == 0)
118 std::string endpoint =
"/api/xdevices.json";
119 endpoint +=
"?key=" + std::string(APIKeyTP[0].
getText());
120 endpoint +=
"&Get=D";
121 auto result = cli.
Get(endpoint);
124 LOG_ERROR(
"Failed to connect to device");
130 auto j = json::parse(result->body);
131 if (j.contains(
"product"))
133 std::string product = j[
"product"].get<std::string>();
135 size_t pos = product.find(
"_");
136 if (pos != std::string::npos)
138 ModelVersionTP[0].setText(product.substr(pos + 1).c_str());
157 UpdateDigitalInputs();
158 UpdateAnalogInputs();
164bool IPX800::UpdateDigitalInputs()
168 std::string endpoint =
"/api/xdevices.json";
169 endpoint +=
"?key=" + std::string(APIKeyTP[0].
getText());
170 endpoint +=
"&Get=D";
171 auto result = cli.Get(endpoint);
174 LOG_ERROR(
"Failed to get digital inputs");
180 auto j = json::parse(result->body);
183 auto inputs = j.get<std::vector<int>>();
184 for (
size_t i = 0; i < DIGITAL_INPUTS && i < inputs.size(); i++)
205bool IPX800::UpdateAnalogInputs()
209 std::string endpoint =
"/api/xdevices.json";
210 endpoint +=
"?key=" + std::string(APIKeyTP[0].
getText());
211 endpoint +=
"&Get=A";
212 auto result = cli.Get(endpoint);
215 LOG_ERROR(
"Failed to get analog inputs");
221 auto j = json::parse(result->body);
224 for (
int i = 0; i < ANALOG_INPUTS; i++)
226 std::string key =
"AN" + std::to_string(i + 1);
229 double value = j[key].get<
double>();
252 std::string endpoint =
"/api/xdevices.json";
253 endpoint +=
"?key=" + std::string(APIKeyTP[0].
getText());
254 endpoint +=
"&Get=R";
255 auto result = cli.
Get(endpoint);
258 LOG_ERROR(
"Failed to get digital outputs");
264 auto j = json::parse(result->body);
267 auto outputs = j.get<std::vector<int>>();
268 for (
size_t i = 0; i < DIGITAL_OUTPUTS && i < outputs.size(); i++)
294 std::string endpoint =
"/api/xdevices.json";
295 endpoint +=
"?key=" + std::string(APIKeyTP[0].
getText());
296 endpoint +=
"&" + std::string(command ==
OutputState::On ?
"SetR=" :
"ClearR=") + std::to_string(index + 1);
298 auto result = cli.
Get(endpoint);
301 LOGF_ERROR(
"Failed to set output %d", index + 1);
305 return result->status == 200;
314 APIKeyTP.
update(texts, names, n);
322 if (InputInterface::processText(dev, name, texts, names, n))
324 if (OutputInterface::processText(dev, name, texts, names, n))
332 if (OutputInterface::processSwitch(dev, name, states, names, n))
340 if (OutputInterface::processNumber(dev, name, values, names, n))
349 InputInterface::saveConfigItems(fp);
350 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)
virtual const char * host() const
virtual uint32_t port() const
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.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
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
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool load()
load Attempt to load property values from configuration file.
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const char *const texts[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
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 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.
Result Get(const std::string &path, DownloadProgress progress=nullptr)
a class to store JSON values
const char * what() const noexcept override
returns the explanatory string
exception indicating a parse error
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
#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