From bbdcac04b0636e9322f481a554a37194b2026063 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Mon, 16 Apr 2012 00:33:03 +0200 Subject: [PATCH 1/4] Fixed exit codes --- test/mbus_parse.c | 1 + test/mbus_parse_hex.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/mbus_parse.c b/test/mbus_parse.c index 4286d08..2dfc32d 100644 --- a/test/mbus_parse.c +++ b/test/mbus_parse.c @@ -52,6 +52,7 @@ main(int argc, char *argv[]) mbus_frame_data_parse(&reply, &frame_data); mbus_frame_print(&reply); printf("%s", mbus_frame_data_xml(&frame_data)); + return 0; } diff --git a/test/mbus_parse_hex.c b/test/mbus_parse_hex.c index f662276..ced5a19 100644 --- a/test/mbus_parse_hex.c +++ b/test/mbus_parse_hex.c @@ -32,13 +32,13 @@ main(int argc, char *argv[]) if (argc != 2) { fprintf(stderr, "%s binary-file\n", argv[0]); - return -1; + return 1; } if ((fd = open(argv[1], O_RDONLY, 0)) == -1) { fprintf(stderr, "%s: failed to open '%s'", argv[0], argv[1]); - return -1; + return 1; } bzero(raw_buff, sizeof(raw_buff)); @@ -70,12 +70,12 @@ main(int argc, char *argv[]) if (result < 0) { fprintf(stderr, "mbus_parse: %s\n", mbus_error_str()); - return -1; + return 1; } else if (result > 0) { fprintf(stderr, "mbus_parse: need %d more bytes\n", result); - return -1; + return 1; } result = mbus_frame_data_parse(&reply, &frame_data); @@ -90,6 +90,7 @@ main(int argc, char *argv[]) //mbus_frame_print(&reply); //mbus_frame_data_print(&frame_data); printf("%s", mbus_frame_data_xml(&frame_data)); + return 0; } From 4958966797688846db09e259a1658c490ffe2dfa Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Mon, 16 Apr 2012 21:00:24 +0200 Subject: [PATCH 2/4] Fixed usage --- test/mbus_parse.c | 2 +- test/mbus_parse_hex.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mbus_parse.c b/test/mbus_parse.c index 2dfc32d..3f23999 100644 --- a/test/mbus_parse.c +++ b/test/mbus_parse.c @@ -31,7 +31,7 @@ main(int argc, char *argv[]) if (argc != 2) { - fprintf(stderr, "%s binary-file\n", argv[0]); + fprintf(stderr, "usage: %s binary-file\n", argv[0]); return 1; } diff --git a/test/mbus_parse_hex.c b/test/mbus_parse_hex.c index ced5a19..913b0d2 100644 --- a/test/mbus_parse_hex.c +++ b/test/mbus_parse_hex.c @@ -31,7 +31,7 @@ main(int argc, char *argv[]) if (argc != 2) { - fprintf(stderr, "%s binary-file\n", argv[0]); + fprintf(stderr, "usage: %s hex-file\n", argv[0]); return 1; } From a65a96e333962cc5f598fabe5ac62622c71e2991 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Mon, 16 Apr 2012 21:01:29 +0200 Subject: [PATCH 3/4] Fixed usage --- bin/mbus-serial-switch-baudrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mbus-serial-switch-baudrate.c b/bin/mbus-serial-switch-baudrate.c index 0a90f95..426526d 100644 --- a/bin/mbus-serial-switch-baudrate.c +++ b/bin/mbus-serial-switch-baudrate.c @@ -48,7 +48,7 @@ main(int argc, char **argv) } else { - fprintf(stderr, "usage: %s device address target-baudrate\n", argv[0]); + fprintf(stderr, "usage: %s [-b BAUDRATE] device address target-baudrate\n", argv[0]); return 0; } From 1b69b1b51b55038df92c63dec82bb86a1f6d4086 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Mon, 16 Apr 2012 21:04:03 +0200 Subject: [PATCH 4/4] Added a new script to generate XML files from hex files in a specified directory --- test/generate-xml.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 test/generate-xml.sh diff --git a/test/generate-xml.sh b/test/generate-xml.sh new file mode 100755 index 0000000..e82b8b8 --- /dev/null +++ b/test/generate-xml.sh @@ -0,0 +1,73 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# Copyright (C) 2010-2012, Robert Johansson and contributors, Raditex AB +# All rights reserved. +# +# rSCADA +# http://www.rSCADA.se +# info@rscada.se +# +# Contributors: +# Large parts of this file was contributed by Stefan Wahren. +# +#------------------------------------------------------------------------------ + +# Check if mbus_parse_hex exists +if [ ! -x ./mbus_parse_hex ]; then + echo "mbus_parse_hex not found" + exit 3 +fi + +# Check commandline parameter +if [ $# -ne 1 ]; then + echo "usage: $0 directory" + exit 3 +fi + +directory="$1" + +# Check directory +if [ ! -d "$directory" ]; then + echo "usage: $0 directory" + exit 3 +fi + +for hexfile in "$directory"/*.hex; do + filename=`basename $hexfile .hex` + + # Parse hex file and write XML in file + ./mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new" + result=$? + + # Check parsing result + if [ $result -ne 0 ]; then + echo "Unable to generate XML for $hexfile" + rm "$directory/$filename.xml.new" + continue + fi + + # Compare old XML with new XML and write in file + diff -u "$directory/$filename.xml" "$directory/$filename.xml.new" 2> /dev/null > "$directory/$filename.dif" + result=$? + + case "$result" in + 0) + # XML equal -> remove new + rm "$directory/$filename.xml.new" + rm "$directory/$filename.dif" + ;; + 1) + # different -> print diff + cat "$directory/$filename.dif" && rm "$directory/$filename.dif" + echo "" + ;; + *) + # no old -> rename XML + echo "Create $filename.xml" + mv "$directory/$filename.xml.new" "$directory/$filename.xml" + rm "$directory/$filename.dif" + ;; + esac +done + +