|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- import serial, sys, os, time
-
- if (len(sys.argv) <= 2):
- print("Usage: '" + sys.argv[0] + " <port> <files>' where:\n\t<port> is the TTY USB port connected to Drum Master\n\t<files> is a list of .RAW files (bash globs work).")
- sys.exit()
-
-
- BYTE_START = "\x7e"
- BYTE_ESCAPE = "\x7d"
- BYTE_SEPARATOR = "\x7c"
-
-
- FLASH_SIZE = 16
-
- totalFileSize = 0;
- for i, filename in enumerate(sys.argv):
- if (i >= 2):
- totalFileSize = totalFileSize + os.path.getsize(filename)
-
- flashSizeBytes = FLASH_SIZE * 1024 * 1024
- if (totalFileSize > flashSizeBytes):
- print("Too many files selsected.\n\tTotal flash size:\t" + "{:>14,}".format(flashSizeBytes) + " bytes\n\tTotal file size:\t" + "{:>14,}".format(totalFileSize) + " bytes")
- sys.exit()
-
- ser = serial.Serial(sys.argv[1])
- print("Uploading " + str(len(sys.argv) - 2) + " files...")
- for i, filename in enumerate(sys.argv):
- if (i >= 2):
- startTime = time.time();
- sys.stdout.write(str(i - 1) + ": ")
- sys.stdout.write(filename)
- sys.stdout.flush()
-
-
- f = open(filename, "rb")
- fileLength = os.path.getsize(filename)
- try:
- encoded = []
-
- encoded.append(BYTE_START)
-
- for byte in os.path.basename(filename):
- encoded.append(byte)
-
- encoded.append(BYTE_SEPARATOR)
-
-
- encoded.append(chr((fileLength >> 24) & 0xFF));
- encoded.append(chr((fileLength >> 16) & 0xFF));
- encoded.append(chr((fileLength >> 8) & 0xFF));
- encoded.append(chr((fileLength >> 0) & 0xFF));
- encoded.append(BYTE_SEPARATOR)
-
-
- for byte in f.read():
- if byte == BYTE_START or byte == BYTE_ESCAPE:
- encoded.append(BYTE_ESCAPE)
- encoded.append(chr(ord(byte) ^ 0x20))
- else:
- encoded.append(byte);
-
-
- encoded.append(BYTE_START)
- ser.write("".join(encoded))
-
- finally:
- f.close()
-
- endTime = time.time();
- print(" (" + str(round(fileLength / 1024 / (endTime - startTime), 2)) + " KB/s)");
-
- print("All files uploaded")
|