APIs, concepts, guides, and more
RTTasksHelpers.h
1
10#ifndef RT_TASKS_HELPERS
11#define RT_TASKS_HELPERS
12
13#include "rttask.h"
14
15#include <iostream>
16#include <memory>
17
18using namespace RSI::RapidCode; // Import our RapidCode namespace
19using namespace RSI::RapidCode::RealTimeTasks; // Import the RealTimeTasks namespace
20
21namespace RTTaskHelper
22{
23
25 // Get the creation parameters for the task manager
26#if defined(WIN32) && defined(NDEBUG)
27
28 // If we are on Windows and not Debug, then we need to create an INtime task manager
29 RTTaskManagerCreationParameters GetTaskManagerCreationParameters()
30 {
32 std::snprintf(
33 parameters.RTTaskDirectory,
35 RMP_DEFAULT_PATH // The RMP install directory
36 );
37 parameters.Platform = PlatformType::INtime;
38 std::snprintf(
39 parameters.NodeName,
41 "NodeA"
42 );
43 return parameters;
44 }
45#else
46
47 // Otherwise, we are on Linux or Debug, so we can create a native task manager
48 RTTaskManagerCreationParameters GetTaskManagerCreationParameters()
49 {
51 std::snprintf(
52 parameters.RTTaskDirectory,
54 RMP_DEFAULT_PATH // The RMP install directory
55 );
56
57 // For Linux real-time set this to a isolated core
58 // parameters.CpuCore = -1;
59 return parameters;
60 }
61#endif // defined(WIN32) && defined(NDEBUG)
63
65 // This calls a task to initialize the global variables and get pointers to RapidCode objects
66 // in the RTTaskFunctions library. It needs to be called before any task
67 // that uses RapidCode objects.
68 void InitializeRTTaskObjects(std::unique_ptr<RTTaskManager>& manager)
69 {
70 std::cout << "Running initialization task..." << std::endl;
71 RTTaskCreationParameters initParams("Initialize");
72 initParams.Repeats = RTTaskCreationParameters::RepeatNone;
73 std::unique_ptr<RTTask> task(manager->TaskSubmit(initParams));
74 constexpr int timeoutMs = 5000;
75 task->ExecutionCountAbsoluteWait(1, timeoutMs); // Wait for the task to execute once.
76 }
78}
79
80#endif // RT_TASKS_HELPERS
RTTaskCreationParameters specifies all the information required to create and configure a real-time t...
Definition rttask.h:124
static constexpr int32_t RepeatNone
Special value to indicate the task should not repeat.
Definition rttask.h:141
RTTaskManagerCreationParameters specifies all the information required to create and configure an RTT...
Definition rttask.h:318
static constexpr int32_t DirectoryLengthMaximum
Maximum length of the directory path.
Definition rttask.h:320
static constexpr int32_t NameLengthMaximum
Maximum length of name fields (node name, user label).
Definition rttask.h:323