30#ifdef _USE_SYSTEM_JSONLIB
31#include <nlohmann/json.hpp>
53 MotorStatsNP[0].fill(
"Voltage",
"Voltage",
"%0.2f V", 0.0, 24.0, 0.01, 0.00);
54 MotorStatsNP[1].fill(
"Current",
"Current",
"%0.2f A", 0.0, 24.0, 0.01, 0.00);
57 FirmwareTP[0].fill(
"Version",
"Version",
nullptr);
58 FirmwareTP[1].fill(
"Serial",
"Serial",
nullptr);
61 IPAddressTP[0].fill(
"IP Address",
"IP Address",
nullptr);
64 DiscoverSwitchSP[0].fill(
"DISCOVER",
"Discover",
ISS_OFF);
67 SafetySensorLP[0].fill(
"SAFETY_SENSOR_1",
"Safety Sensor 1",
IPS_IDLE);
68 SafetySensorLP[1].fill(
"SAFETY_SENSOR_2",
"Safety Sensor 2",
IPS_IDLE);
69 SafetySensorLP[2].fill(
"SAFETY_SENSOR_3",
"Safety Sensor 3",
IPS_IDLE);
70 SafetySensorLP[3].fill(
"SAFETY_SENSOR_4",
"Safety Sensor 4",
IPS_IDLE);
73 LimitSwitchLP[0].fill(
"LIMIT_SWITCH_1",
"Fully Open Switch",
IPS_IDLE);
74 LimitSwitchLP[1].fill(
"LIMIT_SWITCH_2",
"Fully Closed Switch",
IPS_IDLE);
101 if (strlen(IPAddressTP[0].
getText()) == 0)
120 return (
const char *)
"DragonLAIR";
127 DiscoverSwitchSP.update(states, names,
n);
128 auto isToggled = DiscoverSwitchSP[0].getState() ==
ISS_ON;
136 DiscoverSwitchSP.apply();
147 IPAddressTP.update(texts, names,
n);
148 IPAddressTP.setState(
IPS_OK);
191 IPAddressTP.save(fp);
202 auto state = Dome::getDomeState();
208 LOG_WARN(
"Roof is already fully opened.");
213 LOG_WARN(
"Roof is already fully closed.");
218 LOG_INFO(
"Cannot close dome when mount is locking. See: Telescope parking policy, in options tab");
258 LOG_INFO(
"Roll off is unparking...");
275void DragonLAIR::updateStatus()
277 if (strlen(IPAddressTP[0].
getText()) == 0)
283 httplib::Client cli(IPAddressTP[0].
getText(), 80);
287 httplib::Result result = cli.Get(
"/indi/status");
294 if (result.value().status == 200)
296 nlohmann::json j = nlohmann::json::parse(result.value().body,
nullptr,
false,
true);
298 if (j.is_discarded())
304 std::string version = j[
"version"];
305 std::string serial = j[
"serialNumber"];
306 uint32_t voltageMV = j[
"voltage"];
307 uint32_t currentMA = j[
"current"];
309 MotorStatsNP[0].setValue(voltageMV / 1000.0);
310 MotorStatsNP[1].setValue(currentMA / 1000.0);
311 MotorStatsNP.setState(
IPS_OK);
312 MotorStatsNP.apply();
314 FirmwareTP[0].setText(version.c_str());
315 FirmwareTP[1].setText(serial.c_str());
316 FirmwareTP.setState(
IPS_OK);
319 std::string safetySensor1 = j[
"roof"][
"safetySensor1"];
320 std::string safetySensor2 = j[
"roof"][
"safetySensor2"];
321 std::string safetySensor3 = j[
"roof"][
"safetySensor3"];
322 std::string safetySensor4 = j[
"roof"][
"safetySensor4"];
324 SafetySensorLP[0].setState(safetySensor1 ==
"disabled" ?
IPS_IDLE : safetySensor1 ==
"unsafe" ?
IPS_ALERT :
IPS_OK);
325 SafetySensorLP[1].setState(safetySensor2 ==
"disabled" ?
IPS_IDLE : safetySensor2 ==
"unsafe" ?
IPS_ALERT :
IPS_OK);
326 SafetySensorLP[2].setState(safetySensor3 ==
"disabled" ?
IPS_IDLE : safetySensor3 ==
"unsafe" ?
IPS_ALERT :
IPS_OK);
327 SafetySensorLP[3].setState(safetySensor4 ==
"disabled" ?
IPS_IDLE : safetySensor4 ==
"unsafe" ?
IPS_ALERT :
IPS_OK);
328 SafetySensorLP.apply();
330 bool isRoofFullyClosed = j[
"roof"][
"isRoofFullyClosed"];
332 bool isRoofFullyOpen = j[
"roof"].value(
"isRoofFullyOpened", j[
"roof"].
value(
"isRoofFullyOpen",
false));
336 LimitSwitchLP.apply();
338 bool isRoofClosing = j[
"roof"][
"isRoofClosing"];
339 bool isRoofOpening = j[
"roof"][
"isRoofOpening"];
341 if (isRoofFullyClosed)
348 else if (isRoofFullyOpen)
355 else if (isRoofClosing)
362 else if (isRoofOpening)
369 else if (Dome::getDomeState() !=
DOME_IDLE)
379 catch(
const std::exception &e)
381 LOGF_ERROR(
"Error on updateStatus: %s", e.what());
385void DragonLAIR::openRoof()
387 if (strlen(IPAddressTP[0].
getText()) == 0)
395 httplib::Client cli(IPAddressTP[0].
getText(), 80);
397 auto result = cli.Post(
"/indi/roof/open");
404 if (result.value().status == 200)
413 catch(
const std::exception &e)
415 LOGF_ERROR(
"Error on openRoof: %s", e.what());
419void DragonLAIR::closeRoof()
421 if (strlen(IPAddressTP[0].
getText()) == 0)
429 httplib::Client cli(IPAddressTP[0].
getText(), 80);
431 auto result = cli.Post(
"/indi/roof/close");
438 if (result.value().status == 200)
447 catch(
const std::exception &e)
449 LOGF_ERROR(
"Error on closeRoof: %s", e.what());
453void DragonLAIR::stopRoof()
455 if (strlen(IPAddressTP[0].
getText()) == 0)
463 httplib::Client cli(IPAddressTP[0].
getText(), 80);
465 auto result = cli.Post(
"/indi/roof/abort");
472 if (result.value().status == 200)
481 catch(
const std::exception &e)
483 LOGF_ERROR(
"Error on stopRoof: %s", e.what());
487#define DDA_DISCOVERY_PORT 0xdda
488#define DDA_DISCOVERY_TIMEOUT 2
489#define DDA_DISCOVERY_RECEIVE_BUFFER_SIZE 256
491void DragonLAIR::discoverDevices()
495 s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
498 LOG_ERROR(
"Error creating socket for discovery.");
503 setsockopt(s, SOL_SOCKET, SO_BROADCAST, &broadcast,
sizeof(broadcast));
508 setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv));
510 struct sockaddr_in Recv_addr;
512 socklen_t len =
sizeof(
struct sockaddr_in);
514 Recv_addr.sin_family = AF_INET;
516 Recv_addr.sin_addr.s_addr = INADDR_BROADCAST;
518 const char* sendMSG =
"darkdragons";
520 sendto(s, sendMSG, strlen(sendMSG), 0, (sockaddr *)&Recv_addr,
sizeof(Recv_addr));
531 nlohmann::json doc = nlohmann::json::parse(recvbuff,
nullptr,
false,
true);
533 if (!doc.is_discarded() && doc.contains(
"deviceType"))
535 char deviceIP[INET_ADDRSTRLEN];
536 inet_ntop(AF_INET, &(Recv_addr.sin_addr), deviceIP, INET_ADDRSTRLEN);
538 std::string deviceType = doc[
"deviceType"];
539 std::string serialNumber = doc[
"serialNumber"];
541 LOGF_INFO(
"Found %s %s at %s", deviceType.c_str(), serialNumber.c_str(), deviceIP);
547 DiscoverSwitchSP.
reset();
550 DiscoverSwitchSP.
apply();
virtual bool Abort() override
Abort all dome motion.
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool Disconnect() override
Disconnect from device.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
const char * getDefaultName() override
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
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 ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
INDI::PropertyText getText(const char *name) const
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
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)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
void SetDomeCapability(uint32_t cap)
SetDomeCapability set the dome capabilities. All capabilities must be initialized.
void setDomeConnection(const uint8_t &value)
setDomeConnection Set Dome connection mode. Child class should call this in the constructor before Do...
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 initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool isLocked()
isLocked, is the dome currently locked?
virtual bool updateProperties() override
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) 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 saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void setDomeState(const DomeState &value)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetParkDataType(DomeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation)
Move the Dome in a particular direction.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
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.
std::unique_ptr< DragonLAIR > dragonlair(new DragonLAIR())
#define DDA_DISCOVERY_TIMEOUT
#define DDA_DISCOVERY_RECEIVE_BUFFER_SIZE
#define DDA_DISCOVERY_PORT
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#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