Skip to content

Commit

Permalink
Added Microchip SQTP file format
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <texzk@email.it>
  • Loading branch information
TexZK committed Feb 17, 2024
1 parent 9c8a344 commit aa9b15d
Show file tree
Hide file tree
Showing 21 changed files with 1,095 additions and 51 deletions.
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.formats.sqtp.from_numbers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from\_numbers
=============

.. currentmodule:: hexrec.formats.sqtp

.. autofunction:: from_numbers
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.formats.sqtp.from_strings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from\_strings
=============

.. currentmodule:: hexrec.formats.sqtp

.. autofunction:: from_strings
41 changes: 41 additions & 0 deletions docs/_autosummary/hexrec.formats.sqtp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
sqtp
====

.. automodule:: hexrec.formats.sqtp









.. rubric:: Functions

.. autosummary::
:toctree:
:template: custom-base-template.rst
:nosignatures:

from_numbers
from_strings
to_numbers
to_strings

















6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.formats.sqtp.to_numbers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
to\_numbers
===========

.. currentmodule:: hexrec.formats.sqtp

.. autofunction:: to_numbers
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.formats.sqtp.to_strings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
to\_strings
===========

.. currentmodule:: hexrec.formats.sqtp

.. autofunction:: to_strings
1 change: 1 addition & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Reference
hexrec.formats.ihex
hexrec.formats.mos
hexrec.formats.raw
hexrec.formats.sqtp
hexrec.formats.srec
hexrec.formats.titxt
hexrec.formats.xtek
Expand Down
15 changes: 12 additions & 3 deletions src/hexrec/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
r""" Base types and classes."""

import abc
import io
import os
import sys
from typing import IO
Expand Down Expand Up @@ -3211,7 +3212,7 @@ def merge(self, *files: 'BaseFile', clear: bool = False) -> Self:
@classmethod
def parse(
cls,
stream: IO,
stream: Union[AnyBytes, IO],
ignore_errors: bool = False,
ignore_after_termination: bool = True,
) -> Self:
Expand All @@ -3228,8 +3229,8 @@ def parse(
*format*, because it may be more specialized.
Args:
stream (bytes IO):
Stream to serialize records onto.
stream (bytes IO or buffer):
Stream or byte buffer to parse records from.
ignore_errors (bool):
Ignore :class:`Exception` raised by :meth:`BaseRecord.parse`.
Expand Down Expand Up @@ -3265,8 +3266,16 @@ def parse(
[[55930, b'abc']]
>>> file.get_meta()
{'linear': True, 'maxdatalen': 3, 'startaddr': 51966}
>>> file = IhexFile.parse(buffer)
>>> file.memory.to_blocks()
[[55930, b'abc']]
>>> file.get_meta()
{'linear': True, 'maxdatalen': 3, 'startaddr': 51966}
"""

if isinstance(stream, (bytes, bytearray, memoryview)):
stream = io.BytesIO(stream)

Record = cls.Record
records = []
row = 0
Expand Down
21 changes: 15 additions & 6 deletions src/hexrec/formats/ihex.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,15 @@ def validate(

if tag.is_data():
pass

elif tag.is_start():
if data_size != 4:
raise ValueError('start address data size overflow')

elif tag.is_extension():
if data_size != 2:
raise ValueError('extension data size overflow')

else: # elif tag.is_eof():
if data_size:
raise ValueError('unexpected data')
Expand All @@ -449,17 +452,23 @@ class IhexFile(BaseFile):

FILE_EXT: Sequence[str] = [
# https://en.wikipedia.org/wiki/Intel_HEX
# General - purpose:
# General purpose:
'.hex', '.mcs', '.int', '.ihex', '.ihe', '.ihx',
# Platform-specific:
# '.h80', '.h86', '.a43', '.a90', # (currently unsupported)
# Platform specific:
'.h80', '.h86', '.a43', '.a90',
# Split, banked, or paged:
# '.hxl', '.hxh', '.h00', '.h15', '.p00', '.pff' # (currently unsupported)
# '.hxl', '.hxh', '.h00', '.h15', '.p00', '.pff', (currently unsupported)
# Binary or Intel hex:
# '.obj', '.obl', '.obh', '.rom', '.eep' # (currently unsupported)
'.obj', '.obl', '.obh', '.rom', '.eep',
# Microchip SQTP:
'.num',
]

META_KEYS: Sequence[str] = ['linear', 'maxdatalen', 'startaddr']
META_KEYS: Sequence[str] = [
'linear',
'maxdatalen',
'startaddr',
]

Record: Type[IhexRecord] = IhexRecord

Expand Down
Loading

0 comments on commit aa9b15d

Please sign in to comment.