def _upload_file(ev3_obj, path_str): handle = None needs_continue = False cmd = bytearray() cmd.append(CommandType.SYSTEM_COMMAND_REPLY) cmd.append(Command.BEGIN_UPLOAD) message.append_u16(cmd, MAX_REPLY_BYTES) message.append_str(cmd, path_str) reply = ev3_obj.send_message_for_reply(cmd, 0) if (reply[0] == ReplyType.SYSTEM_REPLY_ERROR): raise SystemCommandError('A command failed.') if (reply[1] != Command.BEGIN_UPLOAD): raise SystemCommandError('Sync error detected.') if (reply[2] == ReturnCode.UNKNOWN_ERROR): raise SystemCommandError('An error occurred.') data_size = message.parse_u32(reply, 3) handle = reply[7] result = reply[8:] return (result, handle, (reply[2] != ReturnCode.END_OF_FILE))
def _continue_upload_file(ev3_obj, handle): result = bytearray() cmd = bytearray() cmd.append(CommandType.SYSTEM_COMMAND_REPLY) cmd.append(Command.CONTINUE_UPLOAD) cmd.append(handle) message.append_u16(cmd, MAX_REPLY_BYTES) while (True): reply = ev3_obj.send_message_for_reply(cmd, 1) if (reply[0] == ReplyType.SYSTEM_REPLY_ERROR): raise SystemCommandError('A command failed.') if (reply[1] != Command.CONTINUE_UPLOAD): raise SystemCommandError('Sync error detected.') if (reply[2] == ReturnCode.UNKNOWN_ERROR): raise SystemCommandError('An error occurred.') handle = reply[3] result.extend(reply[4:]) if (reply[2] == ReturnCode.END_OF_FILE): break return result
def _continue_list_files(ev3_obj, handle): result = bytearray() cmd = bytearray() cmd.append(CommandType.SYSTEM_COMMAND_REPLY) cmd.append(Command.CONTINUE_LIST_FILES) cmd.append(handle) message.append_u16(cmd, MAX_REPLY_BYTES) while (True): reply = ev3_obj.send_message_for_reply(cmd) if (reply[0] == ReplyType.SYSTEM_REPLY_ERROR): raise SystemCommandError('A command failed.') if (reply[1] != Command.CONTINUE_LIST_FILES): raise SystemCommandError('Sync error detected.') if (reply[2] == ReturnCode.UNKNOWN_ERROR): raise SystemCommandError('An error occurred.') handle = reply[3] result.extend(message.parse_str(reply, 4)) if (reply[2] == ReturnCode.END_OF_FILE): break return ''.join(result)
def write_mailbox(ev3_obj, mailbox_name_str, byte_seq): """Writes a sequence of bytes to the mailbox with the given name.""" if ('\0' != mailbox_name_str[-1]): mailbox_name_str += '\0' cmd = bytearray() cmd.append(CommandType.SYSTEM_COMMAND_NO_REPLY) cmd.append(Command.WRITEMAILBOX) message.append_u8(cmd, len(mailbox_name_str)) message.append_str(cmd, mailbox_name_str) message.append_u16(cmd, len(byte_seq)) cmd.extend(byte_seq) ev3_obj.send_message(cmd)