24 #include <sys/sysinfo.h>
26 #include <ChimeraTK/ReadAnyGroup.h>
41 this->running =
false;
42 if(this->valueGeneratorThread.joinable()) {
43 this->valueGeneratorThread.join();
50 ReadAnyGroup readAnyGroup;
51 for(
auto& pv :
devManager->getAllProcessVariables()) {
52 if(pv->isReadable()) readAnyGroup.add(pv);
54 readAnyGroup.finalise();
57 clock_t start, end, im1, im2, writeTime;
61 float duration1 = 0.0f;
62 devManager->getProcessArray<int32_t>(
"t")->accessChannel(0) = vector<int32_t>{(int32_t)start};
64 while(this->running) {
65 double double_sine =
devManager->getProcessArray<
double>(
"amplitude")->accessChannel(0).at(0) *
66 sin((2 * 3.141) /
devManager->getProcessArray<
double>(
"period")->accessChannel(0).at(0) *
67 devManager->getProcessArray<int32_t>(
"t")->accessChannel(0).at(0));
68 int32_t int_sine = round(double_sine);
70 devManager->getProcessArray<
double>(
"double_sine")->accessChannel(0) = vector<double>{double_sine};
71 devManager->getProcessArray<
double>(
"double_sine")->write();
72 devManager->getProcessArray<int32_t>(
"int_sine")->accessChannel(0) = vector<int32_t>{int_sine};
73 devManager->getProcessArray<int32_t>(
"int_sine")->write();
74 devManager->getProcessArray<ChimeraTK::Boolean>(
"bool")->accessChannel(0) =
75 vector<ChimeraTK::Boolean>{!
devManager->getProcessArray<ChimeraTK::Boolean>(
"bool")->accessChannel(0).at(0)};
76 devManager->getProcessArray<ChimeraTK::Boolean>(
"bool")->write();
77 devManager->getProcessArray<ChimeraTK::Void>(
"void")->write();
78 devManager->getProcessArray<int32_t>(
"t")->accessChannel(0) =
79 vector<int32_t>{(int32_t)((end - start) / (CLOCKS_PER_SEC / 1000))};
80 devManager->getProcessArray<int32_t>(
"t")->write();
82 usleep(
devManager->getProcessArray<int32_t>(
"dt")->accessChannel(0).at(0));
87 for(int32_t i = 1000; i < 65535; i = i + 1000) {
88 string nameDouble =
"testDoubleArray_" + to_string(i);
89 string nameInt =
"testIntArray_" + to_string(i);
90 ProcessArray<double>::SharedPtr testDoubleArray =
devManager->getProcessArray<
double>(nameDouble);
91 ProcessArray<int32_t>::SharedPtr testIntArray =
devManager->getProcessArray<int32_t>(nameInt);
92 for(int32_t k = 0; k < i; k++) {
94 testDoubleArray->accessChannel(0).at(k) = rand() % 6 + 1;
95 testIntArray->accessChannel(0).at(k) = rand() % 6 + 1;
98 testDoubleArray->accessChannel(0).at(k) = rand() % 50 + 10;
99 testIntArray->accessChannel(0).at(k) = rand() % 50 + 10;
103 testDoubleArray->write();
104 testIntArray->write();
106 writeTime += im2 - im1;
110 duration1 = ((float)writeTime / CLOCKS_PER_SEC) * 1000.0f;
111 printf(
"1: %d write passes, duration write: %.3f ms\n", counter, duration1);
113 ProcessArray<double>::SharedPtr testDoubleArray =
devManager->getProcessArray<
double>(
"testDoubleArray_65535");
114 ProcessArray<int32_t>::SharedPtr testIntArray =
devManager->getProcessArray<int32_t>(
"testIntArray_65535");
115 for(int32_t i = 0; i < 65535; i++) {
117 testDoubleArray->accessChannel(0).at(i) = rand() % 6 + 1;
118 testIntArray->accessChannel(0).at(i) = rand() % 6 + 1;
121 testDoubleArray->accessChannel(0).at(i) = rand() % 50 + 10;
122 testIntArray->accessChannel(0).at(i) = rand() % 50 + 10;
126 clock_t tmp2 = clock();
128 testDoubleArray->write();
129 testIntArray->write();
131 clock_t tmp3 = clock();
132 duration1 = ((float)(tmp3 - tmp2) / CLOCKS_PER_SEC) * 1000.0f;
133 printf(
"write pass 2, duration write: %.3f ms\n", duration1);
135 while(readAnyGroup.readAnyNonBlocking().isValid())
continue;