Data-driven applications¶
Using the mechanisms described in the Objects and References and in the Object configuration sections, together with a special syntax, the framework is capable of instantiating a tree of objects based on a configuration stream (e.g. a file).
Syntax¶
The Initialise
method of the ReferenceContainer will look for any name starting with the character +
.
When the +
character is found, the property Class=LIB::CLASS
shall exist in the subtree. LIB
is the name of the shared library holding the compiled CLASS
.
The CLASS
shall inherit from Object
and shall implement the macros defined in the Objects section.
If LIB
is not defined, it is assumed that the class was already registered (e.g. because it was statically linked) or that the name of the library is equal to the name of the class.
This process is recursively repeated and a tree of Objects is built. The name of the Object is automatically set to the name of the node.
In the following example, an object named A
, of type AClass
, would be created, together with another object of type AClass
, named B
, and with an object of type CClass
named C
. It is assumed that the AClass
inherits from ReferenceContainer
and that, as a consequence, calling Get(0)
on the instance named B
would return a Reference
to C
.
+A = {
Class = AClass
}
+B = {
Class = AClass
+C = {
Class = ALIB::CClass
}
}
The ObjectRegistryDatabase is a ReferenceContainer
which offers a database to hold and link all the Objects
defined in a given configuration stream.
The Find
method can be used to find any of the instantiated Objects
in the tree.
A dot . is used as the path separator.
...
ObjectRegistryDatabase *ord = ObjectRegistryDatabase::Instance();
ReferenceT<CClass> obj = ord->Find("B.C");
if (obj.IsValid()) {
...
If the node name starts with a $
, besides implementing the same behaviour described before for the +
, it will also set the node as a search domain.
This means that when using the ObjectRegistryDatabase Find
method, the :
symbol will allow to perform searches related to a given root domain. For example:
+A = {
Class = AClass
$B = {
Class = BClass
+C = {
Class = CClass
+E = {
Class = EClass
}
}
+D = {
Class = DClass
+F = {
Class = CClass
}
}
}
}
Would allow to Find C
, C.E
, D
and D.F
, using B
as the root domain (see the example below).
Note
Other characters can also be set as a identifiers for the new Object creation and for the setting of a given Object as the root domain. See the methods AddBuildToken
, RemoveBuildToken
, IsBuildToken
, AddDomainToken
, RemoveDomainToken
and IsDomainToken
in ReferenceContainer.
Reading C structures¶
If a C struct
has been registered in the ClassRegistryDatabase it is possible to directly map the contents of a configuration node to the registered structure (see example below).
To read/write a registered structure an AnyType which describes the registered type must be created:
struct AStruct {
float32 f1;
float32 f2;
};
///Register the struct with the required macros.
AStruct aStruct1;
AStruct aStruct2;
ClassRegistryItem * registeredStructClassProperties = ClassRegistryDatabase::Instance()->Find("AStruct");
...
ClassUID registeredStructUID = registeredStructClassProperties->GetUniqueIdentifier();
TypeDescriptor registeredStructTypeDescriptor(false, registeredStructUID);
AnyType registeredStructAnyType1 = AnyType(registeredStructTypeDescriptor, 0u, &aStruct1);
AnyType registeredStructAnyType2 = AnyType(registeredStructTypeDescriptor, 0u, &aStruct2);
...
data.Read("AStruct1", registeredStructAnyType1);
data.Read("AStruct2", registeredStructAnyType2);
...
if (aStruct1.f1 == aStruct2.f1) {
...
Note
Only the types and structure of the configuration tree must match with the types and structure of the C struct
, i.e. the names are ignored.
Reading data-driven C structures¶
The IntrospectionStructure class can also be used to dynamically create and register structures using a standard configuration file.
+Types = {
Class = ReferenceContainer
+GainFromIntroStructure = {
Class = IntrospectionStructure
gain1 = {
Type = float32
NumberOfElements = {1}
}
gain2 = {
Type = float32
NumberOfElements = {1}
}
gain3 = {
Type = float32
NumberOfElements = {6}
}
}
+GainsFromIntroStructure = {
Class = IntrospectionStructure
lowGains = {
Type = GainFromIntroStructure
}
...
Preprocessing¶
The MARTe configuration files can be preprocessed using the C
preprocessor directives (e.g. #include
and #define
).
This strategy can be used to write modular configuration settings (see example below). Note that the files must first be processed with a Makefile.inc
and a Makefile.cfg
, following the MARTe Makefile structure:
#Named of the unit files to be compiled. It will generate files named *_Gen.cfg (e.g. RTApp-6_Gen.cfg)
OBJSX=RTApp-6.x
#Location of the Build directory where the configuration file will be written to
BUILD_DIR?=.
#Location of the MakeDefaults directory.
#Note that the MARTe2_DIR environment variable
#must have been exported before
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
CFLAGS += -DENABLE_WEB_BROWSING
all: $(OBJS)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
export TARGET=cfg
include Makefile.inc
Postprocessing¶
As of v1.7.0, the StandardParser also allows to post-process and assign simple mathematical expressions to nodes in the tree. The syntax is NODE=(OUTPUT_VAR_TYPE|EXPRESSION), where OUTPUT_VAR_TYPE is the output variable type (e.g. uint32) and EXPRESSION is the mathematical expression to be executed.
The variables in the expression can reference to other nodes in the configuration tree, noting that the expressions are executed in order (top to bottom) and that the names in the node path cannot include the + sign.
int a =3;
Parameters = {
T1_FREQUENCY = (uint32)10000
T2_FREQUENCY = (uint32)1
SAMPLES = (uint32|"Parameters.T1_FREQUENCY / Parameters.T2_FREQUENCY")
}
+TestApp = {
Class = RealTimeApplication
+Functions = {
Class = ReferenceContainer
+GAMTimer = {
Class = IOGAM
InputSignals = {
Time = {
Frequency = (uint32|"(uint32)2 * Parameters.T1_FREQUENCY")
...
Examples¶
The following example shows how to load an application from a configuration file.
Note that Objects can be nested inside other Objects (provided that the container Object inherits from ReferenceContainer and that it calls ReferenceContainer::Initialise on its Initialise method).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | /**
* @file ConfigurationExample4.cpp
* @brief Source file for class ConfigurationExample4
* @date 14/03/2018
* @author Andre' Neto
*
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
* the Development of Fusion Energy ('Fusion for Energy').
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence")
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
*
* @warning Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an "AS IS"
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence permissions and limitations under the Licence.
* @details This source file contains the definition of all the methods for
* the class ConfigurationExample4 (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ClassRegistryDatabase.h"
#include "ConfigurationDatabase.h"
#include "ErrorLoggerExample.h"
#include "Matrix.h"
#include "Object.h"
#include "ObjectRegistryDatabase.h"
#include "Reference.h"
#include "ReferenceT.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "Vector.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe2Tutorial {
/**
* Configuration structures
*/
struct Gains {
MARTe::float32 gain1;
MARTe::float32 gain2;
};
struct Waveforms {
MARTe::float32 *times;
MARTe::float32 *values;
};
/**
* @brief A MARTe::Object that will be inserted (data-driven) inside the ControllerEx1.
*/
class ReferenceEx1: public MARTe::Object {
public:
CLASS_REGISTER_DECLARATION()
ReferenceEx1 () {
waveform.times = NULL;
waveform.values = NULL;
}
virtual ~ReferenceEx1 () {
if (waveform.times != NULL) {
delete [] waveform.times;
}
if (waveform.values != NULL) {
delete [] waveform.values;
}
if (GetName() != NULL) {
REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "No more references pointing"
" at %s [%s]. The Object will be safely deleted.", GetName(), GetClassProperties()->GetName());
}
}
/**
* Read the waveform properties
* Times = {0 0.1 0.2 1}
* Values = {1 2 3 4}
*/
virtual bool Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = Object::Initialise(data);
if (ok) {
ok = ReadArray(data, "Times", waveform.times);
}
if (ok) {
ok = ReadArray(data, "Values", waveform.values);
}
return ok;
}
private:
bool ReadArray(MARTe::StructuredDataI &data, const MARTe::char8 * const arrayName, MARTe::float32 *&dest) {
using namespace MARTe;
if (dest != NULL) {
delete [] dest;
}
AnyType arrayDescription = data.GetType(arrayName);
bool ok = arrayDescription.GetDataPointer() != NULL_PTR(void *);
uint32 numberOfElements = 0u;
if (ok) {
numberOfElements = arrayDescription.GetNumberOfElements(0u);
ok = (numberOfElements > 0u);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "No elements defined in the array with name %s", arrayName);
}
}
if (ok) {
dest = new float32[numberOfElements];
Vector<float32> readVector(dest, numberOfElements);
ok = data.Read(arrayName, readVector);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Array set to %f", readVector);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the array with name %s", arrayName);
}
}
return ok;
}
Waveforms waveform;
};
CLASS_REGISTER(ReferenceEx1, "")
/**
* @brief A MARTe::Object class will be automatically registered into the ClassRegistryDatabase.
*/
class ControllerEx1: public MARTe::ReferenceContainer {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief NOOP.
*/
ControllerEx1 () {
}
virtual ~ControllerEx1 () {
if (GetName() != NULL) {
REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "No more references pointing at %s [%s]. "
"The Object will be safely deleted.", GetName(), GetClassProperties()->GetName());
}
}
/**
* Read all the properties which are organised inside a tree
* Gains = {
* Low = {
* Gain1 = -1.0;
* Gain2 = -3.0;
* }
* High = {
* Gain1 = 7.0;
* Gain2 = 9.0;
* }
* }
* +SlowReference = {
* Class = ReferenceEx1
* Times = {0 0.1 0.2 1}
* Values = {1 2 3 4}
* }
* +FastReference = {
* Class = ReferenceEx1
* Times = {0 0.1 0.2 1}
* Values = {1 4 8 12}
* }
*/
virtual bool Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = ReferenceContainer::Initialise(data);
if (ok) {
//Move in the tree
ok = data.MoveRelative("Gains");
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move to the Gains section");
}
}
if (ok) {
ok = data.MoveRelative("Low");
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move to the Gains.Low section");
}
}
if (ok) {
ok = data.Read("Gain1", lowGains.gain1);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains.Low.Gain1 = %f", lowGains.gain1);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gain1");
}
}
if (ok) {
ok = data.Read("Gain2", lowGains.gain2);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains.Low.Gain1 = %f", lowGains.gain2);
}
else {
}
}
if (ok) {
ok = data.MoveToAncestor(1u);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move back to the Gains section");
}
}
if (ok) {
ok = data.MoveRelative("High");
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not move to the Gains.High section");
}
}
if (ok) {
ok = data.Read("Gain1", highGains.gain1);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains.High.Gain1 = %f", highGains.gain1);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gain1");
}
}
if (ok) {
ok = data.Read("Gain2", highGains.gain2);
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains.High.Gain1 = %f", highGains.gain2);
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gain2");
}
}
if (ok) {
//Check if the waveforms were declared
slowWaveform = Get(0);
ok = slowWaveform.IsValid();
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not find the SlowWaveform");
}
}
if (ok) {
//Check if the waveforms were declared
fastWaveform = Get(1);
ok = fastWaveform.IsValid();
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not find the FastWaveform");
}
}
return ok;
}
/**
* A list of properties.
*/
Gains lowGains;
Gains highGains;
MARTe::ReferenceT<ReferenceEx1> slowWaveform;
MARTe::ReferenceT<ReferenceEx1> fastWaveform;
};
CLASS_REGISTER(ControllerEx1, "")
}
int main(int argc, char **argv) {
using namespace MARTe;
using namespace MARTe2Tutorial;
SetErrorProcessFunction(&ErrorProcessExampleFunction);
StreamString configurationCfg = ""
"+ControllerInstance1 = {\n"
" Class = ControllerEx1\n"
" Gains = {\n"
" Low = {\n"
" Gain1 = -1.0\n"
" Gain2 = -3.0\n"
" }\n"
" High = {\n"
" Gain1 = 7.0\n"
" Gain2 = 9.0\n"
" }\n"
" }\n"
" +SlowWaveform = {\n"
" Class = ReferenceEx1\n"
" Times = {0 0.1 0.2 1}\n"
" Values = {1 2 3 4}\n"
" }\n"
" +FastWaveform = {\n"
" Class = ReferenceEx1\n"
" Times = {0 0.1 0.2 1}\n"
" Values = {1 4 6 8}\n"
" }\n"
"}";
REPORT_ERROR_STATIC(ErrorManagement::Information, "Loading CFG:\n%s",
configurationCfg.Buffer());
ConfigurationDatabase cdb;
StreamString err;
//Force the string to be seeked to the beginning.
configurationCfg.Seek(0LLU);
StandardParser parser(configurationCfg, cdb, &err);
bool ok = parser.Parse();
if (ok) {
//After parsing the tree is pointing at the last leaf
cdb.MoveToRoot();
ok = ObjectRegistryDatabase::Instance()->Initialise(cdb);
}
else {
StreamString errPrint;
errPrint.Printf("Failed to parse %s", err.Buffer());
REPORT_ERROR_STATIC(ErrorManagement::ParametersError,
errPrint.Buffer());
}
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information,
"Successfully loaded the configuration file");
}
return 0;
}
|
This example highlights how the Find method can be used to search for Objects in the ObjectRegistryDatabase. Note how the reference G.H is found with respect to B.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /**
* @file ConfigurationExample5.cpp
* @brief Source file for class ConfigurationExample5
* @date 14/03/2018
* @author Andre' Neto
*
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
* the Development of Fusion Energy ('Fusion for Energy').
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence")
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
*
* @warning Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an "AS IS"
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence permissions and limitations under the Licence.
* @details This source file contains the definition of all the methods for
* the class ConfigurationExample5 (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ClassRegistryDatabase.h"
#include "ConfigurationDatabase.h"
#include "ErrorLoggerExample.h"
#include "JsonParser.h"
#include "Matrix.h"
#include "Object.h"
#include "ObjectRegistryDatabase.h"
#include "Reference.h"
#include "ReferenceT.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "Vector.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv) {
using namespace MARTe;
SetErrorProcessFunction(&ErrorProcessExampleFunction);
StreamString configurationCfg = ""
"+A = {\n"
" Class = ReferenceContainer\n"
" $B = {\n"
" Class = ReferenceContainer\n"
" +C = {"
" Class = ReferenceContainer\n"
" +F = {"
" Class = ReferenceContainer\n"
" }\n"
" }\n"
" +G = {"
" Class = ReferenceContainer\n"
" +H = {"
" Class = ReferenceContainer\n"
" }\n"
" }\n"
" }\n"
" +D = {\n"
" Class = ReferenceContainer\n"
" +E = {\n"
" Class = ReferenceContainer\n"
" }\n"
" }\n"
"}\n";
REPORT_ERROR_STATIC(ErrorManagement::Information, "Loading CFG:\n%s",
configurationCfg.Buffer());
ConfigurationDatabase cdb;
StreamString err;
//Force the string to be seeked to the beginning.
configurationCfg.Seek(0LLU);
StandardParser parser(configurationCfg, cdb, &err);
bool ok = parser.Parse();
ObjectRegistryDatabase *ord = ObjectRegistryDatabase::Instance();
if (ok) {
//After parsing the tree is pointing at the last leaf
cdb.MoveToRoot();
ok = ord->Initialise(cdb);
}
else {
StreamString errPrint;
errPrint.Printf("Failed to parse %s", err.Buffer());
REPORT_ERROR_STATIC(ErrorManagement::ParametersError,
errPrint.Buffer());
}
if (ok) {
//Find A.D.E
const char8 * const path = "A.D.E";
ReferenceT<ReferenceContainer> rc = ord->Find(path);
ok = rc.IsValid();
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Found %s", path);
}
else {
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
"Could not find %s !", path);
}
}
if (ok) {
//Find A.B.E
const char8 * const path = "A.B.E";
ReferenceT<ReferenceContainer> rc = ord->Find(path);
ok = !rc.IsValid();
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information,
"Could not find %s as expected", path);
}
else {
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
"Should not have found %s !", path);
}
}
if (ok) {
//Find D.E as relative path to F
const char8 * const path = "A.B.C.F";
ReferenceT<ReferenceContainer> rc = ord->Find(path);
ok = rc.IsValid();
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Found %s", path);
//: Moves up to the next domain (which $B)
const char8 * const path = ":G.H";
//Note that the search is relative to rc (which is currently @ A.B.C.F)
rc = ord->Find(path, rc);
ok = rc.IsValid();
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Found %s",
path);
}
else {
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
"Could not find %s !", path);
}
}
else {
REPORT_ERROR_STATIC(ErrorManagement::FatalError,
"Could not find %s !", path);
}
}
return 0;
}
|
This example shows how to read and write directly from a registered C struct
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | /**
* @file ConfigurationExample6.cpp
* @brief Source file for class ConfigurationExample6
* @date 08/04/2018
* @author Andre' Neto
*
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
* the Development of Fusion Energy ('Fusion for Energy').
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence")
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
*
* @warning Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an "AS IS"
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence permissions and limitations under the Licence.
* @details This source file contains the definition of all the methods for
* the class ConfigurationExample6 (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ClassRegistryDatabase.h"
#include "ClassRegistryItemT.h"
#include "ConfigurationDatabase.h"
#include "ErrorLoggerExample.h"
#include "IntrospectionT.h"
#include "Matrix.h"
#include "Object.h"
#include "ObjectRegistryDatabase.h"
#include "Reference.h"
#include "ReferenceT.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "Vector.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe2Tutorial {
/**
* Configuration structures
*/
struct Gain {
MARTe::float32 gain1;
MARTe::float32 gain2;
MARTe::float32 gain3[6];
};
struct Gains {
struct Gain lowGains;
struct Gain highGains;
};
DECLARE_CLASS_MEMBER(Gain, gain1, float32, "", "");
DECLARE_CLASS_MEMBER(Gain, gain2, float32, "", "");
DECLARE_CLASS_MEMBER(Gain, gain3, float32, "[6]", "");
static const MARTe::IntrospectionEntry* GainStructEntries[] = { &Gain_gain1_introspectionEntry,
&Gain_gain2_introspectionEntry, &Gain_gain3_introspectionEntry, 0 };
DECLARE_STRUCT_INTROSPECTION(Gain, GainStructEntries)
DECLARE_CLASS_MEMBER(Gains, lowGains, Gain, "", "");
DECLARE_CLASS_MEMBER(Gains, highGains, Gain, "", "");
static const MARTe::IntrospectionEntry* GainsStructEntries[] = { &Gains_lowGains_introspectionEntry,
&Gains_highGains_introspectionEntry, 0 };
DECLARE_STRUCT_INTROSPECTION(Gains, GainsStructEntries)
/**
* @brief A MARTe::Object class that will read directly read its configuration from a structure.
*/
class ControllerEx1: public MARTe::ReferenceContainer {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief NOOP.
*/
ControllerEx1 () {
}
virtual ~ControllerEx1 () {
if (GetName() != NULL) {
REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "No more references pointing at %s [%s]. "
"The Object will be safely deleted.", GetName(), GetClassProperties()->GetName());
}
}
/**
* Read all the properties from the Gains struct (names must match the ones of the struct!
* Gains1 = {
* lowGain = {
* Gain1 = -1.0
* Gain2 = -3.0
* Gain3 = {-9.0, -8.0, -7.0, -6.0, -5.0, -4.0}
* }
* High = {
* Gain1 = 7.0
* Gain2 = 9.0
* }
* }
* Gains2 = {
* lowGain = {
* Gain1 = -1.1
* Gain2 = -3.1
* Gain3 = {-9.1, -8.1, -7.1, -6.1, -5.1, -4.1}
* }
* High = {
* Gain1 = 7.1
* Gain2 = 9.1
* Gain3 = {9.1, 8.1, 7.1, 6.1, 5.1, 4.1}"
* }
* }
*/
virtual bool Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = ReferenceContainer::Initialise(data);
ClassRegistryItem *gainsStructClassRegistryItem = NULL_PTR(ClassRegistryItem *);
if (ok) {
//Search for the registered structure
gainsStructClassRegistryItem = ClassRegistryDatabase::Instance()->Find("Gains");
}
const ClassProperties *gainsStructClassProperties = NULL_PTR(ClassProperties *);
if (ok) {
gainsStructClassProperties = gainsStructClassRegistryItem->GetClassProperties();
}
ClassUID gainsStructClassUID;
AnyType gainsAnyType;
if (ok) {
gainsStructClassUID = gainsStructClassProperties->GetUniqueIdentifier();
//Encapsulate the AnyType
TypeDescriptor gainsTypeDescriptor(false, gainsStructClassUID);
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gains1);
ok = data.Read("Gains1", gainsAnyType);
if (ok) {
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gains2);
ok = data.Read("Gains2", gainsAnyType);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gains2 structure");
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gains1 structure");
}
}
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains 1 low gains");
PrintGains(&gains1.lowGains);
REPORT_ERROR(ErrorManagement::Information, "Gains 1 high gains");
PrintGains(&gains1.highGains);
REPORT_ERROR(ErrorManagement::Information, "Gains 2 low gains");
PrintGains(&gains2.lowGains);
REPORT_ERROR(ErrorManagement::Information, "Gains 2 high gains");
PrintGains(&gains2.highGains);
}
return ok;
}
private:
void PrintGains(Gain *gainToPrint) {
using namespace MARTe;
REPORT_ERROR(ErrorManagement::Information, "Gain1 %f", gainToPrint->gain1);
REPORT_ERROR(ErrorManagement::Information, "Gain2 %f", gainToPrint->gain2);
REPORT_ERROR(ErrorManagement::Information, "Gain3 %f", gainToPrint->gain3);
}
/**
* A list of properties.
*/
Gains gains1;
Gains gains2;
};
CLASS_REGISTER(ControllerEx1, "")
}
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv) {
using namespace MARTe;
using namespace MARTe2Tutorial;
SetErrorProcessFunction(&ErrorProcessExampleFunction);
StreamString configurationCfg = ""
"+ControllerInstance1 = {\n"
" Class = ControllerEx1\n"
" Gains1 = {\n"
" lowGains = {\n"
" Gain1 = -1.0\n"
" Gain2 = -3.0\n"
" Gain3 = {-9.0, -8.0, -7.0, -6.0, -5.0, -4.0}\n"
" }\n"
" highGains = {\n"
" Gain1 = 7.0\n"
" Gain2 = 9.0\n"
" Gain3 = {9.0, 8.0, 7.0, 6.0, 5.0, 4.0}\n"
" }\n"
" }\n"
" Gains2 = {\n"
" lowGains = {\n"
" Gain1 = -1.0\n"
" Gain2 = -3.0\n"
" Gain3 = {-9.1, -8.1, -7.1, -6.1, -5.1, -4.1}\n"
" }\n"
" highGains = {\n"
" Gain1 = 7.0\n"
" Gain2 = 9.0\n"
" Gain3 = {9.1, 8.1, 7.1, 6.1, 5.1, 4.1}\n"
" }\n"
" }\n"
"}";
REPORT_ERROR_STATIC(ErrorManagement::Information, "Loading CFG:\n%s", configurationCfg.Buffer());
ConfigurationDatabase cdb;
StreamString err;
//Force the string to be seeked to the beginning.
configurationCfg.Seek(0LLU);
StandardParser parser(configurationCfg, cdb, &err);
bool ok = parser.Parse();
if (ok) {
//After parsing the tree is pointing at the last leaf
cdb.MoveToRoot();
ok = ObjectRegistryDatabase::Instance()->Initialise(cdb);
}
else {
StreamString errPrint;
errPrint.Printf("Failed to parse %s", err.Buffer());
REPORT_ERROR_STATIC(ErrorManagement::ParametersError, errPrint.Buffer());
}
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Successfully loaded the configuration file");
}
//Write a structure to a ConfigurationDatabase
ClassRegistryItem *gainsStructClassRegistryItem = NULL_PTR(ClassRegistryItem *);
if (ok) {
gainsStructClassRegistryItem = ClassRegistryDatabase::Instance()->Find("Gains");
}
AnyType gainsAnyType;
const ClassProperties *gainsStructClassProperties = NULL_PTR(ClassProperties *);
if (ok) {
gainsStructClassProperties = gainsStructClassRegistryItem->GetClassProperties();
}
if (ok) {
ConfigurationDatabase cdb;
Gains gainsExample;
gainsExample.lowGains.gain1 = 1;
gainsExample.lowGains.gain2 = 2;
gainsExample.lowGains.gain3[0] = -1;
gainsExample.lowGains.gain3[5] = 1;
gainsExample.highGains.gain1 = -1;
gainsExample.highGains.gain2 = -2;
gainsExample.highGains.gain3[0] = 1;
gainsExample.highGains.gain3[5] = -1;
ClassUID gainsStructClassUID = gainsStructClassProperties->GetUniqueIdentifier();
//Encapsulate the AnyType
TypeDescriptor gainsTypeDescriptor(false, gainsStructClassUID);
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gainsExample);
ok = cdb.Write("DumpStruct", gainsAnyType);
if (ok) {
cdb.MoveToRoot();
REPORT_ERROR_STATIC(ErrorManagement::Information, "Wrote structure %!", cdb);
}
}
return 0;
}
|
Similar to the example below but the structures are registered using the configuration file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | /**
* @file ConfigurationExample7.cpp
* @brief Source file for class ConfigurationExample7
* @date 08/04/2018
* @author Andre' Neto
*
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
* the Development of Fusion Energy ('Fusion for Energy').
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence")
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
*
* @warning Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an "AS IS"
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence permissions and limitations under the Licence.
* @details This source file contains the definition of all the methods for
* the class ConfigurationExample7 (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
#define DLL_API
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ClassRegistryDatabase.h"
#include "ClassRegistryItemT.h"
#include "ConfigurationDatabase.h"
#include "ErrorLoggerExample.h"
#include "IntrospectionT.h"
#include "Matrix.h"
#include "Object.h"
#include "ObjectRegistryDatabase.h"
#include "Reference.h"
#include "ReferenceT.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "Vector.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
/*---------------------------------------------------------------------------*/
namespace MARTe2Tutorial {
/**
* Configuration structures
*/
#ifdef __GNUC__
struct __attribute__((__packed__)) GainFromIntroStructure {
MARTe::float32 gain1;
MARTe::float32 gain2;
MARTe::float32 gain3[6];
};
struct __attribute__((__packed__)) GainsFromIntroStructure {
struct GainFromIntroStructure lowGains[2];
struct GainFromIntroStructure highGains;
};
#endif
#ifdef _MSC_VER
#pragma pack(push,1)
struct GainFromIntroStructure {
MARTe::float32 gain1;
MARTe::float32 gain2;
MARTe::float32 gain3[6];
};
struct GainsFromIntroStructure {
struct GainFromIntroStructure lowGains[2];
struct GainFromIntroStructure highGains;
};
#pragma pack(pop)
#endif
/**
* @brief A MARTe::Object class that will read directly read its configuration from a structure.
*/
class ControllerEx1: public MARTe::ReferenceContainer {
public:
CLASS_REGISTER_DECLARATION()
/**
* @brief NOOP.
*/
ControllerEx1 () {
}
virtual ~ControllerEx1 () {
if (GetName() != NULL) {
REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "No more references pointing at %s [%s]. "
"The Object will be safely deleted.", GetName(), GetClassProperties()->GetName());
}
}
/**
* Read all the properties from the Gains struct (names must match the ones of the struct!
* Gains1 = {
* lowGain[0] = {
* Gain1 = -1.0
* Gain2 = -3.0
* Gain3 = {-9.0, -8.0, -7.0, -6.0, -5.0, -4.0}
* }
* lowGain[1] = {
* Gain1 = -2.0
* Gain2 = -6.0
* Gain3 = {-18.0, -16.0, -14.0, -12.0, -10.0, -8.0}
* }
* High = {
* Gain1 = 7.0
* Gain2 = 9.0
* }
* }
* Gains2 = {
* lowGain = {
* Gain1 = -1.1
* Gain2 = -3.1
* Gain3 = {-9.1, -8.1, -7.1, -6.1, -5.1, -4.1}
* }
* High = {
* Gain1 = 7.1
* Gain2 = 9.1
* Gain3 = {9.1, 8.1, 7.1, 6.1, 5.1, 4.1}"
* }
* }
*/
virtual bool Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = ReferenceContainer::Initialise(data);
ClassRegistryItem *gainsStructClassRegistryItem = NULL_PTR(ClassRegistryItem *);
if (ok) {
//Search for the registered structure
gainsStructClassRegistryItem = ClassRegistryDatabase::Instance()->Find("GainsFromIntroStructure");
}
const ClassProperties *gainsStructClassProperties = NULL_PTR(ClassProperties *);
if (ok) {
gainsStructClassProperties = gainsStructClassRegistryItem->GetClassProperties();
}
ClassUID gainsStructClassUID;
AnyType gainsAnyType;
if (ok) {
gainsStructClassUID = gainsStructClassProperties->GetUniqueIdentifier();
//Encapsulate the AnyType
TypeDescriptor gainsTypeDescriptor(false, gainsStructClassUID);
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gains1);
ok = data.Read("Gains1", gainsAnyType);
if (ok) {
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gains2);
ok = data.Read("Gains2", gainsAnyType);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gains2 structure");
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Could not read the Gains1 structure");
}
}
if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Gains 1 low[0] gains");
PrintGains(&gains1.lowGains[0]);
REPORT_ERROR(ErrorManagement::Information, "Gains 1 low[1] gains");
PrintGains(&gains1.lowGains[1]);
REPORT_ERROR(ErrorManagement::Information, "Gains 1 high gains");
PrintGains(&gains1.highGains);
REPORT_ERROR(ErrorManagement::Information, "Gains 2 low[0] gains");
PrintGains(&gains2.lowGains[0]);
REPORT_ERROR(ErrorManagement::Information, "Gains 2 low[1] gains");
PrintGains(&gains2.lowGains[1]);
REPORT_ERROR(ErrorManagement::Information, "Gains 2 high gains");
PrintGains(&gains2.highGains);
}
return ok;
}
private:
void PrintGains(GainFromIntroStructure *gainToPrint) {
using namespace MARTe;
float32 gain1 = gainToPrint->gain1;
float32 gain2 = gainToPrint->gain2;
float32 gain3[6] = {gainToPrint->gain3[0], gainToPrint->gain3[1], gainToPrint->gain3[2], gainToPrint->gain3[3], gainToPrint->gain3[4], gainToPrint->gain3[5]};
REPORT_ERROR(ErrorManagement::Information, "Gain1 %f", gain1);
REPORT_ERROR(ErrorManagement::Information, "Gain2 %f", gain2);
REPORT_ERROR(ErrorManagement::Information, "Gain3 %f", gain3);
}
/**
* A list of properties.
*/
GainsFromIntroStructure gains1;
GainsFromIntroStructure gains2;
};
CLASS_REGISTER(ControllerEx1, "")
}
/*---------------------------------------------------------------------------*/
/* Method definitions */
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv) {
using namespace MARTe;
using namespace MARTe2Tutorial;
SetErrorProcessFunction(&ErrorProcessExampleFunction);
StreamString configurationCfg = ""
"+Types = {\n"
" Class = ReferenceContainer\n"
" +GainFromIntroStructure = {\n"
" Class = IntrospectionStructure\n"
" gain1 = {\n"
" Type = float32\n"
" NumberOfElements = {1}\n"
" }\n"
" gain2 = {\n"
" Type = float32\n"
" NumberOfElements = {1}\n"
" }\n"
" gain3 = {\n"
" Type = float32\n"
" NumberOfElements = {6}\n"
" }\n"
" }\n"
" +GainsFromIntroStructure = {\n"
" Class = IntrospectionStructure\n"
" lowGains = {\n"
" Type = GainFromIntroStructure\n"
" NumberOfElements = {2}\n"
" }\n"
" highGains = {\n"
" Type = GainFromIntroStructure\n"
" }\n"
" }\n"
"}\n"
"+ControllerInstance1 = {\n"
" Class = ControllerEx1\n"
" Gains1 = {\n"
" lowGains[0] = {\n"
" Gain1 = -1.0\n"
" Gain2 = -3.0\n"
" Gain3 = {-9.0, -8.0, -7.0, -6.0, -5.0, -4.0}\n"
" }\n"
" lowGains[1] = {\n"
" Gain1 = -2.0\n"
" Gain2 = -6.0\n"
" Gain3 = {-18.0, -16.0, -14.0, -12.0, -10.0, -8.0}\n"
" }\n"
" highGains = {\n"
" Gain1 = 7.0\n"
" Gain2 = 9.0\n"
" Gain3 = {9.0, 8.0, 7.0, 6.0, 5.0, 4.0}\n"
" }\n"
" }\n"
" Gains2 = {\n"
" lowGains[0] = {\n"
" Gain1 = -1.0\n"
" Gain2 = -3.0\n"
" Gain3 = {-9.1, -8.1, -7.1, -6.1, -5.1, -4.1}\n"
" }\n"
" lowGains[1] = {\n"
" Gain1 = -2.0\n"
" Gain2 = -6.0\n"
" Gain3 = {-18.2, -16.2, -14.2, -12.2, -10.2, -8.2}\n"
" }\n"
" highGains = {\n"
" Gain1 = 7.0\n"
" Gain2 = 9.0\n"
" Gain3 = {9.1, 8.1, 7.1, 6.1, 5.1, 4.1}\n"
" }\n"
" }\n"
"}";
REPORT_ERROR_STATIC(ErrorManagement::Information, "Loading CFG:\n%s", configurationCfg.Buffer());
ConfigurationDatabase cdb;
StreamString err;
//Force the string to be seeked to the beginning.
configurationCfg.Seek(0LLU);
StandardParser parser(configurationCfg, cdb, &err);
bool ok = parser.Parse();
if (ok) {
//After parsing the tree is pointing at the last leaf
cdb.MoveToRoot();
ok = ObjectRegistryDatabase::Instance()->Initialise(cdb);
}
else {
StreamString errPrint;
errPrint.Printf("Failed to parse %s", err.Buffer());
REPORT_ERROR_STATIC(ErrorManagement::ParametersError, errPrint.Buffer());
}
if (ok) {
REPORT_ERROR_STATIC(ErrorManagement::Information, "Successfully loaded the configuration file");
}
//Write a structure to a ConfigurationDatabase
ClassRegistryItem *gainsStructClassRegistryItem = NULL_PTR(ClassRegistryItem *);
if (ok) {
gainsStructClassRegistryItem = ClassRegistryDatabase::Instance()->Find("GainsFromIntroStructure");
}
AnyType gainsAnyType;
const ClassProperties *gainsStructClassProperties = NULL_PTR(ClassProperties *);
if (ok) {
gainsStructClassProperties = gainsStructClassRegistryItem->GetClassProperties();
}
if (ok) {
ConfigurationDatabase cdb;
GainsFromIntroStructure gainsExample;
gainsExample.lowGains[0].gain1 = 1;
gainsExample.lowGains[0].gain2 = 2;
gainsExample.lowGains[1].gain3[0] = -1;
gainsExample.lowGains[1].gain3[5] = 1;
gainsExample.highGains.gain1 = -1;
gainsExample.highGains.gain2 = -2;
gainsExample.highGains.gain3[0] = 1;
gainsExample.highGains.gain3[5] = -1;
ClassUID gainsStructClassUID = gainsStructClassProperties->GetUniqueIdentifier();
//Encapsulate the AnyType
TypeDescriptor gainsTypeDescriptor(false, gainsStructClassUID);
gainsAnyType = AnyType(gainsTypeDescriptor, 0u, &gainsExample);
ok = cdb.Write("DumpStruct", gainsAnyType);
if (ok) {
cdb.MoveToRoot();
REPORT_ERROR_STATIC(ErrorManagement::Information, "Wrote structure %!", cdb);
}
}
return 0;
}
|
Instructions on how to compile and execute the example can be found here.
Example on how to preprocess complex configuration files:
1 2 3 4 5 | #ifdef ENABLE_WEB_BROWSING
#include "RTApp-6-Web.cfg"
#endif
#include "RTApp-6-StateMachine.cfg"
#include "RTApp-6-RTApp.cfg"
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
#############################################################
#Named of the unit files to be compiled
OBJSX=RTApp-6.x
#Location of the Build directory where the configuration file will be written to
BUILD_DIR?=.
#Location of the MakeDefaults directory.
#Note that the MARTe2_DIR environment variable
#must have been exported before
MARTe2_MAKEDEFAULT_DIR?=$(MARTe2_DIR)/MakeDefaults
include $(MARTe2_MAKEDEFAULT_DIR)/MakeStdLibDefs.$(TARGET)
CFLAGS += -DENABLE_WEB_BROWSING
all: $(OBJS)
echo $(OBJS)
include $(MARTe2_MAKEDEFAULT_DIR)/MakeStdLibRules.$(TARGET)
|
Example with post-processing of variables:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | Parameters = {
T1_FREQUENCY = (uint32)10000
T2_FREQUENCY = (uint32)1
SAMPLES = (uint32|"Parameters.T1_FREQUENCY / Parameters.T2_FREQUENCY")
}
$TestApp = {
Class = RealTimeApplication
+Functions = {
Class = ReferenceContainer
+GAMTimer = {
Class = IOGAM
InputSignals = {
Counter = {
DataSource = Timer
Type = uint32
}
Time = {
Frequency = (uint32|"Parameters.T1_FREQUENCY")
DataSource = Timer
Type = uint32
}
}
OutputSignals = {
Counter = {
DataSource = DDB1
Type = uint32
}
Time = {
DataSource = DDB1
Type = uint32
}
}
}
+GAMFixed1 = {
Class = FixedGAMExample1
Gain = 2
InputSignals = {
Counter = {
DataSource = DDB1
Type = uint32
}
}
OutputSignals = {
GainCounter = {
DataSource = DDB1
Type = uint32
}
}
}
+GAMT1ToT2 = {
Class = IOGAM
InputSignals = {
Counter = {
DataSource = DDB1
Type = uint32
}
GainCounter = {
DataSource = DDB1
Type = uint32
}
State1_Thread1_CycleTime = {
Alias = State1.Thread1_CycleTime
DataSource = Timings
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = Timings
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = Timings
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = Timings
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = Timings
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = Timings
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = Timings
Type = uint32
}
}
OutputSignals = {
Counter = {
DataSource = RTThreadSynch
Type = uint32
}
GainCounter = {
DataSource = RTThreadSynch
Type = uint32
}
State1_Thread1_CycleTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = RTThreadSynch
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = RTThreadSynch
Type = uint32
}
}
}
+GAMT2FromT1 = {
Class = IOGAM
InputSignals = {
Counter = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GainCounter = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
State1_Thread1_CycleTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = RTThreadSynch
Samples = (uint32|"Parameters.SAMPLES")
Type = uint32
}
}
OutputSignals = {
Counter = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GainCounter = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
State1_Thread1_CycleTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = DDB2
NumberOfElements = 10000
Type = uint32
}
}
}
+GAMDisplay = {
Class = IOGAM
InputSignals = {
Counter = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GainCounter = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
State1_Thread1_CycleTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = DDB2
Ranges = {{0, 10}}
Type = uint32
}
}
OutputSignals = {
Counter = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GainCounter = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
State1_Thread1_CycleTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMTimer_ReadTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMTimer_ExecTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMTimer_WriteTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMFixed1_ReadTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMFixed1_ExecTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
GAMFixed1_WriteTime = {
DataSource = LoggerDataSource
NumberOfElements = 11
Type = uint32
}
}
}
}
+Data = {
Class = ReferenceContainer
DefaultDataSource = DDB2
+DDB1 = {
Class = GAMDataSource
}
+DDB2 = {
Class = GAMDataSource
}
+LoggerDataSource = {
Class = LoggerDataSource
}
+RTThreadSynch = {
Class = RealTimeThreadSynchronisation
Timeout = 10000 //Timeout in ms to wait for the thread to cycle.
}
+Timings = {
Class = TimingDataSource
}
+Timer = {
Class = LinuxTimer
SleepNature = "Default"
Signals = {
Counter = {
Type = uint32
}
Time = {
Type = uint32
}
}
}
}
+States = {
Class = ReferenceContainer
+State1 = {
Class = RealTimeState
+Threads = {
Class = ReferenceContainer
+Thread1 = {
Class = RealTimeThread
CPUs = 0x2
Functions = {GAMTimer GAMFixed1 GAMT1ToT2}
}
+Thread2 = {
Class = RealTimeThread
CPUs = 0x1
Functions = {GAMT2FromT1 GAMDisplay}
}
}
}
}
+Scheduler = {
Class = GAMScheduler
TimingDataSource = Timings
}
}
|