Newer
Older
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
/*
* Generic module to take apart a bit field into individual values
*/
#ifndef CHIMERATK_APPLICATION_CORE_BIT_MASK_H
#define CHIMERATK_APPLICATION_CORE_BIT_MASK_H
#include "ApplicationCore.h"
namespace ChimeraTK {
template<size_t NBITS>
struct WriteBitMask : public ApplicationModule {
using ApplicationModule::ApplicationModule;
/// individual inputs for each bit
struct Input : public VariableGroup {
Input() {}
Input(EntityOwner *owner, const std::string &name, const std::string &description)
: VariableGroup(owner, name, description)
{
setEliminateHierarchy();
for(size_t i=0; i<NBITS; ++i) {
bit[i].replace(ScalarPushInput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask"));
}
}
ScalarPushInput<int> bit[NBITS];
};
Input input{this, "input", "The input bits"};
ScalarOutput<int32_t> bitmask{this, "bitmask", "", "Output bit mask."};
void mainLoop() {
while(true) {
// create bit mask
bitmask = 0;
for(size_t i=0; i<NBITS; ++i) {
if(input.bit[i] != 0) {
bitmask |= 1 << i;
}
}
bitmask.write();
// wait for new input values (at the end, since we want to process the initial values first)
input.readAny();
}
}
};
/*********************************************************************************************************************/
template<size_t NBITS>
struct ReadBitMask : public ApplicationModule {
using ApplicationModule::ApplicationModule;
/// individual outputs for each bit
struct Output : public VariableGroup {
Output() {}
Output(EntityOwner *owner, const std::string &name, const std::string &description)
: VariableGroup(owner, name, description)
{
setEliminateHierarchy();
for(size_t i=0; i<NBITS; ++i) {
bit[i].replace(ScalarOutput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask"));
}
}
ScalarOutput<int> bit[NBITS];
};
Output output{this, "output", "The extracted output bits"};
ScalarPushInput<int32_t> bitmask{this, "bitmask", "", "Input bit mask."};
void mainLoop() {
while(true) {
// decode bit mask
for(size_t i=0; i<NBITS; ++i) {
output.bit[i] = (bitmask & (1 << i)) != 0;
output.bit[i].write(); /// @todo TODO better make a writeAll() for VariableGroups
}
// wait for new input values (at the end, since we want to process the initial values first)
bitmask.read();
}
}
};
} // namespace ChimeraTK
#endif /* CHIMERATK_APPLICATION_CORE_BIT_MASK_H */