From 8eae5e9faeb2524e08c1dc33ccbf697803b0cc81 Mon Sep 17 00:00:00 2001 From: GJayLG <76550884+GJayLG@users.noreply.github.com> Date: Wed, 5 Aug 2026 23:59:17 +0300 Subject: [PATCH 1/2] Fix DEC and longitude conversions in Meade commands After the Meade parser refactor, DEC targets and syncs were treated as degrees from the pole instead of celestial declination, and the longitude sign convention (east negative on the wire) was dropped. --- src/MeadeCommandProcessor.cpp | 38 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 419f7630..65094538 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -97,12 +97,27 @@ meade::RaCoordinate raFrom(const DayTime &t) }; } +Declination decToInternal(const meade::DecCoordinate &d) +{ + long seconds = labs(static_cast(d.degrees)) * 3600L + d.minutes * 60L + d.seconds; + return Declination::FromSeconds(d.degrees < 0 ? -seconds : seconds); +} + meade::DecCoordinate decFrom(const Declination &d) { + const long celestialSeconds = inNorthernHemisphere ? 90L * 3600L - labs(d.getTotalSeconds()) + : -90L * 3600L + labs(d.getTotalSeconds()); + const long absoluteSeconds = labs(celestialSeconds); + int16_t degrees = static_cast(absoluteSeconds / 3600L); + if (celestialSeconds < 0) + { + degrees = -degrees; + } + return meade::DecCoordinate { - static_cast(d.getHours()), - static_cast(d.getMinutes()), - static_cast(d.getSeconds()), + degrees, + static_cast((absoluteSeconds / 60L) % 60L), + static_cast(absoluteSeconds % 60L), }; } } // namespace @@ -160,9 +175,16 @@ meade::MeadeLatitude MeadeCommandProcessor::onSiteLatitude() meade::MeadeLongitude MeadeCommandProcessor::onSiteLongitude() { const Longitude lon = _mount->longitude(); + long secs = labs(static_cast(lon.getTotalSeconds())); + int16_t deg = static_cast(secs / 3600L); + uint8_t min = static_cast((secs / 60L) % 60L); + if (lon.getTotalHours() > 0) + { + deg = -deg; + } return meade::MeadeLongitude { - static_cast(lon.getHours()), - static_cast(lon.getMinutes()), + deg, + min, }; } @@ -248,7 +270,7 @@ void MeadeCommandProcessor::onSyncToTarget() ///////////////////////////// bool MeadeCommandProcessor::onSetTargetDec(meade::DecCoordinate dec) { - _mount->targetDEC() = Declination(static_cast(dec.degrees), static_cast(dec.minutes), static_cast(dec.seconds)); + _mount->targetDEC() = decToInternal(dec); LOG(DEBUG_MEADE, "[MEADE]: SetInfo: Received Target DEC: %s", _mount->targetDEC().ToString()); return true; } @@ -282,7 +304,7 @@ bool MeadeCommandProcessor::onSetHourAngle(uint8_t hours, uint8_t minutes) bool MeadeCommandProcessor::onSyncCoordinates(meade::DecCoordinate dec, meade::RaCoordinate ra) { - Declination decValue(static_cast(dec.degrees), static_cast(dec.minutes), static_cast(dec.seconds)); + Declination decValue = decToInternal(dec); DayTime raValue(static_cast(ra.hours), static_cast(ra.minutes), static_cast(ra.seconds)); _mount->syncPosition(raValue, decValue); return true; @@ -296,7 +318,7 @@ bool MeadeCommandProcessor::onSetSiteLatitude(meade::MeadeLatitude lat) bool MeadeCommandProcessor::onSetSiteLongitude(meade::MeadeLongitude lon) { - _mount->setLongitude(Longitude(static_cast(lon.degrees), static_cast(lon.minutes), 0)); + _mount->setLongitude(Longitude(-static_cast(lon.degrees), static_cast(lon.minutes), 0)); return true; } From a3cce7efa9c85fa4b3fecf6875b62f124abdbb25 Mon Sep 17 00:00:00 2001 From: GJayLG <76550884+GJayLG@users.noreply.github.com> Date: Thu, 6 Aug 2026 00:02:07 +0300 Subject: [PATCH 2/2] style: clang-format --- src/MeadeCommandProcessor.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 65094538..e95e0254 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -105,8 +105,7 @@ Declination decToInternal(const meade::DecCoordinate &d) meade::DecCoordinate decFrom(const Declination &d) { - const long celestialSeconds = inNorthernHemisphere ? 90L * 3600L - labs(d.getTotalSeconds()) - : -90L * 3600L + labs(d.getTotalSeconds()); + const long celestialSeconds = inNorthernHemisphere ? 90L * 3600L - labs(d.getTotalSeconds()) : -90L * 3600L + labs(d.getTotalSeconds()); const long absoluteSeconds = labs(celestialSeconds); int16_t degrees = static_cast(absoluteSeconds / 3600L); if (celestialSeconds < 0)