Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Dec 21, 2018
1 parent 5108297 commit f31b008
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""

from __future__ import print_function, division
from __future__ import print_function
from __future__ import division

import binascii
import string
Expand Down Expand Up @@ -93,7 +94,7 @@ def pack_srec(type_, address, size, data):
"expected record type 0..3 or 5..9, but got '{}'".format(type_))

if data:
line += binascii.hexlify(data).decode('utf-8').upper()
line += binascii.hexlify(data).decode('ascii').upper()

return 'S{}{}{:02X}'.format(type_, line, crc_srec(line))

Expand All @@ -103,6 +104,7 @@ def unpack_srec(record):
"""

# Minimum STSSCC, where T is type, SS is size and CC is crc.
if len(record) < 6:
raise Error("record '{}' too short".format(record))

Expand Down Expand Up @@ -149,7 +151,7 @@ def pack_ihex(type_, address, size, data):
line = '{:02X}{:04X}{:02X}'.format(size, address, type_)

if data:
line += binascii.hexlify(data).decode('utf-8').upper()
line += binascii.hexlify(data).decode('ascii').upper()

return ':{}{:02X}'.format(line, crc_ihex(line))

Expand All @@ -159,6 +161,8 @@ def unpack_ihex(record):
"""

# Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is
# type and CC is crc.
if len(record) < 11:
raise Error("record '{}' too short".format(record))

Expand Down

0 comments on commit f31b008

Please sign in to comment.