Skip to content

Commit

Permalink
Use new dpdumperlib to load file into memory
Browse files Browse the repository at this point in the history
  • Loading branch information
hkzlab committed Aug 22, 2024
1 parent 2a63da9 commit 14f9966
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Changelog
Changelog for the dpdumper utility

## [0.3.3] - 2024-08-22
### Changed
- Depends on dpdumperlib 0.0.2

## [0.3.2] - 2024-08-21
## Added
### Added
- Flag to output the Hi-Z mask of every read in binary format

## Changed
### Changed
- Use upside-down floor division to calculate number of bytes for data entriess and addresses
- Tool description in argsparse

## [0.3.1] - 2024-08-19
## Changed
### Changed
- Depends on dupicolib 0.4.2
- Split out some code in dpdumperlib, now depends on version 0.0.1

## Removed
### Removed
- Example definitions are now moved in the dpdumperlib repo

## [0.3.0] - 2024-08-12
## Changed
### Changed
- Depends on dupicolib 0.4.0

## [0.2.1] - 2024-08-12
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "dpdumper"
version = "0.3.2"
version = "0.3.3"
description = "Tool to use the dupico as a dumping device"
authors = [
{ name = "Fabio Battaglia", email = "hkzlabnet@gmail.com" }
Expand All @@ -19,7 +19,7 @@ requires-python = ">=3.12"
dependencies = [
"pyserial ~= 3.5",
"dupicolib >= 0.4.2",
"dpdumperlib >= 0.0.1"
"dpdumperlib >= 0.0.2"
]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyserial>=3.5
dupicolib>=0.4.2
dpdumperlib>=0.0.1
dpdumperlib>=0.0.2
4 changes: 3 additions & 1 deletion src/dpdumper/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from dpdumperlib.ic.ic_loader import ICLoader
from dpdumperlib.ic.ic_definition import ICDefinition
import dpdumperlib.io.file_utils as FileUtils

from dpdumper import __name__, __version__
from dpdumper.dumper_utilities import DumperUtilities
Expand Down Expand Up @@ -179,7 +180,8 @@ def write_command(ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic
if not skip_note and ic_definition.adapter_notes and bool(ic_definition.adapter_notes.strip()):
print_note(ic_definition.adapter_notes)

data_list: list[int] = OutFileUtilities.build_data_list_from_file(inf, ic_definition)
bytes_per_entry: int = -(len(ic_definition.data) // -8)
data_list: list[int] = FileUtils.load_file_data(inf, bytes_per_entry)

start_time: float = time.time()
HLBoardUtilities.write_ic(ser, cmd_class, ic_definition, data_list)
Expand Down
6 changes: 3 additions & 3 deletions src/dpdumper/hl_board_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def read_ic(cls, ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic:

@staticmethod
def write_ic(ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic: ICDefinition, data: list[int]) -> None:
data_width: int = int(math.ceil(len(ic.data) / 8.0))
data_width: int = -(len(ic.data) // -8)
addr_combs: int = 1 << len(ic.address) # Calculate the number of addresses that this IC supports
_LOGGER.debug(f'write_ic command with definition {ic.name}, IC has {addr_combs} addresses and data width {data_width} bits.')

# Check that we have enough data (or not too much) to write
if addr_combs != len(data):
raise ValueError(f'IC definition supports {addr_combs} addresses, but input array has {len(data)}')
if (d_len := len(data)) != addr_combs:
raise ValueError(f'IC definition supports {addr_combs} addresses, but input array has {d_len}')

hi_pins_mapped: int = cmd_class.map_value_to_pins(ic.adapter_hi_pins, 0xFFFFFFFFFFFFFFFF)

Expand Down
15 changes: 0 additions & 15 deletions src/dpdumper/outfile_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ def _bits_iterator(n: int) -> Generator[int, None, None]:
yield b
n ^= b

def build_data_list_from_file(inf: str, ic: ICDefinition) -> list[int]:
data_list: list[int] = []
in_content: bytes
with open(inf, 'rb') as f:
in_content = f.read()

data_width: int = len(ic.data)
# Use upside-down floor division: https://stackoverflow.com/questions/14822184/is-there-a-ceiling-equivalent-of-operator-in-python
bytes_per_entry = -(data_width // -8)

for block in grouped_iterator(in_content, bytes_per_entry):
data_list.append(int.from_bytes(block, byteorder='big', signed=False))

return data_list

def build_binary_array(ic: ICDefinition, elements: list[DataElement], hiz_high: bool = False) -> tuple[bytearray, bytearray, str]:
"""Builds a binary array out of data read from the IC, and returns it plus the SHA1SUM of the data
Expand Down

0 comments on commit 14f9966

Please sign in to comment.