taste-update-data-view 2.96 KB
Newer Older
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
1
2
3
4
#!/bin/bash

echo TASTE Data View Convertor - From ASN.1 to AADLV2

Maxime Perrotin's avatar
Maxime Perrotin committed
5
6
7
8
9
10
# Initialise the progress bar
myfifo=/tmp/$$$RANDOM
mkfifo $myfifo
tail -f $myfifo | taste-progress-dialog.py &

function quit {
11
    echo '100 Completed' > $myfifo
Maxime Perrotin's avatar
Maxime Perrotin committed
12
    rm $myfifo
13
14
15
16
17
18
19
    tailps=$(pstree -p $$ | grep tail | python -c "try:
    import sys, re; print re.search(r'tail\((.*)\)', [x for x in sys.stdin][0]).group(1)
except: pass")
    if [ ! -z $tailps ]
    then
        kill $tailps || xterm -e "echo Internal Error in taste-update-data-view"
    fi
Maxime Perrotin's avatar
Maxime Perrotin committed
20
21
22
    exit $1
}

23
24
25
# Install a trap handler to make sure Ctrl-C leads to calling the quit function (trap 2 = SINGINT)
trap 2 quit 1

Maxime Perrotin's avatar
Maxime Perrotin committed
26
if [ -t 1 ] ; then
27
28
29
30
31
32
33
34
35
36
37
38
    COLORON="\e[1m\e[32m"
    REDCOLORON="\e[1m\e[31m"
    COLOROFF="\e[0m"
else
    COLORON=""
    REDCOLORON=""
    COLOROFF=""
fi
INFO="${COLORON}[INFO]${COLOROFF}"
ERROR="${REDCOLORON}[ERROR]${COLOROFF}"


Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
39
40
41
42
43
44
45
46
47
# User may pass several ASN.1 files as parameters
for f in $@
do
    # Ignore taste internal ASN.1 files
    name=$(basename "$f")
    if [ "$name" != taste-types.asn -a "$name" != __ExtraTypes.asn ]
    then
        if [ ! -f "$f" ]
        then
48
            echo -e "${INFO} File not found: ${f}"
Maxime Perrotin's avatar
Maxime Perrotin committed
49
            quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
50
        else
51
            echo -e "${INFO} Using file: ${f}"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
52
53
54
55
56
            filename=$(readlink -e "$f")
            DATAVIEW+="$filename "
            acnfile=$(readlink -e "${f%.*}.acn")
            if [ -f "$acnfile" ]
            then
57
                echo -e "${INFO} Using ACN file: ${acnfile}"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
58
59
60
61
62
63
64
65
66
67
68
                DATAVIEW+="$acnfile "
            fi
        fi
    fi
done

# If DATAVIEW string is empty, check for DataView.asn in current folder
if [ -z "$(echo -n $DATAVIEW)" ]
then
    if [ -f DataView.asn ]
    then
Maxime Perrotin's avatar
Maxime Perrotin committed
69
        echo -e "${INFO} Using file: DataView.asn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
70
71
        DATAVIEW=$(readlink -e DataView.asn)
    else
72
73
        >&2 echo -e "${ERROR} No data view found"
        echo -e "${INFO} Usage: taste-update-data-view <set of ASN.1 files>"
Maxime Perrotin's avatar
Maxime Perrotin committed
74
        quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
75
76
77
    fi
    if [ -f DataView.acn ]
    then
78
        echo -e "${INFO} Using file: DataView.acn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
79
80
81
82
83
84
85
86
87
        DATAVIEW+=" $(readlink -e DataView.acn)"
    fi
fi

#AADL=${DATAVIEW%.*}.aadl
AADL=DataView.aadl

if [ -f __ExtraTypes.asn ]
then
88
    echo -e "${INFO} Using file: __ExtraTypes.asn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
89
90
91
92
93
    DATAVIEW+=" $(readlink -e "__ExtraTypes.asn")"
fi

if [ -f __ExtraTypes.acn ]
then
94
    echo -e "${INFO} Using file: __ExtraTypes.acn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
95
96
97
98
99
    DATAVIEW+=" $(readlink -e "__ExtraTypes.acn")"
fi

DATAVIEW+=" $(taste-config --prefix)/share/taste-types/taste-types.asn"

100
101
# can asn2aadlPlus with a call to uniq to filter out duplicate outputs
# due to multiple calls to the ASN.1 compiler
102
#asn2aadlPlus $DATAVIEW "$AADL" -aadlv2 2>&1 | uniq >&2
Maxime Perrotin's avatar
Maxime Perrotin committed
103
echo '0-100 Updating data view' > $myfifo
104
asn2aadlPlus $DATAVIEW "$AADL" -aadlv2 2>&1 > >(uniq >&2)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
105
106
107

if [ "$?" = "1" ]
then
108
109
    >&2 echo -e "${ERROR} Impossible to convert the dataview from ASN.1 to AADL"
    echo -e "${INFO} Command: asn2aadlPlus ${DATAVIEW} ${AADL} -aadlv2"
Maxime Perrotin's avatar
Maxime Perrotin committed
110
    quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
111
else
112
    echo -e "${INFO} All OK"
Maxime Perrotin's avatar
Maxime Perrotin committed
113
    quit 0
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
114
115
fi