Merge branch 'master' of github.com:rscada/libmbus

This commit is contained in:
Robert Johansson 2012-04-21 07:18:21 +09:00
commit 1d0159c531
4 changed files with 82 additions and 7 deletions

View File

@ -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;
}

73
test/generate-xml.sh Executable file
View File

@ -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

View File

@ -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;
}

View File

@ -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;
}