-
-
Save shadow-absorber/6ff74f4c081ace0c3710f5bb6e1aecf9 to your computer and use it in GitHub Desktop.
S-record checksum calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# usage: $ ./srec-checksum.py <s-record without checksum> | |
import sys | |
cad = sys.argv[1] | |
i = 2 | |
checksum = 0 | |
while i<len(cad): | |
checksum = checksum + ord(cad[i:i+2].decode("hex")) | |
i+=2 | |
if (cad[0:2] == "S1"): | |
out = "Data record, address 16 bits" | |
address = cad[4:8] | |
elif (cad[0:2] == "S2"): | |
out = "Data record, address 24 bits" | |
address = cad[4:10] | |
elif (cad[0:2] == "S3"): | |
out = "Data record, address 32 bits" | |
address = cad[4:12] | |
elif (cad[0:2] == "S9"): | |
out = "Termination record, address 16 bits" | |
address = cad[4:8] | |
elif (cad[0:2] == "S8"): | |
out = "Termination record, address 24 bits" | |
address = cad[4:10] | |
elif (cad[0:2] == "S9"): | |
out = "Termination record, address 32 bits" | |
address = cad[4:12] | |
elif (cad[0:2] == "S0"): | |
out = "Header record" | |
address = "0000" | |
print "[*] Record type: %s\taddress=0x%s"%(out, address) | |
print "[*] Checksum: %s\n[*] S-Record: %s"%(hex(checksum^0xff)[-2:].upper(), cad + hex(checksum^0xff)[-2:].upper()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment