@@ -301,7 +301,7 @@ def start(self):
301
301
self .make_safe ()
302
302
print ('Finished initialising servo assembly on {}' .format (device ))
303
303
304
- def _command (self , * args ) -> List [str ]:
304
+ def _command (self , * args , generic_command = False ) -> List [str ]:
305
305
command_id = random .randint (1 , 65535 )
306
306
307
307
while True :
@@ -344,7 +344,7 @@ def _command(self, *args) -> List[str]:
344
344
return results
345
345
346
346
elif line .startswith (b'- ' ):
347
- if b'unknown command' in line :
347
+ if b'unknown command' in line and not generic_command :
348
348
break # try again
349
349
else :
350
350
raise CommandError (
@@ -362,6 +362,12 @@ def _command(self, *args) -> List[str]:
362
362
else :
363
363
raise InvalidResponse (args , line )
364
364
365
+ except InvalidResponse :
366
+ if generic_command :
367
+ raise
368
+ else :
369
+ break
370
+
365
371
except ValueError :
366
372
break
367
373
@@ -407,6 +413,19 @@ def _read_ultrasound(self, trigger_pin, echo_pin):
407
413
408
414
self ._ultrasound_value = list (sorted (found_values ))[1 ] / 1000.0
409
415
416
+ def _generic_command (self , command ):
417
+ try :
418
+ return {
419
+ 'status' : 'ok' ,
420
+ 'data' : self ._command (* command ),
421
+ }
422
+ except (CommandError , InvalidResponse ) as e :
423
+ return {
424
+ 'status' : 'error' ,
425
+ 'type' : type (e ).__name__ ,
426
+ 'description' : str (e ),
427
+ }
428
+
410
429
def status (self ):
411
430
return {
412
431
'servos' : self ._servo_status ,
@@ -449,6 +468,11 @@ def command(self, cmd):
449
468
if len (read_ultrasound ) == 2 :
450
469
self ._read_ultrasound (read_ultrasound [0 ], read_ultrasound [1 ])
451
470
471
+ # handle direct command access
472
+ command = cmd .get ('command' , [])
473
+ if command :
474
+ return self ._generic_command (command )
475
+
452
476
453
477
# Grab the full list of boards from the workings of the metaclass
454
478
BOARDS = BoardMeta .BOARDS
0 commit comments