comm_generic: cleanup

This commit is contained in:
Sebastien Bourdeauducq 2015-08-07 21:12:00 +08:00
parent 54a568c510
commit be55487d2d
1 changed files with 9 additions and 10 deletions

View File

@ -108,10 +108,7 @@ class CommGeneric:
if ty != _D2HMsgType.IDENT_REPLY: if ty != _D2HMsgType.IDENT_REPLY:
raise IOError("Incorrect reply from device: {}".format(ty)) raise IOError("Incorrect reply from device: {}".format(ty))
(reply, ) = struct.unpack("B", self.read(1)) (reply, ) = struct.unpack("B", self.read(1))
runtime_id = chr(reply) runtime_id = self.read(4).decode()
for i in range(3):
(reply, ) = struct.unpack("B", self.read(1))
runtime_id += chr(reply)
if runtime_id != "AROR": if runtime_id != "AROR":
raise UnsupportedDevice("Unsupported runtime ID: {}" raise UnsupportedDevice("Unsupported runtime ID: {}"
.format(runtime_id)) .format(runtime_id))
@ -238,9 +235,11 @@ class CommGeneric:
length, ty = self._read_header() length, ty = self._read_header()
if ty != _D2HMsgType.LOG_REPLY: if ty != _D2HMsgType.LOG_REPLY:
raise IOError("Incorrect request from device: "+str(ty)) raise IOError("Incorrect request from device: "+str(ty))
r = "" log = self.read(length - 9).decode()
for i in range(length - 9): try:
c = struct.unpack("B", self.read(1))[0] idx = log.index("\x00")
if c: except ValueError:
r += chr(c) pass
return r else:
log = log[:idx]
return log