-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.py
More file actions
37 lines (30 loc) · 784 Bytes
/
upload.py
File metadata and controls
37 lines (30 loc) · 784 Bytes
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
import sys
import serial
import time
program = open(sys.argv[2], "rb")
payload = program.read()
payloadsize = len(payload).to_bytes(4,byteorder="big")
ser = serial.Serial(sys.argv[1], 115200, timeout=3)
print(ser.name)
ser.reset_input_buffer()
ser.reset_output_buffer()
ser.write(payloadsize)
c = ser.read(4)
if payloadsize != c:
raise Exception("payloadsize received incorrect!")
print("total bytes to send: ", len(payload))
index = 0
step = 1000
for i in range(0, len(payload), step):
n = ser.write(payload[i:i+step])
#print(n)
c = ser.read(n)
if payload[i:i+n] != c:
raise Exception("payload received incorrect!")
index += n
#print(index)
c = ser.read()
if c == b"#":
print("total received bytes:", index)
ser.close()
program.close()