Example #1
0
def _upload_file(ev3_obj, path_str):
    handle = None
    needs_continue = False

    cmd = []
    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)

    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))
Example #2
0
def _continue_upload_file(ev3_obj, handle):
    result = []

    cmd = []
    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)

        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.append(reply[4:])

        if (reply[2] == ReturnCode.END_OF_FILE):
            break

    return itertools.chain.from_iterable(result)
Example #3
0
def _continue_list_files(ev3_obj, handle):
    result = []

    cmd = []
    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.append(message.parse_str(reply, 4))

        if (reply[2] == ReturnCode.END_OF_FILE):
            break

    return ''.join(result)
Example #4
0
def _continue_upload_file(ev3_obj, handle):
    result = []

    cmd = []
    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)

        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.append(reply[4:])

        if (reply[2] == ReturnCode.END_OF_FILE):
            break

    return itertools.chain.from_iterable(result)
Example #5
0
def _upload_file(ev3_obj, path_str):
    handle = None
    needs_continue = False

    cmd = []
    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)

    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))
Example #6
0
def _continue_list_files(ev3_obj, handle):
    result = []

    cmd = []
    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.append(message.parse_str(reply, 4))

        if (reply[2] == ReturnCode.END_OF_FILE):
            break

    return ''.join(result)
Example #7
0
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 = []
    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))
    map(cmd.append, byte_seq)

    ev3_obj.send_message(cmd)
Example #8
0
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 = []
    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))
    map(cmd.append, byte_seq)

    ev3_obj.send_message(cmd)