taste-create-data-view 2.57 KB
Newer Older
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
1
2
#!/bin/bash -e

Maxime Perrotin's avatar
Maxime Perrotin committed
3
4
# TASTE Dataview Editor

Maxime Perrotin's avatar
Maxime Perrotin committed
5
if [ -t 1 ] ; then
Maxime Perrotin's avatar
Maxime Perrotin committed
6
7
8
9
10
11
12
13
14
    COLORON="\e[1m\e[32m"
    REDCOLORON="\e[1m\e[31m"
    COLOROFF="\e[0m"
else
    COLORON=""
    REDCOLORON=""
    COLOROFF=""
fi

15
16
INFO="${COLORON}[INFO]${COLOROFF}"
ERROR="${REDCOLORON}[ERROR]${COLOROFF}"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
17
18
19
20
21
22
23
24
25
26
27
28
29


# Find a suitable text editor, in order of priority: kate, gvim, vi
if [ ! -z $(which kate) ]
then
    EDITOR="kate -n"
elif [ ! -z $(which gvim) ]
then
    EDITOR="gvim -f"
else
    EDITOR=vi
fi

Maxime Perrotin's avatar
Maxime Perrotin committed
30
31
32
33
34
35
if [ -f "DataView.asn" ]
then
    if [ -z $NONINTERACTIVE ]
    then
        echo -e "${INFO} Opening existing DataView.asn"
    fi
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
36
else
Maxime Perrotin's avatar
Maxime Perrotin committed
37
38
39
40
    if [ -z $NONINTERACTIVE ]
    then
        echo -e "${INFO} Creating a dummy ASN.1 file with a few type examples - feel free to add, edit, delete..."
    fi
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
41
42
43
44
    echo 'TASTE-Dataview DEFINITIONS ::=
BEGIN
IMPORTS T-Int32, T-UInt32, T-Int8, T-UInt8, T-Boolean FROM TASTE-BasicTypes;

Maxime Perrotin's avatar
Maxime Perrotin committed
45
46
TASTE-Boolean ::= BOOLEAN

Maxime Perrotin's avatar
Maxime Perrotin committed
47
48
49
-- ASN.1 Type definitions must start with an uppercase
-- Field names in records (SEQUENCE) must start with a lowercase
-- Underscores are not allowed: use dash (hyphen) 
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
50

Maxime Perrotin's avatar
Maxime Perrotin committed
51
-- Simple types:
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
52

Maxime Perrotin's avatar
Maxime Perrotin committed
53
54
55
56
-- MyInteger   ::= INTEGER (0..255)
-- MyReal      ::= REAL (0.0 .. 1000.0)
-- MyBool      ::= BOOLEAN
-- MyEnum      ::= ENUMERATED { hello, world, how-are-you }
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
57

Maxime Perrotin's avatar
Maxime Perrotin committed
58
-- Complex types:
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
59

Maxime Perrotin's avatar
Maxime Perrotin committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--  MySeq       ::= SEQUENCE {
--      input-data  MyInteger,
--      output-data MyInteger,
--      validity    ENUMERATED { valid, invalid }
--  }
--
--  MyChoice    ::= CHOICE {
--      a BOOLEAN,
--      b MySeq
--  }
--
--  MySeqOf     ::= SEQUENCE (SIZE (2)) OF MyEnum
--
--  MyOctStr    ::= OCTET STRING (SIZE (3))
--
--  -- You can also declare constants
--  myVar       MySeqOf     ::= { hello, world }
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
77

Maxime Perrotin's avatar
Maxime Perrotin committed
78
79
80
END
' > DataView.asn
echo 'TASTE-Dataview DEFINITIONS ::= BEGIN
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
81

Maxime Perrotin's avatar
Maxime Perrotin committed
82
83
84
85
    --  In this ACN model, you can specify custom binary encoding rules for
    --  your data types. For example if you require a specific memory layout
    --  for a record, or need to add padding fields, define endianness, etc.
    --  you can do that with ACN. Refer to the ACN user manual for details.
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
86

Maxime Perrotin's avatar
Maxime Perrotin committed
87
    --  TASTE-Boolean []
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
88
END
Maxime Perrotin's avatar
Maxime Perrotin committed
89
' > DataView.acn
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
90
91
92
93
94
fi

if [ -z $NONINTERACTIVE ]
then
    $EDITOR DataView.asn
Maxime Perrotin's avatar
Maxime Perrotin committed
95
    echo -e "${INFO} Converting the data view to AADL..."
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
96
97
fi

Maxime Perrotin's avatar
Maxime Perrotin committed
98
# cp $(taste-config --prefix)/share/taste-types/taste-types.asn .
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
99
100
101
102
103

taste-update-data-view

if [ -z $NONINTERACTIVE ]
then
Maxime Perrotin's avatar
Maxime Perrotin committed
104
105
106
107
    echo -e "${INFO} Data View created"
    echo -e "${INFO} Run taste-edit-data-view to edit"
    echo -e "${INFO}     taste-create-acn-model to specify binary encodings with ACN"
    echo -e "${INFO}     taste-create-project to create a new TASTE project"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
108
fi