taste-create-data-view 2.57 KB
Newer Older
1 2
#!/bin/bash -e

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

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}"
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
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
41 42 43 44
    echo 'TASTE-Dataview DEFINITIONS ::=
BEGIN
IMPORTS T-Int32, T-UInt32, T-Int8, T-UInt8, T-Boolean FROM TASTE-BasicTypes;

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) 
50

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

53 54 55 56
-- MyInteger   ::= INTEGER (0..255)
-- MyReal      ::= REAL (0.0 .. 1000.0)
-- MyBool      ::= BOOLEAN
-- MyEnum      ::= ENUMERATED { hello, world, how-are-you }
57

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

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 }
77

78 79 80
END
' > DataView.asn
echo 'TASTE-Dataview DEFINITIONS ::= BEGIN
81

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.
86

87
    --  TASTE-Boolean []
88
END
89
' > DataView.acn
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..."
96 97
fi

98
# cp $(taste-config --prefix)/share/taste-types/taste-types.asn .
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"
108
fi