Skip to content

Commit

Permalink
Add PARK_SIMPLE parking type for mounts that only report status but n…
Browse files Browse the repository at this point in the history
…ot position
  • Loading branch information
knro committed Aug 31, 2023
1 parent 10fe419 commit 1dd4a9c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 62 deletions.
17 changes: 2 additions & 15 deletions drivers/telescope/lx200am5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool LX200AM5::initProperties()
{
LX200Generic::initProperties();

SetParkDataType(PARK_NONE);
SetParkDataType(PARK_SIMPLE);
timeFormat = LX200_24;

tcpConnection->setDefaultHost("192.168.4.1");
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion drivers/telescope/telescope_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
99 changes: 59 additions & 40 deletions libs/indibase/inditelescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ void Telescope::SetParkDataType(TelescopeParkData type)
{
parkDataType = type;

if (parkDataType != PARK_NONE)
if (parkDataType != PARK_NONE && parkDataType != PARK_SIMPLE)
{
switch (parkDataType)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.";
}
Expand All @@ -2115,28 +2126,33 @@ const char *Telescope::LoadParkData()
if (!strcmp(pcdataXMLEle(ParkstatusXml), "true"))
IsParked = true;

double axis1Pos = std::numeric_limits<double>::quiet_NaN();
double axis2Pos = std::numeric_limits<double>::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<double>::quiet_NaN();
double axis2Pos = std::numeric_limits<double>::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()
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions libs/indibase/inditelescope.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 1dd4a9c

Please sign in to comment.