DAN

Warning

The DAN DataSource is only available in CODAC Core System distributions.

The DANSource DataSource can be used to archive application data to the ITER Data Archiving Network (DAN).

Given that the property ICProgramName needs to be unique in order to avoid clashes, the configuration file ../Configurations/MassSpring/RTApp-MassSpring-45.cfg will be automatically updated from a Makefile.cfg.

The signals to be archived are defined in a DAN configuration file, which is generated from a template by running the command ../Test/Integrated/GenerateDANConfig.sh.

DAN configuration file.
 1 <danApi>
 2     <version>1.0.0</version>
 3     <ICprogram name="MassSpringDemoAppUSERNAME">
 4         <source name="DANWriter_uint32">
 5             <itemDanType>danUInt32</itemDanType>
 6             <maxTransferRate>100000</maxTransferRate>
 7             <advancedSource>
 8                 <checkPolicy>NO_CHECK</checkPolicy>
 9                 <streamType>DATA_D0</streamType>
10                 <dataModel>DM_BLOCK2D_VAR</dataModel>
11                 <queueSize>1000</queueSize>
12                 <profMonitoring>1</profMonitoring>
13                 <timeFormat>UTC</timeFormat>
14                 <debug>
15                     <srvChunkHeaderSize>20</srvChunkHeaderSize>
16                     <srvChunkSize>10000</srvChunkSize>
17                     <srvBufferSize>2</srvBufferSize>
18                 </debug>
19             </advancedSource>
20             <deviceInfo>
21                 <deviceName>MARTe2</deviceName>
22                 <deviceVersion>v1.3</deviceVersion>
23                 <operationalMode>0</operationalMode>
24                 <manufactureCode>NA</manufactureCode>
25             </deviceInfo>
26             <channelsInfo sequence="SEQUENCIAL">
27                 <channel number="0" variable="Time" label="Time" status="ENABLE"></channel>
28             </channelsInfo>
29         </source>
30         <source name="DANWriter_float64">

The objective of this example is to archive the application data using the DAN DataSource.

