Skip to content

Commit 490e5fd

Browse files
V1.7.25.Az - Updates
- Added ring buffer for collecting logs via Serial. Unfortunately, memory constraints make this less useful, we need to reduce the overall number of debug spew statements
1 parent 92f58df commit 490e5fd

File tree

4 files changed

+105
-18
lines changed

4 files changed

+105
-18
lines changed

Software/Arduino code/OpenAstroTracker/Globals.hpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define DEC_Stepper_TYPE 0 // 28BYJ-48 = 0 | NEMA = 1
1616

1717
// Are we supporting the Azimuth PA motor?
18-
#define AZIMUTH_MOTOR 1
18+
#define AZIMUTH_MOTOR 0
1919

2020
// Make some variables in the sketch files available to the C++ code.
2121
extern bool inSerialControl;
@@ -30,6 +30,14 @@ extern float DECStepsPerRevolution;
3030
extern int DecPulleyTeeth;
3131

3232
// Debugging output control
33+
// Debug log output is tricky, since if we simply send it out via Serial and a client is connected via Serial (USB),
34+
// the debug spew will interfere the protocol and confuse the client. To still be able to get access to debug logs in
35+
// this scenario, you can collect the debug logs in a memory ring buffer instead of sending them to Serial by
36+
// enabling the setting below
37+
// Use the Meade extension command :XGO# to retrieve the logs
38+
#define BUFFER_LOGS 0
39+
40+
// The level of debugging spew is controlled by setting DEBUG_LEVEL to a combination of the bit flags below.
3341
// Each bit in the debug level specifies a kind of debug to enable.
3442
#define DEBUG_NONE 0x00
3543
#define DEBUG_INFO 0x01
@@ -50,16 +58,15 @@ extern int DecPulleyTeeth;
5058
// 4 DEBUG_MOUNT_VERBOSE Verbose mount processing (coordinates, etc)
5159
// 5 DEBUG_GENERAL Other misc. output
5260
// 6 DEBUG_MEADE Meade command handling output
61+
// 7 DEBUG_VERBOSE other verbose debug output
62+
// 7 DEBUG_ANY all debug output
5363

54-
// Set this to specify the amount of debug output OAT should send to the serial port.
55-
// Note that if you use an app to control OAT, ANY debug output will likely confuse that app.
56-
// Debug output is useful if you are using Wifi to control the OAT or if you are issuing
57-
// manual commands via a terminal.
58-
//
64+
// Set this to specify the amount of debug output OAT should generate.
5965
// #define DEBUG_LEVEL (DEBUG_SERIAL|DEBUG_WIFI|DEBUG_INFO|DEBUG_MOUNT|DEBUG_GENERAL)
6066
// #define DEBUG_LEVEL (DEBUG_ANY)
6167
// #define DEBUG_LEVEL (DEBUG_INFO|DEBUG_MOUNT|DEBUG_GENERAL)
6268
// #define DEBUG_LEVEL (DEBUG_WIFI|DEBUG_MEADE|DEBUG_INFO|DEBUG_GENERAL)
69+
// #define DEBUG_LEVEL (DEBUG_MEADE|DEBUG_INFO|DEBUG_GENERAL)
6370
#define DEBUG_LEVEL (DEBUG_NONE)
6471

6572
// Set this to 1 to run a key diagnostic. No tracker functions are on at all.

