### Setup MARTe2 Environment and Build Examples Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/examples.rst This snippet details the necessary environment variable exports and commands to build MARTe2 examples on an x86-linux system. It ensures the MARTe2 installation directory and build artifacts are correctly configured for subsequent execution. ```bash export MARTe2_DIR=FOLDER_WHERE_MARTe2_IS_INSTALLED cd $MARTe2_DIR/Docs/User/source/_static/examples/Core make -f Makefile.x86-linux export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_DIR/Build/x86-linux/Core/ ``` -------------------------------- ### Launch Real-Time Examples with State Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/examples.rst This example demonstrates launching MARTe2 applications for real-time execution. It requires setting MARTe2 and MARTe2_Components directories, then using MARTeApp.sh with a specific state and configuration file to run the application. ```bash export MARTe2_DIR=FOLDER_WHERE_MARTe2_IS_INSTALLED export MARTe2_Components_DIR=FOLDER_WHERE_MARTe2_Components_IS_INSTALLED cd $MARTe2_DIR/Docs/User/source/_static/examples ./MARTeApp.sh -l RealTimeLoader -s NAME_OF_THE_STATE -f Configurations/NAME_OF_THE_CONFIGURATION_FILE ``` -------------------------------- ### Run Standalone MARTe2 Examples Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/examples.rst This command shows how to execute standalone MARTe2 examples after the environment has been set up and potentially built. It points to the compiled example executable within the MARTe2 build directory. ```bash ../../../../../Build/x86-linux/Examples/Core/EXAMPLE_TO_RUN.ex ``` -------------------------------- ### Launch Real-Time Examples with Message Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/examples.rst This command illustrates how to run MARTe2 applications in real-time mode using a message-driven approach. Similar to state-based execution, it involves setting directories and using MARTeApp.sh with a message and configuration file. ```bash export MARTe2_DIR=FOLDER_WHERE_MARTe2_IS_INSTALLED export MARTe2_Components_DIR=FOLDER_WHERE_MARTe2_Components_IS_INSTALLED cd $MARTe2_DIR/Docs/User/source/_static/examples ./MARTeApp.sh -l RealTimeLoader -m MESSAGE -f Configurations/NAME_OF_THE_CONFIGURATION_FILE ``` -------------------------------- ### GAM Setup: Get Input Signal Properties Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/gams/gam.rst Demonstrates how to use the `Setup` method in a GAM to retrieve the number and type of input signals. It iterates through input signals to get their `TypeDescriptor` for validation or configuration. ```c++ virtual bool MyGAM::Setup () { ... uint32 numberOfInputSignals = GetNumberOfInputSignals(); ... for (i = 0u; i`. ``` -------------------------------- ### Configuration Example (C++) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/configuration/parser.rst An example C++ code snippet demonstrating how to parse configuration files in supported languages within the MARTe framework. This example utilizes the framework's parsing capabilities to load configuration data. ```c++ // This is a placeholder for the actual C++ code from ConfigurationExample3.cpp // The literalinclude directive in the source text points to this file. // For actual content, please refer to the specified file path. // Example: // #include // #include "ConfigurationDatabase.h" // #include "ConfigurationParser.h" // // int main() { // // Code to parse configuration files... // return 0; // } ``` -------------------------------- ### Reading Registered Structures Example (ConfigurationExample6.cpp) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/configuration/objectregistrydatabase.rst Shows how to read and write directly from a registered C struct, similar to another example but with structures registered via the configuration file. ```c++ // This is a placeholder for the actual code from the literalinclude directive. // The original file path was /_static/examples/Core/ConfigurationExample6.cpp // The following lines are illustrative based on the description: // Example showing how to read and write directly from a registered "C struct". // Similar to the example below but the structures are registered using the configuration file: ``` -------------------------------- ### MARTe Application Configuration Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/reconfigure/reconfigure.rst Example configuration file for a MARTe application demonstrating runtime reconfiguration. This file is intended to be loaded via a TCP connection using the ConfigurationLoaderTCP component. ```bash # This is a placeholder for the actual content of RTApp-9.cfg # The literalinclude directive in the source text points to this file. # Actual content would typically define application parameters, cycle times, etc. # Example content structure: # [Application] # Name=MyMARTeApp # CycleTime=10ms # # [Component1] # Property1=Value1 # Property2=Value2 ``` -------------------------------- ### Signal Alias Configuration Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/gams/rtappdetails.rst A configuration example showing how to use an Alias to correctly map a signal name containing a dot to a MARTe object name. ```bash InputSignals = { State1_Thread1_CycleTime = { Alias = State1.Thread1_CycleTime DataSource = Timings ``` -------------------------------- ### Create by Name Example (ReferencesExample1) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/objects/references.rst This example showcases the instantiation of a MARTe framework object by its class name and the subsequent assignment of a specific name to that instance. It highlights the object creation mechanism. ```c++ // This is a placeholder for the actual code from ReferencesExample1.cpp // The directive 'literalinclude' points to the source file. // Example functionality: Instantiate an Object by class name and assign a name. ``` -------------------------------- ### Application Configuration Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/scheduling/services.rst A configuration file example for an RTApp, demonstrating how to set up multiple states. This configuration is used to control application behavior, potentially through external commands. ```bash # RTApp-3.cfg # Configuration for application states # Define the state machine component # This might be a specific MARTe component name StateMachine: # Define states and transitions START: # Initial state # Transitions to GOTOSTATE2 NextState: GOTOSTATE2 GOTOSTATE2: # State 2 # Example: Perform some action or wait # Transition back or to another state NextState: START # Other application configurations can follow... ``` -------------------------------- ### ReferenceContainer Example: Add/Get References Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/objects/referencecontainers.rst Illustrates the basic operations of adding and retrieving references to and from a ReferenceContainer. This example highlights common usage patterns for managing object relationships. ```c++ //This is a valid way of creating a new ReferenceContainer ReferenceT ref("ReferenceContainer", GlobalObjectsDatabase::Instance()->GetStandardHeap()); // ... (code omitted for brevity, refers to /_static/examples/Core/ReferencesExample5.cpp) ``` -------------------------------- ### MARTe2 Makefile.inc Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/makefile/makefile.rst Provides an example of a common `Makefile.inc` file used in MARTe2 projects. It specifies the list of object files to compile, the package name, and the root directory for build outputs. ```makefile #List of objects to be compiled OBJSX=File1.x \ File2.x \ File3.x #Name of the package (see the Definitions above) PACKAGE=Components/Examples #Where is the Build directory ROOT_DIR=../../../../ ``` -------------------------------- ### AnyType Example (TypesExample1) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/types/types.rst Demonstrates the usage of AnyType and TypeDescriptor in C++. The example highlights specific lines of code for clarity. Instructions for compilation and execution are available separately. ```c++ // This is a placeholder for the actual code content from /_static/examples/Core/TypesExample1.cpp // The original directive specified: // .. literalinclude:: /_static/examples/Core/TypesExample1.cpp // :language: c++ // :emphasize-lines: 59,73-75,88,92 // :caption: AnyType example (TypesExample1) // :linenos: // Actual code content is not provided in the input text, so this is a representation. // For the complete code, please refer to the original source file. // Example structure (hypothetical): class TypeDescriptor {}; class AnyType { public: // Constructor, methods, etc. }; int main() { // ... code demonstrating AnyType and TypeDescriptor ... return 0; } ``` -------------------------------- ### Project Specific RPM Build Makefile Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/deploying/rpm.rst An example Makefile for building a project-specific RPM package for MARTe2. It configures RPM metadata like name, version, and dependencies, and specifies project folders for inclusion in the package. ```makefile TARGET=rpmbuild ROOT_DIR=. FOLDERSX?=Source.x Makefile.x86-linux.x Makefile.inc.x Startup.x Configurations.x MARTe2_MAKEDEFAULT_DIR?=$(MARTe2_DIR)/MakeDefaults #If not set try to get the project version from a git tag (in the format vx.y, i.e. assuming it starts with v) M2_RPM_VERSION?=$(shell git tag | sort -V | tail -1 | cut -c2-) M2_RPM_NAME?=SUPITA M2_RPM_ID?=supita M2_RPM_REQUIRES=marte2-core marte2-components marte2-components-ccs M2_RPM_SPEC_FILE_PATH=$(MARTe2_DIR)/Resources/RPM/ #If not specified, the MakeDefaults behaviour is to get the latest tag from git #M2_RPM_VERSION=dev$(shell git rev-parse --short HEAD) #Project specific folders that are to be installed. It really has to be escaped with a space. M2_RPM_OTHER_FOLDERS=Startup\ Configurations #Get current CODAC version CODAC_CCS=`codac-version | cut -c 1,3` #If not set it will default to standard OS (e.g. el7) M2_RPM_CUSTOM_DIST="ccs$(CODAC_CCS)" include $(MARTe2_MAKEDEFAULT_DIR)/MakeStdLibDefs.$(TARGET) all: $(OBJS) $(BUILD_DIR)/$(M2_RPM_ID)-$(M2_RPM_VERSION).rpm check-env echo $(OBJS) check-env: ifndef MARTe2_DIR $(error MARTe2_DIR is undefined) endif ifndef MARTe2_Components_DIR $(error MARTe2_Components_DIR is undefined) endif include $(MARTe2_MAKEDEFAULT_DIR)/MakeStdLibRules.$(TARGET) ``` -------------------------------- ### State Machine Configuration Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/gams/rtappdetails.rst Demonstrates the configuration of a StateMachine component, including state definitions, transition events, and message parameters for state changes. ```bash +StateMachine = { Class = StateMachine ... +STATE1 = { Class = ReferenceContainer +GOTOSTATE2 = { Class = StateMachineEvent NextState = "STATE2" NextStateError = "ERROR" Timeout = 0 +PrepareChangeToState2Msg = { Class = Message Destination = TestApp Mode = ExpectsReply Function = PrepareNextState +Parameters = { Class = ConfigurationDatabase param1 = State2 } } } } } ``` -------------------------------- ### Install Development Tools on CentOS Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/contributing/development/environment/linux.rst Installs the 'Development tools' group, which includes essential compilers, build utilities, and libraries required for compiling software on CentOS. This is a prerequisite for many development tasks. ```shell yum groupinstall "Development tools" ``` -------------------------------- ### Install Cppcheck on CentOS Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/contributing/development/environment/linux.rst Installs the Cppcheck static analysis tool on CentOS 7. Cppcheck helps find bugs in C/C++ code and is often used in development workflows for code quality assurance. ```shell yum install -y cppcheck ``` -------------------------------- ### RealTimeApplication Configuration Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/gams/rtappdetails.rst Illustrates a typical configuration structure for a RealTimeApplication, specifying the scheduler class and the TimingDataSource. ```bash +App1 = { Class = RealTimeApplication ... +Scheduler = { Class = GAMScheduler TimingDataSource = Timings } } ``` -------------------------------- ### Update CentOS Distribution Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/contributing/development/environment/linux.rst Updates the CentOS 7 distribution to the latest available packages. This is a standard system maintenance command to ensure the operating system is up-to-date before installing new software. ```shell yum -y update ``` -------------------------------- ### MARTe Makefile.cfg Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/configuration/objectregistrydatabase.rst A sample Makefile.cfg file that sets the target environment variable and includes the Makefile.inc, demonstrating the MARTe build structure. ```makefile export TARGET=cfg include Makefile.inc ``` -------------------------------- ### CompilerTypes.h Example for Xilinx Ultrascale+ Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/porting/porting.rst Demonstrates a C++ pattern for architecture-specific header inclusion. It uses preprocessor directives to conditionally include a custom header for specific environments (like Xilinx Ultrascale+) and falls back to a default implementation if no customization is defined. This approach is often used with the ENV_ARCH_CUSTOMIZATION variable. ```c++ #ifdef XILINX_ULTRASCALE #include "CompilerTypesXil.h" #define CUSTOMIZED_COMPILERTYPES_HEADER #endif #ifndef CUSTOMIZED_COMPILERTYPES_HEADER #include "CompilerTypesDefault.h" #endif ``` -------------------------------- ### Install Eclox Plugin for Doxygen Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/contributing/development/environment/eclipse.rst Details the process of installing the Eclox plugin from a specified URL within Eclipse's 'Install New Software' feature. Eclox integrates Doxygen documentation generation into the IDE. ```text Help -> Install New Software Add Repository: Name: Eclox Location: http://anb0s.github.io/eclox Select Software: Work with: Eclox - http://anb0s.github.io/eclox Features: eclox 0.12, Eclox Doxygen Follow installation instructions. ``` -------------------------------- ### Basic Streams Operations Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/streams/streams.rst Illustrates the usage of basic stream implementations like BasicUDPSocket, BasicConsole, and BasicFile. It shows opening sockets, listening, configuring console output, and opening files with specific flags. ```c++ BasicUDPSocket sock; bool ok = sock.Open(); ... ok = sock.Listen(port); ... BasicConsole bc; ... bc.Open(BasicConsoleMode::EnablePaging); bc.SetSceneSize(ncols, nrows); ... BasicFile f; ok = f.Open(TEST_FILENAME, BasicFile::FLAG_CREAT | BasicFile::ACCESS_MODE_W); ... MARTe::uint32 writeSize = str.Size(); stream.Write(str.Buffer(), writeSize); ``` -------------------------------- ### C++ FileReader Initialise Method Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/app/gams/datasource.rst Demonstrates the initialization of a FileReader component. It highlights the mandatory call to the base class DataSourceI::Initialise and subsequent reading of configuration properties like 'FileFormat'. ```c++ bool FileReader::Initialise(StructuredDataI& data) { //You must call DataSource::Initialise ! bool ok = DataSourceI::Initialise(data); if (ok) { ok = data.Read("FileFormat", fileFormatStr); ... } ``` -------------------------------- ### Install cppcheclipse Plugin Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/contributing/development/environment/eclipse.rst Instructions for installing the cppcheclipse static analysis plugin via the Eclipse Marketplace. This tool helps identify coding errors and stylistic issues in C/C++ code. ```text Help -> Eclipse MarketPlace Search for: cppcheclipse Follow installation instructions. ``` -------------------------------- ### Atomic Operations Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/scheduling/threads.rst A practical example demonstrating the usage of the Atomic API, showcasing how atomic operations are applied in a real-world scenario. ```c++ #include "Atomic.h" #include "Exception.h" #include "Thread.h" #include "HighResolutionTimer.h" #include "Sleep.h" #include "MutexSem.h" #include "EventSem.h" void IncrementDecrementFunction(const void * const parameters) { int64 * i = (int64 *)parameters; *i = *i + 1; } int main() { // Threads example Threads::BeginThread(&IncrementDecrementFunction, (int64 *)1, THREADS_DEFAULT_STACKSIZE, "NamedThread", ExceptionHandler::NotHandled, 0x1); // Atomic operations example int32 a = 10; int32 b = 20; b = Atomic::Exchange(&a, b); Atomic::Increment(&a); bool locked = false; if (!Atomic::TestAndSet(&locked)) { // Critical section } // High Resolution Timer example uint64 countStart = HighResolutionTimer::Counter(); uint64 countEnd = countStart + 1000000; // Example: wait for 1 million ticks while (HighResolutionTimer::Counter() < countEnd); // Sleep example MARTe::Sleep::Sec(1e-3); // Semaphores example MARTe::MutexSem mutexSem; mutexSem.Create(false); if (!mutexSem.Lock()) { // Handle lock failure } // Critical section protected by mutex if (!mutexSem.UnLock()) { // Handle unlock failure } MARTe::EventSem eventSem; eventSem.Create(); bool needsReset = true; mutexSem.Lock(); if (needsReset) { needsReset = false; eventSem.Reset(); } mutexSem.UnLock(); eventSem.Wait(); return 0; } ``` -------------------------------- ### MARTe Makefile.inc Example Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/configuration/objectregistrydatabase.rst A sample Makefile.inc file for MARTe projects, defining object files, build directories, and including default definitions. It also shows how to pass CFLAGS. ```makefile #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) ``` -------------------------------- ### Thread Management Example (C++) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/scheduling/threads.rst Illustrates how to manage threads, including creation, execution, and basic synchronization. This example is fundamental for concurrent programming. ```c++ #include "Thread.h" #include void ThreadFunction() { std::cout << "Thread is running!\n"; } void ThreadsExample1() { Thread myThread(ThreadFunction); myThread.Start(); myThread.Join(); // Wait for the thread to finish std::cout << "Thread finished.\n"; } // ... main function or other calls ... ``` -------------------------------- ### High-Resolution Timer Example (C++) Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/core/scheduling/threads.rst Demonstrates the usage of the HighResolutionTimer class. This example showcases how to utilize precise timing mechanisms for various applications. ```c++ #include "HighResolutionTimer.h" // ... other includes and setup ... void HighResolutionTimerExample1() { HighResolutionTimer timer; timer.Start(); // Simulate some work for (int i = 0; i < 1000000; ++i) { volatile int sink = i; } timer.Stop(); double elapsed_seconds = timer.GetElapsedSeconds(); // Use elapsed_seconds for further processing or logging } // ... main function or other calls ... ``` -------------------------------- ### MARTe2 Build System Variable Definitions Source: https://github.com/aneto0/marte2/blob/master/Docs/User/source/porting/porting.rst Demonstrates how the MakeStdLibDefs file defines key variables like ENVIRONMENT and ARCHITECTURE, which are crucial for the build system to locate the correct porting subdirectories. ```c++ ENVIRONMENT=FreeRTOS ARCHITECTURE=armv8_gcc ```