30#ifdef _USE_SYSTEM_JSONLIB
31#include <nlohmann/json.hpp>
36static std::unique_ptr<DragonLIGHT> dragonlight(
new DragonLIGHT());
47 FirmwareTP[0].
fill(
"Version",
"Version",
nullptr);
48 FirmwareTP[1].
fill(
"Serial",
"Serial",
nullptr);
51 IPAddressTP[0].
fill(
"IP Address",
"IP Address",
nullptr);
54 DiscoverSwitchSP[0].
fill(
"DISCOVER",
"Discover",
ISS_OFF);
102 return "DragonLIGHT";
111 std::string endpoint = enable ?
"/indi/turnon" :
"/indi/turnoff";
113 auto result = cli.
Post(endpoint);
120 return (result.value().status == 200);
127 LOG_ERROR(
"You must set On the Flat Light first.");
136 std::string endpoint =
"/indi/brightness";
139 j[
"brightness"] = value;
141 auto result = cli.
Post(endpoint, j.
dump(),
"application/json");
148 if (result.value().status == 200)
170 IPAddressTP.
update(texts, names, n);
187 DiscoverSwitchSP.
update(states, names, n);
196 DiscoverSwitchSP.
apply();
217 IPAddressTP.
save(fp);
226 if (strlen(IPAddressTP[0].
getText()) == 0)
255void DragonLIGHT::updateStatus()
259 auto result = cli.Get(
"/indi/status");
266 if (result.value().status == 200)
270 std::string version = j[
"version"];
271 std::string serial = j[
"serialNumber"];
273 FirmwareTP[0].setText(version.c_str());
274 FirmwareTP[1].setText(serial.c_str());
278 uint32_t brightness = j[
"brightness"];
284 bool isOn = j[
"isOn"];
297#define DDA_DISCOVERY_PORT 0xdda
298#define DDA_DISCOVERY_TIMEOUT 2
299#define DDA_DISCOVERY_RECEIVE_BUFFER_SIZE 256
301void DragonLIGHT::discoverDevices()
305 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
308 LOG_ERROR(
"Error creating socket for discovery.");
313 setsockopt(s, SOL_SOCKET, SO_BROADCAST, &broadcast,
sizeof(broadcast));
318 setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv));
320 struct sockaddr_in Recv_addr;
322 socklen_t len =
sizeof(
struct sockaddr_in);
324 Recv_addr.sin_family = AF_INET;
326 Recv_addr.sin_addr.s_addr = INADDR_BROADCAST;
328 const char* sendMSG =
"darkdragons";
330 sendto(s, sendMSG, strlen(sendMSG), 0, (sockaddr *)&Recv_addr,
sizeof(Recv_addr));
341 nlohmann::json doc = nlohmann::json::parse(recvbuff,
nullptr,
false,
true);
345 char deviceIP[INET_ADDRSTRLEN];
346 inet_ntop(AF_INET, &(Recv_addr.sin_addr), deviceIP, INET_ADDRSTRLEN);
348 std::string deviceType = doc[
"deviceType"];
349 std::string serialNumber = doc[
"SerialNumber"].
is_string() ? doc[
"SerialNumber"].
get<std::string>() :
"";
351 LOGF_INFO(
"Found %s %s at %s", deviceType.c_str(), serialNumber.c_str(), deviceIP);
357 DiscoverSwitchSP.
reset();
360 DiscoverSwitchSP.
apply();
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
virtual 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 void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
const char * getDefaultName() override
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool Disconnect() override
Disconnect from device.
const char * getDeviceName() const
INDI::PropertyText getText(const char *name) const
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
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 loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
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...
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
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.
void initProperties(const char *group, uint32_t capabilities)
Initialize light box properties. It is recommended to call this function within initProperties() of y...
void ISGetProperties(const char *deviceName)
isGetLightBoxProperties Get light box properties
INDI::PropertyNumber LightIntensityNP
bool saveConfigItems(FILE *fp)
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process light box switch properties.
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process light box text properties.
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process light box number properties.
INDI::PropertySwitch LightSP
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const ISState states[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
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)
INDI::PropertyViewText * getText() const
Provides interface to implement controllable light box/switch device.
Result Post(const std::string &path)
a class to store JSON values
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
constexpr bool is_string() const noexcept
return whether value is a string
constexpr bool is_discarded() const noexcept
return whether value is discarded
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * INFO_TAB
INFO_TAB Where all the properties for general information are located.
#define DDA_DISCOVERY_TIMEOUT
#define DDA_DISCOVERY_RECEIVE_BUFFER_SIZE
#define DDA_DISCOVERY_PORT
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...