Compare commits
695 Commits
gaisser_fi
...
mueller/pr
Author | SHA1 | Date | |
---|---|---|---|
dccfab6f48 | |||
e03007bd72 | |||
4dcfa5125e | |||
6b475792a4 | |||
4e9e465360 | |||
0ead44bea9 | |||
f240827bbd | |||
ebf5d41a78 | |||
7475e6a9b8 | |||
66eac57e3b | |||
58a4f4f8a1 | |||
76cc3e96e8 | |||
18899a4c82 | |||
276c3b172e | |||
c64aa9f7f5 | |||
9fa9421ba5 | |||
9acf82cf51 | |||
69f9ff02f0 | |||
afc16ef2d7 | |||
6425c0dd4c | |||
e179288c00 | |||
b4d6d970bc | |||
aaafed7b28 | |||
47b3a428c6 | |||
e7b6999c5e | |||
15052cb333 | |||
6d99ab3df3 | |||
b4f292f3d7 | |||
99aef0cf28 | |||
7d794c7623 | |||
799846d89f | |||
e4f795d209 | |||
ffba664144 | |||
69946d5276 | |||
35d4267b40 | |||
6a6395313f | |||
444ee80f35 | |||
3145036210 | |||
36a7f2f9ee | |||
e29226c9bb | |||
9716bcdd74 | |||
a7d68f8c52 | |||
be8913efea | |||
9cbc1a18b8 | |||
bdc6e88198 | |||
3551a767a7 | |||
f3739fd213 | |||
7a4cc1a6b6 | |||
1fde3c2c99 | |||
cdd877032f | |||
57418eb877 | |||
ad049cc634 | |||
ceb6197904 | |||
da30680d04 | |||
0cdce6e327 | |||
a5d3d9ea80 | |||
5a351474d2 | |||
32ef807341 | |||
ecd740a101 | |||
6f50356964 | |||
ac9e6e1337 | |||
c8821ae74f | |||
64c290ffe4 | |||
dc27cc9aff | |||
8046d005a4 | |||
236ad1b85b | |||
5ec78b065c | |||
b56aa94f99 | |||
01b1080376 | |||
94f9b1e1ef | |||
264914e86a | |||
2efcda735f | |||
399fc0e287 | |||
dd48f7ccad | |||
06d389ed1e | |||
684b56ac88 | |||
7698f3f13e | |||
359163886b | |||
4f1f610ae0 | |||
e48de981f5 | |||
cb691db807 | |||
fd1e612ea5 | |||
8ba75fc3c2 | |||
f442a5889e | |||
78283ddbee | |||
b61e1df8bc | |||
bb5de8f110 | |||
2158208a2f | |||
ebec074655 | |||
2395e487ae | |||
327b1e9d2f | |||
724fee09ff | |||
26ab1983dc | |||
9e2fa16550 | |||
fcf3f04377 | |||
9dcf0c7118 | |||
b86e5664c4 | |||
1a177d2efa | |||
24240b6c7d | |||
c160000027 | |||
5cee126841 | |||
571da39108 | |||
e0a3257f8b | |||
72768a6815 | |||
18173772af | |||
099e6281ec | |||
3e069c34aa | |||
8011d49ebc | |||
47b8ed2321 | |||
d7bff31a4c | |||
6802ff7d71 | |||
837fecf859 | |||
062ebabb9a | |||
1820b5f95c | |||
2de972bb8a | |||
3a85001855 | |||
85cc936d5d | |||
e2a36efce3 | |||
48df3cbe83 | |||
691be0dcd4 | |||
044aa259e6 | |||
ae6314d8cd | |||
003e70bf47 | |||
d5d968a393 | |||
b81b458ba6 | |||
71f997888b | |||
ba5b8bd682 | |||
08f25370f3 | |||
0c32a96452 | |||
8d633bf127 | |||
6f2bb4125d | |||
7f3607c3d9 | |||
61370d43da | |||
bb9f606ffd | |||
16cbbb2693 | |||
af24cc7d04 | |||
c7c49b4239 | |||
3bf29a7315 | |||
905c1a92e3 | |||
56455a5fa2 | |||
67366c25a0 | |||
5f16d30d82 | |||
6f4682e1c8 | |||
2ecd7c4493 | |||
446e7d2f82 | |||
45ffb7549a | |||
e27310da40 | |||
c0beef4463 | |||
64a02c55ba | |||
f7d55a8a37 | |||
847292ea30 | |||
a82dbcbd50 | |||
6a7f47e06d | |||
dadc867d9e | |||
5734a0a0e9 | |||
3b2fa978e1 | |||
109fdad8b3 | |||
65c775b83c | |||
45a55044dd | |||
95b646046b | |||
3936fe9360 | |||
2c04b87418 | |||
1b0e7c84c7 | |||
2de811e0af | |||
eb4ce980fe | |||
60ae2d4565 | |||
84b8d733c0 | |||
583efec3f8 | |||
ed26992d7f | |||
bb16fd80b8 | |||
259517ac9b | |||
d5ae74f860 | |||
b68ad9e4f9 | |||
f8f10a1730 | |||
38676308e3 | |||
813e82415a | |||
555b7cc982 | |||
7871ee7ca8 | |||
e39d5689e5 | |||
c9d8bd59f0 | |||
6ecf1cf534 | |||
9f69191f23 | |||
cd424d79e7 | |||
8c03f6a823 | |||
6b67f46c80 | |||
7b538e9750 | |||
f578c3ea29 | |||
60aed39bc5 | |||
6838a9e768 | |||
206235ed47 | |||
a9c7ad84c8 | |||
c1fe326f67 | |||
3268806f75 | |||
b2ed0edce0 | |||
bb9a299e33 | |||
5007041bc8 | |||
659594bac7 | |||
606957dc24 | |||
8fbd414a86 | |||
52c887925f | |||
b6427d017b | |||
20e3b3c0e2 | |||
3277d199ac | |||
47aa9ddcc3 | |||
8ff6506ad9 | |||
b1f91439c6 | |||
07302e0d2a | |||
b20ba1f938 | |||
3cb79ebc86 | |||
0ea249aac4 | |||
4c41456ddf | |||
2649fa1507 | |||
e8bc2cec9f | |||
4a90f41122 | |||
3b4413a6ee | |||
98e6ca5f78 | |||
73932f0349 | |||
fe5b50d885 | |||
d0b218c18e | |||
3c80bdfefa | |||
33cc8591dc | |||
c81613690b | |||
65999ac6d6 | |||
3d8993b0c5 | |||
9ed92e5e6f | |||
70212d9f4e | |||
8216b26fde | |||
ea548dea5b | |||
d99be25529 | |||
262d34174e | |||
b79efa6d6c | |||
096fbec156 | |||
dc9ef41bec | |||
b0634ab0a2 | |||
ef01b78140 | |||
212cd58f9a | |||
788f7a3745 | |||
95bc5a871b | |||
04236859da | |||
5289497ab5 | |||
d35524ecbc | |||
8e7593d68a | |||
b4561465ba | |||
d600d48816 | |||
87f64d99cd | |||
d74f2c7560 | |||
579115f904 | |||
2b646551e9 | |||
e9a9a543ce | |||
0d4d4123ab | |||
7247a1af7e | |||
9ec2283d13 | |||
319fa9ddb6 | |||
e04e6a6f15 | |||
9fd5ef0194 | |||
8d3ac33b0e | |||
872c350a92 | |||
ef3e5c4582 | |||
dbeb04895b | |||
4ebd937fe0 | |||
abcd818f2f | |||
2a632ae711 | |||
d7036edb94 | |||
dd210e99af | |||
904721cc36 | |||
dd193fd64d | |||
e4944a067c | |||
d423c00115 | |||
569724843e | |||
849053b830 | |||
71487d60ca | |||
3eca16ff78 | |||
405e1149e5 | |||
4d59ddc3db | |||
6ff1cf46c5 | |||
f2a9d29696 | |||
a115bf1186 | |||
925a54dec9 | |||
17ed9b7796 | |||
5eb3d77bdb | |||
0a512abc33 | |||
5b93799ea6 | |||
1c0ca4c329 | |||
3483dff2ab | |||
5036cdbef3 | |||
6972e72fbf | |||
f0be1b1fff | |||
54edeacb2d | |||
986dc2047e | |||
f0a25b5e2b | |||
de6ed5c085 | |||
42f0687a6b | |||
c8a36a79de | |||
37d1dcb886 | |||
c34c6238c6 | |||
7a22d12d0f | |||
914bf8b9fc | |||
4d4ca2f3bd | |||
f13eff79c9 | |||
6b0558d6c7 | |||
3ef939aca8 | |||
5cf9e938cc | |||
b90492562a | |||
f14bacba32 | |||
6a3dc94108 | |||
d5352a9b87 | |||
e7ae35c659 | |||
5169c09fd8 | |||
78ae109a08 | |||
da403c01d0 | |||
3d2935ac69 | |||
ccf79ab5b6 | |||
671f298935 | |||
56498e5bc1 | |||
8676fcd9a9 | |||
60872f936c | |||
08ffe89682 | |||
7ce505fdf9 | |||
63dbf99592 | |||
95bf5c1071 | |||
c4e60946d3 | |||
88e3dc15b2 | |||
7145982b4a | |||
eabee85ba9 | |||
b4065c7764 | |||
8a1e0dab03 | |||
2d33274c23 | |||
968d7fad81 | |||
66b75802b2 | |||
5b521e039b | |||
9b5095e5b8 | |||
badcacad49 | |||
f6ae0348cb | |||
be4ac0bc8f | |||
f7dd91891a | |||
1a623a6a52 | |||
a19fa231f5 | |||
9f2d5b64e0 | |||
a926312b25 | |||
242ca355f5 | |||
8ddccfe3bd | |||
3fd306356a | |||
243ea9cd87 | |||
eacda67f02 | |||
18d19fbb2c | |||
a37f01cd0e | |||
96462ba8dc | |||
7a0cbfb2f5 | |||
219d85d700 | |||
d6af9da566 | |||
f6ec65d35d | |||
8eb13ec627 | |||
723e715022 | |||
2f16b1e733 | |||
d4abfacd27 | |||
d2d1ef9a85 | |||
aea18c423e | |||
f6b17d6e2e | |||
338651af2f | |||
9b53e2b64f | |||
7afaa752f3 | |||
1aef000eff | |||
e2418d61a6 | |||
f612b095c1 | |||
2790a40d6c | |||
2e244a8bf6 | |||
3c7e2c7cff | |||
066930b110 | |||
7227c3a866 | |||
067cd95731 | |||
b1d9d55f50 | |||
4dd6594845 | |||
9ba21b1e28 | |||
87bf843bef | |||
45b0193ef3 | |||
b237287315 | |||
ec8538b442 | |||
41c0ca6c52 | |||
f8614e23a8 | |||
d1500a7868 | |||
1d4d01d190 | |||
b12bace385 | |||
7e04c055b3 | |||
355bc2b905 | |||
767850e125 | |||
d1b315c7df | |||
1d28e1398e | |||
71f1722b88 | |||
9da0b0b2b2 | |||
8b1fef730d | |||
234fd8e300 | |||
0467b6a1bf | |||
7c48274c9b | |||
9597a0121b | |||
da972e1b58 | |||
e9a4056deb | |||
9056ad36ed | |||
5b8a6e35dc | |||
cbfa21d45a | |||
b673e13892 | |||
7d57988979 | |||
20900227f8 | |||
ebcc4742a9 | |||
abdf04ce79 | |||
0e2438416d | |||
5b41f2a6bd | |||
c77ec9e7fc | |||
3f71babfa9 | |||
24bfbfbd33 | |||
80cee27429 | |||
d48fe8fb09 | |||
6e1bb16d4e | |||
237dd4a256 | |||
5ac32b14f0 | |||
684da2b8d5 | |||
69237bc2e8 | |||
49fa2fe32c | |||
50a1b5170a | |||
19e51575cf | |||
3122f62b0a | |||
291710f257 | |||
d873fcbf8e | |||
6c70abfe16 | |||
5af0c15dfc | |||
1946af64af | |||
e5c46c5ec1 | |||
43d3ca7e37 | |||
d44a06fafc | |||
2f58c3a305 | |||
0f286461d0 | |||
d35a6e6c14 | |||
9489b7abc1 | |||
fe9aa46cf8 | |||
ea01028655 | |||
b016f2995a | |||
e950051b4a | |||
6b205e166b | |||
cc0469fef6 | |||
f09836a9eb | |||
4695e87cdc | |||
160a09790e | |||
bc17b5a907 | |||
ad31a1b97d | |||
1e5002c46b | |||
399e6b3a09 | |||
c05b9cbd01 | |||
1825924b7b | |||
6817aa4d03 | |||
b947253ac3 | |||
4b65d6e847 | |||
3e4263f068 | |||
35594d4b71 | |||
281da25bf9 | |||
15c03863c0 | |||
03333c2af0 | |||
431709a3ec | |||
5c41b65a10 | |||
e1aa285b6d | |||
7ec6d2ceaa | |||
ecf3b4b535 | |||
a5d2cbd7db | |||
0ea692a5ea | |||
01195093e3 | |||
fc4199c3b1 | |||
328737d0ad | |||
1415cd2339 | |||
44d4678089 | |||
ee2ee745c7 | |||
d546317e6a | |||
40d952a349 | |||
e40c9f42c6 | |||
c075e1bf23 | |||
db535e25f2 | |||
2c2ccf8a8d | |||
0e6f8d3f82 | |||
1b5127dc85 | |||
6eda5a0838 | |||
e26f0d54b2 | |||
9f7f8073f1 | |||
fb9a5678fc | |||
4e76b8133e | |||
326e5cf5fe | |||
6553450b4b | |||
a42832ca01 | |||
e3ad5d25c1 | |||
7e3af7cf83 | |||
36715e3f4c | |||
e77ca55b1d | |||
a7d3b4c4a0 | |||
9580f51c30 | |||
e34a438e77 | |||
4d8aca8417 | |||
a405357578 | |||
ea1d55b033 | |||
5595b0f3ce | |||
eb362dcad2 | |||
f45a8cc171 | |||
21650b064d | |||
33b834ad91 | |||
7c360be1e0 | |||
bd0b9cb877 | |||
fc08754b98 | |||
9284fe81da | |||
906f941f32 | |||
af27a2441a | |||
c5e5de1530 | |||
2cc4386b4c | |||
03b0ae7b68 | |||
b48a0a4a4c | |||
fe45c7eb8b | |||
0d016e5a2b | |||
a0ee010926 | |||
eb2df3d88c | |||
69e9710bf1 | |||
841b28b65d | |||
8a8761ea88 | |||
5582ca278b | |||
94137896cc | |||
35eff6dfba | |||
640cc1ddec | |||
5b0f80509f | |||
da9bb97b23 | |||
3dbf353385 | |||
3af241b9c4 | |||
e0e1e64a09 | |||
30ed08005f | |||
c88c6c2a45 | |||
aaabbe8aef | |||
78aad91aab | |||
3654c7bf81 | |||
e791f44c41 | |||
42838272a5 | |||
87852e5f2a | |||
7079c9c56d | |||
06ae64d59c | |||
a65a19f583 | |||
4a35035b28 | |||
80b1d28bc8 | |||
bd468a1b74 | |||
335df7787a | |||
8f39820ace | |||
996dbc9e4b | |||
5218a0d84f | |||
93678adc5a | |||
5d071a1cf1 | |||
0e56a094d3 | |||
e252a5b795 | |||
093fef5d6f | |||
163779622f | |||
b2b6b8ee23 | |||
ea49d88c4b | |||
7e8d92f956 | |||
f7b7e10d05 | |||
b6bf9d7147 | |||
f7bd661e69 | |||
fa058ee602 | |||
d3e2652078 | |||
c50d9d90d6 | |||
af6d18d60b | |||
52c05e2f3d | |||
b7e3449b04 | |||
a3903f80fb | |||
b5fe1fa530 | |||
6579200f55 | |||
68cda479d6 | |||
22e4dabd1b | |||
43ac0ec04b | |||
fb6172fdc5 | |||
dd4a5a45e3 | |||
72963f5855 | |||
d0e8eb386c | |||
238892bd66 | |||
6d6c78b255 | |||
fa38a37604 | |||
c93ee5c6cd | |||
abccd81fdf | |||
083cc7c50a | |||
685c18dc4e | |||
bfc7a768ce | |||
7a426acece | |||
54eeb71f02 | |||
6ab07aeb19 | |||
1001c1d48b | |||
99b90e625d | |||
ddae9ee80f | |||
d8ed5bb1c1 | |||
e15839b3a6 | |||
a7964c7200 | |||
b3faf1e4ad | |||
5190e4c16e | |||
09144b18c4 | |||
7dd4694d9d | |||
8f17d5147e | |||
85048cc9ee | |||
d9fa13b6eb | |||
6eedb3f097 | |||
d330958abb | |||
1977942c4b | |||
3d2bdae14d | |||
dba26baee6 | |||
424c82ce16 | |||
5cb591a063 | |||
6fe0f45c27 | |||
c9e4c73bd2 | |||
1f4391f56e | |||
1d1bb88a6f | |||
9bdbc2c380 | |||
1437f33027 | |||
9aa57f29b8 | |||
9ec0b80497 | |||
f16cce8be1 | |||
b0d88129db | |||
c747952336 | |||
01551b8fa5 | |||
1369e792b4 | |||
d2325e60b6 | |||
a8247eb2f0 | |||
0ce67de8c8 | |||
59b25bee86 | |||
0ddc44062d | |||
2ec486a880 | |||
827f185e20 | |||
a7450144de | |||
0a57103339 | |||
f6e88e83db | |||
e2f07cbcd1 | |||
831a01e79e | |||
c73cb90c36 | |||
a762c159fe | |||
2425685e44 | |||
666341d03d | |||
79e7fee807 | |||
a38a2f4b3a | |||
33a7c033a2 | |||
19e257a90a | |||
8397f5b2b1 | |||
0066a6b788 | |||
29b4480fc4 | |||
e24f9b89e4 | |||
1f1831c4a1 | |||
f6b9b23287 | |||
89f490ac36 | |||
d17146d847 | |||
fa6cbe7e0c | |||
625f3dc79c | |||
9382eb03e6 | |||
29a15e8154 | |||
138cac98d1 | |||
f7d8f0c161 | |||
6abb3cc525 | |||
f33949ba4b | |||
356d1d35dc | |||
e765f8c99b | |||
8168885dd9 | |||
3159ccbc40 | |||
d99ed47150 | |||
950a48078c | |||
9c3a9323b7 | |||
37a70df244 | |||
10c24e39a3 | |||
2039aa5665 | |||
2f14fd5d4d | |||
2b44e1c9c4 | |||
b8af3b5e3d | |||
537e2ceb18 | |||
ee765eafc7 | |||
801bd4d7eb | |||
bf7bc342ff | |||
af4e9db9e3 | |||
b594bc2a97 | |||
8a93a873a8 | |||
e7f7625adf | |||
cb919ada2a | |||
12f51575eb | |||
8eb1a5b13e | |||
46986f69e4 | |||
d47496db40 | |||
16af33a7bb | |||
3887cb8ca1 | |||
3f1d68542e | |||
e8a16ac59c | |||
1ee445ce24 | |||
b51536c772 | |||
d79f072851 | |||
64f84d9d9f | |||
8f1517d276 | |||
1631e739b8 | |||
07950b0c2b | |||
cd1b26b04c | |||
c6e34cada6 | |||
4db655e489 | |||
cbc8012198 | |||
907664cea9 | |||
5e3b7c3625 | |||
743d8abeaf |
@ -35,7 +35,7 @@ public:
|
||||
ReturnValue_t handleActionMessage(CommandMessage* command);
|
||||
/**
|
||||
* Helper initialize function. Must be called before use of any other helper function
|
||||
* @param queueToUse_ Pointer to the messageQueue to be used, optional if queue was set in constructor
|
||||
* @param queueToUse_ Pointer to the messageQueue to be used
|
||||
* @return Returns RETURN_OK if successful
|
||||
*/
|
||||
ReturnValue_t initialize(MessageQueueIF* queueToUse_ = nullptr);
|
||||
|
@ -10,7 +10,7 @@ class ActionMessage {
|
||||
private:
|
||||
ActionMessage();
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::ACTION;
|
||||
static const uint8_t MESSAGE_ID = messagetypes::ACTION;
|
||||
static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1);
|
||||
static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2);
|
||||
static const Command_t STEP_FAILED = MAKE_COMMAND_ID(3);
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef ARRAYLIST_H_
|
||||
#define ARRAYLIST_H_
|
||||
#ifndef FRAMEWORK_CONTAINER_ARRAYLIST_H_
|
||||
#define FRAMEWORK_CONTAINER_ARRAYLIST_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
/**
|
||||
* A List that stores its values in an array.
|
||||
*
|
||||
* The backend is an array that can be allocated by the class itself or supplied via ctor.
|
||||
*
|
||||
* @brief A List that stores its values in an array.
|
||||
* @details
|
||||
* The underlying storage is an array that can be allocated by the class
|
||||
* itself or supplied via ctor.
|
||||
*
|
||||
* @ingroup container
|
||||
*/
|
||||
@ -20,85 +20,13 @@ public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
/**
|
||||
* An Iterator to go trough an ArrayList
|
||||
*
|
||||
* It stores a pointer to an element and increments the
|
||||
* pointer when incremented itself.
|
||||
*/
|
||||
class Iterator {
|
||||
public:
|
||||
/**
|
||||
* Empty ctor, points to NULL
|
||||
*/
|
||||
Iterator() :
|
||||
value(0) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Iterator to point to an element
|
||||
*
|
||||
* @param initialize
|
||||
*/
|
||||
Iterator(T *initialize) {
|
||||
value = initialize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current element the iterator points to
|
||||
*/
|
||||
T *value;
|
||||
|
||||
Iterator& operator++() {
|
||||
value++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator++(int) {
|
||||
Iterator tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Iterator& operator--() {
|
||||
value--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator--(int) {
|
||||
Iterator tmp(*this);
|
||||
operator--();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T& operator*(){
|
||||
return *value;
|
||||
}
|
||||
|
||||
const T& operator*() const{
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->(){
|
||||
return value;
|
||||
}
|
||||
|
||||
const T *operator->() const{
|
||||
return value;
|
||||
}
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator==(const typename ArrayList<T, count_t>::Iterator& other) const{
|
||||
return (value == other.value);
|
||||
}
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator!=(const typename ArrayList<T, count_t>::Iterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
}
|
||||
;
|
||||
/**
|
||||
* Copying is forbiden by declaring copy ctor and copy assignment deleted
|
||||
* It is too ambigous in this case.
|
||||
* (Allocate a new backend? Use the same? What to do in an modifying call?)
|
||||
*/
|
||||
ArrayList(const ArrayList& other) = delete;
|
||||
const ArrayList& operator=(const ArrayList& other) = delete;
|
||||
|
||||
/**
|
||||
* Number of Elements stored in this List
|
||||
@ -139,6 +67,78 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Iterator to go trough an ArrayList
|
||||
*
|
||||
* It stores a pointer to an element and increments the
|
||||
* pointer when incremented itself.
|
||||
*/
|
||||
class Iterator {
|
||||
public:
|
||||
/**
|
||||
* Empty ctor, points to NULL
|
||||
*/
|
||||
Iterator(): value(0) {}
|
||||
|
||||
/**
|
||||
* Initializes the Iterator to point to an element
|
||||
*
|
||||
* @param initialize
|
||||
*/
|
||||
Iterator(T *initialize) {
|
||||
value = initialize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current element the iterator points to
|
||||
*/
|
||||
T *value;
|
||||
|
||||
Iterator& operator++() {
|
||||
value++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator++(int) {
|
||||
Iterator tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Iterator& operator--() {
|
||||
value--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator--(int) {
|
||||
Iterator tmp(*this);
|
||||
operator--();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
return value;
|
||||
}
|
||||
|
||||
const T *operator->() const{
|
||||
return value;
|
||||
}
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator==(const typename ArrayList<T, count_t>::Iterator& other) const{
|
||||
return (value == other.value);
|
||||
}
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator!=(const typename ArrayList<T, count_t>::Iterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterator pointing to the first stored elmement
|
||||
*
|
||||
@ -227,19 +227,7 @@ public:
|
||||
count_t remaining() {
|
||||
return (maxSize_ - size);
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* This is the copy constructor
|
||||
*
|
||||
* It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same?
|
||||
* What to do in an modifying call?)
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
ArrayList(const ArrayList& other) :
|
||||
size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated(
|
||||
false) {
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* pointer to the array in which the entries are stored
|
||||
@ -254,6 +242,6 @@ protected:
|
||||
* true if the array was allocated and needs to be deleted in the destructor.
|
||||
*/
|
||||
bool allocated;
|
||||
|
||||
};
|
||||
|
||||
#endif /* ARRAYLIST_H_ */
|
||||
|
42
container/DynamicFIFO.h
Normal file
42
container/DynamicFIFO.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
|
||||
#define FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
|
||||
|
||||
#include <framework/container/FIFOBase.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief Simple First-In-First-Out data structure. The maximum size
|
||||
* can be set in the constructor.
|
||||
* @details
|
||||
* The maximum capacity can be determined at run-time, so this container
|
||||
* performs dynamic memory allocation!
|
||||
* The public interface of FIFOBase exposes the user interface for the FIFO.
|
||||
* @tparam T Entry Type
|
||||
* @tparam capacity Maximum capacity
|
||||
*/
|
||||
template<typename T>
|
||||
class DynamicFIFO: public FIFOBase<T> {
|
||||
public:
|
||||
DynamicFIFO(size_t maxCapacity): FIFOBase<T>(nullptr, maxCapacity),
|
||||
fifoVector(maxCapacity) {
|
||||
// trying to pass the pointer of the uninitialized vector
|
||||
// to the FIFOBase constructor directly lead to a super evil bug.
|
||||
// So we do it like this now.
|
||||
this->setData(fifoVector.data());
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Custom copy constructor which prevents setting the
|
||||
* underlying pointer wrong.
|
||||
*/
|
||||
DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other),
|
||||
fifoVector(other.maxCapacity) {
|
||||
this->setData(fifoVector.data());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<T> fifoVector;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_DYNAMICFIFO_H_ */
|
@ -1,82 +1,34 @@
|
||||
#ifndef FIFO_H_
|
||||
#define FIFO_H_
|
||||
#ifndef FRAMEWORK_CONTAINER_FIFO_H_
|
||||
#define FRAMEWORK_CONTAINER_FIFO_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/container/FIFOBase.h>
|
||||
#include <array>
|
||||
|
||||
/**
|
||||
* @brief Simple First-In-First-Out data structure
|
||||
* @brief Simple First-In-First-Out data structure with size fixed at
|
||||
* compile time
|
||||
* @details
|
||||
* Performs no dynamic memory allocation.
|
||||
* The public interface of FIFOBase exposes the user interface for the FIFO.
|
||||
* @tparam T Entry Type
|
||||
* @tparam capacity Maximum capacity
|
||||
*/
|
||||
template<typename T, uint8_t capacity>
|
||||
class FIFO {
|
||||
private:
|
||||
uint8_t readIndex, writeIndex, currentSize;
|
||||
T data[capacity];
|
||||
|
||||
uint8_t next(uint8_t current) {
|
||||
++current;
|
||||
if (current == capacity) {
|
||||
current = 0;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
template<typename T, size_t capacity>
|
||||
class FIFO: public FIFOBase<T> {
|
||||
public:
|
||||
FIFO() :
|
||||
readIndex(0), writeIndex(0), currentSize(0) {
|
||||
FIFO(): FIFOBase<T>(fifoArray.data(), capacity) {};
|
||||
|
||||
/**
|
||||
* @brief Custom copy constructor to set pointer correctly.
|
||||
* @param other
|
||||
*/
|
||||
FIFO(const FIFO& other): FIFOBase<T>(other) {
|
||||
this->setData(fifoArray.data());
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
return (currentSize == 0);
|
||||
}
|
||||
|
||||
bool full() {
|
||||
return (currentSize == capacity);
|
||||
}
|
||||
|
||||
uint8_t size(){
|
||||
return currentSize;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(T value) {
|
||||
if (full()) {
|
||||
return FULL;
|
||||
} else {
|
||||
data[writeIndex] = value;
|
||||
writeIndex = next(writeIndex);
|
||||
++currentSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t retrieve(T *value) {
|
||||
if (empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
*value = data[readIndex];
|
||||
readIndex = next(readIndex);
|
||||
--currentSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t peek(T * value) {
|
||||
if(empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
*value = data[readIndex];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t pop() {
|
||||
T value;
|
||||
return this->retrieve(&value);
|
||||
}
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2);
|
||||
private:
|
||||
std::array<T, capacity> fifoArray;
|
||||
};
|
||||
|
||||
#endif /* FIFO_H_ */
|
||||
#endif /* FRAMEWORK_CONTAINERS_STATICFIFO_H_ */
|
||||
|
65
container/FIFOBase.h
Normal file
65
container/FIFOBase.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_FIFOBASE_H_
|
||||
#define FRAMEWORK_CONTAINER_FIFOBASE_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
template <typename T>
|
||||
class FIFOBase {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2);
|
||||
|
||||
/** Default ctor, takes pointer to first entry of underlying container
|
||||
* and maximum capacity */
|
||||
FIFOBase(T* values, const size_t maxCapacity);
|
||||
|
||||
/**
|
||||
* Insert value into FIFO
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t insert(T value);
|
||||
/**
|
||||
* Retrieve item from FIFO. This removes the item from the FIFO.
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t retrieve(T *value);
|
||||
/**
|
||||
* Retrieve item from FIFO without removing it from FIFO.
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t peek(T * value);
|
||||
/**
|
||||
* Remove item from FIFO.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t pop();
|
||||
|
||||
bool empty();
|
||||
bool full();
|
||||
size_t size();
|
||||
|
||||
|
||||
size_t getMaxCapacity() const;
|
||||
|
||||
protected:
|
||||
void setData(T* data);
|
||||
size_t maxCapacity = 0;
|
||||
|
||||
T* values;
|
||||
|
||||
size_t readIndex = 0;
|
||||
size_t writeIndex = 0;
|
||||
size_t currentSize = 0;
|
||||
|
||||
size_t next(size_t current);
|
||||
};
|
||||
|
||||
#include <framework/container/FIFOBase.tpp>
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_FIFOBASE_H_ */
|
87
container/FIFOBase.tpp
Normal file
87
container/FIFOBase.tpp
Normal file
@ -0,0 +1,87 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_FIFOBASE_TPP_
|
||||
#define FRAMEWORK_CONTAINER_FIFOBASE_TPP_
|
||||
|
||||
#ifndef FRAMEWORK_CONTAINER_FIFOBASE_H_
|
||||
#error Include FIFOBase.h before FIFOBase.tpp!
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline FIFOBase<T>::FIFOBase(T* values, const size_t maxCapacity):
|
||||
maxCapacity(maxCapacity), values(values){};
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t FIFOBase<T>::insert(T value) {
|
||||
if (full()) {
|
||||
return FULL;
|
||||
} else {
|
||||
values[writeIndex] = value;
|
||||
writeIndex = next(writeIndex);
|
||||
++currentSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t FIFOBase<T>::retrieve(T* value) {
|
||||
if (empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
*value = values[readIndex];
|
||||
readIndex = next(readIndex);
|
||||
--currentSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t FIFOBase<T>::peek(T* value) {
|
||||
if(empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
*value = values[readIndex];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t FIFOBase<T>::pop() {
|
||||
T value;
|
||||
return this->retrieve(&value);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline bool FIFOBase<T>::empty() {
|
||||
return (currentSize == 0);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline bool FIFOBase<T>::full() {
|
||||
return (currentSize == maxCapacity);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t FIFOBase<T>::size() {
|
||||
return currentSize;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t FIFOBase<T>::next(size_t current) {
|
||||
++current;
|
||||
if (current == maxCapacity) {
|
||||
current = 0;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t FIFOBase<T>::getMaxCapacity() const {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void FIFOBase<T>::setData(T *data) {
|
||||
this->values = data;
|
||||
}
|
||||
|
||||
#endif
|
@ -2,18 +2,41 @@
|
||||
#define FIXEDARRAYLIST_H_
|
||||
|
||||
#include <framework/container/ArrayList.h>
|
||||
|
||||
/**
|
||||
* \ingroup container
|
||||
* @brief Array List with a fixed maximum size
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class FixedArrayList: public ArrayList<T, count_t> {
|
||||
private:
|
||||
T data[MAX_SIZE];
|
||||
public:
|
||||
/**
|
||||
* (Robin) Maybe we should also implement move assignment and move ctor.
|
||||
* Or at least delete them.
|
||||
*/
|
||||
FixedArrayList() :
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
}
|
||||
|
||||
// (Robin): We could create a constructor to initialize the fixed array list
|
||||
// with data and the known size field
|
||||
// so it can be used for serialization too (with SerialFixedArrrayListAdapter)
|
||||
// is this feasible?
|
||||
/**
|
||||
* Initialize a fixed array list with data and number of data fields.
|
||||
* Endianness of entries can be swapped optionally.
|
||||
* @param data_
|
||||
* @param count
|
||||
* @param swapArrayListEndianess
|
||||
*/
|
||||
FixedArrayList(T * data_, count_t count):
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, data_, count * sizeof(T));
|
||||
this->size = count;
|
||||
}
|
||||
|
||||
FixedArrayList(const FixedArrayList& other) :
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
|
@ -1,16 +1,16 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_FIXEDMAP_H_
|
||||
#define FRAMEWORK_CONTAINER_FIXEDMAP_H_
|
||||
#ifndef FIXEDMAP_H_
|
||||
#define FIXEDMAP_H_
|
||||
|
||||
#include <framework/container/ArrayList.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* \ingroup container
|
||||
*
|
||||
*
|
||||
* \warning Iterators return a non-const key_t in the pair.
|
||||
* \warning A User is not allowed to change the key, otherwise the map is corrupted.
|
||||
* @brief Map implementation for maps with a pre-defined size.
|
||||
* @details Can be initialized with desired maximum size.
|
||||
* Iterator is used to access <key,value> pair and
|
||||
* iterate through map entries. Complexity O(n).
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename key_t, typename T>
|
||||
class FixedMap: public SerializeIF {
|
||||
@ -51,8 +51,29 @@ public:
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
// -> operator overloaded, can be used to access value
|
||||
T *operator->() {
|
||||
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
// Can be used to access the key of the iterator
|
||||
key_t first() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->first;
|
||||
}
|
||||
|
||||
// Alternative to access value, similar to std::map implementation
|
||||
T second() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Iterator begin() const {
|
||||
return Iterator(&theMap[0]);
|
||||
}
|
||||
@ -65,16 +86,16 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) {
|
||||
if (exists(key) == HasReturnvaluesIF::RETURN_OK) {
|
||||
return KEY_ALREADY_EXISTS;
|
||||
return FixedMap::KEY_ALREADY_EXISTS;
|
||||
}
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
return FixedMap::MAP_FULL;
|
||||
}
|
||||
theMap[_size].first = key;
|
||||
theMap[_size].second = value;
|
||||
if (storedValue != nullptr) {
|
||||
if (storedValue != NULL) {
|
||||
*storedValue = Iterator(&theMap[_size]);
|
||||
}
|
||||
++_size;
|
||||
@ -143,6 +164,16 @@ public:
|
||||
return theMap.maxSize();
|
||||
}
|
||||
|
||||
|
||||
bool full() {
|
||||
if(_size == theMap.maxSize()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&this->_size,
|
||||
|
@ -10,7 +10,7 @@
|
||||
template<typename key_t, typename T, typename KEY_COMPARE = std::less<key_t>>
|
||||
class FixedOrderedMultimap {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MULTIMAP;
|
||||
static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03);
|
||||
@ -48,7 +48,7 @@ private:
|
||||
if (_size <= position) {
|
||||
return;
|
||||
}
|
||||
memmove(static_cast<void*>(&theMap[position]), static_cast<void*>(&theMap[position + 1]),
|
||||
memmove(&theMap[position], &theMap[position + 1],
|
||||
(_size - position - 1) * sizeof(std::pair<key_t,T>));
|
||||
--_size;
|
||||
}
|
||||
@ -68,6 +68,15 @@ public:
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Iterator begin() const {
|
||||
@ -82,17 +91,17 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) {
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
}
|
||||
uint32_t position = findNicePlace(key);
|
||||
memmove(static_cast<void*>(&theMap[position + 1]),static_cast<void*>(&theMap[position]),
|
||||
memmove(&theMap[position + 1], &theMap[position],
|
||||
(_size - position) * sizeof(std::pair<key_t,T>));
|
||||
theMap[position].first = key;
|
||||
theMap[position].second = value;
|
||||
++_size;
|
||||
if (storedValue != nullptr) {
|
||||
if (storedValue != NULL) {
|
||||
*storedValue = Iterator(&theMap[position]);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -136,6 +145,12 @@ public:
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
//This is potentially unsafe
|
||||
// T *findValue(key_t key) const {
|
||||
// return &theMap[findFirstIndex(key)].second;
|
||||
// }
|
||||
|
||||
|
||||
Iterator find(key_t key) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
|
@ -8,20 +8,27 @@
|
||||
#include <framework/serialize/SerialArrayListAdapter.h>
|
||||
#include <cmath>
|
||||
|
||||
/**
|
||||
* Index is the Type used for the list of indices.
|
||||
*
|
||||
* @tparam T Type which destribes the index. Needs to be a child of SerializeIF
|
||||
* to be able to make it persistent
|
||||
*/
|
||||
template<typename T>
|
||||
class Index: public SerializeIF{
|
||||
/**
|
||||
* Index is the Type used for the list of indices. The template parameter is the type which describes the index, it needs to be a child of SerializeIF to be able to make it persistent
|
||||
*
|
||||
*/
|
||||
static_assert(std::is_base_of<SerializeIF,T>::value,"Wrong Type for Index, Type must implement SerializeIF");
|
||||
static_assert(std::is_base_of<SerializeIF,T>::value,
|
||||
"Wrong Type for Index, Type must implement SerializeIF");
|
||||
public:
|
||||
Index():blockStartAddress(0),size(0),storedPackets(0){}
|
||||
|
||||
Index(uint32_t startAddress):blockStartAddress(startAddress),size(0),storedPackets(0){
|
||||
|
||||
Index(uint32_t startAddress):blockStartAddress(startAddress),
|
||||
size(0),storedPackets(0) {
|
||||
}
|
||||
|
||||
void setBlockStartAddress(uint32_t newAddress){
|
||||
void setBlockStartAddress(uint32_t newAddress) {
|
||||
this->blockStartAddress = newAddress;
|
||||
}
|
||||
|
||||
@ -33,7 +40,7 @@ public:
|
||||
return &indexType;
|
||||
}
|
||||
|
||||
T* modifyIndexType(){
|
||||
T* modifyIndexType() {
|
||||
return &indexType;
|
||||
}
|
||||
/**
|
||||
@ -128,26 +135,35 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indexed Ring Memory Array is a class for a ring memory with indices.
|
||||
* @details
|
||||
* It assumes that the newest data comes in last
|
||||
* It uses the currentWriteBlock as pointer to the current writing position
|
||||
* The currentReadBlock must be set manually
|
||||
* @tparam T
|
||||
*/
|
||||
template<typename T>
|
||||
class IndexedRingMemoryArray: public SerializeIF, public ArrayList<Index<T>, uint32_t>{
|
||||
/**
|
||||
* Indexed Ring Memory Array is a class for a ring memory with indices. It assumes that the newest data comes in last
|
||||
* It uses the currentWriteBlock as pointer to the current writing position
|
||||
* The currentReadBlock must be set manually
|
||||
*
|
||||
*/
|
||||
public:
|
||||
IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock, SerializeIF* additionalInfo,
|
||||
bool overwriteOld) :ArrayList<Index<T>,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld){
|
||||
|
||||
IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock,
|
||||
SerializeIF* additionalInfo, bool overwriteOld):
|
||||
ArrayList<Index<T>,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),
|
||||
indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),
|
||||
lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld)
|
||||
{
|
||||
//Calculate the maximum number of indices needed for this blocksize
|
||||
uint32_t maxNrOfIndices = floor(static_cast<double>(size)/static_cast<double>(bytesPerBlock));
|
||||
|
||||
//Calculate the Size needeed for the index itself
|
||||
uint32_t serializedSize = 0;
|
||||
if(additionalInfo!=NULL){
|
||||
size_t serializedSize = 0;
|
||||
if(additionalInfo!=NULL) {
|
||||
serializedSize += additionalInfo->getSerializedSize();
|
||||
}
|
||||
|
||||
//Size of current iterator type
|
||||
Index<T> tempIndex;
|
||||
serializedSize += tempIndex.getSerializedSize();
|
||||
@ -162,6 +178,7 @@ public:
|
||||
error << "IndexedRingMemory: Store is too small for index" << std::endl;
|
||||
}
|
||||
uint32_t useableSize = totalSize - serializedSize;
|
||||
|
||||
//Update the totalSize for calculations
|
||||
totalSize = useableSize;
|
||||
|
||||
@ -178,12 +195,10 @@ public:
|
||||
this->allocated = true;
|
||||
|
||||
//Check trueNumberOfBlocks
|
||||
if(trueNumberOfBlocks<1){
|
||||
if(trueNumberOfBlocks<1) {
|
||||
error << "IndexedRingMemory: Invalid Number of Blocks: " << trueNumberOfBlocks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Fill address into index
|
||||
uint32_t address = trueStartAddress;
|
||||
for (typename IndexedRingMemoryArray<T>::Iterator it = this->begin();it!=this->end();++it) {
|
||||
@ -193,7 +208,6 @@ public:
|
||||
address += bytesPerBlock;
|
||||
}
|
||||
|
||||
|
||||
//Initialize iterators
|
||||
currentWriteBlock = this->begin();
|
||||
currentReadBlock = this->begin();
|
||||
@ -232,10 +246,10 @@ public:
|
||||
(*typeResetFnc)(it->modifyIndexType());
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Reading
|
||||
* @param it
|
||||
*/
|
||||
|
||||
void setCurrentReadBlock(typename IndexedRingMemoryArray<T>::Iterator it){
|
||||
currentReadBlock = it;
|
||||
currentReadBlockSizeCached = it->getSize();
|
||||
@ -248,6 +262,7 @@ public:
|
||||
lastBlockToRead = currentWriteBlock;
|
||||
lastBlockToReadSize = currentWriteBlock->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last block to read to this iterator.
|
||||
* Can be used to dump until block x
|
||||
@ -292,33 +307,39 @@ public:
|
||||
uint32_t getCurrentReadAddress() const {
|
||||
return getAddressOfCurrentReadBlock() + currentReadSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds readSize to the current size and checks if the read has no more data left and advances the read block
|
||||
* Adds readSize to the current size and checks if the read has no more data
|
||||
* left and advances the read block.
|
||||
* @param readSize The size that was read
|
||||
* @return Returns true if the read can go on
|
||||
*/
|
||||
bool addReadSize(uint32_t readSize) {
|
||||
if(currentReadBlock == lastBlockToRead){
|
||||
if(currentReadBlock == lastBlockToRead) {
|
||||
//The current read block is the last to read
|
||||
if((currentReadSize+readSize)<lastBlockToReadSize){
|
||||
if((currentReadSize+readSize)<lastBlockToReadSize) {
|
||||
//the block has more data -> return true
|
||||
currentReadSize += readSize;
|
||||
return true;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
//Reached end of read -> return false
|
||||
currentReadSize = lastBlockToReadSize;
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
//We are not in the last Block
|
||||
if((currentReadSize + readSize)<currentReadBlockSizeCached){
|
||||
if((currentReadSize + readSize)<currentReadBlockSizeCached) {
|
||||
//The current Block has more data
|
||||
currentReadSize += readSize;
|
||||
return true;
|
||||
}else{
|
||||
}
|
||||
// TODO: Maybe some logic blocks should be extracted
|
||||
else {
|
||||
//The current block is written completely
|
||||
readNext();
|
||||
if(currentReadBlockSizeCached==0){
|
||||
if(currentReadBlockSizeCached==0) {
|
||||
//Next block is empty
|
||||
typename IndexedRingMemoryArray<T>::Iterator it(currentReadBlock);
|
||||
//Search if any block between this and the last block is not empty
|
||||
@ -421,13 +442,13 @@ public:
|
||||
T* modifyCurrentWriteBlockIndexType(){
|
||||
return currentWriteBlock->modifyIndexType();
|
||||
}
|
||||
|
||||
void updatePreviousWriteSize(uint32_t size, uint32_t storedPackets){
|
||||
typename IndexedRingMemoryArray<T>::Iterator it = getPreviousBlock(currentWriteBlock);
|
||||
it->addSize(size);
|
||||
it->addStoredPackets(storedPackets);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the block has enough space for sizeToWrite
|
||||
* @param sizeToWrite The data to be written in the Block
|
||||
@ -436,7 +457,10 @@ public:
|
||||
bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){
|
||||
typename IndexedRingMemoryArray<T>::Iterator next = getNextWrite();
|
||||
uint32_t addressOfNextBlock = next->getBlockStartAddress();
|
||||
uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize;
|
||||
uint32_t availableSize =
|
||||
( ( addressOfNextBlock + totalSize ) -
|
||||
(getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock()))
|
||||
% totalSize;
|
||||
return (sizeToWrite < availableSize);
|
||||
}
|
||||
|
||||
@ -526,7 +550,7 @@ public:
|
||||
*/
|
||||
size_t getSerializedSize() const {
|
||||
|
||||
uint32_t size = 0;
|
||||
size_t size = 0;
|
||||
if(additionalInfo!=NULL){
|
||||
size += additionalInfo->getSerializedSize();
|
||||
}
|
||||
@ -694,7 +718,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_ */
|
||||
|
@ -1,6 +1,13 @@
|
||||
#ifndef ISDERIVEDFROM_H_
|
||||
#define ISDERIVEDFROM_H_
|
||||
|
||||
/**
|
||||
* These template type checks are based on SFINAE
|
||||
* (https://en.cppreference.com/w/cpp/language/sfinae)
|
||||
*
|
||||
* @tparam D Derived Type
|
||||
* @tparam B Base Type
|
||||
*/
|
||||
template<typename D, typename B>
|
||||
class IsDerivedFrom {
|
||||
class No {
|
||||
@ -9,7 +16,9 @@ class IsDerivedFrom {
|
||||
No no[3];
|
||||
};
|
||||
|
||||
// This will be chosen if B is the base type
|
||||
static Yes Test(B*); // declared, but not defined
|
||||
// This will be chosen for anything else
|
||||
static No Test(... ); // declared, but not defined
|
||||
|
||||
public:
|
||||
|
@ -2,16 +2,76 @@
|
||||
#define FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <cstddef>
|
||||
|
||||
template<uint8_t N_READ_PTRS = 1>
|
||||
class RingBufferBase {
|
||||
public:
|
||||
RingBufferBase(uint32_t startAddress, uint32_t size, bool overwriteOld) :
|
||||
start(startAddress), write(startAddress), size(size), overwriteOld(overwriteOld) {
|
||||
RingBufferBase(size_t startAddress, const size_t size, bool overwriteOld) :
|
||||
start(startAddress), write(startAddress), size(size),
|
||||
overwriteOld(overwriteOld) {
|
||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||
read[count] = startAddress;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~RingBufferBase() {}
|
||||
|
||||
bool isFull(uint8_t n = 0) {
|
||||
return (availableWriteSpace(n) == 0);
|
||||
}
|
||||
bool isEmpty(uint8_t n = 0) {
|
||||
return (availableReadData(n) == 0);
|
||||
}
|
||||
|
||||
size_t availableReadData(uint8_t n = 0) const {
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
||||
size_t availableWriteSpace(uint8_t n = 0) const {
|
||||
//One less to avoid ambiguous full/empty problem.
|
||||
return (((read[n] + size) - write - 1) % size);
|
||||
}
|
||||
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
|
||||
size_t maxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
write = start;
|
||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||
read[count] = start;
|
||||
}
|
||||
}
|
||||
|
||||
size_t writeTillWrap() {
|
||||
return (start + size) - write;
|
||||
}
|
||||
|
||||
size_t readTillWrap(uint8_t n = 0) {
|
||||
return (start + size) - read[n];
|
||||
}
|
||||
|
||||
size_t getStart() const {
|
||||
return start;
|
||||
}
|
||||
|
||||
protected:
|
||||
const size_t start;
|
||||
size_t write;
|
||||
size_t read[N_READ_PTRS];
|
||||
const size_t size;
|
||||
const bool overwriteOld;
|
||||
void incrementWrite(uint32_t amount) {
|
||||
write = ((write + amount - start) % size) + start;
|
||||
}
|
||||
void incrementRead(uint32_t amount, uint8_t n = 0) {
|
||||
read[n] = ((read[n] + amount - start) % size) + start;
|
||||
}
|
||||
|
||||
ReturnValue_t readData(uint32_t amount, uint8_t n = 0) {
|
||||
if (availableReadData(n) >= amount) {
|
||||
incrementRead(amount, n);
|
||||
@ -20,77 +80,34 @@ public:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t writeData(uint32_t amount) {
|
||||
if (availableWriteSpace() >= amount || overwriteOld) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
uint32_t availableReadData(uint8_t n = 0) const {
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
||||
uint32_t availableWriteSpace(uint8_t n = 0) const {
|
||||
//One less to avoid ambiguous full/empty problem.
|
||||
return (((read[n] + size) - write - 1) % size);
|
||||
}
|
||||
bool isFull(uint8_t n = 0) {
|
||||
return (availableWriteSpace(n) == 0);
|
||||
}
|
||||
bool isEmpty(uint8_t n = 0) {
|
||||
return (availableReadData(n) == 0);
|
||||
}
|
||||
virtual ~RingBufferBase() {
|
||||
|
||||
}
|
||||
uint32_t getRead(uint8_t n = 0) const {
|
||||
|
||||
size_t getRead(uint8_t n = 0) const {
|
||||
return read[n];
|
||||
}
|
||||
|
||||
void setRead(uint32_t read, uint8_t n = 0) {
|
||||
if (read >= start && read < (start+size)) {
|
||||
this->read[n] = read;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getWrite() const {
|
||||
return write;
|
||||
}
|
||||
|
||||
void setWrite(uint32_t write) {
|
||||
this->write = write;
|
||||
}
|
||||
void clear() {
|
||||
write = start;
|
||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||
read[count] = start;
|
||||
}
|
||||
}
|
||||
uint32_t writeTillWrap() {
|
||||
return (start + size) - write;
|
||||
}
|
||||
uint32_t readTillWrap(uint8_t n = 0) {
|
||||
return (start + size) - read[n];
|
||||
}
|
||||
uint32_t getStart() const {
|
||||
return start;
|
||||
}
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
uint32_t maxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
protected:
|
||||
const uint32_t start;
|
||||
uint32_t write;
|
||||
uint32_t read[N_READ_PTRS];
|
||||
const uint32_t size;
|
||||
const bool overwriteOld;
|
||||
void incrementWrite(uint32_t amount) {
|
||||
write = ((write + amount - start) % size) + start;
|
||||
}
|
||||
void incrementRead(uint32_t amount, uint8_t n = 0) {
|
||||
read[n] = ((read[n] + amount - start) % size) + start;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_ */
|
||||
|
59
container/SharedRingBuffer.cpp
Normal file
59
container/SharedRingBuffer.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <framework/container/SharedRingBuffer.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes, dur_millis_t mutexTimeout):
|
||||
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
|
||||
maxExcessBytes), mutexTimeout(mutexTimeout) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
|
||||
const size_t size, bool overwriteOld, size_t maxExcessBytes,
|
||||
dur_millis_t mutexTimeout):
|
||||
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
|
||||
maxExcessBytes), mutexTimeout(mutexTimeout) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::getFreeElementProtected(uint8_t** writePtr,
|
||||
size_t amount) {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::getFreeElement(writePtr,amount);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
|
||||
size_t amount) {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::writeData(data,amount);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount,
|
||||
bool incrementReadPtr, bool readRemaining,
|
||||
size_t *trueAmount) {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
|
||||
readRemaining, trueAmount);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
|
||||
bool deleteRemaining, size_t *trueAmount) {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount);
|
||||
}
|
||||
|
||||
size_t SharedRingBuffer::getExcessBytes() const {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::getExcessBytes();
|
||||
}
|
||||
|
||||
void SharedRingBuffer::moveExcessBytesToStart() {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::moveExcessBytesToStart();
|
||||
}
|
||||
|
||||
size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
68
container/SharedRingBuffer.h
Normal file
68
container/SharedRingBuffer.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
#define FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
|
||||
#include <framework/container/SimpleRingBuffer.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/timemanager/Clock.h>
|
||||
|
||||
class SharedRingBuffer: public SystemObject,
|
||||
public SimpleRingBuffer {
|
||||
public:
|
||||
/**
|
||||
* This constructor allocates a new internal buffer with the supplied size.
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes,
|
||||
dur_millis_t mutexTimeout = 10);
|
||||
|
||||
/**
|
||||
* This constructor takes an external buffer with the specified size.
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes,
|
||||
dur_millis_t mutexTimeout = 10);
|
||||
|
||||
void setMutexTimeout(dur_millis_t newTimeout);
|
||||
|
||||
virtual size_t getExcessBytes() const override;
|
||||
/**
|
||||
* Helper functions which moves any excess bytes to the start
|
||||
* of the ring buffer.
|
||||
* @return
|
||||
*/
|
||||
virtual void moveExcessBytesToStart() override;
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::getFreeElement call */
|
||||
ReturnValue_t getFreeElementProtected(uint8_t** writePtr, size_t amount);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::writeData call */
|
||||
ReturnValue_t writeDataProtected(const uint8_t* data, size_t amount);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::readData call */
|
||||
ReturnValue_t readDataProtected(uint8_t *data, size_t amount,
|
||||
bool incrementReadPtr = false,
|
||||
bool readRemaining = false, size_t *trueAmount = nullptr);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::deleteData call */
|
||||
ReturnValue_t deleteDataProtected(size_t amount,
|
||||
bool deleteRemaining = false, size_t* trueAmount = nullptr);
|
||||
|
||||
size_t getAvailableReadDataProtected (uint8_t n = 0) const;
|
||||
private:
|
||||
dur_millis_t mutexTimeout;
|
||||
MutexIF* mutex = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_ */
|
@ -1,22 +1,64 @@
|
||||
#include <framework/container/SimpleRingBuffer.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
SimpleRingBuffer::SimpleRingBuffer(uint32_t size, bool overwriteOld) :
|
||||
RingBufferBase<>(0, size, overwriteOld), buffer(NULL) {
|
||||
buffer = new uint8_t[size];
|
||||
SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes) :
|
||||
RingBufferBase<>(0, size, overwriteOld),
|
||||
maxExcessBytes(maxExcessBytes) {
|
||||
if(maxExcessBytes > size) {
|
||||
this->maxExcessBytes = size;
|
||||
}
|
||||
else {
|
||||
this->maxExcessBytes = maxExcessBytes;
|
||||
}
|
||||
buffer = new uint8_t[size + maxExcessBytes];
|
||||
}
|
||||
|
||||
SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes):
|
||||
RingBufferBase<>(0, size, overwriteOld), buffer(buffer) {
|
||||
if(maxExcessBytes > size) {
|
||||
this->maxExcessBytes = size;
|
||||
}
|
||||
else {
|
||||
this->maxExcessBytes = maxExcessBytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SimpleRingBuffer::~SimpleRingBuffer() {
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer,
|
||||
size_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
size_t amountTillWrap = writeTillWrap();
|
||||
if (amountTillWrap < amount) {
|
||||
if((amount - amountTillWrap + excessBytes) > maxExcessBytes) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
excessBytes = amount - amountTillWrap;
|
||||
}
|
||||
*writePointer = &buffer[write];
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
uint32_t amount) {
|
||||
if (availableWriteSpace() >= amount || overwriteOld) {
|
||||
uint32_t amountTillWrap = writeTillWrap();
|
||||
size_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
size_t amountTillWrap = writeTillWrap();
|
||||
if (amountTillWrap >= amount) {
|
||||
// remaining size in buffer is sufficient to fit full amount.
|
||||
memcpy(&buffer[write], data, amount);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
memcpy(&buffer[write], data, amountTillWrap);
|
||||
memcpy(buffer, data + amountTillWrap, amount - amountTillWrap);
|
||||
}
|
||||
@ -27,18 +69,19 @@ ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
|
||||
bool readRemaining, uint32_t* trueAmount) {
|
||||
uint32_t availableData = availableReadData(READ_PTR);
|
||||
uint32_t amountTillWrap = readTillWrap(READ_PTR);
|
||||
ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, size_t amount,
|
||||
bool incrementReadPtr, bool readRemaining, size_t* trueAmount) {
|
||||
size_t availableData = availableReadData(READ_PTR);
|
||||
size_t amountTillWrap = readTillWrap(READ_PTR);
|
||||
if (availableData < amount) {
|
||||
if (readRemaining) {
|
||||
// more data available than amount specified.
|
||||
amount = availableData;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
if (trueAmount != NULL) {
|
||||
if (trueAmount != nullptr) {
|
||||
*trueAmount = amount;
|
||||
}
|
||||
if (amountTillWrap >= amount) {
|
||||
@ -47,12 +90,27 @@ ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
|
||||
memcpy(data, &buffer[read[READ_PTR]], amountTillWrap);
|
||||
memcpy(data + amountTillWrap, buffer, amount - amountTillWrap);
|
||||
}
|
||||
|
||||
if(incrementReadPtr) {
|
||||
deleteData(amount, readRemaining);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
||||
bool deleteRemaining, uint32_t* trueAmount) {
|
||||
uint32_t availableData = availableReadData(READ_PTR);
|
||||
size_t SimpleRingBuffer::getExcessBytes() const {
|
||||
return excessBytes;
|
||||
}
|
||||
|
||||
void SimpleRingBuffer::moveExcessBytesToStart() {
|
||||
if(excessBytes > 0) {
|
||||
std::memcpy(buffer, &buffer[size], excessBytes);
|
||||
excessBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::deleteData(size_t amount,
|
||||
bool deleteRemaining, size_t* trueAmount) {
|
||||
size_t availableData = availableReadData(READ_PTR);
|
||||
if (availableData < amount) {
|
||||
if (deleteRemaining) {
|
||||
amount = availableData;
|
||||
@ -60,9 +118,10 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
if (trueAmount != NULL) {
|
||||
if (trueAmount != nullptr) {
|
||||
*trueAmount = amount;
|
||||
}
|
||||
incrementRead(amount, READ_PTR);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -2,19 +2,117 @@
|
||||
#define FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
|
||||
#include <framework/container/RingBufferBase.h>
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Circular buffer implementation, useful for buffering
|
||||
* into data streams.
|
||||
* @details
|
||||
* Note that the deleteData() has to be called to increment the read pointer.
|
||||
* This class allocated dynamically, so
|
||||
* @ingroup containers
|
||||
*/
|
||||
class SimpleRingBuffer: public RingBufferBase<> {
|
||||
public:
|
||||
SimpleRingBuffer(uint32_t size, bool overwriteOld);
|
||||
/**
|
||||
* This constructor allocates a new internal buffer with the supplied size.
|
||||
*
|
||||
* @param size
|
||||
* @param overwriteOld If the ring buffer is overflowing at a write
|
||||
* operation, the oldest data will be overwritten.
|
||||
* @param maxExcessBytes These additional bytes will be allocated in addtion
|
||||
* to the specified size to accomodate contiguous write operations
|
||||
* with getFreeElement.
|
||||
*
|
||||
*/
|
||||
SimpleRingBuffer(const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes = 0);
|
||||
/**
|
||||
* This constructor takes an external buffer with the specified size.
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
* @param maxExcessBytes
|
||||
* If the buffer can accomodate additional bytes for contigous write
|
||||
* operations with getFreeElement, this is the maximum allowed additional
|
||||
* size
|
||||
*/
|
||||
SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes = 0);
|
||||
|
||||
virtual ~SimpleRingBuffer();
|
||||
ReturnValue_t writeData(const uint8_t* data, uint32_t amount);
|
||||
ReturnValue_t readData(uint8_t* data, uint32_t amount, bool readRemaining = false, uint32_t* trueAmount = NULL);
|
||||
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false, uint32_t* trueAmount = NULL);
|
||||
|
||||
/**
|
||||
* Write to circular buffer and increment write pointer by amount.
|
||||
* @param data
|
||||
* @param amount
|
||||
* @return -@c RETURN_OK if write operation was successfull
|
||||
* -@c RETURN_FAILED if
|
||||
*/
|
||||
ReturnValue_t writeData(const uint8_t* data, size_t amount);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a free element. If the remaining buffer is
|
||||
* not large enough, the data will be written past the actual size
|
||||
* and the amount of excess bytes will be cached.
|
||||
* @param writePointer Pointer to a pointer which can be used to write
|
||||
* contiguous blocks into the ring buffer
|
||||
* @param amount
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t getFreeElement(uint8_t** writePointer, size_t amount);
|
||||
|
||||
virtual size_t getExcessBytes() const;
|
||||
/**
|
||||
* Helper functions which moves any excess bytes to the start
|
||||
* of the ring buffer.
|
||||
* @return
|
||||
*/
|
||||
virtual void moveExcessBytesToStart();
|
||||
|
||||
/**
|
||||
* Read from circular buffer at read pointer.
|
||||
* @param data
|
||||
* @param amount
|
||||
* @param incrementReadPtr
|
||||
* If this is set to true, the read pointer will be incremented.
|
||||
* If readRemaining is set to true, the read pointer will be incremented
|
||||
* accordingly.
|
||||
* @param readRemaining
|
||||
* If this is set to true, the data will be read even if the amount
|
||||
* specified exceeds the read data available.
|
||||
* @param trueAmount [out]
|
||||
* If readRemaining was set to true, the true amount read will be assigned
|
||||
* to the passed value.
|
||||
* @return
|
||||
* - @c RETURN_OK if data was read successfully
|
||||
* - @c RETURN_FAILED if not enough data was available and readRemaining
|
||||
* was set to false.
|
||||
*/
|
||||
ReturnValue_t readData(uint8_t* data, size_t amount,
|
||||
bool incrementReadPtr = false, bool readRemaining = false,
|
||||
size_t* trueAmount = nullptr);
|
||||
|
||||
/**
|
||||
* Delete data by incrementing read pointer.
|
||||
* @param amount
|
||||
* @param deleteRemaining
|
||||
* If the amount specified is larger than the remaing size to read and this
|
||||
* is set to true, the remaining amount will be deleted as well
|
||||
* @param trueAmount [out]
|
||||
* If deleteRemaining was set to true, the amount deleted will be assigned
|
||||
* to the passed value.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t deleteData(size_t amount, bool deleteRemaining = false,
|
||||
size_t* trueAmount = nullptr);
|
||||
private:
|
||||
// static const uint8_t TEMP_READ_PTR = 1;
|
||||
static const uint8_t READ_PTR = 0;
|
||||
uint8_t* buffer;
|
||||
uint8_t* buffer = nullptr;
|
||||
size_t maxExcessBytes;
|
||||
size_t excessBytes = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||
|
@ -1,10 +1,13 @@
|
||||
#ifndef SINGLYLINKEDLIST_H_
|
||||
#define SINGLYLINKEDLIST_H_
|
||||
#ifndef FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||
#define FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
/**
|
||||
* \ingroup container
|
||||
* @brief Linked list data structure,
|
||||
* each entry has a pointer to the next entry (singly)
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename T>
|
||||
class LinkedElement {
|
||||
@ -12,11 +15,8 @@ public:
|
||||
T *value;
|
||||
class Iterator {
|
||||
public:
|
||||
LinkedElement<T> *value;
|
||||
Iterator() :
|
||||
value(NULL) {
|
||||
|
||||
}
|
||||
LinkedElement<T> *value = nullptr;
|
||||
Iterator() {}
|
||||
|
||||
Iterator(LinkedElement<T> *element) :
|
||||
value(element) {
|
||||
@ -45,12 +45,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
LinkedElement(T* setElement, LinkedElement<T>* setNext = NULL) : value(setElement),
|
||||
next(setNext) {
|
||||
}
|
||||
virtual ~LinkedElement(){
|
||||
LinkedElement(T* setElement, LinkedElement<T>* setNext = nullptr):
|
||||
value(setElement), next(setNext) {}
|
||||
|
||||
virtual ~LinkedElement(){}
|
||||
|
||||
}
|
||||
virtual LinkedElement* getNext() const {
|
||||
return next;
|
||||
}
|
||||
@ -58,11 +57,16 @@ public:
|
||||
virtual void setNext(LinkedElement* next) {
|
||||
this->next = next;
|
||||
}
|
||||
|
||||
virtual void setEnd() {
|
||||
this->next = nullptr;
|
||||
}
|
||||
|
||||
LinkedElement* begin() {
|
||||
return this;
|
||||
}
|
||||
LinkedElement* end() {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
LinkedElement *next;
|
||||
@ -71,37 +75,80 @@ private:
|
||||
template<typename T>
|
||||
class SinglyLinkedList {
|
||||
public:
|
||||
SinglyLinkedList() :
|
||||
start(NULL) {
|
||||
}
|
||||
using ElementIterator = typename LinkedElement<T>::Iterator;
|
||||
|
||||
SinglyLinkedList() {}
|
||||
|
||||
SinglyLinkedList(ElementIterator start) :
|
||||
start(start.value) {}
|
||||
|
||||
SinglyLinkedList(typename LinkedElement<T>::Iterator start) :
|
||||
start(start.value) {
|
||||
}
|
||||
SinglyLinkedList(LinkedElement<T>* startElement) :
|
||||
start(startElement) {
|
||||
}
|
||||
typename LinkedElement<T>::Iterator begin() const {
|
||||
return LinkedElement<T>::Iterator::Iterator(start);
|
||||
}
|
||||
typename LinkedElement<T>::Iterator::Iterator end() const {
|
||||
return LinkedElement<T>::Iterator::Iterator();
|
||||
start(startElement) {}
|
||||
|
||||
ElementIterator begin() const {
|
||||
return ElementIterator::Iterator(start);
|
||||
}
|
||||
|
||||
uint32_t getSize() const {
|
||||
uint32_t size = 0;
|
||||
/** Returns iterator to nulltr */
|
||||
ElementIterator end() const {
|
||||
return ElementIterator::Iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element in singly linked list.
|
||||
* @return
|
||||
*/
|
||||
ElementIterator back() const {
|
||||
LinkedElement<T> *element = start;
|
||||
while (element != nullptr) {
|
||||
element = element->getNext();
|
||||
}
|
||||
return ElementIterator::Iterator(element);
|
||||
}
|
||||
|
||||
size_t getSize() const {
|
||||
size_t size = 0;
|
||||
LinkedElement<T> *element = start;
|
||||
while (element != NULL) {
|
||||
while (element != nullptr) {
|
||||
size++;
|
||||
element = element->getNext();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
void setStart(LinkedElement<T>* setStart) {
|
||||
start = setStart;
|
||||
void setStart(LinkedElement<T>* firstElement) {
|
||||
start = firstElement;
|
||||
}
|
||||
|
||||
void setNext(LinkedElement<T>* currentElement,
|
||||
LinkedElement<T>* nextElement) {
|
||||
currentElement->setNext(nextElement);
|
||||
}
|
||||
|
||||
void setLast(LinkedElement<T>* lastElement) {
|
||||
lastElement->setEnd();
|
||||
}
|
||||
|
||||
void insertElement(LinkedElement<T>* element, size_t position) {
|
||||
LinkedElement<T> *currentElement = start;
|
||||
for(size_t count = 0; count < position; count++) {
|
||||
if(currentElement == nullptr) {
|
||||
return;
|
||||
}
|
||||
currentElement = currentElement->getNext();
|
||||
}
|
||||
LinkedElement<T>* elementAfterCurrent = currentElement->next;
|
||||
currentElement->setNext(element);
|
||||
if(elementAfterCurrent != nullptr) {
|
||||
element->setNext(elementAfterCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
void insertBack(LinkedElement<T>* lastElement) {
|
||||
back().value->setNext(lastElement);
|
||||
}
|
||||
|
||||
protected:
|
||||
LinkedElement<T> *start;
|
||||
LinkedElement<T> *start = nullptr;
|
||||
};
|
||||
|
||||
#endif /* SINGLYLINKEDLIST_H_ */
|
||||
|
@ -4,11 +4,9 @@
|
||||
/**
|
||||
* @defgroup container Container
|
||||
*
|
||||
* General Purpose Container to store various elements.
|
||||
*
|
||||
* Also contains Adapter classes to print elements to a
|
||||
* bytestream and to read them from a bytestream, as well
|
||||
* as an Adapter to swap the endianness.
|
||||
* General Purpose Containers to store various elements.
|
||||
* As opposed to the STL library implementation, these implementations
|
||||
* don't allocate memory dynamically.
|
||||
*/
|
||||
|
||||
|
||||
|
@ -56,26 +56,26 @@ MessageQueueId_t ControllerBase::getCommandQueue() const {
|
||||
}
|
||||
|
||||
void ControllerBase::handleQueue() {
|
||||
CommandMessage message;
|
||||
CommandMessage command;
|
||||
ReturnValue_t result;
|
||||
for (result = commandQueue->receiveMessage(&message); result == RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&message)) {
|
||||
for (result = commandQueue->receiveMessage(&command); result == RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&command)) {
|
||||
|
||||
result = modeHelper.handleModeCommand(&message);
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = healthHelper.handleHealthCommand(&message);
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
result = handleCommandMessage(&message);
|
||||
result = handleCommandMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
message.setToUnknownCommand();
|
||||
commandQueue->reply(&message);
|
||||
command.setToUnknownCommand();
|
||||
commandQueue->reply(&command);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
|
||||
MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0), bufferPosition(
|
||||
packetBuffer), packetDestination(setPacketDestination), packetStore(
|
||||
NULL), tcQueueId(MessageQueueSenderIF::NO_QUEUE) {
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0),
|
||||
bufferPosition(packetBuffer), packetDestination(setPacketDestination),
|
||||
packetStore(nullptr), tcQueueId(MessageQueueMessageIF::NO_QUEUE) {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef CONTROLLERSET_H_
|
||||
#define CONTROLLERSET_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
|
||||
class ControllerSet :public DataSet {
|
||||
class ControllerSet :public GlobDataSet {
|
||||
public:
|
||||
ControllerSet();
|
||||
virtual ~ControllerSet();
|
||||
|
@ -1,131 +0,0 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
|
||||
DataPool::DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) ) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if (initFunction != NULL ) {
|
||||
initFunction( &this->data_pool );
|
||||
}
|
||||
}
|
||||
|
||||
DataPool::~DataPool() {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
for ( std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.begin(); it != this->data_pool.end(); ++it ) {
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
//The function checks PID, type and array length before returning a copy of the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
||||
template <typename T> PoolEntry<T>* DataPool::getData( uint32_t data_pool_id, uint8_t sizeOrPosition ) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
if ( it != this->data_pool.end() ) {
|
||||
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
||||
if (entry != NULL ) {
|
||||
if ( sizeOrPosition <= entry->length ) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PoolEntryIF* DataPool::getRawData( uint32_t data_pool_id ) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
if ( it != this->data_pool.end() ) {
|
||||
return it->second;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//uint8_t DataPool::getRawData( uint32_t data_pool_id, uint8_t* address, uint16_t* size, uint32_t maxSize ) {
|
||||
// std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
// if ( it != this->data_pool.end() ) {
|
||||
// if ( it->second->getByteSize() <= maxSize ) {
|
||||
// *size = it->second->getByteSize();
|
||||
// memcpy( address, it->second->getRawData(), *size );
|
||||
// return DP_SUCCESSFUL;
|
||||
// }
|
||||
// }
|
||||
// *size = 0;
|
||||
// return DP_FAILURE;
|
||||
//}
|
||||
|
||||
ReturnValue_t DataPool::freeDataPoolLock() {
|
||||
ReturnValue_t status = mutex->unlockMutex();
|
||||
if ( status != RETURN_OK ) {
|
||||
sif::error << "DataPool::DataPool: unlock of mutex failed with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t DataPool::lockDataPool() {
|
||||
ReturnValue_t status = mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
if ( status != RETURN_OK ) {
|
||||
sif::error << "DataPool::DataPool: lock of mutex failed with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void DataPool::print() {
|
||||
sif::debug << "DataPool contains: " << std::endl;
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
||||
dataPoolIt = this->data_pool.begin();
|
||||
while( dataPoolIt != this->data_pool.end() ) {
|
||||
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
||||
dataPoolIt->second->print();
|
||||
dataPoolIt++;
|
||||
}
|
||||
}
|
||||
|
||||
template PoolEntry<uint8_t>* DataPool::getData<uint8_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint16_t>* DataPool::getData<uint16_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint32_t>* DataPool::getData<uint32_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint64_t>* DataPool::getData<uint64_t>(uint32_t data_pool_id,
|
||||
uint8_t size);
|
||||
template PoolEntry<int8_t>* DataPool::getData<int8_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int16_t>* DataPool::getData<int16_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int32_t>* DataPool::getData<int32_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<float>* DataPool::getData<float>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<double>* DataPool::getData<double>(uint32_t data_pool_id,
|
||||
uint8_t size);
|
||||
|
||||
|
||||
uint32_t DataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
||||
return (parameter_id >> 8) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
uint8_t DataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
||||
return (parameter_id & 0x000000FF);
|
||||
}
|
||||
|
||||
uint32_t DataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
||||
return (poolId << 8) + index;
|
||||
}
|
||||
|
||||
|
||||
//SHOULDDO: Do we need a mutex lock here... I don't think so, as we only check static const values of elements in a list that do not change.
|
||||
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
||||
ReturnValue_t DataPool::getType(uint32_t parameter_id, Type* type) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( PIDToDataPoolId(parameter_id));
|
||||
if ( it != this->data_pool.end() ) {
|
||||
*type = it->second->getType();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
*type = Type::UNKNOWN_TYPE;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
bool DataPool::exists(uint32_t parameterId) {
|
||||
uint32_t poolId = PIDToDataPoolId(parameterId);
|
||||
uint32_t index = PIDToArrayIndex(parameterId);
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( poolId );
|
||||
if (it != data_pool.end()) {
|
||||
if (it->second->getSize() >= index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
/**
|
||||
* \file DataPool.h
|
||||
*
|
||||
* \date 10/17/2012
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
* \brief This file contains the definition of the DataPool class and (temporarily)
|
||||
* the "extern" definition of the global dataPool instance.
|
||||
*/
|
||||
|
||||
#ifndef DATAPOOL_H_
|
||||
#define DATAPOOL_H_
|
||||
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* \defgroup data_pool Data Pool
|
||||
* This is the group, where all classes associated with Data Pool Handling belong to.
|
||||
* This includes classes to access Data Pool variables.
|
||||
*/
|
||||
|
||||
#define DP_SUCCESSFUL 0
|
||||
#define DP_FAILURE 1
|
||||
|
||||
/**
|
||||
* \brief This class represents the OBSW global data-pool.
|
||||
*
|
||||
* \details All variables are registered and space is allocated in an initialization
|
||||
* function, which is passed do the constructor.
|
||||
* Space for the variables is allocated on the heap (with a new call).
|
||||
* The data is found by a data pool id, which uniquely represents a variable.
|
||||
* Data pool variables should be used with a blackboard logic in mind,
|
||||
* which means read data is valid (if flagged so), but not necessarily up-to-date.
|
||||
* Variables are either single values or arrays.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class DataPool : public HasReturnvaluesIF {
|
||||
private:
|
||||
/**
|
||||
* \brief This is the actual data pool itself.
|
||||
* \details It is represented by a map
|
||||
* with the data pool id as index and a pointer to a single PoolEntry as value.
|
||||
*/
|
||||
std::map<uint32_t, PoolEntryIF*> data_pool;
|
||||
public:
|
||||
/**
|
||||
* \brief The mutex is created in the constructor and makes access mutual exclusive.
|
||||
* \details Locking and unlocking the pool is only done by the DataSet class.
|
||||
*/
|
||||
MutexIF* mutex;
|
||||
/**
|
||||
* \brief In the classes constructor, the passed initialization function is called.
|
||||
* \details To enable filling the pool,
|
||||
* a pointer to the map is passed, allowing direct access to the pool's content.
|
||||
* On runtime, adding or removing variables is forbidden.
|
||||
*/
|
||||
DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) );
|
||||
/**
|
||||
* \brief The destructor iterates through the data_pool map and calls all Entries destructors to clean up the heap.
|
||||
*/
|
||||
~DataPool();
|
||||
/**
|
||||
* \brief This is the default call to access the pool.
|
||||
* \details A pointer to the PoolEntry object is returned.
|
||||
* The call checks data pool id, type and array size. Returns NULL in case of failure.
|
||||
* \param data_pool_id The data pool id to search.
|
||||
* \param sizeOrPosition The array size (not byte size!) of the pool entry, or the position the user wants to read.
|
||||
* If smaller than the entry size, everything's ok.
|
||||
*/
|
||||
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id, uint8_t sizeOrPosition );
|
||||
/**
|
||||
* \brief An alternative call to get a data pool entry in case the type is not implicitly known
|
||||
* (i.e. in Housekeeping Telemetry).
|
||||
* \details It returns a basic interface and does NOT perform
|
||||
* a size check. The caller has to assure he does not copy too much data.
|
||||
* Returns NULL in case the entry is not found.
|
||||
* \param data_pool_id The data pool id to search.
|
||||
*/
|
||||
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
||||
* \details It fetches the pool's mutex id and tries to acquire the mutex.
|
||||
*/
|
||||
ReturnValue_t lockDataPool();
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* \details It fetches the pool's mutex id and tries to free the mutex.
|
||||
*/
|
||||
ReturnValue_t freeDataPoolLock();
|
||||
/**
|
||||
* \brief The print call is a simple debug method.
|
||||
* \details It prints the current content of the data pool.
|
||||
* It iterates through the data_pool map and calls each entry's print() method.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Extracts the data pool id from a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The data pool id as used within the OBSW.
|
||||
*/
|
||||
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
||||
/**
|
||||
* Extracts an array index out of a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The index of the corresponding data pool entry.
|
||||
*/
|
||||
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
||||
/**
|
||||
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
||||
*/
|
||||
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
||||
|
||||
/**
|
||||
* Method to return the type of a pool variable.
|
||||
* @param parameter_id A parameterID (not pool id) of a DP member.
|
||||
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
||||
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
||||
|
||||
/**
|
||||
* Method to check if a PID exists.
|
||||
* Does not lock, as there's no possibility to alter the list that is checked during run-time.
|
||||
* @param parameterId The PID (not pool id!) of a parameter.
|
||||
* @return true if exists, false else.
|
||||
*/
|
||||
bool exists(uint32_t parameterId);
|
||||
};
|
||||
|
||||
//We assume someone globally instantiates a DataPool.
|
||||
extern DataPool dataPool;
|
||||
#endif /* DATAPOOL_H_ */
|
@ -1,150 +0,0 @@
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
DataSet::DataSet() :
|
||||
fill_count(0), state(DATA_SET_UNINITIALISED) {
|
||||
for (unsigned count = 0; count < DATA_SET_MAX_SIZE; count++) {
|
||||
registeredVariables[count] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DataSet::~DataSet() {
|
||||
//Don't do anything with your variables, they are dead already! (Destructor is already called)
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::read() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if (state == DATA_SET_UNINITIALISED) {
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
ReturnValue_t status = registeredVariables[count]->read();
|
||||
if (status != RETURN_OK) {
|
||||
result = INVALID_PARAMETER_DEFINITION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = DATA_SET_WAS_READ;
|
||||
freeDataPoolLock();
|
||||
} else {
|
||||
sif::error << "DataSet::read(): Call made in wrong position." << std::endl;
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::commit(uint8_t valid) {
|
||||
setValid(valid);
|
||||
return commit();
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::commit() {
|
||||
if (state == DATA_SET_WAS_READ) {
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commit();
|
||||
}
|
||||
}
|
||||
state = DATA_SET_UNINITIALISED;
|
||||
freeDataPoolLock();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
== PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commit();
|
||||
} else if (registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
if (result != COMMITING_WITHOUT_READING) {
|
||||
sif::error <<
|
||||
"DataSet::commit(): commit-without-read "
|
||||
"call made with non write-only variable." << std::endl;
|
||||
result = COMMITING_WITHOUT_READING;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = DATA_SET_UNINITIALISED;
|
||||
freeDataPoolLock();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DataSet::registerVariable(PoolVariableIF* variable) {
|
||||
if (state == DATA_SET_UNINITIALISED) {
|
||||
if (variable != NULL) {
|
||||
if (fill_count < DATA_SET_MAX_SIZE) {
|
||||
registeredVariables[fill_count] = variable;
|
||||
fill_count++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sif::error
|
||||
<< "DataSet::registerVariable: failed. Either NULL, or set is full, or call made in wrong position."
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t DataSet::freeDataPoolLock() {
|
||||
return ::dataPool.freeDataPoolLock();
|
||||
}
|
||||
|
||||
uint8_t DataSet::lockDataPool() {
|
||||
return ::dataPool.lockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t DataSet::getSerializedSize() const {
|
||||
size_t size = 0;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void DataSet::setValid(uint8_t valid) {
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ) {
|
||||
registeredVariables[count]->setValid(valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
streamEndianness);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* \file DataSet.h
|
||||
*
|
||||
* \brief This file contains the DataSet class and a small structure called DataSetContent.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATASET_H_
|
||||
#define DATASET_H_
|
||||
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapool/PoolVarList.h>
|
||||
#include <framework/datapool/PoolVector.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
/**
|
||||
* \brief The DataSet class manages a set of locally checked out variables.
|
||||
*
|
||||
* \details This class manages a list, where a set of local variables (or pool variables) are
|
||||
* registered. They are checked-out (i.e. their values are looked up and copied)
|
||||
* with the read call. After the user finishes working with the pool variables,
|
||||
* he can write back all variable values to the pool with the commit call.
|
||||
* The data set manages locking and freeing the data pool, to ensure that all values
|
||||
* are read and written back at once.
|
||||
* An internal state manages usage of this class. Variables may only be registered before
|
||||
* the read call is made, and the commit call only after the read call.
|
||||
* If pool variables are writable and not committed until destruction of the set, the
|
||||
* DataSet class automatically sets the valid flag in the data pool to invalid (without)
|
||||
* changing the variable's value.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class DataSet: public DataSetIF, public HasReturnvaluesIF, public SerializeIF {
|
||||
private:
|
||||
//SHOULDDO we could use a linked list of datapool variables
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63; //!< This definition sets the maximum number of variables to register in one DataSet.
|
||||
|
||||
/**
|
||||
* \brief This array represents all pool variables registered in this set.
|
||||
* \details It has a maximum size of DATA_SET_MAX_SIZE.
|
||||
*/
|
||||
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
||||
/**
|
||||
* \brief The fill_count attribute ensures that the variables register in the correct array
|
||||
* position and that the maximum number of variables is not exceeded.
|
||||
*/
|
||||
uint16_t fill_count;
|
||||
/**
|
||||
* States of the seet.
|
||||
*/
|
||||
enum States {
|
||||
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||
};
|
||||
/**
|
||||
* \brief state manages the internal state of the data set, which is important e.g. for the
|
||||
* behavior on destruction.
|
||||
*/
|
||||
States state;
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
||||
* \details It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
uint8_t lockDataPool();
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* \details It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
uint8_t freeDataPoolLock();
|
||||
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
||||
static const ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
||||
MAKE_RETURN_CODE( 0x01 );
|
||||
static const ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
||||
static const ReturnValue_t COMMITING_WITHOUT_READING =
|
||||
MAKE_RETURN_CODE(0x03);
|
||||
|
||||
/**
|
||||
* \brief The constructor simply sets the fill_count to zero and sets the state to "uninitialized".
|
||||
*/
|
||||
DataSet();
|
||||
/**
|
||||
* \brief The destructor automatically manages writing the valid information of variables.
|
||||
* \details In case the data set was read out, but not committed (indicated by state),
|
||||
* the destructor parses all variables that are still registered to the set.
|
||||
* For each, the valid flag in the data pool is set to "invalid".
|
||||
*/
|
||||
~DataSet();
|
||||
/**
|
||||
* \brief The read call initializes reading out all registered variables.
|
||||
* \details It iterates through the list of registered variables and calls all read()
|
||||
* functions of the registered pool variables (which read out their values from the
|
||||
* data pool) which are not write-only. In case of an error (e.g. a wrong data type,
|
||||
* or an invalid data pool id), the operation is aborted and
|
||||
* \c INVALID_PARAMETER_DEFINITION returned.
|
||||
* The data pool is locked during the whole read operation and freed afterwards.
|
||||
* The state changes to "was written" after this operation.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
||||
* requested variable is invalid.
|
||||
* - \c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||
* commit() in between
|
||||
*/
|
||||
ReturnValue_t read();
|
||||
/**
|
||||
* \brief The commit call initializes writing back the registered variables.
|
||||
* \details It iterates through the list of registered variables and calls
|
||||
* the commit() method of the remaining registered variables (which write back
|
||||
* their values to the pool).
|
||||
* The data pool is locked during the whole commit operation and freed afterwards.
|
||||
* The state changes to "was committed" after this operation.
|
||||
* If the set does contain at least one variable which is not write-only commit()
|
||||
* can only be called after read(). If the set only contains variables which are
|
||||
* write only, commit() can be called without a preceding read() call.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
||||
* variables
|
||||
*/
|
||||
ReturnValue_t commit(void);
|
||||
/**
|
||||
* Variant of method above which sets validity of all elements of the set.
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
||||
* variables
|
||||
*/
|
||||
ReturnValue_t commit(uint8_t valid);
|
||||
/**
|
||||
* \brief This operation is used to register the local variables in the set.
|
||||
* \details It copies all required information to the currently
|
||||
* free space in the registeredVariables list.
|
||||
*/
|
||||
void registerVariable(PoolVariableIF* variable);
|
||||
|
||||
/**
|
||||
* Set the valid information of all variables contained in the set which are not readonly
|
||||
*
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
*/
|
||||
void setValid(uint8_t valid);
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
};
|
||||
|
||||
#endif /* DATASET_H_ */
|
168
datapool/DataSetBase.cpp
Normal file
168
datapool/DataSetBase.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
#include <framework/datapool/DataSetBase.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
DataSetBase::DataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount):
|
||||
registeredVariables(registeredVariablesArray),
|
||||
maxFillCount(maxFillCount) {
|
||||
for (uint8_t count = 0; count < maxFillCount; count++) {
|
||||
registeredVariables[count] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DataSetBase::~DataSetBase() {}
|
||||
|
||||
ReturnValue_t DataSetBase::registerVariable(
|
||||
PoolVariableIF *variable) {
|
||||
if (state != States::DATA_SET_UNINITIALISED) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"Call made in wrong position." << std::endl;
|
||||
return DataSetIF::DATA_SET_UNINITIALISED;
|
||||
}
|
||||
if (variable == nullptr) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"Pool variable is nullptr." << std::endl;
|
||||
return DataSetIF::POOL_VAR_NULL;
|
||||
}
|
||||
if (fillCount >= maxFillCount) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"DataSet is full." << std::endl;
|
||||
return DataSetIF::DATA_SET_FULL;
|
||||
}
|
||||
registeredVariables[fillCount] = variable;
|
||||
fillCount++;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if (state == States::DATA_SET_UNINITIALISED) {
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = readVariable(count);
|
||||
if(result != RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_WAS_READ;
|
||||
unlockDataPool();
|
||||
}
|
||||
else {
|
||||
sif::error << "DataSet::read(): "
|
||||
"Call made in wrong position. Don't forget to commit"
|
||||
" member datasets!" << std::endl;
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t DataSetBase::getFillCount() const {
|
||||
return fillCount;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::readVariable(uint16_t count) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
// These checks are often performed by the respective
|
||||
// variable implementation too, but I guess a double check does not hurt.
|
||||
if (registeredVariables[count]->getReadWriteMode() !=
|
||||
PoolVariableIF::VAR_WRITE and
|
||||
registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER)
|
||||
{
|
||||
result = registeredVariables[count]->readWithoutLock();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
result = INVALID_PARAMETER_DEFINITION;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::commit(uint32_t lockTimeout) {
|
||||
if (state == States::DATA_SET_WAS_READ) {
|
||||
handleAlreadyReadDatasetCommit(lockTimeout);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return handleUnreadDatasetCommit(lockTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void DataSetBase::handleAlreadyReadDatasetCommit(uint32_t lockTimeout) {
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commitWithoutLock();
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::handleUnreadDatasetCommit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
== PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commitWithoutLock();
|
||||
} else if (registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
if (result != COMMITING_WITHOUT_READING) {
|
||||
sif::error << "DataSet::commit(): commit-without-read call made "
|
||||
"with non write-only variable." << std::endl;
|
||||
result = COMMITING_WITHOUT_READING;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t DataSetBase::lockDataPool(uint32_t timeoutMs) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::unlockDataPool() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSetBase::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t DataSetBase::getSerializedSize() const {
|
||||
uint32_t size = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
149
datapool/DataSetBase.h
Normal file
149
datapool/DataSetBase.h
Normal file
@ -0,0 +1,149 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_DATASETBASE_H_
|
||||
#define FRAMEWORK_DATAPOOL_DATASETBASE_H_
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
|
||||
/**
|
||||
* @brief The DataSetBase class manages a set of locally checked out variables.
|
||||
* @details
|
||||
* This class manages a list, where a set of local variables (or pool variables)
|
||||
* are registered. They are checked-out (i.e. their values are looked
|
||||
* up and copied) with the read call. After the user finishes working with the
|
||||
* pool variables, he can write back all variable values to the pool with
|
||||
* the commit call. The data set manages locking and freeing the data pool,
|
||||
* to ensure that all values are read and written back at once.
|
||||
*
|
||||
* An internal state manages usage of this class. Variables may only be
|
||||
* registered before the read call is made, and the commit call only
|
||||
* after the read call.
|
||||
*
|
||||
* If pool variables are writable and not committed until destruction
|
||||
* of the set, the DataSet class automatically sets the valid flag in the
|
||||
* data pool to invalid (without) changing the variable's value.
|
||||
*
|
||||
* The base class lockDataPool und unlockDataPool implementation are empty
|
||||
* and should be implemented to protect the underlying pool type.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class DataSetBase: public DataSetIF,
|
||||
public SerializeIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Creates an empty dataset. Use registerVariable or
|
||||
* supply a pointer to this dataset to PoolVariable
|
||||
* initializations to register pool variables.
|
||||
*/
|
||||
DataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount);
|
||||
virtual~ DataSetBase();
|
||||
|
||||
/**
|
||||
* @brief The read call initializes reading out all registered variables.
|
||||
* @details
|
||||
* It iterates through the list of registered variables and calls all read()
|
||||
* functions of the registered pool variables (which read out their values
|
||||
* from the data pool) which are not write-only.
|
||||
* In case of an error (e.g. a wrong data type, or an invalid data pool id),
|
||||
* the operation is aborted and @c INVALID_PARAMETER_DEFINITION returned.
|
||||
*
|
||||
* The data pool is locked during the whole read operation and
|
||||
* freed afterwards.The state changes to "was written" after this operation.
|
||||
* @return
|
||||
* - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
||||
* requested variable is invalid.
|
||||
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||
* commit() in between
|
||||
*/
|
||||
virtual ReturnValue_t read(uint32_t lockTimeout =
|
||||
MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call initializes writing back the registered variables.
|
||||
* @details
|
||||
* It iterates through the list of registered variables and calls the
|
||||
* commit() method of the remaining registered variables (which write back
|
||||
* their values to the pool).
|
||||
*
|
||||
* The data pool is locked during the whole commit operation and
|
||||
* freed afterwards. The state changes to "was committed" after this operation.
|
||||
*
|
||||
* If the set does contain at least one variable which is not write-only
|
||||
* commit() can only be called after read(). If the set only contains
|
||||
* variables which are write only, commit() can be called without a
|
||||
* preceding read() call.
|
||||
* @return - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||
* contains non write-only variables
|
||||
*/
|
||||
virtual ReturnValue_t commit(uint32_t lockTimeout =
|
||||
MutexIF::BLOCKING) override;
|
||||
|
||||
/**
|
||||
* Register the passed pool variable instance into the data set.
|
||||
* @param variable
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t registerVariable( PoolVariableIF* variable) override;
|
||||
/**
|
||||
* Provides the means to lock the underlying data structure to ensure
|
||||
* thread-safety. Default implementation is empty
|
||||
* @return Always returns -@c RETURN_OK
|
||||
*/
|
||||
virtual ReturnValue_t lockDataPool(uint32_t timeoutMs =
|
||||
MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* Provides the means to unlock the underlying data structure to ensure
|
||||
* thread-safety. Default implementation is empty
|
||||
* @return Always returns -@c RETURN_OK
|
||||
*/
|
||||
virtual ReturnValue_t unlockDataPool() override;
|
||||
|
||||
virtual uint16_t getFillCount() const;
|
||||
|
||||
/* SerializeIF implementations */
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief The fill_count attribute ensures that the variables
|
||||
* register in the correct array position and that the maximum
|
||||
* number of variables is not exceeded.
|
||||
*/
|
||||
uint16_t fillCount = 0;
|
||||
/**
|
||||
* States of the seet.
|
||||
*/
|
||||
enum class States {
|
||||
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||
};
|
||||
/**
|
||||
* @brief state manages the internal state of the data set,
|
||||
* which is important e.g. for the behavior on destruction.
|
||||
*/
|
||||
States state = States::DATA_SET_UNINITIALISED;
|
||||
|
||||
/**
|
||||
* @brief This array represents all pool variables registered in this set.
|
||||
* Child classes can use a static or dynamic container to create
|
||||
* an array of registered variables and assign the first entry here.
|
||||
*/
|
||||
PoolVariableIF** registeredVariables = nullptr;
|
||||
const size_t maxFillCount = 0;
|
||||
|
||||
private:
|
||||
ReturnValue_t readVariable(uint16_t count);
|
||||
void handleAlreadyReadDatasetCommit(uint32_t lockTimeout);
|
||||
ReturnValue_t handleUnreadDatasetCommit(uint32_t lockTimeout);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_DATASETBASE_H_ */
|
@ -1,39 +1,62 @@
|
||||
/**
|
||||
* \file DataSetIF.h
|
||||
*
|
||||
* \brief This file contains the small interface to access the DataSet class.
|
||||
*
|
||||
* \date 10/23/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATASETIF_H_
|
||||
#define DATASETIF_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/timemanager/Clock.h>
|
||||
class PoolVariableIF;
|
||||
|
||||
/**
|
||||
* \brief This class defines a small interface to register on a DataSet.
|
||||
* @brief This class defines a small interface to register on a DataSet.
|
||||
*
|
||||
* \details Currently, the only purpose of this interface is to provide a method for locally
|
||||
* checked-out variables to register on a data set. Still, it may become useful for
|
||||
* other purposes as well.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
* @details
|
||||
* Currently, the only purpose of this interface is to provide a
|
||||
* method for locally checked-out variables to register on a data set.
|
||||
* Still, it may become useful for other purposes as well.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class DataSetIF {
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
||||
static constexpr ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
||||
MAKE_RETURN_CODE( 0x01 );
|
||||
static constexpr ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
||||
static constexpr ReturnValue_t COMMITING_WITHOUT_READING =
|
||||
MAKE_RETURN_CODE(0x03);
|
||||
|
||||
static constexpr ReturnValue_t DATA_SET_UNINITIALISED = MAKE_RETURN_CODE( 0x04 );
|
||||
static constexpr ReturnValue_t DATA_SET_FULL = MAKE_RETURN_CODE( 0x05 );
|
||||
static constexpr ReturnValue_t POOL_VAR_NULL = MAKE_RETURN_CODE( 0x06 );
|
||||
|
||||
/**
|
||||
* \brief This is an empty virtual destructor, as it is proposed for C++ interfaces.
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is proposed for C++ interfaces.
|
||||
*/
|
||||
virtual ~DataSetIF() {}
|
||||
|
||||
virtual ReturnValue_t read(uint32_t lockTimeout) = 0;
|
||||
virtual ReturnValue_t commit(uint32_t lockTimeout) = 0;
|
||||
/**
|
||||
* \brief This operation provides a method to register local data pool variables
|
||||
* to register in a data set by passing itself to this DataSet operation.
|
||||
* @brief This operation provides a method to register local data pool
|
||||
* variables to register in a data set by passing itself
|
||||
* to this DataSet operation.
|
||||
*/
|
||||
virtual void registerVariable( PoolVariableIF* variable ) = 0;
|
||||
virtual ReturnValue_t registerVariable(PoolVariableIF* variable) = 0;
|
||||
|
||||
virtual uint16_t getFillCount() const = 0;
|
||||
private:
|
||||
/**
|
||||
* @brief Most underlying data structures will have a pool like structure
|
||||
* and will require a lock and unlock mechanism to ensure
|
||||
* thread-safety
|
||||
* @return Lock operation result
|
||||
*/
|
||||
virtual ReturnValue_t lockDataPool(uint32_t timeoutMs) = 0;
|
||||
/**
|
||||
* @brief Unlock call corresponding to the lock call.
|
||||
* @return Unlock operation result
|
||||
*/
|
||||
virtual ReturnValue_t unlockDataPool() = 0;
|
||||
};
|
||||
|
||||
#endif /* DATASETIF_H_ */
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <framework/datapool/HkSwitchHelper.h>
|
||||
//#include <mission/tmtcservices/HKService_03.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
||||
@ -22,14 +21,14 @@ ReturnValue_t HkSwitchHelper::initialize() {
|
||||
}
|
||||
|
||||
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
|
||||
CommandMessage message;
|
||||
while (actionQueue->receiveMessage(&message) == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = commandActionHelper.handleReply(&message);
|
||||
CommandMessage command;
|
||||
while (actionQueue->receiveMessage(&command) == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = commandActionHelper.handleReply(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
message.setToUnknownCommand();
|
||||
actionQueue->reply(&message);
|
||||
command.setToUnknownCommand();
|
||||
actionQueue->reply(&command);
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
@ -1,187 +0,0 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/serialize/EndianConverter.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(
|
||||
Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0), readWriteMode(
|
||||
setReadWriteMode) {
|
||||
memset(value, 0, sizeof(value));
|
||||
if (data_set != NULL) {
|
||||
data_set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
PoolRawAccess::~PoolRawAccess() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::read() {
|
||||
PoolEntryIF *read_out = ::dataPool.getRawData(dataPoolId);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->getValid();
|
||||
if (read_out->getSize() > arrayEntry) {
|
||||
arraySize = read_out->getSize();
|
||||
typeSize = read_out->getByteSize() / read_out->getSize();
|
||||
type = read_out->getType();
|
||||
if (typeSize <= sizeof(value)) {
|
||||
uint16_t arrayPosition = arrayEntry * typeSize;
|
||||
sizeTillEnd = read_out->getByteSize() - arrayPosition;
|
||||
uint8_t *ptr =
|
||||
&((uint8_t*) read_out->getRawData())[arrayPosition];
|
||||
memcpy(value, ptr, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
//Error value type too large.
|
||||
}
|
||||
} else {
|
||||
//Error index requested too large
|
||||
}
|
||||
} else {
|
||||
//Error entry does not exist.
|
||||
}
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
memset(value, 0, sizeof(value));
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commit() {
|
||||
PoolEntryIF *write_back = ::dataPool.getRawData(dataPoolId);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->setValid(valid);
|
||||
uint8_t array_position = arrayEntry * typeSize;
|
||||
uint8_t *ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
||||
memcpy(ptr, value, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* PoolRawAccess::getEntry() {
|
||||
return value;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t *buffer,
|
||||
size_t *writtenBytes, size_t maxSize) {
|
||||
uint8_t *data_ptr = getEntry();
|
||||
// debug << "PoolRawAccess::getEntry: Array position: " << index * size_of_type << " Size of T: " << (int)size_of_type << " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||
if (typeSize == 0) {
|
||||
return DATA_POOL_ACCESS_FAILED;
|
||||
}
|
||||
if (typeSize > maxSize) {
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||
*writtenBytes = typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeOfType() {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getArraySize() {
|
||||
return arraySize;
|
||||
}
|
||||
|
||||
uint32_t PoolRawAccess::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize) {
|
||||
if (typeSize == setSize) {
|
||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal"
|
||||
<< (uint32_t) typeSize << ", Requested: " << setSize
|
||||
<< std::endl;
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
bool PoolRawAccess::isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void PoolRawAccess::setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
if (typeSize + *size <= maxSize) {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(*buffer, value, typeSize);
|
||||
break;
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSerializedSize() const {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) {
|
||||
|
||||
if (*size >= typeSize) {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(value, *buffer, typeSize);
|
||||
break;
|
||||
}
|
||||
*size -= typeSize;
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
#ifndef POOLRAWACCESS_H_
|
||||
#define POOLRAWACCESS_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
|
||||
/**
|
||||
* This class allows accessing Data Pool variables as raw bytes.
|
||||
* This is necessary to have an access method for HK data, as the PID's alone do not
|
||||
* provide a type information.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccess: public PoolVariableIF {
|
||||
private:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The array entry that is fetched from the data pool.
|
||||
*/
|
||||
uint8_t arrayEntry;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief This value contains the type of the data pool entry.
|
||||
*/
|
||||
Type type;
|
||||
/**
|
||||
* \brief This value contains the size of the data pool entry in bytes.
|
||||
*/
|
||||
size_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
size_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
size_t sizeTillEnd;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
||||
protected:
|
||||
/**
|
||||
* \brief This is a call to read the value from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read();
|
||||
/**
|
||||
* \brief The commit call writes back the variable's value to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit();
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
||||
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
||||
uint8_t value[RAW_MAX_SIZE];
|
||||
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode =
|
||||
PoolVariableIF::VAR_READ);
|
||||
/**
|
||||
* \brief The classes destructor is empty. If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolRawAccess();
|
||||
/**
|
||||
* \brief This operation returns a pointer to the entry fetched.
|
||||
* \details This means, it does not return a pointer to byte "index", but to the start byte of
|
||||
* array entry "index". Example: If the original data pool array consists of an double
|
||||
* array of size four, getEntry(1) returns &(this->value[8]).
|
||||
*/
|
||||
uint8_t* getEntry();
|
||||
/**
|
||||
* \brief This operation returns the fetched entry from the data pool and
|
||||
* flips the bytes, if necessary.
|
||||
* \details It makes use of the getEntry call of this function, but additionally flips the
|
||||
* bytes to big endian, which is the default for external communication (as House-
|
||||
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
||||
* buffer, if it fits in the given maxSize.
|
||||
* \param buffer A pointer to a buffer to write to
|
||||
* \param writtenBytes The number of bytes written is returned with this value.
|
||||
* \param maxSize The maximum size that the function may write to buffer.
|
||||
* \return - \c RETURN_OK if entry could be acquired
|
||||
* - \c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||
size_t maxSize);
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
* @param size Size of the data to write. Must fit this->size.
|
||||
* @return - \c RETURN_OK on success
|
||||
* - \c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize);
|
||||
/**
|
||||
* \brief This operation returns the type of the entry currently stored.
|
||||
*/
|
||||
Type getType();
|
||||
/**
|
||||
* \brief This operation returns the size of the entry currently stored.
|
||||
*/
|
||||
size_t getSizeOfType();
|
||||
/**
|
||||
*
|
||||
* @return the size of the datapool array
|
||||
*/
|
||||
size_t getArraySize();
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const;
|
||||
/**
|
||||
* This method returns if the variable is read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
void setValid(uint8_t valid);
|
||||
/**
|
||||
* Getter for the remaining size.
|
||||
*/
|
||||
size_t getSizeTillEnd() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override;
|
||||
};
|
||||
|
||||
#endif /* POOLRAWACCESS_H_ */
|
188
datapool/PoolRawAccessHelper.cpp
Normal file
188
datapool/PoolRawAccessHelper.cpp
Normal file
@ -0,0 +1,188 @@
|
||||
/**
|
||||
* @file PoolRawAccessHelper.cpp
|
||||
*
|
||||
* @date 22.12.2019
|
||||
* @author R. Mueller
|
||||
*/
|
||||
|
||||
#include <framework/datapool/PoolRawAccessHelper.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_,
|
||||
uint8_t numberOfParameters_):
|
||||
poolIdBuffer(reinterpret_cast<uint8_t * >(poolIdBuffer_)),
|
||||
numberOfParameters(numberOfParameters_), validBufferIndex(0),
|
||||
validBufferIndexBit(1) {
|
||||
}
|
||||
|
||||
PoolRawAccessHelper::~PoolRawAccessHelper() {
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, size_t *size,
|
||||
const size_t max_size, SerializeIF::Endianness streamEndianness) {
|
||||
SerializationArgs serializationArgs = {buffer, size, max_size,
|
||||
streamEndianness};
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
size_t remainingParametersSize = numberOfParameters * 4;
|
||||
for(uint8_t count=0; count < numberOfParameters; count++) {
|
||||
result = serializeCurrentPoolEntryIntoBuffer(serializationArgs,
|
||||
&remainingParametersSize, false);
|
||||
if(result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if(remainingParametersSize != 0) {
|
||||
sif::debug << "PoolRawAccessHelper: "
|
||||
"Remaining parameters size not 0 !" << std::endl;
|
||||
result = RETURN_FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer,
|
||||
size_t * size, const size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
SerializationArgs argStruct = {buffer, size, max_size, streamEndianness};
|
||||
size_t remainingParametersSize = numberOfParameters * 4;
|
||||
uint8_t validityMaskSize = ceil((float)numberOfParameters/8.0);
|
||||
uint8_t validityMask[validityMaskSize];
|
||||
memset(validityMask,0, validityMaskSize);
|
||||
for(uint8_t count = 0; count < numberOfParameters; count++) {
|
||||
result = serializeCurrentPoolEntryIntoBuffer(argStruct,
|
||||
&remainingParametersSize,true,validityMask);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if(remainingParametersSize != 0) {
|
||||
sif::debug << "PoolRawAccessHelper: Remaining "
|
||||
"parameters size not 0 !" << std::endl;
|
||||
result = RETURN_FAILED;
|
||||
}
|
||||
|
||||
memcpy(*argStruct.buffer, validityMask, validityMaskSize);
|
||||
*size += validityMaskSize;
|
||||
validBufferIndex = 1;
|
||||
validBufferIndexBit = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(
|
||||
SerializationArgs argStruct, size_t * remainingParameters,
|
||||
bool withValidMask, uint8_t * validityMask) {
|
||||
uint32_t currentPoolId;
|
||||
// Deserialize current pool ID from pool ID buffer
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(¤tPoolId,
|
||||
&poolIdBuffer,remainingParameters, SerializeIF::Endianness::MACHINE);
|
||||
if(result != RETURN_OK) {
|
||||
sif::debug << std::hex << "PoolRawAccessHelper: Error deSeralizing "
|
||||
"pool IDs" << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
result = handlePoolEntrySerialization(currentPoolId, argStruct,
|
||||
withValidMask, validityMask);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(
|
||||
uint32_t currentPoolId,SerializationArgs argStruct, bool withValidMask,
|
||||
uint8_t * validityMask) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
uint8_t arrayPosition = 0;
|
||||
uint8_t counter = 0;
|
||||
bool poolEntrySerialized = false;
|
||||
//debug << "Pool Raw Access Helper: Handling Pool ID: "
|
||||
// << std::hex << currentPoolId << std::endl;
|
||||
while(not poolEntrySerialized) {
|
||||
|
||||
if(counter > GlobDataSet::DATA_SET_MAX_SIZE) {
|
||||
sif::error << "PoolRawAccessHelper: Config error, "
|
||||
"max. number of possible data set variables exceeded"
|
||||
<< std::endl;
|
||||
return result;
|
||||
}
|
||||
counter ++;
|
||||
|
||||
GlobDataSet currentDataSet;
|
||||
//debug << "Current array position: " << (int)arrayPosition << std::endl;
|
||||
PoolRawAccess currentPoolRawAccess(currentPoolId, arrayPosition,
|
||||
¤tDataSet, PoolVariableIF::VAR_READ);
|
||||
|
||||
result = currentDataSet.read();
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << std::hex << "PoolRawAccessHelper: Error reading raw "
|
||||
"dataset with returncode 0x" << result << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = checkRemainingSize(¤tPoolRawAccess, &poolEntrySerialized,
|
||||
&arrayPosition);
|
||||
if(result != RETURN_OK) {
|
||||
sif::error << "Pool Raw Access Helper: Configuration Error at pool ID "
|
||||
<< std::hex << currentPoolId
|
||||
<< ". Size till end smaller than 0" << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
// set valid mask bit if necessary
|
||||
if(withValidMask) {
|
||||
if(currentPoolRawAccess.isValid()) {
|
||||
handleMaskModification(validityMask);
|
||||
}
|
||||
validBufferIndexBit ++;
|
||||
}
|
||||
|
||||
result = currentDataSet.serialize(argStruct.buffer, argStruct.size,
|
||||
argStruct.max_size, argStruct.streamEndianness);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "Pool Raw Access Helper: Error serializing pool data with "
|
||||
"ID 0x" << std::hex << currentPoolId << " into send buffer "
|
||||
"with return code " << result << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess*
|
||||
currentPoolRawAccess, bool * isSerialized, uint8_t * arrayPosition) {
|
||||
int8_t remainingSize = currentPoolRawAccess->getSizeTillEnd() -
|
||||
currentPoolRawAccess->getSizeOfType();
|
||||
if(remainingSize == 0) {
|
||||
*isSerialized = true;
|
||||
}
|
||||
else if(remainingSize > 0) {
|
||||
*arrayPosition += 1;
|
||||
}
|
||||
else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) {
|
||||
validityMask[validBufferIndex] =
|
||||
bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true);
|
||||
if(validBufferIndexBit == 8) {
|
||||
validBufferIndex ++;
|
||||
validBufferIndexBit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position,
|
||||
bool value) {
|
||||
if(position < 1 or position > 8) {
|
||||
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
|
||||
return byte;
|
||||
}
|
||||
uint8_t shiftNumber = position + (6 - 2 * (position - 1));
|
||||
byte |= 1UL << shiftNumber;
|
||||
return byte;
|
||||
}
|
111
datapool/PoolRawAccessHelper.h
Normal file
111
datapool/PoolRawAccessHelper.h
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @file PoolRawAccessHelper.h
|
||||
*
|
||||
* @date 22.12.2019
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_
|
||||
#define FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/PoolRawAccess.h>
|
||||
|
||||
/**
|
||||
* @brief This helper function simplifies accessing data pool entries
|
||||
* via PoolRawAccess
|
||||
* @details Can be used for a Housekeeping Service
|
||||
* like ECSS PUS Service 3 if the type of the datapool entries is unknown.
|
||||
* The provided dataset can be serialized into a provided buffer automatically by
|
||||
* providing a buffer of pool IDs
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccessHelper: public HasReturnvaluesIF {
|
||||
public:
|
||||
/**
|
||||
* Call this constructor if a dataset needs to be serialized via
|
||||
* Pool Raw Access
|
||||
* @param dataSet_ This dataset will be used to perform thread-safe reading
|
||||
* @param poolIdBuffer_ A buffer of uint32_t pool IDs
|
||||
* @param numberOfParameters_ The number of parameters / pool IDs
|
||||
*/
|
||||
PoolRawAccessHelper(uint32_t * poolIdBuffer_, uint8_t numberOfParameters_);
|
||||
virtual ~PoolRawAccessHelper();
|
||||
|
||||
/**
|
||||
* Serialize the datapool entries derived from the pool ID buffer
|
||||
* directly into a provided buffer
|
||||
* @param [out] buffer
|
||||
* @param [out] size Size of the serialized buffer
|
||||
* @param max_size
|
||||
* @param bigEndian
|
||||
* @return @c RETURN_OK On success
|
||||
* @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t serialize(uint8_t ** buffer, size_t * size,
|
||||
const size_t max_size, SerializeIF::Endianness streamEndianness);
|
||||
|
||||
/**
|
||||
* Serializes data pool entries into provided buffer with the validity mask buffer
|
||||
* at the end of the buffer. Every bit of the validity mask denotes
|
||||
* the validity of a corresponding data pool entry from left to right.
|
||||
* @param [out] buffer
|
||||
* @param [out] size Size of the serialized buffer plus size
|
||||
* of the validity mask
|
||||
* @return @c RETURN_OK On success
|
||||
* @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t serializeWithValidityMask(uint8_t ** buffer, size_t * size,
|
||||
const size_t max_size, SerializeIF::Endianness streamEndianness);
|
||||
|
||||
|
||||
private:
|
||||
// DataSet * dataSet;
|
||||
const uint8_t * poolIdBuffer;
|
||||
uint8_t numberOfParameters;
|
||||
|
||||
uint8_t validBufferIndex;
|
||||
uint8_t validBufferIndexBit;
|
||||
|
||||
struct SerializationArgs {
|
||||
uint8_t ** buffer;
|
||||
size_t * size;
|
||||
const size_t max_size;
|
||||
SerializeIF::Endianness streamEndianness;
|
||||
};
|
||||
/**
|
||||
* Helper function to serialize single pool entries
|
||||
* @param pPoolIdBuffer
|
||||
* @param buffer
|
||||
* @param remainingParameters
|
||||
* @param hkDataSize
|
||||
* @param max_size
|
||||
* @param bigEndian
|
||||
* @param withValidMask Can be set optionally to set a
|
||||
* provided validity mask
|
||||
* @param validityMask Can be supplied and will be set if
|
||||
* @c withValidMask is set to true
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(
|
||||
SerializationArgs argStruct, size_t * remainingParameters,
|
||||
bool withValidMask = false, uint8_t * validityMask = nullptr);
|
||||
|
||||
ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,
|
||||
SerializationArgs argStruct, bool withValidMask = false,
|
||||
uint8_t * validityMask = nullptr);
|
||||
|
||||
ReturnValue_t checkRemainingSize(PoolRawAccess * currentPoolRawAccess,
|
||||
bool * isSerialized, uint8_t * arrayPosition);
|
||||
void handleMaskModification(uint8_t * validityMask);
|
||||
/**
|
||||
* Sets specific bit of a byte
|
||||
* @param byte
|
||||
* @param position Position of byte to set from 1 to 8
|
||||
* @param value Binary value to set
|
||||
* @return
|
||||
*/
|
||||
uint8_t bitSetter(uint8_t byte, uint8_t position, bool value);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_ */
|
@ -1,12 +1,12 @@
|
||||
#ifndef POOLVARLIST_H_
|
||||
#define POOLVARLIST_H_
|
||||
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapoolglob/GlobalPoolVariable.h>
|
||||
template <class T, uint8_t n_var>
|
||||
class PoolVarList {
|
||||
private:
|
||||
PoolVariable<T> variables[n_var];
|
||||
GlobPoolVar<T> variables[n_var];
|
||||
public:
|
||||
PoolVarList( const uint32_t set_id[n_var], DataSetIF* dataSet, PoolVariableIF::ReadWriteMode_t setReadWriteMode ) {
|
||||
//I really should have a look at the new init list c++ syntax.
|
||||
@ -20,7 +20,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
PoolVariable<T> &operator [](int i) { return variables[i]; }
|
||||
GlobPoolVar<T> &operator [](int i) { return variables[i]; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,295 +0,0 @@
|
||||
/*
|
||||
* \file PoolVariable.h
|
||||
*
|
||||
* \brief This file contains the PoolVariable class, which locally represents a non-array data pool variable.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVARIABLE_H_
|
||||
#define POOLVARIABLE_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
template<typename T, uint8_t n_var> class PoolVarList;
|
||||
|
||||
/**
|
||||
* \brief This is the access class for non-array data pool entries.
|
||||
*
|
||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
||||
* entries, but on local copies. This class provides simple type-safe access to single
|
||||
* data pool entries (i.e. entries with length = 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that the variable's value in
|
||||
* the data pool is not changed until the commit call is executed.
|
||||
* \tparam T The template parameter sets the type of the variable. Currently, all plain data types
|
||||
* are supported, but in principle any type is possible.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class PoolVariable: public PoolVariableIF {
|
||||
template<typename U, uint8_t n_var> friend class PoolVarList;
|
||||
protected:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
/**
|
||||
* \brief This is a call to read the value from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read() {
|
||||
PoolEntry<T> *read_out = ::dataPool.getData < T > (dataPoolId, 1);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = *(read_out->address);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
value = 0;
|
||||
valid = false;
|
||||
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief The commit call writes back the variable's value to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
PoolEntry<T> *write_back = ::dataPool.getData < T > (dataPoolId, 1);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
*(write_back->address) = value;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
PoolVariable() :
|
||||
dataPoolId(PoolVariableIF::NO_PARAMETER), valid(
|
||||
PoolVariableIF::INVALID), readWriteMode(VAR_READ), value(0) {
|
||||
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* \brief This is the local copy of the data pool entry.
|
||||
* \details The user can work on this attribute
|
||||
* just like he would on a simple local variable.
|
||||
*/
|
||||
T value;
|
||||
/**
|
||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
||||
* passed).
|
||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
||||
* attribute to default (0). The value is fetched within the read() operation.
|
||||
* \param set_id This is the id in the global data pool this instance of the access class
|
||||
* corresponds to.
|
||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
||||
* the variable is not registered.
|
||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
PoolVariable(uint32_t set_id, DataSetIF *dataSet,
|
||||
ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(PoolVariableIF::INVALID), readWriteMode(
|
||||
setReadWriteMode), value(0) {
|
||||
if (dataSet != NULL) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
PoolVariable(const PoolVariable &rhs) :
|
||||
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
||||
rhs.readWriteMode), value(rhs.value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The classes destructor is empty.
|
||||
* \details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolVariable() {
|
||||
|
||||
}
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
operator T() {
|
||||
return value;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
PoolVariable<T>& operator=(T newValue) {
|
||||
value = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PoolVariable<T>& operator=(PoolVariable<T> newPoolVariable) {
|
||||
value = newPoolVariable.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize<T>(&value, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
return SerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
typedef PoolVariable<uint8_t> db_uint8_t;
|
||||
typedef PoolVariable<uint16_t> db_uint16_t;
|
||||
typedef PoolVariable<uint32_t> db_uint32_t;
|
||||
typedef PoolVariable<int8_t> db_int8_t;
|
||||
typedef PoolVariable<int16_t> db_int16_t;
|
||||
typedef PoolVariable<int32_t> db_int32_t;
|
||||
typedef PoolVariable<uint8_t> db_bool_t;
|
||||
typedef PoolVariable<float> db_float_t;
|
||||
typedef PoolVariable<double> db_double_t;
|
||||
//Alternative (but I thing this is not as useful: code duplication, differences too small):
|
||||
|
||||
//template <typename T>
|
||||
//class PoolReader : public PoolVariableIF {
|
||||
//private:
|
||||
// uint32_t parameter_id;
|
||||
// uint8_t valid;
|
||||
//public:
|
||||
// T value;
|
||||
// PoolReader( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), valid(false), value(0) {
|
||||
// set->registerVariable( this );
|
||||
// }
|
||||
//
|
||||
// ~PoolReader() {};
|
||||
//
|
||||
// uint8_t commit() {
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// }
|
||||
//
|
||||
// uint8_t read() {
|
||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( read_out != NULL ) {
|
||||
// valid = read_out->valid;
|
||||
// value = *(read_out->address);
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// value = 0;
|
||||
// valid = false;
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint32_t getParameterId() { return parameter_id; }
|
||||
// bool isWritable() { return false; };
|
||||
// bool isValid() { if (valid) return true; else return false; }
|
||||
//};
|
||||
//
|
||||
//template <typename T>
|
||||
//class PoolWriter : public PoolVariableIF {
|
||||
//private:
|
||||
// uint32_t parameter_id;
|
||||
//public:
|
||||
// T value;
|
||||
// PoolWriter( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), value(0) {
|
||||
// set->registerVariable( this );
|
||||
// }
|
||||
//
|
||||
// ~PoolWriter() {};
|
||||
//
|
||||
// uint8_t commit() {
|
||||
// PoolEntry<T>* write_back = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( write_back != NULL ) {
|
||||
// write_back->valid = true;
|
||||
// *(write_back->address) = value;
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint8_t read() {
|
||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( read_out != NULL ) {
|
||||
// value = *(read_out->address);
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// value = 0;
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint32_t getParameterId() { return parameter_id; }
|
||||
// bool isWritable() { return true; };
|
||||
// bool isValid() { return false; }
|
||||
//};
|
||||
|
||||
#endif /* POOLVARIABLE_H_ */
|
@ -1,71 +1,99 @@
|
||||
/*
|
||||
* \file PoolVariableIF.h
|
||||
*
|
||||
* \brief This file contains the interface definition for pool variables.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVARIABLEIF_H_
|
||||
#define POOLVARIABLEIF_H_
|
||||
#ifndef FRAMEWORK_DATAPOOL_POOLVARIABLEIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_POOLVARIABLEIF_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
/**
|
||||
* \brief This interface is used to control local data pool variable representations.
|
||||
*
|
||||
* \details To securely handle data pool variables, all pool entries are locally managed by
|
||||
* data pool variable access classes, which are called pool variables. To ensure a
|
||||
* common state of a set of variables needed in a function, these local pool variables
|
||||
* again are managed by other classes, e.g. the DataSet. This interface provides unified
|
||||
* access to local pool variables for such manager classes.
|
||||
* \ingroup data_pool
|
||||
* @brief This interface is used to control data pool
|
||||
* variable representations.
|
||||
* @details
|
||||
* To securely handle data pool variables, all pool entries are locally
|
||||
* managed by data pool variable access classes, which are called pool
|
||||
* variables. To ensure a common state of a set of variables needed in a
|
||||
* function, these local pool variables again are managed by other classes,
|
||||
* like the DataSet classes. This interface provides unified access to
|
||||
* local pool variables for such manager classes.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolVariableIF : public SerializeIF {
|
||||
friend class DataSet;
|
||||
protected:
|
||||
/**
|
||||
* \brief The commit call shall write back a newly calculated local value to the data pool.
|
||||
*/
|
||||
virtual ReturnValue_t commit() = 0;
|
||||
/**
|
||||
* \brief The read call shall read the value of this parameter from the data pool and store
|
||||
* the content locally.
|
||||
*/
|
||||
virtual ReturnValue_t read() = 0;
|
||||
friend class DataSetBase;
|
||||
friend class GlobDataSet;
|
||||
friend class LocalDataSet;
|
||||
public:
|
||||
static const uint8_t VALID = 1;
|
||||
static const uint8_t INVALID = 0;
|
||||
static const uint32_t NO_PARAMETER = 0;
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF;
|
||||
static constexpr ReturnValue_t INVALID_READ_WRITE_MODE = MAKE_RETURN_CODE(0xA0);
|
||||
|
||||
static constexpr bool VALID = 1;
|
||||
static constexpr bool INVALID = 0;
|
||||
static constexpr uint32_t NO_PARAMETER = 0xffffffff;
|
||||
|
||||
enum ReadWriteMode_t {
|
||||
VAR_READ, VAR_WRITE, VAR_READ_WRITE
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief This is an empty virtual destructor, as it is proposed for C++ interfaces.
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is proposed for C++ interfaces.
|
||||
*/
|
||||
virtual ~PoolVariableIF() {
|
||||
}
|
||||
virtual ~PoolVariableIF() {}
|
||||
/**
|
||||
* \brief This method returns if the variable is write-only, read-write or read-only.
|
||||
* @brief This method returns if the variable is write-only,
|
||||
* read-write or read-only.
|
||||
*/
|
||||
virtual ReadWriteMode_t getReadWriteMode() const = 0;
|
||||
/**
|
||||
* \brief This operation shall return the data pool id of the variable.
|
||||
* @brief This operation shall return the data pool id of the variable.
|
||||
*/
|
||||
virtual uint32_t getDataPoolId() const = 0;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
* @brief With this call, the valid information of the
|
||||
* variable is returned.
|
||||
*/
|
||||
virtual bool isValid() const = 0;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is set.
|
||||
* @brief With this call, the valid information of the variable is set.
|
||||
*/
|
||||
virtual void setValid(uint8_t validity) = 0;
|
||||
virtual void setValid(bool validity) = 0;
|
||||
|
||||
/**
|
||||
* @brief The commit call shall write back a newly calculated local
|
||||
* value to the data pool.
|
||||
* @details
|
||||
* It is assumed that these calls are implemented in a thread-safe manner!
|
||||
*/
|
||||
virtual ReturnValue_t commit(uint32_t lockTimeout) = 0;
|
||||
/**
|
||||
* @brief The read call shall read the value of this parameter from
|
||||
* the data pool and store the content locally.
|
||||
* @details
|
||||
* It is assumbed that these calls are implemented in a thread-safe manner!
|
||||
*/
|
||||
virtual ReturnValue_t read(uint32_t lockTimeout) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Same as commit with the difference that comitting will be
|
||||
* performed without a lock
|
||||
* @return
|
||||
* This can be used if the lock protection is handled externally
|
||||
* to avoid the overhead of locking and unlocking consecutively.
|
||||
* Declared protected to avoid free public usage.
|
||||
*/
|
||||
virtual ReturnValue_t readWithoutLock() = 0;
|
||||
/**
|
||||
* @brief Same as commit with the difference that comitting will be
|
||||
* performed without a lock
|
||||
* @return
|
||||
* This can be used if the lock protection is handled externally
|
||||
* to avoid the overhead of locking and unlocking consecutively.
|
||||
* Declared protected to avoid free public usage.
|
||||
*/
|
||||
virtual ReturnValue_t commitWithoutLock() = 0;
|
||||
};
|
||||
|
||||
using pool_rwm_t = PoolVariableIF::ReadWriteMode_t;
|
||||
|
||||
#endif /* POOLVARIABLEIF_H_ */
|
||||
|
@ -1,233 +0,0 @@
|
||||
/*
|
||||
* \file PoolVector.h
|
||||
*
|
||||
* \brief This file contains the PoolVector class, the header only class to handle data pool vectors.
|
||||
*
|
||||
* \date 10/23/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVECTOR_H_
|
||||
#define POOLVECTOR_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
/**
|
||||
* \brief This is the access class for array-type data pool entries.
|
||||
*
|
||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
||||
* entries, but on local copies. This class provides simple type- and length-safe access
|
||||
* to vector-style data pool entries (i.e. entries with length > 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that no array entry in
|
||||
* the data pool is changed until the commit call is executed.
|
||||
* There are two template parameters:
|
||||
* \tparam T This template parameter specifies the data type of an array entry. Currently, all
|
||||
* plain data types are supported, but in principle any type is possible.
|
||||
* \tparam vector_size This template parameter specifies the vector size of this entry.
|
||||
* Using a template parameter for this is not perfect, but avoids dynamic memory allocation.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
template<typename T, uint16_t vector_size>
|
||||
class PoolVector: public PoolVariableIF {
|
||||
private:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief This is a call to read the array's values from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies all array values and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type, size or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read() {
|
||||
PoolEntry<T>* read_out = ::dataPool.getData<T>(this->dataPoolId,
|
||||
vector_size);
|
||||
if (read_out != NULL) {
|
||||
this->valid = read_out->valid;
|
||||
memcpy(this->value, read_out->address, read_out->getByteSize());
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
} else {
|
||||
memset(this->value, 0, vector_size * sizeof(T));
|
||||
sif::error << "PoolVector: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
this->valid = INVALID;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief The commit call copies the array values back to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
PoolEntry<T>* write_back = ::dataPool.getData<T>(this->dataPoolId,
|
||||
vector_size);
|
||||
if ((write_back != NULL) && (this->readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
memcpy(write_back->address, this->value, write_back->getByteSize());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* \brief This is the local copy of the data pool entry.
|
||||
* \detials The user can work on this attribute
|
||||
* just like he would on a local array of this type.
|
||||
*/
|
||||
T value[vector_size];
|
||||
/**
|
||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
||||
* passed).
|
||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
||||
* attribute to default (0). The value is fetched within the read() operation.
|
||||
* \param set_id This is the id in the global data pool this instance of the access class
|
||||
* corresponds to.
|
||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
||||
* the variable is not registered.
|
||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
PoolVector(uint32_t set_id, DataSetIF* set,
|
||||
ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
||||
memset(this->value, 0, vector_size * sizeof(T));
|
||||
if (set != NULL) {
|
||||
set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
// PoolVector(const PoolVector& rhs) {
|
||||
// PoolVector<T, vector_size> temp(rhs.dataPoolId, rhs.)
|
||||
// memcpy(value, rhs.value, sizeof(T)*vector_size);
|
||||
// }
|
||||
/**
|
||||
* \brief The classes destructor is empty.
|
||||
* \details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolVector() {
|
||||
}
|
||||
;
|
||||
/**
|
||||
* \brief The operation returns the number of array entries in this variable.
|
||||
*/
|
||||
uint8_t getSize() {
|
||||
return vector_size;
|
||||
}
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
uint8_t getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
T &operator [](int i) {
|
||||
return value[i];
|
||||
}
|
||||
|
||||
const T &operator [](int i) const {
|
||||
return value[i];
|
||||
}
|
||||
|
||||
PoolVector<T, vector_size> &operator=(
|
||||
PoolVector<T, vector_size> newPoolVector) {
|
||||
|
||||
for (uint16_t i = 0; i < vector_size; i++) {
|
||||
this->value[i] = newPoolVector.value[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return vector_size * SerializeAdapter::getSerializedSize(value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* POOLVECTOR_H_ */
|
@ -1,7 +1,7 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataPoolAdmin.h>
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapoolglob/DataPoolAdmin.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/datapoolglob/PoolRawAccess.h>
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/parameters/ParameterMessage.h>
|
||||
@ -40,9 +40,9 @@ ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId,
|
||||
|
||||
uint8_t valid = data[4];
|
||||
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess variable(poolId, 0, &mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
ReturnValue_t status = mySet.read();
|
||||
if (status != RETURN_OK) {
|
||||
@ -92,9 +92,9 @@ void DataPoolAdmin::handleCommand() {
|
||||
|
||||
ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
const uint8_t* data, size_t size, uint8_t** dataPointer) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -113,7 +113,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
const uint8_t* readPosition = data;
|
||||
|
||||
for (; size > 0; size -= typeSize) {
|
||||
DataSet rawSet;
|
||||
GlobDataSet rawSet;
|
||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
status = rawSet.read();
|
||||
@ -131,9 +131,9 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
|
||||
ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
||||
uint8_t** dataPointer, uint8_t* copyHere) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -146,7 +146,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
||||
}
|
||||
uint8_t* ptrToCopy = copyHere;
|
||||
for (; size > 0; size -= typeSize) {
|
||||
DataSet rawSet;
|
||||
GlobDataSet rawSet;
|
||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
status = rawSet.read();
|
@ -1,15 +1,16 @@
|
||||
#ifndef DATAPOOLADMIN_H_
|
||||
#define DATAPOOLADMIN_H_
|
||||
|
||||
#include <framework/memory/MemoryHelper.h>
|
||||
#include <framework/action/HasActionsIF.h>
|
||||
#include <framework/action/SimpleActionHelper.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/parameters/ReceivesParameterMessagesIF.h>
|
||||
#include <framework/datapool/DataPoolParameterWrapper.h>
|
||||
#include <framework/action/HasActionsIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/parameters/ReceivesParameterMessagesIF.h>
|
||||
|
||||
#include <framework/memory/MemoryHelper.h>
|
||||
#include <framework/action/SimpleActionHelper.h>
|
||||
#include <framework/datapoolglob/DataPoolParameterWrapper.h>
|
||||
|
||||
class DataPoolAdmin: public HasActionsIF,
|
||||
public ExecutableObjectIF,
|
@ -1,10 +1,8 @@
|
||||
#include "DataPoolParameterWrapper.h"
|
||||
|
||||
//for returncodes
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/DataPoolParameterWrapper.h>
|
||||
#include <framework/datapoolglob/PoolRawAccess.h>
|
||||
#include <framework/parameters/HasParametersIF.h>
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
|
||||
DataPoolParameterWrapper::DataPoolParameterWrapper() :
|
||||
type(Type::UNKNOWN_TYPE), rows(0), columns(0), poolId(
|
||||
@ -20,7 +18,7 @@ ReturnValue_t DataPoolParameterWrapper::set(uint8_t domainId,
|
||||
uint16_t parameterId) {
|
||||
poolId = (domainId << 16) + parameterId;
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, 0, &mySet, PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = mySet.read();
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -57,7 +55,7 @@ ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer,
|
||||
}
|
||||
|
||||
for (uint8_t index = 0; index < rows; index++){
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, index, &mySet,PoolVariableIF::VAR_READ);
|
||||
mySet.read();
|
||||
result = raw.serialize(buffer,size,maxSize,streamEndianness);
|
||||
@ -94,7 +92,7 @@ ReturnValue_t DataPoolParameterWrapper::deSerializeData(uint8_t startingRow,
|
||||
|
||||
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, startingRow + fromRow, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
132
datapoolglob/GlobalDataPool.cpp
Normal file
132
datapoolglob/GlobalDataPool.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
|
||||
GlobalDataPool::GlobalDataPool(
|
||||
void(*initFunction)(GlobPoolMap* pool_map)) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if (initFunction != NULL ) {
|
||||
initFunction( &this->globDataPool );
|
||||
}
|
||||
}
|
||||
|
||||
GlobalDataPool::~GlobalDataPool() {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
for(GlobPoolMapIter it = this->globDataPool.begin();
|
||||
it != this->globDataPool.end(); ++it )
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
// The function checks PID, type and array length before returning a copy of
|
||||
// the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
||||
template <typename T> PoolEntry<T>* GlobalDataPool::getData( uint32_t data_pool_id,
|
||||
uint8_t sizeOrPosition ) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
||||
if (entry != nullptr ) {
|
||||
if ( sizeOrPosition <= entry->length ) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PoolEntryIF* GlobalDataPool::getRawData( uint32_t data_pool_id ) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
return it->second;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalDataPool::unlockDataPool() {
|
||||
ReturnValue_t status = mutex->unlockMutex();
|
||||
if(status != RETURN_OK) {
|
||||
sif::error << "DataPool::DataPool: unlock of mutex failed with"
|
||||
" error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalDataPool::lockDataPool(uint32_t timeoutMs) {
|
||||
ReturnValue_t status = mutex->lockMutex(timeoutMs);
|
||||
if(status != RETURN_OK) {
|
||||
sif::error << "DataPool::DataPool: lock of mutex failed "
|
||||
"with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void GlobalDataPool::print() {
|
||||
sif::debug << "DataPool contains: " << std::endl;
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
||||
dataPoolIt = this->globDataPool.begin();
|
||||
while( dataPoolIt != this->globDataPool.end() ) {
|
||||
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
||||
dataPoolIt->second->print();
|
||||
dataPoolIt++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GlobalDataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
||||
return (parameter_id >> 8) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
uint8_t GlobalDataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
||||
return (parameter_id & 0x000000FF);
|
||||
}
|
||||
|
||||
uint32_t GlobalDataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
||||
return (poolId << 8) + index;
|
||||
}
|
||||
|
||||
|
||||
//SHOULDDO: Do we need a mutex lock here... I don't think so,
|
||||
//as we only check static const values of elements in a list that do not change.
|
||||
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
||||
ReturnValue_t GlobalDataPool::getType(uint32_t parameter_id, Type* type) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( PIDToDataPoolId(parameter_id));
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
*type = it->second->getType();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
*type = Type::UNKNOWN_TYPE;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalDataPool::exists(uint32_t parameterId) {
|
||||
uint32_t poolId = PIDToDataPoolId(parameterId);
|
||||
uint32_t index = PIDToArrayIndex(parameterId);
|
||||
GlobPoolMapIter it = this->globDataPool.find( poolId );
|
||||
if (it != globDataPool.end()) {
|
||||
if (it->second->getSize() >= index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template PoolEntry<uint8_t>* GlobalDataPool::getData<uint8_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint16_t>* GlobalDataPool::getData<uint16_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint32_t>* GlobalDataPool::getData<uint32_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint64_t>* GlobalDataPool::getData<uint64_t>(
|
||||
uint32_t data_pool_id, uint8_t size);
|
||||
template PoolEntry<int8_t>* GlobalDataPool::getData<int8_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int16_t>* GlobalDataPool::getData<int16_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int32_t>* GlobalDataPool::getData<int32_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<float>* GlobalDataPool::getData<float>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<double>* GlobalDataPool::getData<double>(
|
||||
uint32_t data_pool_id, uint8_t size);
|
149
datapoolglob/GlobalDataPool.h
Normal file
149
datapoolglob/GlobalDataPool.h
Normal file
@ -0,0 +1,149 @@
|
||||
#ifndef GLOBALDATAPOOL_H_
|
||||
#define GLOBALDATAPOOL_H_
|
||||
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* @defgroup data_pool Global data pool
|
||||
* This is the group, where all classes associated with global
|
||||
* data pool handling belong to.
|
||||
* This includes classes to access Data Pool variables.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Typedefs for the global pool representations
|
||||
*/
|
||||
using GlobPoolMap = std::map<uint32_t, PoolEntryIF*>;
|
||||
using GlobPoolMapIter = GlobPoolMap::iterator;
|
||||
|
||||
/**
|
||||
* @brief This class represents the OBSW global data-pool.
|
||||
*
|
||||
* @details
|
||||
* All variables are registered and space is allocated in an initialization
|
||||
* function, which is passed do the constructor. Space for the variables is
|
||||
* allocated on the heap (with a new call).
|
||||
*
|
||||
* The data is found by a data pool id, which uniquely represents a variable.
|
||||
* Data pool variables should be used with a blackboard logic in mind,
|
||||
* which means read data is valid (if flagged so),
|
||||
* but not necessarily up-to-date.
|
||||
*
|
||||
* Variables are either single values or arrays.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class GlobalDataPool : public HasReturnvaluesIF {
|
||||
private:
|
||||
/**
|
||||
* @brief This is the actual data pool itself.
|
||||
* @details It is represented by a map with the data pool id as index
|
||||
* and a pointer to a single PoolEntry as value.
|
||||
*/
|
||||
GlobPoolMap globDataPool;
|
||||
|
||||
/**
|
||||
* @brief The mutex is created in the constructor and makes
|
||||
* access mutual exclusive.
|
||||
* @details Locking and unlocking the pool is only done by the DataSet class.
|
||||
*/
|
||||
MutexIF* mutex;
|
||||
public:
|
||||
/**
|
||||
* @brief In the classes constructor,
|
||||
* the passed initialization function is called.
|
||||
* @details
|
||||
* To enable filling the pool, a pointer to the map is passed,
|
||||
* allowing direct access to the pool's content.
|
||||
* On runtime, adding or removing variables is forbidden.
|
||||
*/
|
||||
GlobalDataPool( void ( *initFunction )( GlobPoolMap* pool_map ) );
|
||||
|
||||
/**
|
||||
* @brief The destructor iterates through the data_pool map and
|
||||
* calls all entries destructors to clean up the heap.
|
||||
*/
|
||||
~GlobalDataPool();
|
||||
|
||||
/**
|
||||
* @brief This is the default call to access the pool.
|
||||
* @details
|
||||
* A pointer to the PoolEntry object is returned.
|
||||
* The call checks data pool id, type and array size.
|
||||
* Returns NULL in case of failure.
|
||||
* @param data_pool_id The data pool id to search.
|
||||
* @param sizeOrPosition The array size (not byte size!) of the pool entry,
|
||||
* or the position the user wants to read.
|
||||
* If smaller than the entry size, everything's ok.
|
||||
*/
|
||||
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id,
|
||||
uint8_t sizeOrPosition );
|
||||
|
||||
/**
|
||||
* @brief An alternative call to get a data pool entry in case the type is not implicitly known
|
||||
* (i.e. in Housekeeping Telemetry).
|
||||
* @details It returns a basic interface and does NOT perform
|
||||
* a size check. The caller has to assure he does not copy too much data.
|
||||
* Returns NULL in case the entry is not found.
|
||||
* @param data_pool_id The data pool id to search.
|
||||
*/
|
||||
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate locking the global data pool.
|
||||
* @details It fetches the pool's mutex id and tries to acquire the mutex.
|
||||
*/
|
||||
ReturnValue_t lockDataPool(uint32_t timeoutMs = MutexIF::BLOCKING);
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* @details It fetches the pool's mutex id and tries to free the mutex.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool();
|
||||
/**
|
||||
* @brief The print call is a simple debug method.
|
||||
* @details It prints the current content of the data pool.
|
||||
* It iterates through the data_pool map and calls each entry's print() method.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Extracts the data pool id from a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The data pool id as used within the OBSW.
|
||||
*/
|
||||
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
||||
/**
|
||||
* Extracts an array index out of a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The index of the corresponding data pool entry.
|
||||
*/
|
||||
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
||||
/**
|
||||
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
||||
*/
|
||||
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
||||
|
||||
/**
|
||||
* Method to return the type of a pool variable.
|
||||
* @param parameter_id A parameterID (not pool id) of a DP member.
|
||||
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
||||
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
||||
|
||||
/**
|
||||
* Method to check if a PID exists. Does not lock, as there's no
|
||||
* possibility to alter the list that is checked during run-time.
|
||||
* @param parameterId The PID (not pool id!) of a parameter.
|
||||
* @return true if exists, false else.
|
||||
*/
|
||||
bool exists(uint32_t parameterId);
|
||||
};
|
||||
|
||||
//We assume someone globally instantiates a DataPool.
|
||||
namespace glob {
|
||||
extern GlobalDataPool dataPool;
|
||||
}
|
||||
|
||||
#endif /* DATAPOOL_H_ */
|
44
datapoolglob/GlobalDataSet.cpp
Normal file
44
datapoolglob/GlobalDataSet.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
GlobDataSet::GlobDataSet(): DataSetBase(
|
||||
reinterpret_cast<PoolVariableIF**>(®isteredVariables),
|
||||
DATA_SET_MAX_SIZE) {}
|
||||
|
||||
// Don't do anything with your variables, they are dead already!
|
||||
// (Destructor is already called)
|
||||
GlobDataSet::~GlobDataSet() {}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit(bool valid, uint32_t lockTimeout) {
|
||||
setEntriesValid(valid);
|
||||
setSetValid(valid);
|
||||
return commit(lockTimeout);
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit(uint32_t lockTimeout) {
|
||||
return DataSetBase::commit(lockTimeout);
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::unlockDataPool() {
|
||||
return glob::dataPool.unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::lockDataPool(uint32_t timeoutMs) {
|
||||
return glob::dataPool.lockDataPool(timeoutMs);
|
||||
}
|
||||
|
||||
void GlobDataSet::setEntriesValid(bool valid) {
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ) {
|
||||
registeredVariables[count]->setValid(valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlobDataSet::setSetValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
|
96
datapoolglob/GlobalDataSet.h
Normal file
96
datapoolglob/GlobalDataSet.h
Normal file
@ -0,0 +1,96 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||
#define FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||
|
||||
#include <framework/datapool/DataSetBase.h>
|
||||
|
||||
/**
|
||||
* @brief The DataSet class manages a set of locally checked out variables
|
||||
* for the global data pool.
|
||||
* @details
|
||||
* This class uses the read-commit() semantic provided by the DataSetBase class.
|
||||
* It extends the base class by using the global data pool,
|
||||
* having a valid state and implementing lock und unlock calls for the global
|
||||
* datapool.
|
||||
*
|
||||
* For more information on how this class works, see the DataSetBase
|
||||
* documentation.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class GlobDataSet: public DataSetBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Creates an empty GlobDataSet. Use registerVariable or
|
||||
* supply a pointer to this dataset to PoolVariable
|
||||
* initializations to register pool variables.
|
||||
*/
|
||||
GlobDataSet();
|
||||
|
||||
/**
|
||||
* @brief The destructor automatically manages writing the valid
|
||||
* information of variables.
|
||||
* @details
|
||||
* In case the data set was read out, but not committed(indicated by state),
|
||||
* the destructor parses all variables that are still registered to the set.
|
||||
* For each, the valid flag in the data pool is set to "invalid".
|
||||
*/
|
||||
~GlobDataSet();
|
||||
|
||||
/**
|
||||
* Variant of method above which sets validity of all elements of the set.
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
* @return - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||
* contains non write-only variables
|
||||
*/
|
||||
ReturnValue_t commit(bool valid, uint32_t lockTimeout = MutexIF::BLOCKING);
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
/**
|
||||
* Set all entries
|
||||
* @param valid
|
||||
*/
|
||||
void setSetValid(bool valid);
|
||||
|
||||
/**
|
||||
* Set the valid information of all variables contained in the set which
|
||||
* are not read-only
|
||||
*
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
*/
|
||||
void setEntriesValid(bool valid);
|
||||
|
||||
//!< This definition sets the maximum number of variables to
|
||||
//! register in one DataSet.
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63;
|
||||
|
||||
private:
|
||||
/**
|
||||
* If the valid state of a dataset is always relevant to the whole
|
||||
* data set we can use this flag.
|
||||
*/
|
||||
bool valid = false;
|
||||
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate locking
|
||||
* the global data pool.
|
||||
* @details
|
||||
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate
|
||||
* unlocking the global data pool
|
||||
* @details
|
||||
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
void handleAlreadyReadDatasetCommit();
|
||||
ReturnValue_t handleUnreadDatasetCommit();
|
||||
|
||||
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLGLOB_DATASET_H_ */
|
213
datapoolglob/GlobalPoolVariable.h
Normal file
213
datapoolglob/GlobalPoolVariable.h
Normal file
@ -0,0 +1,213 @@
|
||||
#ifndef GLOBALPOOLVARIABLE_H_
|
||||
#define GLOBALPOOLVARIABLE_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
template<typename T, uint8_t n_var> class PoolVarList;
|
||||
|
||||
|
||||
/**
|
||||
* @brief This is the access class for non-array data pool entries.
|
||||
*
|
||||
* @details
|
||||
* To ensure safe usage of the data pool, operation is not done directly
|
||||
* on the data pool entries, but on local copies. This class provides simple
|
||||
* type-safe access to single data pool entries (i.e. entries with length = 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that the
|
||||
* variable's value in the data pool is not changed until the
|
||||
* commit call is executed.
|
||||
* @tparam T The template parameter sets the type of the variable.
|
||||
* Currently, all plain data types are supported, but in principle
|
||||
* any type is possible.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class GlobPoolVar: public PoolVariableIF {
|
||||
template<typename U, uint8_t n_var> friend class PoolVarList;
|
||||
static_assert(not std::is_same<T, bool>::value,
|
||||
"Do not use boolean for the PoolEntry type, use uint8_t instead!"
|
||||
"There is no boolean type in CCSDS.");
|
||||
public:
|
||||
/**
|
||||
* @brief In the constructor, the variable can register itself in a
|
||||
* DataSet (if nullptr is not passed).
|
||||
* @details
|
||||
* It DOES NOT fetch the current value from the data pool, but
|
||||
* sets the value attribute to default (0).
|
||||
* The value is fetched within the read() operation.
|
||||
* @param set_id This is the id in the global data pool
|
||||
* this instance of the access class corresponds to.
|
||||
* @param dataSet The data set in which the variable shall register
|
||||
* itself. If NULL, the variable is not registered.
|
||||
* @param setWritable If this flag is set to true, changes in the value
|
||||
* attribute can be written back to the data pool, otherwise not.
|
||||
*/
|
||||
GlobPoolVar(uint32_t set_id, DataSetIF* dataSet,
|
||||
ReadWriteMode_t setReadWriteMode);
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details The user can work on this attribute
|
||||
* just like he would on a simple local variable.
|
||||
*/
|
||||
T value = 0;
|
||||
|
||||
/**
|
||||
* @brief Copy ctor to copy classes containing Pool Variables.
|
||||
* (Robin): This only copies member variables, which is done
|
||||
* by the default copy ctor. maybe we can ommit this ctor?
|
||||
*/
|
||||
GlobPoolVar(const GlobPoolVar& rhs);
|
||||
|
||||
/**
|
||||
* @brief The classes destructor is empty.
|
||||
* @details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~GlobPoolVar() {}
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the value from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout) override;
|
||||
/**
|
||||
* @brief The commit call writes back the variable's value to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* The commit call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool is
|
||||
* copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
|
||||
/**
|
||||
* @brief The information whether the class is read-write or read-only
|
||||
* is stored here.
|
||||
*/
|
||||
pool_rwm_t readWriteMode;
|
||||
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
GlobPoolVar();
|
||||
public:
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const override;
|
||||
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const override;
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId);
|
||||
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const override;
|
||||
|
||||
uint8_t getValid();
|
||||
|
||||
void setValid(bool valid) override;
|
||||
|
||||
operator T() {
|
||||
return value;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
GlobPoolVar<T> &operator=(T newValue) {
|
||||
value = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GlobPoolVar<T> &operator=(GlobPoolVar<T> newPoolVariable) {
|
||||
value = newPoolVariable.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize(&value, buffer, size, max_size,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return SerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
return SerializeAdapter::deSerialize(&value, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
#include <framework/datapoolglob/GlobalPoolVariable.tpp>
|
||||
|
||||
typedef GlobPoolVar<uint8_t> gp_bool_t;
|
||||
typedef GlobPoolVar<uint8_t> gp_uint8_t;
|
||||
typedef GlobPoolVar<uint16_t> gp_uint16_t;
|
||||
typedef GlobPoolVar<uint32_t> gp_uint32_t;
|
||||
typedef GlobPoolVar<int8_t> gp_int8_t;
|
||||
typedef GlobPoolVar<int16_t> gp_int16_t;
|
||||
typedef GlobPoolVar<int32_t> gp_int32_t;
|
||||
typedef GlobPoolVar<float> gp_float_t;
|
||||
typedef GlobPoolVar<double> gp_double_t;
|
||||
|
||||
#endif /* POOLVARIABLE_H_ */
|
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef GLOBALPOOLVARIABLE_TPP_
|
||||
#define GLOBALPOOLVARIABLE_TPP_
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar(uint32_t set_id,
|
||||
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode):
|
||||
dataPoolId(set_id), valid(PoolVariableIF::INVALID),
|
||||
readWriteMode(setReadWriteMode)
|
||||
{
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::commit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::readWithoutLock() {
|
||||
PoolEntry<T>* read_out = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = *(read_out->address);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
value = 0;
|
||||
valid = false;
|
||||
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::commitWithoutLock() {
|
||||
PoolEntry<T>* write_back = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
*(write_back->address) = value;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar():
|
||||
dataPoolId(PoolVariableIF::NO_PARAMETER),
|
||||
valid(PoolVariableIF::INVALID),
|
||||
readWriteMode(VAR_READ), value(0) {}
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar(const GlobPoolVar& rhs) :
|
||||
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
||||
rhs.readWriteMode), value(rhs.value) {}
|
||||
|
||||
template <class T>
|
||||
inline pool_rwm_t GlobPoolVar<T>::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline uint32_t GlobPoolVar<T>::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void GlobPoolVar<T>::setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool GlobPoolVar<T>::isValid() const {
|
||||
if (valid)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline uint8_t GlobPoolVar<T>::getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void GlobPoolVar<T>::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
#endif
|
185
datapoolglob/GlobalPoolVector.h
Normal file
185
datapoolglob/GlobalPoolVector.h
Normal file
@ -0,0 +1,185 @@
|
||||
#ifndef GLOBALPOOLVECTOR_H_
|
||||
#define GLOBALPOOLVECTOR_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
/**
|
||||
* @brief This is the access class for array-type data pool entries.
|
||||
*
|
||||
* @details
|
||||
* To ensure safe usage of the data pool, operation is not done directly on the
|
||||
* data pool entries, but on local copies. This class provides simple type-
|
||||
* and length-safe access to vector-style data pool entries (i.e. entries with
|
||||
* length > 1). The class can be instantiated as read-write and read only.
|
||||
*
|
||||
* It provides a commit-and-roll-back semantic, which means that no array
|
||||
* entry in the data pool is changed until the commit call is executed.
|
||||
* There are two template parameters:
|
||||
* @tparam T
|
||||
* This template parameter specifies the data type of an array entry. Currently,
|
||||
* all plain data types are supported, but in principle any type is possible.
|
||||
* @tparam vector_size
|
||||
* This template parameter specifies the vector size of this entry. Using a
|
||||
* template parameter for this is not perfect, but avoids
|
||||
* dynamic memory allocation.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T, uint16_t vectorSize>
|
||||
class GlobPoolVector: public PoolVariableIF {
|
||||
public:
|
||||
/**
|
||||
* @brief In the constructor, the variable can register itself in a
|
||||
* DataSet (if no nullptr is passed).
|
||||
* @details
|
||||
* It DOES NOT fetch the current value from the data pool, but sets the
|
||||
* value attribute to default (0). The value is fetched within the
|
||||
* read() operation.
|
||||
* @param set_id
|
||||
* This is the id in the global data pool this instance of the access
|
||||
* class corresponds to.
|
||||
* @param dataSet
|
||||
* The data set in which the variable shall register itself. If nullptr,
|
||||
* the variable is not registered.
|
||||
* @param setWritable
|
||||
* If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
GlobPoolVector(uint32_t set_id, DataSetIF* set,
|
||||
ReadWriteMode_t setReadWriteMode);
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details The user can work on this attribute
|
||||
* just like he would on a local array of this type.
|
||||
*/
|
||||
T value[vectorSize];
|
||||
/**
|
||||
* @brief The classes destructor is empty.
|
||||
* @details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~GlobPoolVector() {};
|
||||
/**
|
||||
* @brief The operation returns the number of array entries
|
||||
* in this variable.
|
||||
*/
|
||||
uint8_t getSize() {
|
||||
return vectorSize;
|
||||
}
|
||||
/**
|
||||
* @brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* @brief This operation sets the data pool id of the variable.
|
||||
* @details
|
||||
* The method is necessary to set id's of data pool member variables
|
||||
* with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void setValid(bool valid) {this->valid = valid;}
|
||||
uint8_t getValid() {return valid;}
|
||||
|
||||
T &operator [](int i) {return value[i];}
|
||||
const T &operator [](int i) const {return value[i];}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t max_size, Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the array's values
|
||||
* from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies all array values
|
||||
* and the valid information to its local attributes.
|
||||
* In case of a failure (wrong type, size or pool id not found), the
|
||||
* variable is set to zero and invalid.
|
||||
* The read call is protected by a lock of the global data pool.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The commit call is protected by a lock of the global data pool.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool id is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool
|
||||
* is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* @brief The information whether the class is read-write or
|
||||
* read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
};
|
||||
|
||||
#include <framework/datapoolglob/GlobalPoolVector.tpp>
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
using gp_vec_t = GlobPoolVector<T, vectorSize>;
|
||||
|
||||
#endif /* POOLVECTOR_H_ */
|
117
datapoolglob/GlobalPoolVector.tpp
Normal file
117
datapoolglob/GlobalPoolVector.tpp
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef GLOBALPOOLVECTOR_TPP_
|
||||
#define GLOBALPOOLVECTOR_TPP_
|
||||
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline GlobPoolVector<T, vectorSize>::GlobPoolVector(uint32_t set_id,
|
||||
DataSetIF* set, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
if (set != nullptr) {
|
||||
set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commit(
|
||||
uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::readWithoutLock() {
|
||||
PoolEntry<T>* read_out = glob::dataPool.getData<T>(this->dataPoolId,
|
||||
vectorSize);
|
||||
if (read_out != nullptr) {
|
||||
this->valid = read_out->valid;
|
||||
memcpy(this->value, read_out->address, read_out->getByteSize());
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
} else {
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
sif::error << "PoolVector: Read of DP Variable 0x" << std::hex
|
||||
<< std::setw(8) << std::setfill('0') << dataPoolId <<
|
||||
std::dec << " failed." << std::endl;
|
||||
this->valid = INVALID;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||
PoolEntry<T>* writeBack = glob::dataPool.getData<T>(this->dataPoolId,
|
||||
vectorSize);
|
||||
if ((writeBack != nullptr) && (this->readWriteMode != VAR_READ)) {
|
||||
writeBack->valid = valid;
|
||||
memcpy(writeBack->address, this->value, writeBack->getByteSize());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
||||
size_t* size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||
max_size, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline size_t GlobPoolVector<T, vectorSize>::getSerializedSize() const {
|
||||
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::deSerialize(
|
||||
const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#ifndef PIDREADER_H_
|
||||
#define PIDREADER_H_
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
@ -15,10 +15,10 @@ class PIDReader: public PoolVariableIF {
|
||||
protected:
|
||||
uint32_t parameterId;
|
||||
uint8_t valid;
|
||||
ReturnValue_t read() {
|
||||
uint8_t arrayIndex = DataPool::PIDToArrayIndex(parameterId);
|
||||
PoolEntry<T> *read_out = ::dataPool.getData<T>(
|
||||
DataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
ReturnValue_t readWithoutLock() {
|
||||
uint8_t arrayIndex = GlobalDataPool::PIDToArrayIndex(parameterId);
|
||||
PoolEntry<T> *read_out = glob::dataPool.getData<T>(
|
||||
GlobalDataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = read_out->address[arrayIndex];
|
||||
@ -36,9 +36,13 @@ protected:
|
||||
* Reason is the possibility to access a single DP vector element, but if we commit,
|
||||
* we set validity of the whole vector.
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
ReturnValue_t commit(uint32_t lockTimeout) override {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
ReturnValue_t commitWithoutLock() override {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
@ -72,6 +76,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t read(uint32_t lockTimeout) override {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "PIDReader::read: Could not unlock data pool!"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
@ -89,7 +106,7 @@ public:
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return DataPool::PIDToDataPoolId(parameterId);
|
||||
return GlobalDataPool::PIDToDataPoolId(parameterId);
|
||||
}
|
||||
uint32_t getParameterId() const {
|
||||
return parameterId;
|
||||
@ -114,7 +131,7 @@ public:
|
||||
return valid;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
void setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
||||
#define FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
||||
#ifndef FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||
#define FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapoolglob/PIDReader.h>
|
||||
template <class T, uint8_t n_var>
|
||||
class PIDReaderList {
|
||||
private:
|
||||
@ -24,4 +24,4 @@ public:
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_PIDREADERLIST_H_ */
|
||||
#endif /* FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_ */
|
239
datapoolglob/PoolRawAccess.cpp
Normal file
239
datapoolglob/PoolRawAccess.cpp
Normal file
@ -0,0 +1,239 @@
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/datapoolglob/PoolRawAccess.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/serialize/EndianConverter.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false),
|
||||
type(Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0),
|
||||
readWriteMode(setReadWriteMode) {
|
||||
memset(value, 0, sizeof(value));
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
PoolRawAccess::~PoolRawAccess() {}
|
||||
|
||||
ReturnValue_t PoolRawAccess::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::readWithoutLock() {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
PoolEntryIF* readOut = glob::dataPool.getRawData(dataPoolId);
|
||||
if (readOut != nullptr) {
|
||||
result = handleReadOut(readOut);
|
||||
if(result == RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
result = READ_ENTRY_NON_EXISTENT;
|
||||
}
|
||||
handleReadError(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* readOut) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
valid = readOut->getValid();
|
||||
if (readOut->getSize() > arrayEntry) {
|
||||
arraySize = readOut->getSize();
|
||||
typeSize = readOut->getByteSize() / readOut->getSize();
|
||||
type = readOut->getType();
|
||||
if (typeSize <= sizeof(value)) {
|
||||
uint16_t arrayPosition = arrayEntry * typeSize;
|
||||
sizeTillEnd = readOut->getByteSize() - arrayPosition;
|
||||
uint8_t* ptr = &((uint8_t*) readOut->getRawData())[arrayPosition];
|
||||
memcpy(value, ptr, typeSize);
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
result = READ_TYPE_TOO_LARGE;
|
||||
}
|
||||
} else {
|
||||
//debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl;
|
||||
result = READ_INDEX_TOO_LARGE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PoolRawAccess::handleReadError(ReturnValue_t result) {
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId
|
||||
<< std::dec << " failed, ";
|
||||
if(result == READ_TYPE_TOO_LARGE) {
|
||||
sif::error << "type too large." << std::endl;
|
||||
}
|
||||
else if(result == READ_INDEX_TOO_LARGE) {
|
||||
sif::error << "index too large." << std::endl;
|
||||
}
|
||||
else if(result == READ_ENTRY_NON_EXISTENT) {
|
||||
sif::error << "entry does not exist." << std::endl;
|
||||
}
|
||||
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
memset(value, 0, sizeof(value));
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commitWithoutLock() {
|
||||
PoolEntryIF* write_back = glob::dataPool.getRawData(dataPoolId);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->setValid(valid);
|
||||
uint8_t array_position = arrayEntry * typeSize;
|
||||
uint8_t* ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
||||
memcpy(ptr, value, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* PoolRawAccess::getEntry() {
|
||||
return value;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
|
||||
size_t* writtenBytes, size_t max_size) {
|
||||
uint8_t* data_ptr = getEntry();
|
||||
// debug << "PoolRawAccess::getEntry: Array position: " <<
|
||||
// index * size_of_type << " Size of T: " << (int)size_of_type <<
|
||||
// " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||
if (typeSize == 0)
|
||||
return DATA_POOL_ACCESS_FAILED;
|
||||
if (typeSize > max_size)
|
||||
return INCORRECT_SIZE;
|
||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||
*writtenBytes = typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
if (typeSize + *size <= maxSize) {
|
||||
switch(streamEndianness) {
|
||||
case(Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case(Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case(Endianness::MACHINE):
|
||||
default:
|
||||
memcpy(*buffer, value, typeSize);
|
||||
break;
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeOfType() {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getArraySize(){
|
||||
return arraySize;
|
||||
}
|
||||
|
||||
uint32_t PoolRawAccess::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize) {
|
||||
if (typeSize == setSize) {
|
||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: "
|
||||
"Internal" << (uint32_t) typeSize << ", Requested: " << setSize
|
||||
<< std::endl;
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
bool PoolRawAccess::isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void PoolRawAccess::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
|
||||
size_t PoolRawAccess::getSerializedSize() const {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) {
|
||||
|
||||
if (*size >= typeSize) {
|
||||
switch(streamEndianness) {
|
||||
case(Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case(Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case(Endianness::MACHINE):
|
||||
default:
|
||||
memcpy(value, *buffer, typeSize);
|
||||
break;
|
||||
}
|
||||
*size -= typeSize;
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
220
datapoolglob/PoolRawAccess.h
Normal file
220
datapoolglob/PoolRawAccess.h
Normal file
@ -0,0 +1,220 @@
|
||||
#ifndef POOLRAWACCESS_H_
|
||||
#define POOLRAWACCESS_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
|
||||
/**
|
||||
* @brief This class allows accessing Data Pool variables as raw bytes.
|
||||
* @details
|
||||
* This is necessary to have an access method for HK data, as the PID's alone
|
||||
* do not provide type information. Please note that the the raw pool access
|
||||
* read() and commit() calls are not thread-safe.
|
||||
*
|
||||
* Please supply a data set and use the data set read(), commit() calls for
|
||||
* thread-safe data pool access.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccess: public PoolVariableIF, HasReturnvaluesIF {
|
||||
public:
|
||||
/**
|
||||
* This constructor is used to access a data pool entry with a
|
||||
* given ID if the target type is not known. A DataSet object is supplied
|
||||
* and the data pool entry with the given ID is registered to that data set.
|
||||
* Please note that a pool raw access buffer only has a buffer
|
||||
* with a size of double. As such, for vector entries which have
|
||||
* @param data_pool_id Target data pool entry ID
|
||||
* @param arrayEntry
|
||||
* @param data_set Dataset to register data pool entry to
|
||||
* @param setReadWriteMode
|
||||
* @param registerVectors If set to true, the constructor checks if
|
||||
* there are multiple vector entries to registers
|
||||
* and registers all of them recursively into the data_set
|
||||
*
|
||||
*/
|
||||
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
||||
DataSetIF* data_set, ReadWriteMode_t setReadWriteMode =
|
||||
PoolVariableIF::VAR_READ);
|
||||
|
||||
/**
|
||||
* @brief This operation returns a pointer to the entry fetched.
|
||||
* @details Return pointer to the buffer containing the raw data
|
||||
* Size and number of data can be retrieved by other means.
|
||||
*/
|
||||
uint8_t* getEntry();
|
||||
/**
|
||||
* @brief This operation returns the fetched entry from the data pool and
|
||||
* flips the bytes, if necessary.
|
||||
* @details It makes use of the getEntry call of this function, but additionally flips the
|
||||
* bytes to big endian, which is the default for external communication (as House-
|
||||
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
||||
* buffer, if it fits in the given max_size.
|
||||
* @param buffer A pointer to a buffer to write to
|
||||
* @param writtenBytes The number of bytes written is returned with this value.
|
||||
* @param max_size The maximum size that the function may write to buffer.
|
||||
* @return - @c RETURN_OK if entry could be acquired
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||
size_t maxSize);
|
||||
|
||||
/**
|
||||
* @brief Serialize raw pool entry into provided buffer directly
|
||||
* @param buffer Provided buffer. Raw pool data will be copied here
|
||||
* @param size [out] Increment provided size value by serialized size
|
||||
* @param max_size Maximum allowed serialization size
|
||||
* @param bigEndian Specify endianess
|
||||
* @return - @c RETURN_OK if serialization was successfull
|
||||
* - @c SerializeIF::BUFFER_TOO_SHORT if range check failed
|
||||
*/
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
* @param size Size of the data to write. Must fit this->size.
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t setEntryFromBigEndian(const uint8_t* buffer,
|
||||
size_t setSize);
|
||||
/**
|
||||
* @brief This operation returns the type of the entry currently stored.
|
||||
*/
|
||||
Type getType();
|
||||
/**
|
||||
* @brief This operation returns the size of the entry currently stored.
|
||||
*/
|
||||
size_t getSizeOfType();
|
||||
/**
|
||||
*
|
||||
* @return the size of the datapool array
|
||||
*/
|
||||
size_t getArraySize();
|
||||
/**
|
||||
* @brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
||||
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t READ_TYPE_TOO_LARGE = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t READ_INDEX_TOO_LARGE = MAKE_RETURN_CODE(0x04);
|
||||
static const ReturnValue_t READ_ENTRY_NON_EXISTENT = MAKE_RETURN_CODE(0x05);
|
||||
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
||||
uint8_t value[RAW_MAX_SIZE];
|
||||
|
||||
|
||||
/**
|
||||
* @brief The classes destructor is empty. If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolRawAccess();
|
||||
|
||||
/**
|
||||
* This method returns if the variable is read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const;
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
void setValid(bool valid);
|
||||
/**
|
||||
* Getter for the remaining size.
|
||||
*/
|
||||
size_t getSizeTillEnd() const;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the value from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The call is protected by a lock of the global data pool.
|
||||
* @return -@c RETURN_OK Read successfull
|
||||
* -@c READ_TYPE_TOO_LARGE
|
||||
* -@c READ_INDEX_TOO_LARGE
|
||||
* -@c READ_ENTRY_NON_EXISTENT
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call writes back the variable's value to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The call is protected by a lock of the global data pool.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
ReturnValue_t handleReadOut(PoolEntryIF* read_out);
|
||||
void handleReadError(ReturnValue_t result);
|
||||
private:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* @brief The array entry that is fetched from the data pool.
|
||||
*/
|
||||
uint8_t arrayEntry;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* @brief This value contains the type of the data pool entry.
|
||||
*/
|
||||
Type type;
|
||||
/**
|
||||
* @brief This value contains the size of the data pool entry type in bytes.
|
||||
*/
|
||||
size_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
size_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
size_t sizeTillEnd;
|
||||
/**
|
||||
* @brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
};
|
||||
|
||||
#endif /* POOLRAWACCESS_H_ */
|
77
datapoollocal/HasLocalDataPoolIF.h
Normal file
77
datapoollocal/HasLocalDataPoolIF.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
#include <framework/housekeeping/HousekeepingMessage.h>
|
||||
#include <map>
|
||||
|
||||
class LocalDataPoolManager;
|
||||
class DataSetIF;
|
||||
/**
|
||||
* @brief Type definition for local pool entries.
|
||||
*/
|
||||
using lp_id_t = uint32_t;
|
||||
using LocalDataPool = std::map<lp_id_t, PoolEntryIF*>;
|
||||
using LocalDataPoolMapIter = LocalDataPool::iterator;
|
||||
|
||||
/**
|
||||
* @brief This interface is implemented by classes which posses a local
|
||||
* data pool (not the managing class). It defines the relationship
|
||||
* between the local data pool owner and the LocalDataPoolManager.
|
||||
* @details
|
||||
* Any class implementing this interface shall also have a LocalDataPoolManager
|
||||
* member class which contains the actual pool data structure
|
||||
* and exposes the public interface for it.
|
||||
* This is required because the pool entries are templates, which makes
|
||||
* specifying an interface rather difficult. The local data pool can be
|
||||
* accessed by using the LocalPoolVariable, LocalPoolVector or LocalDataSet
|
||||
* classes.
|
||||
*
|
||||
* Architectural Note:
|
||||
* This could be circumvented by using a wrapper/accessor function or
|
||||
* implementing the templated function in this interface..
|
||||
* The first solution sounds better than the second but
|
||||
* the LocalPoolVariable classes are templates as well, so this just shifts
|
||||
* the problem somewhere else. Interfaces are nice, but the most
|
||||
* pragmatic solution I found was to offer the client the full interface
|
||||
* of the LocalDataPoolManager.
|
||||
*/
|
||||
class HasLocalDataPoolIF {
|
||||
public:
|
||||
virtual~ HasLocalDataPoolIF() {};
|
||||
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;
|
||||
|
||||
/** Command queue for housekeeping messages. */
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
|
||||
/** Is used by pool owner to initialize the pool map once */
|
||||
virtual ReturnValue_t initializePoolEntries(
|
||||
LocalDataPool& localDataPoolMap) = 0;
|
||||
|
||||
/** Can be used to get a handle to the local data pool manager. */
|
||||
virtual LocalDataPoolManager* getHkManagerHandle() = 0;
|
||||
|
||||
/**
|
||||
* This function is used by the pool manager to get a valid dataset
|
||||
* from a SID
|
||||
* @param sid Corresponding structure ID
|
||||
* @return
|
||||
*/
|
||||
virtual DataSetIF* getDataSetHandle(sid_t sid) = 0;
|
||||
|
||||
/* These function can be implemented by pool owner, as they are required
|
||||
* by the housekeeping message interface */
|
||||
virtual ReturnValue_t addDataSet(sid_t sid) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
virtual ReturnValue_t removeDataSet(sid_t sid) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
virtual ReturnValue_t changeCollectionInterval(sid_t sid,
|
||||
dur_seconds_t newInterval) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_ */
|
218
datapoollocal/LocalDataPoolManager.cpp
Normal file
218
datapoollocal/LocalDataPoolManager.cpp
Normal file
@ -0,0 +1,218 @@
|
||||
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
||||
#include <framework/datapoollocal/LocalDataSet.h>
|
||||
#include <framework/housekeeping/AcceptsHkPacketsIF.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
|
||||
MessageQueueIF* queueToUse, bool appendValidityBuffer):
|
||||
appendValidityBuffer(appendValidityBuffer) {
|
||||
if(owner == nullptr) {
|
||||
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
|
||||
return;
|
||||
}
|
||||
this->owner = owner;
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if(mutex == nullptr) {
|
||||
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
|
||||
"Could not create mutex." << std::endl;
|
||||
}
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if(ipcStore == nullptr) {
|
||||
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
|
||||
"Could not set IPC store." << std::endl;
|
||||
}
|
||||
hkQueue = queueToUse;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
|
||||
object_id_t hkDestination) {
|
||||
if(queueToUse == nullptr) {
|
||||
sif::error << "LocalDataPoolManager::initialize: Supplied queue "
|
||||
"invalid!" << std::endl;
|
||||
}
|
||||
hkQueue = queueToUse;
|
||||
|
||||
if(hkDestination == objects::NO_OBJECT) {
|
||||
return initializeHousekeepingPoolEntriesOnce();
|
||||
}
|
||||
|
||||
AcceptsHkPacketsIF* hkReceiver =
|
||||
objectManager->get<AcceptsHkPacketsIF>(hkDestination);
|
||||
if(hkReceiver != nullptr) {
|
||||
setHkPacketDestination(hkReceiver->getHkQueue());
|
||||
}
|
||||
else {
|
||||
sif::warning << "LocalDataPoolManager::initialize: Could not retrieve"
|
||||
" queue ID from HK destination object ID. " << std::flush;
|
||||
sif::warning << "Make sure it exists and the object impements "
|
||||
"AcceptsHkPacketsIF!" << std::endl;
|
||||
}
|
||||
return initializeHousekeepingPoolEntriesOnce();
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::setHkPacketDestination(
|
||||
MessageQueueId_t hkDestination) {
|
||||
this->hkDestination = hkDestination;
|
||||
}
|
||||
|
||||
LocalDataPoolManager::~LocalDataPoolManager() {}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
|
||||
if(not mapInitialized) {
|
||||
ReturnValue_t result = owner->initializePoolEntries(localPoolMap);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
mapInitialized = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
sif::warning << "HousekeepingManager: The map should only be initialized "
|
||||
"once!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||
CommandMessage* message) {
|
||||
Command_t command = message->getCommand();
|
||||
switch(command) {
|
||||
// I think those are the only commands which can be handled here..
|
||||
case(HousekeepingMessage::ADD_HK_REPORT_STRUCT):
|
||||
case(HousekeepingMessage::ADD_DIAGNOSTICS_REPORT_STRUCT):
|
||||
// We should use OwnsLocalPoolDataIF to specify those functions..
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
|
||||
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
|
||||
//return generateSetStructurePacket(message->getSid());
|
||||
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
|
||||
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT):
|
||||
//return generateHousekeepingPacket(message->getSid());
|
||||
default:
|
||||
return CommandMessageIF::UNKNOWN_COMMAND;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::printPoolEntry(
|
||||
lp_id_t localPoolId) {
|
||||
auto poolIter = localPoolMap.find(localPoolId);
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
sif::debug << "HousekeepingManager::fechPoolEntry:"
|
||||
" Pool entry not found." << std::endl;
|
||||
return POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
poolIter->second->print();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MutexIF* LocalDataPoolManager::getMutexHandle() {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
|
||||
return owner;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
MessageQueueId_t sendTo) {
|
||||
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
|
||||
owner->getDataSetHandle(sid));
|
||||
if(dataSetToSerialize == nullptr) {
|
||||
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
|
||||
" Set ID not found" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = serializeHkPacketIntoStore(&storeId,
|
||||
dataSetToSerialize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// and now we set a HK message and send it the HK packet destination.
|
||||
CommandMessage hkMessage;
|
||||
HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId);
|
||||
if(hkQueue == nullptr) {
|
||||
return QUEUE_OR_DESTINATION_NOT_SET;
|
||||
}
|
||||
|
||||
if(sendTo != MessageQueueIF::NO_QUEUE) {
|
||||
result = hkQueue->sendMessage(sendTo, &hkMessage);
|
||||
}
|
||||
else {
|
||||
if(hkDestination == MessageQueueIF::NO_QUEUE) {
|
||||
sif::warning << "LocalDataPoolManager::generateHousekeepingPacket:"
|
||||
" Destination is not set properly!" << std::endl;
|
||||
return QUEUE_OR_DESTINATION_NOT_SET;
|
||||
}
|
||||
else {
|
||||
result = hkQueue->sendMessage(hkDestination, &hkMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid) {
|
||||
LocalDataSet* dataSet = dynamic_cast<LocalDataSet*>(
|
||||
owner->getDataSetHandle(sid));
|
||||
if(dataSet == nullptr) {
|
||||
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
|
||||
" Set ID not found" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
size_t expectedSize = dataSet->getFillCount() * sizeof(lp_id_t);
|
||||
uint8_t* storePtr = nullptr;
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||
expectedSize,&storePtr);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
|
||||
"Could not get free element from IPC store." << std::endl;
|
||||
return result;
|
||||
}
|
||||
size_t size = 0;
|
||||
result = dataSet->serializeLocalPoolIds(&storePtr, &size,
|
||||
expectedSize, SerializeIF::Endianness::BIG);
|
||||
if(expectedSize != size) {
|
||||
sif::error << "HousekeepingManager::generateSetStructurePacket: "
|
||||
"Expected size is not equal to serialized size" << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::setMinimalSamplingFrequency(float frequencySeconds) {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
|
||||
store_address_t *storeId, LocalDataSet* dataSet) {
|
||||
size_t hkSize = dataSet->getSerializedSize();
|
||||
uint8_t* storePtr = nullptr;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(storeId, hkSize,&storePtr);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
|
||||
"Could not get free element from IPC store." << std::endl;
|
||||
return result;
|
||||
}
|
||||
size_t size = 0;
|
||||
|
||||
if(appendValidityBuffer) {
|
||||
result = dataSet->serializeWithValidityBuffer(&storePtr,
|
||||
&size, hkSize, SerializeIF::Endianness::MACHINE);
|
||||
}
|
||||
else {
|
||||
result = dataSet->serialize(&storePtr, &size, hkSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
}
|
||||
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "HousekeepingManager::serializeHkPacketIntoStore: "
|
||||
"Serialization proccess failed!" << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::performHkOperation() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
229
datapoollocal/LocalDataPoolManager.h
Normal file
229
datapoollocal/LocalDataPoolManager.h
Normal file
@ -0,0 +1,229 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
|
||||
#include <framework/housekeeping/HousekeepingMessage.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
class LocalDataSet;
|
||||
|
||||
/**
|
||||
* @brief This class is the managing instance for local data pool.
|
||||
* @details
|
||||
* The actual data pool structure is a member of this class. Any class which
|
||||
* has a local data pool shall have this class as a member and implement
|
||||
* the HasLocalDataPoolIF.
|
||||
*
|
||||
* Users of the data pool use the helper classes LocalDataSet,
|
||||
* LocalPoolVariable and LocalPoolVector to access pool entries in
|
||||
* a thread-safe and efficient way.
|
||||
*
|
||||
* The local data pools employ a blackboard logic: Only the most recent
|
||||
* value is stored. The helper classes offer a read() and commit() interface
|
||||
* through the PoolVariableIF which is used to read and update values.
|
||||
* Each pool entry has a valid state too.
|
||||
*
|
||||
*/
|
||||
class LocalDataPoolManager {
|
||||
template<typename T>
|
||||
friend class LocalPoolVar;
|
||||
template<typename T, uint16_t vecSize>
|
||||
friend class LocalPoolVector;
|
||||
friend class LocalDataSet;
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
|
||||
|
||||
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x0);
|
||||
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x1);
|
||||
|
||||
static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x2);
|
||||
//static constexpr ReturnValue_t SET_NOT_FOUND = MAKE_RETURN_CODE(0x3);
|
||||
|
||||
/**
|
||||
* This constructor is used by a class which wants to implement
|
||||
* a personal local data pool. The queueToUse can be supplied if it
|
||||
* is already known.
|
||||
*
|
||||
* initialize() has to be called in any case before using the object!
|
||||
* @param owner
|
||||
* @param queueToUse
|
||||
* @param appendValidityBuffer
|
||||
*/
|
||||
LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse,
|
||||
bool appendValidityBuffer = true);
|
||||
virtual~ LocalDataPoolManager();
|
||||
|
||||
/**
|
||||
* Initializes the map by calling the map initialization function of the
|
||||
* owner and assigns the queue to use.
|
||||
* @param queueToUse
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t initialize(MessageQueueIF* queueToUse,
|
||||
object_id_t hkDestination);
|
||||
|
||||
/**
|
||||
* This should be called in the periodic handler of the owner.
|
||||
* It performs all the periodic functionalities of the data pool manager.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t performHkOperation();
|
||||
/**
|
||||
* This function is used to set the default HK packet destination.
|
||||
* This destination will usually only be set once.
|
||||
* @param hkDestination
|
||||
*/
|
||||
void setHkPacketDestination(MessageQueueId_t hkDestination);
|
||||
|
||||
/**
|
||||
* Generate a housekeeping packet with a given SID.
|
||||
* @param sid
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t generateHousekeepingPacket(sid_t sid, MessageQueueId_t sendTo
|
||||
= MessageQueueIF::NO_QUEUE);
|
||||
ReturnValue_t generateSetStructurePacket(sid_t sid);
|
||||
|
||||
ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
|
||||
|
||||
/**
|
||||
* This function is used to fill the local data pool map with pool
|
||||
* entries. It should only be called once by the pool owner.
|
||||
* @param localDataPoolMap
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t initializeHousekeepingPoolEntriesOnce();
|
||||
|
||||
const HasLocalDataPoolIF* getOwner() const;
|
||||
|
||||
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
|
||||
|
||||
/**
|
||||
* Different types of housekeeping reporting are possible.
|
||||
* 1. PERIODIC: HK packets are generated in fixed intervals
|
||||
* 2. UPDATED: HK packets are generated if a value was updated
|
||||
* 3. REQUESTED: HK packets are only generated if explicitely requested
|
||||
*/
|
||||
enum class ReportingType: uint8_t {
|
||||
PERIODIC,
|
||||
ON_UPDATE,
|
||||
REQUESTED
|
||||
};
|
||||
|
||||
/* Copying forbidden */
|
||||
LocalDataPoolManager(const LocalDataPoolManager &) = delete;
|
||||
LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete;
|
||||
|
||||
private:
|
||||
LocalDataPool localPoolMap;
|
||||
/** Every housekeeping data manager has a mutex to protect access
|
||||
* to it's data pool. */
|
||||
MutexIF* mutex = nullptr;
|
||||
/** The class which actually owns the manager (and its datapool). */
|
||||
HasLocalDataPoolIF* owner = nullptr;
|
||||
|
||||
/**
|
||||
* The data pool manager will keep an internal map of HK receivers.
|
||||
*/
|
||||
struct HkReceiver {
|
||||
LocalDataSet* dataSet = nullptr;
|
||||
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
|
||||
ReportingType reportingType = ReportingType::PERIODIC;
|
||||
bool reportingStatus = true;
|
||||
/** Different members of this union will be used depending on reporting
|
||||
* type */
|
||||
union hkParameter {
|
||||
/** This parameter will be used for the PERIODIC type */
|
||||
dur_seconds_t collectionInterval = 0;
|
||||
/** This parameter will be used for the ON_UPDATE type */
|
||||
bool hkDataChanged;
|
||||
};
|
||||
};
|
||||
|
||||
/** Using a multimap as the same object might request multiple datasets */
|
||||
using HkReceiversMap = std::multimap<object_id_t, struct HkReceiver>;
|
||||
|
||||
HkReceiversMap hkReceiversMap;
|
||||
|
||||
/** This is the map holding the actual data. Should only be initialized
|
||||
* once ! */
|
||||
bool mapInitialized = false;
|
||||
/** This specifies whether a validity buffer is appended at the end
|
||||
* of generated housekeeping packets. */
|
||||
bool appendValidityBuffer = true;
|
||||
|
||||
/**
|
||||
* @brief Queue used for communication, for example commands.
|
||||
* Is also used to send messages. Can be set either in the constructor
|
||||
* or in the initialize() function.
|
||||
*/
|
||||
MessageQueueIF* hkQueue = nullptr;
|
||||
|
||||
/**
|
||||
* HK replies will always be a reply to the commander, but HK packet
|
||||
* can be sent to another destination by specifying this message queue
|
||||
* ID, for example to a dedicated housekeeping service implementation.
|
||||
*/
|
||||
MessageQueueId_t hkDestination = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
/** Global IPC store is used to store all packets. */
|
||||
StorageManagerIF* ipcStore = nullptr;
|
||||
/**
|
||||
* Get the pointer to the mutex. Can be used to lock the data pool
|
||||
* eternally. Use with care and don't forget to unlock locked mutexes!
|
||||
* For now, only friend classes can accss this function.
|
||||
* @return
|
||||
*/
|
||||
MutexIF* getMutexHandle();
|
||||
|
||||
/**
|
||||
* Read a variable by supplying its local pool ID and assign the pool
|
||||
* entry to the supplied PoolEntry pointer. The type of the pool entry
|
||||
* is deduced automatically. This call is not thread-safe!
|
||||
* For now, only friend classes like LocalPoolVar may access this
|
||||
* function.
|
||||
* @tparam T Type of the pool entry
|
||||
* @param localPoolId Pool ID of the variable to read
|
||||
* @param poolVar [out] Corresponding pool entry will be assigned to the
|
||||
* supplied pointer.
|
||||
* @return
|
||||
*/
|
||||
template <class T> ReturnValue_t fetchPoolEntry(lp_id_t localPoolId,
|
||||
PoolEntry<T> **poolEntry);
|
||||
|
||||
void setMinimalSamplingFrequency(float frequencySeconds);
|
||||
ReturnValue_t serializeHkPacketIntoStore(store_address_t* storeId,
|
||||
LocalDataSet* dataSet);
|
||||
};
|
||||
|
||||
|
||||
template<class T> inline
|
||||
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
|
||||
PoolEntry<T> **poolEntry) {
|
||||
auto poolIter = localPoolMap.find(localPoolId);
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry "
|
||||
"not found." << std::endl;
|
||||
return POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
|
||||
if(*poolEntry == nullptr) {
|
||||
sif::debug << "HousekeepingManager::fetchPoolEntry:"
|
||||
" Pool entry not found." << std::endl;
|
||||
return POOL_ENTRY_TYPE_CONFLICT;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ */
|
106
datapoollocal/LocalDataSet.cpp
Normal file
106
datapoollocal/LocalDataSet.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
||||
#include <framework/datapoollocal/LocalDataSet.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner,
|
||||
const size_t maxNumberOfVariables):
|
||||
DataSetBase(poolVarList.data(), maxNumberOfVariables) {
|
||||
poolVarList.reserve(maxNumberOfVariables);
|
||||
poolVarList.resize(maxNumberOfVariables);
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
}
|
||||
|
||||
LocalDataSet::LocalDataSet(object_id_t ownerId,
|
||||
const size_t maxNumberOfVariables):
|
||||
DataSetBase(poolVarList.data(), maxNumberOfVariables) {
|
||||
poolVarList.reserve(maxNumberOfVariables);
|
||||
poolVarList.resize(maxNumberOfVariables);
|
||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||
ownerId);
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
}
|
||||
|
||||
LocalDataSet::~LocalDataSet() {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::lockDataPool(uint32_t timeoutMs) {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->lockMutex(timeoutMs);
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::serializeWithValidityBuffer(uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||
uint8_t validityMask[validityMaskSize];
|
||||
uint8_t validBufferIndex = 0;
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count]->isValid()) {
|
||||
// set validity buffer here.
|
||||
this->bitSetter(validityMask + validBufferIndex,
|
||||
validBufferIndexBit);
|
||||
if(validBufferIndexBit == 7) {
|
||||
validBufferIndex ++;
|
||||
validBufferIndexBit = 0;
|
||||
}
|
||||
else {
|
||||
validBufferIndexBit ++;
|
||||
}
|
||||
}
|
||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// copy validity buffer to end
|
||||
std::memcpy(*buffer, validityMask, validityMaskSize);
|
||||
*size += validityMaskSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::unlockDataPool() {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->unlockMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::serializeLocalPoolIds(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
|
||||
auto result = SerializeAdapter::serialize(¤tPoolId, buffer,
|
||||
size, maxSize, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "LocalDataSet::serializeLocalPoolIds: Serialization"
|
||||
" error!" << std::endl;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void LocalDataSet::bitSetter(uint8_t* byte, uint8_t position) const {
|
||||
if(position > 7) {
|
||||
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
|
||||
return;
|
||||
}
|
||||
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||
*byte |= 1 << shiftNumber;
|
||||
}
|
||||
|
115
datapoollocal/LocalDataSet.h
Normal file
115
datapoollocal/LocalDataSet.h
Normal file
@ -0,0 +1,115 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||
#include <framework/datapool/DataSetBase.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class LocalDataPoolManager;
|
||||
|
||||
/**
|
||||
* @brief The LocalDataSet class manages a set of locally checked out variables
|
||||
* for local data pools
|
||||
* @details
|
||||
* This class manages a list, where a set of local variables (or pool variables)
|
||||
* are registered. They are checked-out (i.e. their values are looked
|
||||
* up and copied) with the read call. After the user finishes working with the
|
||||
* pool variables, he can write back all variable values to the pool with
|
||||
* the commit call. The data set manages locking and freeing the local data pools,
|
||||
* to ensure thread-safety.
|
||||
*
|
||||
* An internal state manages usage of this class. Variables may only be
|
||||
* registered before the read call is made, and the commit call only
|
||||
* after the read call.
|
||||
*
|
||||
* If pool variables are writable and not committed until destruction
|
||||
* of the set, the DataSet class automatically sets the valid flag in the
|
||||
* data pool to invalid (without) changing the variable's value.
|
||||
*
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class LocalDataSet: public DataSetBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the creator of local pool data.
|
||||
* The constructor simply sets the fill_count to zero and sets
|
||||
* the state to "uninitialized".
|
||||
*/
|
||||
LocalDataSet(HasLocalDataPoolIF *hkOwner,
|
||||
const size_t maxNumberOfVariables);
|
||||
|
||||
/**
|
||||
* @brief Constructor for users of local pool data. The passed pool
|
||||
* owner should implement the HasHkPoolParametersIF.
|
||||
* The constructor simply sets the fill_count to zero and sets
|
||||
* the state to "uninitialized".
|
||||
*/
|
||||
LocalDataSet(object_id_t ownerId,
|
||||
const size_t maxNumberOfVariables);
|
||||
|
||||
/**
|
||||
* @brief The destructor automatically manages writing the valid
|
||||
* information of variables.
|
||||
* @details
|
||||
* In case the data set was read out, but not committed(indicated by state),
|
||||
* the destructor parses all variables that are still registered to the set.
|
||||
* For each, the valid flag in the data pool is set to "invalid".
|
||||
*/
|
||||
~LocalDataSet();
|
||||
|
||||
/**
|
||||
* Special version of the serilization function which appends a
|
||||
* validity buffer at the end. Each bit of this validity buffer
|
||||
* denotes whether the container data set entries are valid from left
|
||||
* to right, MSB first.
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param maxSize
|
||||
* @param bigEndian
|
||||
* @param withValidityBuffer
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const;
|
||||
|
||||
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const;
|
||||
protected:
|
||||
private:
|
||||
/**
|
||||
* If the valid state of a dataset is always relevant to the whole
|
||||
* data set we can use this flag.
|
||||
*/
|
||||
bool valid = false;
|
||||
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate locking
|
||||
* the global data pool.
|
||||
* @details
|
||||
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate
|
||||
* unlocking the global data pool
|
||||
* @details
|
||||
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
LocalDataPoolManager* hkManager;
|
||||
|
||||
/**
|
||||
* Set n-th bit of a byte, with n being the position from 0
|
||||
* (most significant bit) to 7 (least significant bit)
|
||||
*/
|
||||
void bitSetter(uint8_t* byte, uint8_t position) const;
|
||||
|
||||
std::vector<PoolVariableIF*> poolVarList;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */
|
173
datapoollocal/LocalPoolVariable.h
Normal file
173
datapoollocal/LocalPoolVariable.h
Normal file
@ -0,0 +1,173 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
/**
|
||||
* @brief Local Pool Variable class which is used to access the local pools.
|
||||
* @details
|
||||
* This class is not stored in the map. Instead, it is used to access
|
||||
* the pool entries by using a pointer to the map storing the pool
|
||||
* entries. It can also be used to organize these pool entries into data sets.
|
||||
*
|
||||
* @tparam T The template parameter sets the type of the variable. Currently,
|
||||
* all plain data types are supported, but in principle any type is possible.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalPoolVar: public PoolVariableIF, HasReturnvaluesIF {
|
||||
public:
|
||||
//! Default ctor is forbidden.
|
||||
LocalPoolVar() = delete;
|
||||
|
||||
/**
|
||||
* This constructor is used by the data creators to have pool variable
|
||||
* instances which can also be stored in datasets.
|
||||
*
|
||||
* It does not fetch the current value from the data pool, which
|
||||
* has to be done by calling the read() operation.
|
||||
* Datasets can be used to access multiple local pool entries in an
|
||||
* efficient way. A pointer to a dataset can be passed to register
|
||||
* the pool variable in that dataset directly.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||
* class itself which passes "this".
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
/**
|
||||
* This constructor is used by data users like controllers to have
|
||||
* access to the local pool variables of data creators by supplying
|
||||
* the respective creator object ID.
|
||||
*
|
||||
* It does not fetch the current value from the data pool, which
|
||||
* has to be done by calling the read() operation.
|
||||
* Datasets can be used to access multiple local pool entries in an
|
||||
* efficient way. A pointer to a dataset can be passed to register
|
||||
* the pool variable in that dataset directly.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner object ID of the pool owner.
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
virtual~ LocalPoolVar() {};
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details The user can work on this attribute
|
||||
* just like he would on a simple local variable.
|
||||
*/
|
||||
T value = 0;
|
||||
|
||||
pool_rwm_t getReadWriteMode() const override;
|
||||
|
||||
lp_id_t getDataPoolId() const override;
|
||||
void setDataPoolId(lp_id_t poolId);
|
||||
|
||||
bool isValid() const override;
|
||||
void setValid(bool validity) override;
|
||||
uint8_t getValid() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the array's values
|
||||
* from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the data pool and copies all array values and the valid
|
||||
* information to its local attributes.
|
||||
* In case of a failure (wrong type, size or pool id not found), the
|
||||
* variable is set to zero and invalid.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t read(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the local valid flag is written back as well.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
// std::ostream is the type for object std::cout
|
||||
template <typename U>
|
||||
friend std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVar<U> &var);
|
||||
|
||||
private:
|
||||
//! @brief Pool ID of pool entry inside the used local pool.
|
||||
lp_id_t localPoolId = PoolVariableIF::NO_PARAMETER;
|
||||
//! @brief Read-write mode of the pool variable
|
||||
pool_rwm_t readWriteMode = pool_rwm_t::VAR_READ_WRITE;
|
||||
//! @brief Specifies whether the entry is valid or invalid.
|
||||
bool valid = false;
|
||||
|
||||
//! Pointer to the class which manages the HK pool.
|
||||
LocalDataPoolManager* hkManager;
|
||||
};
|
||||
|
||||
#include <framework/datapoollocal/LocalPoolVariable.tpp>
|
||||
|
||||
template<class T>
|
||||
using lp_var_t = LocalPoolVar<T>;
|
||||
|
||||
using lp_bool_t = LocalPoolVar<uint8_t>;
|
||||
using lp_uint8_t = LocalPoolVar<uint8_t>;
|
||||
using lp_uint16_t = LocalPoolVar<uint16_t>;
|
||||
using lp_uint32_t = LocalPoolVar<uint32_t>;
|
||||
using lp_uint64_t = LocalPoolVar<uint64_t>;
|
||||
using lp_int8_t = LocalPoolVar<int8_t>;
|
||||
using lp_int16_t = LocalPoolVar<int16_t>;
|
||||
using lp_int32_t = LocalPoolVar<int32_t>;
|
||||
using lp_int64_t = LocalPoolVar<int64_t>;
|
||||
using lp_float_t = LocalPoolVar<float>;
|
||||
using lp_double_t = LocalPoolVar<double>;
|
||||
|
||||
#endif
|
159
datapoollocal/LocalPoolVariable.tpp
Normal file
159
datapoollocal/LocalPoolVariable.tpp
Normal file
@ -0,0 +1,159 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
|
||||
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||
#error Include LocalPoolVariable.h before LocalPoolVariable.tpp!
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId,
|
||||
HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode,
|
||||
DataSetIF* dataSet):
|
||||
localPoolId(poolId),readWriteMode(setReadWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
|
||||
"NO_PARAMETER value!" << std::endl;
|
||||
}
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalPoolVariable: The supplied pool owner is a nullptr!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF *dataSet):
|
||||
readWriteMode(readWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
|
||||
"NO_PARAMETER value!" << std::endl;
|
||||
}
|
||||
HasLocalDataPoolIF* hkOwner =
|
||||
objectManager->get<HasLocalDataPoolIF>(poolOwner);
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
|
||||
"the correct interface HasHkPoolParametersIF!" << std::endl;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
|
||||
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
|
||||
return readWithoutLock();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for read() call." << std::endl;
|
||||
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||
}
|
||||
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||
if(result != RETURN_OK and poolEntry != nullptr) {
|
||||
sif::error << "PoolVector: Read of local pool variable of object "
|
||||
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||
std::dec << " failed.\n" << std::flush;
|
||||
return result;
|
||||
}
|
||||
this->value = *(poolEntry->address);
|
||||
this->valid = poolEntry->valid;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
|
||||
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
|
||||
return commitWithoutLock();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for commit() call." << std::endl;
|
||||
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||
}
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||
if(result != RETURN_OK) {
|
||||
sif::error << "PoolVector: Read of local pool variable of object "
|
||||
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||
std::dec << " failed.\n" << std::flush;
|
||||
return result;
|
||||
}
|
||||
*(poolEntry->address) = this->value;
|
||||
poolEntry->valid = this->valid;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline pool_rwm_t LocalPoolVar<T>::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline lp_id_t LocalPoolVar<T>::getDataPoolId() const {
|
||||
return localPoolId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void LocalPoolVar<T>::setDataPoolId(lp_id_t poolId) {
|
||||
this->localPoolId = poolId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool LocalPoolVar<T>::isValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void LocalPoolVar<T>::setValid(bool validity) {
|
||||
this->valid = validity;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline uint8_t LocalPoolVar<T>::getValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, SerializeIF::Endianness streamEndianness) const {
|
||||
return SerializeAdapter::serialize(&value,
|
||||
buffer, size ,max_size, streamEndianness);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t LocalPoolVar<T>::getSerializedSize() const {
|
||||
return SerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::deSerialize(const uint8_t** buffer,
|
||||
size_t* size, SerializeIF::Endianness streamEndianness) {
|
||||
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVar<T> &var) {
|
||||
out << var.value;
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif
|
200
datapoollocal/LocalPoolVector.h
Normal file
200
datapoollocal/LocalPoolVector.h
Normal file
@ -0,0 +1,200 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief This is the access class for array-type data pool entries.
|
||||
* @details
|
||||
* To ensure safe usage of the data pool, operation is not done directly on the
|
||||
* data pool entries, but on local copies. This class provides simple type-
|
||||
* and length-safe access to vector-style data pool entries (i.e. entries with
|
||||
* length > 1). The class can be instantiated as read-write and read only.
|
||||
*
|
||||
* It provides a commit-and-roll-back semantic, which means that no array
|
||||
* entry in the data pool is changed until the commit call is executed.
|
||||
* There are two template parameters:
|
||||
* @tparam T
|
||||
* This template parameter specifies the data type of an array entry. Currently,
|
||||
* all plain data types are supported, but in principle any type is possible.
|
||||
* @tparam vector_size
|
||||
* This template parameter specifies the vector size of this entry. Using a
|
||||
* template parameter for this is not perfect, but avoids
|
||||
* dynamic memory allocation.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T, uint16_t vectorSize>
|
||||
class LocalPoolVector: public PoolVariableIF, public HasReturnvaluesIF {
|
||||
public:
|
||||
LocalPoolVector() = delete;
|
||||
/**
|
||||
* This constructor is used by the data creators to have pool variable
|
||||
* instances which can also be stored in datasets.
|
||||
* It does not fetch the current value from the data pool. This is performed
|
||||
* by the read() operation (which is not thread-safe).
|
||||
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||
* class itself which passes "this".
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
/**
|
||||
* This constructor is used by data users like controllers to have
|
||||
* access to the local pool variables of data creators by supplying
|
||||
* the respective creator object ID.
|
||||
* It does not fetch the current value from the data pool. This is performed
|
||||
* by the read() operation (which is not thread-safe).
|
||||
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||
* class itself which passes "this".
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVector(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details
|
||||
* The user can work on this attribute just like he would on a local
|
||||
* array of this type.
|
||||
*/
|
||||
T value[vectorSize];
|
||||
/**
|
||||
* @brief The classes destructor is empty.
|
||||
* @details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~LocalPoolVector() {};
|
||||
/**
|
||||
* @brief The operation returns the number of array entries
|
||||
* in this variable.
|
||||
*/
|
||||
uint8_t getSize() {
|
||||
return vectorSize;
|
||||
}
|
||||
|
||||
uint32_t getDataPoolId() const override;
|
||||
/**
|
||||
* @brief This operation sets the data pool ID of the variable.
|
||||
* @details
|
||||
* The method is necessary to set id's of data pool member variables
|
||||
* with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId);
|
||||
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
pool_rwm_t getReadWriteMode() const;
|
||||
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const override;
|
||||
void setValid(bool valid) override;
|
||||
uint8_t getValid() const;
|
||||
|
||||
T& operator [](int i);
|
||||
const T &operator [](int i) const;
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize,
|
||||
SerializeIF::Endianness streamEndiannes) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the array's values
|
||||
* from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the data pool and copies all array values and the valid
|
||||
* information to its local attributes.
|
||||
* In case of a failure (wrong type, size or pool id not found), the
|
||||
* variable is set to zero and invalid.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the local valid flag is written back as well.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool id is stored.
|
||||
*/
|
||||
uint32_t localPoolId;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool
|
||||
* is copied to this attribute.
|
||||
*/
|
||||
bool valid;
|
||||
/**
|
||||
* @brief The information whether the class is read-write or
|
||||
* read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
//! @brief Pointer to the class which manages the HK pool.
|
||||
LocalDataPoolManager* hkManager;
|
||||
|
||||
// std::ostream is the type for object std::cout
|
||||
template <typename U, uint16_t otherSize>
|
||||
friend std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVector<U, otherSize> &var);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#include <framework/datapoollocal/LocalPoolVector.tpp>
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
using lp_vec_t = LocalPoolVector<T, vectorSize>;
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ */
|
206
datapoollocal/LocalPoolVector.tpp
Normal file
206
datapoollocal/LocalPoolVector.tpp
Normal file
@ -0,0 +1,206 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_
|
||||
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||
#error Include LocalPoolVector.h before LocalPoolVector.tpp!
|
||||
#endif
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId,
|
||||
HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode,
|
||||
DataSetIF* dataSet) :
|
||||
localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
|
||||
"NO_PARAMETER value!" << std::endl;
|
||||
}
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId,
|
||||
object_id_t poolOwner, pool_rwm_t setReadWriteMode, DataSetIF *dataSet):
|
||||
readWriteMode(readWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
|
||||
"NO_PARAMETER value!" << std::endl;
|
||||
}
|
||||
HasLocalDataPoolIF* hkOwner =
|
||||
objectManager->get<HasLocalDataPoolIF>(poolOwner);
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
|
||||
"the correct interface HasHkPoolParametersIF!" << std::endl;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
||||
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
|
||||
return readWithoutLock();
|
||||
}
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for read() call." << std::endl;
|
||||
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||
}
|
||||
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
|
||||
if(result != RETURN_OK) {
|
||||
sif::error << "PoolVector: Read of local pool variable of object "
|
||||
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
hkManager->getOwner() << "and lp ID 0x" << localPoolId <<
|
||||
std::dec << " failed." << std::endl;
|
||||
return result;
|
||||
}
|
||||
memcpy(this->value, poolEntry->address, poolEntry->getByteSize());
|
||||
this->valid = poolEntry->valid;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(
|
||||
uint32_t lockTimeout) {
|
||||
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
|
||||
return commitWithoutLock();
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for commit() call." << std::endl;
|
||||
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||
}
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||
if(result != RETURN_OK) {
|
||||
sif::error << "PoolVector: Read of local pool variable of object "
|
||||
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||
std::dec << " failed.\n" << std::flush;
|
||||
return result;
|
||||
}
|
||||
memcpy(poolEntry->address, this->value, poolEntry->getByteSize());
|
||||
poolEntry->valid = this->valid;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline T& LocalPoolVector<T, vectorSize>::operator [](int i) {
|
||||
if(i <= vectorSize) {
|
||||
return value[i];
|
||||
}
|
||||
// If this happens, I have to set some value. I consider this
|
||||
// a configuration error, but I wont exit here.
|
||||
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!" << std::endl;
|
||||
return value[i];
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline const T& LocalPoolVector<T, vectorSize>::operator [](int i) const {
|
||||
if(i <= vectorSize) {
|
||||
return value[i];
|
||||
}
|
||||
// If this happens, I have to set some value. I consider this
|
||||
// a configuration error, but I wont exit here.
|
||||
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!" << std::endl;
|
||||
return value[i];
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline size_t LocalPoolVector<T, vectorSize>::getSerializedSize() const {
|
||||
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t LocalPoolVector<T, vectorSize>::deSerialize(
|
||||
const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline pool_rwm_t LocalPoolVector<T, vectorSize>::getReadWriteMode() const {
|
||||
return this->readWriteMode;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline uint32_t LocalPoolVector<T, vectorSize>::getDataPoolId() const {
|
||||
return localPoolId;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline void LocalPoolVector<T, vectorSize>::setDataPoolId(uint32_t poolId) {
|
||||
this->localPoolId = poolId;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline void LocalPoolVector<T, vectorSize>::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline uint8_t LocalPoolVector<T, vectorSize>::getValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline bool LocalPoolVector<T, vectorSize>::isValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVector<T, vectorSize> &var) {
|
||||
out << "Vector: [";
|
||||
for(int i = 0;i < vectorSize; i++) {
|
||||
out << var.value[i];
|
||||
if(i < vectorSize - 1) {
|
||||
out << ", ";
|
||||
}
|
||||
}
|
||||
out << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif
|
6
datapoollocal/StaticLocalDataSet.cpp
Normal file
6
datapoollocal/StaticLocalDataSet.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include <framework/datapoollocal/StaticLocalDataSet.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
11
datapoollocal/StaticLocalDataSet.h
Normal file
11
datapoollocal/StaticLocalDataSet.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_
|
||||
#include <framework/datapool/DataSetBase.h>
|
||||
|
||||
|
||||
class StaticLocalDataSet: public DataSetBase {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_ */
|
@ -1,23 +1,19 @@
|
||||
/**
|
||||
* @file AcceptsDeviceResponsesIF.h
|
||||
* @brief This file defines the AcceptsDeviceResponsesIF class.
|
||||
* @date 15.05.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef ACCEPTSDEVICERESPONSESIF_H_
|
||||
#define ACCEPTSDEVICERESPONSESIF_H_
|
||||
#ifndef FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
|
||||
#define FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
|
||||
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
/**
|
||||
* This interface is used by the device handler to send a device response
|
||||
* to the queue ID, which is returned in the implemented abstract method.
|
||||
*/
|
||||
class AcceptsDeviceResponsesIF {
|
||||
public:
|
||||
/**
|
||||
* Default empty virtual destructor.
|
||||
*/
|
||||
virtual ~AcceptsDeviceResponsesIF() {
|
||||
}
|
||||
virtual MessageQueueId_t getDeviceQueue() = 0;
|
||||
virtual ~AcceptsDeviceResponsesIF() {}
|
||||
virtual MessageQueueId_t getDeviceQueue() = 0;
|
||||
};
|
||||
|
||||
#endif /* ACCEPTSDEVICERESPONSESIF_H_ */
|
||||
#endif /* FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
|
||||
uint16_t commandQueueDepth) :
|
||||
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth), internalState(
|
||||
STATE_NONE), recoveryState(RECOVERY_IDLE), recoveringDevice(
|
||||
childrenMap.end()), targetMode(MODE_OFF), targetSubmode(
|
||||
SUBMODE_NONE) {
|
||||
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth),
|
||||
internalState(STATE_NONE), recoveryState(RECOVERY_IDLE),
|
||||
recoveringDevice(childrenMap.end()), targetMode(MODE_OFF),
|
||||
targetSubmode(SUBMODE_NONE) {
|
||||
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
|
||||
}
|
||||
|
||||
|
@ -3,15 +3,19 @@
|
||||
#include <framework/subsystem/SubsystemBase.h>
|
||||
|
||||
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
|
||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId, uint32_t parent,
|
||||
object_id_t deviceCommunication, CookieIF * cookie,
|
||||
object_id_t hkDestination, uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId,
|
||||
object_id_t parent,
|
||||
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
|
||||
DeviceHandlerBase(setObjectId, deviceCommunication, comCookie,
|
||||
setDeviceSwitch, thermalStatePoolId,thermalRequestPoolId,
|
||||
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
||||
cmdQueueSize),
|
||||
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
|
||||
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
||||
cmdQueueSize),
|
||||
parentId(parent), childHandlerFdir(setObjectId) {
|
||||
this->setHkDestination(hkDestination);
|
||||
this->setThermalStateRequestPoolIds(thermalStatePoolId,
|
||||
thermalRequestPoolId);
|
||||
|
||||
}
|
||||
|
||||
ChildHandlerBase::~ChildHandlerBase() {
|
||||
@ -25,7 +29,7 @@ ReturnValue_t ChildHandlerBase::initialize() {
|
||||
|
||||
MessageQueueId_t parentQueue = 0;
|
||||
|
||||
if (parentId != 0) {
|
||||
if (parentId != objects::NO_OBJECT) {
|
||||
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
||||
if (parent == NULL) {
|
||||
return RETURN_FAILED;
|
||||
|
@ -6,12 +6,11 @@
|
||||
|
||||
class ChildHandlerBase: public DeviceHandlerBase {
|
||||
public:
|
||||
ChildHandlerBase(object_id_t setObjectId,
|
||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId, uint32_t parent,
|
||||
FailureIsolationBase* customFdir = nullptr,
|
||||
size_t cmdQueueSize = 20);
|
||||
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||
CookieIF * cookie, object_id_t hkDestination,
|
||||
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
|
||||
object_id_t parent = objects::NO_OBJECT,
|
||||
FailureIsolationBase* customFdir = nullptr, size_t cmdQueueSize = 20);
|
||||
virtual ~ChildHandlerBase();
|
||||
|
||||
virtual ReturnValue_t initialize();
|
||||
|
201
devicehandlers/CommunicationMessage.cpp
Normal file
201
devicehandlers/CommunicationMessage.cpp
Normal file
@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @file CommunicationMessage.cpp
|
||||
*
|
||||
* @date 28.02.2020
|
||||
*/
|
||||
|
||||
#include <framework/devicehandlers/CommunicationMessage.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <cstring>
|
||||
|
||||
CommunicationMessage::CommunicationMessage(): uninitialized(true) {
|
||||
}
|
||||
|
||||
CommunicationMessage::~CommunicationMessage() {}
|
||||
|
||||
void CommunicationMessage::setSendRequestFromPointer(uint32_t address,
|
||||
uint32_t dataLen, const uint8_t * data) {
|
||||
setMessageType(SEND_DATA_FROM_POINTER);
|
||||
setAddress(address);
|
||||
setDataLen(dataLen);
|
||||
setDataPointer(data);
|
||||
}
|
||||
|
||||
void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) {
|
||||
setMessageType(SEND_DATA_FROM_IPC_STORE);
|
||||
setAddress(address);
|
||||
setStoreId(storeId.raw);
|
||||
}
|
||||
|
||||
void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length,
|
||||
uint16_t sendBufferPosition) {
|
||||
setMessageType(SEND_DATA_RAW);
|
||||
setAddress(address);
|
||||
setDataLen(length);
|
||||
if(sendBufferPosition != 0) {
|
||||
setBufferPosition(sendBufferPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) {
|
||||
setMessageType(REPLY_DATA_IPC_STORE);
|
||||
setAddress(address);
|
||||
setStoreId(storeId.raw);
|
||||
}
|
||||
void CommunicationMessage::setDataReplyFromPointer(uint32_t address,
|
||||
uint32_t dataLen, uint8_t *data) {
|
||||
setMessageType(REPLY_DATA_FROM_POINTER);
|
||||
setAddress(address);
|
||||
setDataLen(dataLen);
|
||||
setDataPointer(data);
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataReplyRaw(uint32_t address,
|
||||
uint32_t length, uint16_t receiveBufferPosition) {
|
||||
setMessageType(REPLY_DATA_RAW);
|
||||
setAddress(address);
|
||||
setDataLen(length);
|
||||
if(receiveBufferPosition != 0) {
|
||||
setBufferPosition(receiveBufferPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void CommunicationMessage::setMessageType(messageType status) {
|
||||
uint8_t status_uint8 = status;
|
||||
memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8));
|
||||
}
|
||||
|
||||
void CommunicationMessage::setAddress(address_t address) {
|
||||
memcpy(getData(),&address,sizeof(address));
|
||||
}
|
||||
|
||||
address_t CommunicationMessage::getAddress() const {
|
||||
address_t address;
|
||||
memcpy(&address,getData(),sizeof(address));
|
||||
return address;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setBufferPosition(uint16_t bufferPosition) {
|
||||
memcpy(getData() + sizeof(uint32_t) + sizeof(uint16_t),
|
||||
&bufferPosition, sizeof(bufferPosition));
|
||||
}
|
||||
|
||||
uint16_t CommunicationMessage::getBufferPosition() const {
|
||||
uint16_t bufferPosition;
|
||||
memcpy(&bufferPosition,
|
||||
getData() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(bufferPosition));
|
||||
return bufferPosition;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataPointer(const void * data) {
|
||||
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void CommunicationMessage::setStoreId(store_address_t storeId) {
|
||||
memcpy(getData() + 2 * sizeof(uint32_t), &storeId.raw, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
store_address_t CommunicationMessage::getStoreId() const{
|
||||
store_address_t temp;
|
||||
memcpy(&temp.raw,getData() + 2 * sizeof(uint32_t), sizeof(uint32_t));
|
||||
return temp;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataLen(uint32_t length) {
|
||||
memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length));
|
||||
}
|
||||
|
||||
uint32_t CommunicationMessage::getDataLen() const {
|
||||
uint32_t len;
|
||||
memcpy(&len, getData() + 2 * sizeof(uint32_t), sizeof(len));
|
||||
return len;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setUint32Data(uint32_t data) {
|
||||
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data));
|
||||
}
|
||||
|
||||
uint32_t CommunicationMessage::getUint32Data() const{
|
||||
uint32_t data;
|
||||
memcpy(&data,getData() + 3 * sizeof(uint32_t), sizeof(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataByte(uint8_t byte, uint8_t position) {
|
||||
if(0 <= position && position <= 3) {
|
||||
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), &byte, sizeof(byte));
|
||||
}
|
||||
else {
|
||||
sif::error << "Comm Message: Invalid byte position" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CommunicationMessage::getDataByte(uint8_t position) const {
|
||||
if(0 <= position && position <= 3) {
|
||||
uint8_t byte;
|
||||
memcpy(&byte, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), sizeof(byte));
|
||||
return byte;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
sif::error << "Comm Message: Invalid byte position" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CommunicationMessage::setDataUint16(uint16_t data, uint8_t position) {
|
||||
if(position == 0 || position == 1) {
|
||||
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), &data, sizeof(data));
|
||||
}
|
||||
else {
|
||||
sif::error << "Comm Message: Invalid byte position" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint16_t CommunicationMessage::getDataUint16(uint8_t position) const{
|
||||
if(position == 0 || position == 1) {
|
||||
uint16_t data;
|
||||
memcpy(&data, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), sizeof(data));
|
||||
return data;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
sif::error << "Comm Message: Invalid byte position" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
CommunicationMessage::messageType CommunicationMessage::getMessageType() const{
|
||||
messageType messageType;
|
||||
memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t));
|
||||
return messageType;
|
||||
}
|
||||
|
||||
void CommunicationMessage::setMessageId(uint8_t messageId) {
|
||||
memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), &messageId, sizeof(messageId));
|
||||
}
|
||||
|
||||
uint8_t CommunicationMessage::getMessageId() const {
|
||||
uint8_t messageId;
|
||||
memcpy(&messageId, getData() + sizeof(uint32_t) + sizeof(uint8_t), sizeof(messageId));
|
||||
return messageId;
|
||||
}
|
||||
|
||||
void CommunicationMessage::clearCommunicationMessage() {
|
||||
messageType messageType = getMessageType();
|
||||
switch(messageType) {
|
||||
case(messageType::REPLY_DATA_IPC_STORE):
|
||||
case(messageType::SEND_DATA_FROM_IPC_STORE): {
|
||||
store_address_t storeId = getStoreId();
|
||||
StorageManagerIF *ipcStore = objectManager->
|
||||
get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore != NULL) {
|
||||
ipcStore->deleteData(storeId);
|
||||
}
|
||||
}
|
||||
/* NO BREAK falls through*/
|
||||
default:
|
||||
memset(getData(),0,4*sizeof(uint32_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
173
devicehandlers/CommunicationMessage.h
Normal file
173
devicehandlers/CommunicationMessage.h
Normal file
@ -0,0 +1,173 @@
|
||||
/**
|
||||
* @file CommunicationMessage.h
|
||||
*
|
||||
* @date 28.02.2020
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
|
||||
#define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
|
||||
#include <framework/devicehandlers/CommunicationMessage.h>
|
||||
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerBase.h>
|
||||
|
||||
/**
|
||||
* @brief Message type to send larger messages
|
||||
*
|
||||
* @details
|
||||
* Can be used to pass information like data pointers and
|
||||
* data sizes between communication tasks.
|
||||
*
|
||||
*/
|
||||
class CommunicationMessage: public MessageQueueMessage {
|
||||
public:
|
||||
enum messageType {
|
||||
NONE,
|
||||
SEND_DATA_FROM_POINTER,
|
||||
SEND_DATA_FROM_IPC_STORE,
|
||||
SEND_DATA_RAW,
|
||||
REPLY_DATA_FROM_POINTER,
|
||||
REPLY_DATA_IPC_STORE,
|
||||
REPLY_DATA_RAW,
|
||||
FAULTY,
|
||||
};
|
||||
|
||||
//Add other messageIDs here if necessary.
|
||||
static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t);
|
||||
|
||||
CommunicationMessage();
|
||||
virtual ~CommunicationMessage();
|
||||
|
||||
/**
|
||||
* Message Type is stored as the fifth byte of the message data
|
||||
* @param status
|
||||
*/
|
||||
void setMessageType(messageType status);
|
||||
messageType getMessageType() const;
|
||||
|
||||
/**
|
||||
* This is a unique ID which can be used to handle different kinds of messages.
|
||||
* For example, the same interface (e.g. SPI) could be used to exchange raw data
|
||||
* (e.g. sensor values) and data stored in the IPC store.
|
||||
* The ID can be used to distinguish the messages in child implementations.
|
||||
* The message ID is stored as the sixth byte of the message data.
|
||||
* @param messageId
|
||||
*/
|
||||
void setMessageId(uint8_t messageId);
|
||||
uint8_t getMessageId() const;
|
||||
|
||||
/**
|
||||
* Send requests with pointer to the data to be sent and send data length
|
||||
* @param address Target Address, first four bytes
|
||||
* @param dataLen Length of data to send, next four bytes
|
||||
* @param data Pointer to data to send
|
||||
*
|
||||
*/
|
||||
void setSendRequestFromPointer(uint32_t address, uint32_t dataLen, const uint8_t * data);
|
||||
|
||||
/**
|
||||
* Send requests with a store ID, using the IPC store
|
||||
* @param address Target Address, first four bytes
|
||||
* @param storeId Store ID in the IPC store
|
||||
*
|
||||
*/
|
||||
void setSendRequestFromIpcStore(uint32_t address, store_address_t storeId);
|
||||
|
||||
/**
|
||||
* Send requests with data length and data in message (max. 4 bytes)
|
||||
* @param address Target Address, first four bytes
|
||||
* @param dataLen Length of data to send, next four bytes
|
||||
* @param data Pointer to data to send
|
||||
*
|
||||
*/
|
||||
void setSendRequestRaw(uint32_t address, uint32_t length,
|
||||
uint16_t sendBufferPosition = 0);
|
||||
|
||||
/**
|
||||
* Data message with data stored in IPC store
|
||||
* @param address Target Address, first four bytes
|
||||
* @param length
|
||||
* @param storeId
|
||||
*/
|
||||
void setDataReplyFromIpcStore(uint32_t address, store_address_t storeId);
|
||||
|
||||
/**
|
||||
* Data reply with data stored in buffer, passing the pointer to
|
||||
* the buffer and the data size
|
||||
* @param address Target Address, first four bytes
|
||||
* @param dataLen Length of data to send, next four bytes
|
||||
* @param data Pointer to the data
|
||||
*/
|
||||
void setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t * data);
|
||||
|
||||
/**
|
||||
* Data message with data stored in actual message.
|
||||
* 4 byte datafield is intialized with 0.
|
||||
* Set data with specific setter functions below.
|
||||
* Can also be used to supply information at which position the raw data should be stored
|
||||
* in a receive buffer.
|
||||
*/
|
||||
void setDataReplyRaw(uint32_t address, uint32_t length, uint16_t receiveBufferPosition = 0);
|
||||
|
||||
/**
|
||||
* First four bytes of message data
|
||||
* @param address
|
||||
*/
|
||||
void setAddress(address_t address);
|
||||
|
||||
address_t getAddress() const;
|
||||
/**
|
||||
* Set byte as position of 4 byte data field
|
||||
* @param byte
|
||||
* @param position Position, 0 to 3 possible
|
||||
*/
|
||||
void setDataByte(uint8_t byte, uint8_t position);
|
||||
uint8_t getDataByte(uint8_t position) const;
|
||||
|
||||
/**
|
||||
* Set 2 byte value at position 1 or 2 of data field
|
||||
* @param data
|
||||
* @param position 0 or 1 possible
|
||||
*/
|
||||
void setDataUint16(uint16_t data, uint8_t position);
|
||||
uint16_t getDataUint16(uint8_t position) const;
|
||||
|
||||
void setUint32Data(uint32_t data);
|
||||
uint32_t getUint32Data() const;
|
||||
|
||||
/**
|
||||
* Stored in Bytes 13-16 of message data
|
||||
* @param length
|
||||
*/
|
||||
void setDataLen(uint32_t length);
|
||||
|
||||
uint32_t getDataLen() const;
|
||||
|
||||
/**
|
||||
* Stored in last four bytes (Bytes 17-20) of message data
|
||||
* @param sendData
|
||||
*/
|
||||
void setDataPointer(const void * data);
|
||||
|
||||
/**
|
||||
* In case the send request data or reply data is to be stored in a buffer,
|
||||
* a buffer Position can be stored here as the seventh and eigth byte of
|
||||
* the message, so the receive buffer can't be larger than sizeof(uint16_t) for now.
|
||||
* @param bufferPosition In case the data is stored in a buffer, the position can be supplied here
|
||||
*/
|
||||
void setBufferPosition(uint16_t bufferPosition);
|
||||
uint16_t getBufferPosition() const;
|
||||
void setStoreId(store_address_t storeId);
|
||||
store_address_t getStoreId() const;
|
||||
|
||||
/**
|
||||
* Clear the message. Deletes IPC Store data
|
||||
* and sets all data to 0. Also sets message type to NONE
|
||||
*/
|
||||
void clearCommunicationMessage();
|
||||
private:
|
||||
bool uninitialized; //!< Could be used to warn if data has not been set.
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */
|
@ -16,7 +16,6 @@ typedef std::uint32_t address_t;
|
||||
* calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...)
|
||||
* @endcode .
|
||||
*
|
||||
* [not implemented yet]
|
||||
* This cookie is then passed to the child device handlers, which stores the
|
||||
* pointer and passes it to the communication interface functions.
|
||||
*
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef DEVICECOMMUNICATIONIF_H_
|
||||
#define DEVICECOMMUNICATIONIF_H_
|
||||
#ifndef FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||
#define FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||
|
||||
#include <framework/devicehandlers/CookieIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <cstddef>
|
||||
/**
|
||||
* @defgroup interfaces Interfaces
|
||||
* @brief Interfaces for flight software objects
|
||||
@ -19,8 +19,8 @@
|
||||
* the device handler to allow reuse of these components.
|
||||
* @details
|
||||
* Documentation: Dissertation Baetz p.138.
|
||||
* It works with the assumption that received data
|
||||
* is polled by a component. There are four generic steps of device communication:
|
||||
* It works with the assumption that received data is polled by a component.
|
||||
* There are four generic steps of device communication:
|
||||
*
|
||||
* 1. Send data to a device
|
||||
* 2. Get acknowledgement for sending
|
||||
@ -38,24 +38,20 @@ class DeviceCommunicationIF: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
|
||||
|
||||
//! Standard Error Codes
|
||||
//! This is returned in readReceivedMessage() if no reply was reived.
|
||||
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
//! General protocol error. Define more concrete errors in child handler
|
||||
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
|
||||
//! If cookie is a null pointer
|
||||
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04);
|
||||
// is this needed if there is no open/close call?
|
||||
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
|
||||
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0x06);
|
||||
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x07);
|
||||
static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x08);
|
||||
|
||||
//! Can be used in readReceivedMessage() if no reply was received.
|
||||
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0xA1);
|
||||
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
|
||||
|
||||
virtual ~DeviceCommunicationIF() {}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Device specific initialization, using the cookie.
|
||||
* @details
|
||||
@ -76,13 +72,13 @@ public:
|
||||
* by implementing and calling related drivers or wrapper functions.
|
||||
* @param cookie
|
||||
* @param data
|
||||
* @param len
|
||||
* @param len If this is 0, nothing shall be sent.
|
||||
* @return
|
||||
* - @c RETURN_OK for successfull send
|
||||
* - Everything else triggers failure event with returnvalue as parameter 1
|
||||
*/
|
||||
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
|
||||
size_t sendLen) = 0;
|
||||
virtual ReturnValue_t sendMessage(CookieIF *cookie,
|
||||
const uint8_t * sendData, size_t sendLen) = 0;
|
||||
|
||||
/**
|
||||
* Called by DHB in the GET_WRITE doGetWrite().
|
||||
@ -108,7 +104,7 @@ public:
|
||||
* returnvalue as parameter 1
|
||||
*/
|
||||
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) = 0;
|
||||
size_t requestLen) = 0;
|
||||
|
||||
/**
|
||||
* Called by DHB in the GET_WRITE doGetRead().
|
||||
@ -124,8 +120,8 @@ public:
|
||||
* - Everything else triggers failure event with
|
||||
* returnvalue as parameter 1
|
||||
*/
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) = 0;
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t *size) = 0;
|
||||
};
|
||||
|
||||
#endif /* DEVICECOMMUNICATIONIF_H_ */
|
||||
|
@ -4,55 +4,65 @@
|
||||
#include <framework/thermal/ThermalComponentIF.h>
|
||||
#include <framework/devicehandlers/AcceptsDeviceResponsesIF.h>
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/GlobalPoolVariable.h>
|
||||
#include <framework/devicehandlers/DeviceTmReportingWrapper.h>
|
||||
#include <framework/globalfunctions/CRC.h>
|
||||
#include <framework/housekeeping/HousekeepingMessage.h>
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/subsystem/SubsystemBase.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
object_id_t DeviceHandlerBase::powerSwitcherId = 0;
|
||||
object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
|
||||
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
|
||||
object_id_t DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
|
||||
object_id_t DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
|
||||
object_id_t DeviceHandlerBase::defaultFdirParentId = objects::NO_OBJECT;
|
||||
object_id_t DeviceHandlerBase::defaultHkDestination = objects::NO_OBJECT;
|
||||
|
||||
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance,
|
||||
size_t cmdQueueSize) :
|
||||
FailureIsolationBase* fdirInstance, size_t cmdQueueSize) :
|
||||
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
|
||||
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
||||
deviceCommunicationId(deviceCommunication), comCookie(comCookie),
|
||||
deviceThermalStatePoolId(thermalStatePoolId),
|
||||
deviceThermalRequestPoolId(thermalRequestPoolId),
|
||||
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
||||
actionHelper(this, nullptr), hkManager(this, nullptr),
|
||||
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
|
||||
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
|
||||
switchOffWasReported(false), actionHelper(this, nullptr),
|
||||
childTransitionDelay(5000),
|
||||
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(
|
||||
SUBMODE_NONE), deviceSwitch(setDeviceSwitch) {
|
||||
switchOffWasReported(false), childTransitionDelay(5000),
|
||||
transitionSourceMode(_MODE_POWER_DOWN),
|
||||
transitionSourceSubMode(SUBMODE_NONE) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||
CommandMessage::MAX_MESSAGE_SIZE);
|
||||
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
insertInCommandMap(RAW_COMMAND_ID);
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
cookieInfo.pendingCommand = deviceCommandMap.end();
|
||||
if (comCookie == nullptr) {
|
||||
sif::error << "DeviceHandlerBase: ObjectID 0x" << std::hex <<
|
||||
std::setw(8) << std::setfill('0') << this->getObjectId() <<
|
||||
std::dec << ": Do not pass nullptr as a cookie, consider "
|
||||
<< std::setfill(' ') << "passing a dummy cookie instead!" <<
|
||||
std::endl;
|
||||
sif::error << "DeviceHandlerBase: ObjectID 0x" << std::hex
|
||||
<< std::setw(8) << std::setfill('0') << this->getObjectId()
|
||||
<< std::dec << ": Do not pass nullptr as a cookie, consider "
|
||||
<< std::setfill(' ') << "passing a dummy cookie instead!"
|
||||
<< std::endl;
|
||||
}
|
||||
if (this->fdirInstance == nullptr) {
|
||||
this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId,
|
||||
defaultFDIRParentId);
|
||||
defaultFdirParentId);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::setHkDestination(object_id_t hkDestination) {
|
||||
this->hkDestination = hkDestination;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::setThermalStateRequestPoolIds(
|
||||
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) {
|
||||
this->deviceThermalRequestPoolId = thermalStatePoolId;
|
||||
this->deviceThermalRequestPoolId = thermalRequestPoolId;
|
||||
}
|
||||
|
||||
|
||||
DeviceHandlerBase::~DeviceHandlerBase() {
|
||||
delete comCookie;
|
||||
if (defaultFDIRUsed) {
|
||||
@ -108,37 +118,56 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
|
||||
communicationInterface = objectManager->get<DeviceCommunicationIF>(
|
||||
deviceCommunicationId);
|
||||
if (communicationInterface == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if (communicationInterface == nullptr) {
|
||||
sif::error << "DeviceHandlerBase::initialize: Communication interface "
|
||||
"invalid." << std::endl;
|
||||
sif::error << "Make sure it is set up properly and implements"
|
||||
" DeviceCommunicationIF" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
result = communicationInterface->initializeInterface(comCookie);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
sif::error << "DeviceHandlerBase::initialize: Initializing "
|
||||
"communication interface failed!" << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (IPCStore == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if (IPCStore == nullptr) {
|
||||
sif::error << "DeviceHandlerBase::initialize: IPC store not set up in "
|
||||
"factory." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
AcceptsDeviceResponsesIF *rawReceiver = objectManager->get<
|
||||
AcceptsDeviceResponsesIF>(rawDataReceiverId);
|
||||
if(rawDataReceiverId != objects::NO_OBJECT) {
|
||||
AcceptsDeviceResponsesIF *rawReceiver = objectManager->get<
|
||||
AcceptsDeviceResponsesIF>(rawDataReceiverId);
|
||||
|
||||
if (rawReceiver == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if (rawReceiver == nullptr) {
|
||||
sif::error << "DeviceHandlerBase::initialize: Raw receiver object "
|
||||
"ID set but no valid object found." << std::endl;
|
||||
sif::error << "Make sure the raw receiver object is set up properly"
|
||||
" and implements AcceptsDeviceResponsesIF" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
defaultRawReceiver = rawReceiver->getDeviceQueue();
|
||||
}
|
||||
|
||||
defaultRawReceiver = rawReceiver->getDeviceQueue();
|
||||
|
||||
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
|
||||
if (powerSwitcher == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if(powerSwitcherId != objects::NO_OBJECT) {
|
||||
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
|
||||
if (powerSwitcher == nullptr) {
|
||||
sif::error << "DeviceHandlerBase::initialize: Power switcher "
|
||||
<< "object ID set but no valid object found." << std::endl;
|
||||
sif::error << "Make sure the raw receiver object is set up properly"
|
||||
<< " and implements PowerSwitchIF" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
result = healthHelper.initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = modeHelper.initialize();
|
||||
@ -164,11 +193,20 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(hkDestination == objects::NO_OBJECT) {
|
||||
hkDestination = defaultHkDestination;
|
||||
}
|
||||
|
||||
result = hkManager.initialize(commandQueue, hkDestination);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fillCommandAndReplyMap();
|
||||
|
||||
//Set temperature target state to NON_OP.
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_WRITE);
|
||||
mySet.read();
|
||||
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
||||
@ -200,38 +238,43 @@ void DeviceHandlerBase::readCommandQueue() {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandMessage message;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result != RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = healthHelper.handleHealthCommand(&message);
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = modeHelper.handleModeCommand(&message);
|
||||
result = actionHelper.handleActionMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = actionHelper.handleActionMessage(&message);
|
||||
result = parameterHelper.handleParameterMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = parameterHelper.handleParameterMessage(&message);
|
||||
result = hkManager.handleHousekeepingMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = handleDeviceHandlerMessage(&message);
|
||||
result = handleDeviceHandlerMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = letChildHandleMessage(&message);
|
||||
result = letChildHandleMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
@ -273,7 +316,8 @@ void DeviceHandlerBase::doStateMachine() {
|
||||
case _MODE_WAIT_ON: {
|
||||
uint32_t currentUptime;
|
||||
Clock::getUptime(¤tUptime);
|
||||
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
||||
if (powerSwitcher != nullptr and currentUptime - timeoutStart >=
|
||||
powerSwitcher->getSwitchDelayMs()) {
|
||||
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
||||
0);
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
@ -293,6 +337,12 @@ void DeviceHandlerBase::doStateMachine() {
|
||||
case _MODE_WAIT_OFF: {
|
||||
uint32_t currentUptime;
|
||||
Clock::getUptime(¤tUptime);
|
||||
|
||||
if(powerSwitcher == nullptr) {
|
||||
setMode(MODE_OFF);
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
||||
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
||||
0);
|
||||
@ -343,9 +393,10 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode,
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
||||
uint16_t maxDelayCycles, size_t replyLen, bool periodic,
|
||||
bool hasDifferentReplyId, DeviceCommandId_t replyId) {
|
||||
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
|
||||
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
|
||||
size_t replyLen, bool periodic, bool hasDifferentReplyId,
|
||||
DeviceCommandId_t replyId) {
|
||||
//No need to check, as we may try to insert multiple times.
|
||||
insertInCommandMap(deviceCommand);
|
||||
if (hasDifferentReplyId) {
|
||||
@ -371,7 +422,8 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand) {
|
||||
ReturnValue_t DeviceHandlerBase::insertInCommandMap(
|
||||
DeviceCommandId_t deviceCommand) {
|
||||
DeviceCommandInfo info;
|
||||
info.expectedReplies = 0;
|
||||
info.isExecuting = false;
|
||||
@ -419,7 +471,7 @@ void DeviceHandlerBase::setTransition(Mode_t modeTo, Submode_t submodeTo) {
|
||||
transitionSourceSubMode = submode;
|
||||
childTransitionFailure = CHILD_TIMEOUT;
|
||||
|
||||
//transitionTargetMode is set by setMode
|
||||
// transitionTargetMode is set by setMode
|
||||
setMode((modeTo | TRANSITION_MODE_CHILD_ACTION_MASK), submodeTo);
|
||||
}
|
||||
|
||||
@ -436,8 +488,8 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
||||
Clock::getUptime(&timeoutStart);
|
||||
|
||||
if (mode == MODE_OFF) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -578,11 +630,8 @@ void DeviceHandlerBase::doSendRead() {
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::doGetRead() {
|
||||
size_t receivedDataLen;
|
||||
uint8_t *receivedData;
|
||||
DeviceCommandId_t foundId = 0xFFFFFFFF;
|
||||
size_t foundLen = 0;
|
||||
ReturnValue_t result;
|
||||
size_t receivedDataLen = 0;
|
||||
uint8_t *receivedData = nullptr;
|
||||
|
||||
if (cookieInfo.state != COOKIE_READ_SENT) {
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
@ -591,8 +640,8 @@ void DeviceHandlerBase::doGetRead() {
|
||||
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
|
||||
result = communicationInterface->readReceivedMessage(comCookie,
|
||||
&receivedData, &receivedDataLen);
|
||||
ReturnValue_t result = communicationInterface->readReceivedMessage(
|
||||
comCookie, &receivedData, &receivedDataLen);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
|
||||
@ -608,51 +657,109 @@ void DeviceHandlerBase::doGetRead() {
|
||||
replyRawData(receivedData, receivedDataLen, requestedRawTraffic);
|
||||
}
|
||||
|
||||
if (mode == MODE_RAW) {
|
||||
if (mode == MODE_RAW and defaultRawReceiver != MessageQueueIF::NO_QUEUE) {
|
||||
replyRawReplyIfnotWiretapped(receivedData, receivedDataLen);
|
||||
} else {
|
||||
//The loop may not execute more often than the number of received bytes (worst case).
|
||||
//This approach avoids infinite loops due to buggy scanForReply routines (seen in bug 1077).
|
||||
uint32_t remainingLength = receivedDataLen;
|
||||
for (uint32_t count = 0; count < receivedDataLen; count++) {
|
||||
result = scanForReply(receivedData, remainingLength, &foundId,
|
||||
&foundLen);
|
||||
switch (result) {
|
||||
case RETURN_OK:
|
||||
handleReply(receivedData, foundId, foundLen);
|
||||
break;
|
||||
case APERIODIC_REPLY: {
|
||||
result = interpretDeviceReply(foundId, receivedData);
|
||||
if (result != RETURN_OK) {
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
|
||||
foundId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
parseReply(receivedData, receivedDataLen);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
|
||||
size_t receivedDataLen) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
DeviceCommandId_t foundId = 0xFFFFFFFF;
|
||||
size_t foundLen = 0;
|
||||
// The loop may not execute more often than the number of received bytes
|
||||
// (worst case). This approach avoids infinite loops due to buggy
|
||||
// scanForReply routines.
|
||||
uint32_t remainingLength = receivedDataLen;
|
||||
for (uint32_t count = 0; count < receivedDataLen; count++) {
|
||||
result = scanForReply(receivedData, remainingLength, &foundId,
|
||||
&foundLen);
|
||||
switch (result) {
|
||||
case RETURN_OK:
|
||||
handleReply(receivedData, foundId, foundLen);
|
||||
if(foundLen == 0) {
|
||||
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
|
||||
" Packet parsing will be stuck." << std::endl;
|
||||
}
|
||||
break;
|
||||
case IGNORE_REPLY_DATA:
|
||||
break;
|
||||
case IGNORE_FULL_PACKET:
|
||||
return;
|
||||
default:
|
||||
//We need to wait for timeout.. don't know what command failed and who sent it.
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_READING_REPLY_FAILED, result, foundLen);
|
||||
break;
|
||||
break;
|
||||
case APERIODIC_REPLY: {
|
||||
result = interpretDeviceReply(foundId, receivedData);
|
||||
if (result != RETURN_OK) {
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
|
||||
foundId);
|
||||
}
|
||||
receivedData += foundLen;
|
||||
if (remainingLength > foundLen) {
|
||||
remainingLength -= foundLen;
|
||||
} else {
|
||||
return;
|
||||
if(foundLen == 0) {
|
||||
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
|
||||
" Packet parsing will be stuck." << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IGNORE_REPLY_DATA:
|
||||
break;
|
||||
case IGNORE_FULL_PACKET:
|
||||
return;
|
||||
default:
|
||||
//We need to wait for timeout.. don't know what command failed and who sent it.
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_READING_REPLY_FAILED, result, foundLen);
|
||||
break;
|
||||
}
|
||||
receivedData += foundLen;
|
||||
if (remainingLength > foundLen) {
|
||||
remainingLength -= foundLen;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
||||
DeviceCommandId_t foundId, uint32_t foundLen) {
|
||||
ReturnValue_t result;
|
||||
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
|
||||
|
||||
if (iter == deviceReplyMap.end()) {
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceReplyInfo *info = &(iter->second);
|
||||
|
||||
if (info->delayCycles != 0) {
|
||||
|
||||
if (info->periodic != false) {
|
||||
info->delayCycles = info->maxDelayCycles;
|
||||
}
|
||||
else {
|
||||
info->delayCycles = 0;
|
||||
}
|
||||
|
||||
result = interpretDeviceReply(foundId, receivedData);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
// Report failed interpretation to FDIR.
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
|
||||
}
|
||||
replyToReply(iter, result);
|
||||
}
|
||||
else {
|
||||
// Other completion failure messages are created by timeout.
|
||||
// Powering down the device might take some time during which periodic
|
||||
// replies may still come in.
|
||||
if (mode != _MODE_WAIT_OFF) {
|
||||
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress,
|
||||
uint8_t * *data, uint32_t * len) {
|
||||
uint8_t** data, uint32_t * len) {
|
||||
size_t lenTmp;
|
||||
|
||||
if (IPCStore == nullptr) {
|
||||
@ -675,7 +782,7 @@ ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress,
|
||||
|
||||
void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||
MessageQueueId_t sendTo, bool isCommand) {
|
||||
if (IPCStore == NULL || len == 0) {
|
||||
if (IPCStore == nullptr or len == 0 or sendTo == MessageQueueIF::NO_QUEUE) {
|
||||
return;
|
||||
}
|
||||
store_address_t address;
|
||||
@ -686,18 +793,17 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||
return;
|
||||
}
|
||||
|
||||
CommandMessage message;
|
||||
CommandMessage command;
|
||||
|
||||
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&message,
|
||||
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&command,
|
||||
getObjectId(), address, isCommand);
|
||||
|
||||
// this->DeviceHandlerCommand = CommandMessage::CMD_NONE;
|
||||
|
||||
result = commandQueue->sendMessage(sendTo, &message);
|
||||
result = commandQueue->sendMessage(sendTo, &command);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
IPCStore->deleteData(address);
|
||||
//Silently discard data, this indicates heavy TM traffic which should not be increased by additional events.
|
||||
// Silently discard data, this indicates heavy TM traffic which
|
||||
// should not be increased by additional events.
|
||||
}
|
||||
}
|
||||
|
||||
@ -726,57 +832,6 @@ MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
||||
DeviceCommandId_t foundId, uint32_t foundLen) {
|
||||
ReturnValue_t result;
|
||||
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
|
||||
|
||||
if (iter == deviceReplyMap.end()) {
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceReplyInfo *info = &(iter->second);
|
||||
|
||||
if (info->delayCycles != 0) {
|
||||
|
||||
if (info->periodic) {
|
||||
info->delayCycles = info->maxDelayCycles;
|
||||
} else {
|
||||
info->delayCycles = 0;
|
||||
}
|
||||
result = interpretDeviceReply(foundId, receivedData);
|
||||
if (result != RETURN_OK) {
|
||||
//Report failed interpretation to FDIR.
|
||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
|
||||
}
|
||||
replyToReply(iter, result);
|
||||
} else {
|
||||
//Other completion failure messages are created by timeout.
|
||||
//Powering down the device might take some time during which periodic replies may still come in.
|
||||
if (mode != _MODE_WAIT_OFF) {
|
||||
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) {
|
||||
// DeviceCommunicationIF *newCommunication = objectManager->get<
|
||||
// DeviceCommunicationIF>(newChannelId);
|
||||
//
|
||||
// if (newCommunication != NULL) {
|
||||
// ReturnValue_t result = newCommunication->reOpen(cookie, ioBoardAddress,
|
||||
// maxDeviceReplyLen);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
// return RETURN_OK;
|
||||
// }
|
||||
// return RETURN_FAILED;
|
||||
//}
|
||||
|
||||
void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
||||
storedRawData = DeviceHandlerMessage::getStoreAddress(commandMessage);
|
||||
ReturnValue_t result = getStorageData(storedRawData, &rawPacket,
|
||||
@ -793,6 +848,9 @@ void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
|
||||
if(powerSwitcher == nullptr) {
|
||||
return;
|
||||
}
|
||||
const uint8_t *switches;
|
||||
uint8_t numberOfSwitches = 0;
|
||||
ReturnValue_t result = getSwitches(&switches, &numberOfSwitches);
|
||||
@ -807,9 +865,7 @@ void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::getSwitches(const uint8_t **switches,
|
||||
uint8_t *numberOfSwitches) {
|
||||
*switches = &deviceSwitch;
|
||||
*numberOfSwitches = 1;
|
||||
return RETURN_OK;
|
||||
return DeviceHandlerBase::NO_SWITCH;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::modeChanged(void) {
|
||||
@ -845,6 +901,9 @@ uint32_t DeviceHandlerBase::getTransitionDelayMs(Mode_t modeFrom,
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) {
|
||||
if(powerSwitcher == nullptr) {
|
||||
return NO_SWITCH;
|
||||
}
|
||||
uint8_t numberOfSwitches = 0;
|
||||
const uint8_t *switches;
|
||||
|
||||
@ -894,10 +953,10 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
|
||||
|
||||
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
||||
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalState(deviceThermalStatePoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -924,8 +983,8 @@ void DeviceHandlerBase::startTransition(Mode_t commandedMode,
|
||||
childTransitionDelay = getTransitionDelayMs(_MODE_START_UP,
|
||||
MODE_ON);
|
||||
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -997,8 +1056,8 @@ HasHealthIF::HealthState DeviceHandlerBase::getHealth() {
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::setHealth(HealthState health) {
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::checkSwitchState() {
|
||||
@ -1111,37 +1170,49 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
||||
return;
|
||||
}
|
||||
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, data);
|
||||
if (iter->second.command != deviceCommandMap.end()) {//replies to a command
|
||||
//replies to a command
|
||||
if (iter->second.command != deviceCommandMap.end())
|
||||
{
|
||||
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
|
||||
|
||||
if (queueId != NO_COMMANDER) {
|
||||
//This may fail, but we'll ignore the fault.
|
||||
actionHelper.reportData(queueId, replyId, data);
|
||||
}
|
||||
|
||||
//This check should make sure we get any TM but don't get anything doubled.
|
||||
if (wiretappingMode == TM && (requestedRawTraffic != queueId)) {
|
||||
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
||||
} else if (forceDirectTm && (defaultRawReceiver != queueId)) {
|
||||
|
||||
// hiding of sender needed so the service will handle it as unexpected Data, no matter what state
|
||||
//(progress or completed) it is in
|
||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||
true);
|
||||
|
||||
}
|
||||
} else { //unrequested/aperiodic replies
|
||||
if (wiretappingMode == TM) {
|
||||
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
||||
} else if (forceDirectTm) {
|
||||
// hiding of sender needed so the service will handle it as unexpected Data, no matter what state
|
||||
//(progress or completed) it is in
|
||||
else if (forceDirectTm and (defaultRawReceiver != queueId) and
|
||||
(defaultRawReceiver != MessageQueueIF::NO_QUEUE))
|
||||
{
|
||||
// hiding of sender needed so the service will handle it as
|
||||
// unexpected Data, no matter what state (progress or completed)
|
||||
// it is in
|
||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||
true);
|
||||
true);
|
||||
}
|
||||
}
|
||||
//Try to cast to DataSet and commit data.
|
||||
//unrequested/aperiodic replies
|
||||
else
|
||||
{
|
||||
if (wiretappingMode == TM) {
|
||||
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
||||
}
|
||||
else if (forceDirectTm and defaultRawReceiver !=
|
||||
MessageQueueIF::NO_QUEUE)
|
||||
{
|
||||
// hiding of sender needed so the service will handle it as
|
||||
// unexpected Data, no matter what state (progress or completed)
|
||||
// it is in
|
||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||
true);
|
||||
}
|
||||
}
|
||||
//Try to cast to GlobDataSet and commit data.
|
||||
if (!neverInDataPool) {
|
||||
DataSet* dataSet = dynamic_cast<DataSet*>(data);
|
||||
GlobDataSet* dataSet = dynamic_cast<GlobDataSet*>(data);
|
||||
if (dataSet != NULL) {
|
||||
dataSet->commit(PoolVariableIF::VALID);
|
||||
}
|
||||
@ -1178,18 +1249,23 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
||||
if (mode == MODE_NORMAL) {
|
||||
result = buildNormalDeviceCommand(&deviceCommandId);
|
||||
if (result == BUSY) {
|
||||
//so we can track misconfigurations
|
||||
sif::debug << std::hex << getObjectId()
|
||||
<< ": DHB::buildInternalCommand busy" << std::endl; //so we can track misconfigurations
|
||||
<< ": DHB::buildInternalCommand: Busy" << std::endl;
|
||||
result = NOTHING_TO_SEND; //no need to report this
|
||||
}
|
||||
} else if (mode == MODE_RAW) {
|
||||
}
|
||||
else if (mode == MODE_RAW) {
|
||||
result = buildChildRawCommand();
|
||||
deviceCommandId = RAW_COMMAND_ID;
|
||||
} else if (mode & TRANSITION_MODE_CHILD_ACTION_MASK) {
|
||||
}
|
||||
else if (mode & TRANSITION_MODE_CHILD_ACTION_MASK) {
|
||||
result = buildTransitionDeviceCommand(&deviceCommandId);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == NOTHING_TO_SEND) {
|
||||
return;
|
||||
}
|
||||
@ -1281,11 +1357,41 @@ void DeviceHandlerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
|
||||
executingTask = task_;
|
||||
executingTask = task_;
|
||||
}
|
||||
|
||||
// Default implementations empty.
|
||||
void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
|
||||
object_id_t objectId, uint32_t parameter) {}
|
||||
|
||||
void DeviceHandlerBase::performOperationHook() {}
|
||||
void DeviceHandlerBase::performOperationHook() {
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::initializePoolEntries(
|
||||
LocalDataPool &localDataPoolMap) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
|
||||
return &hkManager;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() {
|
||||
// In this function, the task handle should be valid if the task
|
||||
// was implemented correctly. We still check to be 1000 % sure :-)
|
||||
if(executingTask != nullptr) {
|
||||
pstIntervalMs = executingTask->getPeriodMs();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
DataSetIF* DeviceHandlerBase::getDataSetHandle(sid_t sid) {
|
||||
auto iter = deviceReplyMap.find(sid.ownerSetId);
|
||||
if(iter != deviceReplyMap.end()) {
|
||||
return iter->second.dataSet;
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef DEVICEHANDLERBASE_H_
|
||||
#define DEVICEHANDLERBASE_H_
|
||||
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
@ -11,13 +11,15 @@
|
||||
#include <framework/modes/HasModesIF.h>
|
||||
#include <framework/power/PowerSwitchIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/tasks/PeriodicTaskIF.h>
|
||||
|
||||
#include <framework/action/ActionHelper.h>
|
||||
#include <framework/health/HealthHelper.h>
|
||||
#include <framework/parameters/ParameterHelper.h>
|
||||
#include <framework/datapool/HkSwitchHelper.h>
|
||||
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace Factory{
|
||||
@ -46,14 +48,16 @@ class StorageManagerIF;
|
||||
* If data has been received (GET_READ), the data will be interpreted.
|
||||
* The action for each step can be defined by the child class but as most
|
||||
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
|
||||
* a default implementation is provided. NOTE: RMAP is a standard which is used for FLP.
|
||||
* a default implementation is provided.
|
||||
* NOTE: RMAP is a standard which is used for FLP.
|
||||
* RMAP communication is not mandatory for projects implementing the FSFW.
|
||||
* However, the communication principles are similar to RMAP as there are
|
||||
* two write and two send calls involved.
|
||||
*
|
||||
* Device handler instances should extend this class and implement the abstract functions.
|
||||
* Components and drivers can send so called cookies which are used for communication
|
||||
* and contain information about the communcation (e.g. slave address for I2C or RMAP structs).
|
||||
* Device handler instances should extend this class and implement the abstract
|
||||
* functions. Components and drivers can send so called cookies which are used
|
||||
* for communication and contain information about the communcation (e.g. slave
|
||||
* address for I2C or RMAP structs).
|
||||
* The following abstract methods must be implemented by a device handler:
|
||||
* 1. doStartUp()
|
||||
* 2. doShutDown()
|
||||
@ -82,7 +86,8 @@ class DeviceHandlerBase: public DeviceHandlerIF,
|
||||
public HasModesIF,
|
||||
public HasHealthIF,
|
||||
public HasActionsIF,
|
||||
public ReceivesParameterMessagesIF {
|
||||
public ReceivesParameterMessagesIF,
|
||||
public HasLocalDataPoolIF {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
public:
|
||||
/**
|
||||
@ -100,12 +105,13 @@ public:
|
||||
* @param cmdQueueSize
|
||||
*/
|
||||
DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||
CookieIF * comCookie, uint8_t setDeviceSwitch,
|
||||
uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER,
|
||||
uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER,
|
||||
FailureIsolationBase* fdirInstance = nullptr,
|
||||
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
|
||||
size_t cmdQueueSize = 20);
|
||||
|
||||
void setHkDestination(object_id_t hkDestination);
|
||||
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId);
|
||||
|
||||
/**
|
||||
* @brief This function is the device handler base core component and is
|
||||
* called periodically.
|
||||
@ -150,11 +156,9 @@ public:
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initialize();
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
/** Destructor. */
|
||||
virtual ~DeviceHandlerBase();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief This is used to let the child class handle the transition from
|
||||
@ -232,8 +236,9 @@ protected:
|
||||
* Build the device command to send for a transitional mode.
|
||||
*
|
||||
* This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW,
|
||||
* @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp()
|
||||
* and doShutDown() as well as doTransition()
|
||||
* @c _MODE_START_UP and @c _MODE_SHUT_DOWN. So it is used by doStartUp()
|
||||
* and doShutDown() as well as doTransition(), by setting those
|
||||
* modes in the respective functions.
|
||||
*
|
||||
* A good idea is to implement a flag indicating a command has to be built
|
||||
* and a variable containing the command number to be built
|
||||
@ -321,12 +326,11 @@ protected:
|
||||
* - @c RETURN_FAILED when the reply could not be interpreted,
|
||||
* e.g. logical errors or range violations occurred
|
||||
*/
|
||||
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) = 0;
|
||||
|
||||
/**
|
||||
* @brief fill the #deviceCommandMap
|
||||
* @brief fill the #DeviceCommandMap and #DeviceReplyMap
|
||||
* called by the initialize() of the base class
|
||||
* @details
|
||||
* This is used to let the base class know which replies are expected.
|
||||
@ -375,6 +379,8 @@ protected:
|
||||
* @param deviceCommand Identifier of the command to add.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the command
|
||||
* waits until it times out.
|
||||
* @param replyLen Will be supplied to the requestReceiveMessage call of
|
||||
* the communication interface.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent
|
||||
* by the device repeatedly without request) or not. Default is aperiodic (0)
|
||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||
@ -470,6 +476,18 @@ protected:
|
||||
virtual ReturnValue_t getSwitches(const uint8_t **switches,
|
||||
uint8_t *numberOfSwitches);
|
||||
|
||||
/**
|
||||
* This function is used to initialize the local housekeeping pool
|
||||
* entries. The default implementation leaves the pool empty.
|
||||
* @param localDataPoolMap
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initializePoolEntries(
|
||||
LocalDataPool& localDataPoolMap) override;
|
||||
|
||||
/** Get the HK manager object handle */
|
||||
virtual LocalDataPoolManager* getHkManagerHandle() override;
|
||||
|
||||
/**
|
||||
* @brief Hook function for child handlers which is called once per
|
||||
* performOperation(). Default implementation is empty.
|
||||
@ -493,7 +511,7 @@ public:
|
||||
ReturnValue_t setHealth(HealthState health);
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) override;
|
||||
/**
|
||||
* Implementation of ExecutableObjectIF function
|
||||
*
|
||||
@ -505,7 +523,7 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The Returnvalues ID of this class, required by HasReturnvaluesIF
|
||||
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||
*/
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
|
||||
|
||||
@ -527,114 +545,140 @@ protected:
|
||||
static const DeviceCommandId_t NO_COMMAND_ID = -2;
|
||||
static const MessageQueueId_t NO_COMMANDER = 0;
|
||||
|
||||
/**
|
||||
* Pointer to the raw packet that will be sent.
|
||||
*/
|
||||
/** Pointer to the raw packet that will be sent.*/
|
||||
uint8_t *rawPacket = nullptr;
|
||||
/**
|
||||
* Size of the #rawPacket.
|
||||
*/
|
||||
/** Size of the #rawPacket. */
|
||||
uint32_t rawPacketLen = 0;
|
||||
|
||||
/**
|
||||
* The mode the device handler is currently in.
|
||||
*
|
||||
* This should never be changed directly but only with setMode()
|
||||
*/
|
||||
Mode_t mode;
|
||||
|
||||
/**
|
||||
* The submode the device handler is currently in.
|
||||
*
|
||||
* This should never be changed directly but only with setMode()
|
||||
*/
|
||||
Submode_t submode;
|
||||
|
||||
/**
|
||||
* This is the counter value from performOperation().
|
||||
*/
|
||||
/** This is the counter value from performOperation(). */
|
||||
uint8_t pstStep = 0;
|
||||
uint32_t pstIntervalMs = 0;
|
||||
|
||||
/**
|
||||
* wiretapping flag:
|
||||
* Wiretapping flag:
|
||||
*
|
||||
* indicates either that all raw messages to and from the device should be sent to #theOneWhoWantsToReadRawTraffic
|
||||
* or that all device TM should be downlinked to #theOneWhoWantsToReadRawTraffic
|
||||
* indicates either that all raw messages to and from the device should be
|
||||
* sent to #defaultRawReceiver
|
||||
* or that all device TM should be downlinked to #defaultRawReceiver.
|
||||
*/
|
||||
enum WiretappingMode {
|
||||
OFF = 0, RAW = 1, TM = 2
|
||||
} wiretappingMode;
|
||||
|
||||
/**
|
||||
* A message queue that accepts raw replies
|
||||
* @brief A message queue that accepts raw replies
|
||||
*
|
||||
* Statically initialized in initialize() to a configurable object. Used when there is no method
|
||||
* of finding a recipient, ie raw mode and reporting erreonous replies
|
||||
* Statically initialized in initialize() to a configurable object.
|
||||
* Used when there is no method of finding a recipient, ie raw mode and
|
||||
* reporting erroneous replies
|
||||
*/
|
||||
MessageQueueId_t defaultRawReceiver = 0;
|
||||
|
||||
MessageQueueId_t defaultRawReceiver = MessageQueueIF::NO_QUEUE;
|
||||
store_address_t storedRawData;
|
||||
|
||||
/**
|
||||
* the message queue which wants to read all raw traffic
|
||||
*
|
||||
* if #isWiretappingActive all raw communication from and to the device will be sent to this queue
|
||||
* @brief The message queue which wants to read all raw traffic
|
||||
* If #isWiretappingActive all raw communication from and to the device
|
||||
* will be sent to this queue
|
||||
*/
|
||||
MessageQueueId_t requestedRawTraffic = 0;
|
||||
|
||||
/**
|
||||
* the object used to set power switches
|
||||
*/
|
||||
PowerSwitchIF *powerSwitcher = nullptr;
|
||||
|
||||
/**
|
||||
* Pointer to the IPCStore.
|
||||
*
|
||||
* This caches the pointer received from the objectManager in the constructor.
|
||||
*/
|
||||
StorageManagerIF *IPCStore = nullptr;
|
||||
|
||||
/**
|
||||
* cached for init
|
||||
*/
|
||||
/** The comIF object ID is cached for the intialize() function */
|
||||
object_id_t deviceCommunicationId;
|
||||
|
||||
/**
|
||||
* Communication object used for device communication
|
||||
*/
|
||||
/** Communication object used for device communication */
|
||||
DeviceCommunicationIF * communicationInterface = nullptr;
|
||||
|
||||
/**
|
||||
* Cookie used for communication
|
||||
*/
|
||||
/** Cookie used for communication */
|
||||
CookieIF * comCookie;
|
||||
|
||||
/** Health helper for HasHealthIF */
|
||||
HealthHelper healthHelper;
|
||||
/** Mode helper for HasModesIF */
|
||||
ModeHelper modeHelper;
|
||||
/** Parameter helper for ReceivesParameterMessagesIF */
|
||||
ParameterHelper parameterHelper;
|
||||
/** Action helper for HasActionsIF */
|
||||
ActionHelper actionHelper;
|
||||
/** Housekeeping Manager */
|
||||
LocalDataPoolManager hkManager;
|
||||
|
||||
/**
|
||||
* @brief Information about commands
|
||||
*/
|
||||
struct DeviceCommandInfo {
|
||||
bool isExecuting; //!< Indicates if the command is already executing.
|
||||
uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0.
|
||||
MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander.
|
||||
//! Indicates if the command is already executing.
|
||||
bool isExecuting;
|
||||
//! Dynamic value to indicate how many replies are expected.
|
||||
//! Inititated with 0.
|
||||
uint8_t expectedReplies;
|
||||
//! if this is != NO_COMMANDER, DHB was commanded externally and shall
|
||||
//! report everything to commander.
|
||||
MessageQueueId_t sendReplyTo;
|
||||
};
|
||||
using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ;
|
||||
/**
|
||||
* Information about commands
|
||||
*/
|
||||
DeviceCommandMap deviceCommandMap;
|
||||
|
||||
/**
|
||||
* @brief Information about expected replies
|
||||
*
|
||||
* This is used to keep track of pending replies
|
||||
* This is used to keep track of pending replies.
|
||||
*/
|
||||
struct DeviceReplyInfo {
|
||||
uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command.
|
||||
uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected
|
||||
//! The maximum number of cycles the handler should wait for a reply
|
||||
//! to this command.
|
||||
uint16_t maxDelayCycles;
|
||||
//! The currently remaining cycles the handler should wait for a reply,
|
||||
//! 0 means there is no reply expected
|
||||
uint16_t delayCycles;
|
||||
size_t replyLen = 0; //!< Expected size of the reply.
|
||||
bool periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles
|
||||
DeviceCommandMap::iterator command; //!< The command that expects this reply.
|
||||
//! if this is !=0, the delayCycles will not be reset to 0 but to
|
||||
//! maxDelayCycles
|
||||
bool periodic = false;
|
||||
//! The dataset used to access housekeeping data related to the
|
||||
//! respective device reply. Will point to a dataset held by
|
||||
//! the child handler (if one is specified)
|
||||
DataSetIF* dataSet = nullptr;
|
||||
float collectionInterval = 0.0;
|
||||
uint32_t intervalCounter = 0;
|
||||
//! The command that expects this reply.
|
||||
DeviceCommandMap::iterator command;
|
||||
};
|
||||
|
||||
using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ;
|
||||
using DeviceReplyIter = DeviceReplyMap::iterator;
|
||||
|
||||
/**
|
||||
* The MessageQueue used to receive device handler commands and to send replies.
|
||||
* This map is used to check and track correct reception of all replies.
|
||||
*
|
||||
* It has multiple use:
|
||||
* - It stores the information on pending replies. If a command is sent,
|
||||
* the DeviceCommandInfo.count is incremented.
|
||||
* - It is used to time-out missing replies. If a command is sent, the
|
||||
* DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
|
||||
* - It is queried to check if a reply from the device can be interpreted.
|
||||
* scanForReply() returns the id of the command a reply was found for.
|
||||
* The reply is ignored in the following cases:
|
||||
* - No entry for the returned id was found
|
||||
* - The deviceReplyInfo.delayCycles is == 0
|
||||
*/
|
||||
DeviceReplyMap deviceReplyMap;
|
||||
|
||||
//! The MessageQueue used to receive device handler commands
|
||||
//! and to send replies.
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
|
||||
/**
|
||||
@ -642,23 +686,14 @@ protected:
|
||||
*
|
||||
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
||||
*/
|
||||
uint32_t deviceThermalStatePoolId;
|
||||
uint32_t deviceThermalStatePoolId = PoolVariableIF::NO_PARAMETER;
|
||||
|
||||
/**
|
||||
* this is the datapool variable with the thermal request of the device
|
||||
*
|
||||
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
||||
*/
|
||||
uint32_t deviceThermalRequestPoolId;
|
||||
|
||||
/**
|
||||
* Taking care of the health
|
||||
*/
|
||||
HealthHelper healthHelper;
|
||||
|
||||
ModeHelper modeHelper;
|
||||
|
||||
ParameterHelper parameterHelper;
|
||||
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
|
||||
|
||||
/**
|
||||
* Optional Error code
|
||||
@ -676,13 +711,15 @@ protected:
|
||||
|
||||
bool switchOffWasReported; //!< Indicates if SWITCH_WENT_OFF was already thrown.
|
||||
|
||||
PeriodicTaskIF* executingTask = nullptr;//!< Pointer to the task which executes this component, is invalid before setTaskIF was called.
|
||||
//! Pointer to the task which executes this component, is invalid
|
||||
//! before setTaskIF was called.
|
||||
PeriodicTaskIF* executingTask = nullptr;
|
||||
|
||||
static object_id_t powerSwitcherId; //!< Object which switches power on and off.
|
||||
|
||||
static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default.
|
||||
|
||||
static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault.
|
||||
static object_id_t defaultFdirParentId; //!< Object which may be the root cause of an identified fault.
|
||||
/**
|
||||
* Helper function to report a missed reply
|
||||
*
|
||||
@ -730,28 +767,40 @@ protected:
|
||||
/**
|
||||
* Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW).
|
||||
*
|
||||
* If the transition is complete, the mode should be set to the target mode, which can be deduced from the current mode which is
|
||||
* If the transition is complete, the mode should be set to the target mode,
|
||||
* which can be deduced from the current mode which is
|
||||
* [_MODE_TO_ON, _MODE_TO_NORMAL, _MODE_TO_RAW]
|
||||
*
|
||||
* The intended target submode is already set. The origin submode can be read in subModeFrom.
|
||||
* The intended target submode is already set.
|
||||
* The origin submode can be read in subModeFrom.
|
||||
*
|
||||
* If the transition can not be completed, the child class can try to reach an working mode by setting the mode either directly
|
||||
* or setting the mode to an transitional mode (TO_ON, TO_NORMAL, TO_RAW) if the device needs to be reconfigured.
|
||||
* If the transition can not be completed, the child class can try to reach
|
||||
* an working mode by setting the mode either directly
|
||||
* or setting the mode to an transitional mode (TO_ON, TO_NORMAL, TO_RAW)
|
||||
* if the device needs to be reconfigured.
|
||||
*
|
||||
* If nothing works, the child class can wait for the timeout and the base class will reset the mode to the mode where the transition
|
||||
* If nothing works, the child class can wait for the timeout and the base
|
||||
* class will reset the mode to the mode where the transition
|
||||
* originated from (the child should report the reason for the failed transition).
|
||||
*
|
||||
* The intended way to send commands is to set a flag (enum) indicating which command is to be sent here
|
||||
* and then to check in buildTransitionCommand() for the flag. This flag can also be used by doStartUp() and
|
||||
* doShutDown() to get a nice and clean implementation of buildTransitionCommand() without switching through modes.
|
||||
* The intended way to send commands is to set a flag (enum) indicating
|
||||
* which command is to be sent here and then to check in
|
||||
* buildTransitionCommand() for the flag. This flag can also be used by
|
||||
* doStartUp() and doShutDown() to get a nice and clean implementation of
|
||||
* buildTransitionCommand() without switching through modes.
|
||||
*
|
||||
* When the the condition for the completion of the transition is met, the mode can be set, for example in the parseReply() function.
|
||||
* When the the condition for the completion of the transition is met, the
|
||||
* mode can be set, for example in the scanForReply() function.
|
||||
*
|
||||
* The default implementation goes into the target mode;
|
||||
* The default implementation goes into the target mode directly.
|
||||
*
|
||||
* #transitionFailure can be set to a failure code indicating the reason for a failed transition
|
||||
* #transitionFailure can be set to a failure code indicating the reason
|
||||
* for a failed transition
|
||||
*
|
||||
* @param modeFrom the mode the transition originated from: [MODE_ON, MODE_NORMAL, MODE_RAW and _MODE_POWER_DOWN (if the mode changed from _MODE_START_UP to _MODE_TO_ON)]
|
||||
* @param modeFrom
|
||||
* The mode the transition originated from:
|
||||
* [MODE_ON, MODE_NORMAL, MODE_RAW and _MODE_POWER_DOWN (if the mode changed
|
||||
* from _MODE_START_UP to _MODE_TO_ON)]
|
||||
* @param subModeFrom the subMode of modeFrom
|
||||
*/
|
||||
virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom);
|
||||
@ -953,24 +1002,11 @@ protected:
|
||||
bool commandIsExecuting(DeviceCommandId_t commandId);
|
||||
|
||||
/**
|
||||
* This map is used to check and track correct reception of all replies.
|
||||
* set all switches returned by getSwitches()
|
||||
*
|
||||
* It has multiple use:
|
||||
* - it stores the information on pending replies. If a command is sent, the DeviceCommandInfo.count is incremented.
|
||||
* - it is used to time-out missing replies. If a command is sent, the DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
|
||||
* - it is queried to check if a reply from the device can be interpreted. scanForReply() returns the id of the command a reply was found for.
|
||||
* The reply is ignored in the following cases:
|
||||
* - No entry for the returned id was found
|
||||
* - The deviceReplyInfo.delayCycles is == 0
|
||||
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
||||
*/
|
||||
DeviceReplyMap deviceReplyMap;
|
||||
|
||||
/**
|
||||
* Information about commands
|
||||
*/
|
||||
DeviceCommandMap deviceCommandMap;
|
||||
|
||||
ActionHelper actionHelper;
|
||||
void commandSwitch(ReturnValue_t onOff);
|
||||
private:
|
||||
|
||||
/**
|
||||
@ -997,15 +1033,21 @@ private:
|
||||
};
|
||||
|
||||
/**
|
||||
* Info about the #cookie
|
||||
*
|
||||
* @brief Info about the #cookie
|
||||
* Used to track the state of the communication
|
||||
*/
|
||||
CookieInfo cookieInfo;
|
||||
|
||||
/** the object used to set power switches */
|
||||
PowerSwitchIF *powerSwitcher = nullptr;
|
||||
|
||||
/** Cached for initialize() */
|
||||
static object_id_t defaultHkDestination;
|
||||
/** HK destination can also be set individually */
|
||||
object_id_t hkDestination = objects::NO_OBJECT;
|
||||
|
||||
/**
|
||||
* Used for timing out mode transitions.
|
||||
*
|
||||
* @brief Used for timing out mode transitions.
|
||||
* Set when setMode() is called.
|
||||
*/
|
||||
uint32_t timeoutStart = 0;
|
||||
@ -1016,11 +1058,12 @@ private:
|
||||
uint32_t childTransitionDelay;
|
||||
|
||||
/**
|
||||
* The mode the current transition originated from
|
||||
* @brief The mode the current transition originated from
|
||||
*
|
||||
* This is private so the child can not change it and fuck up the timeouts
|
||||
*
|
||||
* IMPORTANT: This is not valid during _MODE_SHUT_DOWN and _MODE_START_UP!! (it is _MODE_POWER_DOWN during this modes)
|
||||
* IMPORTANT: This is not valid during _MODE_SHUT_DOWN and _MODE_START_UP!!
|
||||
* (it is _MODE_POWER_DOWN during this modes)
|
||||
*
|
||||
* is element of [MODE_ON, MODE_NORMAL, MODE_RAW]
|
||||
*/
|
||||
@ -1031,13 +1074,6 @@ private:
|
||||
*/
|
||||
Submode_t transitionSourceSubMode;
|
||||
|
||||
/**
|
||||
* the switch of the device
|
||||
*
|
||||
* for devices using two switches override getSwitches()
|
||||
*/
|
||||
const uint8_t deviceSwitch;
|
||||
|
||||
/**
|
||||
* read the command queue
|
||||
*/
|
||||
@ -1135,12 +1171,6 @@ private:
|
||||
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
||||
uint32_t *len);
|
||||
|
||||
/**
|
||||
* set all switches returned by getSwitches()
|
||||
*
|
||||
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
||||
*/
|
||||
void commandSwitch(ReturnValue_t onOff);
|
||||
|
||||
/**
|
||||
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
|
||||
@ -1165,7 +1195,13 @@ private:
|
||||
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
|
||||
|
||||
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
|
||||
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||
DataSetIF* getDataSetHandle(sid_t sid) override;
|
||||
|
||||
void parseReply(const uint8_t* receivedData,
|
||||
size_t receivedDataLen);
|
||||
};
|
||||
|
||||
#endif /* DEVICEHANDLERBASE_H_ */
|
||||
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */
|
||||
|
||||
|
@ -7,13 +7,15 @@
|
||||
|
||||
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = 0;
|
||||
|
||||
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent) :
|
||||
FailureIsolationBase(owner, parent), strangeReplyCount(MAX_STRANGE_REPLIES,
|
||||
STRANGE_REPLIES_TIME_MS, parameterDomainBase++), missedReplyCount(
|
||||
MAX_MISSED_REPLY_COUNT, MISSED_REPLY_TIME_MS,
|
||||
parameterDomainBase++), recoveryCounter(MAX_REBOOT,
|
||||
REBOOT_TIME_MS, parameterDomainBase++), fdirState(NONE), powerConfirmation(
|
||||
0) {
|
||||
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner,
|
||||
object_id_t parent) :
|
||||
FailureIsolationBase(owner, parent),
|
||||
strangeReplyCount(MAX_STRANGE_REPLIES, STRANGE_REPLIES_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
missedReplyCount( MAX_MISSED_REPLY_COUNT, MISSED_REPLY_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
recoveryCounter(MAX_REBOOT, REBOOT_TIME_MS, parameterDomainBase++),
|
||||
fdirState(NONE), powerConfirmation(0) {
|
||||
}
|
||||
|
||||
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {
|
||||
@ -68,9 +70,11 @@ ReturnValue_t DeviceHandlerFailureIsolation::eventReceived(EventMessage* event)
|
||||
break;
|
||||
//****Power*****
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
result = sendConfirmationRequest(event, powerConfirmation);
|
||||
if (result == RETURN_OK) {
|
||||
setFdirState(DEVICE_MIGHT_BE_OFF);
|
||||
if(hasPowerConfirmation) {
|
||||
result = sendConfirmationRequest(event, powerConfirmation);
|
||||
if (result == RETURN_OK) {
|
||||
setFdirState(DEVICE_MIGHT_BE_OFF);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Fuse::FUSE_WENT_OFF:
|
||||
@ -133,7 +137,7 @@ void DeviceHandlerFailureIsolation::decrementFaultCounters() {
|
||||
|
||||
void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
||||
clearFaultCounters();
|
||||
if (!recoveryCounter.incrementAndCheck()) {
|
||||
if (not recoveryCounter.incrementAndCheck()) {
|
||||
startRecovery(reason);
|
||||
} else {
|
||||
setFaulty(reason);
|
||||
@ -142,7 +146,8 @@ void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
||||
|
||||
void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) {
|
||||
//We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset.
|
||||
//This means, no fault message will come through until a MODE_ or HEALTH_INFO message comes through -> Is that ok?
|
||||
//This means, no fault message will come through until a MODE_ or
|
||||
//HEALTH_INFO message comes through -> Is that ok?
|
||||
//Same issue in TxFailureIsolation!
|
||||
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
|
||||
// && (fdirState != RECOVERY_ONGOING)) {
|
||||
@ -158,14 +163,17 @@ void DeviceHandlerFailureIsolation::clearFaultCounters() {
|
||||
ReturnValue_t DeviceHandlerFailureIsolation::initialize() {
|
||||
ReturnValue_t result = FailureIsolationBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "DeviceHandlerFailureIsolation::initialize: Could not"
|
||||
" initialize FailureIsolationBase." << std::endl;
|
||||
return result;
|
||||
}
|
||||
ConfirmsFailuresIF* power = objectManager->get<ConfirmsFailuresIF>(
|
||||
powerConfirmationId);
|
||||
if (power == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if (power != nullptr) {
|
||||
powerConfirmation = power->getEventReceptionQueue();
|
||||
hasPowerConfirmation = true;
|
||||
}
|
||||
powerConfirmation = power->getEventReceptionQueue();
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,10 @@ protected:
|
||||
NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN
|
||||
};
|
||||
FDIRState fdirState;
|
||||
bool hasPowerConfirmation = false;
|
||||
MessageQueueId_t powerConfirmation;
|
||||
static object_id_t powerConfirmationId;
|
||||
// TODO: Are those hardcoded value? How can they be changed.
|
||||
static const uint32_t MAX_REBOOT = 1;
|
||||
static const uint32_t REBOOT_TIME_MS = 180000;
|
||||
static const uint32_t MAX_STRANGE_REPLIES = 10;
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
//! This is a transitional state which can not be commanded.
|
||||
//! The device handler performs all actions and commands to get the device
|
||||
//! shut down. When the device is off, the mode changes to @c MODE_OFF.
|
||||
//! It is possible to set the mode to _MODE_SHUT_DOWN to use the to off
|
||||
//! transition if available.
|
||||
static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6;
|
||||
//! It is possible to set the mode to _MODE_TO_ON to use the to on
|
||||
//! transition if available.
|
||||
@ -96,7 +98,7 @@ public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
|
||||
|
||||
// Standard codes used when building commands.
|
||||
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If the command size is 0. Checked in DHB
|
||||
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If no command data was given when expected.
|
||||
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB
|
||||
static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB
|
||||
static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3);
|
||||
|
@ -47,7 +47,7 @@ void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
|
||||
|
||||
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
|
||||
CommandMessage* message, uint32_t ioBoardIdentifier) {
|
||||
message->setCommand(CMD_SWITCH_IOBOARD);
|
||||
message->setCommand(CMD_SWITCH_ADDRESS);
|
||||
message->setParameter(ioBoardIdentifier);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ void DeviceHandlerMessage::clear(CommandMessage* message) {
|
||||
}
|
||||
}
|
||||
/* NO BREAK falls through*/
|
||||
case CMD_SWITCH_IOBOARD:
|
||||
case CMD_SWITCH_ADDRESS:
|
||||
case CMD_WIRETAPPING:
|
||||
message->setCommand(CommandMessage::CMD_NONE);
|
||||
message->setParameter(0);
|
||||
|
@ -25,10 +25,10 @@ public:
|
||||
/**
|
||||
* These are the commands that can be sent to a DeviceHandlerBase
|
||||
*/
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::DEVICE_HANDLER_COMMAND;
|
||||
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
||||
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send
|
||||
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command
|
||||
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID( 4 ); //!< (De)Activates the monitoring of all raw traffic in DeviceHandlers, setParameter is 0 to deactivate, 1 to activate
|
||||
|
||||
/*static const Command_t REPLY_SWITCHED_IOBOARD = MAKE_COMMAND_ID(1 );//!< Reply to a @c CMD_SWITCH_IOBOARD, indicates switch was successful, getParameter() contains the board switched to (0: nominal, 1: redundant)
|
||||
|
@ -5,7 +5,7 @@ HealthDevice::HealthDevice(object_id_t setObjectId,
|
||||
MessageQueueId_t parentQueue) :
|
||||
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
|
||||
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::COMMAND_MESSAGE_SIZE);
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::MINIMUM_COMMAND_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
HealthDevice::~HealthDevice() {
|
||||
@ -13,10 +13,10 @@ HealthDevice::~HealthDevice() {
|
||||
}
|
||||
|
||||
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
|
||||
CommandMessage message;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
healthHelper.handleHealthCommand(&message);
|
||||
healthHelper.handleHealthCommand(&command);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef EVENTOBJECT_EVENT_H_
|
||||
#define EVENTOBJECT_EVENT_H_
|
||||
#ifndef FRAMEWORK_EVENTS_EVENT_H_
|
||||
#define FRAMEWORK_EVENTS_EVENT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <framework/events/fwSubsystemIdRanges.h>
|
||||
//could be move to more suitable location
|
||||
#include <config/tmtc/subsystemIdRanges.h>
|
||||
#include <subsystemIdRanges.h>
|
||||
|
||||
typedef uint16_t EventId_t;
|
||||
typedef uint8_t EventSeverity_t;
|
||||
@ -21,6 +21,7 @@ EventSeverity_t getSeverity(Event event);
|
||||
Event makeEvent(EventId_t eventId, EventSeverity_t eventSeverity);
|
||||
|
||||
}
|
||||
|
||||
namespace SEVERITY {
|
||||
static const EventSeverity_t INFO = 1;
|
||||
static const EventSeverity_t LOW = 2;
|
||||
@ -41,4 +42,4 @@ namespace SEVERITY {
|
||||
// static const EventSeverity_t HIGH = 4;
|
||||
//};
|
||||
|
||||
#endif /* EVENTOBJECT_EVENT_H_ */
|
||||
#endif /* FRAMEWORK_EVENTS_EVENT_H_ */
|
||||
|
@ -8,13 +8,16 @@
|
||||
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
||||
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
|
||||
sizeof(ReporterRangeMatcher) };
|
||||
//If one checks registerListener calls, there are around 40 (to max 50) objects registering for certain events.
|
||||
//Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher. So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
||||
// If one checks registerListener calls, there are around 40 (to max 50)
|
||||
// objects registering for certain events.
|
||||
// Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher.
|
||||
// So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
||||
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
|
||||
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
||||
|
||||
EventManager::EventManager(object_id_t setObjectId) :
|
||||
SystemObject(setObjectId), eventReportQueue(NULL), mutex(NULL), factoryBackend(
|
||||
0, POOL_SIZES, N_ELEMENTS, false, true) {
|
||||
SystemObject(setObjectId),
|
||||
factoryBackend(0, POOL_SIZES, N_ELEMENTS, false, true) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||
@ -49,7 +52,7 @@ void EventManager::notifyListeners(EventMessage* message) {
|
||||
for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) {
|
||||
if (iter->second.match(message)) {
|
||||
MessageQueueSenderIF::sendMessage(iter->first, message,
|
||||
message->getSender());
|
||||
message->getSender());
|
||||
}
|
||||
}
|
||||
unlockMutex();
|
||||
@ -130,16 +133,23 @@ void EventManager::printEvent(EventMessage* message) {
|
||||
break;
|
||||
default:
|
||||
string = translateObject(message->getReporter());
|
||||
sif::error << "EVENT: ";
|
||||
sif::debug << "EventManager: ";
|
||||
if (string != 0) {
|
||||
sif::error << string;
|
||||
} else {
|
||||
sif::error << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
sif::debug << string;
|
||||
}
|
||||
sif::error << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
<< message->getParameter1() << " P2: 0x"
|
||||
<< message->getParameter2() << std::dec << std::endl;
|
||||
else {
|
||||
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
sif::debug << " reported " << translateEvents(message->getEvent())
|
||||
<< " (" << std::dec << message->getEventId() << ") "
|
||||
<< std::endl;
|
||||
|
||||
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
|
||||
<< ", P1 Dec: " << std::dec << message->getParameter1()
|
||||
<< std::endl;
|
||||
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
|
||||
<< ", P2 Dec: " << std::dec << message->getParameter2()
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -147,7 +157,7 @@ void EventManager::printEvent(EventMessage* message) {
|
||||
#endif
|
||||
|
||||
void EventManager::lockMutex() {
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
}
|
||||
|
||||
void EventManager::unlockMutex() {
|
||||
|
@ -36,11 +36,11 @@ public:
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
protected:
|
||||
|
||||
MessageQueueIF* eventReportQueue;
|
||||
MessageQueueIF* eventReportQueue = nullptr;
|
||||
|
||||
std::map<MessageQueueId_t, EventMatchTree> listenerList;
|
||||
|
||||
MutexIF* mutex;
|
||||
MutexIF* mutex = nullptr;
|
||||
|
||||
static const uint8_t N_POOLS = 3;
|
||||
LocalPool<N_POOLS> factoryBackend;
|
||||
|
@ -18,8 +18,7 @@ enum {
|
||||
SYSTEM_MANAGER = 74,
|
||||
SYSTEM_MANAGER_1 = 75,
|
||||
SYSTEM_1 = 79,
|
||||
PUS_SERVICE_1 = 80,
|
||||
FW_SUBSYSTEM_ID_RANGE
|
||||
PUS_SERVICE_1 = 80
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
// TODO: Documentation.
|
||||
class ConfirmsFailuresIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::HANDLES_FAILURES_IF;
|
||||
|
@ -5,10 +5,12 @@
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
FailureIsolationBase::FailureIsolationBase(object_id_t owner, object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
|
||||
eventQueue(NULL), ownerId(
|
||||
owner), owner(NULL), faultTreeParent(parent), parameterDomainBase(parameterDomainBase) {
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth, EventMessage::EVENT_MESSAGE_SIZE);
|
||||
FailureIsolationBase::FailureIsolationBase(object_id_t owner,
|
||||
object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
|
||||
eventQueue(NULL), ownerId(owner), owner(NULL),
|
||||
faultTreeParent(parent), parameterDomainBase(parameterDomainBase) {
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
|
||||
EventMessage::EVENT_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
FailureIsolationBase::~FailureIsolationBase() {
|
||||
@ -18,27 +20,36 @@ FailureIsolationBase::~FailureIsolationBase() {
|
||||
ReturnValue_t FailureIsolationBase::initialize() {
|
||||
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
||||
objects::EVENT_MANAGER);
|
||||
if (manager == NULL) {
|
||||
if (manager == nullptr) {
|
||||
sif::error << "FailureIsolationBase::initialize: Event Manager has not"
|
||||
" been initialized!" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
ReturnValue_t result = manager->registerListener(eventQueue->getId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (ownerId != 0) {
|
||||
if (ownerId != objects::NO_OBJECT) {
|
||||
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), ownerId);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
owner = objectManager->get<HasHealthIF>(ownerId);
|
||||
if (owner == NULL) {
|
||||
return RETURN_FAILED;
|
||||
if (owner == nullptr) {
|
||||
sif::error << "FailureIsolationBase::intialize: Owner object "
|
||||
"invalid. Make sure it implements HasHealthIF" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
}
|
||||
if (faultTreeParent != 0) {
|
||||
if (faultTreeParent != objects::NO_OBJECT) {
|
||||
ConfirmsFailuresIF* parentIF = objectManager->get<ConfirmsFailuresIF>(
|
||||
faultTreeParent);
|
||||
if (parentIF == NULL) {
|
||||
if (parentIF == nullptr) {
|
||||
sif::error << "FailureIsolationBase::intialize: Parent object"
|
||||
<< "invalid." << std::endl;
|
||||
sif::error << "Make sure it implements ConfirmsFailuresIF."
|
||||
<< std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
eventQueue->setDefaultDestination(parentIF->getEventReceptionQueue());
|
||||
@ -93,9 +104,9 @@ MessageQueueId_t FailureIsolationBase::getEventReceptionQueue() {
|
||||
ReturnValue_t FailureIsolationBase::sendConfirmationRequest(EventMessage* event,
|
||||
MessageQueueId_t destination) {
|
||||
event->setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
||||
if (destination != 0) {
|
||||
if (destination != MessageQueueIF::NO_QUEUE) {
|
||||
return eventQueue->sendMessage(destination, event);
|
||||
} else if (faultTreeParent != 0) {
|
||||
} else if (faultTreeParent != objects::NO_OBJECT) {
|
||||
return eventQueue->sendToDefault(event);
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
|
@ -17,12 +17,19 @@ public:
|
||||
static const Event FDIR_CHANGED_STATE = MAKE_EVENT(1, SEVERITY::INFO); //!< FDIR has an internal state, which changed from par2 (oldState) to par1 (newState).
|
||||
static const Event FDIR_STARTS_RECOVERY = MAKE_EVENT(2, SEVERITY::MEDIUM); //!< FDIR tries to restart device. Par1: event that caused recovery.
|
||||
static const Event FDIR_TURNS_OFF_DEVICE = MAKE_EVENT(3, SEVERITY::MEDIUM); //!< FDIR turns off device. Par1: event that caused recovery.
|
||||
FailureIsolationBase(object_id_t owner, object_id_t parent = 0,
|
||||
|
||||
FailureIsolationBase(object_id_t owner,
|
||||
object_id_t parent = objects::NO_OBJECT,
|
||||
uint8_t messageDepth = 10, uint8_t parameterDomainBase = 0xF0);
|
||||
|
||||
virtual ~FailureIsolationBase();
|
||||
virtual ReturnValue_t initialize();
|
||||
|
||||
/**
|
||||
* This is called by the DHB in performOperation()
|
||||
*/
|
||||
void checkForFailures();
|
||||
MessageQueueId_t getEventReceptionQueue();
|
||||
MessageQueueId_t getEventReceptionQueue() override;
|
||||
virtual void triggerEvent(Event event, uint32_t parameter1 = 0,
|
||||
uint32_t parameter2 = 0);
|
||||
protected:
|
||||
@ -38,7 +45,7 @@ protected:
|
||||
virtual ReturnValue_t confirmFault(EventMessage* event);
|
||||
virtual void decrementFaultCounters() = 0;
|
||||
ReturnValue_t sendConfirmationRequest(EventMessage* event,
|
||||
MessageQueueId_t destination = 0);
|
||||
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
|
||||
void throwFdirEvent(Event event, uint32_t parameter1 = 0,
|
||||
uint32_t parameter2 = 0);
|
||||
private:
|
||||
|
@ -8,6 +8,9 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/controller/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/coordinates/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datalinklayer/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapool/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoolglob/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoollocal/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/housekeeping/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/devicehandlers/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/eventmatching/*.cpp)
|
||||
@ -34,7 +37,7 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/FreeRTOS/*.cpp)
|
||||
else ifeq ($(OS_FSFW),host)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/host/*.cpp)
|
||||
else
|
||||
$(error invalid OS_FSFW specified, valid OS_FSFW are rtems, linux, freeRTOS, host)
|
||||
$(error invalid OS specified, valid OS are rtems, linux, freeRTOS, host)
|
||||
endif
|
||||
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/parameters/*.cpp)
|
||||
@ -55,4 +58,4 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/pus/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/pus/*.cpp)
|
@ -1,95 +1,123 @@
|
||||
#include <framework/globalfunctions/DleEncoder.h>
|
||||
|
||||
DleEncoder::DleEncoder() {
|
||||
}
|
||||
DleEncoder::DleEncoder() {}
|
||||
|
||||
DleEncoder::~DleEncoder() {
|
||||
}
|
||||
|
||||
ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
|
||||
uint32_t sourceStreamLen, uint32_t *readLen, uint8_t *destStream,
|
||||
uint32_t maxDestStreamlen, uint32_t *decodedLen) {
|
||||
uint32_t encodedIndex = 0, decodedIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (*sourceStream != STX) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
++encodedIndex;
|
||||
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
|
||||
&& (sourceStream[encodedIndex] != ETX)
|
||||
&& (sourceStream[encodedIndex] != STX)) {
|
||||
if (sourceStream[encodedIndex] == DLE) {
|
||||
nextByte = sourceStream[encodedIndex + 1];
|
||||
if (nextByte == 0x10) {
|
||||
destStream[decodedIndex] = nextByte;
|
||||
} else {
|
||||
if ((nextByte == 0x42) || (nextByte == 0x43)
|
||||
|| (nextByte == 0x4D)) {
|
||||
destStream[decodedIndex] = nextByte - 0x40;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
++encodedIndex;
|
||||
} else {
|
||||
destStream[decodedIndex] = sourceStream[encodedIndex];
|
||||
}
|
||||
++encodedIndex;
|
||||
++decodedIndex;
|
||||
}
|
||||
if (sourceStream[encodedIndex] != ETX) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
*readLen = ++encodedIndex;
|
||||
*decodedLen = decodedIndex;
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
DleEncoder::~DleEncoder() {}
|
||||
|
||||
ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
||||
uint32_t sourceLen, uint8_t* destStream, uint32_t maxDestLen,
|
||||
uint32_t* encodedLen, bool addStxEtx) {
|
||||
size_t sourceLen, uint8_t* destStream, size_t maxDestLen,
|
||||
size_t* encodedLen, bool addStxEtx) {
|
||||
if (maxDestLen < 2) {
|
||||
return RETURN_FAILED;
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
uint32_t encodedIndex = 0, sourceIndex = 0;
|
||||
size_t encodedIndex = 0, sourceIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (addStxEtx) {
|
||||
destStream[0] = STX;
|
||||
++encodedIndex;
|
||||
}
|
||||
while ((encodedIndex < maxDestLen) && (sourceIndex < sourceLen)) {
|
||||
|
||||
while (encodedIndex < maxDestLen and sourceIndex < sourceLen)
|
||||
{
|
||||
nextByte = sourceStream[sourceIndex];
|
||||
if ((nextByte == STX) || (nextByte == ETX) || (nextByte == 0x0D)) {
|
||||
// STX, ETX and CR characters in the stream need to be escaped with DLE
|
||||
if (nextByte == STX or nextByte == ETX or nextByte == CARRIAGE_RETURN) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = DLE;
|
||||
++encodedIndex;
|
||||
/* Escaped byte will be actual byte + 0x40. This prevents
|
||||
* STX, ETX, and carriage return characters from appearing
|
||||
* in the encoded data stream at all, so when polling an
|
||||
* encoded stream, the transmission can be stopped at ETX.
|
||||
* 0x40 was chosen at random with special requirements:
|
||||
* - Prevent going from one control char to another
|
||||
* - Prevent overflow for common characters */
|
||||
destStream[encodedIndex] = nextByte + 0x40;
|
||||
}
|
||||
} else if (nextByte == DLE) {
|
||||
}
|
||||
// DLE characters are simply escaped with DLE.
|
||||
else if (nextByte == DLE) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = DLE;
|
||||
++encodedIndex;
|
||||
destStream[encodedIndex] = DLE;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = nextByte;
|
||||
}
|
||||
++encodedIndex;
|
||||
++sourceIndex;
|
||||
}
|
||||
if ((sourceIndex == sourceLen) && (encodedIndex < maxDestLen)) {
|
||||
|
||||
if (sourceIndex == sourceLen and encodedIndex < maxDestLen) {
|
||||
if (addStxEtx) {
|
||||
destStream[encodedIndex] = ETX;
|
||||
++encodedIndex;
|
||||
}
|
||||
*encodedLen = encodedIndex;
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen) {
|
||||
size_t encodedIndex = 0, decodedIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (*sourceStream != STX) {
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
++encodedIndex;
|
||||
|
||||
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
|
||||
&& (sourceStream[encodedIndex] != ETX)
|
||||
&& (sourceStream[encodedIndex] != STX)) {
|
||||
if (sourceStream[encodedIndex] == DLE) {
|
||||
nextByte = sourceStream[encodedIndex + 1];
|
||||
// The next byte is a DLE character that was escaped by another
|
||||
// DLE character, so we can write it to the destination stream.
|
||||
if (nextByte == DLE) {
|
||||
destStream[decodedIndex] = nextByte;
|
||||
}
|
||||
else {
|
||||
/* The next byte is a STX, DTX or 0x0D character which
|
||||
* was escaped by a DLE character. The actual byte was
|
||||
* also encoded by adding + 0x40 to preven having control chars,
|
||||
* in the stream at all, so we convert it back. */
|
||||
if (nextByte == 0x42 or nextByte == 0x43 or nextByte == 0x4D) {
|
||||
destStream[decodedIndex] = nextByte - 0x40;
|
||||
}
|
||||
else {
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
}
|
||||
++encodedIndex;
|
||||
}
|
||||
else {
|
||||
destStream[decodedIndex] = sourceStream[encodedIndex];
|
||||
}
|
||||
|
||||
++encodedIndex;
|
||||
++decodedIndex;
|
||||
}
|
||||
|
||||
if (sourceStream[encodedIndex] != ETX) {
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
else {
|
||||
*readLen = ++encodedIndex;
|
||||
*decodedLen = decodedIndex;
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,79 @@
|
||||
#ifndef DLEENCODER_H_
|
||||
#define DLEENCODER_H_
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This DLE Encoder (Data Link Encoder) can be used to encode and
|
||||
* decode arbitrary data with ASCII control characters
|
||||
* @details
|
||||
* List of control codes:
|
||||
* https://en.wikipedia.org/wiki/C0_and_C1_control_codes
|
||||
*
|
||||
* This encoder can be used to achieve a basic transport layer when using
|
||||
* char based transmission systems.
|
||||
* The passed source strean is converted into a encoded stream by adding
|
||||
* a STX marker at the start of the stream and an ETX marker at the end of
|
||||
* the stream. Any STX, ETX, DLE and CR occurences in the source stream are
|
||||
* escaped by a DLE character. The encoder also replaces escaped control chars
|
||||
* by another char, so STX, ETX and CR should not appear anywhere in the actual
|
||||
* encoded data stream.
|
||||
*
|
||||
* When using a strictly char based reception of packets enoded with DLE,
|
||||
* STX can be used to notify a reader that actual data will start to arrive
|
||||
* while ETX can be used to notify the reader that the data has ended.
|
||||
*/
|
||||
class DleEncoder: public HasReturnvaluesIF {
|
||||
private:
|
||||
DleEncoder();
|
||||
virtual ~DleEncoder();
|
||||
|
||||
public:
|
||||
static const uint8_t STX = 0x02;
|
||||
static const uint8_t ETX = 0x03;
|
||||
static const uint8_t DLE = 0x10;
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER;
|
||||
static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01);
|
||||
static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02);
|
||||
|
||||
//! Start Of Text character. First character is encoded stream
|
||||
static constexpr uint8_t STX = 0x02;
|
||||
//! End Of Text character. Last character in encoded stream
|
||||
static constexpr uint8_t ETX = 0x03;
|
||||
//! Data Link Escape character. Used to escape STX, ETX and DLE occurences
|
||||
//! in the source stream.
|
||||
static constexpr uint8_t DLE = 0x10;
|
||||
static constexpr uint8_t CARRIAGE_RETURN = 0x0D;
|
||||
|
||||
/**
|
||||
* Encodes the give data stream by preceding it with the STX marker
|
||||
* and ending it with an ETX marker. STX, ETX and DLE characters inside
|
||||
* the stream are escaped by DLE characters and also replaced by adding
|
||||
* 0x40 (which is reverted in the decoing process).
|
||||
* @param sourceStream
|
||||
* @param sourceLen
|
||||
* @param destStream
|
||||
* @param maxDestLen
|
||||
* @param encodedLen
|
||||
* @param addStxEtx
|
||||
* Adding STX and ETX can be omitted, if they are added manually.
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen,
|
||||
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
|
||||
bool addStxEtx = true);
|
||||
|
||||
/**
|
||||
* Converts an encoded stream back.
|
||||
* @param sourceStream
|
||||
* @param sourceStreamLen
|
||||
* @param readLen
|
||||
* @param destStream
|
||||
* @param maxDestStreamlen
|
||||
* @param decodedLen
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t decode(const uint8_t *sourceStream,
|
||||
uint32_t sourceStreamLen, uint32_t *readLen, uint8_t *destStream,
|
||||
uint32_t maxDestStreamlen, uint32_t *decodedLen);
|
||||
|
||||
static ReturnValue_t encode(const uint8_t *sourceStream, uint32_t sourceLen,
|
||||
uint8_t *destStream, uint32_t maxDestLen, uint32_t *encodedLen,
|
||||
bool addStxEtx = true);
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen);
|
||||
};
|
||||
|
||||
#endif /* DLEENCODER_H_ */
|
||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
/**
|
||||
* @brief Type definition for CCSDS or ECSS.
|
||||
*/
|
||||
class Type: public SerializeIF {
|
||||
public:
|
||||
enum ActualType_t {
|
||||
|
@ -90,3 +90,10 @@ double timevalOperations::toDouble(const timeval timeval) {
|
||||
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
|
||||
return result / 1000000.;
|
||||
}
|
||||
|
||||
timeval timevalOperations::toTimeval(const double seconds) {
|
||||
timeval tval;
|
||||
tval.tv_sec = seconds;
|
||||
tval.tv_usec = seconds *(double) 1e6 - (tval.tv_sec *1e6);
|
||||
return tval;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ namespace timevalOperations {
|
||||
* @return seconds
|
||||
*/
|
||||
double toDouble(const timeval timeval);
|
||||
timeval toTimeval(const double seconds);
|
||||
}
|
||||
|
||||
#endif /* TIMEVALOPERATIONS_H_ */
|
||||
|
@ -1,9 +1,8 @@
|
||||
#include <framework/health/HealthHelper.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) :
|
||||
healthTable(NULL), eventSender(NULL), objectId(objectId), parentQueue(
|
||||
0), owner(owner) {
|
||||
objectId(objectId), owner(owner) {
|
||||
}
|
||||
|
||||
HealthHelper::~HealthHelper() {
|
||||
@ -40,9 +39,19 @@ void HealthHelper::setParentQueue(MessageQueueId_t parentQueue) {
|
||||
ReturnValue_t HealthHelper::initialize() {
|
||||
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
|
||||
eventSender = objectManager->get<EventReportingProxyIF>(objectId);
|
||||
if ((healthTable == NULL) || eventSender == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
||||
if (healthTable == nullptr) {
|
||||
sif::error << "HealthHelper::initialize: Health table object needs"
|
||||
"to be created in factory." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
if(eventSender == nullptr) {
|
||||
sif::error << "HealthHelper::initialize: Owner has to implement "
|
||||
"ReportingProxyIF." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t result = healthTable->registerObject(objectId,
|
||||
HasHealthIF::HEALTHY);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -62,22 +71,22 @@ void HealthHelper::setHealth(HasHealthIF::HealthState health) {
|
||||
|
||||
void HealthHelper::informParent(HasHealthIF::HealthState health,
|
||||
HasHealthIF::HealthState oldHealth) {
|
||||
if (parentQueue == 0) {
|
||||
if (parentQueue == MessageQueueMessageIF::NO_QUEUE) {
|
||||
return;
|
||||
}
|
||||
CommandMessage message;
|
||||
HealthMessage::setHealthMessage(&message, HealthMessage::HEALTH_INFO,
|
||||
CommandMessage information;
|
||||
HealthMessage::setHealthMessage(&information, HealthMessage::HEALTH_INFO,
|
||||
health, oldHealth);
|
||||
if (MessageQueueSenderIF::sendMessage(parentQueue, &message,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (MessageQueueSenderIF::sendMessage(parentQueue, &information,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "HealthHelper::informParent: sending health reply failed."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
|
||||
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(message));
|
||||
if (message->getSender() == 0) {
|
||||
void HealthHelper::handleSetHealthCommand(CommandMessage* command) {
|
||||
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(command));
|
||||
if (command->getSender() == MessageQueueMessageIF::NO_QUEUE) {
|
||||
return;
|
||||
}
|
||||
CommandMessage reply;
|
||||
@ -85,12 +94,12 @@ void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
|
||||
HealthMessage::setHealthMessage(&reply,
|
||||
HealthMessage::REPLY_HEALTH_SET);
|
||||
} else {
|
||||
reply.setReplyRejected(result, message->getCommand());
|
||||
reply.setReplyRejected(result, command->getCommand());
|
||||
}
|
||||
if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug
|
||||
<< "HealthHelper::handleHealthCommand: sending health reply failed."
|
||||
<< std::endl;
|
||||
if (MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "HealthHelper::handleHealthCommand: sending health "
|
||||
"reply failed." << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef HEALTHHELPER_H_
|
||||
#define HEALTHHELPER_H_
|
||||
#ifndef FRAMEWORK_HEALTH_HEALTHHELPER_H_
|
||||
#define FRAMEWORK_HEALTH_HEALTHHELPER_H_
|
||||
|
||||
#include <framework/events/EventManagerIF.h>
|
||||
#include <framework/events/EventReportingProxyIF.h>
|
||||
#include <framework/health/HasHealthIF.h>
|
||||
#include <framework/health/HealthMessage.h>
|
||||
#include <framework/health/HealthTableIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
@ -27,8 +28,8 @@ public:
|
||||
/**
|
||||
* ctor
|
||||
*
|
||||
* @param owner
|
||||
* @param objectId the object Id to use when communication with the HealthTable
|
||||
* @param useAsFrom id to use as from id when sending replies, can be set to 0
|
||||
*/
|
||||
HealthHelper(HasHealthIF* owner, object_id_t objectId);
|
||||
|
||||
@ -39,12 +40,12 @@ public:
|
||||
*
|
||||
* only valid after initialize() has been called
|
||||
*/
|
||||
HealthTableIF *healthTable;
|
||||
HealthTableIF *healthTable = nullptr;
|
||||
|
||||
/**
|
||||
* Proxy to forward events.
|
||||
*/
|
||||
EventReportingProxyIF* eventSender;
|
||||
EventReportingProxyIF* eventSender = nullptr;
|
||||
|
||||
/**
|
||||
* Try to handle the message.
|
||||
@ -100,7 +101,7 @@ private:
|
||||
/**
|
||||
* The Queue of the parent
|
||||
*/
|
||||
MessageQueueId_t parentQueue;
|
||||
MessageQueueId_t parentQueue = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
/**
|
||||
* The one using the healthHelper.
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class HealthMessage {
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::HEALTH_COMMAND;
|
||||
static const uint8_t MESSAGE_ID = messagetypes::HEALTH_COMMAND;
|
||||
static const Command_t HEALTH_SET = MAKE_COMMAND_ID(1);//REPLY_COMMAND_OK/REPLY_REJECTED
|
||||
static const Command_t HEALTH_ANNOUNCE = MAKE_COMMAND_ID(3); //NO REPLY!
|
||||
static const Command_t HEALTH_INFO = MAKE_COMMAND_ID(5);
|
||||
|
@ -26,7 +26,7 @@ ReturnValue_t HealthTable::registerObject(object_id_t object,
|
||||
|
||||
void HealthTable::setHealth(object_id_t object,
|
||||
HasHealthIF::HealthState newState) {
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
iter->second = newState;
|
||||
@ -36,7 +36,7 @@ void HealthTable::setHealth(object_id_t object,
|
||||
|
||||
HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
||||
HasHealthIF::HealthState state = HasHealthIF::HEALTHY;
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
state = iter->second;
|
||||
@ -46,7 +46,7 @@ HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
||||
}
|
||||
|
||||
uint32_t HealthTable::getPrintSize() {
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
uint32_t size = healthMap.size() * 5 + 2;
|
||||
mutex->unlockMutex();
|
||||
return size;
|
||||
@ -54,7 +54,7 @@ uint32_t HealthTable::getPrintSize() {
|
||||
|
||||
bool HealthTable::hasHealth(object_id_t object) {
|
||||
bool exits = false;
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
if (iter != healthMap.end()) {
|
||||
exits = true;
|
||||
@ -64,7 +64,7 @@ bool HealthTable::hasHealth(object_id_t object) {
|
||||
}
|
||||
|
||||
void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
size_t size = 0;
|
||||
uint16_t count = healthMap.size();
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&count,
|
||||
@ -85,7 +85,7 @@ void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
||||
ReturnValue_t HealthTable::iterate(
|
||||
std::pair<object_id_t, HasHealthIF::HealthState> *value, bool reset) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::BLOCKING);
|
||||
if (reset) {
|
||||
mapIterator = healthMap.begin();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef HEALTHTABLE_H_
|
||||
#define HEALTHTABLE_H_
|
||||
#ifndef FRAMEWORK_HEALTH_HEALTHTABLE_H_
|
||||
#define FRAMEWORK_HEALTH_HEALTHTABLE_H_
|
||||
|
||||
#include <framework/health/HealthTableIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user