@@ -16,7 +16,6 @@ void processSerialData();
1616// The main loop when under serial control
1717void serialLoop ()
1818{
19- // Serial.print('.');
2019 mount.loop ();
2120 mount.displayStepperPositionThrottled ();
2221
@@ -126,36 +125,33 @@ void processSerialData()
126125 #endif
127126 index = 0 ;
128127 }
129- else
128+ else if (buffer[index] == ' # ' )
130129 {
131- if (buffer[index] == ' #' )
132- {
133- // Ignoring trailing hash
134- buffer[index] = 0 ;
135- String inCmd = String (buffer);
136- LOG (DEBUG_SERIAL, " [SERIAL]: ReceivedCommand(%d chars): [%s]" , inCmd.length (), inCmd.c_str ());
130+ // Ignoring trailing hash
131+ buffer[index] = ' \0 ' ;
132+ const String inCmd = String (buffer);
133+ LOG (DEBUG_SERIAL, " [SERIAL]: ReceivedCommand(%d chars): [%s]" , inCmd.length (), inCmd.c_str ());
137134
138- String retVal = MeadeCommandProcessor::instance ()->processCommand (inCmd);
139- if (retVal != " " )
140- {
141- LOG (DEBUG_SERIAL, " [SERIAL]: RepliedWith: [%s]" , retVal.c_str ());
142- // When not debugging, print the result to the serial port .
143- // When debugging, only print the result to Serial if we're on seperate ports.
135+ const String retVal = MeadeCommandProcessor::instance ()->processCommand (inCmd);
136+ if (retVal != " " )
137+ {
138+ LOG (DEBUG_SERIAL, " [SERIAL]: RepliedWith: [%s]" , retVal.c_str ());
139+ // When not debugging, print the result to the serial port .
140+ // When debugging, only print the result to Serial if we're on seperate ports.
144141 #if (DEBUG_LEVEL == DEBUG_NONE) || (DEBUG_SEPARATE_SERIAL == 1)
145- Serial.print (retVal);
142+ Serial.print (retVal);
146143 #endif
147- }
148- // Wait for next command
149- index = 0 ;
150144 }
151- else if (buffer[index] > 31 )
145+ // Wait for next command
146+ index = 0 ;
147+ }
148+ else if (buffer[index] >= ' ' )
149+ {
150+ index++;
151+ if (index >= sizeof (buffer))
152152 {
153- index++;
154- if (index >= sizeof (buffer))
155- {
156- LOG (DEBUG_SERIAL, " [SERIAL]: Command buffer overflow! Ignoring received data." );
157- index = 0 ;
158- }
153+ LOG (DEBUG_SERIAL, " [SERIAL]: Command buffer overflow! Ignoring received data." );
154+ index = 0 ;
159155 }
160156 }
161157 }
0 commit comments