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; } 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 + + diff --git a/test/mbus_parse.c b/test/mbus_parse.c index 4286d08..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; } @@ -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..913b0d2 100644 --- a/test/mbus_parse_hex.c +++ b/test/mbus_parse_hex.c @@ -31,14 +31,14 @@ main(int argc, char *argv[]) if (argc != 2) { - fprintf(stderr, "%s binary-file\n", argv[0]); - return -1; + fprintf(stderr, "usage: %s hex-file\n", argv[0]); + 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; }