Skip to content

Commit

Permalink
Ensure we only snoop updated values
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Dec 23, 2024
1 parent c68e12b commit c6483e5
Showing 1 changed file with 93 additions and 61 deletions.
154 changes: 93 additions & 61 deletions libs/indibase/indiccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,10 @@ bool CCD::ISSnoopDevice(XMLEle * root)
for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
newFilterSlot = atoi(pcdataXMLEle(ep));
if (newFilterSlot != CurrentFilterSlot)
{
CurrentFilterSlot = newFilterSlot;
LOGF_DEBUG("SNOOP: FILTER_SLOT is %d", CurrentFilterSlot);
}
{
CurrentFilterSlot = newFilterSlot;
LOGF_DEBUG("SNOOP: FILTER_SLOT is %d", CurrentFilterSlot);
}
}
else if (!strcmp(propName, "SKY_QUALITY") && deviceName == ActiveDeviceTP[ACTIVE_SKYQUALITY].getText())
{
Expand Down Expand Up @@ -922,86 +922,118 @@ bool CCD::ISNewText(const char * dev, const char * name, char * texts[], char *
// first check if it's for our device
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
// This is for our device
// Now lets see if it's something we process here
if (ActiveDeviceTP.isNameMatch(name))
{
ActiveDeviceTP.setState(IPS_OK);
ActiveDeviceTP.update(texts, names, n);
ActiveDeviceTP.apply();
std::vector<std::string> prevValues;
prevValues.reserve(n);

// Update the property name!
// strncpy(EqNP.device, ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), MAXINDIDEVICE);
EqNP.setDeviceName(ActiveDeviceTP[ACTIVE_TELESCOPE].getText());
J2000EqNP.setDeviceName(ActiveDeviceTP[ACTIVE_TELESCOPE].getText());
if (strlen(ActiveDeviceTP[ACTIVE_TELESCOPE].getText()) > 0)
{
LOGF_DEBUG("Snopping on Mount %s", ActiveDeviceTP[ACTIVE_TELESCOPE].getText());
IDSnoopDevice(ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), "EQUATORIAL_EOD_COORD");
IDSnoopDevice(ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), "EQUATORIAL_COORD");
IDSnoopDevice(ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), "TELESCOPE_INFO");
IDSnoopDevice(ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), "GEOGRAPHIC_COORD");
}
else
{
LOG_DEBUG("No mount is set. Clearing all mount watchers.");
RA = std::numeric_limits<double>::quiet_NaN();
Dec = std::numeric_limits<double>::quiet_NaN();
J2000RA = std::numeric_limits<double>::quiet_NaN();
J2000DE = std::numeric_limits<double>::quiet_NaN();
Latitude = std::numeric_limits<double>::quiet_NaN();
Longitude = std::numeric_limits<double>::quiet_NaN();
Airmass = std::numeric_limits<double>::quiet_NaN();
Azimuth = std::numeric_limits<double>::quiet_NaN();
Altitude = std::numeric_limits<double>::quiet_NaN();
}
// Store all previous values
for (int i = 0; i < n; i++)
prevValues.push_back(ActiveDeviceTP[i].getText());

if (strlen(ActiveDeviceTP[ACTIVE_ROTATOR].getText()) > 0)
// Check if any values actually changed
bool hasChanged = false;
for (int i = 0; i < n; i++)
{
LOGF_DEBUG("Snopping on Rotator %s", ActiveDeviceTP[ACTIVE_ROTATOR].getText());
IDSnoopDevice(ActiveDeviceTP[ACTIVE_ROTATOR].getText(), "ABS_ROTATOR_ANGLE");
if (prevValues[i] != texts[i])
{
hasChanged = true;
break;
}
}
else

if (!hasChanged)
{
LOG_DEBUG("No rotator is set. Clearing all rotator watchers.");
MPSAS = std::numeric_limits<double>::quiet_NaN();
ActiveDeviceTP.setState(IPS_OK);
ActiveDeviceTP.apply();
return true;
}

// JJ ed 2019-12-10
if (strlen(ActiveDeviceTP[ACTIVE_FOCUSER].getText()) > 0)
// Update the properties since we have changes
ActiveDeviceTP.setState(IPS_OK);
ActiveDeviceTP.update(texts, names, n);
ActiveDeviceTP.apply();

