devices/corecom_serial: unpack unsigned chars

This commit is contained in:
Sebastien Bourdeauducq 2014-09-22 13:23:39 +08:00
parent 19abab3feb
commit bad87ef38b
1 changed files with 6 additions and 6 deletions

View File

@ -88,7 +88,7 @@ class CoreCom:
# Ignore them with a warning for now. # Ignore them with a warning for now.
spurious_zero_count = 0 spurious_zero_count = 0
while True: while True:
(reply, ) = struct.unpack("b", _read_exactly(self.port, 1)) (reply, ) = struct.unpack("B", _read_exactly(self.port, 1))
if reply == 0: if reply == 0:
spurious_zero_count += 1 spurious_zero_count += 1
else: else:
@ -101,7 +101,7 @@ class CoreCom:
(length, ) = struct.unpack(">h", _read_exactly(self.port, 2)) (length, ) = struct.unpack(">h", _read_exactly(self.port, 2))
log_message = "" log_message = ""
for i in range(length): for i in range(length):
(c, ) = struct.unpack("b", _read_exactly(self.port, 1)) (c, ) = struct.unpack("B", _read_exactly(self.port, 1))
log_message += chr(c) log_message += chr(c)
logger.info("DEVICE LOG: " + log_message) logger.info("DEVICE LOG: " + log_message)
else: else:
@ -114,10 +114,10 @@ class CoreCom:
msg = self._get_device_msg() msg = self._get_device_msg()
if msg != _D2HMsgType.IDENT: if msg != _D2HMsgType.IDENT:
raise IOError("Incorrect reply from device: "+str(msg)) raise IOError("Incorrect reply from device: "+str(msg))
(reply, ) = struct.unpack("b", _read_exactly(self.port, 1)) (reply, ) = struct.unpack("B", _read_exactly(self.port, 1))
runtime_id = chr(reply) runtime_id = chr(reply)
for i in range(3): for i in range(3):
(reply, ) = struct.unpack("b", _read_exactly(self.port, 1)) (reply, ) = struct.unpack("B", _read_exactly(self.port, 1))
runtime_id += chr(reply) runtime_id += chr(reply)
if runtime_id != "AROR": if runtime_id != "AROR":
raise UnsupportedDevice("Unsupported runtime ID: "+runtime_id) raise UnsupportedDevice("Unsupported runtime ID: "+runtime_id)
@ -139,14 +139,14 @@ class CoreCom:
_write_exactly(self.port, struct.pack( _write_exactly(self.port, struct.pack(
">lbl", 0x5a5a5a5a, _H2DMsgType.RUN_KERNEL.value, len(kname))) ">lbl", 0x5a5a5a5a, _H2DMsgType.RUN_KERNEL.value, len(kname)))
for c in kname: for c in kname:
_write_exactly(self.port, struct.pack("b", ord(c))) _write_exactly(self.port, struct.pack("B", ord(c)))
logger.debug("running kernel: {}".format(kname)) logger.debug("running kernel: {}".format(kname))
def serve(self, rpc_map, exception_map): def serve(self, rpc_map, exception_map):
while True: while True:
msg = self._get_device_msg() msg = self._get_device_msg()
if msg == _D2HMsgType.RPC_REQUEST: if msg == _D2HMsgType.RPC_REQUEST:
rpc_num, n_args = struct.unpack(">hb", rpc_num, n_args = struct.unpack(">hB",
_read_exactly(self.port, 3)) _read_exactly(self.port, 3))
args = [] args = []
for i in range(n_args): for i in range(n_args):