to_numbers#

hexrec.formats.sqtp.to_numbers(file, retlw=False, byteorder='little')[source]#

Extracts numbers from a file.

Given a Microchip SQTP file (as special Intel HEX format), it extracts numbers from data records.

Warning

This algorithm ignores addressing. It just takes data records and converts them into numbers. Please provide valid Microchip SQTP files only.

Parameters:
  • file (IhexFile) – Microchip SQTP file as special Intel HEX format.

  • retlw (bool) – The RETLW byte is put after each byte of the byte string. If true, it ignores the RETLW bytes.

  • byteorder (str) – By default, Microchip SQTP uses little endian. Provide big for the alternative integer byte order.

Returns:

list of int – Sequence of serial numbers.

Examples

https://developerhelp.microchip.com/xwiki/bin/view/software-tools/ipe/sqtp-file-format-specification/examples/.

>>> from hexrec import IhexFile
>>> from hexrec.formats.sqtp import to_numbers
>>> # Program Memory - PIC18F1220
>>> file = IhexFile.parse(b'''
...     :04000000000C000CE4
...     :04000000010C000CE3
...     :04000000020C000CE2
...     :04000000030C000CE1
...     :04000000040C000CE0
...     :00000001FF
... ''')
>>> to_numbers(file, retlw=True)
[0, 1, 2, 3, 4]
>>> # Program Memory - PIC32MX360F512L
>>> file = IhexFile.parse(b'''
...     :02000004740086
...     :0400000000000000FC
...     :0400000001000000FB
...     :0400000002000000FA
...     :0400000003000000F9
...     :0400000004000000F8
...     :00000001FF
... ''')
>>> to_numbers(file)
[0, 1, 2, 3, 4]
>>> # User ID - PIC12F1501 (with correct checksums)
>>> file = IhexFile.parse(b'''
...     :020000040001F9
...     :040000007E34CF3447
...     :040000009034C5343F
...     :040000000B34113478
...     :04000000F234F334AF
...     :040000001C34683410
...     :00000001FF
... ''')
>>> to_numbers(file, retlw=True)
[53118, 50576, 4363, 62450, 26652]
>>> to_numbers(file, retlw=True, byteorder='big')
[32463, 37061, 2833, 62195, 7272]
>>> # User ID - PIC32MX360F512L
>>> file = IhexFile.parse(b'''
...     :020000047F007B
...     :04BFC000000000007D
...     :04BFC000010000007C
...     :04BFC000020000007B
...     :04BFC000030000007A
...     :04BFC0000400000079
...     :00000001FF
... ''')
>>> to_numbers(file)
[0, 1, 2, 3, 4]
>>> # Auxiliary Memory - dsPIC33EP256MU806
>>> file = IhexFile.parse(b'''
...     :0200000401FFFA
...     :0400000000000000FC
...     :0400000001000000FB
...     :0400000002000000FA
...     :0400000003000000F9
...     :0400000004000000F8
...     :00000001FF
... ''')
>>> to_numbers(file)
[0, 1, 2, 3, 4]
>>> # Boot Memory - PIC32MX110F016B
>>> file = IhexFile.parse(b'''
...     :020000047F007B
...     :0400000039268EC748
...     :040000001FB777E2CD
...     :04000000031E7E3D20
...     :04000000D56F64E272
...     :04000000F993C2A707
...     :00000001FF
... ''')
>>> to_numbers(file)
[3347981881, 3799496479, 1031675395, 3798233045, 2814546937]
>>> to_numbers(file, byteorder='big')
[958828231, 532117474, 52330045, 3580847330, 4187210407]
>>> # EEPROM - PIC12F1840
>>> file = IhexFile.parse(b'''
...     :020000040000FA
...     :020000000000FE
...     :020000000100FD
...     :020000000200FC
...     :020000000300FB
...     :020000000400FA
...     :00000001FF
... ''')
>>> to_numbers(file)
[0, 1, 2, 3, 4]
>>> # EEPROM - PIC18F1220 (with actual start address 0x00780000)
>>> file = IhexFile.parse(b'''
...     :0200000400F00A
...     :020000000000FE
...     :020000000100FD
...     :020000000200FC
...     :020000000300FB
...     :020000000400FA
...     :00000001FF
... ''')
>>> to_numbers(file)
[0, 1, 2, 3, 4]