Skip to content

Commit

Permalink
removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
apatrushev committed Aug 29, 2023
1 parent 3bbed85 commit 9027e48
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/pyflipper/lib/serial_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,23 @@ def __init__(self, addr) -> None:
port = int(port)
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.connect((host, port))
buff = ''
while True:
buff += self._socket.recv(1024).decode()
if '>:' in buff:
break
self._read_response()

@error_handler
def send(self, payload: str) -> str:
self._socket.sendall(f"{payload}\r".encode())
buff = ''
while True:
buff += self._socket.recv(1024).decode()
if '>:' in buff:
break
return '\n'.join(buff.splitlines()[1:-2])
return self._read_response()

def write(self, msg):
self._socket.sendall(msg)

def ctrl_c(self):
self._socket.sendall(b'\x03')

def _read_response(self):
buff = ''
while True:
buff += self._socket.recv(1024).decode()
if '>:' in buff:
break
return '\n'.join(buff.splitlines()[1:-2])

0 comments on commit 9027e48

Please sign in to comment.