@@ -228,12 +228,26 @@ void Commander::executeCommand( char *cmd ){
228
228
// Pointer to the selected command data.
229
229
API_t *commandData_ptr;
230
230
231
+ int32_t pipePos;
232
+
231
233
// Copy the command data to the internal buffer.
232
234
// It is necessary because we have to modify the content
233
235
// of it. If it is points to a const char array we will
234
236
// get a bus-fault error without a buffer.
235
237
strncpy ( tempBuff, cmd, COMMANDER_MAX_COMMAND_SIZE );
236
238
239
+ // Remove whitespaces at the beginning.
240
+ while ( *tempBuff = ' ' ){
241
+ tempBuff++;
242
+ }
243
+
244
+ pipePos = hasChar ( tempBuff, ' |' );
245
+
246
+ if ( pipePos > 0 ){
247
+
248
+ tempBuff[ pipePos ] = ' \0 ' ;
249
+
250
+ }
237
251
238
252
// tempBuff is the address of the first character of the incoming command.
239
253
// If we give arg variable the value stored in tempBuff means arg will point to
@@ -272,6 +286,13 @@ void Commander::executeCommand( char *cmd ){
272
286
273
287
}
274
288
289
+ else if ( *arg == ' |' ){
290
+
291
+ *arg = ' \0 ' ;
292
+ arg++;
293
+
294
+ }
295
+
275
296
// Try to find the command datata.
276
297
commandData_ptr = (*this )[ tempBuff ];
277
298
@@ -289,12 +310,37 @@ void Commander::executeCommand( char *cmd ){
289
310
290
311
}
291
312
313
+ // Example: random 0 180 | setServo
314
+
292
315
// If show_description flag is not set, than we have to execute the commands function.
293
316
else {
294
317
318
+ if ( pipePos > 0 ){
319
+
320
+ // TODO Switch response to pipe response.
321
+ response = &pipeResponse;
322
+
323
+ }
324
+
325
+ // TODO if the internal buffer has data, the arg has to be replaced with that.
326
+ if ( pipeResponse.available () ){
327
+
328
+ arg = pipeResponse.getData ();
329
+
330
+ }
331
+
295
332
// Execute commands function.
296
333
(commandData_ptr -> func)( arg, response );
297
334
335
+ pipeResponse.flush ();
336
+
337
+ // TODO recursive function call.
338
+ if ( pipePos > 0 ){
339
+
340
+ executeCommand ( cmd + pipePos );
341
+
342
+ }
343
+
298
344
}
299
345
300
346
}
@@ -621,3 +667,23 @@ void Commander::helpFunction( bool description ){
621
667
}
622
668
623
669
}
670
+
671
+ int32_t Commander::hasChar ( char * str, char c ){
672
+
673
+ int32_t cntr = 0 ;
674
+
675
+ while ( str[ cntr ] ){
676
+
677
+ if ( str[ cntr ] == c ){
678
+
679
+ return cntr;
680
+
681
+ }
682
+
683
+ cntr++;
684
+
685
+ }
686
+
687
+ return -1 ;
688
+
689
+ }
0 commit comments