DAN::DANSource configuration. Note that the ICProgramName is automatically replaced by the Makefile.cfg.
 1        +DANWriter = {
 2            Class = "DAN::DANSource"
 3            NumberOfBuffers = 50
 4            CPUMask = 2
 5            DanBufferMultiplier = 4
 6            ICProgName = APP_NAME(USERNAME_FIRST_CAP)
 7            StackSize = 10000000
 8            StoreOnTrigger = 0
 9            Interleave = 0
10
11            Signals = {
12                Time = {
13                    Type = uint32
14                    Period = 10e-3
15                }
16                ReferencePosition = {
17                    Type = float64
18                    Period = 10e-3
19                }
20                Position = {
21                    Type = float64
22                    Period = 10e-3
23                }

Important

As explained in the DANSource documentation, the DAN DataSource requires that OpenStream is called using the MARTe2 messaging system (see also the section Messages) before writing any signal to the DataSource. In this example, this is implemented using the StateMachine (see also the section StateMachine).

Examples with the StateMachine component are covered later in the tutorial.

The DataSource also supports the archiving of structures (see the DANSource documentation), but in this example only simple signals are archived for simplicity.

Running the application

Start the DAN archiver (if not already running):

sudo dan_archiver_writer start

Generate the DAN configuration file from the template:

../Test/Integrated/GenerateDANConfig.sh

Use the danApiTool to configure and initialise the archiver:

/opt/codac/bin/danApiTool api init ../Test/Integrated/dan_mass_spring_demo_0.xml

Start the application with:

make -C ../Configurations/MassSpring/ -f Makefile.cfg
./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-45_Gen.cfg -l RealTimeLoader -m StateMachine::START #Note that the command is different from the previous examples.

Once the application is running, inspect the screen output and verify that the application is running without any issues. The log should show entries similar to the following:

...
$ [Warning - Threads.cpp:185]: Failed to change the thread priority (likely due to insufficient permissions)
$ [Information - StateMachine.cpp:340]: In state (INITIAL) triggered message (StartNextStateExecutionRTApp)
$ [Information - LoggerBroker.cpp:152]: Time [0:0]:1000000
$ [Information - LoggerBroker.cpp:152]: Time [0:0]:2000000
...

Wait a few seconds and stop the application.

The files will be stored in /tmp/data/. Open another terminal and plot the archived data using dan-tool:

dan-plot VT /tmp/data/ICMassSpringDemoAppUSERNAME_DANSTREAMER0_DANWriter_float64_NUMBER.h5 ReferencePosition,Position #Replace USERNAME with your username with the first letter in capital letters and NUMBER with the actual number of the file generated in the ``/tmp/data/`` directory.

Exercises

Ex. 1: Statistics archiving

Archive the following statistics signals using a separate DANSource.

  1. Edit the file ../Configurations/MassSpring/RTApp-MassSpring-46.cfg and add a new DataSource instance to archive the following signals: Time, Thread1CycleTime, Thread1CycleTimeMax, Thread1CycleTimeMin, Thread1CycleTimeHistogram, Thread1FreeTimeHistogram, and GAMsExecutionTime; with a period of 0.01 seconds.

  2. Open the file ../Test/Integrated/dan_mass_spring_demo_template.xml to check how the DataSource needs to be named, and name it accordingly.

Note

As explained in the DANSource documentation, arrays need to follow a specific naming convention in the xml file.

No action is required in the MARTe2 configuration file, but the arrays in the DAN configuration file need to be named following the convention <SignalName>_N_T, where N is the number of elements in the array and T is the period in nanoseconds.

For example, for the signal Thread1CycleTimeHistogram with 11 elements and a period of 0.01 seconds, the element in the DAN configuration file needs to be named DANWriterPerf_T10000000_N11_uint32.

DAN configuration file, highlighting the naming convention for arrays. Note that N denotes the number of elements in the array and T the period in nanoseconds.
1         <source name="DANWriterPerf_T10000000_N11_uint32">
2             <itemDanType>danUInt32</itemDanType>
3             <channelsInfo sequence="SEQUENCIAL">
4                 <channel number="0" variable="Thread1CycleTimeHistogram" label="Thread1CycleTimeHistogram" status="ENABLE"></channel>
5                 <channel number="1" variable="Thread1FreeTimeHistogram" label="Thread1FreeTimeHistogram" status="ENABLE"></channel>
6             </channelsInfo>
7         </source>
  1. Add the corresponding IOGAM and add it to the execution list.

  2. Note that the StateMachine already contains the necessary messages to open the DAN stream, so no modification is needed in this case.

  3. Start the archiving application.

make -C ../Configurations/MassSpring/ -f Makefile.cfg
./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-46_Gen.cfg -l RealTimeLoader -m StateMachine::START
  1. Wait a few seconds and stop the application.

  2. Open another terminal and check that the performance signals have been archived.

dan-plot VT /tmp/data/ICMassSpringDemoAppUSERNAME_DANSTREAMER0_DANWriterPerf_uint32_NUMBER.h5 Thread1CycleTime,Thread1CycleTimeMin,Thread1CycleTimeMax #Replace USERNAME with your username with the first letter in capital letters and NUMBER with the actual number of the file generated in the ``/tmp/data/`` directory.
Solution

The solution is to add a new DAN::DANSource instance, named DANSourcePerf, to the configuration file and set the corresponding properties.

New DANSource configuration.
 1        +DANWriterPerf = {
 2            Class = "DAN::DANSource"
 3            NumberOfBuffers = 50
 4            CPUMask = 2
 5            DanBufferMultiplier = 4
 6            ICProgName = APP_NAME(USERNAME_FIRST_CAP)
 7            StackSize = 10000000
 8            StoreOnTrigger = 0
 9            Interleave = 0
10            Signals = {
11                Time = {
12                    Type = uint32
13                    Period = 10e-3
14                }
15                Thread1CycleTime = {
16                    Type = uint32
17                    Period = 10e-3
18                }
19                Thread1CycleTimeMax = {
20                    Type = uint32
21                    Period = 10e-3
22                }
23                Thread1CycleTimeMin = {
24                    Type = uint32
25                    Period = 10e-3
26                }
27                Thread1CycleTimeHistogram = {
28                    Type = uint32
29                    Period = 10e-3
30                    NumberOfElements = 11
31                }
32                Thread1FreeTimeHistogram = {
33                    Type = uint32
34                    Period = 10e-3
35                    NumberOfElements = 11
36                }
37                GAMsExecutionTime = {
38                    Type = int32
39                    Period = 10e-3
40                }
41            }
42        }

Add a new IOGAM to read the performance signals and add it to the execution list.

IOGAM to copy the performance signals.
 1        +GAMWriterPerf = {
 2            Class = IOGAM
 3            InputSignals = {
 4                Time = {
 5                    DataSource = DDB1
 6                    Type = uint32
 7                }
 8                Thread1CycleTime = {
 9            OutputSignals = {
10                Time = {
11                    DataSource = DANWriterPerf
12                    Type = uint32
13                }
14                Thread1CycleTime = {
Updated execution list.
 1        +State1 = {
 2            Class = RealTimeState
 3            +Threads = {
 4                Class = ReferenceContainer
 5                +Thread1 = {
 6                    Class = RealTimeThread
 7                    CPUs = 0x1
 8                    Functions = {GAMPerfMonitor GAMTimer GAMReferenceWaveform GAMDisturbanceWaveform GAMMathDisturbance GAMFilterDisturbance GAMController GAMSpringMass GAMMathModel GAMMathPositionErr GAMStats GAMPatchForceDims GAMForceStats GAMHist GAMMathExpr GAMConversion GAMFilterMovingAvg GAMMathTrigger GAMMathTriggerSecond GAMDisplay GAMWriterPerf GAMWriter}
 9                }
10            }
11        }