libmbus/test/generate-xml.sh

79 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/sh
#------------------------------------------------------------------------------
# Copyright (C) 2010-2012, Robert Johansson and contributors, Raditex AB
# All rights reserved.
#
2016-02-05 14:36:19 +01:00
# rSCADA
# http://www.rSCADA.se
# info@rscada.se
#
# Contributors:
# Large parts of this file was contributed by Stefan Wahren.
#
#------------------------------------------------------------------------------
# Check commandline parameter
2020-04-14 11:01:07 +02:00
if [ $# -ne 2 ]; then
echo "usage: $0 path_to_directory_with_xml_files path_to_mbus_parse_hex_with_filename"
exit 3
fi
directory="$1"
2020-04-14 11:01:07 +02:00
# Check if mbus_parse_hex exists
if [ ! -x $2 ]; then
echo "mbus_parse_hex not found"
exit 3
fi
mbus_parse_hex="$2"
# # Check directory
if [ ! -d "$directory" ]; then
2020-04-14 11:01:07 +02:00
echo "$directory not found"
exit 3
fi
for hexfile in "$directory"/*.hex; do
2016-02-05 14:36:19 +01:00
if [ ! -f "$hexfile" ]; then
continue
fi
filename=`basename $hexfile .hex`
2016-02-05 14:36:19 +01:00
# Parse hex file and write XML in file
2020-04-14 11:01:07 +02:00
$mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new"
result=$?
2016-02-05 14:36:19 +01:00
# Check parsing result
if [ $result -ne 0 ]; then
echo "Unable to generate XML for $hexfile"
rm "$directory/$filename.xml.new"
continue
fi
2016-02-05 14:36:19 +01:00
# 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=$?
2016-02-05 14:36:19 +01:00
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 ""
;;
2016-02-05 14:36:19 +01:00
*)
# no old -> rename XML
echo "Create $filename.xml"
mv "$directory/$filename.xml.new" "$directory/$filename.xml"
rm "$directory/$filename.dif"
;;
esac
done