From d494b3e160812d2c831cafc6fb5075d74bcf8f0d Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Wed, 27 Mar 2024 13:12:36 +0300 Subject: [PATCH] Fix active device issue with config update --- drivers/auxiliary/astrometrydriver.cpp | 1 - libs/indibase/indidome.cpp | 1 - libs/indibase/inditelescope.cpp | 40 ++++++++++++-------------- libs/indibase/inditelescope.h | 8 ++++-- libs/indibase/indiweather.cpp | 29 ++++++++++--------- libs/indibase/indiweather.h | 8 +++--- 6 files changed, 45 insertions(+), 42 deletions(-) diff --git a/drivers/auxiliary/astrometrydriver.cpp b/drivers/auxiliary/astrometrydriver.cpp index 00f8045d52..2724600089 100644 --- a/drivers/auxiliary/astrometrydriver.cpp +++ b/drivers/auxiliary/astrometrydriver.cpp @@ -106,7 +106,6 @@ void AstrometryDriver::ISGetProperties(const char *dev) DefaultDevice::ISGetProperties(dev); defineProperty(&ActiveDeviceTP); - loadConfig(true, "ACTIVE_DEVICES"); } bool AstrometryDriver::updateProperties() diff --git a/libs/indibase/indidome.cpp b/libs/indibase/indidome.cpp index 0915466dfd..eec9d3a865 100644 --- a/libs/indibase/indidome.cpp +++ b/libs/indibase/indidome.cpp @@ -262,7 +262,6 @@ void Dome::ISGetProperties(const char * dev) DefaultDevice::ISGetProperties(dev); defineProperty(&ActiveDeviceTP); - loadConfig(true, "ACTIVE_DEVICES"); ISState isMountIgnored = ISS_OFF; if (IUGetConfigSwitch(getDeviceName(), MountPolicySP.name, MountPolicyS[MOUNT_IGNORED].name, &isMountIgnored) == 0) diff --git a/libs/indibase/inditelescope.cpp b/libs/indibase/inditelescope.cpp index 0d68c0ad2b..8fa96145f4 100644 --- a/libs/indibase/inditelescope.cpp +++ b/libs/indibase/inditelescope.cpp @@ -67,10 +67,10 @@ bool Telescope::initProperties() DefaultDevice::initProperties(); // Active Devices - IUFillText(&ActiveDeviceT[0], "ACTIVE_GPS", "GPS", "GPS Simulator"); - IUFillText(&ActiveDeviceT[1], "ACTIVE_DOME", "DOME", "Dome Simulator"); - IUFillTextVector(&ActiveDeviceTP, ActiveDeviceT, 2, getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, - IP_RW, 60, IPS_IDLE); + ActiveDeviceTP[GPS].fill("ACTIVE_GPS", "GPS", "GPS Simulator"); + ActiveDeviceTP[DOME].fill("ACTIVE_DOME", "DOME", "Dome Simulator"); + ActiveDeviceTP.fill(getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE); + ActiveDeviceTP.load(); // Use locking if dome is closed (and or) park scope if dome is closing IUFillSwitch(&DomePolicyS[DOME_IGNORED], "DOME_IGNORED", "Dome ignored", ISS_ON); @@ -235,11 +235,11 @@ bool Telescope::initProperties() registerConnection(tcpConnection); } - IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD"); - IDSnoopDevice(ActiveDeviceT[0].text, "TIME_UTC"); + IDSnoopDevice(ActiveDeviceTP[GPS].getText(), "GEOGRAPHIC_COORD"); + IDSnoopDevice(ActiveDeviceTP[GPS].getText(), "TIME_UTC"); - IDSnoopDevice(ActiveDeviceT[1].text, "DOME_PARK"); - IDSnoopDevice(ActiveDeviceT[1].text, "DOME_SHUTTER"); + IDSnoopDevice(ActiveDeviceTP[DOME].getText(), "DOME_PARK"); + IDSnoopDevice(ActiveDeviceTP[DOME].getText(), "DOME_SHUTTER"); addPollPeriodControl(); @@ -266,13 +266,11 @@ bool Telescope::initProperties() void Telescope::ISGetProperties(const char *dev) { - // First we let our parent populate DefaultDevice::ISGetProperties(dev); if (CanGOTO()) { - defineProperty(&ActiveDeviceTP); - loadConfig(true, "ACTIVE_DEVICES"); + defineProperty(ActiveDeviceTP); ISState isDomeIgnored = ISS_OFF; if (IUGetConfigSwitch(getDeviceName(), DomePolicySP.name, DomePolicyS[DOME_IGNORED].name, &isDomeIgnored) == 0) @@ -589,7 +587,7 @@ bool Telescope::saveConfigItems(FILE *fp) { DefaultDevice::saveConfigItems(fp); - IUSaveConfigText(fp, &ActiveDeviceTP); + ActiveDeviceTP.save(fp); IUSaveConfigSwitch(fp, &DomePolicySP); // Ensure that we only save valid locations @@ -708,18 +706,18 @@ bool Telescope::ISNewText(const char *dev, const char *name, char *texts[], char return processTimeInfo(texts[utcindex], texts[offsetindex]); } - if (!strcmp(name, ActiveDeviceTP.name)) + if (ActiveDeviceTP.isNameMatch(name)) { - ActiveDeviceTP.s = IPS_OK; - IUUpdateText(&ActiveDeviceTP, texts, names, n); + ActiveDeviceTP.setState(IPS_OK); + ActiveDeviceTP.update(texts, names, n); // Update client display - IDSetText(&ActiveDeviceTP, nullptr); + ActiveDeviceTP.apply(); - IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD"); - IDSnoopDevice(ActiveDeviceT[0].text, "TIME_UTC"); + IDSnoopDevice(ActiveDeviceTP[GPS].getText(), "GEOGRAPHIC_COORD"); + IDSnoopDevice(ActiveDeviceTP[GPS].getText(), "TIME_UTC"); - IDSnoopDevice(ActiveDeviceT[1].text, "DOME_PARK"); - IDSnoopDevice(ActiveDeviceT[1].text, "DOME_SHUTTER"); + IDSnoopDevice(ActiveDeviceTP[DOME].getText(), "DOME_PARK"); + IDSnoopDevice(ActiveDeviceTP[DOME].getText(), "DOME_SHUTTER"); return true; } } @@ -1434,7 +1432,7 @@ bool Telescope::ISNewSwitch(const char *dev, const char *name, ISState *states, #endif DomePolicySP.s = IPS_OK; IDSetSwitch(&DomePolicySP, nullptr); - triggerSnoop(ActiveDeviceT[1].text, "DOME_PARK"); + triggerSnoop(ActiveDeviceTP[DOME].getText(), "DOME_PARK"); return true; } diff --git a/libs/indibase/inditelescope.h b/libs/indibase/inditelescope.h index c4d57e49c8..dbf1fda573 100644 --- a/libs/indibase/inditelescope.h +++ b/libs/indibase/inditelescope.h @@ -779,8 +779,12 @@ class Telescope : public DefaultDevice void sendTimeFromSystem(); // Active GPS/Dome device to snoop - ITextVectorProperty ActiveDeviceTP; - IText ActiveDeviceT[2] {}; + INDI::PropertyText ActiveDeviceTP {2}; + enum + { + GPS, + DOME + }; // Switch to lock if dome is closed. ISwitchVectorProperty DomePolicySP; diff --git a/libs/indibase/indiweather.cpp b/libs/indibase/indiweather.cpp index fe61a45192..f856e65b7a 100644 --- a/libs/indibase/indiweather.cpp +++ b/libs/indibase/indiweather.cpp @@ -51,11 +51,11 @@ bool Weather::initProperties() IPS_OK); // Active Devices - IUFillText(&ActiveDeviceT[0], "ACTIVE_GPS", "GPS", "GPS Simulator"); - IUFillTextVector(&ActiveDeviceTP, ActiveDeviceT, 1, getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, - IP_RW, 60, IPS_IDLE); + ActiveDeviceTP[0].fill("ACTIVE_GPS", "GPS", "GPS Simulator"); + ActiveDeviceTP.fill(getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE); + ActiveDeviceTP.load(); - IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD"); + IDSnoopDevice(ActiveDeviceTP[0].getText(), "GEOGRAPHIC_COORD"); if (weatherConnection & CONNECTION_SERIAL) { @@ -82,6 +82,12 @@ bool Weather::initProperties() return true; } +void Weather::ISGetProperties(const char *dev) +{ + DefaultDevice::ISGetProperties(dev); + defineProperty(ActiveDeviceTP); +} + bool Weather::updateProperties() { DefaultDevice::updateProperties(); @@ -91,7 +97,6 @@ bool Weather::updateProperties() WI::updateProperties(); defineProperty(&LocationNP); - defineProperty(&ActiveDeviceTP); DEBUG(Logger::DBG_SESSION, "Weather update is in progress..."); } @@ -100,7 +105,6 @@ bool Weather::updateProperties() WI::updateProperties(); deleteProperty(LocationNP.name); - deleteProperty(ActiveDeviceTP.name); } return true; @@ -154,14 +158,13 @@ bool INDI::Weather::ISNewText(const char *dev, const char *name, char *texts[], // first check if it's for our device if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (!strcmp(name, ActiveDeviceTP.name)) + if (ActiveDeviceTP.isNameMatch(name)) { - ActiveDeviceTP.s = IPS_OK; - IUUpdateText(&ActiveDeviceTP, texts, names, n); + ActiveDeviceTP.setState(IPS_OK); + ActiveDeviceTP.update(texts, names, n); // Update client display - IDSetText(&ActiveDeviceTP, nullptr); - - IDSnoopDevice(ActiveDeviceT[0].text, "GEOGRAPHIC_COORD"); + ActiveDeviceTP.apply(); + IDSnoopDevice(ActiveDeviceTP[0].getText(), "GEOGRAPHIC_COORD"); return true; } } @@ -246,7 +249,7 @@ bool Weather::saveConfigItems(FILE *fp) { DefaultDevice::saveConfigItems(fp); WI::saveConfigItems(fp); - IUSaveConfigText(fp, &ActiveDeviceTP); + ActiveDeviceTP.save(fp); IUSaveConfigNumber(fp, &LocationNP); return true; } diff --git a/libs/indibase/indiweather.h b/libs/indibase/indiweather.h index 844631c63d..c2edf6e6da 100644 --- a/libs/indibase/indiweather.h +++ b/libs/indibase/indiweather.h @@ -88,6 +88,7 @@ class Weather : public DefaultDevice, public WeatherInterface Weather(); virtual bool initProperties() override; + virtual void ISGetProperties(const char *dev) override; virtual bool updateProperties() override; virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; @@ -95,7 +96,7 @@ class Weather : public DefaultDevice, public WeatherInterface virtual bool ISSnoopDevice(XMLEle *root) override; - protected: + protected: /** \brief Update weather station location * \param latitude Site latitude in degrees. * \param longitude Site latitude in degrees increasing eastward from Greenwich (0 to 360). @@ -127,13 +128,12 @@ class Weather : public DefaultDevice, public WeatherInterface INumber LocationN[3]; // Active devices to snoop - ITextVectorProperty ActiveDeviceTP; - IText ActiveDeviceT[1] {}; + INDI::PropertyText ActiveDeviceTP {1}; Connection::Serial *serialConnection {nullptr}; Connection::TCP *tcpConnection {nullptr}; - int PortFD = -1; + int PortFD = -1; private: bool processLocationInfo(double latitude, double longitude, double elevation);