Skip to content

Commit d387d8d

Browse files
Fixes to Meade Longitude and UC handling (#181)
* 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
1 parent 87f918c commit d387d8d

File tree

9 files changed

+85
-35
lines changed

9 files changed

+85
-35
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
**V1.11.5 - Updates**
2+
- Corrected Longitude parsing to account for sign
3+
- Corrected Longitude output to provide sign
4+
- Corrected inverted UTC offset
5+
- Corrected handshake response to 0x06 to be P for Polar mode
6+
17
**V1.11.4 - Updates**
28
- Allow disabling Points Of Interest in LCD menu
39

Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// Also, numbers are interpreted as simple numbers. _ __ _
44
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/
55

6-
#define VERSION "V1.11.4"
6+
#define VERSION "V1.11.5"

src/DayTime.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ const char *DayTime::formatStringImpl(char *targetBuffer, const char *format, ch
267267
i++;
268268
}
269269

270-
if (degs >= 100)
270+
long absdegs = labs(degs);
271+
if (absdegs >= 100)
271272
{
272-
achDegs[i++] = '0' + min(9L, (degs / 100));
273-
degs = degs % 100;
273+
achDegs[i++] = '0' + min(9L, (absdegs / 100));
274+
absdegs = absdegs % 100;
274275
}
275276

276-
printTwoDigits(achDegs + i, degs);
277+
printTwoDigits(achDegs + i, absdegs);
277278
printTwoDigits(achMins, mins);
278279
printTwoDigits(achSecs, secs);
279280

@@ -294,6 +295,11 @@ const char *DayTime::formatStringImpl(char *targetBuffer, const char *format, ch
294295
{
295296
switch (macro)
296297
{
298+
case '+':
299+
{
300+
*p++ = (degs < 0 ? '-' : '+');
301+
}
302+
break;
297303
case 'd':
298304
{
299305
strcpy(p, achDegs);

src/EPROMStore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ void EEPROMStore::displayContents()
121121
uint16_t marker = readUint16(MAGIC_MARKER_AND_FLAGS_ADDR);
122122
LOG(DEBUG_EEPROM, "[EEPROM]: Magic Marker: %x", marker);
123123

124-
LOG(DEBUG_INFO, "[EEPROM]: Values? %s", ((marker & MAGIC_MARKER_MASK) == MAGIC_MARKER_VALUE) ? F("Yes") : F("No"));
125-
LOG(DEBUG_INFO, "[EEPROM]: Extended values? %s", ((marker & EXTENDED_FLAG) == EXTENDED_FLAG) ? F("Yes") : F("No"));
126-
LOG(DEBUG_INFO, "[EEPROM]: IsPresent(EXTENDED)? %s", (EEPROMStore::isPresent(EXTENDED_FLAG) ? F("Yes") : F("No")));
124+
LOG(DEBUG_INFO, "[EEPROM]: Values? %s", ((marker & MAGIC_MARKER_MASK) == MAGIC_MARKER_VALUE) ? "Yes" : "No");
125+
LOG(DEBUG_INFO, "[EEPROM]: Extended values? %s", ((marker & EXTENDED_FLAG) == EXTENDED_FLAG) ? "Yes" : "No");
126+
LOG(DEBUG_INFO, "[EEPROM]: IsPresent(EXTENDED)? %s", (EEPROMStore::isPresent(EXTENDED_FLAG) ? "Yes" : "No"));
127127
LOG(DEBUG_INFO, "[EEPROM]: Stored HATime: %s", getHATime().ToString());
128128
LOG(DEBUG_INFO, "[EEPROM]: Stored UTC Offset: %d", getUtcOffset());
129129
LOG(DEBUG_INFO, "[EEPROM]: Stored Brightness: %d", getBrightness());

src/Longitude.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ Longitude Longitude::ParseFromMeade(String const &s)
4040
// Use the DayTime code to parse it.
4141
DayTime dt = DayTime::ParseFromMeade(s);
4242

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

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

7078
const char *Longitude::formatString(char *targetBuffer, const char *format, long *) const
7179
{
72-
long secs = totalSeconds;
73-
74-
// Map to 0..360 westwards
75-
secs = 180L * 3600L - secs;
80+
long secs = labs(totalSeconds);
7681

7782
long degs = secs / 3600;
7883
secs = secs - degs * 3600;
7984
long mins = secs / 60;
8085
secs = secs - mins * 60;
86+
if (totalSeconds < 0)
87+
{
88+
degs = -degs;
89+
}
8190

8291
return formatStringImpl(targetBuffer, format, '\0', degs, mins, secs);
8392
}
93+
94+
const char *Longitude::formatStringForMeade(char *targetBuffer) const
95+
{
96+
LOG(DEBUG_MEADE, "[LONGITUDE] Format %l for Meade", totalSeconds);
97+
long secs = labs(totalSeconds);
98+
99+
long degs = secs / 3600;
100+
secs = secs - degs * 3600;
101+
long mins = secs / 60;
102+
secs = secs - mins * 60;
103+
LOG(DEBUG_MEADE, "[LONGITUDE] Degs is %l, Mins is %l", degs, mins);
104+
105+
// Since internal storage is actual longitude, Meade is negated
106+
if (totalSeconds > 0)
107+
{
108+
// Since we already inverted it when it was negative (by using ABS a few
109+
// lines above here), we only invert it if it is positive.
110+
degs = -degs;
111+
}
112+
113+
LOG(DEBUG_MEADE, "[LONGITUDE] Inverted Degs, now %l, Mins is %l", degs, mins);
114+
115+
return formatStringImpl(targetBuffer, "{+}{d}*{m}", '\0', degs, mins, secs);
116+
}

src/Longitude.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Longitude : public DayTime
1414
Longitude(float inDegrees);
1515

1616
virtual const char *formatString(char *targetBuffer, const char *format, long *pSeconds = nullptr) const;
17+
const char *formatStringForMeade(char *targetBuffer) const;
1718
virtual const char *ToString() const;
1819

1920
static Longitude ParseFromMeade(String const &s);

src/MeadeCommandProcessor.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
157157
// Description:
158158
// Get Site Longitude
159159
// Returns:
160-
// "DDD*MM#"
160+
// "sDDD*MM#"
161161
// Parameters:
162-
// "DDD" is the longitude in degrees
163-
// "MM" the minutes
162+
// "s" is the sign of the longitude
163+
// "DDD" is the degrees
164+
// "MM" is the minutes
164165
// Remarks:
165-
// Longitudes are from 0 to 360 going WEST. so 179W is 359 and 179E is 1.
166+
// Note that this is the actual longitude, but east coordinates are negative (opposite of normal cartographic coordinates)
166167
//
167168
// :Gc#
168169
// Description:
@@ -172,12 +173,14 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
172173
//
173174
// :GG#
174175
// Description:
175-
// Get UTC offset time
176+
// Get offset to UTC time
176177
// Returns:
177178
// "sHH#"
178179
// Parameters:
179180
// "s" is the sign
180-
// "HH" are the number of hours that need to be added to local time to convert to UTC time
181+
// "HH" is the number of hours
182+
// Remarks
183+
// 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.
181184
//
182185
// :Ga#
183186
// Description:
@@ -330,7 +333,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
330333
// "DD" is the degree (90 or less)
331334
// "MM" is minutes
332335
//
333-
// :SgDDD*MM#
336+
// :SgsDDD*MM#
334337
// Description:
335338
// Set Site Longitude
336339
// Information:
@@ -339,10 +342,12 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
339342
// "1" if successfully set
340343
// "0" otherwise
341344
// Parameters:
342-
// "DDD" the nmber of degrees (0 to 360)
343-
// "MM" is minutes
345+
// "s" (optional) is the sign of the longitude (see Remarks)
346+
// "DDD" is the number of degrees
347+
// "MM" is the minutes
344348
// Remarks:
345-
// Longitudes are from 0 to 360 going WEST. so 179W is 359 and 179E is 1.
349+
// When a sign is provided, longitudes are interpreted as given, with zero at Greenwich but negative coordinates going east (opposite of normal cartographic coordinates)
350+
// 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.
346351
//
347352
// :SGsHH#
348353
// Description:
@@ -375,7 +380,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
375380
// Returns:
376381
// "1Updating Planetary Data# #"
377382
// Parameters:
378-
// "HHMM" is the month
383+
// "MM" is the month
379384
// "DD" is the day
380385
// "YY" is the year since 2000
381386
//
@@ -1130,8 +1135,8 @@ String MeadeCommandProcessor::handleMeadeGetInfo(String inCmd)
11301135
}
11311136
case 'g': // :Gg
11321137
{
1133-
_mount->longitude().formatString(achBuffer, "{d}*{m}#");
1134-
return String(achBuffer);
1138+
_mount->longitude().formatStringForMeade(achBuffer);
1139+
return String(achBuffer) + "#";
11351140
}
11361141
case 'c': // :Gc
11371142
{
@@ -1140,7 +1145,7 @@ String MeadeCommandProcessor::handleMeadeGetInfo(String inCmd)
11401145
case 'G': // :GG
11411146
{
11421147
int offset = _mount->getLocalUtcOffset();
1143-
sprintf(achBuffer, "%+03d#", offset);
1148+
sprintf(achBuffer, "%+03d#", -offset);
11441149
return String(achBuffer);
11451150
}
11461151
case 'a': // :Ga
@@ -1329,17 +1334,16 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd)
13291334
_mount->setLatitude(lat);
13301335
return "1";
13311336
}
1332-
else if (inCmd[0] == 'g') // longitude :Sg097*34#
1337+
else if (inCmd[0] == 'g') // longitude :Sg097*34# or :Sg-122*54#
13331338
{
13341339
Longitude lon = Longitude::ParseFromMeade(inCmd.substring(1));
1335-
13361340
_mount->setLongitude(lon);
13371341
return "1";
13381342
}
13391343
else if (inCmd[0] == 'G') // utc offset :SG+05#
13401344
{
13411345
int offset = inCmd.substring(1, 4).toInt();
1342-
_mount->setLocalUtcOffset(offset);
1346+
_mount->setLocalUtcOffset(-offset);
13431347
return "1";
13441348
}
13451349
else if (inCmd[0] == 'L') // Local time :SL19:33:03#

src/WifiControl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ void WifiControl::tcpLoop()
182182
{
183183
client.read();
184184
LOG(DEBUG_WIFI, "[WIFITCP]: Query <-- Handshake request");
185-
client.write("1");
186-
LOG(DEBUG_WIFI, "[WIFITCP]: Reply --> 1");
185+
client.write("P");
186+
LOG(DEBUG_WIFI, "[WIFITCP]: Reply --> P (polar mode)");
187187
}
188188
else
189189
{

src/f_serial.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ void processSerialData()
4242
{
4343
if (buffer[0] == 0x06)
4444
{
45-
LOG(DEBUG_SERIAL, "[SERIAL]: Received: ACK request, replying 1");
45+
LOG(DEBUG_SERIAL, "[SERIAL]: Received: ACK request, replying P");
4646
// When not debugging, print the result to the serial port .
4747
// When debugging, only print the result to Serial if we're on seperate ports.
4848
#if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1)
49-
Serial.print('1');
49+
Serial.print('P');
5050
#endif
5151
}
5252
else

0 commit comments

Comments
 (0)