Skip to content

Commit

Permalink
Fixes to Meade Longitude and UC handling (#181)
Browse files Browse the repository at this point in the history
* Meade Updates V1.11.5

- Corrected Longitude parsing to account for sign
- Corrected Longitude output to provide sign
- Corrected inverted UTC offset
- Corrected handshake response to 0x06 to be P for Polar mode
- EEPROM debug code caused crash due to using F() macro in args
- Added specific Longitude output function for Meade
- Fixed comment on Meade :SC command
  • Loading branch information
ClutchplateDude authored Mar 27, 2022
1 parent 87f918c commit d387d8d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 35 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**V1.11.5 - Updates**
- Corrected Longitude parsing to account for sign
- Corrected Longitude output to provide sign
- Corrected inverted UTC offset
- Corrected handshake response to 0x06 to be P for Polar mode

**V1.11.4 - Updates**
- Allow disabling Points Of Interest in LCD menu

Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// Also, numbers are interpreted as simple numbers. _ __ _
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/

#define VERSION "V1.11.4"
#define VERSION "V1.11.5"
14 changes: 10 additions & 4 deletions src/DayTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ const char *DayTime::formatStringImpl(char *targetBuffer, const char *format, ch
i++;
}

if (degs >= 100)
long absdegs = labs(degs);
if (absdegs >= 100)
{
achDegs[i++] = '0' + min(9L, (degs / 100));
degs = degs % 100;
achDegs[i++] = '0' + min(9L, (absdegs / 100));
absdegs = absdegs % 100;
}

printTwoDigits(achDegs + i, degs);
printTwoDigits(achDegs + i, absdegs);
printTwoDigits(achMins, mins);
printTwoDigits(achSecs, secs);

Expand All @@ -294,6 +295,11 @@ const char *DayTime::formatStringImpl(char *targetBuffer, const char *format, ch
{
switch (macro)
{
case '+':
{
*p++ = (degs < 0 ? '-' : '+');
}
break;
case 'd':
{
strcpy(p, achDegs);
Expand Down
6 changes: 3 additions & 3 deletions src/EPROMStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ void EEPROMStore::displayContents()
uint16_t marker = readUint16(MAGIC_MARKER_AND_FLAGS_ADDR);
LOG(DEBUG_EEPROM, "[EEPROM]: Magic Marker: %x", marker);

LOG(DEBUG_INFO, "[EEPROM]: Values? %s", ((marker & MAGIC_MARKER_MASK) == MAGIC_MARKER_VALUE) ? F("Yes") : F("No"));
LOG(DEBUG_INFO, "[EEPROM]: Extended values? %s", ((marker & EXTENDED_FLAG) == EXTENDED_FLAG) ? F("Yes") : F("No"));
LOG(DEBUG_INFO, "[EEPROM]: IsPresent(EXTENDED)? %s", (EEPROMStore::isPresent(EXTENDED_FLAG) ? F("Yes") : F("No")));
LOG(DEBUG_INFO, "[EEPROM]: Values? %s", ((marker & MAGIC_MARKER_MASK) == MAGIC_MARKER_VALUE) ? "Yes" : "No");
LOG(DEBUG_INFO, "[EEPROM]: Extended values? %s", ((marker & EXTENDED_FLAG) == EXTENDED_FLAG) ? "Yes" : "No");
LOG(DEBUG_INFO, "[EEPROM]: IsPresent(EXTENDED)? %s", (EEPROMStore::isPresent(EXTENDED_FLAG) ? "Yes" : "No"));
LOG(DEBUG_INFO, "[EEPROM]: Stored HATime: %s", getHATime().ToString());
LOG(DEBUG_INFO, "[EEPROM]: Stored UTC Offset: %d", getUtcOffset());
LOG(DEBUG_INFO, "[EEPROM]: Stored Brightness: %d", getBrightness());
Expand Down
45 changes: 39 additions & 6 deletions src/Longitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ Longitude Longitude::ParseFromMeade(String const &s)
// Use the DayTime code to parse it.
DayTime dt = DayTime::ParseFromMeade(s);

//from indilib driver: Meade defines longitude as 0 to 360 WESTWARD (https://github.com/indilib/indi/blob/1b2f462b9c9b0f75629b635d77dc626b9d4b74a3/drivers/telescope/lx200driver.cpp#L1019)
result.totalSeconds = 180L * 3600L - dt.getTotalSeconds();
if ((s[0] == '-') || (s[0] == '+'))
{
// According to spec 2010.10, if a sign is present it is straight up longitude with east as negative.
result.totalSeconds = -dt.getTotalSeconds();
}
else
{
//from indilib driver: Meade defines longitude as 0 to 360 WESTWARD (https://github.com/indilib/indi/blob/1b2f462b9c9b0f75629b635d77dc626b9d4b74a3/drivers/telescope/lx200driver.cpp#L1019)
result.totalSeconds = 180L * 3600L - dt.getTotalSeconds();
}
result.checkHours();

LOG(DEBUG_GENERAL, "[LONGITUDE]: Parse(%s) -> %s = %ls", s.c_str(), result.ToString(), result.getTotalSeconds());
Expand Down Expand Up @@ -69,15 +77,40 @@ const char *Longitude::ToString() const

const char *Longitude::formatString(char *targetBuffer, const char *format, long *) const
{
long secs = totalSeconds;

// Map to 0..360 westwards
secs = 180L * 3600L - secs;
long secs = labs(totalSeconds);

long degs = secs / 3600;
secs = secs - degs * 3600;
long mins = secs / 60;
secs = secs - mins * 60;
if (totalSeconds < 0)
{
degs = -degs;
}

return formatStringImpl(targetBuffer, format, '\0', degs, mins, secs);
}

const char *Longitude::formatStringForMeade(char *targetBuffer) const
{
LOG(DEBUG_MEADE, "[LONGITUDE] Format %l for Meade", totalSeconds);
long secs = labs(totalSeconds);

long degs = secs / 3600;
secs = secs - degs * 3600;
long mins = secs / 60;
secs = secs - mins * 60;
LOG(DEBUG_MEADE, "[LONGITUDE] Degs is %l, Mins is %l", degs, mins);

// Since internal storage is actual longitude, Meade is negated
if (totalSeconds > 0)
{
// Since we already inverted it when it was negative (by using ABS a few
// lines above here), we only invert it if it is positive.
degs = -degs;
}

LOG(DEBUG_MEADE, "[LONGITUDE] Inverted Degs, now %l, Mins is %l", degs, mins);

return formatStringImpl(targetBuffer, "{+}{d}*{m}", '\0', degs, mins, secs);
}
1 change: 1 addition & 0 deletions src/Longitude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Longitude : public DayTime
Longitude(float inDegrees);

virtual const char *formatString(char *targetBuffer, const char *format, long *pSeconds = nullptr) const;
const char *formatStringForMeade(char *targetBuffer) const;
virtual const char *ToString() const;

static Longitude ParseFromMeade(String const &s);
Expand Down
38 changes: 21 additions & 17 deletions src/MeadeCommandProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
// Description:
// Get Site Longitude
// Returns:
// "DDD*MM#"
// "sDDD*MM#"
// Parameters:
// "DDD" is the longitude in degrees
// "MM" the minutes
// "s" is the sign of the longitude
// "DDD" is the degrees
// "MM" is the minutes
// Remarks:
// Longitudes are from 0 to 360 going WEST. so 179W is 359 and 179E is 1.
// Note that this is the actual longitude, but east coordinates are negative (opposite of normal cartographic coordinates)
//
// :Gc#
// Description:
Expand All @@ -172,12 +173,14 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
//
// :GG#
// Description:
// Get UTC offset time
// Get offset to UTC time
// Returns:
// "sHH#"
// Parameters:
// "s" is the sign
// "HH" are the number of hours that need to be added to local time to convert to UTC time
// "HH" is the number of hours
// Remarks
// Note that this is NOT simply the timezone offset you are in (like -8 for Pacific Standard Time), it is the negative of it. So how many hours need to be added to your local time to get to UTC.
//
// :Ga#
// Description:
Expand Down Expand Up @@ -330,7 +333,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
// "DD" is the degree (90 or less)
// "MM" is minutes
//
// :SgDDD*MM#
// :SgsDDD*MM#
// Description:
// Set Site Longitude
// Information:
Expand All @@ -339,10 +342,12 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
// "1" if successfully set
// "0" otherwise
// Parameters:
// "DDD" the nmber of degrees (0 to 360)
// "MM" is minutes
// "s" (optional) is the sign of the longitude (see Remarks)
// "DDD" is the number of degrees
// "MM" is the minutes
// Remarks:
// Longitudes are from 0 to 360 going WEST. so 179W is 359 and 179E is 1.
// When a sign is provided, longitudes are interpreted as given, with zero at Greenwich but negative coordinates going east (opposite of normal cartographic coordinates)
// When a sign is not provided, longitudes are from 0 to 360 going WEST with 180 at Greenwich. So 369 is 179W and 1 is 179E. 190 would be 10W and 170 would be 10E.
//
// :SGsHH#
// Description:
Expand Down Expand Up @@ -375,7 +380,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
// Returns:
// "1Updating Planetary Data# #"
// Parameters:
// "HHMM" is the month
// "MM" is the month
// "DD" is the day
// "YY" is the year since 2000
//
Expand Down Expand Up @@ -1130,8 +1135,8 @@ String MeadeCommandProcessor::handleMeadeGetInfo(String inCmd)
}
case 'g': // :Gg
{
_mount->longitude().formatString(achBuffer, "{d}*{m}#");
return String(achBuffer);
_mount->longitude().formatStringForMeade(achBuffer);
return String(achBuffer) + "#";
}
case 'c': // :Gc
{
Expand All @@ -1140,7 +1145,7 @@ String MeadeCommandProcessor::handleMeadeGetInfo(String inCmd)
case 'G': // :GG
{
int offset = _mount->getLocalUtcOffset();
sprintf(achBuffer, "%+03d#", offset);
sprintf(achBuffer, "%+03d#", -offset);
return String(achBuffer);
}
case 'a': // :Ga
Expand Down Expand Up @@ -1329,17 +1334,16 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd)
_mount->setLatitude(lat);
return "1";
}
else if (inCmd[0] == 'g') // longitude :Sg097*34#
else if (inCmd[0] == 'g') // longitude :Sg097*34# or :Sg-122*54#
{
Longitude lon = Longitude::ParseFromMeade(inCmd.substring(1));

_mount->setLongitude(lon);
return "1";
}
else if (inCmd[0] == 'G') // utc offset :SG+05#
{
int offset = inCmd.substring(1, 4).toInt();
_mount->setLocalUtcOffset(offset);
_mount->setLocalUtcOffset(-offset);
return "1";
}
else if (inCmd[0] == 'L') // Local time :SL19:33:03#
Expand Down
4 changes: 2 additions & 2 deletions src/WifiControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ void WifiControl::tcpLoop()
{
client.read();
LOG(DEBUG_WIFI, "[WIFITCP]: Query <-- Handshake request");
client.write("1");
LOG(DEBUG_WIFI, "[WIFITCP]: Reply --> 1");
client.write("P");
LOG(DEBUG_WIFI, "[WIFITCP]: Reply --> P (polar mode)");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/f_serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void processSerialData()
{
if (buffer[0] == 0x06)
{
LOG(DEBUG_SERIAL, "[SERIAL]: Received: ACK request, replying 1");
LOG(DEBUG_SERIAL, "[SERIAL]: Received: ACK request, replying P");
// When not debugging, print the result to the serial port .
// When debugging, only print the result to Serial if we're on seperate ports.
#if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1)
Serial.print('1');
Serial.print('P');
#endif
}
else
Expand Down

0 comments on commit d387d8d

Please sign in to comment.