serload.py: implement sending multiple files
This commit is contained in:
parent
136e3f74a0
commit
3c32dff0a7
1 changed files with 48 additions and 9 deletions
|
|
@ -19,6 +19,8 @@ import sys
|
||||||
import serial
|
import serial
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
import platform
|
||||||
|
import argparse
|
||||||
|
|
||||||
blocksize = 32
|
blocksize = 32
|
||||||
BEL = 7
|
BEL = 7
|
||||||
|
|
@ -32,6 +34,13 @@ wordmask = 0xFFFFFFFF
|
||||||
pattern = 0xAFFECAFE
|
pattern = 0xAFFECAFE
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_device():
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
return 'COM4:'
|
||||||
|
else:
|
||||||
|
return '/dev/ttyUSB1'
|
||||||
|
|
||||||
|
|
||||||
def serwrite_slow(databytes, ser):
|
def serwrite_slow(databytes, ser):
|
||||||
total = len(data)
|
total = len(data)
|
||||||
count = 1
|
count = 1
|
||||||
|
|
@ -268,20 +277,50 @@ def serdownload(fname, ser):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def mput(filenames, ser):
|
||||||
|
for f in filenames:
|
||||||
|
f_encoded = f.encode('utf8')
|
||||||
|
print("Setting filename", f)
|
||||||
|
resp = sendcommand(ser, b'S')
|
||||||
|
if len(resp) == 0:
|
||||||
|
print("timeout sending 'S' command")
|
||||||
|
return
|
||||||
|
if resp != b'S\r\n' and resp != b'> S\r\n':
|
||||||
|
print("unrecognized response to 'S' command, aborting")
|
||||||
|
return
|
||||||
|
resp = sendcommand(ser, f_encoded + b'\r')
|
||||||
|
if not f_encoded in resp:
|
||||||
|
print("unrecognized response to filename, aborting")
|
||||||
|
return
|
||||||
|
serload_bin(f, ser)
|
||||||
|
|
||||||
|
resp = ser.read_until()
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cmd = None
|
argparser = argparse.ArgumentParser(
|
||||||
if len(sys.argv) == 4:
|
description='transfer files from/to the Tridora-CPU')
|
||||||
cmd = sys.argv[1]
|
argparser.add_argument('-d', '--device', help='serial device', default=get_default_device())
|
||||||
filename = sys.argv[2]
|
argparser.add_argument('command', choices=['get', 'put', 'mput'])
|
||||||
serial_port = sys.argv[3]
|
argparser.add_argument('filename', nargs='+')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
cmd = args.command
|
||||||
|
serial_port = args.device
|
||||||
|
filenames = args.filename
|
||||||
|
|
||||||
ser = serial.Serial(serial_port,115200, timeout=3)
|
ser = serial.Serial(serial_port,115200, timeout=3)
|
||||||
|
|
||||||
if cmd == 'get':
|
if cmd == 'get':
|
||||||
serdownload(filename, ser)
|
serdownload(filenames[0], ser)
|
||||||
elif cmd == 'put':
|
elif cmd == 'put':
|
||||||
serload_bin(filename, ser)
|
serload_bin(filenames[0], ser)
|
||||||
|
elif cmd == 'mput':
|
||||||
|
mput(filenames, ser)
|
||||||
else:
|
else:
|
||||||
print("Usage: {} get|put <filename> <serial device>".format(sys.argv[0]))
|
print("should not get here")
|
||||||
|
|
||||||
if cmd is not None:
|
if cmd is not None:
|
||||||
ser.close()
|
ser.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue