Skip to content

Commit

Permalink
Fix active device issue with config update
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Mar 27, 2024
1 parent c5f64f5 commit d494b3e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 42 deletions.
1 change: 0 additions & 1 deletion drivers/auxiliary/astrometrydriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void AstrometryDriver::ISGetProperties(const char *dev)
DefaultDevice::ISGetProperties(dev);

defineProperty(&ActiveDeviceTP);
loadConfig(true, "ACTIVE_DEVICES");
}

bool AstrometryDriver::updateProperties()
Expand Down
1 change: 0 additions & 1 deletion libs/indibase/indidome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 19 additions & 21 deletions libs/indibase/inditelescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions libs/indibase/inditelescope.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 16 additions & 13 deletions libs/indibase/indiweather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();
Expand All @@ -91,7 +97,6 @@ bool Weather::updateProperties()
WI::updateProperties();

defineProperty(&LocationNP);
defineProperty(&ActiveDeviceTP);

DEBUG(Logger::DBG_SESSION, "Weather update is in progress...");
}
Expand All @@ -100,7 +105,6 @@ bool Weather::updateProperties()
WI::updateProperties();

deleteProperty(LocationNP.name);
deleteProperty(ActiveDeviceTP.name);
}

return true;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions libs/indibase/indiweather.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ 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;
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;

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).
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d494b3e

Please sign in to comment.