Software/Arduino code/OpenAstroTracker/MeadeCommandProcessor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) {
752752
else if (inCmd[1] == 'M') {
753753
return String(_mount->getMountHardwareInfo()) + "#";
754754
}
755+
else if (inCmd[1] == 'O') {
756+
return getLogBuffer();
757+
}
755758
else if (inCmd[1] == 'H') {
756759
char scratchBuffer[10];
757760
sprintf(scratchBuffer, "%02d%02d%02d#", _mount->HA().getHours(), _mount->HA().getMinutes(), _mount->HA().getSeconds());

Software/Arduino code/OpenAstroTracker/Utility.cpp

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,86 @@ unsigned long RealTime::_suspendStart = 0;
1212
int RealTime::_suspended = 0;
1313
#endif
1414

15+
#if BUFFER_LOGS
16+
#define LOG_BUFFER_SIZE 512
17+
char logBuffer[LOG_BUFFER_SIZE];
18+
int bufferWritePos = 0;
19+
int bufferStartPos = 0;
20+
21+
int scanForNextNewLine(int bufPos) {
22+
for (int i = bufPos; i < LOG_BUFFER_SIZE; i++) {
23+
if (logBuffer[i] == '\n') {
24+
return i;
25+
}
26+
}
27+
28+
for (int i = 0; i < LOG_BUFFER_SIZE; i++) {
29+
if (logBuffer[i] == '\n') {
30+
return i;
31+
}
32+
}
33+
// WTF?
34+
return 0;
35+
}
36+
37+
void addToLogBuffer(String s) {
38+
s += '\n';
39+
int charsToWrite = s.length();
40+
if (bufferWritePos + charsToWrite > LOG_BUFFER_SIZE) {
41+
int charsToWriteAtEndOfBuffer = LOG_BUFFER_SIZE - bufferWritePos;
42+
memcpy(logBuffer + bufferWritePos, s.c_str(), charsToWriteAtEndOfBuffer);
43+
charsToWrite -= charsToWriteAtEndOfBuffer;
44+
memcpy(logBuffer, s.c_str() + charsToWriteAtEndOfBuffer, charsToWrite);
45+
bufferWritePos = charsToWrite;
46+
logBuffer[bufferWritePos] = '\0';
47+
bufferStartPos = scanForNextNewLine(bufferWritePos);
48+
}
49+
else {
50+
memcpy(logBuffer + bufferWritePos, s.c_str(), charsToWrite);
51+
if (bufferStartPos > bufferWritePos) {
52+
bufferWritePos += charsToWrite;
53+
bufferStartPos = scanForNextNewLine(bufferWritePos);
54+
}
55+
else {
56+
bufferWritePos += charsToWrite;
57+
}
58+
}
59+
}
60+
61+
class MyString : public String {
62+
public:
63+
void setLen(unsigned int newLen) { len = newLen ; }
64+
};
65+
66+
String getLogBuffer() {
67+
MyString result;
68+
unsigned int len = (bufferStartPos > bufferWritePos) ? LOG_BUFFER_SIZE - bufferStartPos : 0;
69+
len += bufferWritePos;
70+
result.reserve(len + 2);
71+
char* buffer = result.begin();
72+
73+
if (bufferStartPos > bufferWritePos) {
74+
for (int i = bufferStartPos;i < LOG_BUFFER_SIZE; i++)
75+
{
76+
*buffer++ = (logBuffer[i] == '#') ? '%' : logBuffer[i];
77+
}
78+
}
79+
80+
for (int i = 0; i < bufferWritePos; i++)
81+
{
82+
*buffer++ = (logBuffer[i] == '#') ? '%' : logBuffer[i];
83+
}
84+
85+
*buffer++ = '#';
86+
*buffer = '\0';
87+
result.setLen(buffer - result.begin());
88+
return result;
89+
}
90+
#else
91+
String getLogBuffer() {
92+
return "Debugging disabled.#";
93+
}
94+
#endif
1595

1696
// Adjust the given number by the given adjustment, wrap around the limits.
1797
// Limits are inclusive, so they represent the lowest and highest valid number.
@@ -174,24 +254,18 @@ String format(const char *input, ...)
174254
return ret;
175255
}
176256

177-
// void log(const char* input) {
178-
// Serial.println(input);
179-
// Serial.flush();
180-
// }
181-
182-
// void log(String input) {
183-
// Serial.println(input);
184-
// Serial.flush();
185-
// }
186-
187257
void logv(int levelFlags, const char *input, ...)
188258
{
189259
if ((levelFlags & DEBUG_LEVEL) != 0)
190260
{
191261
va_list argp;
192262
va_start(argp, input);
193-
Serial.println(formatArg(input, argp));
194-
Serial.flush();
263+
#if BUFFER_LOGS
264+
addToLogBuffer(formatArg(input, argp));
265+
#else
266+
Serial.println(formatArg(input, argp));
267+
Serial.flush();
268+
#endif
195269
va_end(argp);
196270
}
197271
}

Software/Arduino code/OpenAstroTracker/Utility.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
#define btnSELECT 4
1313
#define btnNONE 5
1414

15+
String getLogBuffer();
16+
1517
#if DEBUG_LEVEL>0
1618

19+
1720
#define LOGV1(level,a) logv((level),(a))
1821
#define LOGV2(level,a,b) logv((level),(a),(b))
1922
#define LOGV3(level,a,b,c) logv((level),(a),(b),(c))

0 commit comments

Comments
 (0)