// Mount
auto newMount = ActiveDeviceTP[ACTIVE_TELESCOPE].getText();
if (newMount != prevValues[ACTIVE_TELESCOPE])
{
LOGF_DEBUG("Snopping on Focuser %s", ActiveDeviceTP[ACTIVE_FOCUSER].getText());
IDSnoopDevice(ActiveDeviceTP[ACTIVE_FOCUSER].getText(), "ABS_FOCUS_POSITION");
IDSnoopDevice(ActiveDeviceTP[ACTIVE_FOCUSER].getText(), "FOCUS_TEMPERATURE");
EqNP.setDeviceName(newMount);
J2000EqNP.setDeviceName(newMount);
if (strlen(newMount) > 0)
{
LOGF_DEBUG("Snopping on Mount %s", newMount);
IDSnoopDevice(newMount, "EQUATORIAL_EOD_COORD");
IDSnoopDevice(newMount, "EQUATORIAL_COORD");
IDSnoopDevice(newMount, "TELESCOPE_INFO");
IDSnoopDevice(newMount, "GEOGRAPHIC_COORD");
}
else if (!std::isnan(RA))
{
LOG_DEBUG("No mount is set. Clearing all mount watchers.");
RA = Dec = J2000RA = J2000DE = Latitude = Longitude = Airmass = Azimuth = Altitude = std::numeric_limits<double>::quiet_NaN();
}
}
else

// Rotator
auto newRotator = ActiveDeviceTP[ACTIVE_ROTATOR].getText();
if (newRotator != prevValues[ACTIVE_ROTATOR])
{
LOG_DEBUG("No focuser is set. Clearing all focuser watchers.");
FocuserPos = -1;
FocuserTemp = std::numeric_limits<double>::quiet_NaN();
if (strlen(newRotator) > 0)
{
LOGF_DEBUG("Snopping on Rotator %s", newRotator);
IDSnoopDevice(newRotator, "ABS_ROTATOR_ANGLE");
}
else if (!std::isnan(MPSAS))
{
LOG_DEBUG("No rotator is set. Clearing all rotator watchers.");
MPSAS = std::numeric_limits<double>::quiet_NaN();
}
}


if (strlen(ActiveDeviceTP[ACTIVE_FILTER].getText()) > 0)
// Focuser
auto newFocuser = ActiveDeviceTP[ACTIVE_FOCUSER].getText();
if (newFocuser != prevValues[ACTIVE_FOCUSER])
{
LOGF_DEBUG("Snopping on Filter Wheel %s", ActiveDeviceTP[ACTIVE_FILTER].getText());
IDSnoopDevice(ActiveDeviceTP[ACTIVE_FILTER].getText(), "FILTER_SLOT");
IDSnoopDevice(ActiveDeviceTP[ACTIVE_FILTER].getText(), "FILTER_NAME");
if (strlen(newFocuser) > 0)
{
LOGF_DEBUG("Snopping on Focuser %s", newFocuser);
IDSnoopDevice(newFocuser, "ABS_FOCUS_POSITION");
IDSnoopDevice(newFocuser, "FOCUS_TEMPERATURE");
}
else if (!std::isnan(FocuserTemp))
{
LOG_DEBUG("No focuser is set. Clearing all focuser watchers.");
FocuserPos = -1;
FocuserTemp = std::numeric_limits<double>::quiet_NaN();
}
}
else

// Filter Wheel
auto newFilterWheel = ActiveDeviceTP[ACTIVE_FILTER].getText();
if (newFilterWheel != prevValues[ACTIVE_FILTER])
{
LOG_DEBUG("No filter wheel is set. Clearing All filter wheel watchers.");
CurrentFilterSlot = -1;
if (strlen(newFilterWheel) > 0)
{
LOGF_DEBUG("Snopping on Filter Wheel %s", newFilterWheel);
IDSnoopDevice(newFilterWheel, "FILTER_SLOT");
IDSnoopDevice(newFilterWheel, "FILTER_NAME");
}
else if (CurrentFilterSlot != -1)
{
LOG_DEBUG("No filter wheel is set. Clearing All filter wheel watchers.");
CurrentFilterSlot = -1;
}
}

IDSnoopDevice(ActiveDeviceTP[ACTIVE_SKYQUALITY].getText(), "SKY_QUALITY");
// Sky Quality
auto newSkyQuality = ActiveDeviceTP[ACTIVE_SKYQUALITY].getText();
if (newSkyQuality != prevValues[ACTIVE_SKYQUALITY] && strlen(newSkyQuality) > 0)
IDSnoopDevice(newSkyQuality, "SKY_QUALITY");

// Tell children active devices was updated.
activeDevicesUpdated();

saveConfig(ActiveDeviceTP);

// We processed this one, so, tell the world we did it
return true;
}

Expand Down

0 comments on commit c6483e5

Please sign in to comment.