Skip to content

Commit

Permalink
[otci] fix command issue after factoryreset (openthread#6670)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlingoogle authored Jun 25, 2021
1 parent d360c4b commit 98d9b45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 8 additions & 1 deletion tools/otci/otci/command_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def __repr__(self):
def execute_command(self, cmd, timeout=10) -> List[str]:
self.__otcli.writeline(cmd)

if cmd in {'reset', 'factoryreset'}:
if cmd in ('reset', 'factoryreset'):
self.wait(3)
self.__otcli.writeline('extaddr')
self.wait(1)
return []

if self.__expect_command_echoback:
Expand Down Expand Up @@ -210,6 +213,10 @@ def execute_command(self, cmd: str, timeout: float) -> List[str]:
raise CommandError(cmd, [err])

output = [l.rstrip('\r\n') for l in cmd_out.readlines()]

if cmd in ('reset', 'factoryreset'):
self.wait(3)

return output

def close(self):
Expand Down
8 changes: 0 additions & 8 deletions tools/otci/otci/otci.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import ipaddress
import logging
import re
import time
from collections import Counter
from typing import List, Collection, Union, Tuple, Optional, Dict, Pattern, Any

Expand Down Expand Up @@ -105,7 +104,6 @@ def execute_command(self, cmd: str, timeout: float = 10, silent: bool = False) -
self.__logger and self.__logger.info('%s', line)

if cmd in ('reset', 'factoryreset'):
self.__wait_reset()
return output

if output[-1] == 'Done':
Expand Down Expand Up @@ -2335,12 +2333,6 @@ def __escape_escapable(self, s: str) -> str:
s = s.replace(char, '\\%s' % char)
return s

def __wait_reset(self):
# reset would restart the otbr-agent executable. It's risky to send commands after reset too quickly because
# it might cause ot-ctl to quit abnormally.
# So we sleep for a while after reset.
time.sleep(3)

def __txt_to_hex(self, txt: Dict[str, Union[str, bytes, bool]]) -> str:
txt_bin = b''
for k, v in txt.items():
Expand Down

0 comments on commit 98d9b45

Please sign in to comment.