libmbus/test/generate-xml.sh

78 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 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
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
./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