Browse Source

CLI completion

master
Alex Mikhalev 6 years ago
parent
commit
dfcf050761
  1. 6
      tools/ugv.py
  2. 16
      tools/ugv_cmd.py

6
tools/ugv.py

@ -9,18 +9,18 @@ import time @@ -9,18 +9,18 @@ import time
import binascii
from base64 import b64decode, b64encode
from e32 import E32
import messages_pb2 as messages
from google.protobuf.message import Message
log = logging.getLogger("ugv")
class UGVComms(E32):
class UGVComms:
MAX_WRITE_RETRY = 5
RETRY_TIME = 3.0
def __init__(self, serial_port: serial.Serial):
E32.__init__(self, serial_port)
self.ser = serial_port
self.msg_acks = []
self.ack_cv = threading.Condition()
self.next_command_id = 1

16
tools/ugv_cmd.py

@ -55,6 +55,7 @@ class UGV_CLI: @@ -55,6 +55,7 @@ class UGV_CLI:
'get_status': self.get_status,
's': self.get_status,
}
self.ugv = None
pass
@cli_cmd(names=["help", "h", "?"], description="Print this help message")
@ -128,12 +129,21 @@ class UGV_CLI: @@ -128,12 +129,21 @@ class UGV_CLI:
log.info("last status (%.4f seconds ago): %s",
last_status_delay, self.ugv.last_status)
def find_command(self, name):
@staticmethod
def find_command(name):
for cmd in cli_commands:
if name in cmd.names:
return cmd
return None
@staticmethod
def complete_command(text, state):
options = [name for cmd in cli_commands for name in cmd.names if name.startswith(text)]
if state < len(options):
return options[state]
else:
return None
def start(self):
self.is_running = True
@ -144,6 +154,10 @@ class UGV_CLI: @@ -144,6 +154,10 @@ class UGV_CLI:
ser = serial.serial_for_url(ser_url, baudrate=9600, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS,
timeout=0.5)
readline.parse_and_bind("tab: complete")
readline.set_completer(self.complete_command)
self.ugv = UGVComms(ser)
self.ugv.start()
time.sleep(0.2)

Loading…
Cancel
Save