2012-04-16 21:04:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Copyright (C) 2010-2012, Robert Johansson and contributors, Raditex AB
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2016-02-05 14:36:19 +01:00
|
|
|
# rSCADA
|
2012-04-16 21:04:03 +02:00
|
|
|
# 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
|
2013-08-03 15:51:34 +02:00
|
|
|
|
2012-04-16 21:04:03 +02:00
|
|
|
filename=`basename $hexfile .hex`
|
2016-02-05 14:36:19 +01:00
|
|
|
|
2012-04-16 21:04:03 +02: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
|
|
|
|
2012-04-16 21:04:03 +02: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
|
|
|
|
2012-04-16 21:04:03 +02: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
|
|
|
|
2012-04-16 21:04:03 +02: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
|
|
|
*)
|
2012-04-16 21:04:03 +02:00
|
|
|
# no old -> rename XML
|
|
|
|
echo "Create $filename.xml"
|
|
|
|
mv "$directory/$filename.xml.new" "$directory/$filename.xml"
|
|
|
|
rm "$directory/$filename.dif"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|