From 1dd4a9c4897da66126f64e47c56f7555e1396bb3 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Thu, 31 Aug 2023 10:55:22 +0300 Subject: [PATCH] Add PARK_SIMPLE parking type for mounts that only report status but not position --- drivers/telescope/lx200am5.cpp | 17 +--- drivers/telescope/telescope_simulator.cpp | 3 +- libs/indibase/inditelescope.cpp | 99 ++++++++++++++--------- libs/indibase/inditelescope.h | 13 +-- 4 files changed, 70 insertions(+), 62 deletions(-) diff --git a/drivers/telescope/lx200am5.cpp b/drivers/telescope/lx200am5.cpp index 6be8d6066c..bd9420c5d9 100644 --- a/drivers/telescope/lx200am5.cpp +++ b/drivers/telescope/lx200am5.cpp @@ -54,7 +54,7 @@ bool LX200AM5::initProperties() { LX200Generic::initProperties(); - SetParkDataType(PARK_NONE); + SetParkDataType(PARK_SIMPLE); timeFormat = LX200_24; tcpConnection->setDefaultHost("192.168.4.1"); @@ -171,20 +171,7 @@ void LX200AM5::setup() // MountTypeSP.setState(setMountType(MountTypeSP.findOnSwitchIndex()) ? IPS_OK : IPS_ALERT); // MountTypeSP.apply(); - if (InitPark()) - { - // If loading parking data is successful, we just set the default parking values. - SetAxis1ParkDefault(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180); - SetAxis2ParkDefault(LocationN[LOCATION_LATITUDE].value); - } - else - { - // Otherwise, we set all parking data to default in case no parking data is found. - SetAxis1Park(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180); - SetAxis2Park(LocationN[LOCATION_LATITUDE].value); - SetAxis1ParkDefault(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180); - SetAxis2ParkDefault(LocationN[LOCATION_LATITUDE].value); - } + InitPark(); getMountType(); getTrackMode(); diff --git a/drivers/telescope/telescope_simulator.cpp b/drivers/telescope/telescope_simulator.cpp index 82bed074fd..42390f6a50 100644 --- a/drivers/telescope/telescope_simulator.cpp +++ b/drivers/telescope/telescope_simulator.cpp @@ -121,7 +121,8 @@ bool ScopeSim::initProperties() ScopeParametersN[3].value = 900; // RA is a rotating frame, while HA or Alt/Az is not - SetParkDataType(PARK_HA_DEC); + //SetParkDataType(PARK_HA_DEC); + SetParkDataType(PARK_SIMPLE); initGuiderProperties(getDeviceName(), MOTION_TAB); diff --git a/libs/indibase/inditelescope.cpp b/libs/indibase/inditelescope.cpp index 0277951551..a7cc1d3f83 100644 --- a/libs/indibase/inditelescope.cpp +++ b/libs/indibase/inditelescope.cpp @@ -1919,7 +1919,7 @@ void Telescope::SetParkDataType(TelescopeParkData type) { parkDataType = type; - if (parkDataType != PARK_NONE) + if (parkDataType != PARK_NONE && parkDataType != PARK_SIMPLE) { switch (parkDataType) { @@ -2004,10 +2004,13 @@ bool Telescope::InitPark() SyncParkStatus(isParked()); - LOGF_DEBUG("InitPark Axis1 %.2f Axis2 %.2f", Axis1ParkPosition, Axis2ParkPosition); - ParkPositionN[AXIS_RA].value = Axis1ParkPosition; - ParkPositionN[AXIS_DE].value = Axis2ParkPosition; - IDSetNumber(&ParkPositionNP, nullptr); + if (parkDataType != PARK_SIMPLE) + { + LOGF_DEBUG("InitPark Axis1 %.2f Axis2 %.2f", Axis1ParkPosition, Axis2ParkPosition); + ParkPositionN[AXIS_RA].value = Axis1ParkPosition; + ParkPositionN[AXIS_DE].value = Axis2ParkPosition; + IDSetNumber(&ParkPositionNP, nullptr); + } return true; } @@ -2090,13 +2093,21 @@ const char *Telescope::LoadParkXML() ParkdeviceXml = parkxml; ParkstatusXml = findXMLEle(parkxml, "parkstatus"); - ParkpositionXml = findXMLEle(parkxml, "parkposition"); - if (ParkpositionXml) - ParkpositionAxis1Xml = findXMLEle(ParkpositionXml, "axis1position"); - if (ParkpositionXml) - ParkpositionAxis2Xml = findXMLEle(ParkpositionXml, "axis2position"); - if (ParkstatusXml == nullptr || ParkpositionAxis1Xml == nullptr || ParkpositionAxis2Xml == nullptr) + if (parkDataType != PARK_SIMPLE) + { + ParkpositionXml = findXMLEle(parkxml, "parkposition"); + if (ParkpositionXml) + ParkpositionAxis1Xml = findXMLEle(ParkpositionXml, "axis1position"); + if (ParkpositionXml) + ParkpositionAxis2Xml = findXMLEle(ParkpositionXml, "axis2position"); + + if (ParkstatusXml == nullptr || ParkpositionAxis1Xml == nullptr || ParkpositionAxis2Xml == nullptr) + { + return "Park data invalid or missing."; + } + } + else if (ParkstatusXml == nullptr) { return "Park data invalid or missing."; } @@ -2115,28 +2126,33 @@ const char *Telescope::LoadParkData() if (!strcmp(pcdataXMLEle(ParkstatusXml), "true")) IsParked = true; - double axis1Pos = std::numeric_limits::quiet_NaN(); - double axis2Pos = std::numeric_limits::quiet_NaN(); - - int rc = sscanf(pcdataXMLEle(ParkpositionAxis1Xml), "%lf", &axis1Pos); - if (rc != 1) + if (parkDataType != PARK_SIMPLE) { - return "Unable to parse Park Position Axis 1."; - } - rc = sscanf(pcdataXMLEle(ParkpositionAxis2Xml), "%lf", &axis2Pos); - if (rc != 1) - { - return "Unable to parse Park Position Axis 2."; - } + double axis1Pos = std::numeric_limits::quiet_NaN(); + double axis2Pos = std::numeric_limits::quiet_NaN(); - if (std::isnan(axis1Pos) == false && std::isnan(axis2Pos) == false) - { - Axis1ParkPosition = axis1Pos; - Axis2ParkPosition = axis2Pos; - return nullptr; + int rc = sscanf(pcdataXMLEle(ParkpositionAxis1Xml), "%lf", &axis1Pos); + if (rc != 1) + { + return "Unable to parse Park Position Axis 1."; + } + rc = sscanf(pcdataXMLEle(ParkpositionAxis2Xml), "%lf", &axis2Pos); + if (rc != 1) + { + return "Unable to parse Park Position Axis 2."; + } + + if (std::isnan(axis1Pos) == false && std::isnan(axis2Pos) == false) + { + Axis1ParkPosition = axis1Pos; + Axis2ParkPosition = axis2Pos; + return nullptr; + } + + return "Failed to parse Park Position."; } - return "Failed to parse Park Position."; + return nullptr; } bool Telescope::PurgeParkData() @@ -2274,19 +2290,22 @@ bool Telescope::WriteParkData() if (!ParkstatusXml) ParkstatusXml = addXMLEle(ParkdeviceXml, "parkstatus"); - if (!ParkpositionXml) - ParkpositionXml = addXMLEle(ParkdeviceXml, "parkposition"); - if (!ParkpositionAxis1Xml) - ParkpositionAxis1Xml = addXMLEle(ParkpositionXml, "axis1position"); - if (!ParkpositionAxis2Xml) - ParkpositionAxis2Xml = addXMLEle(ParkpositionXml, "axis2position"); - editXMLEle(ParkstatusXml, (IsParked ? "true" : "false")); - snprintf(pcdata, sizeof(pcdata), "%lf", Axis1ParkPosition); - editXMLEle(ParkpositionAxis1Xml, pcdata); - snprintf(pcdata, sizeof(pcdata), "%lf", Axis2ParkPosition); - editXMLEle(ParkpositionAxis2Xml, pcdata); + if (parkDataType != PARK_SIMPLE) + { + if (!ParkpositionXml) + ParkpositionXml = addXMLEle(ParkdeviceXml, "parkposition"); + if (!ParkpositionAxis1Xml) + ParkpositionAxis1Xml = addXMLEle(ParkpositionXml, "axis1position"); + if (!ParkpositionAxis2Xml) + ParkpositionAxis2Xml = addXMLEle(ParkpositionXml, "axis2position"); + + snprintf(pcdata, sizeof(pcdata), "%lf", Axis1ParkPosition); + editXMLEle(ParkpositionAxis1Xml, pcdata); + snprintf(pcdata, sizeof(pcdata), "%lf", Axis2ParkPosition); + editXMLEle(ParkpositionAxis2Xml, pcdata); + } prXMLEle(fp, ParkdataXmlRoot, 0); fclose(fp); diff --git a/libs/indibase/inditelescope.h b/libs/indibase/inditelescope.h index 328f8d58ec..234e0c744d 100644 --- a/libs/indibase/inditelescope.h +++ b/libs/indibase/inditelescope.h @@ -106,12 +106,13 @@ class Telescope : public DefaultDevice }; enum TelescopeParkData { - PARK_NONE, - PARK_RA_DEC, - PARK_HA_DEC, - PARK_AZ_ALT, - PARK_RA_DEC_ENCODER, - PARK_AZ_ALT_ENCODER + PARK_NONE, /*!< Mount does not support any form of parking */ + PARK_RA_DEC, /*!< Park to specific RA/DE coordinate. Deprecated, do not use */ + PARK_HA_DEC, /*!< Park to specific HA/DE coordinate. Hour Angle & Declination degrees */ + PARK_AZ_ALT, /*!< Park to specific AZ/ALT coordinate. Azimuth & Altitude degrees */ + PARK_RA_DEC_ENCODER, /*!< Park to specific HA/DE encoder. Hour Angle & Declination steps */ + PARK_AZ_ALT_ENCODER, /*!< Park to specific AZ/ALT encoder. Azimuth & Altitude steps */ + PARK_SIMPLE /*!< Only Park or Unpark is known but location is unknown. */ }; enum TelescopeLocation {