From c6483e5b0e67c3f44795659878496ffe63da7d65 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Mon, 23 Dec 2024 11:56:34 +0300 Subject: [PATCH] Ensure we only snoop updated values --- libs/indibase/indiccd.cpp | 154 +++++++++++++++++++++++--------------- 1 file changed, 93 insertions(+), 61 deletions(-) diff --git a/libs/indibase/indiccd.cpp b/libs/indibase/indiccd.cpp index ef7bc59d39..4f4d25b914 100644 --- a/libs/indibase/indiccd.cpp +++ b/libs/indibase/indiccd.cpp @@ -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()) { @@ -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 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::quiet_NaN(); - Dec = std::numeric_limits::quiet_NaN(); - J2000RA = std::numeric_limits::quiet_NaN(); - J2000DE = std::numeric_limits::quiet_NaN(); - Latitude = std::numeric_limits::quiet_NaN(); - Longitude = std::numeric_limits::quiet_NaN(); - Airmass = std::numeric_limits::quiet_NaN(); - Azimuth = std::numeric_limits::quiet_NaN(); - Altitude = std::numeric_limits::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::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::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::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::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::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; }