diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-05-25 11:37:40 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-05-25 11:37:40 -0400 |
commit | f582a36e4df16d5709943f7df17a900c8bcc12ab (patch) | |
tree | 628d927c4f3e19e54618f7f47c7a44af66bf0c2f /klippy/parsedump.py | |
parent | 37a91e9c10648208de002c75df304e23ca89e256 (diff) | |
download | kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.gz kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.xz kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.zip |
Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/parsedump.py')
-rwxr-xr-x | klippy/parsedump.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/klippy/parsedump.py b/klippy/parsedump.py new file mode 100755 index 00000000..0f6c48b3 --- /dev/null +++ b/klippy/parsedump.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# Script to parse a serial port data dump +# +# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net> +# +# This file may be distributed under the terms of the GNU GPLv3 license. +import os, sys, logging +import msgproto + +def read_dictionary(filename): + dfile = open(filename, 'rb') + dictionary = dfile.read() + dfile.close() + return dictionary + +def main(): + dict_filename, data_filename = sys.argv[1:] + + dictionary = read_dictionary(dict_filename) + + mp = msgproto.MessageParser() + mp.process_identify(dictionary, decompress=False) + + f = open(data_filename, 'rb') + fd = f.fileno() + data = "" + while 1: + newdata = os.read(fd, 4096) + if not newdata: + break + data += newdata + while 1: + l = mp.check_packet(data) + if l == 0: + break + if l < 0: + logging.error("Invalid data") + data = data[-l:] + continue + msgs = mp.dump(bytearray(data[:l])) + sys.stdout.write('\n'.join(msgs[1:]) + '\n') + data = data[l:] + +if __name__ == '__main__': + main() |