-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog.py
43 lines (30 loc) · 763 Bytes
/
prog.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
from select import kevent
import serial
import sys
import time
with open(sys.argv[2], 'rb') as f:
data = f.read()
s = serial.Serial(sys.argv[1], 115200)
def upload():
s.write(b'p')
s.read_all()
global data
data = data
c = s.read()
while not c == b'r':
c = s.read()
print('ready')
total = len(data)
for i, c in enumerate(data):
b = bytes([c])
s.write(b)
q = b'\x100'
while not int(c^0xff) == int.from_bytes(q, byteorder='little'):
#print(c, c^0xff,'==?', int.from_bytes(q, byteorder='little'))
q = s.read()
#print('ok',c, c^0xff, '==', int.from_bytes(q, byteorder='little'))
print(f'\r{i}/{total} {i/total*100:0.2f}%', end='')
print('done')
s.write(b'\xdd\x64')
time.sleep(1)
upload()