Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename _send_and_receive to _exchange #77

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/mcbootflash/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _read_version(connection: Connection) -> tuple[int, int, int, int, int]:
Write block size. When writing to flash, the number of bytes to be
written must align with a write block.
"""
read_version_response = _send_and_receive(
read_version_response = _exchange(
connection,
Command(CommandCode.READ_VERSION),
)
Expand Down Expand Up @@ -139,7 +139,7 @@ def _get_memory_address_range(connection: Connection) -> tuple[int, int]:
The returned tuple is suitable for use in `range`, i.e. the upper bound is not
part of the writable range.
"""
mem_range_response = _send_and_receive(
mem_range_response = _exchange(
connection,
Command(CommandCode.GET_MEMORY_ADDRESS_RANGE),
)
Expand Down Expand Up @@ -194,7 +194,7 @@ def erase_flash(
raise ValueError(msg)

_logger.debug(f"Erasing addresses {start:#08x}:{end:#08x}")
_send_and_receive(
_exchange(
connection,
command=Command(
command=CommandCode.ERASE_FLASH,
Expand All @@ -216,7 +216,7 @@ def write_flash(connection: Connection, chunk: Chunk) -> None:
Firmware chunk to write to bootloader.
"""
_logger.debug(f"Writing {len(chunk.data)} bytes to {chunk.address:#08x}")
_send_and_receive(
_exchange(
connection,
Command(
command=CommandCode.WRITE_FLASH,
Expand All @@ -242,7 +242,7 @@ def self_verify(connection: Connection) -> None:
If the bootloader cannot detect a bootable application in program
memory.
"""
_send_and_receive(connection, Command(command=CommandCode.SELF_VERIFY))
_exchange(connection, Command(command=CommandCode.SELF_VERIFY))


def checksum(
Expand Down Expand Up @@ -285,7 +285,7 @@ def checksum(


def _get_remote_checksum(connection: Connection, address: int, length: int) -> int:
checksum_response = _send_and_receive(
checksum_response = _exchange(
connection,
Command(
command=CommandCode.CALC_CHECKSUM,
Expand Down Expand Up @@ -315,7 +315,7 @@ def reset(connection: Connection) -> None:
connection : Connection
Connection to device in bootloader mode.
"""
_send_and_receive(connection, Command(command=CommandCode.RESET_DEVICE))
_exchange(connection, Command(command=CommandCode.RESET_DEVICE))
_logger.debug("Device reset")


Expand Down Expand Up @@ -387,7 +387,7 @@ def _get_response(connection: Connection, in_response_to: Command) -> ResponseBa
return response_type.from_bytes(bytes(response) + remainder)


def _send_and_receive(
def _exchange(
connection: Connection,
command: Command,
data: bytes = b"",
Expand Down