GAM
The Generic Application Module (GAM) is the component where user-algorithms are to be implemented.
The GAM offers one interface for configuration and two interfaces for real-time input and output processing.

Warning
No interface with operating system (e.g. reading from files/sockets) shall be implemented in the GAMs. The only exception is memory allocation during configuration.
GAMs can be conceptually divided in two sets: one where the inputs and outputs signals (number, type and dimensions) are fixed by design; and another where the algorithm behaviour varies with the signal characteristics of a given real-time application (see examples below).
Configuration
A GAM is initialised just like any other MARTe Object.
The properties related to the input and output signals are available when the Setup
method is called. At this stage any of the signal related methods described in the GAM API can be used to query the signal properties.
virtual bool MyGAM::Setup () {
...
uint32 numberOfInputSignals = GetNumberOfInputSignals();
...
for (i = 0u; i<numberOfInputSignals; i++) {
TypeDescriptor td = GetSignalType(InputSignals, i);
...
}
...
}
Typical use cases of the Setup method are to validate and/or configure the algorithm against the input/output signal requirements of the specific application (e.g. the number, type and dimensions);
virtual bool MyGAM::Setup () {
...
uint32 numberOfInputSignals = GetNumberOfInputSignals();
...
//Only accept one input signal
bool ok = (numberOfInputSignals == 1u);
...
}
In the configuration stream the input signals shall be placed inside a node named InputSignals
and the output signals inside a node named OutputSignals
.
...
InputSignals = {
Counter = {
DataSource = DDB1
Type = uint32
}
}
OutputSignals = {
GainCounter = {
DataSource = DDB1
Type = uint32
}
}
...
GAMs can also use registered structured types as input/output signals.
For example, the following structure can be used as a signal:
struct ModelGAMExampleStructInner1 {
MARTe::float32 f1;
MARTe::float32 f2;
MARTe::float32 f3[6];
};
struct ModelGAMExampleStructSignal {
MARTe::uint32 u1;
ModelGAMExampleStructInner1 s1;
ModelGAMExampleStructInner1 s2;
};
...
InputSignals = {
Signal1 = {
DataSource = DDB1
Type = ModelGAMExampleStructSignal
}
}
OutputSignals = {
Signal1 = {
DataSource = DDB1
Type = ModelGAMExampleStructSignal
}
}
...
Note that the structure will be automatically expanded into the equivalent configuration structure (this means that the GAM API will see the expanded structure):
...
InputSignals = {
Signal1 = {
u1 = {
DataSource = DDB1
Type = uint32
}
s1 = {
f1 = {
DataSource = DDB1
Type = float32
}
f2 = {
DataSource = DDB1
Type = float32
}
f3 = {
DataSource = DDB1
Type = float32
NumberOfDimensions = 1
NumberOfElements = 6
}
}
s2 = {
...
}
}
}
...
Signal properties
The signal name (in the context of the GAM) is the name of the node. Other properties that can be set for any signal are:
Property |
Meaning |
---|---|
Type |
The signal type as any of the supported Types or a structure type. |
DataSource |
The name of the DataSource from where the signal will read/written from/to. |
Frequency |
Only meaningful for input signals. The frequency at which the signal is expected to be produced (at most one signal per real-time thread) may have this property set. |
Trigger |
Only meaningful for output signals. Trigger the DataSource when this signal is written. |
NumberOfElements |
The number of elements (1 if the signal is a scalar). |
NumberOfDimensions |
The number of dimensions (0 if scalar, 1 if vector, 2 if matrix). |
Samples |
The number of samples to read from a DataSource. This number defines the number of samples that the DataSource shall acquire for each control cycle. Note that each sample may contain an array. Indeed, the amount of memory required to hold a signal of type T, with M samples and N elements is: sizeof(T) x M x N. Typical use cases: i) ADC: M samples, 1 element; ii) Image: 1 sample, N elements; iii) Video: M samples, N elements. |
Ranges |
In the case of a vector read/write only a subset. The format is a matrix, indexed to zero, of the ranges that are to be read (e.g. |
Alias |
The name of the signal in the DataSource (which can be different from the name of the signal in the GAM). |
Default |
The default value to be used in the first control cycle (if needed, i.e. if it depends from a value of the previous cycle). |
The structure types offer to extra properties:
Property |
Meaning |
---|---|
MemberAliases |
The name of the structured member signal in the DataSource (which can be different from the name of the signal in the GAM). |
Defaults |
The default value for a given member of the structure. |
The following snippet shows how to change the alias and the defaults of a structure.
...
InputSignals = {
Signal1 = {
DataSource = DDB1
Type = ModelGAMExampleStructSignal
Defaults = {
Signal1.s1.f1 = 2
Signal1.s1.f2 = 3
Signal1.s1.f3 = {1, 2, 3, 4, 5, 6}
Signal1.s2.f1 = -2
Signal1.s2.f2 = -3
Signal1.s2.f3 = {-1, -2, -3, -4, -5, -6}
}
MemberAliases = {
//Rename of a structured member
Signal1.s2.f2 = Signal1.s2.g2
}
}
...
Real-time execution
The Execute
method is called at every real-time cycle.
When the method is called, the input signals will be ready to be processed by the GAM. After the method is called the output signals will be propagated accordingly.
...
bool GAM1::Setup() {
...
inputSignal = reinterpret_cast<uint32 *>(GetInputSignalMemory(0u));
outputSignal = reinterpret_cast<uint32 *>(GetOutputSignalMemory(0u));
...
bool GAM1::Execute() {
...
*outputSignal = gain * *inputSignal;
...
GAMGroup
GAMs can also be grouped into a context where a set of constant data is shared between them.

Typical use-cases for GAMGroups are the need to share initialisation data which is either onerous to compute or that requires the storing of a large amount of memory. In both cases it would be a waste of resources to repeat and store the same initialisation process on all the GAMs requiring access to this information.
The shared context is set by calling the method GAMGroup::SetContext
in the class inheriting from GAMGroup. This will then trigger the calling of the method SetContext
on all the GAM components that, in the configuration stream, are a child of this GAMGroup instance.
...
+GAMGroup1 = {
Class = ParentGAMGroupExample1
//The model to be shared by all the GAMs belonging to this group
Model = {{2, 0, 0}, {0, 3, 0}, {1, 0, 4}}
+GAMChild1 = {
Class = ChildGAMGroupExample1
...
}
+GAMChild2 = {
Class = ChildGAMGroupExample2
...
}
...
...
class ParentGAMGroupExample1: public MARTe::GAMGroup {
...
bool PrepareNextState(const MARTe::char8*, const MARTe::char8*) {
...
ok = SetContext(matrixModelContext);
...
class ChildGAMGroupExample1 : public MARTe::GAM {
...
bool SetContext(ConstReference context) {
matrixModelContext = context;
contextSet = context.IsValid();
...
Examples
Fixed GAM
The following is an example of GAM which has a fixed number of signals.
1/**
2 * @file FixedGAMExample1.cpp
3 * @brief Source file for class FixedGAMExample1
4 * @date 06/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class FixedGAMExample1 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "FixedGAMExample1.h"
33
34/*---------------------------------------------------------------------------*/
35/* Static definitions */
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/* Method definitions */
40/*---------------------------------------------------------------------------*/
41namespace MARTe2Tutorial {
42FixedGAMExample1::FixedGAMExample1() {
43 gain = 0u;
44 inputSignal = NULL_PTR(MARTe::uint32 *);
45 outputSignal = NULL_PTR(MARTe::uint32 *);
46}
47
48FixedGAMExample1::~FixedGAMExample1() {
49
50}
51
52bool FixedGAMExample1::Initialise(MARTe::StructuredDataI & data) {
53 using namespace MARTe;
54 bool ok = GAM::Initialise(data);
55 if (!ok) {
56 REPORT_ERROR(ErrorManagement::ParametersError, "Could not Initialise the GAM");
57 }
58 if (ok) {
59 ok = data.Read("Gain", gain);
60 if (!ok) {
61 REPORT_ERROR(ErrorManagement::ParametersError, "The parameter Gain shall be set");
62 }
63 }
64 if (ok) {
65 REPORT_ERROR(ErrorManagement::Information, "Parameter Gain set to %d", gain);
66 }
67 return ok;
68}
69
70bool FixedGAMExample1::Setup() {
71 using namespace MARTe;
72 uint32 numberOfInputSignals = GetNumberOfInputSignals();
73 uint32 numberOfOutputSignals = GetNumberOfOutputSignals();
74 bool ok = (numberOfInputSignals == numberOfOutputSignals);
75 if (ok) {
76 ok = (numberOfOutputSignals == 1u);
77 if (!ok) {
78 REPORT_ERROR(ErrorManagement::ParametersError,
79 "The number of input and output signals shall be equal to 1. numberOfInputSignals = %d numberOfOutputSignals = %d",
80 numberOfInputSignals, numberOfOutputSignals);
81 }
82 }
83 if (ok) {
84 TypeDescriptor inputSignalType = GetSignalType(InputSignals, 0u);
85 TypeDescriptor outputSignalType = GetSignalType(OutputSignals, 0u);
86 ok = (inputSignalType == outputSignalType);
87 if (ok) {
88 ok = (inputSignalType == UnsignedInteger32Bit);
89 }
90 if (!ok) {
91 const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
92 const char8 * const outputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(outputSignalType);
93 REPORT_ERROR(ErrorManagement::ParametersError,
94 "The type of the input and output signal shall be uint32. inputSignalType = %s outputSignalType = %s", inputSignalTypeStr,
95 outputSignalTypeStr);
96 }
97 }
98 if (ok) {
99 uint32 numberOfInputSamples = 0u;
100 uint32 numberOfOutputSamples = 0u;
101 ok = GetSignalNumberOfSamples(InputSignals, 0u, numberOfInputSamples);
102 if (ok) {
103 ok = GetSignalNumberOfSamples(OutputSignals, 0u, numberOfOutputSamples);
104 }
105 if (ok) {
106 ok = (numberOfInputSamples == numberOfOutputSamples);
107 }
108 if (ok) {
109 ok = (numberOfInputSamples == 1u);
110 }
111 if (!ok) {
112 REPORT_ERROR(ErrorManagement::ParametersError,
113 "The number of input and output signals samples shall be equal to 1. numberOfInputSamples = %d numberOfOutputSamples = %d",
114 numberOfInputSamples, numberOfOutputSamples);
115 }
116 }
117 if (ok) {
118 uint32 numberOfInputDimensions = 0u;
119 uint32 numberOfOutputDimensions = 0u;
120 ok = GetSignalNumberOfDimensions(InputSignals, 0u, numberOfInputDimensions);
121 if (ok) {
122 ok = GetSignalNumberOfDimensions(OutputSignals, 0u, numberOfOutputDimensions);
123 }
124 if (ok) {
125 ok = (numberOfInputDimensions == numberOfOutputDimensions);
126 }
127 if (ok) {
128 ok = (numberOfInputDimensions == 0u);
129 }
130 if (!ok) {
131 REPORT_ERROR(ErrorManagement::ParametersError,
132 "The number of input and output signals dimensions shall be equal to 0. numberOfInputDimensions = %d numberOfOutputDimensions = %d",
133 numberOfInputDimensions, numberOfOutputDimensions);
134 }
135 }
136 if (ok) {
137 uint32 numberOfInputElements = 0u;
138 uint32 numberOfOutputElements = 0u;
139 ok = GetSignalNumberOfElements(InputSignals, 0u, numberOfInputElements);
140 if (ok) {
141 ok = GetSignalNumberOfElements(OutputSignals, 0u, numberOfOutputElements);
142 }
143 if (ok) {
144 ok = (numberOfInputElements == numberOfOutputElements);
145 }
146 if (ok) {
147 ok = (numberOfInputElements == 1u);
148 }
149 if (!ok) {
150 REPORT_ERROR(ErrorManagement::ParametersError,
151 "The number of input and output signals elements shall be equal to 1. numberOfInputElements = %d numberOfOutputElements = %d",
152 numberOfInputElements, numberOfOutputElements);
153 }
154 }
155 if (ok) {
156 inputSignal = reinterpret_cast<uint32 *>(GetInputSignalMemory(0u));
157 outputSignal = reinterpret_cast<uint32 *>(GetOutputSignalMemory(0u));
158 }
159 return ok;
160
161}
162
163bool FixedGAMExample1::Execute() {
164 *outputSignal = gain * *inputSignal;
165 return true;
166}
167
168CLASS_REGISTER(FixedGAMExample1, "")
169}
1$TestApp = {
2 Class = RealTimeApplication
3 +Functions = {
4 Class = ReferenceContainer
5 +GAMTimer = {
6 Class = IOGAM
7 InputSignals = {
8 Counter = {
9 DataSource = Timer
10 Type = uint32
11 }
12 Time = {
13 Frequency = 1
14 DataSource = Timer
15 Type = uint32
16 }
17 }
18 OutputSignals = {
19 Counter = {
20 DataSource = DDB1
21 Type = uint32
22 }
23 Time = {
24 DataSource = DDB1
25 Type = uint32
26 }
27 }
28 }
29 +GAMFixed1 = {
30 Class = FixedGAMExample1
31 Gain = 2
32 InputSignals = {
33 Counter = {
34 DataSource = DDB1
35 Type = uint32
36 }
37 }
38 OutputSignals = {
39 GainCounter = {
40 DataSource = DDB1
41 Type = uint32
42 }
43 }
44 }
45 +GAMDisplay = {
46 Class = IOGAM
47 InputSignals = {
48 Counter = {
49 DataSource = DDB1
50 Type = uint32
51 }
52 GainCounter = {
53 DataSource = DDB1
54 Type = uint32
55 }
56 }
57 OutputSignals = {
58 Counter = {
59 DataSource = LoggerDataSource
60 Type = uint32
61 }
62 GainCounter = {
63 DataSource = LoggerDataSource
64 Type = uint32
65 }
66 }
67 }
68 }
69 +Data = {
70 Class = ReferenceContainer
71 DefaultDataSource = DDB1
72 +DDB1 = {
73 Class = GAMDataSource
74 }
75 +LoggerDataSource = {
76 Class = LoggerDataSource
77 }
78 +Timings = {
79 Class = TimingDataSource
80 }
81 +Timer = {
82 Class = LinuxTimer
83 SleepNature = "Default"
84 Signals = {
85 Counter = {
86 Type = uint32
87 }
88 Time = {
89 Type = uint32
90 }
91 }
92 }
93 }
94 +States = {
95 Class = ReferenceContainer
96 +State1 = {
97 Class = RealTimeState
98 +Threads = {
99 Class = ReferenceContainer
100 +Thread1 = {
101 Class = RealTimeThread
102 CPUs = 0x1
103 Functions = {GAMTimer GAMFixed1 GAMDisplay }
104 }
105 }
106 }
107 }
108 +Scheduler = {
109 Class = GAMScheduler
110 TimingDataSource = Timings
111 }
112}
Variable GAM
The following is an example of GAM which adapts to the number of output signals.
1/**
2 * @file VariableGAMExample1.cpp
3 * @brief Source file for class VariableGAMExample1
4 * @date 06/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class VariableGAMExample1 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "VariableGAMExample1.h"
33
34/*---------------------------------------------------------------------------*/
35/* Static definitions */
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/* Method definitions */
40/*---------------------------------------------------------------------------*/
41namespace MARTe2Tutorial {
42VariableGAMExample1::VariableGAMExample1() {
43 numberOfOutputSignals = 0u;
44 gains = NULL_PTR(MARTe::uint32 *);
45 inputSignal = NULL_PTR(MARTe::uint32 *);
46 outputSignals = NULL_PTR(MARTe::uint32 **);
47}
48
49VariableGAMExample1::~VariableGAMExample1() {
50 if (gains != NULL_PTR(MARTe::uint32 *)) {
51 delete[] gains;
52 }
53 if (outputSignals != NULL_PTR(MARTe::uint32 **)) {
54 delete[] outputSignals;
55 }
56}
57
58bool VariableGAMExample1::Initialise(MARTe::StructuredDataI & data) {
59 using namespace MARTe;
60 bool ok = GAM::Initialise(data);
61 if (!ok) {
62 REPORT_ERROR(ErrorManagement::ParametersError, "Could not Initialise the GAM");
63 }
64 if (ok) {
65 AnyType arrayDescription = data.GetType("Gains");
66 ok = arrayDescription.GetDataPointer() != NULL_PTR(void *);
67 uint32 numberOfElements = 0u;
68 if (ok) {
69 numberOfElements = arrayDescription.GetNumberOfElements(0u);
70 ok = (numberOfElements > 0u);
71 if (!ok) {
72 REPORT_ERROR(ErrorManagement::ParametersError, "No elements defined in the array");
73 }
74 }
75 if (ok) {
76 //Reconfiguration...
77 if (gains != NULL) {
78 delete [] gains;
79 }
80 gains = new uint32[numberOfElements];
81 Vector<uint32> readVector(gains, numberOfElements);
82 ok = data.Read("Gains", readVector);
83 if (ok) {
84 REPORT_ERROR(ErrorManagement::Information, "Gains set to %d", readVector);
85 }
86 else {
87 REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gains");
88 }
89 }
90 if (!ok) {
91 REPORT_ERROR(ErrorManagement::ParametersError, "The parameter Gains shall be set as an array");
92 }
93 }
94 return ok;
95}
96
97bool VariableGAMExample1::Setup() {
98 using namespace MARTe;
99 uint32 numberOfInputSignals = GetNumberOfInputSignals();
100 numberOfOutputSignals = GetNumberOfOutputSignals();
101 bool ok = (numberOfInputSignals == 1u);
102 if (!ok) {
103 REPORT_ERROR(ErrorManagement::ParametersError, "The number of input signals shall be equal to 1. numberOfInputSignals = %d ", numberOfInputSignals);
104 }
105 if (ok) {
106 ok = (numberOfOutputSignals > 0u);
107 if (!ok) {
108 REPORT_ERROR(ErrorManagement::ParametersError, "The number of output signals shall be greater than 1. numberOfOutputSignals = %d ",
109 numberOfOutputSignals);
110 }
111 }
112 if (ok) {
113 outputSignals = new uint32*[numberOfOutputSignals];
114 }
115 if (ok) {
116 TypeDescriptor inputSignalType = GetSignalType(InputSignals, 0u);
117 uint32 n;
118 for (n = 0u; (n < numberOfOutputSignals) && (ok); n++) {
119 StreamString outputSignalName;
120 ok = GetSignalName(OutputSignals, n, outputSignalName);
121 TypeDescriptor outputSignalType = GetSignalType(OutputSignals, n);
122 ok = (inputSignalType == outputSignalType);
123 if (ok) {
124 ok = (inputSignalType == UnsignedInteger32Bit);
125 }
126 if (!ok) {
127 const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
128 const char8 * const outputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(outputSignalType);
129 REPORT_ERROR(ErrorManagement::ParametersError,
130 "The type of the input and output signals shall be uint32. inputSignalType = %s outputSignalType (%s) = %s", inputSignalTypeStr,
131 outputSignalName.Buffer(), outputSignalTypeStr);
132 }
133
134 uint32 numberOfInputSamples = 0u;
135 uint32 numberOfOutputSamples = 0u;
136 if (ok) {
137 ok = GetSignalNumberOfSamples(InputSignals, 0u, numberOfInputSamples);
138 }
139 if (ok) {
140 ok = GetSignalNumberOfSamples(OutputSignals, n, numberOfOutputSamples);
141 }
142 if (ok) {
143 ok = (numberOfInputSamples == numberOfOutputSamples);
144 }
145 if (ok) {
146 ok = (numberOfInputSamples == 1u);
147 if (!ok) {
148 REPORT_ERROR(
149 ErrorManagement::ParametersError,
150 "The number of input and output signals samples shall be equal to 1. numberOfInputSamples = %d numberOfOutputSamples (%s) = %d",
151 numberOfInputSamples, outputSignalName.Buffer(), numberOfOutputSamples);
152 }
153 }
154 uint32 numberOfInputDimensions = 0u;
155 uint32 numberOfOutputDimensions = 0u;
156 if (ok) {
157 ok = GetSignalNumberOfDimensions(InputSignals, 0u, numberOfInputDimensions);
158 }
159 if (ok) {
160 ok = GetSignalNumberOfDimensions(OutputSignals, n, numberOfOutputDimensions);
161 }
162 if (ok) {
163 ok = (numberOfInputDimensions == numberOfOutputDimensions);
164 }
165 if (ok) {
166 ok = (numberOfInputDimensions == 0u);
167 if (!ok) {
168 REPORT_ERROR(
169 ErrorManagement::ParametersError,
170 "The number of input and output signals dimensions shall be equal to 0. numberOfInputDimensions = %d numberOfOutputDimensions (%s) = %d",
171 numberOfInputDimensions, outputSignalName.Buffer(), numberOfOutputDimensions);
172 }
173 }
174 uint32 numberOfInputElements = 0u;
175 uint32 numberOfOutputElements = 0u;
176 if (ok) {
177 ok = GetSignalNumberOfElements(InputSignals, 0u, numberOfInputElements);
178 }
179 if (ok) {
180 ok = GetSignalNumberOfElements(OutputSignals, n, numberOfOutputElements);
181 }
182 if (ok) {
183 ok = (numberOfInputElements == numberOfOutputElements);
184 }
185 if (ok) {
186 ok = (numberOfInputElements == 1u);
187 }
188 if (!ok) {
189 REPORT_ERROR(ErrorManagement::ParametersError,
190 "The number of input and output signals elements shall be equal to 1. numberOfInputElements = %d numberOfOutputElements (%s) = %d",
191 numberOfInputElements, outputSignalName.Buffer(), numberOfOutputElements);
192 }
193 if (ok) {
194 outputSignals[n] = reinterpret_cast<uint32 *>(GetOutputSignalMemory(n));
195 }
196 }
197 if (ok) {
198 inputSignal = reinterpret_cast<uint32 *>(GetInputSignalMemory(0u));
199 }
200 }
201 return ok;
202}
203
204bool VariableGAMExample1::Execute() {
205 MARTe::uint32 n;
206 for (n = 0u; (n < numberOfOutputSignals); n++) {
207 *(outputSignals[n]) = gains[n] * *inputSignal;
208 }
209 return true;
210}
211
212CLASS_REGISTER(VariableGAMExample1, "")
213}
1$TestApp = {
2 Class = RealTimeApplication
3 +Functions = {
4 Class = ReferenceContainer
5 +GAMTimer = {
6 Class = IOGAM
7 InputSignals = {
8 Counter = {
9 DataSource = Timer
10 Type = uint32
11 }
12 Time = {
13 Frequency = 1
14 DataSource = Timer
15 Type = uint32
16 }
17 }
18 OutputSignals = {
19 Counter = {
20 DataSource = DDB1
21 Type = uint32
22 }
23 Time = {
24 DataSource = DDB1
25 Type = uint32
26 }
27 }
28 }
29 +GAMVariable1 = {
30 Class = VariableGAMExample1
31 Gains = {2}
32 InputSignals = {
33 Counter = {
34 DataSource = DDB1
35 Type = uint32
36 }
37 }
38 OutputSignals = {
39 GainCounter1 = {
40 DataSource = DDB1
41 Type = uint32
42 }
43 }
44 }
45 +GAMVariable2 = {
46 Class = VariableGAMExample1
47 Gains = {3, 4, 5}
48 InputSignals = {
49 Counter = {
50 DataSource = DDB1
51 Type = uint32
52 }
53 }
54 OutputSignals = {
55 GainCounter2 = {
56 DataSource = DDB1
57 Type = uint32
58 }
59 GainCounter3 = {
60 DataSource = DDB1
61 Type = uint32
62 }
63 GainCounter4 = {
64 DataSource = DDB1
65 Type = uint32
66 }
67 }
68 }
69 +GAMDisplay = {
70 Class = IOGAM
71 InputSignals = {
72 Counter = {
73 DataSource = DDB1
74 Type = uint32
75 }
76 GainCounter1 = {
77 DataSource = DDB1
78 Type = uint32
79 }
80 GainCounter2 = {
81 DataSource = DDB1
82 Type = uint32
83 }
84 GainCounter3 = {
85 DataSource = DDB1
86 Type = uint32
87 }
88 GainCounter4 = {
89 DataSource = DDB1
90 Type = uint32
91 }
92 }
93 OutputSignals = {
94 Counter = {
95 DataSource = LoggerDataSource
96 Type = uint32
97 }
98 GainCounter1 = {
99 DataSource = LoggerDataSource
100 Type = uint32
101 }
102 GainCounter2 = {
103 DataSource = LoggerDataSource
104 Type = uint32
105 }
106 GainCounter3 = {
107 DataSource = LoggerDataSource
108 Type = uint32
109 }
110 GainCounter4 = {
111 DataSource = LoggerDataSource
112 Type = uint32
113 }
114 }
115 }
116 }
117 +Data = {
118 Class = ReferenceContainer
119 DefaultDataSource = DDB1
120 +DDB1 = {
121 Class = GAMDataSource
122 }
123 +LoggerDataSource = {
124 Class = LoggerDataSource
125 }
126 +Timings = {
127 Class = TimingDataSource
128 }
129 +Timer = {
130 Class = LinuxTimer
131 SleepNature = "Default"
132 Signals = {
133 Counter = {
134 Type = uint32
135 }
136 Time = {
137 Type = uint32
138 }
139 }
140 }
141 }
142 +States = {
143 Class = ReferenceContainer
144 +State1 = {
145 Class = RealTimeState
146 +Threads = {
147 Class = ReferenceContainer
148 +Thread1 = {
149 Class = RealTimeThread
150 CPUs = 0x1
151 Functions = {GAMTimer GAMVariable1 GAMVariable2 GAMDisplay }
152 }
153 }
154 }
155 }
156 +Scheduler = {
157 Class = GAMScheduler
158 TimingDataSource = Timings
159 }
160}
Structure GAM
The following is an example of GAM which uses a (registered) structured signal in input and output.
1/**
2 * @file ModelGAMExample1.cpp
3 * @brief Source file for class ModelGAMExample1
4 * @date 09/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class ModelGAMExample1 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "IntrospectionT.h"
33#include "ModelGAMExample1.h"
34
35/*---------------------------------------------------------------------------*/
36/* Static definitions */
37/*---------------------------------------------------------------------------*/
38//Register the structures
39DECLARE_CLASS_MEMBER(ModelGAMExampleStructInner1, f1, float32, "", "");
40DECLARE_CLASS_MEMBER(ModelGAMExampleStructInner1, f2, float32, "", "");
41DECLARE_CLASS_MEMBER(ModelGAMExampleStructInner1, f3, float32, "[6]", "");
42//The array members must follow the naming convention CLASSNAME_MEMBERNAME_introspectionEntry
43static const MARTe::IntrospectionEntry* ModelGAMExampleStructInner1Entries[] = { &ModelGAMExampleStructInner1_f1_introspectionEntry,
44 &ModelGAMExampleStructInner1_f2_introspectionEntry, &ModelGAMExampleStructInner1_f3_introspectionEntry, 0 };
45//Finally declare the class as introspectable
46DECLARE_STRUCT_INTROSPECTION(ModelGAMExampleStructInner1, ModelGAMExampleStructInner1Entries)
47
48DECLARE_CLASS_MEMBER(ModelGAMExampleStructSignal, u1, uint32, "", "");
49DECLARE_CLASS_MEMBER(ModelGAMExampleStructSignal, s1, ModelGAMExampleStructInner1, "", "");
50DECLARE_CLASS_MEMBER(ModelGAMExampleStructSignal, s2, ModelGAMExampleStructInner1, "", "");
51//The array members must follow the naming convention CLASSNAME_MEMBERNAME_introspectionEntry
52static const MARTe::IntrospectionEntry* ModelGAMExampleStructSignalEntries[] = { &ModelGAMExampleStructSignal_u1_introspectionEntry,
53 &ModelGAMExampleStructSignal_s1_introspectionEntry, &ModelGAMExampleStructSignal_s2_introspectionEntry, 0 };
54//Finally declare the class as introspectable
55DECLARE_STRUCT_INTROSPECTION(ModelGAMExampleStructSignal, ModelGAMExampleStructSignalEntries)
56
57/*---------------------------------------------------------------------------*/
58/* Method definitions */
59/*---------------------------------------------------------------------------*/
60
61ModelGAMExample1::ModelGAMExample1() {
62 inputSignal = NULL_PTR(ModelGAMExampleStructSignal *);
63 outputSignal = NULL_PTR(ModelGAMExampleStructSignal *);
64}
65
66ModelGAMExample1::~ModelGAMExample1() {
67}
68
69bool ModelGAMExample1::CheckSignal(MARTe::SignalDirection signalDirection, MARTe::IntrospectionEntry introEntry, MARTe::uint32 signalIdx) {
70 using namespace MARTe;
71 TypeDescriptor signalMemberType = GetSignalType(signalDirection, signalIdx);
72 TypeDescriptor introMemberType = introEntry.GetMemberTypeDescriptor();
73 StreamString signalName;
74 bool ok = GetSignalName(signalDirection, signalIdx, signalName);
75 if (ok) {
76 ok = (signalMemberType == introMemberType);
77 if (!ok) {
78 const char8 * const memberTypeTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(signalMemberType);
79 const char8 * const introMemberTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(introMemberType);
80 REPORT_ERROR(ErrorManagement::ParametersError, "Output type signal mismatch = %s != %s for signal %s", memberTypeTypeStr, introMemberTypeStr,
81 signalName.Buffer());
82 }
83 }
84 if (ok) {
85 uint32 numberOfOutputSamples = 0u;
86 ok = GetSignalNumberOfSamples(signalDirection, signalIdx, numberOfOutputSamples);
87 if (ok) {
88 ok = (numberOfOutputSamples == 1u);
89 }
90 if (!ok) {
91 REPORT_ERROR(ErrorManagement::ParametersError, "The number of output signals samples shall be equal to 1. numberOfOutputSamples = %d for signal %s",
92 signalIdx, numberOfOutputSamples, signalName.Buffer());
93 }
94 }
95 uint32 introNumberOfElements = 1u;
96 if (ok) {
97 uint32 signalNumberOfDimensions = 0u;
98 uint8 introMemberNumberOfDimensions = introEntry.GetNumberOfDimensions();
99 ok = GetSignalNumberOfDimensions(signalDirection, signalIdx, signalNumberOfDimensions);
100 if (ok) {
101 ok = (signalNumberOfDimensions == introMemberNumberOfDimensions);
102 }
103 if (!ok) {
104 REPORT_ERROR(ErrorManagement::ParametersError, "Number of dimensions mismatch = %d != %d for signal %s", signalNumberOfDimensions,
105 introMemberNumberOfDimensions, signalName.Buffer());
106 ok = true;
107 }
108 if (ok) {
109 uint32 k;
110 for (k = 0; k < introMemberNumberOfDimensions; k++) {
111 introNumberOfElements *= introEntry.GetNumberOfElements(k);
112 }
113 }
114 }
115 if (ok) {
116 uint32 signalNumberOfElements = 0u;
117 ok = GetSignalNumberOfElements(signalDirection, signalIdx, signalNumberOfElements);
118 if (ok) {
119 ok = (signalNumberOfElements == introNumberOfElements);
120 }
121 if (!ok) {
122 REPORT_ERROR(ErrorManagement::ParametersError, "Number of elements mismatch = %d != %d for signal %s", signalNumberOfElements,
123 introNumberOfElements, signalName.Buffer());
124 }
125 }
126 return ok;
127}
128
129bool ModelGAMExample1::Setup() {
130 using namespace MARTe;
131 uint32 numberOfInputSignals = GetNumberOfInputSignals();
132 uint32 numberOfOutputSignals = GetNumberOfOutputSignals();
133 bool ok = (numberOfInputSignals == numberOfOutputSignals);
134 if (!ok) {
135 REPORT_ERROR(ErrorManagement::ParametersError, "The number of input signals shall be equal to the number of output signals. numberOfInputSignals = %d != numberOfOutputSignals ", numberOfInputSignals, numberOfOutputSignals);
136 }
137
138 ClassRegistryItem *cri = NULL_PTR(ClassRegistryItem *);
139 if (ok) {
140 cri = ClassRegistryDatabase::Instance()->Find("ModelGAMExampleStructSignal");
141 ok = (cri != NULL_PTR(ClassRegistryItem *));
142 if (!ok) {
143 REPORT_ERROR(ErrorManagement::FatalError, "ModelGAMExampleStructSignal is not registered!");
144 }
145 }
146 const Introspection *introspectionMainStruct = NULL_PTR(Introspection *);
147 if (ok) {
148 introspectionMainStruct = cri->GetIntrospection();
149 }
150 if (ok) {
151 cri = ClassRegistryDatabase::Instance()->Find("ModelGAMExampleStructInner1");
152 }
153 const Introspection *introspectionInnerStruct = NULL_PTR(Introspection *);
154 if (ok) {
155 introspectionInnerStruct = cri->GetIntrospection();
156 }
157
158 uint32 introspectionMainStructNumberOfMembers = 0u;
159 if (ok) {
160 //where +1 is the //u1
161 introspectionMainStructNumberOfMembers = introspectionInnerStruct->GetNumberOfMembers() * 2 + 1;
162 }
163 if (ok) {
164 //The structure has 7 signals
165 ok = (numberOfOutputSignals == introspectionMainStructNumberOfMembers);
166 if (!ok) {
167 REPORT_ERROR(ErrorManagement::ParametersError, "The number of output signals shall be equal to %d. numberOfOutputSignals = %d",
168 introspectionMainStructNumberOfMembers, numberOfOutputSignals);
169 }
170 }
171 //Check that all the properties match
172 if (ok) {
173 ok = CheckSignal(InputSignals, introspectionMainStruct->operator [](0), 0);
174 }
175 if (ok) {
176 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](0), 1);
177 }
178 if (ok) {
179 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](1), 2);
180 }
181 if (ok) {
182 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](2), 3);
183 }
184 if (ok) {
185 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](0), 4);
186 }
187 if (ok) {
188 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](1), 5);
189 }
190 if (ok) {
191 ok = CheckSignal(InputSignals, introspectionInnerStruct->operator [](2), 6);
192 }
193 if (ok) {
194 ok = CheckSignal(OutputSignals, introspectionMainStruct->operator [](0), 0);
195 }
196 if (ok) {
197 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](0), 1);
198 }
199 if (ok) {
200 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](1), 2);
201 }
202 if (ok) {
203 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](2), 3);
204 }
205 if (ok) {
206 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](0), 4);
207 }
208 if (ok) {
209 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](1), 5);
210 }
211 if (ok) {
212 ok = CheckSignal(OutputSignals, introspectionInnerStruct->operator [](2), 6);
213 }
214 if (ok) {
215 inputSignal = reinterpret_cast<ModelGAMExampleStructSignal *>(GetInputSignalMemory(0u));
216 }
217 if (ok) {
218 outputSignal = reinterpret_cast<ModelGAMExampleStructSignal *>(GetOutputSignalMemory(0u));
219 }
220 return ok;
221}
222
223bool ModelGAMExample1::Execute() {
224 MARTe::float32 gain1 = 1.02;
225 MARTe::float32 gain2 = 1.03;
226 (outputSignal->u1)++;
227 outputSignal->s1.f1 = gain1 * inputSignal->s1.f1;
228 outputSignal->s1.f2 = gain2 * inputSignal->s1.f2;
229 outputSignal->s1.f3[0] = inputSignal->s1.f1;
230 outputSignal->s1.f3[1] = -inputSignal->s1.f1;
231 outputSignal->s1.f3[2] = inputSignal->s1.f2;
232 outputSignal->s1.f3[3] = -inputSignal->s1.f2;
233 outputSignal->s1.f3[4] = inputSignal->s1.f1 + inputSignal->s1.f2;
234 outputSignal->s1.f3[5] = inputSignal->s1.f1 - inputSignal->s1.f2;
235 outputSignal->s2.f1 = gain1 * inputSignal->s2.f1;
236 outputSignal->s2.f2 = gain2 * inputSignal->s2.f2;
237 outputSignal->s2.f3[0] = inputSignal->s2.f1;
238 outputSignal->s2.f3[1] = -inputSignal->s2.f1;
239 outputSignal->s2.f3[2] = inputSignal->s2.f2;
240 outputSignal->s2.f3[3] = -inputSignal->s2.f2;
241 outputSignal->s2.f3[4] = inputSignal->s2.f1 - inputSignal->s2.f2;
242 outputSignal->s2.f3[5] = inputSignal->s2.f1 + inputSignal->s2.f2;
243 return true;
244}
245
246CLASS_REGISTER(ModelGAMExample1, "")
1$TestApp = {
2 Class = RealTimeApplication
3 +Functions = {
4 Class = ReferenceContainer
5 +GAMTimer = {
6 Class = IOGAM
7 InputSignals = {
8 Counter = {
9 DataSource = Timer
10 Type = uint32
11 }
12 Time = {
13 Frequency = 1
14 DataSource = Timer
15 Type = uint32
16 }
17 }
18 OutputSignals = {
19 Counter = {
20 DataSource = DDB1
21 Type = uint32
22 }
23 Time = {
24 DataSource = DDB1
25 Type = uint32
26 }
27 }
28 }
29 +GAMModel1 = {
30 Class = ModelGAMExample1
31 InputSignals = {
32 Model1 = {
33 DataSource = DDB1
34 Type = ModelGAMExampleStructSignal
35 Defaults = {
36 Model1.s1.f1 = 2
37 Model1.s1.f2 = 3
38 Model1.s1.f3 = {1, 2, 3, 4, 5, 6}
39 Model1.s2.f1 = -2
40 Model1.s2.f2 = -3
41 Model1.s2.f3 = {-1, -2, -3, -4, -5, -6}
42 }
43 MemberAliases = {
44 Model1.s2.f2 = Model1.s2.g2
45 }
46 }
47 }
48 OutputSignals = {
49 Model1 = {
50 DataSource = DDB1
51 Type = ModelGAMExampleStructSignal
52 MemberAliases = {
53 Model1.s2.f2 = Model1.s2.g2
54 }
55 }
56 }
57 }
58 +GAMDisplay = {
59 Class = IOGAM
60 InputSignals = {
61 Counter = {
62 DataSource = DDB1
63 Type = uint32
64 }
65 Model1U1 = {
66 DataSource = DDB1
67 Alias = "Model1.u1"
68 Type = uint32
69 }
70 Model1S1F1 = {
71 DataSource = DDB1
72 Alias = "Model1.s1.f1"
73 Type = float32
74 }
75 Model1S1F2 = {
76 DataSource = DDB1
77 Alias = "Model1.s1.f2"
78 Type = float32
79 }
80 Model1S1F3 = {
81 DataSource = DDB1
82 Alias = "Model1.s1.f3"
83 Type = float32
84 }
85 Model1S2F1 = {
86 DataSource = DDB1
87 Alias = "Model1.s2.f1"
88 Type = float32
89 }
90 Model1S2G2 = {
91 DataSource = DDB1
92 Alias = "Model1.s2.g2"
93 Type = float32
94 }
95 Model1S2F3 = {
96 DataSource = DDB1
97 Alias = "Model1.s2.f3"
98 Type = float32
99 }
100 }
101 OutputSignals = {
102 Counter = {
103 DataSource = LoggerDataSource
104 Type = uint32
105 }
106 Model1U1 = {
107 DataSource = LoggerDataSource
108 Type = uint32
109 }
110 Model1S1F1 = {
111 DataSource = LoggerDataSource
112 Type = float32
113 }
114 Model1S1F2 = {
115 DataSource = LoggerDataSource
116 Type = float32
117 }
118 Model1S1F3 = {
119 DataSource = LoggerDataSource
120 Type = float32
121 NumberOfDimensions = 1
122 NumberOfElements = 6
123 }
124 Model1S2F1 = {
125 DataSource = LoggerDataSource
126 Type = float32
127 }
128 Model1S2G2 = {
129 DataSource = LoggerDataSource
130 Type = float32
131 }
132 Model1S2F3 = {
133 DataSource = LoggerDataSource
134 Type = float32
135 NumberOfDimensions = 1
136 NumberOfElements = 6
137 }
138 }
139 }
140 }
141 +Data = {
142 Class = ReferenceContainer
143 DefaultDataSource = DDB1
144 +DDB1 = {
145 Class = GAMDataSource
146 }
147 +LoggerDataSource = {
148 Class = LoggerDataSource
149 }
150 +Timings = {
151 Class = TimingDataSource
152 }
153 +Timer = {
154 Class = LinuxTimer
155 SleepNature = "Default"
156 Signals = {
157 Counter = {
158 Type = uint32
159 }
160 Time = {
161 Type = uint32
162 }
163 }
164 }
165 }
166 +States = {
167 Class = ReferenceContainer
168 +State1 = {
169 Class = RealTimeState
170 +Threads = {
171 Class = ReferenceContainer
172 +Thread1 = {
173 Class = RealTimeThread
174 CPUs = 0x1
175 Functions = {GAMTimer GAMModel1 GAMDisplay }
176 }
177 }
178 }
179 }
180 +Scheduler = {
181 Class = GAMScheduler
182 TimingDataSource = Timings
183 }
184}
GAMGroup
The following is an example of GAMGroup which shares a Matrix with several GAMs.
1/**
2 * @file ParentGAMGroupExample1.cpp
3 * @brief Source file for class ParentGAMGroupExample1
4 * @date 06/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class ParentGAMGroupExample1 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "ParentGAMGroupExample1.h"
33
34/*---------------------------------------------------------------------------*/
35/* Static definitions */
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/* Method definitions */
40/*---------------------------------------------------------------------------*/
41namespace MARTe2Tutorial {
42ParentGAMGroupExample1::ParentGAMGroupExample1() {
43}
44
45ParentGAMGroupExample1::~ParentGAMGroupExample1() {
46
47}
48
49bool ParentGAMGroupExample1::Initialise(MARTe::StructuredDataI & data) {
50 using namespace MARTe;
51 bool ok = GAMGroup::Initialise(data);
52 matrixModelContext = MARTe::ReferenceT<GAMGroupSharedInfoExample1>(GlobalObjectsDatabase::Instance()->GetStandardHeap());
53 if (ok) {
54 ok = matrixModelContext.IsValid();
55 }
56 if (ok) {
57 ok = matrixModelContext->Initialise(data);
58 }
59 return ok;
60}
61
62bool ParentGAMGroupExample1::PrepareNextState(const MARTe::char8*, const MARTe::char8*) {
63 using namespace MARTe;
64 bool ok = matrixModelContext.IsValid();
65 if (ok) {
66 ok = SetContext(matrixModelContext);
67 }
68 return ok;
69}
70
71CLASS_REGISTER(ParentGAMGroupExample1, "")
72}
1/**
2 * @file ChildGAMGroupExample1.cpp
3 * @brief Source file for class ChildGAMGroupExample1
4 * @date 06/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class ChildGAMGroupExample1 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "ChildGAMGroupExample1.h"
33
34/*---------------------------------------------------------------------------*/
35/* Static definitions */
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/* Method definitions */
40/*---------------------------------------------------------------------------*/
41namespace MARTe2Tutorial {
42
43ChildGAMGroupExample1::ChildGAMGroupExample1() {
44 contextSet = false;
45 inputSignal = NULL_PTR(MARTe::Matrix<MARTe::uint32> *);
46 outputSignal = NULL_PTR(MARTe::Matrix<MARTe::uint32> *);
47}
48
49ChildGAMGroupExample1::~ChildGAMGroupExample1() {
50 if (inputSignal != NULL_PTR(MARTe::Matrix<MARTe::uint32> *)) {
51 delete inputSignal;
52 }
53 if (outputSignal != NULL_PTR(MARTe::Matrix<MARTe::uint32> *)) {
54 delete outputSignal;
55 }
56}
57
58bool ChildGAMGroupExample1::Setup() {
59 using namespace MARTe;
60 uint32 numberOfInputSignals = GetNumberOfInputSignals();
61 uint32 numberOfOutputSignals = GetNumberOfOutputSignals();
62 bool ok = (numberOfInputSignals == numberOfOutputSignals);
63 if (ok) {
64 ok = (numberOfOutputSignals == 1u);
65 if (!ok) {
66 REPORT_ERROR(ErrorManagement::ParametersError,
67 "The number of input and output signals shall be equal to 1. numberOfInputSignals = %d numberOfOutputSignals = %d",
68 numberOfInputSignals, numberOfOutputSignals);
69 }
70 }
71 if (ok) {
72 TypeDescriptor inputSignalType = GetSignalType(InputSignals, 0u);
73 TypeDescriptor outputSignalType = GetSignalType(OutputSignals, 0u);
74 ok = (inputSignalType == outputSignalType);
75 if (ok) {
76 ok = (inputSignalType == UnsignedInteger32Bit);
77 }
78 if (!ok) {
79 const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
80 const char8 * const outputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(outputSignalType);
81 REPORT_ERROR(ErrorManagement::ParametersError,
82 "The type of the input and output signal shall be uint32. inputSignalType = %s outputSignalType = %s", inputSignalTypeStr,
83 outputSignalTypeStr);
84 }
85 }
86 if (ok) {
87 uint32 numberOfInputSamples = 0u;
88 uint32 numberOfOutputSamples = 0u;
89 ok = GetSignalNumberOfSamples(InputSignals, 0u, numberOfInputSamples);
90 if (ok) {
91 ok = GetSignalNumberOfSamples(OutputSignals, 0u, numberOfOutputSamples);
92 }
93 if (ok) {
94 ok = (numberOfInputSamples == numberOfOutputSamples);
95 }
96 if (ok) {
97 ok = (numberOfInputSamples == 1u);
98 }
99 if (!ok) {
100 REPORT_ERROR(ErrorManagement::ParametersError,
101 "The number of input and output signals samples shall be equal to 1. numberOfInputSamples = %d numberOfOutputSamples = %d",
102 numberOfInputSamples, numberOfOutputSamples);
103 }
104 }
105 if (ok) {
106 uint32 numberOfInputDimensions = 0u;
107 uint32 numberOfOutputDimensions = 0u;
108 ok = GetSignalNumberOfDimensions(InputSignals, 0u, numberOfInputDimensions);
109 if (ok) {
110 ok = GetSignalNumberOfDimensions(OutputSignals, 0u, numberOfOutputDimensions);
111 }
112 if (ok) {
113 ok = (numberOfInputDimensions == numberOfOutputDimensions);
114 }
115 if (ok) {
116 ok = (numberOfInputDimensions == 1u);
117 }
118 if (!ok) {
119 REPORT_ERROR(ErrorManagement::ParametersError,
120 "The number of input and output signals dimensions shall be equal to 1. numberOfInputDimensions = %d numberOfOutputDimensions = %d",
121 numberOfInputDimensions, numberOfOutputDimensions);
122 }
123 }
124 return ok;
125
126}
127
128bool ChildGAMGroupExample1::SetContext(ConstReference context) {
129 using namespace MARTe;
130
131 matrixModelContext = context;
132 contextSet = context.IsValid();
133 bool ok = contextSet;
134 //Check that the matrix dimensions are valid.
135 uint32 numberOfInputElements = 0u;
136 uint32 numberOfOutputElements = 0u;
137 if (ok) {
138 ok = GetSignalNumberOfElements(InputSignals, 0u, numberOfInputElements);
139 if (ok) {
140 ok = GetSignalNumberOfElements(OutputSignals, 0u, numberOfOutputElements);
141 }
142 if (ok) {
143 ok = (numberOfInputElements == matrixModelContext->matrixModel->GetNumberOfRows());
144 }
145 if (ok) {
146 ok = (numberOfInputElements == numberOfOutputElements);
147 }
148 if (!ok) {
149 REPORT_ERROR(ErrorManagement::ParametersError,
150 "The number of input and output signals elements shall be equal. numberOfInputElements = %d numberOfOutputElements = %d",
151 numberOfInputElements, numberOfOutputElements);
152 }
153 }
154 if (ok) {
155 inputSignal = new Matrix<uint32>(reinterpret_cast<uint32 *>(GetInputSignalMemory(0u)), numberOfInputElements, 1);
156 outputSignal = new Matrix<uint32>(reinterpret_cast<uint32 *>(GetOutputSignalMemory(0u)), numberOfOutputElements, 1);
157 }
158
159 return contextSet;
160}
161
162bool ChildGAMGroupExample1::Execute() {
163 using namespace MARTe;
164 if (contextSet) {
165 matrixModelContext->matrixModel->Product(*inputSignal, *outputSignal);
166 }
167 return contextSet;
168}
169
170CLASS_REGISTER(ChildGAMGroupExample1, "")
171}
1/**
2 * @file ChildGAMGroupExample2.cpp
3 * @brief Source file for class ChildGAMGroupExample2
4 * @date 06/04/2018
5 * @author Andre Neto
6 *
7 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
8 * the Development of Fusion Energy ('Fusion for Energy').
9 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
10 * by the European Commission - subsequent versions of the EUPL (the "Licence")
11 * You may not use this work except in compliance with the Licence.
12 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
13 *
14 * @warning Unless required by applicable law or agreed to in writing,
15 * software distributed under the Licence is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the Licence permissions and limitations under the Licence.
18
19 * @details This source file contains the definition of all the methods for
20 * the class ChildGAMGroupExample2 (public, protected, and private). Be aware that some
21 * methods, such as those inline could be defined on the header file, instead.
22 */
23
24/*---------------------------------------------------------------------------*/
25/* Standard header includes */
26/*---------------------------------------------------------------------------*/
27
28/*---------------------------------------------------------------------------*/
29/* Project header includes */
30/*---------------------------------------------------------------------------*/
31#include "AdvancedErrorManagement.h"
32#include "ChildGAMGroupExample2.h"
33
34/*---------------------------------------------------------------------------*/
35/* Static definitions */
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/* Method definitions */
40/*---------------------------------------------------------------------------*/
41namespace MARTe2Tutorial {
42
43ChildGAMGroupExample2::ChildGAMGroupExample2() {
44 contextSet = false;
45 inputSignal = NULL_PTR(MARTe::Matrix<MARTe::uint32> *);
46 outputSignal = NULL_PTR(MARTe::Matrix<MARTe::uint32> *);
47 transposedModel = NULL_PTR(MARTe::Matrix<MARTe::uint32> *);
48}
49
50ChildGAMGroupExample2::~ChildGAMGroupExample2() {
51 if (inputSignal != NULL_PTR(MARTe::Matrix<MARTe::uint32> *)) {
52 delete inputSignal;
53 }
54 if (outputSignal != NULL_PTR(MARTe::Matrix<MARTe::uint32> *)) {
55 delete outputSignal;
56 }
57 if (transposedModel != NULL_PTR(MARTe::Matrix<MARTe::uint32> *)) {
58 delete transposedModel;
59 }
60}
61
62bool ChildGAMGroupExample2::Setup() {
63 using namespace MARTe;
64 uint32 numberOfInputSignals = GetNumberOfInputSignals();
65 uint32 numberOfOutputSignals = GetNumberOfOutputSignals();
66 bool ok = (numberOfInputSignals == numberOfOutputSignals);
67 if (ok) {
68 ok = (numberOfOutputSignals == 1u);
69 if (!ok) {
70 REPORT_ERROR(ErrorManagement::ParametersError,
71 "The number of input and output signals shall be equal to 1. numberOfInputSignals = %d numberOfOutputSignals = %d",
72 numberOfInputSignals, numberOfOutputSignals);
73 }
74 }
75 if (ok) {
76 TypeDescriptor inputSignalType = GetSignalType(InputSignals, 0u);
77 TypeDescriptor outputSignalType = GetSignalType(OutputSignals, 0u);
78 ok = (inputSignalType == outputSignalType);
79 if (ok) {
80 ok = (inputSignalType == UnsignedInteger32Bit);
81 }
82 if (!ok) {
83 const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
84 const char8 * const outputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(outputSignalType);
85 REPORT_ERROR(ErrorManagement::ParametersError,
86 "The type of the input and output signal shall be uint32. inputSignalType = %s outputSignalType = %s", inputSignalTypeStr,
87 outputSignalTypeStr);
88 }
89 }
90 if (ok) {
91 uint32 numberOfInputSamples = 0u;
92 uint32 numberOfOutputSamples = 0u;
93 ok = GetSignalNumberOfSamples(InputSignals, 0u, numberOfInputSamples);
94 if (ok) {
95 ok = GetSignalNumberOfSamples(OutputSignals, 0u, numberOfOutputSamples);
96 }
97 if (ok) {
98 ok = (numberOfInputSamples == numberOfOutputSamples);
99 }
100 if (ok) {
101 ok = (numberOfInputSamples == 1u);
102 }
103 if (!ok) {
104 REPORT_ERROR(ErrorManagement::ParametersError,
105 "The number of input and output signals samples shall be equal to 1. numberOfInputSamples = %d numberOfOutputSamples = %d",
106 numberOfInputSamples, numberOfOutputSamples);
107 }
108 }
109 if (ok) {
110 uint32 numberOfInputDimensions = 0u;
111 uint32 numberOfOutputDimensions = 0u;
112 ok = GetSignalNumberOfDimensions(InputSignals, 0u, numberOfInputDimensions);
113 if (ok) {
114 ok = GetSignalNumberOfDimensions(OutputSignals, 0u, numberOfOutputDimensions);
115 }
116 if (ok) {
117 ok = (numberOfInputDimensions == numberOfOutputDimensions);
118 }
119 if (ok) {
120 ok = (numberOfInputDimensions == 1u);
121 }
122 if (!ok) {
123 REPORT_ERROR(ErrorManagement::ParametersError,
124 "The number of input and output signals dimensions shall be equal to 1. numberOfInputDimensions = %d numberOfOutputDimensions = %d",
125 numberOfInputDimensions, numberOfOutputDimensions);
126 }
127 }
128 return ok;
129
130}
131
132bool ChildGAMGroupExample2::SetContext(ConstReference context) {
133 using namespace MARTe;
134
135 matrixModelContext = context;
136 contextSet = context.IsValid();
137 bool ok = contextSet;
138 //Check that the matrix dimensions are valid.
139 uint32 numberOfInputElements = 0u;
140 uint32 numberOfOutputElements = 0u;
141 if (ok) {
142 ok = GetSignalNumberOfElements(InputSignals, 0u, numberOfInputElements);
143 if (ok) {
144 ok = GetSignalNumberOfElements(OutputSignals, 0u, numberOfOutputElements);
145 }
146 if (ok) {
147 ok = (numberOfInputElements == matrixModelContext->matrixModel->GetNumberOfRows());
148 }
149 if (ok) {
150 ok = (numberOfInputElements == numberOfOutputElements);
151 }
152 if (!ok) {
153 REPORT_ERROR(ErrorManagement::ParametersError,
154 "The number of input and output signals elements shall be equal. numberOfInputElements = %d numberOfOutputElements = %d",
155 numberOfInputElements, numberOfOutputElements);
156 }
157 }
158 if (ok) {
159 inputSignal = new Matrix<uint32>(reinterpret_cast<uint32 *>(GetInputSignalMemory(0u)), numberOfInputElements, 1);
160 outputSignal = new Matrix<uint32>(reinterpret_cast<uint32 *>(GetOutputSignalMemory(0u)), numberOfOutputElements, 1);
161 transposedModel = new Matrix<uint32>(numberOfInputElements, numberOfInputElements);
162 }
163
164 return contextSet;
165}
166
167bool ChildGAMGroupExample2::Execute() {
168 using namespace MARTe;
169 if (contextSet) {
170 matrixModelContext->matrixModel->Transpose(*transposedModel);
171 transposedModel->Product(*inputSignal, *outputSignal);
172 }
173 return contextSet;
174}
175
176CLASS_REGISTER(ChildGAMGroupExample2, "")
177}
1$TestApp = {
2 Class = RealTimeApplication
3 +Functions = {
4 Class = ReferenceContainer
5 +GAMTimer = {
6 Class = IOGAM
7 InputSignals = {
8 Counter = {
9 DataSource = Timer
10 Type = uint32
11 }
12 Time = {
13 Frequency = 1
14 DataSource = Timer
15 Type = uint32
16 }
17 }
18 OutputSignals = {
19 Counter = {
20 DataSource = DDB1
21 Type = uint32
22 }
23 Time = {
24 DataSource = DDB1
25 Type = uint32
26 }
27 }
28 }
29 +GAMFixed1 = {
30 Class = FixedGAMExample1
31 Gain = 2
32 InputSignals = {
33 Counter = {
34 DataSource = DDB1
35 Type = uint32
36 }
37 }
38 OutputSignals = {
39 GainCounter = {
40 DataSource = DDB1
41 Type = uint32
42 }
43 }
44 }
45 +GAMGroup1 = {
46 Class = ParentGAMGroupExample1
47 Model = {{2, 0, 0}, {0, 3, 0}, {1, 0, 4}}
48 +GAMChild1 = {
49 Class = ChildGAMGroupExample1
50 InputSignals = {
51 Signal3 = {
52 DataSource = DDB1
53 Type = uint32
54 NumberOfDimensions = 1
55 NumberOfElements = 3
56 }
57 }
58 OutputSignals = {
59 Signal1 = {
60 DataSource = DDB1
61 Type = uint32
62 NumberOfDimensions = 1
63 NumberOfElements = 3
64 Default = {1, 1, 1}
65 }
66 }
67 }
68 +GAMChild2 = {
69 Class = ChildGAMGroupExample2
70 InputSignals = {
71 Signal1 = {
72 DataSource = DDB1
73 Type = uint32
74 NumberOfDimensions = 1
75 NumberOfElements = 3
76 }
77 }
78 OutputSignals = {
79 Signal2 = {
80 DataSource = DDB1
81 Type = uint32
82 NumberOfDimensions = 1
83 NumberOfElements = 3
84 Default = {1, 1, 1}
85 }
86 }
87 }
88 +GAMChild3 = {
89 Class = ChildGAMGroupExample1
90 InputSignals = {
91 Signal2 = {
92 DataSource = DDB1
93 Type = uint32
94 NumberOfDimensions = 1
95 NumberOfElements = 3
96 }
97 }
98 OutputSignals = {
99 Signal3 = {
100 DataSource = DDB1
101 Type = uint32
102 NumberOfDimensions = 1
103 NumberOfElements = 3
104 Default = {1, 1, 1}
105 }
106 }
107 }
108 }
109 +GAMDisplay = {
110 Class = IOGAM
111 InputSignals = {
112 Counter = {
113 DataSource = DDB1
114 Type = uint32
115 }
116 GainCounter = {
117 DataSource = DDB1
118 Type = uint32
119 }
120 Signal1 = {
121 DataSource = DDB1
122 Type = uint32
123 }
124 Signal2 = {
125 DataSource = DDB1
126 Type = uint32
127 }
128 Signal3 = {
129 DataSource = DDB1
130 Type = uint32
131 }
132 }
133 OutputSignals = {
134 Counter = {
135 DataSource = LoggerDataSource
136 Type = uint32
137 }
138 GainCounter = {
139 DataSource = LoggerDataSource
140 Type = uint32
141 }
142 Signal1 = {
143 DataSource = LoggerDataSource
144 Type = uint32
145 NumberOfElements = 3
146 NumberOfDimensions = 1
147 }
148 Signal2 = {
149 DataSource = LoggerDataSource
150 Type = uint32
151 NumberOfElements = 3
152 NumberOfDimensions = 1
153 }
154 Signal3 = {
155 DataSource = LoggerDataSource
156 Type = uint32
157 NumberOfElements = 3
158 NumberOfDimensions = 1
159 }
160 }
161 }
162 }
163 +Data = {
164 Class = ReferenceContainer
165 DefaultDataSource = DDB1
166 +DDB1 = {
167 Class = GAMDataSource
168 }
169 +LoggerDataSource = {
170 Class = LoggerDataSource
171 }
172 +Timings = {
173 Class = TimingDataSource
174 }
175 +Timer = {
176 Class = LinuxTimer
177 SleepNature = "Default"
178 Signals = {
179 Counter = {
180 Type = uint32
181 }
182 Time = {
183 Type = uint32
184 }
185 }
186 }
187 }
188 +States = {
189 Class = ReferenceContainer
190 +State1 = {
191 Class = RealTimeState
192 +Threads = {
193 Class = ReferenceContainer
194 +Thread1 = {
195 Class = RealTimeThread
196 CPUs = 0x1
197 //Note that only the GAMGroup1 has to be scheduled for execution (all the GAMGroup child GAMs will be automatically executed)
198 Functions = {GAMTimer GAMFixed1 GAMGroup1 GAMDisplay }
199 }
200 }
201 }
202 }
203 +Scheduler = {
204 Class = GAMScheduler
205 TimingDataSource = Timings
206 }
207}
Instructions on how to compile and execute the examples can be found here.