-
Notifications
You must be signed in to change notification settings - Fork 0
/
srecUtils.py
53 lines (37 loc) · 1.14 KB
/
srecUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import datetime
def checkSumCal(srecIn):
# Motorla srec checksum calculator
srec = srecIn
hexSum = 0
for i in range(2, len(srec), 2):
currentByte = srec[i:i+2]
currentByte = int(currentByte, 16)
hexSum = hexSum + currentByte
# print(hex(currentByte))
print(hex(hexSum))
dummyHex = 0xFF
# last significant dig
lsgHex = str(hex(hexSum))[-2:]
lsgHex = int(lsgHex, 16)
# check sum Hex
csHex = dummyHex - lsgHex
csHex = str(hex(csHex))
csHex = csHex[2:].zfill(2).upper()
print('CheckSum: ' + csHex)
return csHex
def char2hex(charIn):
# convert ASCII char to hex format
letter = charIn
# letter = hex(ord(charIn))
letter = letter.encode('utf-8')
return letter.hex().upper()
def dateString():
# date string gen function
dateToday = datetime.date.today()
dateTodayUS = dateToday.strftime("%m%d%Y")
dateTodaySTD = dateToday.strftime("%Y%m%d")
return dateTodayUS
# debug section
# checkSumCal("S315A032C02000000000000040400000A04000004040")
# checkSumCal("S315A032C01047414835303000000000000012345678")
# print(dateString())