Compare commits
709 Commits
ASTP_1.0.0
...
8f95b03e6a
Author | SHA1 | Date | |
---|---|---|---|
8f95b03e6a | |||
527dba9a9d | |||
22cd38fffd | |||
1a518109d0 | |||
8030d9ac1b | |||
992c05df56 | |||
6698d283b6 | |||
33386550cf | |||
3a65c0db91 | |||
41614303d7 | |||
783176848a | |||
07cb980e06 | |||
d8c5bd125e | |||
bf5a11cbd3 | |||
ddcac2bbac | |||
70b593df65 | |||
e5cc7069a6 | |||
98dbaf03e0 | |||
e0c50477cb | |||
30687f84c8 | |||
fed39defd3 | |||
acbc2cd749 | |||
368481f88b | |||
d2b561ba2f | |||
990e8672a8 | |||
9cde8c7f45 | |||
751de7accc | |||
74ae3f1371 | |||
02ac92a6b3 | |||
b83b2e8f89 | |||
8a39971a1c | |||
1ead156c64 | |||
5b968f7e5a | |||
b98127cea6 | |||
eba9abfc9a | |||
bf7fabd7ba | |||
cf3d4d8de3 | |||
8414c9d471 | |||
386843e3e7 | |||
441b3b83c8 | |||
c453af5911 | |||
fe95c3337a | |||
bc5a6b4a51 | |||
371ff931bf | |||
6c63d82f5c | |||
78ddce249c | |||
d93f2c5055 | |||
bd64a43819 | |||
d0c7878da4 | |||
2bd1e6acbd | |||
9697575f50 | |||
cec44ad44c | |||
661b7b44e0 | |||
d39e0c8bb6 | |||
e952a82b65 | |||
7a84dff7d6 | |||
6a6f6011ba | |||
602fa3a956 | |||
c3a0aabfb8 | |||
cbcfa8fe56 | |||
32ba4301e4 | |||
4a5204d6f6 | |||
5907f8ee9d | |||
df45f02c39 | |||
15dddd7fc4 | |||
fd7581f8ba | |||
c2bf09d506 | |||
bf31248a50 | |||
9fadc9b830 | |||
8c17c7e1a7 | |||
9c5e3565c6 | |||
ecc7f1d691 | |||
00dced31ee | |||
ab7117d81e | |||
05c4f4fadc | |||
186b3565e0 | |||
e688105073 | |||
f7c6ec329b | |||
30217aa42b | |||
0176c07886 | |||
6d5eb5b387 | |||
9a38106b57 | |||
75e16e0b7b | |||
87a15910fe | |||
9ad215c9a3 | |||
2ca7a84e86 | |||
fbeb578d1c | |||
58d4525e8a | |||
8d004e9621 | |||
a53992fdc9 | |||
c6bbc19b85 | |||
36aaf3d758 | |||
7c855592d0 | |||
cb7399b999 | |||
d675621b73 | |||
3448a8c01b | |||
42458725e8 | |||
cc7250fcf5 | |||
da42edcc0c | |||
b02f737418 | |||
1923b339e9 | |||
3c41472649 | |||
da19764232 | |||
2126e6e375 | |||
5f8adc63b7 | |||
81bae85825 | |||
e263f2fbdc | |||
8d34561137 | |||
19f9b0280c | |||
e86319707f | |||
0e653378c3 | |||
a506b94d7e | |||
7bff632042 | |||
07a0dd5331 | |||
f16dcebf6b | |||
dc6ed40bfb | |||
a5a306ff66 | |||
7122c37511 | |||
dacec0c1f6 | |||
84cd010a25 | |||
a077a1b587 | |||
b94baf838d | |||
084a3daec6 | |||
b23ed11c7e | |||
9d7d22510b | |||
76d12e3db1 | |||
cee42f9b70 | |||
afe8fe6605 | |||
6e97bd4db4 | |||
7694decaaa | |||
113c992f99 | |||
0738a0b6a4 | |||
4251ccacf9 | |||
5d31a54fba | |||
cadf97de88 | |||
01f5dfe6b4 | |||
cae3feb5da | |||
2180c47f4f | |||
c46bde417e | |||
4924da1667 | |||
f8e9042943 | |||
e6a7108614 | |||
08926f9b70 | |||
52f0c29e99 | |||
060b3a3b2c | |||
348975ba5f | |||
e8927d6aa8 | |||
b2b648c4aa | |||
fc9101cd8f | |||
d2371b3e71 | |||
ffa38a81b7 | |||
ae689408f3 | |||
155432663b | |||
ecdbf98ca4 | |||
54a6c1b0aa | |||
9efe9e78d8 | |||
d4bb9397ee | |||
bf5590ce26 | |||
460941c225 | |||
3d6f28c48d | |||
bb9ae86159 | |||
306a4b647f | |||
19061c3d50 | |||
22dbabba38 | |||
ac8df112b1 | |||
ad744fb593 | |||
6c75b56054 | |||
fb67df6d7f | |||
1b6fa9822b | |||
5798aa1e3a | |||
b00f61445d | |||
ad117e07e0 | |||
c26c2a5a96 | |||
e02ac05097 | |||
a827ec6a92 | |||
12321a5d49 | |||
ad3238aa19 | |||
f67868516c | |||
1ddf9c0f11 | |||
9bcd701a50 | |||
6ad7f51297 | |||
12983a7143 | |||
27a3598526 | |||
dd1631a456 | |||
cd6d616806 | |||
ade15ad16d | |||
76416f523d | |||
5749e159e4 | |||
85a90a6ec5 | |||
80b41e937b | |||
ab906fa534 | |||
146e1e3282 | |||
857a1624c6 | |||
f11957d827 | |||
a977302a53 | |||
198fdbba62 | |||
53400c8bfa | |||
f2d0a0d9ee | |||
9e12f59707 | |||
2439613f21 | |||
1c8f86364d | |||
4e1c52f465 | |||
c7c6d78f4b | |||
9f856761e2 | |||
2f119f102d | |||
afb472996c | |||
f76f462022 | |||
0f90d50065 | |||
b0cbd40e64 | |||
1c1433e797 | |||
7671c93095 | |||
0df5491193 | |||
897d8b37ad | |||
ba4249d658 | |||
de7542c9c1 | |||
5a30dd969f | |||
05ed25d397 | |||
0a2c912f29 | |||
65f4433fad | |||
febe3cc4d4 | |||
f388878b99 | |||
faa7e1e24f | |||
9002c12cf1 | |||
2b15f9e644 | |||
42b5f8a79d | |||
0a6a32a130 | |||
cffd77ed32 | |||
b1a9c90087 | |||
a619087fef | |||
32b5060c62 | |||
936bac5abd | |||
bf02f14772 | |||
358ee0fbf2 | |||
4f08b2d342 | |||
1622e23f1c | |||
a4d6421510 | |||
f02852d8d2 | |||
bbea5e33bc | |||
e536918804 | |||
09299802f0 | |||
4b62c8aa81 | |||
1b38f84edc | |||
5064d44999 | |||
322c14d4bb | |||
8ec35f158c | |||
9a25f08fef | |||
f3caa122ae | |||
6e88f8f400 | |||
01762ad222 | |||
71d66c406f | |||
42df77ff32 | |||
85c04dee23 | |||
4c96db847d | |||
0246dccbe9 | |||
423f7c8281 | |||
59feaa4b5c | |||
a84e60a37a | |||
061d79bb62 | |||
a37b6184fc | |||
f6b03dee6a | |||
a6bd7c0d6e | |||
f2bc374f0f | |||
52b3d9473e | |||
fc9b85d5db | |||
bfae25ff2d | |||
ea3812fbbd | |||
f40f783cb4 | |||
9429f6b868 | |||
39c909946b | |||
01c833f001 | |||
7c21980ece | |||
599ff6b45a | |||
0ddce61175 | |||
576a7293cb | |||
1732359f72 | |||
3e3c38e459 | |||
a6e4eb9ad4 | |||
e5db64cbb9 | |||
21b5eaa891 | |||
23c562bb67 | |||
5193294d25 | |||
a986b22345 | |||
646b1139a6 | |||
d9e2fd92fb | |||
ca65daab1a | |||
b3e0eeb14e | |||
2837d6e0dd | |||
cd82bebe78 | |||
1148adb43d | |||
ae27a4bb6c | |||
741d96d7ed | |||
596a056622 | |||
9c9b251322 | |||
0e0989db95 | |||
ba7acac215 | |||
af133a2928 | |||
abacfbf2d5 | |||
dae27a8e10 | |||
d36d849e69 | |||
7c7a8a5df7 | |||
134deb3f43 | |||
11a3c8c21f | |||
c9bfc8464a | |||
a88e97bc09 | |||
ea573b0523 | |||
3d336c08f2 | |||
d05eb23ea7 | |||
35b53e9a17 | |||
b5063117f6 | |||
29abef40a4 | |||
dfc44fce07 | |||
38afa494ce | |||
c42eb59d2e | |||
0a56441510 | |||
879d1f71c5 | |||
e226f19ca8 | |||
6ccf4bee49 | |||
7bf66dc401 | |||
a6d744c9c8 | |||
98e3ed897c | |||
b6aebb3061 | |||
5dcf0e44b6 | |||
3cec9f5f80 | |||
845c00044e | |||
8780c5ddcd | |||
654b23869f | |||
28f2db2c11 | |||
5fcac4d85b | |||
ece7dce6f7 | |||
4b72e246c3 | |||
92d3f0743b | |||
fa14ebbe1f | |||
db3284c2b8 | |||
517d52f55d | |||
6e9a0ddcf4 | |||
cfb8bc5dfd | |||
a18706ec53 | |||
eecb69d230 | |||
14a30f30db | |||
ccaa0aa24f | |||
d92a796705 | |||
1fa59c5cae | |||
83b5ade6b7 | |||
62873c3118 | |||
1301988892 | |||
1c3770ce96 | |||
20adc1c981 | |||
90a1571707 | |||
2706b8fa24 | |||
8b39248a33 | |||
ec00a84b29 | |||
4d9c07a1ec | |||
c3fbe04fc6 | |||
466f1e000f | |||
f1f167c2d1 | |||
6f816b2592 | |||
0e5cfcf28f | |||
dee063e259 | |||
aabc729e77 | |||
c0591c3d24 | |||
5bbe16081f | |||
490ab440e5 | |||
0b207b2b1a | |||
e1f92b3da4 | |||
b75c815361 | |||
a94725c423 | |||
2d667cfb95 | |||
3d80d5d036 | |||
ebc9d99022 | |||
2489276350 | |||
3895806a2b | |||
7b500eb0ed | |||
a918c672a5 | |||
1515d59432 | |||
ab6c616cdb | |||
ee4449b74d | |||
10e81fdfb8 | |||
ce93b9220e | |||
d4f5c31881 | |||
d47906e833 | |||
7849b8e391 | |||
08364e2dca | |||
4b03db38eb | |||
ac146339a2 | |||
cbdf92a775 | |||
4c41cb1f71 | |||
16ed5e3270 | |||
baf3d4da47 | |||
e93230d0ef | |||
0b45e5c89a | |||
6d2bfaeb3b | |||
68498f6b74 | |||
291a8d4ea3 | |||
a65a184083 | |||
21ac5afd35 | |||
aafccd191e | |||
1db5c950b8 | |||
d11e54dc0a | |||
3c364604ac | |||
8db0ca861a | |||
e2da68795b | |||
243cf42dc4 | |||
0b0e2e5f75 | |||
516e3c0f9f | |||
62e0465b3d | |||
f19f3681ca | |||
a3e6b1018b | |||
fbdff5d0b4 | |||
22693eee50 | |||
e5807c396c | |||
704193eeaf | |||
3c4289335e | |||
df1d5e5005 | |||
5f0a3f3baa | |||
f6d1b8981c | |||
8f1a54aa19 | |||
376617f9f9 | |||
82299c7e3e | |||
4803fb2cbd | |||
d5dfffda2d | |||
66a79cb86c | |||
a6de52e212 | |||
936d0e9f0c | |||
ca297a7dcd | |||
3a9add82fe | |||
eee84f9318 | |||
f14d5edf42 | |||
f15352bb2f | |||
bdb8b0a757 | |||
5adb5cce95 | |||
f427c87270 | |||
8189435b94 | |||
ff63a34384 | |||
afebe15dc2 | |||
8035af28b9 | |||
c9156e1219 | |||
da8a447073 | |||
323577cdc6 | |||
eef2fd3b7a | |||
5e960f118f | |||
c2b8507d29 | |||
b00bfe4bda | |||
38f2f69c78 | |||
2b2899e100 | |||
b52644dd2a | |||
c0c4a3190f | |||
1015cdbe88 | |||
cae69d5400 | |||
47af5260a2 | |||
1e380fe562 | |||
bd7c13ff7e
|
|||
2684e82c7f | |||
66d1d14ae3 | |||
5f9a6bb155 | |||
8a5a3c0243 | |||
2ccc0dbb00
|
|||
cfbdb10a55 | |||
ee89a2f00d
|
|||
dbfcf8b271 | |||
717971f69c
|
|||
b0a69d4c9d | |||
ecb03b8a6d
|
|||
b1f6252e30 | |||
05edb7a00c | |||
0cde65f5a1
|
|||
fbbc640f4d | |||
03e1a3e945 | |||
cc5c8ca698 | |||
996fbf134e | |||
1c7c532ef6 | |||
41e3a6b54b | |||
aa1bfcbb96 | |||
0f484abcaa | |||
c371cf4851 | |||
ad191409f4 | |||
398250c959 | |||
4b248740f3 | |||
21d213f35f | |||
105a498b93 | |||
0a0c5592f3 | |||
aa33ff2f48 | |||
3076c423c0 | |||
5f27fe6392 | |||
af99303eac | |||
1d2dabb4b4 | |||
eead2a8a49
|
|||
a7068acca7 | |||
99b007f37e | |||
7cf4aa0d5a | |||
b1e3a1b2b5 | |||
56d2af9d25 | |||
dadba69272 | |||
40a8c9a495 | |||
8dc66784a8 | |||
d0f37b851b | |||
1b6759020a | |||
537a30a4de | |||
a993872884 | |||
d700fb551c | |||
73bae057bd | |||
589e64fc46 | |||
1630682548 | |||
4b095eea89 | |||
fb7b059137 | |||
bc151983b5 | |||
40b2979ce8 | |||
7030d3e108 | |||
41cb8cb8ae | |||
75adf52d28 | |||
0157681471 | |||
b6b144bcdb | |||
145dd33fb1 | |||
50fac22f54 | |||
8b83541264 | |||
57699cccb7 | |||
33e7c635c5 | |||
070c3f3bbf | |||
3891014340 | |||
c3be4cdee6 | |||
6b9747ee0b | |||
ad820fbe99 | |||
722a7b3240 | |||
442b9370ae | |||
54e60f4ddc | |||
e961f3f038 | |||
c9836abf03 | |||
404c3821e6 | |||
567699954c | |||
43d4953e4a | |||
e6059812b5 | |||
f0a7b1cad2 | |||
e46615e830 | |||
e7ac2c7009 | |||
95c6a24437 | |||
237ba8112b | |||
aab3fd828b | |||
46cfe7452a | |||
e6868464bf | |||
e15f03fb0a | |||
59e7f0caae | |||
a2deac3441 | |||
5eadcaf10d | |||
2bf5a972e1 | |||
5d2c62e75d | |||
5ac68f731e | |||
7fa0443725 | |||
f4cb63c53c | |||
0cde6f317d | |||
2737bc390c | |||
07ba05b209 | |||
f3d9fb645e | |||
e9adaf672f | |||
fc4e65b2fc | |||
36030ef87c | |||
b7060a9c78 | |||
e147d5a4f5 | |||
a8c0d96c39 | |||
ed27d388d5 | |||
e2ae9756f3 | |||
c07672f9b4 | |||
6db2efc20d | |||
94062c67d3 | |||
9e0146f579 | |||
d3423b30b0 | |||
58a532fc4d | |||
ac027e3ff2 | |||
ff6b4134a5 | |||
5847081a24 | |||
0bc124fd21 | |||
1e9c789287 | |||
b06113993c | |||
4fa56a2f1d | |||
a320e3e1ef | |||
4095be449a | |||
d20f0c5da1 | |||
9496ed42e2 | |||
14027e449c | |||
1626b266d7 | |||
d27f49c968 | |||
a6dd2d5dcb | |||
8293e6b0c7 | |||
d81c6f40fb | |||
5b23b928cf | |||
cd016c8281 | |||
e1c91f82b7 | |||
9d0155d9ae
|
|||
d807998f4d | |||
8b17c40aa6 | |||
d7d24bd9aa | |||
c1d30aad13 | |||
126def219b | |||
08b9e92d25 | |||
86431c854b | |||
f3530d3c7e | |||
0a76c5b0b5 | |||
6ede3f9ba2 | |||
097244bf8b | |||
5c9b1769c1 | |||
413ff0d1b9 | |||
5273ffa721 | |||
e7c00b5633 | |||
f2ab07c782 | |||
ff33a1274d | |||
e7cfd324ae | |||
52b549b97c | |||
cac9a0eecd | |||
56d43f5b49 | |||
10e7e42388 | |||
fc34e7fd75 | |||
18a9729c75 | |||
763347f203 | |||
1ff52e43a0 | |||
7f1cbaef23 | |||
3356ccc9d4 | |||
3f91803422 | |||
5759c2cbe6 | |||
e45b8bc739 | |||
dcd72d421e | |||
cc8c3aef3d | |||
9352e15405 | |||
1cceda8e63 | |||
8c4381eca6 | |||
29a05eb113 | |||
534b4850df | |||
a66fc53396 | |||
5471030c32 | |||
770356f8b6 | |||
62e409a9f2 | |||
cf8a9996a7 | |||
fc7e401ddc | |||
ed186b04df | |||
f906605097 | |||
9a2fbefc9f | |||
07f1216316 | |||
4faa5b0685 | |||
ae1dab1fce | |||
9a5f717169 | |||
d7d52439d7 | |||
5d93cf12f7 | |||
438049bb80 | |||
6e6fb62b3c | |||
7b8928ef47 | |||
924ea420a9 | |||
fbe860c6a5 | |||
8b266aa542 | |||
5144cbd789 | |||
720ce59680 | |||
f1ffa88e07 | |||
d4b26825af | |||
7e249db15e | |||
83e7dbb1f0 | |||
2e417c787d | |||
316310e993 | |||
6db0725aa4 | |||
e0d39b1feb | |||
d9a0a4f2ea | |||
b8c7a65709 | |||
d3c3a9147a | |||
40cc3c383b | |||
d92a20a669 | |||
c1f4ae08fb | |||
2b84ab018c | |||
9e881b6a16 | |||
905d525aa2 | |||
e6a1a7cc2d | |||
dd367bf083 | |||
8f4ab6d7ed | |||
b30a3aaa38 | |||
efb7c8760a | |||
bddd8720b2 | |||
00d9a4f3ed | |||
f988271be4 | |||
38d929c2a8 | |||
e799e45198 | |||
9ee1bd15c4 | |||
cbeb78f089 | |||
80aab5f461 | |||
43ddb44573 | |||
9f8a345e35 | |||
3ff5484415 | |||
7322a7d0f5 | |||
0e76333d33 | |||
dea2205908 | |||
d1a256cbf6 | |||
f2da31239c | |||
42720e6f7d | |||
83d0db8242 | |||
533d164cac | |||
0e92fa4046 | |||
32b289cbec | |||
fa108f0a3b | |||
f82cc1bca4 | |||
778ef4ef23 | |||
17b8d3fed0 | |||
d57955ade7 | |||
18e40d6248 | |||
41e30dcb6c | |||
92f249dc62 | |||
f3cc664d4f | |||
91f69aa34f | |||
8b561d073c | |||
c55cf8f279 | |||
c5b2c47af4 | |||
f0178a8f73 | |||
e1b57424f8 | |||
8d7d4c639a | |||
a3d245f5a0 | |||
1ccfb74709 | |||
939fa16d1a |
7
.clang-format
Normal file
7
.clang-format
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 2
|
||||
---
|
||||
Language: Cpp
|
||||
ColumnLimit: 100
|
||||
---
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
.project
|
||||
.settings
|
||||
.metadata
|
||||
|
||||
/build*
|
||||
|
79
CHANGELOG
79
CHANGELOG
@ -1,4 +1,81 @@
|
||||
## Changes from ASTP 0.0.1 to 1.0.0
|
||||
# Changed from ASTP 1.1.0 to 1.2.0
|
||||
|
||||
## API Changes
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- New src folder which contains all source files except the HAL, contributed code and test code
|
||||
- External and internal API mostly stayed the same
|
||||
- Folder names are now all smaller case: internalError was renamed to internalerror and
|
||||
FreeRTOS was renamed to freertos
|
||||
- Warning if optional headers are used but the modules was not added to the source files to compile
|
||||
|
||||
### HAL
|
||||
|
||||
- HAL added back into FSFW. It is tightly bound to the FSFW, and compiling it as a static library
|
||||
made using it more complicated than necessary
|
||||
|
||||
## Bugfixes
|
||||
|
||||
### FreeRTOS QueueMapManager
|
||||
|
||||
- Fixed a bug which causes the first generated Queue ID to be invalid
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- See API changes chapter. This change will keep the internal API consistent in the future
|
||||
|
||||
# Changes from ASTP 1.0.0 to 1.1.0
|
||||
|
||||
## API Changes
|
||||
|
||||
### PUS
|
||||
|
||||
- Added PUS C support
|
||||
- SUBSYSTEM_IDs added for PUS Services
|
||||
- Added new Parameter which must be defined in config: fsfwconfig::FSFW_MAX_TM_PACKET_SIZE
|
||||
|
||||
### ObjectManager
|
||||
|
||||
- ObjectManager is now a singelton
|
||||
|
||||
|
||||
### Configuration
|
||||
|
||||
- Additional configuration option fsfwconfig::FSFW_MAX_TM_PACKET_SIZE which
|
||||
need to be specified in FSFWConfig.h
|
||||
|
||||
### CMake
|
||||
|
||||
- Changed Cmake FSFW_ADDITIONAL_INC_PATH to FSFW_ADDITIONAL_INC_PATHS
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- timemanager/TimeStamperIF.h: Timestamp config was not used correctly, leading to different timestamp sizes than configured in fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE
|
||||
- TCP server fixes
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FreeRTOS Queue Handles
|
||||
|
||||
- Fixed an internal issue how FreeRTOS MessageQueues were handled
|
||||
|
||||
### Linux OSAL
|
||||
|
||||
- Better printf error messages
|
||||
|
||||
### CMake
|
||||
|
||||
- Check for C++11 as mininimum required Version
|
||||
|
||||
### Debug Output
|
||||
|
||||
- Changed Warning color to magenta, which is well readable on both dark and light mode IDEs
|
||||
|
||||
|
||||
# Changes from ASTP 0.0.1 to 1.0.0
|
||||
|
||||
### Host OSAL
|
||||
|
||||
|
302
CMakeLists.txt
302
CMakeLists.txt
@ -1,124 +1,249 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(FSFW_VERSION 2)
|
||||
set(FSFW_SUBVERSION 0)
|
||||
set(FSFW_REVISION 0)
|
||||
|
||||
# Add the cmake folder so the FindSphinx module is found
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
|
||||
option(FSFW_GENERATE_SECTIONS
|
||||
"Generate function and data sections. Required to remove unused code" ON
|
||||
)
|
||||
|
||||
if(FSFW_GENERATE_SECTIONS)
|
||||
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
|
||||
endif()
|
||||
|
||||
option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF)
|
||||
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
|
||||
endif()
|
||||
|
||||
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
||||
# Options to exclude parts of the FSFW from compilation.
|
||||
option(FSFW_USE_RMAP "Compile with RMAP" ON)
|
||||
option(FSFW_USE_DATALINKLAYER "Compile with Data Link Layer" ON)
|
||||
option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
|
||||
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
|
||||
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
|
||||
|
||||
# Optional sources
|
||||
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
|
||||
option(FSFW_ADD_MONITORING "Compile with monitoring components" ON)
|
||||
|
||||
option(FSFW_ADD_RMAP "Compile with RMAP" OFF)
|
||||
option(FSFW_ADD_DATALINKLAYER "Compile with Data Link Layer" OFF)
|
||||
option(FSFW_ADD_COORDINATES "Compile with coordinate components" OFF)
|
||||
option(FSFW_ADD_TMSTORAGE "Compile with tm storage components" OFF)
|
||||
|
||||
# Contrib sources
|
||||
option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
|
||||
|
||||
set(LIB_FSFW_NAME fsfw)
|
||||
set(FSFW_TEST_TGT fsfw-tests)
|
||||
set(FSFW_DUMMY_TGT fsfw-dummy)
|
||||
|
||||
project(${LIB_FSFW_NAME})
|
||||
add_library(${LIB_FSFW_NAME})
|
||||
|
||||
set_property(CACHE OS_FSFW PROPERTY STRINGS host linux rtems freertos)
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
message(STATUS "Building the FSFW unittests in addition to the static library")
|
||||
# Check whether the user has already installed Catch2 first
|
||||
find_package(Catch2 3)
|
||||
# Not installed, so use FetchContent to download and provide Catch2
|
||||
if(NOT Catch2_FOUND)
|
||||
include(FetchContent)
|
||||
|
||||
if(NOT OS_FSFW)
|
||||
message(STATUS "No OS for FSFW via OS_FSFW set. Assuming host OS")
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.0.0-preview4
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
endif()
|
||||
|
||||
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
||||
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
||||
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h)
|
||||
|
||||
project(${FSFW_TEST_TGT} CXX C)
|
||||
add_executable(${FSFW_TEST_TGT})
|
||||
|
||||
if(FSFW_TESTS_GEN_COV)
|
||||
message(STATUS "Generating coverage data for the library")
|
||||
message(STATUS "Targets linking against ${LIB_FSFW_NAME} "
|
||||
"will be compiled with coverage data as well"
|
||||
)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cmake-modules
|
||||
GIT_REPOSITORY https://github.com/bilke/cmake-modules.git
|
||||
)
|
||||
FetchContent_MakeAvailable(cmake-modules)
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR})
|
||||
include(CodeCoverage)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(FSFW_CORE_INC_PATH "inc")
|
||||
|
||||
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos)
|
||||
|
||||
# For configure files
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
elseif(${CMAKE_CXX_STANDARD} LESS 11)
|
||||
message(FATAL_ERROR "Compiling the FSFW requires a minimum of C++11 support")
|
||||
endif()
|
||||
|
||||
# Backwards comptability
|
||||
if(OS_FSFW AND NOT FSFW_OSAL)
|
||||
message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
|
||||
set(FSFW_OSAL OS_FSFW)
|
||||
endif()
|
||||
|
||||
if(NOT FSFW_OSAL)
|
||||
message(STATUS "No OS for FSFW via FSFW_OSAL set. Assuming host OS")
|
||||
# Assume host OS and autodetermine from OS_FSFW
|
||||
if(UNIX)
|
||||
set(OS_FSFW "linux"
|
||||
set(FSFW_OSAL "linux"
|
||||
CACHE STRING
|
||||
"OS abstraction layer used in the FSFW"
|
||||
)
|
||||
elseif(WIN32)
|
||||
set(OS_FSFW "host"
|
||||
set(FSFW_OSAL "host"
|
||||
CACHE STRING "OS abstraction layer used in the FSFW"
|
||||
)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
set(FSFW_OSAL_DEFINITION FSFW_HOST)
|
||||
set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST)
|
||||
|
||||
if(${OS_FSFW} STREQUAL host)
|
||||
set(OS_FSFW_NAME "Host")
|
||||
elseif(${OS_FSFW} STREQUAL linux)
|
||||
set(OS_FSFW_NAME "Linux")
|
||||
set(FSFW_OSAL_DEFINITION FSFW_LINUX)
|
||||
elseif(${OS_FSFW} STREQUAL freertos)
|
||||
set(OS_FSFW_NAME "FreeRTOS")
|
||||
set(FSFW_OSAL_DEFINITION FSFW_FREERTOS)
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
if(FSFW_OSAL MATCHES host)
|
||||
set(FSFW_OS_NAME "Host")
|
||||
set(FSFW_OSAL_HOST ON)
|
||||
elseif(FSFW_OSAL MATCHES linux)
|
||||
set(FSFW_OS_NAME "Linux")
|
||||
set(FSFW_OSAL_LINUX ON)
|
||||
elseif(FSFW_OSAL MATCHES freertos)
|
||||
set(FSFW_OS_NAME "FreeRTOS")
|
||||
set(FSFW_OSAL_FREERTOS ON)
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
${LIB_OS_NAME}
|
||||
)
|
||||
elseif(${OS_FSFW} STREQUAL rtems)
|
||||
set(OS_FSFW_NAME "RTEMS")
|
||||
set(FSFW_OSAL_DEFINITION FSFW_RTEMS)
|
||||
)
|
||||
elseif(FSFW_OSAL STREQUAL rtems)
|
||||
set(FSFW_OS_NAME "RTEMS")
|
||||
set(FSFW_OSAL_RTEMS ON)
|
||||
else()
|
||||
message(WARNING
|
||||
"Invalid operating system for FSFW specified! Setting to host.."
|
||||
)
|
||||
set(OS_FSFW_NAME "Host")
|
||||
set(OS_FSFW "host")
|
||||
message(WARNING
|
||||
"Invalid operating system for FSFW specified! Setting to host.."
|
||||
)
|
||||
set(FSFW_OS_NAME "Host")
|
||||
set(OS_FSFW "host")
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${LIB_FSFW_NAME} PRIVATE
|
||||
${FSFW_OSAL_DEFINITION}
|
||||
)
|
||||
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
||||
|
||||
target_compile_definitions(${LIB_FSFW_NAME} INTERFACE
|
||||
${FSFW_OSAL_DEFINITION}
|
||||
)
|
||||
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
||||
|
||||
message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.")
|
||||
|
||||
add_subdirectory(action)
|
||||
add_subdirectory(container)
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(coordinates)
|
||||
|
||||
if(FSFW_USE_DATALINKLAYER)
|
||||
add_subdirectory(datalinklayer)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
if(FSFW_ADD_HAL)
|
||||
add_subdirectory(hal)
|
||||
endif()
|
||||
add_subdirectory(contrib)
|
||||
if(FSFW_BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
add_subdirectory(datapool)
|
||||
add_subdirectory(datapoollocal)
|
||||
add_subdirectory(housekeeping)
|
||||
add_subdirectory(devicehandlers)
|
||||
add_subdirectory(events)
|
||||
add_subdirectory(fdir)
|
||||
add_subdirectory(globalfunctions)
|
||||
add_subdirectory(health)
|
||||
add_subdirectory(internalError)
|
||||
add_subdirectory(ipc)
|
||||
add_subdirectory(memory)
|
||||
add_subdirectory(modes)
|
||||
add_subdirectory(monitoring)
|
||||
add_subdirectory(objectmanager)
|
||||
add_subdirectory(osal)
|
||||
add_subdirectory(parameters)
|
||||
add_subdirectory(power)
|
||||
add_subdirectory(pus)
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
if(FSFW_TESTS_GEN_COV)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
include(CodeCoverage)
|
||||
|
||||
if(FSFW_USE_RMAP)
|
||||
add_subdirectory(rmap)
|
||||
# Remove quotes.
|
||||
separate_arguments(COVERAGE_COMPILER_FLAGS
|
||||
NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}"
|
||||
)
|
||||
|
||||
# Add compile options manually, we don't want coverage for Catch2
|
||||
target_compile_options(${FSFW_TEST_TGT} PRIVATE
|
||||
"${COVERAGE_COMPILER_FLAGS}"
|
||||
)
|
||||
target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
||||
"${COVERAGE_COMPILER_FLAGS}"
|
||||
)
|
||||
|
||||
# Exclude directories here
|
||||
if(WIN32)
|
||||
set(GCOVR_ADDITIONAL_ARGS
|
||||
"--exclude-throw-branches"
|
||||
"--exclude-unreachable-branches"
|
||||
)
|
||||
set(COVERAGE_EXCLUDES
|
||||
"/c/msys64/mingw64/*" "*/fsfw_hal/*"
|
||||
)
|
||||
elseif(UNIX)
|
||||
set(COVERAGE_EXCLUDES
|
||||
"/usr/include/*" "/usr/bin/*" "Catch2/*"
|
||||
"/usr/local/include/*" "*/fsfw_tests/*"
|
||||
"*/catch2-src/*" "*/fsfw_hal/*"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_options(${FSFW_TEST_TGT} PRIVATE
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
target_link_options(${LIB_FSFW_NAME} PRIVATE
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
# Need to specify this as an interface, otherwise there will the compile issues
|
||||
target_link_options(${LIB_FSFW_NAME} INTERFACE
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
setup_target_for_coverage_gcovr_html(
|
||||
NAME ${FSFW_TEST_TGT}_coverage
|
||||
EXECUTABLE ${FSFW_TEST_TGT}
|
||||
DEPENDENCIES ${FSFW_TEST_TGT}
|
||||
)
|
||||
else()
|
||||
setup_target_for_coverage_lcov(
|
||||
NAME ${FSFW_TEST_TGT}_coverage
|
||||
EXECUTABLE ${FSFW_TEST_TGT}
|
||||
DEPENDENCIES ${FSFW_TEST_TGT}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
target_link_libraries(${FSFW_TEST_TGT} PRIVATE Catch2::Catch2 ${LIB_FSFW_NAME})
|
||||
endif()
|
||||
|
||||
add_subdirectory(serialize)
|
||||
add_subdirectory(serviceinterface)
|
||||
add_subdirectory(storagemanager)
|
||||
add_subdirectory(subsystem)
|
||||
add_subdirectory(tasks)
|
||||
add_subdirectory(tcdistribution)
|
||||
add_subdirectory(thermal)
|
||||
add_subdirectory(timemanager)
|
||||
add_subdirectory(tmstorage)
|
||||
add_subdirectory(tmtcpacket)
|
||||
add_subdirectory(tmtcservices)
|
||||
add_subdirectory(unittest)
|
||||
|
||||
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
||||
# If this is not given, we include the default configuration and emit a warning.
|
||||
if(NOT FSFW_CONFIG_PATH)
|
||||
message(WARNING "Flight Software Framework configuration path not set!")
|
||||
message(WARNING "Setting default configuration!")
|
||||
add_subdirectory(defaultcfg/fsfwconfig)
|
||||
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
||||
if(NOT FSFW_BUILD_DOCS)
|
||||
message(WARNING "Flight Software Framework configuration path not set!")
|
||||
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||
endif()
|
||||
add_subdirectory(${DEF_CONF_PATH})
|
||||
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
|
||||
endif()
|
||||
|
||||
# FSFW might be part of a possibly complicated folder structure, so we
|
||||
@ -131,9 +256,9 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATH})
|
||||
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATHS})
|
||||
if(IS_ABSOLUTE ${INCLUDE_PATH})
|
||||
set(CURR_ABS_INC_PATH "${FREERTOS_PATH}")
|
||||
set(CURR_ABS_INC_PATH "${INCLUDE_PATH}")
|
||||
else()
|
||||
get_filename_component(CURR_ABS_INC_PATH
|
||||
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
|
||||
@ -184,6 +309,7 @@ endif()
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${FSFW_CONFIG_PATH_ABSOLUTE}
|
||||
${FSFW_CORE_INC_PATH}
|
||||
${FSFW_ADD_INC_PATHS_ABS}
|
||||
)
|
||||
|
||||
@ -193,6 +319,7 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${FSFW_CONFIG_PATH_ABSOLUTE}
|
||||
${FSFW_CORE_INC_PATH}
|
||||
${FSFW_ADD_INC_PATHS_ABS}
|
||||
)
|
||||
|
||||
@ -203,4 +330,17 @@ target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
||||
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
${FSFW_ADDITIONAL_LINK_LIBS}
|
||||
)
|
||||
)
|
||||
|
||||
string(CONCAT POST_BUILD_COMMENT
|
||||
"######################################################################\n"
|
||||
"Built FSFW v${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}, "
|
||||
"Target OSAL: ${FSFW_OS_NAME}\n"
|
||||
"######################################################################\n"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${LIB_FSFW_NAME}
|
||||
POST_BUILD
|
||||
COMMENT ${POST_BUILD_COMMENT}
|
||||
)
|
||||
|
@ -1,12 +0,0 @@
|
||||
#ifndef FSFW_DEFAULTCFG_VERSION_H_
|
||||
#define FSFW_DEFAULTCFG_VERSION_H_
|
||||
|
||||
const char* const FSFW_VERSION_NAME = "ASTP";
|
||||
|
||||
#define FSFW_VERSION 1
|
||||
#define FSFW_SUBVERSION 0
|
||||
#define FSFW_REVISION 0
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DEFAULTCFG_VERSION_H_ */
|
106
README.md
106
README.md
@ -1,4 +1,4 @@
|
||||

|
||||

|
||||
|
||||
# Flight Software Framework (FSFW)
|
||||
|
||||
@ -22,27 +22,107 @@ Currently, the FSFW provides the following OSALs:
|
||||
- FreeRTOS
|
||||
- RTEMS
|
||||
|
||||
The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile Memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a ISISPACE IOBC or a Zynq-7020 SoC. The `fsfw` was also successfully run on the STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active satellite mission Flying Laptop.
|
||||
The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile
|
||||
memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a
|
||||
ISISPACE IOBC or a Zynq-7020 SoC. The `fsfw` was also successfully run on the
|
||||
STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active
|
||||
satellite mission Flying Laptop.
|
||||
|
||||
## Getting started
|
||||
|
||||
The [FSFW example](https://egit.irs.uni-stuttgart.de/fsfw/fsfw_example) provides a good starting point and a demo to see the FSFW capabilities and build it with the Make or the CMake build system. It is recommended to evaluate the FSFW by building and playing around with the demo application.
|
||||
The [Hosted FSFW example](https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted) provides a
|
||||
good starting point and a demo to see the FSFW capabilities.
|
||||
It is recommended to get started by building and playing around with the demo application.
|
||||
There are also other examples provided for all OSALs using the popular embedded platforms
|
||||
Raspberry Pi, Beagle Bone Black and STM32H7.
|
||||
|
||||
Generally, the FSFW is included in a project by compiling the FSFW sources and providing
|
||||
a configuration folder and adding it to the include path. There are some functions like `printChar` which are different depending on the target architecture and need to be implemented by the mission developer.
|
||||
Generally, the FSFW is included in a project by providing
|
||||
a configuration folder, building the static library and linking against it.
|
||||
There are some functions like `printChar` which are different depending on the target architecture
|
||||
and need to be implemented by the mission developer.
|
||||
|
||||
A template configuration folder was provided and can be copied into the project root to have
|
||||
a starting point. The [configuration section](doc/README-config.md#top) provides more specific information about the possible options.
|
||||
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||
information about the possible options.
|
||||
|
||||
## Adding the library
|
||||
|
||||
The following steps show how to add and use FSFW components. It is still recommended to
|
||||
try out the example mentioned above to get started, but the following steps show how to
|
||||
add and link against the FSFW library in general.
|
||||
|
||||
1. Add this repository as a submodule
|
||||
|
||||
```sh
|
||||
git submodule add https://egit.irs.uni-stuttgart.de/fsfw/fsfw.git fsfw
|
||||
```
|
||||
|
||||
2. Add the following directive inside the uppermost `CMakeLists.txt` file of your project
|
||||
|
||||
```cmake
|
||||
add_subdirectory(fsfw)
|
||||
```
|
||||
|
||||
3. Make sure to provide a configuration folder and supply the path to that folder with
|
||||
the `FSFW_CONFIG_PATH` CMake variable from the uppermost `CMakeLists.txt` file.
|
||||
It is also necessary to provide the `printChar` function. You can find an example
|
||||
implementation for a hosted build
|
||||
[here](https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/bsp_hosted/utility/printChar.c).
|
||||
|
||||
4. Link against the FSFW library
|
||||
|
||||
```cmake
|
||||
target_link_libraries(<YourProjectName> PRIVATE fsfw)
|
||||
```
|
||||
|
||||
5. It should now be possible use the FSFW as a static library from the user code.
|
||||
|
||||
## Building the unittests
|
||||
|
||||
The FSFW also has unittests which use the [Catch2 library](https://github.com/catchorg/Catch2).
|
||||
These are built by setting the CMake option `FSFW_BUILD_UNITTESTS` to `ON` or `TRUE`
|
||||
from your project `CMakeLists.txt` file or from the command line.
|
||||
|
||||
The fsfw-tests binary will be built as part of the static library and dropped alongside it.
|
||||
If the unittests are built, the library and the tests will be built with coverage information by
|
||||
default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`.
|
||||
|
||||
You can use the following commands inside the `fsfw` folder to set up the build system
|
||||
|
||||
```sh
|
||||
mkdir build-Unittest && cd build-Unittest
|
||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
|
||||
```
|
||||
|
||||
You can also use `-DFSFW_OSAL=linux` on Linux systems.
|
||||
|
||||
Coverage data in HTML format can be generated using the `CodeCoverage`
|
||||
[CMake module](https://github.com/bilke/cmake-modules/tree/master).
|
||||
To build the unittests, run them and then generare the coverage data in this format,
|
||||
the following command can be used inside the build directory after the build system was set up
|
||||
|
||||
```sh
|
||||
cmake --build . -- fsfw-tests_coverage -j
|
||||
```
|
||||
|
||||
The `coverage.py` script located in the `script` folder can also be used to do this conveniently.
|
||||
|
||||
## Formatting the sources
|
||||
|
||||
The formatting is done by the `clang-format` tool. The configuration is contained within the
|
||||
`.clang-format` file in the repository root. As long as `clang-format` is installed, you
|
||||
can run the `apply-clang-format.sh` helper script to format all source files consistently.
|
||||
|
||||
## Index
|
||||
|
||||
[1. High-level overview](doc/README-highlevel.md#top) <br>
|
||||
[2. Core components](doc/README-core.md#top) <br>
|
||||
[3. OSAL overview](doc/README-osal.md#top) <br>
|
||||
[4. PUS services](doc/README-pus.md#top) <br>
|
||||
[5. Device Handler overview](doc/README-devicehandlers.md#top) <br>
|
||||
[6. Controller overview](doc/README-controllers.md#top) <br>
|
||||
[7. Local Data Pools](doc/README-localpools.md#top) <br>
|
||||
[1. High-level overview](docs/README-highlevel.md#top) <br>
|
||||
[2. Core components](docs/README-core.md#top) <br>
|
||||
[3. Configuration](docs/README-config.md#top) <br>
|
||||
[4. OSAL overview](docs/README-osal.md#top) <br>
|
||||
[5. PUS services](docs/README-pus.md#top) <br>
|
||||
[6. Device Handler overview](docs/README-devicehandlers.md#top) <br>
|
||||
[7. Controller overview](docs/README-controllers.md#top) <br>
|
||||
[8. Local Data Pools](docs/README-localpools.md#top) <br>
|
||||
|
||||
|
||||
|
||||
|
@ -1,167 +0,0 @@
|
||||
#include "ActionHelper.h"
|
||||
#include "HasActionsIF.h"
|
||||
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
|
||||
ActionHelper::ActionHelper(HasActionsIF* setOwner,
|
||||
MessageQueueIF* useThisQueue) :
|
||||
owner(setOwner), queueToUse(useThisQueue) {
|
||||
}
|
||||
|
||||
ActionHelper::~ActionHelper() {
|
||||
}
|
||||
|
||||
ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) {
|
||||
if (command->getCommand() == ActionMessage::EXECUTE_ACTION) {
|
||||
ActionId_t currentAction = ActionMessage::getActionId(command);
|
||||
prepareExecution(command->getSender(), currentAction,
|
||||
ActionMessage::getStoreId(command));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return CommandMessage::UNKNOWN_COMMAND;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if(queueToUse_ != nullptr) {
|
||||
setQueueToUse(queueToUse_);
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo,
|
||||
ActionId_t commandId, ReturnValue_t result) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result);
|
||||
queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t commandId,
|
||||
ReturnValue_t result) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setCompletionReply(&reply, commandId, success, result);
|
||||
queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
void ActionHelper::setQueueToUse(MessageQueueIF* queue) {
|
||||
queueToUse = queue;
|
||||
}
|
||||
|
||||
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress) {
|
||||
const uint8_t* dataPtr = NULL;
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
return;
|
||||
}
|
||||
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
|
||||
ipcStore->deleteData(dataAddress);
|
||||
if(result == HasActionsIF::EXECUTION_FINISHED) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setCompletionReply(&reply, actionId, true, result);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
}
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
ActionId_t replyId, SerializeIF* data, bool hideSender) {
|
||||
CommandMessage reply;
|
||||
store_address_t storeAddress;
|
||||
uint8_t *dataPtr;
|
||||
size_t maxSize = data->getSerializedSize();
|
||||
if (maxSize == 0) {
|
||||
/* No error, there's simply nothing to report. */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize,
|
||||
&dataPtr);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "ActionHelper::reportData: Getting free element from IPC store failed!" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printWarning("ActionHelper::reportData: Getting free element from IPC "
|
||||
"store failed!\n");
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
result = data->serialize(&dataPtr, &size, maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ipcStore->deleteData(storeAddress);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* We don't need to report the objectId, as we receive REQUESTED data before the completion
|
||||
success message. True aperiodic replies need to be reported with another dedicated message. */
|
||||
ActionMessage::setDataReply(&reply, replyId, storeAddress);
|
||||
|
||||
/* If the sender needs to be hidden, for example to handle packet
|
||||
as unrequested reply, this will be done here. */
|
||||
if (hideSender) {
|
||||
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
|
||||
}
|
||||
else {
|
||||
result = queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK){
|
||||
ipcStore->deleteData(storeAddress);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ActionHelper::resetHelper() {
|
||||
}
|
||||
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
ActionId_t replyId, const uint8_t *data, size_t dataSize,
|
||||
bool hideSender) {
|
||||
CommandMessage reply;
|
||||
store_address_t storeAddress;
|
||||
ReturnValue_t result = ipcStore->addData(&storeAddress, data, dataSize);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "ActionHelper::reportData: Adding data to IPC store failed!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("ActionHelper::reportData: Adding data to IPC store failed!\n");
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
/* We don't need to report the objectId, as we receive REQUESTED data before the completion
|
||||
success message. True aperiodic replies need to be reported with another dedicated message. */
|
||||
ActionMessage::setDataReply(&reply, replyId, storeAddress);
|
||||
|
||||
/* If the sender needs to be hidden, for example to handle packet
|
||||
as unrequested reply, this will be done here. */
|
||||
if (hideSender) {
|
||||
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
|
||||
}
|
||||
else {
|
||||
result = queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ipcStore->deleteData(storeAddress);
|
||||
}
|
||||
return result;
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
#ifndef FSFW_ACTION_ACTIONHELPER_H_
|
||||
#define FSFW_ACTION_ACTIONHELPER_H_
|
||||
|
||||
#include "ActionMessage.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
/**
|
||||
* @brief Action Helper is a helper class which handles action messages
|
||||
*
|
||||
* Components which use the HasActionIF this helper can be used to handle
|
||||
* the action messages.
|
||||
* It does handle step messages as well as other answers to action calls.
|
||||
* It uses the executeAction function of its owner as callback.
|
||||
* The call of the initialize function is mandatory and needs a
|
||||
* valid MessageQueueIF pointer!
|
||||
*/
|
||||
class HasActionsIF;
|
||||
|
||||
class ActionHelper {
|
||||
public:
|
||||
/**
|
||||
* Constructor of the action helper
|
||||
* @param setOwner Pointer to the owner of the interface
|
||||
* @param useThisQueue messageQueue to be used, can be set during
|
||||
* initialize function as well.
|
||||
*/
|
||||
ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue);
|
||||
|
||||
virtual ~ActionHelper();
|
||||
/**
|
||||
* Function to be called from the owner with a new command message
|
||||
*
|
||||
* If the message is a valid action message the helper will use the
|
||||
* executeAction function from HasActionsIF.
|
||||
* If the message is invalid or the callback fails a message reply will be
|
||||
* send to the sender of the message automatically.
|
||||
*
|
||||
* @param command Pointer to a command message received by the owner
|
||||
* @return HasReturnvaluesIF::RETURN_OK if the message is a action message,
|
||||
* CommandMessage::UNKNOW_COMMAND if this message ID is unkown
|
||||
*/
|
||||
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
|
||||
* @return Returns RETURN_OK if successful
|
||||
*/
|
||||
ReturnValue_t initialize(MessageQueueIF* queueToUse_ = nullptr);
|
||||
/**
|
||||
* Function to be called from the owner to send a step message.
|
||||
* Success or failure will be determined by the result value.
|
||||
*
|
||||
* @param step Number of steps already done
|
||||
* @param reportTo The messageQueueId to report the step message to
|
||||
* @param commandId ID of the executed command
|
||||
* @param result Result of the execution
|
||||
*/
|
||||
void step(uint8_t step, MessageQueueId_t reportTo,
|
||||
ActionId_t commandId,
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
/**
|
||||
* Function to be called by the owner to send a action completion message
|
||||
* @param success Specify whether action was completed successfully or not.
|
||||
* @param reportTo MessageQueueId_t to report the action completion message to
|
||||
* @param commandId ID of the executed command
|
||||
* @param result Result of the execution
|
||||
*/
|
||||
void finish(bool success, MessageQueueId_t reportTo, ActionId_t commandId,
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
/**
|
||||
* Function to be called by the owner if an action does report data.
|
||||
* Takes a SerializeIF* pointer and serializes it into the IPC store.
|
||||
* @param reportTo MessageQueueId_t to report the action completion
|
||||
* message to
|
||||
* @param replyId ID of the executed command
|
||||
* @param data Pointer to the data
|
||||
* @return Returns RETURN_OK if successful, otherwise failure code
|
||||
*/
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
SerializeIF* data, bool hideSender = false);
|
||||
/**
|
||||
* Function to be called by the owner if an action does report data.
|
||||
* Takes the raw data and writes it into the IPC store.
|
||||
* @param reportTo MessageQueueId_t to report the action completion
|
||||
* message to
|
||||
* @param replyId ID of the executed command
|
||||
* @param data Pointer to the data
|
||||
* @return Returns RETURN_OK if successful, otherwise failure code
|
||||
*/
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
const uint8_t* data, size_t dataSize, bool hideSender = false);
|
||||
/**
|
||||
* Function to setup the MessageQueueIF* of the helper. Can be used to
|
||||
* set the MessageQueueIF* if message queue is unavailable at construction
|
||||
* and initialize but must be setup before first call of other functions.
|
||||
* @param queue Queue to be used by the helper
|
||||
*/
|
||||
void setQueueToUse(MessageQueueIF *queue);
|
||||
protected:
|
||||
//! Increase of value of this per step
|
||||
static const uint8_t STEP_OFFSET = 1;
|
||||
//! Pointer to the owner
|
||||
HasActionsIF* owner;
|
||||
//! Queue to be used as response sender, has to be set in ctor or with
|
||||
//! setQueueToUse
|
||||
MessageQueueIF* queueToUse;
|
||||
//! Pointer to an IPC Store, initialized during construction or
|
||||
StorageManagerIF* ipcStore = nullptr;
|
||||
|
||||
/**
|
||||
* Internal function called by handleActionMessage
|
||||
* @param commandedBy MessageQueueID of Commander
|
||||
* @param actionId ID of action to be done
|
||||
* @param dataAddress Address of additional data in IPC Store
|
||||
*/
|
||||
virtual void prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress);
|
||||
/**
|
||||
* @brief Default implementation is empty.
|
||||
*/
|
||||
virtual void resetHelper();
|
||||
};
|
||||
|
||||
#endif /* FSFW_ACTION_ACTIONHELPER_H_ */
|
@ -1,82 +0,0 @@
|
||||
#include "ActionMessage.h"
|
||||
#include "HasActionsIF.h"
|
||||
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
|
||||
ActionMessage::ActionMessage() {
|
||||
}
|
||||
|
||||
ActionMessage::~ActionMessage() {
|
||||
}
|
||||
|
||||
void ActionMessage::setCommand(CommandMessage* message, ActionId_t fid,
|
||||
store_address_t parameters) {
|
||||
message->setCommand(EXECUTE_ACTION);
|
||||
message->setParameter(fid);
|
||||
message->setParameter2(parameters.raw);
|
||||
}
|
||||
|
||||
ActionId_t ActionMessage::getActionId(const CommandMessage* message) {
|
||||
return ActionId_t(message->getParameter());
|
||||
}
|
||||
|
||||
store_address_t ActionMessage::getStoreId(const CommandMessage* message) {
|
||||
store_address_t temp;
|
||||
temp.raw = message->getParameter2();
|
||||
return temp;
|
||||
}
|
||||
|
||||
void ActionMessage::setStepReply(CommandMessage* message, ActionId_t fid, uint8_t step,
|
||||
ReturnValue_t result) {
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
message->setCommand(STEP_SUCCESS);
|
||||
} else {
|
||||
message->setCommand(STEP_FAILED);
|
||||
}
|
||||
message->setParameter(fid);
|
||||
message->setParameter2((step << 16) + result);
|
||||
}
|
||||
|
||||
uint8_t ActionMessage::getStep(const CommandMessage* message) {
|
||||
return uint8_t((message->getParameter2() >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
ReturnValue_t ActionMessage::getReturnCode(const CommandMessage* message) {
|
||||
return message->getParameter2() & 0xFFFF;
|
||||
}
|
||||
|
||||
void ActionMessage::setDataReply(CommandMessage* message, ActionId_t actionId,
|
||||
store_address_t data) {
|
||||
message->setCommand(DATA_REPLY);
|
||||
message->setParameter(actionId);
|
||||
message->setParameter2(data.raw);
|
||||
}
|
||||
|
||||
void ActionMessage::setCompletionReply(CommandMessage* message,
|
||||
ActionId_t fid, bool success, ReturnValue_t result) {
|
||||
if (success) {
|
||||
message->setCommand(COMPLETION_SUCCESS);
|
||||
}
|
||||
else {
|
||||
message->setCommand(COMPLETION_FAILED);
|
||||
}
|
||||
message->setParameter(fid);
|
||||
message->setParameter2(result);
|
||||
}
|
||||
|
||||
void ActionMessage::clear(CommandMessage* message) {
|
||||
switch(message->getCommand()) {
|
||||
case EXECUTE_ACTION:
|
||||
case DATA_REPLY: {
|
||||
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
||||
objects::IPC_STORE);
|
||||
if (ipcStore != NULL) {
|
||||
ipcStore->deleteData(getStoreId(message));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#ifndef FSFW_ACTION_ACTIONMESSAGE_H_
|
||||
#define FSFW_ACTION_ACTIONMESSAGE_H_
|
||||
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
|
||||
using ActionId_t = uint32_t;
|
||||
|
||||
/**
|
||||
* @brief These messages are part of the action module of the FSFW.
|
||||
* @details
|
||||
* These messages are sent amongst objects implementing the HasActionsIF. Classes like the
|
||||
* ActionHelper are able to process these messages.
|
||||
*/
|
||||
class ActionMessage {
|
||||
private:
|
||||
ActionMessage();
|
||||
public:
|
||||
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);
|
||||
static const Command_t DATA_REPLY = MAKE_COMMAND_ID(4);
|
||||
static const Command_t COMPLETION_SUCCESS = MAKE_COMMAND_ID(5);
|
||||
static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6);
|
||||
|
||||
virtual ~ActionMessage();
|
||||
static void setCommand(CommandMessage* message, ActionId_t fid,
|
||||
store_address_t parameters);
|
||||
|
||||
static ActionId_t getActionId(const CommandMessage* message );
|
||||
static store_address_t getStoreId(const CommandMessage* message);
|
||||
|
||||
static void setStepReply(CommandMessage* message, ActionId_t fid,
|
||||
uint8_t step, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
static uint8_t getStep(const CommandMessage* message );
|
||||
static ReturnValue_t getReturnCode(const CommandMessage* message );
|
||||
static void setDataReply(CommandMessage* message, ActionId_t actionId,
|
||||
store_address_t data);
|
||||
static void setCompletionReply(CommandMessage* message, ActionId_t fid,
|
||||
bool success, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FSFW_ACTION_ACTIONMESSAGE_H_ */
|
@ -1,127 +0,0 @@
|
||||
#include "ActionMessage.h"
|
||||
#include "CommandActionHelper.h"
|
||||
#include "CommandsActionsIF.h"
|
||||
#include "HasActionsIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner) :
|
||||
owner(setOwner), queueToUse(NULL), ipcStore(
|
||||
NULL), commandCount(0), lastTarget(0) {
|
||||
}
|
||||
|
||||
CommandActionHelper::~CommandActionHelper() {
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, SerializeIF *data) {
|
||||
HasActionsIF *receiver = objectManager->get<HasActionsIF>(commandTo);
|
||||
if (receiver == NULL) {
|
||||
return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS;
|
||||
}
|
||||
store_address_t storeId;
|
||||
uint8_t *storePointer;
|
||||
size_t maxSize = data->getSerializedSize();
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize,
|
||||
&storePointer);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
size_t size = 0;
|
||||
result = data->serialize(&storePointer, &size, maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, const uint8_t *data, uint32_t size) {
|
||||
// if (commandCount != 0) {
|
||||
// return CommandsFunctionsIF::ALREADY_COMMANDING;
|
||||
// }
|
||||
HasActionsIF *receiver = objectManager->get<HasActionsIF>(commandTo);
|
||||
if (receiver == NULL) {
|
||||
return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS;
|
||||
}
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = ipcStore->addData(&storeId, data, size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId,
|
||||
ActionId_t actionId, store_address_t storeId) {
|
||||
CommandMessage command;
|
||||
ActionMessage::setCommand(&command, actionId, storeId);
|
||||
ReturnValue_t result = queueToUse->sendMessage(queueId, &command);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ipcStore->deleteData(storeId);
|
||||
}
|
||||
lastTarget = queueId;
|
||||
commandCount++;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::initialize() {
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
queueToUse = owner->getCommandQueuePtr();
|
||||
if (queueToUse == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::handleReply(CommandMessage *reply) {
|
||||
if (reply->getSender() != lastTarget) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
switch (reply->getCommand()) {
|
||||
case ActionMessage::COMPLETION_SUCCESS:
|
||||
commandCount--;
|
||||
owner->completionSuccessfulReceived(ActionMessage::getActionId(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::COMPLETION_FAILED:
|
||||
commandCount--;
|
||||
owner->completionFailedReceived(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getReturnCode(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::STEP_SUCCESS:
|
||||
owner->stepSuccessfulReceived(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getStep(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::STEP_FAILED:
|
||||
commandCount--;
|
||||
owner->stepFailedReceived(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getStep(reply),
|
||||
ActionMessage::getReturnCode(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::DATA_REPLY:
|
||||
extractDataForOwner(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getStoreId(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CommandActionHelper::getCommandCount() const {
|
||||
return commandCount;
|
||||
}
|
||||
|
||||
void CommandActionHelper::extractDataForOwner(ActionId_t actionId, store_address_t storeId) {
|
||||
const uint8_t * data = NULL;
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(storeId, &data, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
owner->dataReceived(actionId, data, size);
|
||||
ipcStore->deleteData(storeId);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
#ifndef COMMANDACTIONHELPER_H_
|
||||
#define COMMANDACTIONHELPER_H_
|
||||
|
||||
#include "ActionMessage.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
|
||||
class CommandsActionsIF;
|
||||
|
||||
class CommandActionHelper {
|
||||
friend class CommandsActionsIF;
|
||||
public:
|
||||
CommandActionHelper(CommandsActionsIF* owner);
|
||||
virtual ~CommandActionHelper();
|
||||
ReturnValue_t commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, const uint8_t* data, uint32_t size);
|
||||
ReturnValue_t commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, SerializeIF* data);
|
||||
ReturnValue_t initialize();
|
||||
ReturnValue_t handleReply(CommandMessage* reply);
|
||||
uint8_t getCommandCount() const;
|
||||
private:
|
||||
CommandsActionsIF* owner;
|
||||
MessageQueueIF* queueToUse;
|
||||
StorageManagerIF* ipcStore;
|
||||
uint8_t commandCount;
|
||||
MessageQueueId_t lastTarget;
|
||||
void extractDataForOwner(ActionId_t actionId, store_address_t storeId);
|
||||
ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId,
|
||||
store_address_t storeId);
|
||||
};
|
||||
|
||||
#endif /* COMMANDACTIONHELPER_H_ */
|
@ -1,37 +0,0 @@
|
||||
#ifndef FSFW_ACTION_COMMANDSACTIONSIF_H_
|
||||
#define FSFW_ACTION_COMMANDSACTIONSIF_H_
|
||||
|
||||
#include "CommandActionHelper.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
|
||||
/**
|
||||
* Interface to separate commanding actions of other objects.
|
||||
* In next iteration, IF should be shortened to three calls:
|
||||
* - dataReceived(data)
|
||||
* - successReceived(id, step)
|
||||
* - failureReceived(id, step, cause)
|
||||
* or even
|
||||
* - replyReceived(id, step, cause) (if cause == OK, it's a success).
|
||||
*/
|
||||
class CommandsActionsIF {
|
||||
friend class CommandActionHelper;
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMANDS_ACTIONS_IF;
|
||||
static const ReturnValue_t OBJECT_HAS_NO_FUNCTIONS = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t ALREADY_COMMANDING = MAKE_RETURN_CODE(2);
|
||||
virtual ~CommandsActionsIF() {}
|
||||
virtual MessageQueueIF* getCommandQueuePtr() = 0;
|
||||
protected:
|
||||
virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) = 0;
|
||||
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step,
|
||||
ReturnValue_t returnCode) = 0;
|
||||
virtual void dataReceived(ActionId_t actionId, const uint8_t* data,
|
||||
uint32_t size) = 0;
|
||||
virtual void completionSuccessfulReceived(ActionId_t actionId) = 0;
|
||||
virtual void completionFailedReceived(ActionId_t actionId,
|
||||
ReturnValue_t returnCode) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_ACTION_COMMANDSACTIONSIF_H_ */
|
@ -1,75 +0,0 @@
|
||||
#include "HasActionsIF.h"
|
||||
#include "SimpleActionHelper.h"
|
||||
|
||||
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner,
|
||||
MessageQueueIF* useThisQueue) :
|
||||
ActionHelper(setOwner, useThisQueue), isExecuting(false) {
|
||||
}
|
||||
|
||||
SimpleActionHelper::~SimpleActionHelper() {
|
||||
}
|
||||
|
||||
void SimpleActionHelper::step(ReturnValue_t result) {
|
||||
// STEP_OFFESET is subtracted to compensate for adding offset in base
|
||||
// method, which is not necessary here.
|
||||
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction,
|
||||
result);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
resetHelper();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleActionHelper::finish(ReturnValue_t result) {
|
||||
ActionHelper::finish(lastCommander, lastAction, result);
|
||||
resetHelper();
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleActionHelper::reportData(SerializeIF* data) {
|
||||
return ActionHelper::reportData(lastCommander, lastAction, data);
|
||||
}
|
||||
|
||||
void SimpleActionHelper::resetHelper() {
|
||||
stepCount = 0;
|
||||
isExecuting = false;
|
||||
lastAction = 0;
|
||||
lastCommander = 0;
|
||||
}
|
||||
|
||||
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress) {
|
||||
CommandMessage reply;
|
||||
if (isExecuting) {
|
||||
ipcStore->deleteData(dataAddress);
|
||||
ActionMessage::setStepReply(&reply, actionId, 0,
|
||||
HasActionsIF::IS_BUSY);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
}
|
||||
const uint8_t* dataPtr = NULL;
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
return;
|
||||
}
|
||||
lastCommander = commandedBy;
|
||||
lastAction = actionId;
|
||||
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
|
||||
ipcStore->deleteData(dataAddress);
|
||||
switch (result) {
|
||||
case HasReturnvaluesIF::RETURN_OK:
|
||||
isExecuting = true;
|
||||
stepCount++;
|
||||
break;
|
||||
case HasActionsIF::EXECUTION_FINISHED:
|
||||
ActionMessage::setCompletionReply(&reply, actionId,
|
||||
true, HasReturnvaluesIF::RETURN_OK);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
break;
|
||||
default:
|
||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef FSFW_ACTION_SIMPLEACTIONHELPER_H_
|
||||
#define FSFW_ACTION_SIMPLEACTIONHELPER_H_
|
||||
|
||||
#include "ActionHelper.h"
|
||||
|
||||
/**
|
||||
* @brief This is an action helper which is only able to service one action
|
||||
* at a time but remembers last commander and last action which
|
||||
* simplifies usage
|
||||
*/
|
||||
class SimpleActionHelper: public ActionHelper {
|
||||
public:
|
||||
SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue);
|
||||
virtual ~SimpleActionHelper();
|
||||
void step(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
void finish(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
ReturnValue_t reportData(SerializeIF* data);
|
||||
|
||||
protected:
|
||||
void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||
store_address_t dataAddress);
|
||||
virtual void resetHelper();
|
||||
private:
|
||||
bool isExecuting;
|
||||
MessageQueueId_t lastCommander = MessageQueueIF::NO_QUEUE;
|
||||
ActionId_t lastAction = 0;
|
||||
uint8_t stepCount = 0;
|
||||
};
|
||||
|
||||
#endif /* SIMPLEACTIONHELPER_H_ */
|
14
automation/Dockerfile
Normal file
14
automation/Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM ubuntu:focal
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get --yes upgrade
|
||||
|
||||
#tzdata is a dependency, won't install otherwise
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano iputils-ping
|
||||
|
||||
RUN git clone https://github.com/catchorg/Catch2.git && \
|
||||
cd Catch2 && \
|
||||
git checkout v3.0.0-preview4 && \
|
||||
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
|
||||
cmake --build build/ --target install
|
49
automation/Jenkinsfile
vendored
Normal file
49
automation/Jenkinsfile
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
pipeline {
|
||||
environment {
|
||||
BUILDDIR = 'build-tests'
|
||||
}
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
//force docker to redownload base image and rebuild all steps instead of caching them
|
||||
//this way, we always get an up to date docker image one each build
|
||||
additionalBuildArgs '--no-cache --pull'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Clean') {
|
||||
steps {
|
||||
sh 'rm -rf $BUILDDIR'
|
||||
}
|
||||
}
|
||||
stage('Configure') {
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -j'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Unittests') {
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -- fsfw-tests_coverage -j'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Valgrind') {
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
cmake/FindSphinx.cmake
Normal file
13
cmake/FindSphinx.cmake
Normal file
@ -0,0 +1,13 @@
|
||||
# Look for an executable called sphinx-build
|
||||
find_program(SPHINX_EXECUTABLE
|
||||
NAMES sphinx-build
|
||||
DOC "Path to sphinx-build executable")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Handle standard arguments to find_package like REQUIRED and QUIET
|
||||
find_package_handle_standard_args(
|
||||
Sphinx
|
||||
"Failed to find sphinx-build executable"
|
||||
SPHINX_EXECUTABLE
|
||||
)
|
@ -1,253 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_ARRAYLIST_H_
|
||||
#define FSFW_CONTAINER_ARRAYLIST_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
class ArrayList {
|
||||
template<typename U, typename count> friend class SerialArrayListAdapter;
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
/**
|
||||
* This is the allocating constructor.
|
||||
* It allocates an array of the specified size.
|
||||
* @param maxSize
|
||||
*/
|
||||
ArrayList(count_t maxSize) :
|
||||
size(0), maxSize_(maxSize), allocated(true) {
|
||||
entries = new T[maxSize];
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the non-allocating constructor
|
||||
*
|
||||
* It expects a pointer to an array of a certain size and initializes
|
||||
* itself to it.
|
||||
*
|
||||
* @param storage the array to use as backend
|
||||
* @param maxSize size of storage
|
||||
* @param size size of data already present in storage
|
||||
*/
|
||||
ArrayList(T *storage, count_t maxSize, count_t size = 0) :
|
||||
size(size), entries(storage), maxSize_(maxSize), allocated(false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
count_t size;
|
||||
|
||||
|
||||
/**
|
||||
* Destructor, if the allocating constructor was used, it deletes the array.
|
||||
*/
|
||||
virtual ~ArrayList() {
|
||||
if (allocated) {
|
||||
delete[] entries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
|
||||
friend bool operator==(const ArrayList::Iterator& lhs,
|
||||
const ArrayList::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
friend bool operator!=(const ArrayList::Iterator& lhs,
|
||||
const ArrayList::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator pointing to the first stored elmement
|
||||
*
|
||||
* @return Iterator to the first element
|
||||
*/
|
||||
Iterator begin() const {
|
||||
return Iterator(&entries[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an Iterator pointing to the element after the last stored entry
|
||||
*
|
||||
* @return Iterator to the element after the last entry
|
||||
*/
|
||||
Iterator end() const {
|
||||
return Iterator(&entries[size]);
|
||||
}
|
||||
|
||||
T & operator[](count_t i) const {
|
||||
return entries[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* The first element
|
||||
*
|
||||
* @return pointer to the first stored element
|
||||
*/
|
||||
T *front() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* The last element
|
||||
*
|
||||
* does not return a valid pointer if called on an empty list.
|
||||
*
|
||||
* @return pointer to the last stored element
|
||||
*/
|
||||
T *back() {
|
||||
return &entries[size - 1];
|
||||
//Alternative solution
|
||||
//return const_cast<T*>(static_cast<const T*>(*this).back());
|
||||
}
|
||||
|
||||
const T* back() const{
|
||||
return &entries[size-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum number of elements this List can contain
|
||||
*
|
||||
* @return maximum number of elements
|
||||
*/
|
||||
size_t maxSize() const {
|
||||
return this->maxSize_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new element into the list.
|
||||
*
|
||||
* The new element is inserted after the last stored element.
|
||||
*
|
||||
* @param entry
|
||||
* @return
|
||||
* -@c FULL if the List is full
|
||||
* -@c RETURN_OK else
|
||||
*/
|
||||
ReturnValue_t insert(T entry) {
|
||||
if (size >= maxSize_) {
|
||||
return FULL;
|
||||
}
|
||||
entries[size] = entry;
|
||||
++size;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the List
|
||||
*
|
||||
* This does not actually clear all entries, it only sets the size to 0.
|
||||
*/
|
||||
void clear() {
|
||||
size = 0;
|
||||
}
|
||||
|
||||
count_t remaining() {
|
||||
return (maxSize_ - size);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* pointer to the array in which the entries are stored
|
||||
*/
|
||||
T *entries;
|
||||
/**
|
||||
* remembering the maximum size
|
||||
*/
|
||||
size_t maxSize_;
|
||||
|
||||
/**
|
||||
* true if the array was allocated and needs to be deleted in the destructor.
|
||||
*/
|
||||
bool allocated;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_CONTAINER_ARRAYLIST_H_ */
|
@ -1,153 +0,0 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_BINARYTREE_H_
|
||||
#define FRAMEWORK_CONTAINER_BINARYTREE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
template<typename Tp>
|
||||
class BinaryNode {
|
||||
public:
|
||||
BinaryNode(Tp* setValue) :
|
||||
value(setValue), left(NULL), right(NULL), parent(NULL) {
|
||||
}
|
||||
Tp *value;
|
||||
BinaryNode* left;
|
||||
BinaryNode* right;
|
||||
BinaryNode* parent;
|
||||
};
|
||||
|
||||
template<typename Tp>
|
||||
class ExplicitNodeIterator {
|
||||
public:
|
||||
typedef ExplicitNodeIterator<Tp> _Self;
|
||||
typedef BinaryNode<Tp> _Node;
|
||||
typedef Tp value_type;
|
||||
typedef Tp* pointer;
|
||||
typedef Tp& reference;
|
||||
ExplicitNodeIterator() :
|
||||
element(NULL) {
|
||||
}
|
||||
ExplicitNodeIterator(_Node* node) :
|
||||
element(node) {
|
||||
}
|
||||
BinaryNode<Tp>* element;
|
||||
_Self up() {
|
||||
return _Self(element->parent);
|
||||
}
|
||||
_Self left() {
|
||||
if (element != NULL) {
|
||||
return _Self(element->left);
|
||||
} else {
|
||||
return _Self(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
_Self right() {
|
||||
if (element != NULL) {
|
||||
return _Self(element->right);
|
||||
} else {
|
||||
return _Self(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
bool operator==(const _Self& __x) const {
|
||||
return element == __x.element;
|
||||
}
|
||||
bool operator!=(const _Self& __x) const {
|
||||
return element != __x.element;
|
||||
}
|
||||
pointer
|
||||
operator->() const {
|
||||
if (element != NULL) {
|
||||
return element->value;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
pointer operator*() const {
|
||||
return this->operator->();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Pretty rudimentary version of a simple binary tree (not a binary search tree!).
|
||||
*/
|
||||
template<typename Tp>
|
||||
class BinaryTree {
|
||||
public:
|
||||
typedef ExplicitNodeIterator<Tp> iterator;
|
||||
typedef BinaryNode<Tp> Node;
|
||||
typedef std::pair<iterator, iterator> children;
|
||||
BinaryTree() :
|
||||
rootNode(NULL) {
|
||||
}
|
||||
BinaryTree(Node* rootNode) :
|
||||
rootNode(rootNode) {
|
||||
}
|
||||
iterator begin() const {
|
||||
return iterator(rootNode);
|
||||
}
|
||||
static iterator end() {
|
||||
return iterator(NULL);
|
||||
}
|
||||
iterator insert(bool insertLeft, iterator parentNode, Node* newNode ) {
|
||||
newNode->parent = parentNode.element;
|
||||
if (parentNode.element != NULL) {
|
||||
if (insertLeft) {
|
||||
parentNode.element->left = newNode;
|
||||
} else {
|
||||
parentNode.element->right = newNode;
|
||||
}
|
||||
} else {
|
||||
//Insert first element.
|
||||
rootNode = newNode;
|
||||
}
|
||||
return iterator(newNode);
|
||||
}
|
||||
//No recursion to children. Needs to be done externally.
|
||||
children erase(iterator node) {
|
||||
if (node.element == rootNode) {
|
||||
//We're root node
|
||||
rootNode = NULL;
|
||||
} else {
|
||||
//Delete parent's reference
|
||||
if (node.up().left() == node) {
|
||||
node.up().element->left = NULL;
|
||||
} else {
|
||||
node.up().element->right = NULL;
|
||||
}
|
||||
}
|
||||
return children(node.element->left, node.element->right);
|
||||
}
|
||||
static uint32_t countLeft(iterator start) {
|
||||
if (start == end()) {
|
||||
return 0;
|
||||
}
|
||||
//We also count the start node itself.
|
||||
uint32_t count = 1;
|
||||
while (start.left() != end()) {
|
||||
count++;
|
||||
start = start.left();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
static uint32_t countRight(iterator start) {
|
||||
if (start == end()) {
|
||||
return 0;
|
||||
}
|
||||
//We also count the start node itself.
|
||||
uint32_t count = 1;
|
||||
while (start.right() != end()) {
|
||||
count++;
|
||||
start = start.right();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected:
|
||||
Node* rootNode;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_BINARYTREE_H_ */
|
@ -1,55 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_DYNAMICFIFO_H_
|
||||
#define FSFW_CONTAINER_DYNAMICFIFO_H_
|
||||
|
||||
#include "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->setContainer(fifoVector.data());
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Custom copy constructor which prevents setting the
|
||||
* underlying pointer wrong. This function allocates memory!
|
||||
* @details This is a very heavy operation so try to avoid this!
|
||||
*
|
||||
*/
|
||||
DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other),
|
||||
fifoVector(other.maxCapacity) {
|
||||
this->fifoVector = other.fifoVector;
|
||||
this->setContainer(fifoVector.data());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Custom assignment operator
|
||||
* @details This is a very heavy operation so try to avoid this!
|
||||
* @param other DyamicFIFO to copy from
|
||||
*/
|
||||
DynamicFIFO& operator=(const DynamicFIFO& other){
|
||||
FIFOBase<T>::operator=(other);
|
||||
this->fifoVector = other.fifoVector;
|
||||
this->setContainer(fifoVector.data());
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
std::vector<T> fifoVector;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTAINER_DYNAMICFIFO_H_ */
|
@ -1,47 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_FIFO_H_
|
||||
#define FSFW_CONTAINER_FIFO_H_
|
||||
|
||||
#include "FIFOBase.h"
|
||||
#include <array>
|
||||
|
||||
/**
|
||||
* @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, size_t capacity>
|
||||
class FIFO: public FIFOBase<T> {
|
||||
public:
|
||||
FIFO(): FIFOBase<T>(nullptr, capacity) {
|
||||
this->setContainer(fifoArray.data());
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Custom copy constructor to set pointer correctly.
|
||||
* @param other
|
||||
*/
|
||||
FIFO(const FIFO& other): FIFOBase<T>(other) {
|
||||
this->fifoArray = other.fifoArray;
|
||||
this->setContainer(fifoArray.data());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Custom assignment operator
|
||||
* @param other
|
||||
*/
|
||||
FIFO& operator=(const FIFO& other){
|
||||
FIFOBase<T>::operator=(other);
|
||||
this->fifoArray = other.fifoArray;
|
||||
this->setContainer(fifoArray.data());
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<T, capacity> fifoArray;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTAINER_FIFO_H_ */
|
@ -1,79 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_FIFOBASE_H_
|
||||
#define FSFW_CONTAINER_FIFOBASE_H_
|
||||
|
||||
#include "../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 RETURN_OK on success, FULL if full
|
||||
*/
|
||||
ReturnValue_t insert(T value);
|
||||
/**
|
||||
* Retrieve item from FIFO. This removes the item from the FIFO.
|
||||
* @param value Must point to a valid T
|
||||
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||
*/
|
||||
ReturnValue_t retrieve(T *value);
|
||||
/**
|
||||
* Retrieve item from FIFO without removing it from FIFO.
|
||||
* @param value Must point to a valid T
|
||||
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||
*/
|
||||
ReturnValue_t peek(T * value);
|
||||
/**
|
||||
* Remove item from FIFO.
|
||||
* @return RETURN_OK on success, EMPTY if empty
|
||||
*/
|
||||
ReturnValue_t pop();
|
||||
|
||||
/***
|
||||
* Check if FIFO is empty
|
||||
* @return True if empty, False if not
|
||||
*/
|
||||
bool empty();
|
||||
/***
|
||||
* Check if FIFO is Full
|
||||
* @return True if full, False if not
|
||||
*/
|
||||
bool full();
|
||||
/***
|
||||
* Current used size (elements) used
|
||||
* @return size_t in elements
|
||||
*/
|
||||
size_t size();
|
||||
/***
|
||||
* Get maximal capacity of fifo
|
||||
* @return size_t with max capacity of this fifo
|
||||
*/
|
||||
size_t getMaxCapacity() const;
|
||||
|
||||
protected:
|
||||
void setContainer(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 "FIFOBase.tpp"
|
||||
|
||||
#endif /* FSFW_CONTAINER_FIFOBASE_H_ */
|
@ -1,40 +0,0 @@
|
||||
#ifndef FIXEDARRAYLIST_H_
|
||||
#define FIXEDARRAYLIST_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include <cmath>
|
||||
/**
|
||||
* \ingroup container
|
||||
*/
|
||||
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class FixedArrayList: public ArrayList<T, count_t> {
|
||||
#if !defined(_MSC_VER)
|
||||
static_assert(MAX_SIZE <= (std::pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
|
||||
#endif
|
||||
private:
|
||||
T data[MAX_SIZE];
|
||||
public:
|
||||
FixedArrayList() :
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
}
|
||||
|
||||
FixedArrayList(const FixedArrayList& other) :
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
this->entries = data;
|
||||
this->size = other.size;
|
||||
}
|
||||
|
||||
FixedArrayList& operator=(FixedArrayList other) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
this->entries = data;
|
||||
this->size = other.size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~FixedArrayList() {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* FIXEDARRAYLIST_H_ */
|
@ -1,230 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_FIXEDMAP_H_
|
||||
#define FSFW_CONTAINER_FIXEDMAP_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* @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).
|
||||
* @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.
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename key_t, typename T>
|
||||
class FixedMap: public SerializeIF {
|
||||
static_assert (std::is_trivially_copyable<T>::value or
|
||||
std::is_base_of<SerializeIF, T>::value,
|
||||
"Types used in FixedMap must either be trivial copy-able or a "
|
||||
"derived class from SerializeIF to be serialize-able");
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
|
||||
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);
|
||||
|
||||
private:
|
||||
static const key_t EMPTY_SLOT = -1;
|
||||
ArrayList<std::pair<key_t, T>, uint32_t> theMap;
|
||||
uint32_t _size;
|
||||
|
||||
uint32_t findIndex(key_t key) const {
|
||||
if (_size == 0) {
|
||||
return 1;
|
||||
}
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < _size; ++i) {
|
||||
if (theMap[i].first == key) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
public:
|
||||
FixedMap(uint32_t maxSize) :
|
||||
theMap(maxSize), _size(0) {
|
||||
}
|
||||
|
||||
class Iterator: public ArrayList<std::pair<key_t, T>, uint32_t>::Iterator {
|
||||
public:
|
||||
Iterator() :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator() {
|
||||
}
|
||||
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
}
|
||||
};
|
||||
|
||||
friend bool operator==(const typename FixedMap::Iterator& lhs,
|
||||
const typename FixedMap::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
friend bool operator!=(const typename FixedMap::Iterator& lhs,
|
||||
const typename FixedMap::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
Iterator begin() const {
|
||||
return Iterator(&theMap[0]);
|
||||
}
|
||||
|
||||
Iterator end() const {
|
||||
return Iterator(&theMap[_size]);
|
||||
}
|
||||
|
||||
uint32_t size() const {
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
if (exists(key) == HasReturnvaluesIF::RETURN_OK) {
|
||||
return KEY_ALREADY_EXISTS;
|
||||
}
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
}
|
||||
theMap[_size].first = key;
|
||||
theMap[_size].second = value;
|
||||
if (storedValue != nullptr) {
|
||||
*storedValue = Iterator(&theMap[_size]);
|
||||
}
|
||||
++_size;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(std::pair<key_t, T> pair) {
|
||||
return insert(pair.first, pair.second);
|
||||
}
|
||||
|
||||
ReturnValue_t exists(key_t key) const {
|
||||
ReturnValue_t result = KEY_DOES_NOT_EXIST;
|
||||
if (findIndex(key) < _size) {
|
||||
result = HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t erase(Iterator *iter) {
|
||||
uint32_t i;
|
||||
if ((i = findIndex((*iter).value->first)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
theMap[i] = theMap[_size - 1];
|
||||
--_size;
|
||||
--((*iter).value);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t erase(key_t key) {
|
||||
uint32_t i;
|
||||
if ((i = findIndex(key)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
theMap[i] = theMap[_size - 1];
|
||||
--_size;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
T *findValue(key_t key) const {
|
||||
return &theMap[findIndex(key)].second;
|
||||
}
|
||||
|
||||
Iterator find(key_t key) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return end();
|
||||
}
|
||||
return Iterator(&theMap[findIndex(key)]);
|
||||
}
|
||||
|
||||
ReturnValue_t find(key_t key, T **value) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
*value = &theMap[findIndex(key)].second;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
if(_size == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool full() {
|
||||
if(_size >= theMap.maxSize()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
uint32_t maxSize() const {
|
||||
return theMap.maxSize();
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&this->_size,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
uint32_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) {
|
||||
result = SerializeAdapter::serialize(&theMap[i].first, buffer,
|
||||
size, maxSize, streamEndianness);
|
||||
result = SerializeAdapter::serialize(&theMap[i].second, buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
uint32_t printSize = sizeof(_size);
|
||||
uint32_t i = 0;
|
||||
|
||||
for (i = 0; i < _size; ++i) {
|
||||
printSize += SerializeAdapter::getSerializedSize(
|
||||
&theMap[i].first);
|
||||
printSize += SerializeAdapter::getSerializedSize(&theMap[i].second);
|
||||
}
|
||||
|
||||
return printSize;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size,
|
||||
buffer, size, streamEndianness);
|
||||
if (this->_size > theMap.maxSize()) {
|
||||
return SerializeIF::TOO_MANY_ELEMENTS;
|
||||
}
|
||||
uint32_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) {
|
||||
result = SerializeAdapter::deSerialize(&theMap[i].first, buffer,
|
||||
size, streamEndianness);
|
||||
result = SerializeAdapter::deSerialize(&theMap[i].second, buffer, size,
|
||||
streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTAINER_FIXEDMAP_H_ */
|
@ -1,207 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
#define FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief An associative container which allows multiple entries of the same key.
|
||||
* @details
|
||||
* Same keys are ordered by KEY_COMPARE function which is std::less<key_t> > by default.
|
||||
*
|
||||
* It uses the ArrayList, so technically this is not a real map, it is an array of pairs
|
||||
* of type key_t, T. It is ordered by key_t as FixedMap but allows same keys. Thus it has a linear
|
||||
* complexity O(n). As long as the number of entries remains low, this
|
||||
* should not be an issue.
|
||||
* The number of insertion and deletion operation should be minimized
|
||||
* as those incur extensive memory move operations (the underlying container
|
||||
* is not node based).
|
||||
*
|
||||
* Its of fixed size so no allocations are performed after the construction.
|
||||
*
|
||||
* The maximum size is given as first parameter of the constructor.
|
||||
*
|
||||
* It provides an iterator to do list iterations.
|
||||
*
|
||||
* The type T must have a copy constructor if it is not trivial copy-able.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* \ingroup container
|
||||
*/
|
||||
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_MULTIMAP;
|
||||
static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x02);
|
||||
|
||||
/***
|
||||
* Constructor which needs a size_t for the maximum allowed size
|
||||
*
|
||||
* Can not be resized during runtime
|
||||
*
|
||||
* Allocates memory at construction
|
||||
* @param maxSize size_t of Maximum allowed size
|
||||
*/
|
||||
FixedOrderedMultimap(size_t maxSize):theMap(maxSize), _size(0){
|
||||
}
|
||||
|
||||
/***
|
||||
* Virtual destructor frees Memory by deleting its member
|
||||
*/
|
||||
virtual ~FixedOrderedMultimap() {
|
||||
}
|
||||
|
||||
/***
|
||||
* Special iterator for FixedOrderedMultimap
|
||||
*/
|
||||
class Iterator: public ArrayList<std::pair<key_t, T>, size_t>::Iterator {
|
||||
public:
|
||||
Iterator() :
|
||||
ArrayList<std::pair<key_t, T>, size_t>::Iterator() {
|
||||
}
|
||||
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, size_t>::Iterator(pair) {
|
||||
}
|
||||
};
|
||||
|
||||
/***
|
||||
* Returns an iterator pointing to the first element
|
||||
* @return Iterator pointing to first element
|
||||
*/
|
||||
Iterator begin() const {
|
||||
return Iterator(&theMap[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator pointing to one element past the end
|
||||
* @return Iterator pointing to one element past the end
|
||||
*/
|
||||
Iterator end() const {
|
||||
return Iterator(&theMap[_size]);
|
||||
}
|
||||
|
||||
/***
|
||||
* Returns the current size of the map (not maximum size!)
|
||||
* @return Current size
|
||||
*/
|
||||
size_t size() const{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the map, does not deallocate any memory
|
||||
*/
|
||||
void clear(){
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum size of the map
|
||||
* @return Maximum size of the map
|
||||
*/
|
||||
size_t maxSize() const{
|
||||
return theMap.maxSize();
|
||||
}
|
||||
|
||||
/***
|
||||
* Used to insert a key and value separately.
|
||||
*
|
||||
* @param[in] key Key of the new element
|
||||
* @param[in] value Value of the new element
|
||||
* @param[in/out] (optional) storedValue On success this points to the new value, otherwise a nullptr
|
||||
* @return RETURN_OK if insert was successful, MAP_FULL if no space is available
|
||||
*/
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr);
|
||||
|
||||
/***
|
||||
* Used to insert new pair instead of single values
|
||||
*
|
||||
* @param pair Pair to be inserted
|
||||
* @return RETURN_OK if insert was successful, MAP_FULL if no space is available
|
||||
*/
|
||||
ReturnValue_t insert(std::pair<key_t, T> pair);
|
||||
|
||||
/***
|
||||
* Can be used to check if a certain key is in the map
|
||||
* @param key Key to be checked
|
||||
* @return RETURN_OK if the key exists KEY_DOES_NOT_EXIST otherwise
|
||||
*/
|
||||
ReturnValue_t exists(key_t key) const;
|
||||
|
||||
/***
|
||||
* Used to delete the element in the iterator
|
||||
*
|
||||
* The iterator will point to the element before or begin(),
|
||||
* but never to one element in front of the map.
|
||||
*
|
||||
* @warning The iterator needs to be valid and dereferenceable
|
||||
* @param[in/out] iter Pointer to iterator to the element that needs to be ereased
|
||||
* @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this
|
||||
*/
|
||||
ReturnValue_t erase(Iterator *iter);
|
||||
|
||||
/***
|
||||
* Used to erase by key
|
||||
* @param key Key to be erased
|
||||
* @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this
|
||||
*/
|
||||
ReturnValue_t erase(key_t key);
|
||||
|
||||
/***
|
||||
* Find returns the first appearance of the key
|
||||
*
|
||||
* If the key does not exist, it points to end()
|
||||
*
|
||||
* @param key Key to search for
|
||||
* @return Iterator pointing to the first entry of key
|
||||
*/
|
||||
Iterator find(key_t key) const{
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return end();
|
||||
}
|
||||
return Iterator(&theMap[findFirstIndex(key)]);
|
||||
};
|
||||
|
||||
/***
|
||||
* Finds first entry of the given key and returns a
|
||||
* pointer to the value
|
||||
*
|
||||
* @param key Key to search for
|
||||
* @param value Found value
|
||||
* @return RETURN_OK if it points to the value,
|
||||
* KEY_DOES_NOT_EXIST if the key is not in the map
|
||||
*/
|
||||
ReturnValue_t find(key_t key, T **value) const;
|
||||
|
||||
friend bool operator==(const typename FixedOrderedMultimap::Iterator& lhs,
|
||||
const typename FixedOrderedMultimap::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
friend bool operator!=(const typename FixedOrderedMultimap::Iterator& lhs,
|
||||
const typename FixedOrderedMultimap::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef KEY_COMPARE compare;
|
||||
compare myComp;
|
||||
ArrayList<std::pair<key_t, T>, size_t> theMap;
|
||||
size_t _size;
|
||||
|
||||
size_t findFirstIndex(key_t key, size_t startAt = 0) const;
|
||||
|
||||
size_t findNicePlace(key_t key) const;
|
||||
|
||||
void removeFromPosition(size_t position);
|
||||
};
|
||||
|
||||
#include "FixedOrderedMultimap.tpp"
|
||||
|
||||
#endif /* FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_ */
|
@ -1,90 +0,0 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_
|
||||
#define FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include "SinglyLinkedList.h"
|
||||
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
class HybridIterator: public LinkedElement<T>::Iterator,
|
||||
public ArrayList<T, count_t>::Iterator {
|
||||
public:
|
||||
HybridIterator() {}
|
||||
|
||||
HybridIterator(typename LinkedElement<T>::Iterator *iter) :
|
||||
LinkedElement<T>::Iterator(*iter), value(iter->value),
|
||||
linked(true) {
|
||||
|
||||
}
|
||||
|
||||
HybridIterator(LinkedElement<T> *start) :
|
||||
LinkedElement<T>::Iterator(start), value(start->value),
|
||||
linked(true) {
|
||||
|
||||
}
|
||||
|
||||
HybridIterator(typename ArrayList<T, count_t>::Iterator start,
|
||||
typename ArrayList<T, count_t>::Iterator end) :
|
||||
ArrayList<T, count_t>::Iterator(start), value(start.value),
|
||||
linked(false), end(end.value) {
|
||||
if (value == this->end) {
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
HybridIterator(T *firstElement, T *lastElement) :
|
||||
ArrayList<T, count_t>::Iterator(firstElement), value(firstElement),
|
||||
linked(false), end(++lastElement) {
|
||||
if (value == end) {
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
HybridIterator& operator++() {
|
||||
if (linked) {
|
||||
LinkedElement<T>::Iterator::operator++();
|
||||
if (LinkedElement<T>::Iterator::value != nullptr) {
|
||||
value = LinkedElement<T>::Iterator::value->value;
|
||||
} else {
|
||||
value = nullptr;
|
||||
}
|
||||
} else {
|
||||
ArrayList<T, count_t>::Iterator::operator++();
|
||||
value = ArrayList<T, count_t>::Iterator::value;
|
||||
|
||||
if (value == end) {
|
||||
value = nullptr;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
HybridIterator operator++(int) {
|
||||
HybridIterator tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator==(const HybridIterator& other) const {
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
bool operator!=(const HybridIterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
return value;
|
||||
}
|
||||
|
||||
T* value = nullptr;
|
||||
|
||||
private:
|
||||
bool linked = false;
|
||||
T *end = nullptr;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ */
|
@ -1,700 +0,0 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_
|
||||
#define FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerialArrayListAdapter.h"
|
||||
#include <cmath>
|
||||
|
||||
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");
|
||||
public:
|
||||
Index():blockStartAddress(0),size(0),storedPackets(0){}
|
||||
|
||||
Index(uint32_t startAddress):blockStartAddress(startAddress),size(0),storedPackets(0){
|
||||
|
||||
}
|
||||
|
||||
void setBlockStartAddress(uint32_t newAddress){
|
||||
this->blockStartAddress = newAddress;
|
||||
}
|
||||
|
||||
uint32_t getBlockStartAddress() const {
|
||||
return blockStartAddress;
|
||||
}
|
||||
|
||||
const T* getIndexType() const {
|
||||
return &indexType;
|
||||
}
|
||||
|
||||
T* modifyIndexType(){
|
||||
return &indexType;
|
||||
}
|
||||
/**
|
||||
* Updates the index Type. Uses = operator
|
||||
* @param indexType Type to copy from
|
||||
*/
|
||||
void setIndexType(T* indexType) {
|
||||
this->indexType = *indexType;
|
||||
}
|
||||
|
||||
uint32_t getSize() const {
|
||||
return size;
|
||||
}
|
||||
|
||||
void setSize(uint32_t size) {
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
void addSize(uint32_t size){
|
||||
this->size += size;
|
||||
}
|
||||
|
||||
void setStoredPackets(uint32_t newStoredPackets){
|
||||
this->storedPackets = newStoredPackets;
|
||||
}
|
||||
|
||||
void addStoredPackets(uint32_t packets){
|
||||
this->storedPackets += packets;
|
||||
}
|
||||
|
||||
uint32_t getStoredPackets() const{
|
||||
return this->storedPackets;
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&blockStartAddress,buffer,size,maxSize,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = indexType.serialize(buffer,size,maxSize,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::serialize(&this->storedPackets,buffer,size,maxSize,streamEndianness);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness){
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&blockStartAddress,buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = indexType.deSerialize(buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::deSerialize(&this->size,buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::deSerialize(&this->storedPackets,buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t getSerializedSize() const {
|
||||
uint32_t size = SerializeAdapter::getSerializedSize(&blockStartAddress);
|
||||
size += indexType.getSerializedSize();
|
||||
size += SerializeAdapter::getSerializedSize(&this->size);
|
||||
size += SerializeAdapter::getSerializedSize(&this->storedPackets);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const Index<T>& other){
|
||||
return ((blockStartAddress == other.getBlockStartAddress()) && (size==other.getSize())) && (indexType == *(other.getIndexType()));
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t blockStartAddress;
|
||||
uint32_t size;
|
||||
uint32_t storedPackets;
|
||||
T indexType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
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){
|
||||
|
||||
//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){
|
||||
serializedSize += additionalInfo->getSerializedSize();
|
||||
}
|
||||
//Size of current iterator type
|
||||
Index<T> tempIndex;
|
||||
serializedSize += tempIndex.getSerializedSize();
|
||||
|
||||
//Add Size of Array
|
||||
serializedSize += sizeof(uint32_t); //size of array
|
||||
serializedSize += (tempIndex.getSerializedSize() * maxNrOfIndices); //size of elements
|
||||
serializedSize += sizeof(uint16_t); //size of crc
|
||||
|
||||
//Calculate new size after index
|
||||
if(serializedSize > totalSize){
|
||||
error << "IndexedRingMemory: Store is too small for index" << std::endl;
|
||||
}
|
||||
uint32_t useableSize = totalSize - serializedSize;
|
||||
//Update the totalSize for calculations
|
||||
totalSize = useableSize;
|
||||
|
||||
//True StartAddress
|
||||
uint32_t trueStartAddress = indexAddress + serializedSize;
|
||||
|
||||
//Calculate True number of Blocks and reset size of true Number of Blocks
|
||||
uint32_t trueNumberOfBlocks = floor(static_cast<double>(totalSize) / static_cast<double>(bytesPerBlock));
|
||||
|
||||
//allocate memory now
|
||||
this->entries = new Index<T>[trueNumberOfBlocks];
|
||||
this->size = trueNumberOfBlocks;
|
||||
this->maxSize_ = trueNumberOfBlocks;
|
||||
this->allocated = true;
|
||||
|
||||
//Check trueNumberOfBlocks
|
||||
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) {
|
||||
it->setBlockStartAddress(address);
|
||||
it->setSize(0);
|
||||
it->setStoredPackets(0);
|
||||
address += bytesPerBlock;
|
||||
}
|
||||
|
||||
|
||||
//Initialize iterators
|
||||
currentWriteBlock = this->begin();
|
||||
currentReadBlock = this->begin();
|
||||
lastBlockToRead = this->begin();
|
||||
|
||||
//Check last blockSize
|
||||
uint32_t lastBlockSize = (trueStartAddress + useableSize) - (this->back()->getBlockStartAddress());
|
||||
if((lastBlockSize<bytesPerBlock) && (this->size > 1)){
|
||||
//remove the last Block so the second last block has more size
|
||||
this->size -= 1;
|
||||
debug << "IndexedRingMemory: Last Block is smaller than bytesPerBlock, removed last block" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the whole index, the iterators and executes the given reset function on every index type
|
||||
* @param typeResetFnc static reset function which accepts a pointer to the index Type
|
||||
*/
|
||||
void reset(void (*typeResetFnc)(T*)){
|
||||
currentReadBlock = this->begin();
|
||||
currentWriteBlock = this->begin();
|
||||
lastBlockToRead = this->begin();
|
||||
currentReadSize = 0;
|
||||
currentReadBlockSizeCached = 0;
|
||||
lastBlockToReadSize = 0;
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it = this->begin();it!=this->end();++it){
|
||||
it->setSize(0);
|
||||
it->setStoredPackets(0);
|
||||
(*typeResetFnc)(it->modifyIndexType());
|
||||
}
|
||||
}
|
||||
|
||||
void resetBlock(typename IndexedRingMemoryArray<T>::Iterator it,void (*typeResetFnc)(T*)){
|
||||
it->setSize(0);
|
||||
it->setStoredPackets(0);
|
||||
(*typeResetFnc)(it->modifyIndexType());
|
||||
}
|
||||
|
||||
/*
|
||||
* Reading
|
||||
*/
|
||||
|
||||
void setCurrentReadBlock(typename IndexedRingMemoryArray<T>::Iterator it){
|
||||
currentReadBlock = it;
|
||||
currentReadBlockSizeCached = it->getSize();
|
||||
}
|
||||
|
||||
void resetRead(){
|
||||
currentReadBlock = this->begin();
|
||||
currentReadSize = 0;
|
||||
currentReadBlockSizeCached = this->begin()->getSize();
|
||||
lastBlockToRead = currentWriteBlock;
|
||||
lastBlockToReadSize = currentWriteBlock->getSize();
|
||||
}
|
||||
/**
|
||||
* Sets the last block to read to this iterator.
|
||||
* Can be used to dump until block x
|
||||
* @param it The iterator for the last read block
|
||||
*/
|
||||
void setLastBlockToRead(typename IndexedRingMemoryArray<T>::Iterator it){
|
||||
lastBlockToRead = it;
|
||||
lastBlockToReadSize = it->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read pointer to the first written Block, which is the first non empty block in front of the write block
|
||||
* Can be the currentWriteBlock as well
|
||||
*/
|
||||
void readOldest(){
|
||||
resetRead();
|
||||
currentReadBlock = getNextNonEmptyBlock();
|
||||
currentReadBlockSizeCached = currentReadBlock->getSize();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current read iterator to the next Block and resets the current read size
|
||||
* The current size of the block will be cached to avoid race condition between write and read
|
||||
* If the end of the ring is reached the read pointer will be set to the begin
|
||||
*/
|
||||
void readNext(){
|
||||
currentReadSize = 0;
|
||||
if((this->size != 0) && (currentReadBlock.value ==this->back())){
|
||||
currentReadBlock = this->begin();
|
||||
}else{
|
||||
currentReadBlock++;
|
||||
}
|
||||
|
||||
currentReadBlockSizeCached = currentReadBlock->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the address which is currently read from
|
||||
* @return Address to read from
|
||||
*/
|
||||
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
|
||||
* @param readSize The size that was read
|
||||
* @return Returns true if the read can go on
|
||||
*/
|
||||
bool addReadSize(uint32_t readSize) {
|
||||
if(currentReadBlock == lastBlockToRead){
|
||||
//The current read block is the last to read
|
||||
if((currentReadSize+readSize)<lastBlockToReadSize){
|
||||
//the block has more data -> return true
|
||||
currentReadSize += readSize;
|
||||
return true;
|
||||
}else{
|
||||
//Reached end of read -> return false
|
||||
currentReadSize = lastBlockToReadSize;
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
//We are not in the last Block
|
||||
if((currentReadSize + readSize)<currentReadBlockSizeCached){
|
||||
//The current Block has more data
|
||||
currentReadSize += readSize;
|
||||
return true;
|
||||
}else{
|
||||
//The current block is written completely
|
||||
readNext();
|
||||
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
|
||||
for(;it!=lastBlockToRead;++it){
|
||||
if(it == this->end()){
|
||||
//This is the end, next block is the begin
|
||||
it = this->begin();
|
||||
if(it == lastBlockToRead){
|
||||
//Break if the begin is the lastBlockToRead
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(it->getSize()!=0){
|
||||
//This is a non empty block. Go on reading with this block
|
||||
currentReadBlock = it;
|
||||
currentReadBlockSizeCached = it->getSize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//reached lastBlockToRead and every block was empty, check if the last block is also empty
|
||||
if(lastBlockToReadSize!=0){
|
||||
//go on with last Block
|
||||
currentReadBlock = lastBlockToRead;
|
||||
currentReadBlockSizeCached = lastBlockToReadSize;
|
||||
return true;
|
||||
}
|
||||
//There is no non empty block left
|
||||
return false;
|
||||
}
|
||||
//Size is larger than 0
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t getRemainigSizeOfCurrentReadBlock() const{
|
||||
if(currentReadBlock == lastBlockToRead){
|
||||
return (lastBlockToReadSize - currentReadSize);
|
||||
}else{
|
||||
return (currentReadBlockSizeCached - currentReadSize);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getAddressOfCurrentReadBlock() const {
|
||||
return currentReadBlock->getBlockStartAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next non empty Block after the current write block,
|
||||
* @return Returns the iterator to the block. If there is non, the current write block is returned
|
||||
*/
|
||||
typename IndexedRingMemoryArray<T>::Iterator getNextNonEmptyBlock() const {
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it = getNextWrite();it!=currentWriteBlock;++it){
|
||||
if(it == this->end()){
|
||||
it = this->begin();
|
||||
if(it == currentWriteBlock){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(it->getSize()!=0){
|
||||
return it;
|
||||
}
|
||||
}
|
||||
return currentWriteBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the oldest Index type
|
||||
* @return Type of Index
|
||||
*/
|
||||
T* getOldest(){
|
||||
return (getNextNonEmptyBlock()->modifyIndexType());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Writing
|
||||
*/
|
||||
uint32_t getAddressOfCurrentWriteBlock() const{
|
||||
return currentWriteBlock->getBlockStartAddress();
|
||||
}
|
||||
|
||||
uint32_t getSizeOfCurrentWriteBlock() const{
|
||||
return currentWriteBlock->getSize();
|
||||
}
|
||||
|
||||
uint32_t getCurrentWriteAddress() const{
|
||||
return getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock();
|
||||
}
|
||||
|
||||
void clearCurrentWriteBlock(){
|
||||
currentWriteBlock->setSize(0);
|
||||
currentWriteBlock->setStoredPackets(0);
|
||||
}
|
||||
|
||||
void addCurrentWriteBlock(uint32_t size, uint32_t storedPackets){
|
||||
currentWriteBlock->addSize(size);
|
||||
currentWriteBlock->addStoredPackets(storedPackets);
|
||||
}
|
||||
|
||||
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
|
||||
* @return Returns true if size to write is smaller the remaining size of the block
|
||||
*/
|
||||
bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){
|
||||
typename IndexedRingMemoryArray<T>::Iterator next = getNextWrite();
|
||||
uint32_t addressOfNextBlock = next->getBlockStartAddress();
|
||||
uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize;
|
||||
return (sizeToWrite < availableSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the store is full if overwrite old is false
|
||||
* @return Returns true if it is writeable and false if not
|
||||
*/
|
||||
bool isNextBlockWritable(){
|
||||
//First check if this is the end of the list
|
||||
typename IndexedRingMemoryArray<T>::Iterator next;
|
||||
next = getNextWrite();
|
||||
if((next->getSize()!=0) && (!overwriteOld)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates current write Block Index Type
|
||||
* @param infoOfNewBlock
|
||||
*/
|
||||
void updateCurrentBlock(T* infoOfNewBlock){
|
||||
currentWriteBlock->setIndexType(infoOfNewBlock);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Succeed to next block, returns FAILED if overwrite is false and the store is full
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t writeNext(){
|
||||
//Check Next Block
|
||||
if(!isNextBlockWritable()){
|
||||
//The Index is full and does not overwrite old
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
//Next block can be written, update Metadata
|
||||
currentWriteBlock = getNextWrite();
|
||||
currentWriteBlock->setSize(0);
|
||||
currentWriteBlock->setStoredPackets(0);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the Index and calculates the CRC.
|
||||
* Parameters according to HasSerializeIF
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param maxSize
|
||||
* @param streamEndianness
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const{
|
||||
uint8_t* crcBuffer = *buffer;
|
||||
uint32_t oldSize = *size;
|
||||
if(additionalInfo!=NULL){
|
||||
additionalInfo->serialize(buffer,size,maxSize,streamEndianness);
|
||||
}
|
||||
ReturnValue_t result = currentWriteBlock->serialize(buffer,size,maxSize,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) {
|
||||
result = SerializeAdapter::serialize(&this->entries[i], buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
uint16_t crc = Calculate_CRC(crcBuffer,(*size-oldSize));
|
||||
result = SerializeAdapter::serialize(&crc,buffer,size,maxSize,streamEndianness);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the serialized Size of the index
|
||||
* @return The serialized size of the index
|
||||
*/
|
||||
size_t getSerializedSize() const {
|
||||
|
||||
uint32_t size = 0;
|
||||
if(additionalInfo!=NULL){
|
||||
size += additionalInfo->getSerializedSize();
|
||||
}
|
||||
size += currentWriteBlock->getSerializedSize();
|
||||
size += SerializeAdapter::getSerializedSize(&this->size);
|
||||
size += (this->entries[0].getSerializedSize()) * this->size;
|
||||
uint16_t crc = 0;
|
||||
size += SerializeAdapter::getSerializedSize(&crc);
|
||||
return size;
|
||||
}
|
||||
/**
|
||||
* DeSerialize the Indexed Ring from a buffer, deSerializes the current write iterator
|
||||
* CRC Has to be checked before!
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param streamEndianness
|
||||
* @return
|
||||
*/
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness){
|
||||
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if(additionalInfo!=NULL){
|
||||
result = additionalInfo->deSerialize(buffer,size,streamEndianness);
|
||||
}
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
|
||||
Index<T> tempIndex;
|
||||
result = tempIndex.deSerialize(buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
uint32_t tempSize = 0;
|
||||
result = SerializeAdapter::deSerialize(&tempSize,buffer,size,streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
if(this->size != tempSize){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
uint32_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) {
|
||||
result = SerializeAdapter::deSerialize(
|
||||
&this->entries[i], buffer, size,
|
||||
streamEndianness);
|
||||
++i;
|
||||
}
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
typename IndexedRingMemoryArray<T>::Iterator cmp(&tempIndex);
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it= this->begin();it!=this->end();++it){
|
||||
if(*(cmp.value) == *(it.value)){
|
||||
currentWriteBlock = it;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
//Reached if current write block iterator is not found
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
uint32_t getIndexAddress() const {
|
||||
return indexAddress;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Statistics
|
||||
*/
|
||||
uint32_t getStoredPackets() const {
|
||||
uint32_t size = 0;
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it= this->begin();it!=this->end();++it){
|
||||
size += it->getStoredPackets();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t getTotalSize() const {
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
uint32_t getCurrentSize() const{
|
||||
uint32_t size = 0;
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it= this->begin();it!=this->end();++it){
|
||||
size += it->getSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
bool isEmpty() const{
|
||||
return getCurrentSize()==0;
|
||||
}
|
||||
|
||||
double getPercentageFilled() const{
|
||||
uint32_t filledSize = 0;
|
||||
for(typename IndexedRingMemoryArray<T>::Iterator it= this->begin();it!=this->end();++it){
|
||||
filledSize += it->getSize();
|
||||
}
|
||||
|
||||
return (double)filledSize/(double)this->totalSize;
|
||||
}
|
||||
|
||||
typename IndexedRingMemoryArray<T>::Iterator getCurrentWriteBlock() const{
|
||||
return currentWriteBlock;
|
||||
}
|
||||
/**
|
||||
* Get the next block of the currentWriteBlock.
|
||||
* Returns the first one if currentWriteBlock is the last one
|
||||
* @return Iterator pointing to the next block after currentWriteBlock
|
||||
*/
|
||||
typename IndexedRingMemoryArray<T>::Iterator getNextWrite() const{
|
||||
typename IndexedRingMemoryArray<T>::Iterator next(currentWriteBlock);
|
||||
if((this->size != 0) && (currentWriteBlock.value == this->back())){
|
||||
next = this->begin();
|
||||
}else{
|
||||
++next;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
/**
|
||||
* Get the block in front of the Iterator
|
||||
* Returns the last block if it is the first block
|
||||
* @param it iterator which you want the previous block from
|
||||
* @return pointing to the block before it
|
||||
*/
|
||||
typename IndexedRingMemoryArray<T>::Iterator getPreviousBlock(typename IndexedRingMemoryArray<T>::Iterator it) {
|
||||
if(this->begin() == it){
|
||||
typename IndexedRingMemoryArray<T>::Iterator next((this->back()));
|
||||
return next;
|
||||
}
|
||||
typename IndexedRingMemoryArray<T>::Iterator next(it);
|
||||
--next;
|
||||
return next;
|
||||
}
|
||||
private:
|
||||
//The total size used by the blocks (without index)
|
||||
uint32_t totalSize;
|
||||
|
||||
//The address of the index
|
||||
const uint32_t indexAddress;
|
||||
|
||||
//The iterators for writing and reading
|
||||
typename IndexedRingMemoryArray<T>::Iterator currentWriteBlock;
|
||||
typename IndexedRingMemoryArray<T>::Iterator currentReadBlock;
|
||||
|
||||
//How much of the current read block is read already
|
||||
uint32_t currentReadSize;
|
||||
|
||||
//Cached Size of current read block
|
||||
uint32_t currentReadBlockSizeCached;
|
||||
|
||||
//Last block of current write (should be write block)
|
||||
typename IndexedRingMemoryArray<T>::Iterator lastBlockToRead;
|
||||
//current size of last Block to read
|
||||
uint32_t lastBlockToReadSize;
|
||||
|
||||
//Additional Info to be serialized with the index
|
||||
SerializeIF* additionalInfo;
|
||||
|
||||
//Does it overwrite old blocks?
|
||||
const bool overwriteOld;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_ */
|
@ -1,71 +0,0 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_PLACEMENTFACTORY_H_
|
||||
#define FRAMEWORK_CONTAINER_PLACEMENTFACTORY_H_
|
||||
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include <utility>
|
||||
/**
|
||||
* The Placement Factory is used to create objects at runtime in a specific pool.
|
||||
* In general, this should be avoided and it should only be used if you know what you are doing.
|
||||
* You are not allowed to use this container with a type that allocates memory internally like ArrayList.
|
||||
*
|
||||
* Also, you have to check the returned pointer in generate against nullptr!
|
||||
*
|
||||
* A backend of Type StorageManagerIF must be given as a place to store the new objects.
|
||||
* Therefore ThreadSafety is only provided by your StorageManager Implementation.
|
||||
*
|
||||
* Objects must be destroyed by the user with "destroy"! Otherwise the pool will not be cleared.
|
||||
*
|
||||
* The concept is based on the placement new operator.
|
||||
*
|
||||
* @warning Do not use with any Type that allocates memory internally!
|
||||
* @ingroup container
|
||||
*/
|
||||
class PlacementFactory {
|
||||
public:
|
||||
PlacementFactory(StorageManagerIF* backend) :
|
||||
dataBackend(backend) {
|
||||
}
|
||||
|
||||
/***
|
||||
* Generates an object of type T in the backend storage.
|
||||
*
|
||||
* @warning Do not use with any Type that allocates memory internally!
|
||||
*
|
||||
* @tparam T Type of Object
|
||||
* @param args Constructor Arguments to be passed
|
||||
* @return A pointer to the new object or a nullptr in case of failure
|
||||
*/
|
||||
template<typename T, typename ... Args>
|
||||
T* generate(Args&&... args) {
|
||||
store_address_t tempId;
|
||||
uint8_t* pData = nullptr;
|
||||
ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T),
|
||||
&pData);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
T* temp = new (pData) T(std::forward<Args>(args)...);
|
||||
return temp;
|
||||
}
|
||||
/***
|
||||
* Function to destroy the object allocated with generate and free space in backend.
|
||||
* This must be called by the user.
|
||||
*
|
||||
* @param thisElement Element to be destroyed
|
||||
* @return RETURN_OK if the element was destroyed, different errors on failure
|
||||
*/
|
||||
template<typename T>
|
||||
ReturnValue_t destroy(T* thisElement) {
|
||||
if (thisElement == nullptr){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
//Need to call destructor first, in case something was allocated by the object (shouldn't do that, however).
|
||||
thisElement->~T();
|
||||
uint8_t* pointer = (uint8_t*) (thisElement);
|
||||
return dataBackend->deleteData(pointer, sizeof(T));
|
||||
}
|
||||
private:
|
||||
StorageManagerIF* dataBackend;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_PLACEMENTFACTORY_H_ */
|
@ -1,113 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_RINGBUFFERBASE_H_
|
||||
#define FSFW_CONTAINER_RINGBUFFERBASE_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
template<uint8_t N_READ_PTRS = 1>
|
||||
class RingBufferBase {
|
||||
public:
|
||||
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 (getAvailableReadData(n) == 0);
|
||||
}
|
||||
|
||||
size_t getAvailableReadData(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 getMaxSize() 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 (getAvailableReadData(n) >= amount) {
|
||||
incrementRead(amount, n);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t writeData(uint32_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTAINER_RINGBUFFERBASE_H_ */
|
@ -1,60 +0,0 @@
|
||||
#include "SharedRingBuffer.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
#include "../ipc/MutexGuard.h"
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes):
|
||||
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
|
||||
maxExcessBytes) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
|
||||
const size_t size, bool overwriteOld, size_t maxExcessBytes):
|
||||
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
|
||||
maxExcessBytes) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedRingBuffer::~SharedRingBuffer() {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
|
||||
void SharedRingBuffer::setToUseReceiveSizeFIFO(size_t fifoDepth) {
|
||||
this->fifoDepth = fifoDepth;
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::lockRingBufferMutex(
|
||||
MutexIF::TimeoutType timeoutType, dur_millis_t timeout) {
|
||||
return mutex->lockMutex(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() {
|
||||
return mutex->unlockMutex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
MutexIF* SharedRingBuffer::getMutexHandle() const {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::initialize() {
|
||||
if(fifoDepth > 0) {
|
||||
receiveSizesFIFO = new DynamicFIFO<size_t>(fifoDepth);
|
||||
}
|
||||
return SystemObject::initialize();
|
||||
}
|
||||
|
||||
DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
|
||||
if(receiveSizesFIFO == nullptr) {
|
||||
// Configuration error.
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer"
|
||||
<< " was not configured to have sizes FIFO, returning nullptr!"
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
return receiveSizesFIFO;
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
#define FSFW_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
|
||||
#include "SimpleRingBuffer.h"
|
||||
#include "DynamicFIFO.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
|
||||
/**
|
||||
* @brief Ring buffer which can be shared among multiple objects
|
||||
* @details
|
||||
* This class offers a mutex to perform thread-safe operation on the ring
|
||||
* buffer. It is still up to the developer to actually perform the lock
|
||||
* and unlock operations.
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* 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);
|
||||
|
||||
virtual~ SharedRingBuffer();
|
||||
|
||||
/**
|
||||
* @brief This function can be used to add an optional FIFO to the class
|
||||
* @details
|
||||
* This FIFO will be allocated in the initialize function (and will
|
||||
* have a fixed maximum size after that). It can be used to store
|
||||
* values like packet sizes, for example for a shared ring buffer
|
||||
* used by producer/consumer tasks.
|
||||
*/
|
||||
void setToUseReceiveSizeFIFO(size_t fifoDepth);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Unless a read-only constant value is read, all operations on the
|
||||
* shared ring buffer should be protected by calling this function.
|
||||
* @param timeoutType
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t lockRingBufferMutex(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t timeout);
|
||||
/**
|
||||
* Any locked mutex also has to be unlocked, otherwise, access to the
|
||||
* shared ring buffer will be blocked.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t unlockRingBufferMutex();
|
||||
|
||||
/**
|
||||
* The mutex handle can be accessed directly, for example to perform
|
||||
* the lock with the #MutexGuard for a RAII compliant lock operation.
|
||||
* @return
|
||||
*/
|
||||
MutexIF* getMutexHandle() const;
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
/**
|
||||
* If the shared ring buffer was configured to have a sizes FIFO, a handle
|
||||
* to that FIFO can be retrieved with this function.
|
||||
* Do not forget to protect access with a lock if required!
|
||||
* @return
|
||||
*/
|
||||
DynamicFIFO<size_t>* getReceiveSizesFIFO();
|
||||
private:
|
||||
MutexIF* mutex = nullptr;
|
||||
|
||||
size_t fifoDepth = 0;
|
||||
DynamicFIFO<size_t>* receiveSizesFIFO = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */
|
@ -1,131 +0,0 @@
|
||||
#include "SimpleRingBuffer.h"
|
||||
#include <cstring>
|
||||
|
||||
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];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleRingBuffer::confirmBytesWritten(size_t amount) {
|
||||
if(getExcessBytes() > 0) {
|
||||
moveExcessBytesToStart();
|
||||
}
|
||||
incrementWrite(amount);
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
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 {
|
||||
memcpy(&buffer[write], data, amountTillWrap);
|
||||
memcpy(buffer, data + amountTillWrap, amount - amountTillWrap);
|
||||
}
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, size_t amount,
|
||||
bool incrementReadPtr, bool readRemaining, size_t* trueAmount) {
|
||||
size_t availableData = getAvailableReadData(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 != nullptr) {
|
||||
*trueAmount = amount;
|
||||
}
|
||||
if (amountTillWrap >= amount) {
|
||||
memcpy(data, &buffer[read[READ_PTR]], amount);
|
||||
} else {
|
||||
memcpy(data, &buffer[read[READ_PTR]], amountTillWrap);
|
||||
memcpy(data + amountTillWrap, buffer, amount - amountTillWrap);
|
||||
}
|
||||
|
||||
if(incrementReadPtr) {
|
||||
deleteData(amount, readRemaining);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
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 = getAvailableReadData(READ_PTR);
|
||||
if (availableData < amount) {
|
||||
if (deleteRemaining) {
|
||||
amount = availableData;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
if (trueAmount != nullptr) {
|
||||
*trueAmount = amount;
|
||||
}
|
||||
incrementRead(amount, READ_PTR);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
#ifndef FSFW_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
#define FSFW_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
|
||||
#include "RingBufferBase.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:
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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. This function
|
||||
* does not increment the write pointer!
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* This increments the write pointer and also copies the excess bytes
|
||||
* to the beginning. It should be called if the write operation
|
||||
* conducted after calling getFreeElement() was performed.
|
||||
* @return
|
||||
*/
|
||||
void confirmBytesWritten(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 READ_PTR = 0;
|
||||
uint8_t* buffer = nullptr;
|
||||
size_t maxExcessBytes;
|
||||
size_t excessBytes = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||
|
@ -1,154 +0,0 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||
#define FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Linked list data structure,
|
||||
* each entry has a pointer to the next entry (singly)
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename T>
|
||||
class LinkedElement {
|
||||
public:
|
||||
T *value;
|
||||
class Iterator {
|
||||
public:
|
||||
LinkedElement<T> *value = nullptr;
|
||||
Iterator() {}
|
||||
|
||||
Iterator(LinkedElement<T> *element) :
|
||||
value(element) {
|
||||
}
|
||||
|
||||
Iterator& operator++() {
|
||||
value = value->getNext();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator++(int) {
|
||||
Iterator tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator==(Iterator other) {
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
bool operator!=(Iterator other) {
|
||||
return !(*this == other);
|
||||
}
|
||||
T *operator->() {
|
||||
return value->value;
|
||||
}
|
||||
};
|
||||
|
||||
LinkedElement(T* setElement, LinkedElement<T>* setNext = nullptr):
|
||||
value(setElement), next(setNext) {}
|
||||
|
||||
virtual ~LinkedElement(){}
|
||||
|
||||
virtual LinkedElement* getNext() const {
|
||||
return next;
|
||||
}
|
||||
|
||||
virtual void setNext(LinkedElement* next) {
|
||||
this->next = next;
|
||||
}
|
||||
|
||||
virtual void setEnd() {
|
||||
this->next = nullptr;
|
||||
}
|
||||
|
||||
LinkedElement* begin() {
|
||||
return this;
|
||||
}
|
||||
LinkedElement* end() {
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
LinkedElement *next;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class SinglyLinkedList {
|
||||
public:
|
||||
using ElementIterator = typename LinkedElement<T>::Iterator;
|
||||
|
||||
SinglyLinkedList() {}
|
||||
|
||||
SinglyLinkedList(ElementIterator start) :
|
||||
start(start.value) {}
|
||||
|
||||
SinglyLinkedList(LinkedElement<T>* startElement) :
|
||||
start(startElement) {}
|
||||
|
||||
ElementIterator begin() const {
|
||||
return ElementIterator::Iterator(start);
|
||||
}
|
||||
|
||||
/** 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->getNext() != nullptr) {
|
||||
element = element->getNext();
|
||||
}
|
||||
return ElementIterator::Iterator(element);
|
||||
}
|
||||
|
||||
size_t getSize() const {
|
||||
size_t size = 0;
|
||||
LinkedElement<T> *element = start;
|
||||
while (element != nullptr) {
|
||||
size++;
|
||||
element = element->getNext();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
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 = nullptr;
|
||||
};
|
||||
|
||||
#endif /* SINGLYLINKEDLIST_H_ */
|
9
contrib/CMakeLists.txt
Normal file
9
contrib/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_subdirectory(fsfw_contrib)
|
11
contrib/fsfw_contrib/CMakeLists.txt
Normal file
11
contrib/fsfw_contrib/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
if(FSFW_ADD_SGP4_PROPAGATOR)
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
sgp4/sgp4unit.cpp
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
endif()
|
@ -1,137 +0,0 @@
|
||||
#include "ControllerBase.h"
|
||||
|
||||
#include "../subsystem/SubsystemBase.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../action/HasActionsIF.h"
|
||||
|
||||
ControllerBase::ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
||||
size_t commandQueueDepth) :
|
||||
SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF),
|
||||
submode(SUBMODE_NONE), modeHelper(this),
|
||||
healthHelper(this, setObjectId) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(
|
||||
commandQueueDepth);
|
||||
}
|
||||
|
||||
ControllerBase::~ControllerBase() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t ControllerBase::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageQueueId_t parentQueue = 0;
|
||||
if (parentId != objects::NO_OBJECT) {
|
||||
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
||||
if (parent == nullptr) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
parentQueue = parent->getCommandQueue();
|
||||
|
||||
parent->registerChild(getObjectId());
|
||||
}
|
||||
|
||||
result = healthHelper.initialize(parentQueue);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = modeHelper.initialize(parentQueue);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t ControllerBase::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
void ControllerBase::handleQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
for (result = commandQueue->receiveMessage(&command);
|
||||
result == RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&command)) {
|
||||
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
result = handleCommandMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
command.setToUnknownCommand();
|
||||
commandQueue->reply(&command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ControllerBase::startTransition(Mode_t mode, Submode_t submode) {
|
||||
changeHK(this->mode, this->submode, false);
|
||||
triggerEvent(CHANGING_MODE, mode, submode);
|
||||
this->mode = mode;
|
||||
this->submode = submode;
|
||||
modeHelper.modeChanged(mode, submode);
|
||||
modeChanged(mode, submode);
|
||||
announceMode(false);
|
||||
changeHK(this->mode, this->submode, true);
|
||||
}
|
||||
|
||||
void ControllerBase::getMode(Mode_t* mode, Submode_t* submode) {
|
||||
*mode = this->mode;
|
||||
*submode = this->submode;
|
||||
}
|
||||
|
||||
void ControllerBase::setToExternalControl() {
|
||||
healthHelper.setHealth(EXTERNAL_CONTROL);
|
||||
}
|
||||
|
||||
void ControllerBase::announceMode(bool recursive) {
|
||||
triggerEvent(MODE_INFO, mode, submode);
|
||||
}
|
||||
|
||||
ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
|
||||
handleQueue();
|
||||
performControlOperation();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void ControllerBase::modeChanged(Mode_t mode, Submode_t submode) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReturnValue_t ControllerBase::setHealth(HealthState health) {
|
||||
switch (health) {
|
||||
case HEALTHY:
|
||||
case EXTERNAL_CONTROL:
|
||||
healthHelper.setHealth(health);
|
||||
return RETURN_OK;
|
||||
default:
|
||||
return INVALID_HEALTH_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState ControllerBase::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
void ControllerBase::setTaskIF(PeriodicTaskIF* task_){
|
||||
executingTask = task_;
|
||||
}
|
||||
|
||||
void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
|
||||
}
|
||||
|
||||
ReturnValue_t ControllerBase::initializeAfterTaskCreation() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
#ifndef FSFW_CONTROLLER_CONTROLLERBASE_H_
|
||||
#define FSFW_CONTROLLER_CONTROLLERBASE_H_
|
||||
|
||||
#include "../health/HasHealthIF.h"
|
||||
#include "../health/HealthHelper.h"
|
||||
#include "../modes/HasModesIF.h"
|
||||
#include "../modes/ModeHelper.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
#include "../tasks/PeriodicTaskIF.h"
|
||||
#include "../datapool/HkSwitchHelper.h"
|
||||
|
||||
/**
|
||||
* @brief Generic base class for controller classes
|
||||
* @details
|
||||
* Implements common interfaces for controllers, which generally have
|
||||
* a mode and a health state. This avoids boilerplate code.
|
||||
*/
|
||||
class ControllerBase: public HasModesIF,
|
||||
public HasHealthIF,
|
||||
public ExecutableObjectIF,
|
||||
public SystemObject,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
static const Mode_t MODE_NORMAL = 2;
|
||||
|
||||
ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
||||
size_t commandQueueDepth = 3);
|
||||
virtual ~ControllerBase();
|
||||
|
||||
/** SystemObject override */
|
||||
virtual ReturnValue_t initialize() override;
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const override;
|
||||
|
||||
/** HasHealthIF overrides */
|
||||
virtual ReturnValue_t setHealth(HealthState health) override;
|
||||
virtual HasHealthIF::HealthState getHealth() override;
|
||||
|
||||
/** ExecutableObjectIF overrides */
|
||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
virtual void setTaskIF(PeriodicTaskIF* task) override;
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Implemented by child class. Handle command messages which are not
|
||||
* mode or health messages.
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
||||
|
||||
/**
|
||||
* Periodic helper, implemented by child class.
|
||||
*/
|
||||
virtual void performControlOperation() = 0;
|
||||
|
||||
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) = 0;
|
||||
|
||||
const object_id_t parentId;
|
||||
|
||||
Mode_t mode;
|
||||
|
||||
Submode_t submode;
|
||||
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
|
||||
ModeHelper modeHelper;
|
||||
|
||||
HealthHelper healthHelper;
|
||||
|
||||
/**
|
||||
* Pointer to the task which executes this component,
|
||||
* is invalid before setTaskIF was called.
|
||||
*/
|
||||
PeriodicTaskIF* executingTask = nullptr;
|
||||
|
||||
/** Handle mode and health messages */
|
||||
virtual void handleQueue();
|
||||
|
||||
/** Mode helpers */
|
||||
virtual void modeChanged(Mode_t mode, Submode_t submode);
|
||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||
virtual void getMode(Mode_t *mode, Submode_t *submode);
|
||||
virtual void setToExternalControl();
|
||||
virtual void announceMode(bool recursive);
|
||||
/** HK helpers */
|
||||
virtual void changeHK(Mode_t mode, Submode_t submode, bool enable);
|
||||
};
|
||||
|
||||
#endif /* FSFW_CONTROLLER_CONTROLLERBASE_H_ */
|
@ -1,104 +0,0 @@
|
||||
#include "ExtendedControllerBase.h"
|
||||
|
||||
|
||||
ExtendedControllerBase::ExtendedControllerBase(object_id_t objectId,
|
||||
object_id_t parentId, size_t commandQueueDepth):
|
||||
ControllerBase(objectId, parentId, commandQueueDepth),
|
||||
poolManager(this, commandQueue),
|
||||
actionHelper(this, commandQueue) {
|
||||
}
|
||||
|
||||
ExtendedControllerBase::~ExtendedControllerBase() {
|
||||
}
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t *data, size_t size) {
|
||||
/* Needs to be overriden and implemented by child class. */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
object_id_t ExtendedControllerBase::getObjectId() const {
|
||||
return SystemObject::getObjectId();
|
||||
}
|
||||
|
||||
uint32_t ExtendedControllerBase::getPeriodicOperationFrequency() const {
|
||||
return this->executingTask->getPeriodMs();
|
||||
}
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::handleCommandMessage(
|
||||
CommandMessage *message) {
|
||||
ReturnValue_t result = actionHelper.handleActionMessage(message);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return poolManager.handleHousekeepingMessage(message);
|
||||
}
|
||||
|
||||
void ExtendedControllerBase::handleQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
for (result = commandQueue->receiveMessage(&command);
|
||||
result == RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&command)) {
|
||||
result = actionHelper.handleActionMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = poolManager.handleHousekeepingMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = handleCommandMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
command.setToUnknownCommand();
|
||||
commandQueue->reply(&command);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::initialize() {
|
||||
ReturnValue_t result = ControllerBase::initialize();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = actionHelper.initialize(commandQueue);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return poolManager.initialize(commandQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::initializeAfterTaskCreation() {
|
||||
return poolManager.initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
ReturnValue_t ExtendedControllerBase::performOperation(uint8_t opCode) {
|
||||
handleQueue();
|
||||
performControlOperation();
|
||||
/* We do this after performing control operation because variables will be set changed
|
||||
in this function. */
|
||||
poolManager.performHkOperation();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t ExtendedControllerBase::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
LocalDataPoolManager* ExtendedControllerBase::getHkManagerHandle() {
|
||||
return &poolManager;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
#ifndef FSFW_CONTROLLER_EXTENDEDCONTROLLERBASE_H_
|
||||
#define FSFW_CONTROLLER_EXTENDEDCONTROLLERBASE_H_
|
||||
|
||||
#include "ControllerBase.h"
|
||||
|
||||
#include "../action/HasActionsIF.h"
|
||||
#include "../datapoollocal/HasLocalDataPoolIF.h"
|
||||
#include "../action/ActionHelper.h"
|
||||
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||
|
||||
/**
|
||||
* @brief Extendes the basic ControllerBase with the common components
|
||||
* HasActionsIF for commandability and HasLocalDataPoolIF to keep
|
||||
* a pool of local data pool variables.
|
||||
* @details
|
||||
* Default implementations required for the interfaces will be empty and have
|
||||
* to be implemented by child class.
|
||||
*/
|
||||
class ExtendedControllerBase: public ControllerBase,
|
||||
public HasActionsIF,
|
||||
public HasLocalDataPoolIF {
|
||||
public:
|
||||
ExtendedControllerBase(object_id_t objectId, object_id_t parentId,
|
||||
size_t commandQueueDepth = 3);
|
||||
virtual ~ExtendedControllerBase();
|
||||
|
||||
/* SystemObjectIF overrides */
|
||||
virtual ReturnValue_t initialize() override;
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const override;
|
||||
|
||||
/* ExecutableObjectIF overrides */
|
||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
protected:
|
||||
LocalDataPoolManager poolManager;
|
||||
ActionHelper actionHelper;
|
||||
|
||||
/**
|
||||
* Implemented by child class. Handle all command messages which are
|
||||
* not health, mode, action or housekeeping messages.
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
||||
|
||||
/**
|
||||
* Periodic helper from ControllerBase, implemented by child class.
|
||||
*/
|
||||
virtual void performControlOperation() = 0;
|
||||
|
||||
/* Handle the four messages mentioned above */
|
||||
void handleQueue() override;
|
||||
|
||||
/* HasActionsIF overrides */
|
||||
virtual ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data,
|
||||
size_t size) override;
|
||||
|
||||
/* HasLocalDatapoolIF overrides */
|
||||
virtual LocalDataPoolManager* getHkManagerHandle() override;
|
||||
virtual object_id_t getObjectId() const override;
|
||||
virtual uint32_t getPeriodicOperationFrequency() const override;
|
||||
|
||||
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override = 0;
|
||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_CONTROLLER_EXTENDEDCONTROLLERBASE_H_ */
|
@ -1,227 +0,0 @@
|
||||
#include "CoordinateTransformations.h"
|
||||
#include "../globalfunctions/constants.h"
|
||||
#include "../globalfunctions/math/MatrixOperations.h"
|
||||
#include "../globalfunctions/math/VectorOperations.h"
|
||||
#include <stddef.h>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
void CoordinateTransformations::positionEcfToEci(const double* ecfPosition,
|
||||
double* eciPosition, timeval *timeUTC) {
|
||||
ecfToEci(ecfPosition, eciPosition, NULL, timeUTC);
|
||||
|
||||
}
|
||||
|
||||
void CoordinateTransformations::velocityEcfToEci(const double* ecfVelocity,
|
||||
const double* ecfPosition, double* eciVelocity, timeval *timeUTC) {
|
||||
ecfToEci(ecfVelocity, eciVelocity, ecfPosition, timeUTC);
|
||||
}
|
||||
|
||||
void CoordinateTransformations::positionEciToEcf(const double* eciCoordinates, double* ecfCoordinates,timeval *timeUTC){
|
||||
eciToEcf(eciCoordinates,ecfCoordinates,NULL,timeUTC);
|
||||
};
|
||||
|
||||
void CoordinateTransformations::velocityEciToEcf(const double* eciVelocity,const double* eciPosition, double* ecfVelocity,timeval* timeUTC){
|
||||
eciToEcf(eciVelocity,ecfVelocity,eciPosition,timeUTC);
|
||||
}
|
||||
|
||||
double CoordinateTransformations::getEarthRotationAngle(timeval timeUTC) {
|
||||
|
||||
double jD2000UTC;
|
||||
Clock::convertTimevalToJD2000(timeUTC, &jD2000UTC);
|
||||
|
||||
double TTt2000 = getJuleanCenturiesTT(timeUTC);
|
||||
|
||||
double theta = 2 * Math::PI
|
||||
* (0.779057273264 + 1.00273781191135448 * jD2000UTC);
|
||||
|
||||
//Correct theta according to IAU 2000 precession-nutation model
|
||||
theta = theta + 7.03270725817493E-008 + 0.0223603701 * TTt2000
|
||||
+ 6.77128219501896E-006 * TTt2000 * TTt2000
|
||||
+ 4.5300990362875E-010 * TTt2000 * TTt2000 * TTt2000
|
||||
+ 9.12419347848147E-011 * TTt2000 * TTt2000 * TTt2000 * TTt2000;
|
||||
return theta;
|
||||
}
|
||||
|
||||
void CoordinateTransformations::getEarthRotationMatrix(timeval timeUTC,
|
||||
double matrix[][3]) {
|
||||
double theta = getEarthRotationAngle(timeUTC);
|
||||
|
||||
matrix[0][0] = cos(theta);
|
||||
matrix[0][1] = sin(theta);
|
||||
matrix[0][2] = 0;
|
||||
matrix[1][0] = -sin(theta);
|
||||
matrix[1][1] = cos(theta);
|
||||
matrix[1][2] = 0;
|
||||
matrix[2][0] = 0;
|
||||
matrix[2][1] = 0;
|
||||
matrix[2][2] = 1;
|
||||
}
|
||||
|
||||
void CoordinateTransformations::ecfToEci(const double* ecfCoordinates,
|
||||
double* eciCoordinates,
|
||||
const double* ecfPositionIfCoordinatesAreVelocity, timeval *timeUTCin) {
|
||||
|
||||
timeval timeUTC;
|
||||
if (timeUTCin != NULL) {
|
||||
timeUTC = *timeUTCin;
|
||||
} else {
|
||||
Clock::getClock_timeval(&timeUTC);
|
||||
}
|
||||
|
||||
double Tfi[3][3];
|
||||
double Tif[3][3];
|
||||
getTransMatrixECITOECF(timeUTC,Tfi);
|
||||
|
||||
MatrixOperations<double>::transpose(Tfi[0], Tif[0], 3);
|
||||
|
||||
MatrixOperations<double>::multiply(Tif[0], ecfCoordinates, eciCoordinates,
|
||||
3, 3, 1);
|
||||
|
||||
|
||||
|
||||
|
||||
if (ecfPositionIfCoordinatesAreVelocity != NULL) {
|
||||
|
||||
double Tdotfi[3][3];
|
||||
double Tdotif[3][3];
|
||||
double Trot[3][3] = { { 0, Earth::OMEGA, 0 },
|
||||
{ 0 - Earth::OMEGA, 0, 0 }, { 0, 0, 0 } };
|
||||
|
||||
MatrixOperations<double>::multiply(Trot[0], Tfi[0], Tdotfi[0], 3, 3,
|
||||
3);
|
||||
|
||||
MatrixOperations<double>::transpose(Tdotfi[0], Tdotif[0], 3);
|
||||
|
||||
double velocityCorrection[3];
|
||||
|
||||
MatrixOperations<double>::multiply(Tdotif[0],
|
||||
ecfPositionIfCoordinatesAreVelocity, velocityCorrection, 3, 3,
|
||||
1);
|
||||
|
||||
VectorOperations<double>::add(velocityCorrection, eciCoordinates,
|
||||
eciCoordinates, 3);
|
||||
}
|
||||
}
|
||||
|
||||
double CoordinateTransformations::getJuleanCenturiesTT(timeval timeUTC) {
|
||||
timeval timeTT;
|
||||
Clock::convertUTCToTT(timeUTC, &timeTT);
|
||||
double jD2000TT;
|
||||
Clock::convertTimevalToJD2000(timeTT, &jD2000TT);
|
||||
|
||||
return jD2000TT / 36525.;
|
||||
}
|
||||
|
||||
void CoordinateTransformations::eciToEcf(const double* eciCoordinates,
|
||||
double* ecfCoordinates,
|
||||
const double* eciPositionIfCoordinatesAreVelocity,timeval *timeUTCin){
|
||||
timeval timeUTC;
|
||||
if (timeUTCin != NULL) {
|
||||
timeUTC = *timeUTCin;
|
||||
}else{
|
||||
Clock::getClock_timeval(&timeUTC);
|
||||
}
|
||||
|
||||
double Tfi[3][3];
|
||||
|
||||
getTransMatrixECITOECF(timeUTC,Tfi);
|
||||
|
||||
MatrixOperations<double>::multiply(Tfi[0],eciCoordinates,ecfCoordinates,3,3,1);
|
||||
|
||||
if (eciPositionIfCoordinatesAreVelocity != NULL) {
|
||||
|
||||
double Tdotfi[3][3];
|
||||
double Trot[3][3] = { { 0, Earth::OMEGA, 0 },
|
||||
{ 0 - Earth::OMEGA, 0, 0 }, { 0, 0, 0 } };
|
||||
|
||||
MatrixOperations<double>::multiply(Trot[0], Tfi[0], Tdotfi[0], 3, 3,
|
||||
3);
|
||||
|
||||
double velocityCorrection[3];
|
||||
|
||||
MatrixOperations<double>::multiply(Tdotfi[0],
|
||||
eciPositionIfCoordinatesAreVelocity, velocityCorrection, 3, 3,
|
||||
1);
|
||||
|
||||
VectorOperations<double>::add(ecfCoordinates, velocityCorrection,
|
||||
ecfCoordinates, 3);
|
||||
}
|
||||
};
|
||||
|
||||
void CoordinateTransformations::getTransMatrixECITOECF(timeval timeUTC,double Tfi[3][3]){
|
||||
double TTt2000 = getJuleanCenturiesTT(timeUTC);
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Calculate Precession Matrix
|
||||
|
||||
double zeta = 0.0111808609 * TTt2000
|
||||
+ 1.46355554053347E-006 * TTt2000 * TTt2000
|
||||
+ 8.72567663260943E-008 * TTt2000 * TTt2000 * TTt2000;
|
||||
double theta_p = 0.0097171735 * TTt2000
|
||||
- 2.06845757045384E-006 * TTt2000 * TTt2000
|
||||
- 2.02812107218552E-007 * TTt2000 * TTt2000 * TTt2000;
|
||||
double z = zeta + 3.8436028638364E-006 * TTt2000 * TTt2000
|
||||
+ 0.000000001 * TTt2000 * TTt2000 * TTt2000;
|
||||
|
||||
double mPrecession[3][3];
|
||||
|
||||
mPrecession[0][0] = -sin(z) * sin(zeta) + cos(z) * cos(theta_p) * cos(zeta);
|
||||
mPrecession[1][0] = cos(z) * sin(zeta) + sin(z) * cos(theta_p) * cos(zeta);
|
||||
mPrecession[2][0] = sin(theta_p) * cos(zeta);
|
||||
|
||||
mPrecession[0][1] = -sin(z) * cos(zeta) - cos(z) * cos(theta_p) * sin(zeta);
|
||||
mPrecession[1][1] = cos(z) * cos(zeta) - sin(z) * cos(theta_p) * sin(zeta);
|
||||
mPrecession[2][1] = -sin(theta_p) * sin(zeta);
|
||||
|
||||
mPrecession[0][2] = -cos(z) * sin(theta_p);
|
||||
mPrecession[1][2] = -sin(z) * sin(theta_p);
|
||||
mPrecession[2][2] = cos(theta_p);
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Calculate Nutation Matrix
|
||||
|
||||
double omega_moon = 2.1824386244 - 33.7570459338 * TTt2000
|
||||
+ 3.61428599267159E-005 * TTt2000 * TTt2000
|
||||
+ 3.87850944887629E-008 * TTt2000 * TTt2000 * TTt2000;
|
||||
|
||||
double deltaPsi = -0.000083388 * sin(omega_moon);
|
||||
double deltaEpsilon = 4.46174030725106E-005 * cos(omega_moon);
|
||||
|
||||
double epsilon = 0.4090928042 - 0.0002269655 * TTt2000
|
||||
- 2.86040071854626E-009 * TTt2000 * TTt2000
|
||||
+ 8.78967203851589E-009 * TTt2000 * TTt2000 * TTt2000;
|
||||
|
||||
|
||||
double mNutation[3][3];
|
||||
|
||||
mNutation[0][0] = cos(deltaPsi);
|
||||
mNutation[1][0] = cos(epsilon + deltaEpsilon) * sin(deltaPsi);
|
||||
mNutation[2][0] = sin(epsilon + deltaEpsilon) * sin(deltaPsi);
|
||||
|
||||
mNutation[0][1] = -cos(epsilon) * sin(deltaPsi);
|
||||
mNutation[1][1] = cos(epsilon) * cos(epsilon + deltaEpsilon) * cos(deltaPsi)
|
||||
+ sin(epsilon) * sin(epsilon + deltaEpsilon);
|
||||
mNutation[2][1] = cos(epsilon) * sin(epsilon + deltaEpsilon) * cos(deltaPsi)
|
||||
- sin(epsilon) * cos(epsilon + deltaEpsilon);
|
||||
|
||||
mNutation[0][2] = -sin(epsilon) * sin(deltaPsi);
|
||||
mNutation[1][2] = sin(epsilon) * cos(epsilon + deltaEpsilon) * cos(deltaPsi)
|
||||
- cos(epsilon) * sin(epsilon + deltaEpsilon);
|
||||
mNutation[2][2] = sin(epsilon) * sin(epsilon + deltaEpsilon) * cos(deltaPsi)
|
||||
+ cos(epsilon) * cos(epsilon + deltaEpsilon);
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Calculate Earth rotation matrix
|
||||
//calculate theta
|
||||
|
||||
double mTheta[3][3];
|
||||
double Ttemp[3][3];
|
||||
getEarthRotationMatrix(timeUTC, mTheta);
|
||||
|
||||
//polar motion is neglected
|
||||
MatrixOperations<double>::multiply(mNutation[0], mPrecession[0], Ttemp[0],
|
||||
3, 3, 3);
|
||||
|
||||
MatrixOperations<double>::multiply(mTheta[0], Ttemp[0], Tfi[0], 3, 3, 3);
|
||||
};
|
@ -1,34 +0,0 @@
|
||||
#ifndef COORDINATETRANSFORMATIONS_H_
|
||||
#define COORDINATETRANSFORMATIONS_H_
|
||||
|
||||
#include "../timemanager/Clock.h"
|
||||
#include <cstring>
|
||||
|
||||
class CoordinateTransformations {
|
||||
public:
|
||||
static void positionEcfToEci(const double* ecfCoordinates, double* eciCoordinates, timeval *timeUTC = NULL);
|
||||
|
||||
static void velocityEcfToEci(const double* ecfVelocity,
|
||||
const double* ecfPosition,
|
||||
double* eciVelocity, timeval *timeUTC = NULL);
|
||||
|
||||
static void positionEciToEcf(const double* eciCoordinates, double* ecfCoordinates,timeval *timeUTC = NULL);
|
||||
static void velocityEciToEcf(const double* eciVelocity,const double* eciPosition, double* ecfVelocity,timeval* timeUTC = NULL);
|
||||
|
||||
static double getEarthRotationAngle(timeval timeUTC);
|
||||
|
||||
static void getEarthRotationMatrix(timeval timeUTC, double matrix[][3]);
|
||||
private:
|
||||
CoordinateTransformations();
|
||||
static void ecfToEci(const double* ecfCoordinates, double* eciCoordinates,
|
||||
const double* ecfPositionIfCoordinatesAreVelocity, timeval *timeUTCin);
|
||||
static void eciToEcf(const double* eciCoordinates,
|
||||
double* ecfCoordinates,
|
||||
const double* eciPositionIfCoordinatesAreVelocity,timeval *timeUTCin);
|
||||
|
||||
static double getJuleanCenturiesTT(timeval timeUTC);
|
||||
static void getTransMatrixECITOECF(timeval time,double Tfi[3][3]);
|
||||
|
||||
};
|
||||
|
||||
#endif /* COORDINATETRANSFORMATIONS_H_ */
|
@ -1,180 +0,0 @@
|
||||
#ifndef FRAMEWORK_COORDINATES_JGM3MODEL_H_
|
||||
#define FRAMEWORK_COORDINATES_JGM3MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "CoordinateTransformations.h"
|
||||
#include "../globalfunctions/math/VectorOperations.h"
|
||||
#include "../globalfunctions/timevalOperations.h"
|
||||
#include "../globalfunctions/constants.h"
|
||||
#include <memory.h>
|
||||
|
||||
|
||||
template<uint8_t DEGREE,uint8_t ORDER>
|
||||
class Jgm3Model {
|
||||
public:
|
||||
static const uint32_t factorialLookupTable[DEGREE+3]; //This table is used instead of factorial calculation, must be increased if order or degree is higher
|
||||
|
||||
Jgm3Model() {
|
||||
y0[0] = 0;
|
||||
y0[1] = 0;
|
||||
y0[2] = 0;
|
||||
y0[3] = 0;
|
||||
y0[4] = 0;
|
||||
y0[5] = 0;
|
||||
|
||||
lastExecutionTime.tv_sec = 0;
|
||||
lastExecutionTime.tv_usec = 0;
|
||||
}
|
||||
virtual ~Jgm3Model(){};
|
||||
|
||||
//double acsNavOrbit(double posECF[3],double velECF[3],timeval gpsTime);
|
||||
|
||||
double y0[6]; //position and velocity at beginning of RK step in EC
|
||||
timeval lastExecutionTime; //Time of last execution
|
||||
|
||||
|
||||
void accelDegOrd(const double pos[3],const double S[ORDER+1][DEGREE+1],const double C[ORDER+1][DEGREE+1],double* accel){
|
||||
//Get radius of this position
|
||||
double r = VectorOperations<double>::norm(pos,3);
|
||||
|
||||
|
||||
|
||||
//Initialize the V and W matrix
|
||||
double V[DEGREE+2][ORDER+2] = {{0}};
|
||||
double W[DEGREE+2][ORDER+2] = {{0}};
|
||||
|
||||
for(uint8_t m=0;m<(ORDER+2);m++){
|
||||
for(uint8_t n=m;n<(DEGREE+2);n++){
|
||||
if((n==0) && (m==0)){
|
||||
//Montenbruck "Satellite Orbits Eq.3.31"
|
||||
V[0][0] = Earth::MEAN_RADIUS / r;
|
||||
W[0][0] = 0;
|
||||
}else{
|
||||
if(n==m){
|
||||
//Montenbruck "Satellite Orbits Eq.3.29"
|
||||
V[m][m] = (2*m-1)* (pos[0]*Earth::MEAN_RADIUS/pow(r,2)*V[m-1][m-1] - pos[1]*Earth::MEAN_RADIUS/pow(r,2)*W[m-1][m-1]);
|
||||
W[m][m] = (2*m-1)* (pos[0]*Earth::MEAN_RADIUS/pow(r,2)*W[m-1][m-1] + pos[1]*Earth::MEAN_RADIUS/pow(r,2)*V[m-1][m-1]);
|
||||
}else{
|
||||
//Montenbruck "Satellite Orbits Eq.3.30"
|
||||
V[n][m] = ((2*n-1)/(double)(n-m))*pos[2]*Earth::MEAN_RADIUS / pow(r,2)*V[n-1][m];
|
||||
W[n][m] = ((2*n-1)/(double)(n-m))*pos[2]*Earth::MEAN_RADIUS / pow(r,2)*W[n-1][m];
|
||||
if(n!=(m+1)){
|
||||
V[n][m] = V[n][m] - (((n+m-1)/(double)(n-m)) * (pow(Earth::MEAN_RADIUS,2) / pow(r,2)) * V[n-2][m]);
|
||||
W[n][m] = W[n][m] - (((n+m-1)/(double)(n-m)) * (pow(Earth::MEAN_RADIUS,2) / pow(r,2)) * W[n-2][m]);
|
||||
}//End of if(n!=(m+1))
|
||||
}//End of if(n==m){
|
||||
}//End of if(n==0 and m==0)
|
||||
}//End of for(uint8_t n=0;n<(DEGREE+1);n++)
|
||||
}//End of for(uint8_t m=0;m<(ORDER+1);m++)
|
||||
|
||||
|
||||
//overwrite accel if not properly initialized
|
||||
accel[0] = 0;
|
||||
accel[1] = 0;
|
||||
accel[2] = 0;
|
||||
|
||||
for(uint8_t m=0;m<(ORDER+1);m++){
|
||||
for(uint8_t n=m;n<(DEGREE+1);n++){
|
||||
//Use table lookup to get factorial
|
||||
double partAccel[3] = {0};
|
||||
double factor = Earth::STANDARD_GRAVITATIONAL_PARAMETER/pow(Earth::MEAN_RADIUS,2);
|
||||
if(m==0){
|
||||
//Montenbruck "Satellite Orbits Eq.3.33"
|
||||
partAccel[0] = factor * (-C[n][0]*V[n+1][1]);
|
||||
partAccel[1] = factor * (-C[n][0]*W[n+1][1]);
|
||||
}else{
|
||||
double factMN = static_cast<double>(factorialLookupTable[n-m+2]) / static_cast<double>(factorialLookupTable[n-m]);
|
||||
partAccel[0] = factor * 0.5 * ((-C[n][m]*V[n+1][m+1]-S[n][m]*W[n+1][m+1])+factMN*(C[n][m]*V[n+1][m-1]+S[n][m]*W[n+1][m-1]));
|
||||
partAccel[1] = factor * 0.5 * ((-C[n][m]*W[n+1][m+1]+S[n][m]*V[n+1][m+1])+factMN*(-C[n][m]*W[n+1][m-1]+S[n][m]*V[n+1][m-1]));
|
||||
}
|
||||
|
||||
partAccel[2] = factor * ((n-m+1)*(-C[n][m]*V[n+1][m]-S[n][m]*W[n+1][m]));
|
||||
|
||||
|
||||
accel[0] += partAccel[0];
|
||||
accel[1] += partAccel[1];
|
||||
accel[2] += partAccel[2];
|
||||
}//End of for(uint8_t n=0;n<DEGREE;n++)
|
||||
}//End of uint8_t m=0;m<ORDER;m++
|
||||
}
|
||||
|
||||
void initializeNavOrbit(const double position[3],const double velocity[3], timeval timeUTC){
|
||||
CoordinateTransformations::positionEcfToEci(position,&y0[0],&timeUTC);
|
||||
CoordinateTransformations::velocityEcfToEci(velocity,position,&y0[3],&timeUTC);
|
||||
lastExecutionTime = timeUTC;
|
||||
}
|
||||
|
||||
|
||||
void acsNavOrbit(timeval timeUTC, const double S[ORDER+1][DEGREE+1],const double C[ORDER+1][DEGREE+1], double outputPos[3],double outputVel[3]){
|
||||
|
||||
//RK4 Integration for this timestamp
|
||||
double deltaT = timevalOperations::toDouble(timeUTC-lastExecutionTime);
|
||||
|
||||
double y0dot[6] = {0,0,0,0,0,0};
|
||||
double yA[6] = {0,0,0,0,0,0};
|
||||
double yAdot[6] = {0,0,0,0,0,0};
|
||||
double yB[6] = {0,0,0,0,0,0};
|
||||
double yBdot[6] = {0,0,0,0,0,0};
|
||||
double yC[6] = {0,0,0,0,0,0};
|
||||
double yCdot[6] = {0,0,0,0,0,0};
|
||||
|
||||
//Step One
|
||||
rungeKuttaStep(y0,y0dot,lastExecutionTime,S,C);
|
||||
|
||||
//Step Two
|
||||
VectorOperations<double>::mulScalar(y0dot,deltaT/2,yA,6);
|
||||
VectorOperations<double>::add(y0,yA,yA,6);
|
||||
rungeKuttaStep(yA,yAdot,lastExecutionTime,S,C);
|
||||
|
||||
//Step Three
|
||||
VectorOperations<double>::mulScalar(yAdot,deltaT/2,yB,6);
|
||||
VectorOperations<double>::add(y0,yB,yB,6);
|
||||
rungeKuttaStep(yB,yBdot,lastExecutionTime,S,C);
|
||||
|
||||
//Step Four
|
||||
VectorOperations<double>::mulScalar(yBdot,deltaT,yC,6);
|
||||
VectorOperations<double>::add(y0,yC,yC,6);
|
||||
rungeKuttaStep(yC,yCdot,lastExecutionTime,S,C);
|
||||
|
||||
//Calc new State
|
||||
VectorOperations<double>::mulScalar(yAdot,2,yAdot,6);
|
||||
VectorOperations<double>::mulScalar(yBdot,2,yBdot,6);
|
||||
VectorOperations<double>::add(y0dot,yAdot,y0dot,6);
|
||||
VectorOperations<double>::add(y0dot,yBdot,y0dot,6);
|
||||
VectorOperations<double>::add(y0dot,yCdot,y0dot,6);
|
||||
VectorOperations<double>::mulScalar(y0dot,1./6.*deltaT,y0dot,6);
|
||||
VectorOperations<double>::add(y0,y0dot,y0,6);
|
||||
|
||||
CoordinateTransformations::positionEciToEcf(&y0[0],outputPos,&timeUTC);
|
||||
CoordinateTransformations::velocityEciToEcf(&y0[3],&y0[0],outputVel,&timeUTC);
|
||||
|
||||
lastExecutionTime = timeUTC;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rungeKuttaStep(const double* yIn,double* yOut,timeval time, const double S[ORDER+1][DEGREE+1],const double C[ORDER+1][DEGREE+1]){
|
||||
double rECF[3] = {0,0,0};
|
||||
double rDotECF[3] = {0,0,0};
|
||||
double accelECF[3] = {0,0,0};
|
||||
double accelECI[3] = {0,0,0};
|
||||
|
||||
|
||||
CoordinateTransformations::positionEciToEcf(&yIn[0],rECF,&time);
|
||||
CoordinateTransformations::velocityEciToEcf(&yIn[3],&yIn[0],rDotECF,&time);
|
||||
accelDegOrd(rECF,S,C,accelECF);
|
||||
//This is not correct, as the acceleration would have derived terms but we don't know the velocity and position at that time
|
||||
//Tests showed that a wrong velocity does make the equation worse than neglecting it
|
||||
CoordinateTransformations::positionEcfToEci(accelECF,accelECI,&time);
|
||||
memcpy(&yOut[0],&yIn[3],sizeof(yOut[0])*3);
|
||||
memcpy(&yOut[3],accelECI,sizeof(yOut[0])*3);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_COORDINATES_JGM3MODEL_H_ */
|
@ -1,228 +0,0 @@
|
||||
#include "CoordinateTransformations.h"
|
||||
#include "Sgp4Propagator.h"
|
||||
#include "../globalfunctions/constants.h"
|
||||
#include "../globalfunctions/math/MatrixOperations.h"
|
||||
#include "../globalfunctions/math/VectorOperations.h"
|
||||
#include "../globalfunctions/timevalOperations.h"
|
||||
#include <cstring>
|
||||
Sgp4Propagator::Sgp4Propagator() :
|
||||
initialized(false), epoch({0, 0}), whichconst(wgs84) {
|
||||
|
||||
}
|
||||
|
||||
Sgp4Propagator::~Sgp4Propagator() {
|
||||
|
||||
}
|
||||
|
||||
void jday(int year, int mon, int day, int hr, int minute, double sec,
|
||||
double& jd) {
|
||||
jd = 367.0 * year - floor((7 * (year + floor((mon + 9) / 12.0))) * 0.25)
|
||||
+ floor(275 * mon / 9.0) + day + 1721013.5
|
||||
+ ((sec / 60.0 + minute) / 60.0 + hr) / 24.0; // ut in days
|
||||
// - 0.5*sgn(100.0*year + mon - 190002.5) + 0.5;
|
||||
}
|
||||
|
||||
void days2mdhms(int year, double days, int& mon, int& day, int& hr, int& minute,
|
||||
double& sec) {
|
||||
int i, inttemp, dayofyr;
|
||||
double temp;
|
||||
int lmonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
dayofyr = (int) floor(days);
|
||||
/* ----------------- find month and day of month ---------------- */
|
||||
if ((year % 4) == 0)
|
||||
lmonth[1] = 29;
|
||||
|
||||
i = 1;
|
||||
inttemp = 0;
|
||||
while ((dayofyr > inttemp + lmonth[i - 1]) && (i < 12)) {
|
||||
inttemp = inttemp + lmonth[i - 1];
|
||||
i++;
|
||||
}
|
||||
mon = i;
|
||||
day = dayofyr - inttemp;
|
||||
|
||||
/* ----------------- find hours minutes and seconds ------------- */
|
||||
temp = (days - dayofyr) * 24.0;
|
||||
hr = (int) floor(temp);
|
||||
temp = (temp - hr) * 60.0;
|
||||
minute = (int) floor(temp);
|
||||
sec = (temp - minute) * 60.0;
|
||||
}
|
||||
|
||||
ReturnValue_t Sgp4Propagator::initialize(const uint8_t* line1,
|
||||
const uint8_t* line2) {
|
||||
|
||||
char longstr1[130];
|
||||
char longstr2[130];
|
||||
|
||||
//need some space for decimal points
|
||||
memcpy(longstr1, line1, 69);
|
||||
memcpy(longstr2, line2, 69);
|
||||
|
||||
const double deg2rad = Math::PI / 180.0; // 0.0174532925199433
|
||||
const double xpdotp = 1440.0 / (2.0 * Math::PI); // 229.1831180523293
|
||||
|
||||
double sec, mu, radiusearthkm, tumin, xke, j2, j3, j4, j3oj2;
|
||||
int cardnumb, numb, j;
|
||||
long revnum = 0, elnum = 0;
|
||||
char classification, intldesg[11];
|
||||
int year = 0;
|
||||
int mon, day, hr, minute, nexp, ibexp;
|
||||
|
||||
getgravconst(whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2);
|
||||
|
||||
satrec.error = 0;
|
||||
|
||||
// set the implied decimal points since doing a formated read
|
||||
// fixes for bad input data values (missing, ...)
|
||||
for (j = 10; j <= 15; j++)
|
||||
if (longstr1[j] == ' ')
|
||||
longstr1[j] = '_';
|
||||
|
||||
if (longstr1[44] != ' ')
|
||||
longstr1[43] = longstr1[44];
|
||||
longstr1[44] = '.';
|
||||
if (longstr1[7] == ' ')
|
||||
longstr1[7] = 'U';
|
||||
if (longstr1[9] == ' ')
|
||||
longstr1[9] = '.';
|
||||
for (j = 45; j <= 49; j++)
|
||||
if (longstr1[j] == ' ')
|
||||
longstr1[j] = '0';
|
||||
if (longstr1[51] == ' ')
|
||||
longstr1[51] = '0';
|
||||
if (longstr1[53] != ' ')
|
||||
longstr1[52] = longstr1[53];
|
||||
longstr1[53] = '.';
|
||||
longstr2[25] = '.';
|
||||
for (j = 26; j <= 32; j++)
|
||||
if (longstr2[j] == ' ')
|
||||
longstr2[j] = '0';
|
||||
if (longstr1[62] == ' ')
|
||||
longstr1[62] = '0';
|
||||
if (longstr1[68] == ' ')
|
||||
longstr1[68] = '0';
|
||||
|
||||
sscanf(longstr1,
|
||||
"%2d %5ld %1c %10s %2d %12lf %11lf %7lf %2d %7lf %2d %2d %6ld ",
|
||||
&cardnumb, &satrec.satnum, &classification, intldesg,
|
||||
&satrec.epochyr, &satrec.epochdays, &satrec.ndot, &satrec.nddot,
|
||||
&nexp, &satrec.bstar, &ibexp, &numb, &elnum);
|
||||
|
||||
if (longstr2[52] == ' ') {
|
||||
sscanf(longstr2, "%2d %5ld %9lf %9lf %8lf %9lf %9lf %10lf %6ld \n",
|
||||
&cardnumb, &satrec.satnum, &satrec.inclo, &satrec.nodeo,
|
||||
&satrec.ecco, &satrec.argpo, &satrec.mo, &satrec.no, &revnum);
|
||||
} else {
|
||||
sscanf(longstr2, "%2d %5ld %9lf %9lf %8lf %9lf %9lf %11lf %6ld \n",
|
||||
&cardnumb, &satrec.satnum, &satrec.inclo, &satrec.nodeo,
|
||||
&satrec.ecco, &satrec.argpo, &satrec.mo, &satrec.no, &revnum);
|
||||
}
|
||||
|
||||
// ---- find no, ndot, nddot ----
|
||||
satrec.no = satrec.no / xpdotp; //* rad/min
|
||||
satrec.nddot = satrec.nddot * pow(10.0, nexp);
|
||||
satrec.bstar = satrec.bstar * pow(10.0, ibexp);
|
||||
|
||||
// ---- convert to sgp4 units ----
|
||||
satrec.a = pow(satrec.no * tumin, (-2.0 / 3.0));
|
||||
satrec.ndot = satrec.ndot / (xpdotp * 1440.0); //* ? * minperday
|
||||
satrec.nddot = satrec.nddot / (xpdotp * 1440.0 * 1440);
|
||||
|
||||
// ---- find standard orbital elements ----
|
||||
satrec.inclo = satrec.inclo * deg2rad;
|
||||
satrec.nodeo = satrec.nodeo * deg2rad;
|
||||
satrec.argpo = satrec.argpo * deg2rad;
|
||||
satrec.mo = satrec.mo * deg2rad;
|
||||
|
||||
satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
|
||||
satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// find sgp4epoch time of element set
|
||||
// remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
|
||||
// and minutes from the epoch (time)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// ---------------- temp fix for years from 1957-2056 -------------------
|
||||
// --------- correct fix will occur when year is 4-digit in tle ---------
|
||||
if (satrec.epochyr < 57) {
|
||||
year = satrec.epochyr + 2000;
|
||||
} else {
|
||||
year = satrec.epochyr + 1900;
|
||||
}
|
||||
|
||||
days2mdhms(year, satrec.epochdays, mon, day, hr, minute, sec);
|
||||
jday(year, mon, day, hr, minute, sec, satrec.jdsatepoch);
|
||||
|
||||
double unixSeconds = (satrec.jdsatepoch - 2451544.5) * 24 * 3600
|
||||
+ 946684800;
|
||||
|
||||
epoch.tv_sec = unixSeconds;
|
||||
double subseconds = unixSeconds - epoch.tv_sec;
|
||||
epoch.tv_usec = subseconds * 1000000;
|
||||
|
||||
// ---------------- initialize the orbit at sgp4epoch -------------------
|
||||
uint8_t result = sgp4init(whichconst, satrec.satnum,
|
||||
satrec.jdsatepoch - 2433281.5, satrec.bstar, satrec.ecco,
|
||||
satrec.argpo, satrec.inclo, satrec.mo, satrec.no, satrec.nodeo,
|
||||
satrec);
|
||||
|
||||
if (result != 00) {
|
||||
return MAKE_RETURN_CODE(result);
|
||||
} else {
|
||||
initialized = true;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t Sgp4Propagator::propagate(double* position, double* velocity,
|
||||
timeval time, uint8_t gpsUtcOffset) {
|
||||
|
||||
if (!initialized) {
|
||||
return TLE_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
//Time since epoch in minutes
|
||||
timeval timeSinceEpoch = time - epoch;
|
||||
double minutesSinceEpoch = timeSinceEpoch.tv_sec / 60.
|
||||
+ timeSinceEpoch.tv_usec / 60000000.;
|
||||
|
||||
double yearsSinceEpoch = minutesSinceEpoch / 60 / 24 / 365;
|
||||
|
||||
if ((yearsSinceEpoch > 1) || (yearsSinceEpoch < -1)) {
|
||||
return TLE_TOO_OLD;
|
||||
}
|
||||
|
||||
double positionTEME[3];
|
||||
double velocityTEME[3];
|
||||
|
||||
uint8_t result = sgp4(whichconst, satrec, minutesSinceEpoch, positionTEME,
|
||||
velocityTEME);
|
||||
|
||||
VectorOperations<double>::mulScalar(positionTEME, 1000, positionTEME, 3);
|
||||
VectorOperations<double>::mulScalar(velocityTEME, 1000, velocityTEME, 3);
|
||||
|
||||
//Transform to ECF
|
||||
double earthRotationMatrix[3][3];
|
||||
CoordinateTransformations::getEarthRotationMatrix(time,
|
||||
earthRotationMatrix);
|
||||
|
||||
MatrixOperations<double>::multiply(earthRotationMatrix[0], positionTEME,
|
||||
position, 3, 3, 1);
|
||||
MatrixOperations<double>::multiply(earthRotationMatrix[0], velocityTEME,
|
||||
velocity, 3, 3, 1);
|
||||
|
||||
double omegaEarth[3] = { 0, 0, Earth::OMEGA };
|
||||
double velocityCorrection[3];
|
||||
VectorOperations<double>::cross(omegaEarth, position, velocityCorrection);
|
||||
VectorOperations<double>::subtract(velocity, velocityCorrection, velocity);
|
||||
|
||||
if (result != 0) {
|
||||
return MAKE_RETURN_CODE(result || 0xB0);
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef SGP4PROPAGATOR_H_
|
||||
#define SGP4PROPAGATOR_H_
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "../contrib/sgp4/sgp4unit.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class Sgp4Propagator {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SGP4PROPAGATOR_CLASS;
|
||||
static const ReturnValue_t INVALID_ECCENTRICITY = MAKE_RETURN_CODE(0xA1);
|
||||
static const ReturnValue_t INVALID_MEAN_MOTION = MAKE_RETURN_CODE(0xA2);
|
||||
static const ReturnValue_t INVALID_PERTURBATION_ELEMENTS = MAKE_RETURN_CODE(0xA3);
|
||||
static const ReturnValue_t INVALID_SEMI_LATUS_RECTUM = MAKE_RETURN_CODE(0xA4);
|
||||
static const ReturnValue_t INVALID_EPOCH_ELEMENTS = MAKE_RETURN_CODE(0xA5);
|
||||
static const ReturnValue_t SATELLITE_HAS_DECAYED = MAKE_RETURN_CODE(0xA6);
|
||||
static const ReturnValue_t TLE_TOO_OLD = MAKE_RETURN_CODE(0xB1);
|
||||
static const ReturnValue_t TLE_NOT_INITIALIZED = MAKE_RETURN_CODE(0xB2);
|
||||
|
||||
|
||||
|
||||
Sgp4Propagator();
|
||||
virtual ~Sgp4Propagator();
|
||||
|
||||
ReturnValue_t initialize(const uint8_t *line1, const uint8_t *line2);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param[out] position in ECF
|
||||
* @param[out] velocity in ECF
|
||||
* @param time to which to propagate
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t propagate(double *position, double *velocity, timeval time, uint8_t gpsUtcOffset);
|
||||
|
||||
private:
|
||||
bool initialized;
|
||||
timeval epoch;
|
||||
elsetrec satrec;
|
||||
gravconsttype whichconst;
|
||||
|
||||
};
|
||||
|
||||
#endif /* SGP4PROPAGATOR_H_ */
|
@ -1,62 +0,0 @@
|
||||
/**
|
||||
* @file BCFrame.h
|
||||
* @brief This file defines the BCFrame class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef BCFRAME_H_
|
||||
#define BCFRAME_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
|
||||
/**
|
||||
* Small helper class to identify a BcFrame.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class BcFrame: public CCSDSReturnValuesIF {
|
||||
private:
|
||||
static const uint8_t UNLOCK_COMMAND = 0b00000000;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_1 = 0b10000010;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_2 = 0b00000000;//! Identifier for a certain BC Command.
|
||||
|
||||
public:
|
||||
uint8_t byte1; //!< First content byte
|
||||
uint8_t byte2; //!< Second content byte
|
||||
uint8_t vR; //!< vR byte
|
||||
/**
|
||||
* Simple default constructor.
|
||||
*/
|
||||
BcFrame() :
|
||||
byte1(0), byte2(0), vR(0) {
|
||||
}
|
||||
/**
|
||||
* Main and only useful method of the class.
|
||||
* With the buffer and size information passed, the class passes the content
|
||||
* and checks if it is one of the two valid BC Command Frames.
|
||||
* @param inBuffer Content of the frame to check,
|
||||
* @param inSize Size of the data to check.
|
||||
* @return - #BC_ILLEGAL_COMMAND if it is no command.
|
||||
* - #BC_IS_UNLOCK_COMMAND if it is an unlock command.
|
||||
* - #BC_IS_SET_VR_COMMAND if it is such.
|
||||
*/
|
||||
ReturnValue_t initialize(const uint8_t* inBuffer, uint16_t inSize) {
|
||||
ReturnValue_t returnValue = BC_ILLEGAL_COMMAND;
|
||||
if (inSize == 1) {
|
||||
byte1 = inBuffer[0];
|
||||
if (byte1 == UNLOCK_COMMAND) {
|
||||
returnValue = BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
} else if (inSize == 3) {
|
||||
byte1 = inBuffer[0];
|
||||
byte2 = inBuffer[1];
|
||||
vR = inBuffer[2];
|
||||
if (byte1 == SET_V_R_1 && byte2 == SET_V_R_2) {
|
||||
returnValue = BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BCFRAME_H_ */
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file CCSDSReturnValuesIF.h
|
||||
* @brief This file defines the CCSDSReturnValuesIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CCSDSRETURNVALUESIF_H_
|
||||
#define CCSDSRETURNVALUESIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
/**
|
||||
* This is a helper class to collect special return values that come up during CCSDS Handling.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class CCSDSReturnValuesIF: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_HANDLER_IF; //!< Basic ID of the interface.
|
||||
|
||||
static const ReturnValue_t BC_IS_SET_VR_COMMAND = MAKE_RETURN_CODE( 0x01 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_IS_UNLOCK_COMMAND = MAKE_RETURN_CODE( 0x02 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_ILLEGAL_COMMAND = MAKE_RETURN_CODE( 0xB0 );//!< A value to describe an illegal BC frame.
|
||||
static const ReturnValue_t BOARD_READING_NOT_FINISHED = MAKE_RETURN_CODE( 0xB1 ); //! The CCSDS Board is not yet finished reading, it requires another cycle.
|
||||
|
||||
static const ReturnValue_t NS_POSITIVE_W = MAKE_RETURN_CODE( 0xF0 );//!< NS is in the positive window
|
||||
static const ReturnValue_t NS_NEGATIVE_W = MAKE_RETURN_CODE( 0xF1 );//!< NS is in the negative window
|
||||
static const ReturnValue_t NS_LOCKOUT = MAKE_RETURN_CODE( 0xF2 ); //!< NS is in lockout state
|
||||
static const ReturnValue_t FARM_IN_LOCKOUT = MAKE_RETURN_CODE( 0xF3 );//!< FARM-1 is currently in lockout state
|
||||
static const ReturnValue_t FARM_IN_WAIT = MAKE_RETURN_CODE( 0xF4 ); //!< FARM-1 is currently in wait state
|
||||
|
||||
static const ReturnValue_t WRONG_SYMBOL = MAKE_RETURN_CODE( 0xE0 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t DOUBLE_START = MAKE_RETURN_CODE( 0xE1 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t START_SYMBOL_MISSED = MAKE_RETURN_CODE( 0xE2 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t END_WITHOUT_START = MAKE_RETURN_CODE( 0xE3 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t TOO_LARGE = MAKE_RETURN_CODE( 0xE4 );//!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE( 0xE5 );//!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_TF_VERSION = MAKE_RETURN_CODE( 0xE6 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_SPACECRAFT_ID = MAKE_RETURN_CODE( 0xE7 );//!< An error code for a frame.
|
||||
static const ReturnValue_t NO_VALID_FRAME_TYPE = MAKE_RETURN_CODE( 0xE8 );//!< An error code for a frame.
|
||||
static const ReturnValue_t CRC_FAILED = MAKE_RETURN_CODE( 0xE9 );//!< An error code for a frame.
|
||||
static const ReturnValue_t VC_NOT_FOUND = MAKE_RETURN_CODE( 0xEA ); //!< An error code for a frame.
|
||||
static const ReturnValue_t FORWARDING_FAILED = MAKE_RETURN_CODE( 0xEB );//!< An error code for a frame.
|
||||
static const ReturnValue_t CONTENT_TOO_LARGE = MAKE_RETURN_CODE( 0xEC );//!< An error code for a frame.
|
||||
static const ReturnValue_t RESIDUAL_DATA = MAKE_RETURN_CODE( 0xED );//!< An error code for a frame.
|
||||
static const ReturnValue_t DATA_CORRUPTED = MAKE_RETURN_CODE( 0xEE );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_SEGMENTATION_FLAG = MAKE_RETURN_CODE( 0xEF );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_FLAG_COMBINATION = MAKE_RETURN_CODE( 0xD0 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t SHORTER_THAN_HEADER = MAKE_RETURN_CODE( 0xD1 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_BLOCKED_PACKET = MAKE_RETURN_CODE( 0xD2 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_MAP_EXTRACTION = MAKE_RETURN_CODE( 0xD3 ); //!< An error code for a frame.
|
||||
|
||||
virtual ~CCSDSReturnValuesIF() {
|
||||
} //!< Empty virtual destructor
|
||||
};
|
||||
|
||||
#endif /* CCSDSRETURNVALUESIF_H_ */
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
* @file Clcw.cpp
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Clcw.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
Clcw::Clcw() {
|
||||
content.raw = 0;
|
||||
content.status = STATUS_FIELD_DEFAULT;
|
||||
}
|
||||
|
||||
Clcw::~Clcw() {
|
||||
}
|
||||
|
||||
void Clcw::setVirtualChannel(uint8_t setChannel) {
|
||||
content.virtualChannelIdSpare = ((setChannel & 0x3F) << 2);
|
||||
}
|
||||
|
||||
void Clcw::setLockoutFlag(bool lockout) {
|
||||
content.flags = (content.flags & LOCKOUT_FLAG_MASK) | (lockout << LOCKOUT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setWaitFlag(bool waitFlag) {
|
||||
content.flags = (content.flags & WAIT_FLAG_MASK) | (waitFlag << WAIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setRetransmitFlag(bool retransmitFlag) {
|
||||
content.flags = (content.flags & RETRANSMIT_FLAG_MASK) | (retransmitFlag << RETRANSMIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setFarmBCount(uint8_t count) {
|
||||
content.flags = (content.flags & FARM_B_COUNT_MASK) | ((count & 0x03) << 1);
|
||||
}
|
||||
|
||||
void Clcw::setReceiverFrameSequenceNumber(uint8_t vR) {
|
||||
content.vRValue = vR;
|
||||
}
|
||||
|
||||
uint32_t Clcw::getAsWhole() {
|
||||
return content.raw;
|
||||
}
|
||||
|
||||
void Clcw::setRFAvailable(bool rfAvailable) {
|
||||
content.flags = (content.flags & NO_RF_AVIALABLE_MASK) | (!rfAvailable << NO_RF_AVIALABLE_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setBitLock(bool bitLock) {
|
||||
content.flags = (content.flags & NO_BIT_LOCK_MASK) | (!bitLock << NO_BIT_LOCK_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::print() {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "Clcw::print: Clcw is: " << std::hex << getAsWhole() << std::dec << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Clcw::setWhole(uint32_t rawClcw) {
|
||||
content.raw = rawClcw;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* @file Clcw.h
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CLCW_H_
|
||||
#define CLCW_H_
|
||||
|
||||
#include "ClcwIF.h"
|
||||
/**
|
||||
* Small helper method to handle the Clcw values.
|
||||
* It has a content struct that manages the register and can be set externally.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class Clcw : public ClcwIF {
|
||||
private:
|
||||
static const uint8_t STATUS_FIELD_DEFAULT = 0b00000001; //!< Default for the status field.
|
||||
static const uint8_t NO_RF_AVIALABLE_POSITION = 7; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_BIT_LOCK_POSITION = 6; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t LOCKOUT_FLAG_POSITION = 5; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t WAIT_FLAG_POSITION = 4; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t RETRANSMIT_FLAG_POSITION = 3; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_RF_AVIALABLE_MASK = 0xFF xor (1 << NO_RF_AVIALABLE_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t NO_BIT_LOCK_MASK = 0xFF xor (1 << NO_BIT_LOCK_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t LOCKOUT_FLAG_MASK = 0xFF xor (1 << LOCKOUT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t WAIT_FLAG_MASK = 0xFF xor (1 << WAIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t RETRANSMIT_FLAG_MASK = 0xFF xor (1 << RETRANSMIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t FARM_B_COUNT_MASK = 0b11111001; //!< Mask for a counter in the register.
|
||||
/**
|
||||
* This is the data structure of the CLCW register.
|
||||
*/
|
||||
union clcwContent {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t status;
|
||||
uint8_t virtualChannelIdSpare;
|
||||
uint8_t flags;
|
||||
uint8_t vRValue;
|
||||
};
|
||||
};
|
||||
clcwContent content; //!< Represents the content of the register.
|
||||
public:
|
||||
/**
|
||||
* The constructor sets everything to default values.
|
||||
*/
|
||||
Clcw();
|
||||
/**
|
||||
* Nothing happens in the destructor.
|
||||
*/
|
||||
~Clcw();
|
||||
void setVirtualChannel( uint8_t setChannel );
|
||||
void setLockoutFlag( bool lockout );
|
||||
void setWaitFlag( bool waitFlag );
|
||||
void setRetransmitFlag( bool retransmitFlag );
|
||||
void setFarmBCount( uint8_t count );
|
||||
void setReceiverFrameSequenceNumber( uint8_t vR );
|
||||
void setRFAvailable( bool rfAvailable );
|
||||
void setBitLock( bool bitLock );
|
||||
uint32_t getAsWhole();
|
||||
void setWhole( uint32_t rawClcw );
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif /* CLCW_H_ */
|
@ -1,70 +0,0 @@
|
||||
/**
|
||||
* @file ClcwIF.h
|
||||
* @brief This file defines the ClcwIF class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CLCWIF_H_
|
||||
#define CLCWIF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Interface to manage a CLCW register.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class ClcwIF {
|
||||
public:
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~ClcwIF() { }
|
||||
/**
|
||||
* Simple setter.
|
||||
* @param setChannel The virtual channel id to set.
|
||||
*/
|
||||
virtual void setVirtualChannel( uint8_t setChannel ) = 0;
|
||||
/**
|
||||
* Simple setter.
|
||||
* @param lockout status of the flag.
|
||||
*/
|
||||
virtual void setLockoutFlag( bool lockout ) = 0;
|
||||
/**
|
||||
* Simple setter.
|
||||
* @param waitFlag status of the flag.
|
||||
*/
|
||||
virtual void setWaitFlag( bool waitFlag ) = 0;
|
||||
/**
|
||||
* Simple setter.
|
||||
* @param retransmitFlag status of the flag.
|
||||
*/
|
||||
virtual void setRetransmitFlag( bool retransmitFlag ) = 0;
|
||||
/**
|
||||
* Sets the farm B count.
|
||||
* @param count A full 8bit counter value can be passed. Only the last three bits are used.
|
||||
*/
|
||||
virtual void setFarmBCount( uint8_t count ) = 0;
|
||||
/**
|
||||
* Simple setter.
|
||||
* @param vR Value of vR.
|
||||
*/
|
||||
virtual void setReceiverFrameSequenceNumber( uint8_t vR ) = 0;
|
||||
/**
|
||||
* Returns the register as a full 32bit value.
|
||||
* @return The value.
|
||||
*/
|
||||
virtual uint32_t getAsWhole() = 0;
|
||||
/**
|
||||
* Sets the whole content to this value.
|
||||
* @param rawClcw The value to set the content.
|
||||
*/
|
||||
virtual void setWhole( uint32_t rawClcw ) = 0;
|
||||
/**
|
||||
* Debug method to print the CLCW.
|
||||
*/
|
||||
virtual void print() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* CLCWIF_H_ */
|
@ -1,143 +0,0 @@
|
||||
#include "DataLinkLayer.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
DataLinkLayer::DataLinkLayer(uint8_t* set_frame_buffer, ClcwIF* setClcw,
|
||||
uint8_t set_start_sequence_length, uint16_t set_scid) :
|
||||
spacecraftId(set_scid), frameBuffer(set_frame_buffer), clcw(setClcw), receivedDataLength(0), currentFrame(
|
||||
NULL), startSequenceLength(set_start_sequence_length) {
|
||||
//Nothing to do except from setting the values above.
|
||||
}
|
||||
|
||||
DataLinkLayer::~DataLinkLayer() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameDelimitingAndFillRemoval() {
|
||||
if ((receivedDataLength - startSequenceLength) < FRAME_PRIMARY_HEADER_LENGTH) {
|
||||
return SHORTER_THAN_HEADER;
|
||||
}
|
||||
//Removing start sequence.
|
||||
//SHOULDDO: Not implemented here.
|
||||
while ( *frameBuffer == START_SEQUENCE_PATTERN ) {
|
||||
frameBuffer++;
|
||||
}
|
||||
TcTransferFrame frame_candidate(frameBuffer);
|
||||
this->currentFrame = frame_candidate; //should work with shallow copy.
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameValidationCheck() {
|
||||
//Check TF_version number
|
||||
if (this->currentFrame.getVersionNumber() != FRAME_VERSION_NUMBER_DEFAULT) {
|
||||
return WRONG_TF_VERSION;
|
||||
}
|
||||
//Check SpaceCraft ID
|
||||
if (this->currentFrame.getSpacecraftId() != this->spacecraftId) {
|
||||
return WRONG_SPACECRAFT_ID;
|
||||
}
|
||||
//Check other header limitations:
|
||||
if (!this->currentFrame.bypassFlagSet() && this->currentFrame.controlCommandFlagSet()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//- Spares are zero
|
||||
if (!this->currentFrame.spareIsZero()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//Compare detected frame length with the one in the header
|
||||
uint16_t length = currentFrame.getFullSize();
|
||||
if (length > receivedDataLength) {
|
||||
//Frame is too long or just right
|
||||
// error << "frameValidationCheck: Too short.";
|
||||
// currentFrame.print();
|
||||
return TOO_SHORT;
|
||||
}
|
||||
if (USE_CRC) {
|
||||
return this->frameCheckCRC();
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameCheckCRC() {
|
||||
uint16_t checkValue = CRC::crc16ccitt(this->currentFrame.getFullFrame(),
|
||||
this->currentFrame.getFullSize());
|
||||
if (checkValue == 0) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return CRC_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::allFramesReception() {
|
||||
ReturnValue_t status = this->frameDelimitingAndFillRemoval();
|
||||
if (status != RETURN_OK) {
|
||||
return status;
|
||||
}
|
||||
return this->frameValidationCheck();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::masterChannelDemultiplexing() {
|
||||
//Nothing to do at present. Ideally, there would be a map of MCID's identifying which MC to use.
|
||||
return virtualChannelDemultiplexing();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::virtualChannelDemultiplexing() {
|
||||
uint8_t vcId = currentFrame.getVirtualChannelId();
|
||||
virtualChannelIterator iter = virtualChannels.find(vcId);
|
||||
if (iter == virtualChannels.end()) {
|
||||
//Do not report because passive board will get this error all the time.
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return (iter->second)->frameAcceptanceAndReportingMechanism(¤tFrame, clcw);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::processFrame(uint16_t length) {
|
||||
receivedDataLength = length;
|
||||
ReturnValue_t status = allFramesReception();
|
||||
if (status != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataLinkLayer::processFrame: frame reception failed. "
|
||||
"Error code: " << std::hex << status << std::dec << std::endl;
|
||||
#endif
|
||||
// currentFrame.print();
|
||||
return status;
|
||||
} else {
|
||||
return masterChannelDemultiplexing();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::addVirtualChannel(uint8_t virtualChannelId,
|
||||
VirtualChannelReceptionIF* object) {
|
||||
std::pair<virtualChannelIterator, bool> returnValue = virtualChannels.insert(
|
||||
std::pair<uint8_t, VirtualChannelReceptionIF*>(virtualChannelId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
//Set Virtual Channel ID to first virtual channel instance in this DataLinkLayer instance to avoid faulty information (e.g. 0) in the VCID.
|
||||
if ( virtualChannels.begin() != virtualChannels.end() ) {
|
||||
clcw->setVirtualChannel( virtualChannels.begin()->second->getChannelId() );
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataLinkLayer::initialize: No VC assigned to this DLL instance! " << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
for (virtualChannelIterator iterator = virtualChannels.begin();
|
||||
iterator != virtualChannels.end(); iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
#ifndef DATALINKLAYER_H_
|
||||
#define DATALINKLAYER_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "ClcwIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReceptionIF.h"
|
||||
#include "../events/Event.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
class VirtualChannelReception;
|
||||
/**
|
||||
* A complete representation of the CCSDS Data Link Layer.
|
||||
* The operations of this layer are defined in the CCSDS TC Space Data Link Protocol
|
||||
* document. It is configured to handle a VC Demultiplexing function. All reception
|
||||
* steps are performed.
|
||||
*/
|
||||
class DataLinkLayer : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1;
|
||||
static const Event RF_AVAILABLE = MAKE_EVENT(0, severity::INFO); //!< A RF available signal was detected. P1: raw RFA state, P2: 0
|
||||
static const Event RF_LOST = MAKE_EVENT(1, severity::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0
|
||||
static const Event BIT_LOCK = MAKE_EVENT(2, severity::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0
|
||||
static const Event BIT_LOCK_LOST = MAKE_EVENT(3, severity::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0
|
||||
// static const Event RF_CHAIN_LOST = MAKE_EVENT(4, severity::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters.
|
||||
static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, severity::LOW); //!< The CCSDS Board could not interpret a TC
|
||||
/**
|
||||
* The Constructor sets the passed parameters and nothing else.
|
||||
* @param set_frame_buffer The buffer in which incoming frame candidates are stored.
|
||||
* @param setClcw The CLCW class to work on when returning CLCW information.
|
||||
* @param set_start_sequence_length Length of the Start sequence in front of every TC Transfer Frame.
|
||||
* @param set_scid The SCID to operate on.
|
||||
*/
|
||||
DataLinkLayer( uint8_t* set_frame_buffer, ClcwIF* setClcw, uint8_t set_start_sequence_length, uint16_t set_scid );
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
~DataLinkLayer();
|
||||
/**
|
||||
* This method tries to process a frame that is placed in #frameBuffer.
|
||||
* The procedures described in the Standard are performed.
|
||||
* @param length Length of the incoming frame candidate.
|
||||
* @return @c RETURN_OK on successful handling, otherwise the return codes of the higher methods.
|
||||
*/
|
||||
ReturnValue_t processFrame( uint16_t length );
|
||||
/**
|
||||
* Configuration method to add a new TC Virtual Channel.
|
||||
* Shall only be called during initialization. As soon as the method was called, the layer can
|
||||
* handle Frames directed to this VC.
|
||||
* @param virtualChannelId Id of the VC. Shall be smaller than 64.
|
||||
* @param object Reference to the object that handles the Frame.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addVirtualChannel( uint8_t virtualChannelId, VirtualChannelReceptionIF* object );
|
||||
/**
|
||||
* The initialization method calls the @c initialize routine of all virtual channels.
|
||||
* @return The return code of the first failed VC initialization or @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
private:
|
||||
typedef std::map<uint8_t, VirtualChannelReceptionIF*>::iterator virtualChannelIterator; //!< Typedef to simplify handling the #virtualChannels map.
|
||||
static const uint8_t FRAME_VERSION_NUMBER_DEFAULT = 0x00; //!< Constant for the default value of Frame Version Numbers.
|
||||
static const uint8_t FRAME_PRIMARY_HEADER_LENGTH = 5; //!< Length of the frame's primary header.
|
||||
static const uint8_t START_SEQUENCE_PATTERN = 0x00; //!< The start sequence pattern which might be with the frame.
|
||||
static const bool USE_CRC = true; //!< A global, so called "Managed Parameter" that identifies if incoming frames have CRC's or not.
|
||||
uint16_t spacecraftId; //!< The Space Craft Identifier (SCID) configured.
|
||||
uint8_t* frameBuffer; //!< A pointer to point to the current incoming frame.
|
||||
ClcwIF* clcw; //!< Pointer to store the CLCW to work on.
|
||||
uint16_t receivedDataLength; //!< Stores the length of the currently processed frame.
|
||||
TcTransferFrame currentFrame; //!< Stores a more convenient access to the current frame.
|
||||
uint8_t startSequenceLength; //!< Configured length of the start sequence. Maybe this must be done more variable.
|
||||
std::map<uint8_t, VirtualChannelReceptionIF*> virtualChannels; //!< Map of all virtual channels assigned.
|
||||
/**
|
||||
* Method that performs all possible frame validity checks (as specified).
|
||||
* @return Various error codes or @c RETURN_OK on success.
|
||||
*/
|
||||
ReturnValue_t frameValidationCheck();
|
||||
/**
|
||||
* First method to call.
|
||||
* Removes start sequence bytes and checks if the complete frame was received.
|
||||
* SHOULDDO: Maybe handling the start sequence must be done more variable.
|
||||
* @return @c RETURN_OK or @c TOO_SHORT.
|
||||
*/
|
||||
ReturnValue_t frameDelimitingAndFillRemoval();
|
||||
/**
|
||||
* Small helper method to check the CRC of the Frame.
|
||||
* @return @c RETURN_OK or @c CRC_FAILED.
|
||||
*/
|
||||
ReturnValue_t frameCheckCRC();
|
||||
/**
|
||||
* Method that groups the reception process of all Frames.
|
||||
* Calls #frameDelimitingAndFillRemoval and #frameValidationCheck.
|
||||
* @return The return codes of the sub calls.
|
||||
*/
|
||||
ReturnValue_t allFramesReception();
|
||||
/**
|
||||
* Dummy method for master channel demultiplexing.
|
||||
* As there's only one Master Channel here, the method calls #virtualChannelDemultiplexing.
|
||||
* @return The return codes of #virtualChannelDemultiplexing.
|
||||
*/
|
||||
ReturnValue_t masterChannelDemultiplexing();
|
||||
/**
|
||||
* Method to demultiplex the Frames to Virtual Channels (VC's).
|
||||
* Looks up the requested VC in #virtualChannels and forwards the Frame to its
|
||||
* #frameAcceptanceAndReportingMechanism method, if found.
|
||||
* @return The higher method codes or @c VC_NOT_FOUND.
|
||||
*/
|
||||
ReturnValue_t virtualChannelDemultiplexing();
|
||||
};
|
||||
|
||||
#endif /* DATALINKLAYER_H_ */
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateIF.h
|
||||
* @brief This file defines the Farm1StateIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEIF_H_
|
||||
#define FARM1STATEIF_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
class VirtualChannelReception;
|
||||
class TcTransferFrame;
|
||||
class ClcwIF;
|
||||
|
||||
/**
|
||||
* This is the interface for states of the FARM-1 state machine.
|
||||
* Classes implementing this interface can be used as FARM-1 states. This is a simple implementation
|
||||
* of the state pattern.
|
||||
*/
|
||||
class Farm1StateIF : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
/**
|
||||
* A method that shall handle an incoming frame as AD Frame.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Unlock frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Set VR frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) = 0;
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~Farm1StateIF() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FARM1STATEIF_H_ */
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateLockout.cpp
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateLockout.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
Farm1StateLockout::Farm1StateLockout(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
return FARM_IN_LOCKOUT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setLockoutFlag( false );
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCSetVrCommand(ClcwIF* clcw,
|
||||
uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateLockout.h
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATELOCKOUT_H_
|
||||
#define FARM1STATELOCKOUT_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Lockout" State.
|
||||
* The Lockout state is reached if the received Transfer Frame Sequence Number is completely wrong
|
||||
* (i.e. within the Lockout Window). No AD Frames are forwarded. To leave the State, a BC Unlock
|
||||
* command is required.
|
||||
*/
|
||||
class Farm1StateLockout : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateLockout( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* All AD Frames are rejected with FARM_IN_LOCKOUT
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return FARM_IN_LOCKOUT
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* The V(r) value is not set in Lockout State, even though the Command itself is accepted.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATELOCKOUT_H_ */
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateOpen.cpp
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateOpen.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
|
||||
Farm1StateOpen::Farm1StateOpen(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if (diff == 0 ) {
|
||||
myVC->vR++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return RETURN_OK;
|
||||
} else if (diff < myVC->positiveWindow && diff > 0 ) {
|
||||
clcw->setRetransmitFlag(true);
|
||||
return NS_POSITIVE_W;
|
||||
} else if (diff < 0 && diff >= -myVC->negativeWindow) {
|
||||
return NS_NEGATIVE_W;
|
||||
} else {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
return NS_LOCKOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCUnlockCommand( ClcwIF* clcw ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateOpen.h
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEOPEN_H_
|
||||
#define FARM1STATEOPEN_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Open" State.
|
||||
* The Open state is the state of normal operation. It handles all types of frames,
|
||||
* including AD Frames. If a wrong Frame Sequence Number is detected in an AD Frame, the
|
||||
* State reacts as specified.
|
||||
*/
|
||||
class Farm1StateOpen : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateOpen( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* Method to check the validity of AD Frames.
|
||||
* It checks the Frame Sequence Number and reacts as specified in the standard. The state may
|
||||
* change to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If the Sequence Number is ok, it returns #RETURN_OK. Otherwise either #NS_POSITIVE_W,
|
||||
* #NS_NEGATIVE_W or NS_LOCKOUT is returned.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEOPEN_H_ */
|
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateWait.cpp
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateWait.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
|
||||
Farm1StateWait::Farm1StateWait(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if ( diff < -myVC->negativeWindow || diff >= myVC->positiveWindow ) {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
}
|
||||
return FARM_IN_WAIT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCSetVrCommand(ClcwIF* clcw, uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setWaitFlag( false );
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
* @file Farm1StateWait.h
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEWAIT_H_
|
||||
#define FARM1STATEWAIT_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Wait" State.
|
||||
* The Wait state is reached if higher level procedures inform the FARM-1 Machine to wait
|
||||
* for a certain period. Currently, it is not in use.
|
||||
*/
|
||||
class Farm1StateWait : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateWait( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* AD Frames are always discarded.
|
||||
* If the frame number is in the lockout window, the state changes to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return Always returns FARM_IN_WAIT.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEWAIT_H_ */
|
@ -1,159 +0,0 @@
|
||||
#include "MapPacketExtraction.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../tmtcservices/AcceptsTelecommandsIF.h"
|
||||
#include "../tmtcservices/TmTcMessage.h"
|
||||
#include <cstring>
|
||||
|
||||
MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId),
|
||||
bufferPosition(packetBuffer), packetDestination(setPacketDestination),
|
||||
tcQueueId(MessageQueueIF::NO_QUEUE) {
|
||||
std::memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::extractPackets(TcTransferFrame* frame) {
|
||||
uint8_t segmentationFlag = frame->getSequenceFlags();
|
||||
ReturnValue_t status = TOO_SHORT_MAP_EXTRACTION;
|
||||
switch (segmentationFlag) {
|
||||
case NO_SEGMENTATION:
|
||||
status = unpackBlockingPackets(frame);
|
||||
break;
|
||||
case FIRST_PORTION:
|
||||
packetLength = frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(packetBuffer, frame->getDataField(), packetLength);
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
#endif
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
break;
|
||||
case CONTINUING_PORTION:
|
||||
case LAST_PORTION:
|
||||
if (lastSegmentationFlag == FIRST_PORTION
|
||||
|| lastSegmentationFlag == CONTINUING_PORTION) {
|
||||
packetLength += frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(bufferPosition, frame->getDataField(),
|
||||
frame->getDataLength());
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
if (segmentationFlag == LAST_PORTION) {
|
||||
status = sendCompletePacket(packetBuffer, packetLength);
|
||||
clearBuffers();
|
||||
}
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
#endif
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segment! Last flag: "
|
||||
<< (int) lastSegmentationFlag << std::endl;
|
||||
#endif
|
||||
clearBuffers();
|
||||
status = ILLEGAL_SEGMENTATION_FLAG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segmentationFlag: "
|
||||
<< (int) segmentationFlag << std::endl;
|
||||
#endif
|
||||
clearBuffers();
|
||||
status = DATA_CORRUPTED;
|
||||
break;
|
||||
}
|
||||
lastSegmentationFlag = segmentationFlag;
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::unpackBlockingPackets(
|
||||
TcTransferFrame* frame) {
|
||||
ReturnValue_t status = TOO_SHORT_BLOCKED_PACKET;
|
||||
uint32_t totalLength = frame->getDataLength();
|
||||
if (totalLength > MAX_PACKET_SIZE)
|
||||
return CONTENT_TOO_LARGE;
|
||||
uint8_t* position = frame->getDataField();
|
||||
while ((totalLength > SpacePacketBase::MINIMUM_SIZE)) {
|
||||
SpacePacketBase packet(position);
|
||||
uint32_t packetSize = packet.getFullSize();
|
||||
if (packetSize <= totalLength) {
|
||||
status = sendCompletePacket(packet.getWholeData(),
|
||||
packet.getFullSize());
|
||||
totalLength -= packet.getFullSize();
|
||||
position += packet.getFullSize();
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
status = DATA_CORRUPTED;
|
||||
totalLength = 0;
|
||||
}
|
||||
}
|
||||
if (totalLength > 0) {
|
||||
status = RESIDUAL_DATA;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::sendCompletePacket(uint8_t* data,
|
||||
uint32_t size) {
|
||||
store_address_t store_id;
|
||||
ReturnValue_t status = this->packetStore->addData(&store_id, data, size);
|
||||
if (status == RETURN_OK) {
|
||||
TmTcMessage message(store_id);
|
||||
status = MessageQueueSenderIF::sendMessage(tcQueueId,&message);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void MapPacketExtraction::clearBuffers() {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
bufferPosition = packetBuffer;
|
||||
packetLength = 0;
|
||||
lastSegmentationFlag = NO_SEGMENTATION;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::initialize() {
|
||||
packetStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
AcceptsTelecommandsIF* distributor = objectManager->get<
|
||||
AcceptsTelecommandsIF>(packetDestination);
|
||||
if ((packetStore != NULL) && (distributor != NULL)) {
|
||||
tcQueueId = distributor->getRequestQueue();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void MapPacketExtraction::printPacketBuffer(void) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "DLL: packet_buffer contains: " << std::endl;
|
||||
#endif
|
||||
for (uint32_t i = 0; i < this->packetLength; ++i) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "packet_buffer[" << std::dec << i << "]: 0x" << std::hex
|
||||
<< (uint16_t) this->packetBuffer[i] << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MapPacketExtraction::getMapId() const {
|
||||
return mapId;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
#ifndef FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_
|
||||
#define FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_
|
||||
|
||||
#include "MapPacketExtractionIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class StorageManagerIF;
|
||||
|
||||
/**
|
||||
* Implementation of a MAP Packet Extraction class.
|
||||
* The class implements the full MAP Packet Extraction functionality as described in the CCSDS
|
||||
* TC Space Data Link Protocol. It internally stores incomplete segmented packets until they are
|
||||
* fully received. All found packets are forwarded to a single distribution entity.
|
||||
* @author B. Baetz
|
||||
*/
|
||||
class MapPacketExtraction: public MapPacketExtractionIF {
|
||||
private:
|
||||
static const uint32_t MAX_PACKET_SIZE = 4096;
|
||||
uint8_t lastSegmentationFlag; //!< The segmentation flag of the last received frame.
|
||||
uint8_t mapId; //!< MAP ID of this MAP Channel.
|
||||
uint32_t packetLength = 0; //!< Complete length of the current Space Packet.
|
||||
uint8_t* bufferPosition; //!< Position to write to in the internal Packet buffer.
|
||||
uint8_t packetBuffer[MAX_PACKET_SIZE]; //!< The internal Space Packet Buffer.
|
||||
object_id_t packetDestination;
|
||||
//!< Pointer to the store where full TC packets are stored.
|
||||
StorageManagerIF* packetStore = nullptr;
|
||||
MessageQueueId_t tcQueueId; //!< QueueId to send found packets to the distributor.
|
||||
/**
|
||||
* Debug method to print the packet Buffer's content.
|
||||
*/
|
||||
void printPacketBuffer();
|
||||
/**
|
||||
* Method that is called if the segmentation flag is @c NO_SEGMENTATION.
|
||||
* The method extracts one or more packets within the frame and forwards them to the OBSW.
|
||||
* @param frame The TC Transfer Frame to work on.
|
||||
* @return @c RETURN_OK if all Packets were extracted. If something is entirely wrong,
|
||||
* @c DATA_CORRUPTED is returned, if some bytes are left over @c RESIDUAL_DATA.
|
||||
*/
|
||||
ReturnValue_t unpackBlockingPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* Helper method to forward a complete packet to the OBSW.
|
||||
* @param data Pointer to the data, either directly from the frame or from the packetBuffer.
|
||||
* @param size Complete total size of the packet.
|
||||
* @return Return Code of the Packet Store or the Message Queue.
|
||||
*/
|
||||
ReturnValue_t sendCompletePacket( uint8_t* data, uint32_t size );
|
||||
/**
|
||||
* Helper method to reset the internal buffer.
|
||||
*/
|
||||
void clearBuffers();
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Members are set to default values.
|
||||
* @param setMapId The MAP ID of the instance.
|
||||
*/
|
||||
MapPacketExtraction( uint8_t setMapId, object_id_t setPacketDestination );
|
||||
ReturnValue_t extractPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* The #packetStore and the default destination of #tcQueue are initialized here.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The MAP ID of this instance.
|
||||
*/
|
||||
uint8_t getMapId() const;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_ */
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* @file MapPacketExtractionIF.h
|
||||
* @brief This file defines the MapPacketExtractionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef MAPPACKETEXTRACTIONIF_H_
|
||||
#define MAPPACKETEXTRACTIONIF_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is the interface for MAP Packet Extraction classes.
|
||||
* All classes implementing this interface shall be able to extract blocked or segmented Space
|
||||
* Packets on a certain MAP channel. This is done in accordance with the CCSDS TC Space Data Link
|
||||
* Protocol.
|
||||
*/
|
||||
class MapPacketExtractionIF : public CCSDSReturnValuesIF {
|
||||
protected:
|
||||
static const uint8_t FIRST_PORTION = 0b01; //!< Identification of the first part of a segmented Packet.
|
||||
static const uint8_t CONTINUING_PORTION = 0b00; //!< Identification of a continuing part of segmented Packets.
|
||||
static const uint8_t LAST_PORTION = 0b10; //!< The last portion of a segmented Packet.
|
||||
static const uint8_t NO_SEGMENTATION = 0b11; //!< A Frame without segmentation but maybe with blocking.
|
||||
public:
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~MapPacketExtractionIF() {
|
||||
}
|
||||
/**
|
||||
* Method to call to handle a single Transfer Frame.
|
||||
* The method tries to extract Packets from the frame as stated in the Standard.
|
||||
* @param frame
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t extractPackets( TcTransferFrame* frame ) = 0;
|
||||
/**
|
||||
* Any post-instantiation initialization shall be done in this method.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MAPPACKETEXTRACTIONIF_H_ */
|
@ -1,111 +0,0 @@
|
||||
/**
|
||||
* @file TcTransferFrame.cpp
|
||||
* @brief This file defines the TcTransferFrame class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "TcTransferFrame.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
TcTransferFrame::TcTransferFrame() {
|
||||
frame = NULL;
|
||||
}
|
||||
|
||||
TcTransferFrame::TcTransferFrame(uint8_t* setData) {
|
||||
this->frame = (tc_transfer_frame*)setData;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVersionNumber() {
|
||||
return (this->frame->header.flagsAndScid & 0b11000000) >> 6;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::bypassFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00100000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::controlCommandFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00010000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::spareIsZero() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00001100) == 0 );
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getSpacecraftId() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00000011) << 8 ) + this->frame->header.spacecraftId_l;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVirtualChannelId() {
|
||||
return (this->frame->header.vcidAndLength_h & 0b11111100) >> 2;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFrameLength() {
|
||||
return ( (this->frame->header.vcidAndLength_h & 0b00000011) << 8 ) + this->frame->header.length_l;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() -1 - FRAME_CRC_SIZE + 1; // -1 for the segment header.
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceNumber() {
|
||||
return this->frame->header.sequenceNumber;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceFlags() {
|
||||
return (this->frame->dataField & 0b11000000)>>6;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getMAPId() {
|
||||
return this->frame->dataField & 0b00111111;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getDataField() {
|
||||
return &(this->frame->dataField) + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullFrame() {
|
||||
return (uint8_t*)this->frame;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullSize() {
|
||||
return this->getFrameLength() + 1;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getHeaderSize() {
|
||||
return sizeof(frame->header);
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() - FRAME_CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullDataField() {
|
||||
return &frame->dataField;
|
||||
}
|
||||
|
||||
void TcTransferFrame::print() {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "Raw Frame: " << std::hex << std::endl;
|
||||
for (uint16_t count = 0; count < this->getFullSize(); count++ ) {
|
||||
sif::debug << (uint16_t)this->getFullFrame()[count] << " ";
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
|
||||
sif::debug << "Frame Header:" << std::endl;
|
||||
sif::debug << "Version Number: " << std::hex
|
||||
<< (uint16_t)this->getVersionNumber() << std::endl;
|
||||
sif::debug << "Bypass Flag set?| Ctrl Cmd Flag set?: "
|
||||
<< (uint16_t)this->bypassFlagSet() << " | "
|
||||
<< (uint16_t)this->controlCommandFlagSet() << std::endl;
|
||||
sif::debug << "SCID : " << this->getSpacecraftId() << std::endl;
|
||||
sif::debug << "VCID : " << (uint16_t)this->getVirtualChannelId()
|
||||
<< std::endl;
|
||||
sif::debug << "Frame length: " << std::dec << this->getFrameLength()
|
||||
<< std::endl;
|
||||
sif::debug << "Sequence Number: " << (uint16_t)this->getSequenceNumber()
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
#ifndef TCTRANSFERFRAME_H_
|
||||
#define TCTRANSFERFRAME_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* The TcTransferFrame class simplifies handling of such Frames.
|
||||
* It operates on any buffer passed on construction. The data length
|
||||
* is determined by the length field in the frame itself.
|
||||
* It has a lot of getters for convenient access to the content.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class TcTransferFrame {
|
||||
protected:
|
||||
/**
|
||||
* The struct that defines the Frame's Primary Header.
|
||||
*/
|
||||
struct TcTransferFramePrimaryHeader {
|
||||
uint8_t flagsAndScid; //!< Highest byte with Flags and part of SCID.
|
||||
uint8_t spacecraftId_l; //!< Byte with rest of SCID
|
||||
uint8_t vcidAndLength_h; //!< Byte with VCID and part of length.
|
||||
uint8_t length_l; //!< Byte with rest of length.
|
||||
uint8_t sequenceNumber; //!< Lowest byte with Frame Sequence Number N(S).
|
||||
};
|
||||
/**
|
||||
* The struct defining the whole Transfer Frame.
|
||||
*/
|
||||
struct tc_transfer_frame {
|
||||
TcTransferFramePrimaryHeader header; //!< The header struct.
|
||||
uint8_t dataField; //!< The data field of the Transfer Frame.
|
||||
};
|
||||
tc_transfer_frame* frame; //!< Pointer to a buffer where a Frame is placed.
|
||||
public:
|
||||
static const uint8_t FRAME_CRC_SIZE = 2; //!< Constant for the CRC size.
|
||||
/**
|
||||
* Empty Constructor that sets the data pointer to NULL.
|
||||
*/
|
||||
TcTransferFrame();
|
||||
/**
|
||||
* The data pointer passed in this Constructor is casted to the #tc_transfer_frame struct.
|
||||
* @param setData The data on which the class shall operate.
|
||||
*/
|
||||
TcTransferFrame(uint8_t* setData);
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Version number.
|
||||
*/
|
||||
uint8_t getVersionNumber();
|
||||
/**
|
||||
* Getter.
|
||||
* @return If the bypass flag is set or not.
|
||||
*/
|
||||
bool bypassFlagSet();
|
||||
/**
|
||||
* Getter.
|
||||
* @return If the control command flag is set or not.
|
||||
*/
|
||||
bool controlCommandFlagSet();
|
||||
/**
|
||||
* Getter.
|
||||
* @return If the spare bits in the Header are zero or not.
|
||||
*/
|
||||
bool spareIsZero();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Spacecraft Identifier.
|
||||
*/
|
||||
uint16_t getSpacecraftId();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Virtual Channel Identifier.
|
||||
*/
|
||||
uint8_t getVirtualChannelId();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Frame length as stored in the Header.
|
||||
*/
|
||||
uint16_t getFrameLength();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The length of pure data (without CRC), assuming that a Segment Header is present.
|
||||
*/
|
||||
uint16_t getDataLength();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The length of pure data (without CRC), assuming that no Segment Header is present (for BC Frames).
|
||||
*/
|
||||
uint16_t getFullDataLength();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The sequence number from the header.
|
||||
*/
|
||||
uint8_t getSequenceNumber();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Sequence Flags in the Segment Header byte (right aligned).
|
||||
*/
|
||||
uint8_t getSequenceFlags();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The Multiplexer Access Point Identifier from the Segment Header byte.
|
||||
*/
|
||||
uint8_t getMAPId();
|
||||
/**
|
||||
* Getter.
|
||||
* @return A pointer to the date field AFTER a Segment Header.
|
||||
*/
|
||||
uint8_t* getDataField();
|
||||
/**
|
||||
* Getter.
|
||||
* @return A pointer to the first byte in the Data Field (ignoring potential Segment Headers, for BC Frames).
|
||||
*/
|
||||
uint8_t* getFullDataField();
|
||||
/**
|
||||
* Getter.
|
||||
* @return A pointer to the beginning of the Frame.
|
||||
*/
|
||||
uint8_t* getFullFrame();
|
||||
/**
|
||||
* Getter
|
||||
* @return The total size of the Frame, which is the size stated in the Header + 1.
|
||||
*/
|
||||
uint16_t getFullSize();
|
||||
/**
|
||||
* Getter.
|
||||
* @return Size of the #TcTransferFramePrimaryHeader.
|
||||
*/
|
||||
uint16_t getHeaderSize();
|
||||
/**
|
||||
* Debug method to print the whole Frame to screen.
|
||||
*/
|
||||
void print();
|
||||
|
||||
};
|
||||
|
||||
#endif /* TCTRANSFERFRAME_H_ */
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* @file TcTransferFrameLocal.cpp
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "TcTransferFrameLocal.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <string.h>
|
||||
|
||||
TcTransferFrameLocal::TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid,
|
||||
uint8_t vcId, uint8_t sequenceNumber, uint8_t setSegmentHeader, uint8_t* data, uint16_t dataSize, uint16_t forceCrc) {
|
||||
this->frame = (tc_transfer_frame*)&localData;
|
||||
frame->header.flagsAndScid = (bypass << 5) + (controlCommand << 4) + ((scid & 0x0300) >> 8);
|
||||
frame->header.spacecraftId_l = (scid & 0x00FF);
|
||||
frame->header.vcidAndLength_h = (vcId & 0b00111111) << 2;
|
||||
frame->header.length_l = sizeof(TcTransferFramePrimaryHeader) -1;
|
||||
frame->header.sequenceNumber = sequenceNumber;
|
||||
frame->dataField = setSegmentHeader;
|
||||
if (data != NULL) {
|
||||
if (bypass && controlCommand) {
|
||||
memcpy(&(frame->dataField), data, dataSize);
|
||||
uint16_t totalSize = sizeof(TcTransferFramePrimaryHeader) + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (totalSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (totalSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else if (dataSize <= 1016) {
|
||||
memcpy(&(frame->dataField) +1, data, dataSize);
|
||||
uint16_t dataCrcSize = sizeof(TcTransferFramePrimaryHeader) + 1 + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (dataCrcSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (dataCrcSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "TcTransferFrameLocal: dataSize too large: " << dataSize << std::endl;
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
//No data in frame
|
||||
}
|
||||
if (forceCrc != 0 ) {
|
||||
localData.data[getFullSize()-2] = (forceCrc & 0xFF00) >> 8;
|
||||
localData.data[getFullSize()-1] = (forceCrc & 0x00FF);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* @file TcTransferFrameLocal.h
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef TCTRANSFERFRAMELOCAL_H_
|
||||
#define TCTRANSFERFRAMELOCAL_H_
|
||||
|
||||
#include "TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is a helper class to locally create TC Transfer Frames.
|
||||
* This is mainly required for testing purposes and therefore not very sophisticated.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class TcTransferFrameLocal : public TcTransferFrame {
|
||||
private:
|
||||
/**
|
||||
* A stuct to locally store the complete data.
|
||||
*/
|
||||
struct frameData {
|
||||
TcTransferFramePrimaryHeader header; //!< The primary header.
|
||||
uint8_t data[1019]; //!< The data field.
|
||||
};
|
||||
public:
|
||||
frameData localData; //!< The local data in the Frame.
|
||||
/**
|
||||
* The default Constructor.
|
||||
* All parameters in the Header are passed.
|
||||
* If a BC Frame is detected no segment header is created.
|
||||
* Otherwise (AD and BD), the Segment Header is set.
|
||||
* @param bypass The bypass flag.
|
||||
* @param controlCommand The Control Command flag.
|
||||
* @param scid The SCID.
|
||||
* @param vcId The VCID.
|
||||
* @param sequenceNumber The Frame Sequence Number N(s)
|
||||
* @param setSegmentHeader A value for the Segment Header.
|
||||
* @param data Data to put into the Frame Data Field.
|
||||
* @param dataSize Size of the Data.
|
||||
* @param forceCrc if != 0, the value is used as CRC.
|
||||
*/
|
||||
TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid, uint8_t vcId, uint8_t sequenceNumber,
|
||||
uint8_t setSegmentHeader = 0xC0, uint8_t* data = NULL, uint16_t dataSize = 0, uint16_t forceCrc = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCTRANSFERFRAMELOCAL_H_ */
|
@ -1,123 +0,0 @@
|
||||
/**
|
||||
* @file VirtualChannelReception.cpp
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "BCFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
VirtualChannelReception::VirtualChannelReception(uint8_t setChannelId,
|
||||
uint8_t setSlidingWindowWidth) :
|
||||
channelId(setChannelId), slidingWindowWidth(setSlidingWindowWidth), positiveWindow(
|
||||
setSlidingWindowWidth / 2), negativeWindow(setSlidingWindowWidth / 2), currentState(
|
||||
&openState), openState(this), waitState(this), lockoutState(this), vR(0), farmBCounter(
|
||||
0) {
|
||||
internalClcw.setVirtualChannel(channelId);
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::mapDemultiplexing(TcTransferFrame* frame) {
|
||||
uint8_t mapId = frame->getMAPId();
|
||||
mapChannelIterator iter = mapChannels.find(mapId);
|
||||
if (iter == mapChannels.end()) {
|
||||
// error << "VirtualChannelReception::mapDemultiplexing on VC " << std::hex << (int) channelId
|
||||
// << ": MapChannel " << (int) mapId << std::dec << " not found." << std::endl;
|
||||
return VC_NOT_FOUND;
|
||||
} else {
|
||||
return (iter->second)->extractPackets(frame);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::doFARM(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
uint8_t bypass = frame->bypassFlagSet();
|
||||
uint8_t controlCommand = frame->controlCommandFlagSet();
|
||||
uint8_t typeValue = (bypass << 1) + controlCommand;
|
||||
switch (typeValue) {
|
||||
case AD_FRAME:
|
||||
return currentState->handleADFrame(frame, clcw);
|
||||
case BD_FRAME:
|
||||
return handleBDFrame(frame, clcw);
|
||||
case BC_FRAME:
|
||||
return handleBCFrame(frame, clcw);
|
||||
default:
|
||||
return ILLEGAL_FLAG_COMBINATION;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::frameAcceptanceAndReportingMechanism(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = doFARM(frame, &internalClcw);
|
||||
internalClcw.setReceiverFrameSequenceNumber(vR);
|
||||
internalClcw.setFarmBCount(farmBCounter);
|
||||
clcw->setWhole(internalClcw.getAsWhole());
|
||||
switch (result) {
|
||||
case RETURN_OK:
|
||||
return mapDemultiplexing(frame);
|
||||
case BC_IS_SET_VR_COMMAND:
|
||||
case BC_IS_UNLOCK_COMMAND:
|
||||
//Need to catch these codes to avoid error reporting later.
|
||||
return RETURN_OK;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::addMapChannel(uint8_t mapId, MapPacketExtractionIF* object) {
|
||||
std::pair<mapChannelIterator, bool> returnValue = mapChannels.insert(
|
||||
std::pair<uint8_t, MapPacketExtractionIF*>(mapId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBDFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
farmBCounter++;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBCFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
BcFrame content;
|
||||
ReturnValue_t returnValue = content.initialize(frame->getFullDataField(),
|
||||
frame->getFullDataLength());
|
||||
if (returnValue == BC_IS_UNLOCK_COMMAND) {
|
||||
returnValue = currentState->handleBCUnlockCommand(clcw);
|
||||
} else if (returnValue == BC_IS_SET_VR_COMMAND) {
|
||||
returnValue = currentState->handleBCSetVrCommand(clcw, content.vR);
|
||||
} else {
|
||||
//Do nothing
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
uint8_t VirtualChannelReception::getChannelId() const {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
if ((slidingWindowWidth > 254) || (slidingWindowWidth % 2 != 0)) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "VirtualChannelReception::initialize: Illegal sliding window width: "
|
||||
<< (int) slidingWindowWidth << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
for (mapChannelIterator iterator = mapChannels.begin(); iterator != mapChannels.end();
|
||||
iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void VirtualChannelReception::setToWaitState() {
|
||||
internalClcw.setWaitFlag(true);
|
||||
this->currentState = &waitState;
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/**
|
||||
* @file VirtualChannelReception.h
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTION_H_
|
||||
#define VIRTUALCHANNELRECEPTION_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "Clcw.h"
|
||||
#include "Farm1StateIF.h"
|
||||
#include "Farm1StateLockout.h"
|
||||
#include "Farm1StateOpen.h"
|
||||
#include "Farm1StateWait.h"
|
||||
#include "MapPacketExtractionIF.h"
|
||||
#include "VirtualChannelReceptionIF.h"
|
||||
#include <map>
|
||||
/**
|
||||
* Implementation of a TC Virtual Channel.
|
||||
* This is a full implementation of a virtual channel as specified in the CCSDS TC Space Data Link
|
||||
* Protocol. It is designed to operate within an instance of the @c DataLinkLayer class.
|
||||
* Features:
|
||||
* - any (6bit) Virtual Channel ID is assignable.
|
||||
* - Supports an arbitrary number of MAP Channels (with a map).
|
||||
* - Has a complete FARM-1 Machine built-in.
|
||||
*
|
||||
* The FARM-1 state machine uses the State Pattern.
|
||||
*/
|
||||
class VirtualChannelReception : public VirtualChannelReceptionIF, public CCSDSReturnValuesIF {
|
||||
friend class Farm1StateOpen;
|
||||
friend class Farm1StateWait;
|
||||
friend class Farm1StateLockout;
|
||||
private:
|
||||
uint8_t channelId; //!< Stores the VCID that was assigned on construction.
|
||||
uint8_t slidingWindowWidth; //!< A constant to set the FARM-1 sliding window width.
|
||||
uint8_t positiveWindow; //!< The positive window for the FARM-1 machine.
|
||||
uint8_t negativeWindow; //!< The negative window for the FARM-1 machine.
|
||||
protected:
|
||||
Farm1StateIF* currentState; //!< The current state. To change, one of the other states must be assigned to this pointer.
|
||||
Farm1StateOpen openState; //!< Instance of the FARM-1 State "Open".
|
||||
Farm1StateWait waitState; //!< Instance of the FARM-1 State "Wait".
|
||||
Farm1StateLockout lockoutState; //!< Instance of the FARM-1 State "Lockout".
|
||||
Clcw internalClcw; //!< A CLCW class to internally set the values before writing them back to the TTC System.
|
||||
uint8_t vR; //!< The Receiver Frame Sequence Number V(R) as it shall be maintained for every Virtual Channel.
|
||||
uint8_t farmBCounter; //!< The FARM-B COunter as it shall be maintained for every Virtual Channel.
|
||||
typedef std::map<uint8_t, MapPacketExtractionIF*>::iterator mapChannelIterator; //!< Typedef to simplify handling of the mapChannels map.
|
||||
std::map<uint8_t, MapPacketExtractionIF*> mapChannels; //!< A map that maintains all map Channels. Channels must be configured on initialization. MAy be omitted in a simplified version.
|
||||
/**
|
||||
* This method handles demultiplexing to different map channels.
|
||||
* It parses the entries of #mapChannels and forwards the Frame to a found MAP Channel.
|
||||
* @param frame The frame to forward.
|
||||
* @return #VC_NOT_FOUND or the return value of the map channel extraction.
|
||||
*/
|
||||
ReturnValue_t mapDemultiplexing( TcTransferFrame* frame );
|
||||
/**
|
||||
* A sub-method that actually does the FARM-1 handling for different Frame types.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The return code of higher methods or @c ILLEGAL_FLAG_COMBINATION.
|
||||
*/
|
||||
ReturnValue_t doFARM(TcTransferFrame* frame, ClcwIF* clcw);
|
||||
/**
|
||||
* Handles incoming BD Frames.
|
||||
* Handling these Frames is independent of the State, so no subcall to #currentState is
|
||||
* required.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return Always returns @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t handleBDFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Handles incoming BC Frames.
|
||||
* The type of the BC Frame is detected and checked first, then methods of #currentState are called.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The failure code of BC Frame interpretation or the return code of higher methods.
|
||||
*/
|
||||
ReturnValue_t handleBCFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Only sets the channelId of the channel. Setting the Sliding Window width is possible as well.
|
||||
* @param setChannelId Virtual Channel Identifier (VCID) of the channel.
|
||||
*/
|
||||
VirtualChannelReception( uint8_t setChannelId, uint8_t setSlidingWindowWidth );
|
||||
ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Helper method to simplify adding a mapChannel during construction.
|
||||
* @param mapId The mapId of the object to add.
|
||||
* @param object Pointer to the MapPacketExtraction object itself.
|
||||
* @return @c RETURN_OK if the channel was successfully inserted, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addMapChannel( uint8_t mapId, MapPacketExtractionIF* object );
|
||||
/**
|
||||
* The initialization routine checks the set #slidingWindowWidth and initializes all MAP
|
||||
* channels.
|
||||
* @return @c RETURN_OK on successful initialization, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
uint8_t getChannelId() const;
|
||||
/**
|
||||
* Small method to set the state to Farm1StateWait.
|
||||
*/
|
||||
void setToWaitState();
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTION_H_ */
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* @file VirtualChannelReceptionIF.h
|
||||
* @brief This file defines the VirtualChannelReceptionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTIONIF_H_
|
||||
#define VIRTUALCHANNELRECEPTIONIF_H_
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* This is the interface for Virtual Channel reception classes.
|
||||
* It represents a single TC Virtual Channel that operates on one IO
|
||||
*/
|
||||
class VirtualChannelReceptionIF {
|
||||
public:
|
||||
/**
|
||||
* Enum including all valid types of frames.
|
||||
* The type is made up by two flags, so 0b1111 is definitely illegal.
|
||||
*/
|
||||
enum frameType {
|
||||
AD_FRAME = 0b00,
|
||||
BC_FRAME = 0b11,
|
||||
BD_FRAME = 0b10,
|
||||
ILLEGAL_FRAME = 0b1111
|
||||
};
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~VirtualChannelReceptionIF() {
|
||||
}
|
||||
/**
|
||||
* This method shall accept frames and do all FARM-1 stuff.
|
||||
* Handling the Frame includes forwarding to higher-level procedures.
|
||||
* @param frame The Tc Transfer Frame that was received and checked.
|
||||
* @param clcw Any changes to the CLCW value are forwarded by using this parameter.
|
||||
* @return The return Value shall indicate successful processing with @c RETURN_OK.
|
||||
*/
|
||||
virtual ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* If any other System Objects are required for operation they shall be initialized here.
|
||||
* @return @c RETURN_OK for successful initialization.
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
virtual uint8_t getChannelId() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTIONIF_H_ */
|
@ -1,45 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_DATASETIF_H_
|
||||
#define FSFW_DATAPOOL_DATASETIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
class PoolVariableIF;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @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(1);
|
||||
static constexpr ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t COMMITING_WITHOUT_READING = MAKE_RETURN_CODE(3);
|
||||
|
||||
static constexpr ReturnValue_t DATA_SET_UNINITIALISED = MAKE_RETURN_CODE(4);
|
||||
static constexpr ReturnValue_t DATA_SET_FULL = MAKE_RETURN_CODE(5);
|
||||
static constexpr ReturnValue_t POOL_VAR_NULL = MAKE_RETURN_CODE(6);
|
||||
|
||||
/**
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is proposed for C++ interfaces.
|
||||
*/
|
||||
virtual ~DataSetIF() {}
|
||||
|
||||
/**
|
||||
* @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 ReturnValue_t registerVariable(PoolVariableIF* variable) = 0;
|
||||
|
||||
virtual uint16_t getFillCount() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_DATASETIF_H_ */
|
@ -1,75 +0,0 @@
|
||||
#include "../datapool/HkSwitchHelper.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
||||
commandActionHelper(this), eventProxy(eventProxy) {
|
||||
actionQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
HkSwitchHelper::~HkSwitchHelper() {
|
||||
QueueFactory::instance()->deleteMessageQueue(actionQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t HkSwitchHelper::initialize() {
|
||||
ReturnValue_t result = commandActionHelper.initialize();
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
|
||||
CommandMessage command;
|
||||
while (actionQueue->receiveMessage(&command) == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = commandActionHelper.handleReply(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
command.setToUnknownCommand();
|
||||
actionQueue->reply(&command);
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void HkSwitchHelper::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) {
|
||||
}
|
||||
|
||||
void HkSwitchHelper::stepFailedReceived(ActionId_t actionId, uint8_t step,
|
||||
ReturnValue_t returnCode) {
|
||||
eventProxy->forwardEvent(SWITCHING_TM_FAILED, returnCode, actionId);
|
||||
}
|
||||
|
||||
void HkSwitchHelper::dataReceived(ActionId_t actionId, const uint8_t* data,
|
||||
uint32_t size) {
|
||||
}
|
||||
|
||||
void HkSwitchHelper::completionSuccessfulReceived(ActionId_t actionId) {
|
||||
}
|
||||
|
||||
void HkSwitchHelper::completionFailedReceived(ActionId_t actionId,
|
||||
ReturnValue_t returnCode) {
|
||||
eventProxy->forwardEvent(SWITCHING_TM_FAILED, returnCode, actionId);
|
||||
}
|
||||
|
||||
ReturnValue_t HkSwitchHelper::switchHK(SerializeIF* sids, bool enable) {
|
||||
// ActionId_t action = HKService::DISABLE_HK;
|
||||
// if (enable) {
|
||||
// action = HKService::ENABLE_HK;
|
||||
// }
|
||||
//
|
||||
// ReturnValue_t result = commandActionHelper.commandAction(
|
||||
// objects::PUS_HK_SERVICE, action, sids);
|
||||
//
|
||||
// if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// eventProxy->forwardEvent(SWITCHING_TM_FAILED, result);
|
||||
// }
|
||||
// return result;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueIF* HkSwitchHelper::getCommandQueuePtr() {
|
||||
return actionQueue;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_HKSWITCHHELPER_H_
|
||||
#define FRAMEWORK_DATAPOOL_HKSWITCHHELPER_H_
|
||||
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
#include "../action/CommandsActionsIF.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
|
||||
//TODO this class violations separation between mission and framework
|
||||
//but it is only a transitional solution until the Datapool is
|
||||
//implemented decentrally
|
||||
|
||||
class HkSwitchHelper: public ExecutableObjectIF, public CommandsActionsIF {
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HK;
|
||||
static const Event SWITCHING_TM_FAILED = MAKE_EVENT(1, severity::LOW); //!< Commanding the HK Service failed, p1: error code, p2 action: 0 disable / 1 enable
|
||||
|
||||
HkSwitchHelper(EventReportingProxyIF *eventProxy);
|
||||
virtual ~HkSwitchHelper();
|
||||
|
||||
ReturnValue_t initialize();
|
||||
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0);
|
||||
|
||||
ReturnValue_t switchHK(SerializeIF *sids, bool enable);
|
||||
|
||||
virtual void setTaskIF(PeriodicTaskIF* task_){};
|
||||
|
||||
protected:
|
||||
virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step);
|
||||
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step,
|
||||
ReturnValue_t returnCode);
|
||||
virtual void dataReceived(ActionId_t actionId, const uint8_t* data,
|
||||
uint32_t size);
|
||||
virtual void completionSuccessfulReceived(ActionId_t actionId);
|
||||
virtual void completionFailedReceived(ActionId_t actionId,
|
||||
ReturnValue_t returnCode);
|
||||
virtual MessageQueueIF* getCommandQueuePtr();
|
||||
|
||||
private:
|
||||
CommandActionHelper commandActionHelper;
|
||||
MessageQueueIF* actionQueue;
|
||||
EventReportingProxyIF *eventProxy;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_HKSWITCHHELPER_H_ */
|
@ -1,233 +0,0 @@
|
||||
#include "PoolDataSetBase.h"
|
||||
#include "ReadCommitIFAttorney.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount):
|
||||
registeredVariables(registeredVariablesArray),
|
||||
maxFillCount(maxFillCount) {}
|
||||
|
||||
PoolDataSetBase::~PoolDataSetBase() {}
|
||||
|
||||
|
||||
ReturnValue_t PoolDataSetBase::registerVariable(PoolVariableIF *variable) {
|
||||
if(registeredVariables == nullptr) {
|
||||
/* Underlying container invalid */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (state != States::STATE_SET_UNINITIALISED) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataSet::registerVariable: Call made in wrong position." << std::endl;
|
||||
#else
|
||||
sif::printError("DataSet::registerVariable: Call made in wrong position.");
|
||||
#endif
|
||||
return DataSetIF::DATA_SET_UNINITIALISED;
|
||||
}
|
||||
if (variable == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataSet::registerVariable: Pool variable is nullptr." << std::endl;
|
||||
#else
|
||||
sif::printError("DataSet::registerVariable: Pool variable is nullptr.\n");
|
||||
#endif
|
||||
return DataSetIF::POOL_VAR_NULL;
|
||||
}
|
||||
if (fillCount >= maxFillCount) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataSet::registerVariable: DataSet is full." << std::endl;
|
||||
#else
|
||||
sif::printError("DataSet::registerVariable: DataSet is full.\n");
|
||||
#endif
|
||||
return DataSetIF::DATA_SET_FULL;
|
||||
}
|
||||
registeredVariables[fillCount] = variable;
|
||||
fillCount++;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::read(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
ReturnValue_t error = result;
|
||||
if (state == States::STATE_SET_UNINITIALISED) {
|
||||
lockDataPool(timeoutType, lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = readVariable(count);
|
||||
if(result != RETURN_OK) {
|
||||
error = result;
|
||||
}
|
||||
}
|
||||
state = States::STATE_SET_WAS_READ;
|
||||
unlockDataPool();
|
||||
}
|
||||
else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "PoolDataSetBase::read: Call made in wrong position. Don't forget to "
|
||||
"commit member datasets!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("PoolDataSetBase::read: Call made in wrong position. Don't forget to "
|
||||
"commit member datasets!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
|
||||
if(error != HasReturnvaluesIF::RETURN_OK) {
|
||||
result = error;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t PoolDataSetBase::getFillCount() const {
|
||||
return fillCount;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if(registeredVariables[count] == nullptr) {
|
||||
/* Configuration error. */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
if(protectEveryReadCommitCall) {
|
||||
result = registeredVariables[count]->read(timeoutTypeForSingleVars,
|
||||
mutexTimeoutForSingleVars);
|
||||
}
|
||||
else {
|
||||
/* The readWithoutLock function is protected, so we use the attorney here */
|
||||
result = ReadCommitIFAttorney::readWithoutLock(registeredVariables[count]);
|
||||
}
|
||||
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
result = INVALID_PARAMETER_DEFINITION;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::commit(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t lockTimeout) {
|
||||
if (state == States::STATE_SET_WAS_READ) {
|
||||
handleAlreadyReadDatasetCommit(timeoutType, lockTimeout);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return handleUnreadDatasetCommit(timeoutType, lockTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void PoolDataSetBase::handleAlreadyReadDatasetCommit(
|
||||
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
||||
lockDataPool(timeoutType, lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if ((registeredVariables[count]->getReadWriteMode() != PoolVariableIF::VAR_READ) and
|
||||
(registeredVariables[count]->getDataPoolId() != PoolVariableIF::NO_PARAMETER)) {
|
||||
if(protectEveryReadCommitCall) {
|
||||
registeredVariables[count]->commit(timeoutTypeForSingleVars,
|
||||
mutexTimeoutForSingleVars);
|
||||
}
|
||||
else {
|
||||
/* The commitWithoutLock function is protected, so we use the attorney here */
|
||||
ReadCommitIFAttorney::commitWithoutLock(registeredVariables[count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
state = States::STATE_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(
|
||||
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
lockDataPool(timeoutType, lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if ((registeredVariables[count]->getReadWriteMode() == PoolVariableIF::VAR_WRITE) and
|
||||
(registeredVariables[count]->getDataPoolId() != PoolVariableIF::NO_PARAMETER)) {
|
||||
if(protectEveryReadCommitCall) {
|
||||
result = registeredVariables[count]->commit(timeoutTypeForSingleVars,
|
||||
mutexTimeoutForSingleVars);
|
||||
}
|
||||
else {
|
||||
/* The commitWithoutLock function is protected, so we use the attorney here */
|
||||
ReadCommitIFAttorney::commitWithoutLock(registeredVariables[count]);
|
||||
}
|
||||
|
||||
} else if (registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
if (result != COMMITING_WITHOUT_READING) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DataSet::commit(): commit-without-read call made "
|
||||
"with non write-only variable." << std::endl;
|
||||
#endif
|
||||
result = COMMITING_WITHOUT_READING;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = States::STATE_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PoolDataSetBase::lockDataPool(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t lockTimeout) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::unlockDataPool() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::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 PoolDataSetBase::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 PoolDataSetBase::getSerializedSize() const {
|
||||
uint32_t size = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
||||
this->registeredVariables = variablesContainer;
|
||||
}
|
||||
|
||||
PoolVariableIF** PoolDataSetBase::getContainer() const {
|
||||
return registeredVariables;
|
||||
}
|
||||
|
||||
void PoolDataSetBase::setReadCommitProtectionBehaviour(
|
||||
bool protectEveryReadCommit, MutexIF::TimeoutType timeoutType,
|
||||
uint32_t mutexTimeout) {
|
||||
this->protectEveryReadCommitCall = protectEveryReadCommit;
|
||||
this->timeoutTypeForSingleVars = timeoutType;
|
||||
this->mutexTimeoutForSingleVars = mutexTimeout;
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||
#define FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||
|
||||
#include "PoolDataSetIF.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "../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 PoolDataSetBase:
|
||||
public PoolDataSetIF,
|
||||
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.
|
||||
*/
|
||||
PoolDataSetBase(PoolVariableIF** registeredVariablesArray, const size_t maxFillCount);
|
||||
|
||||
/* Forbidden for now */
|
||||
PoolDataSetBase(const PoolDataSetBase& otherSet) = delete;
|
||||
const PoolDataSetBase& operator=(const PoolDataSetBase& otherSet) = delete;
|
||||
|
||||
virtual~ PoolDataSetBase();
|
||||
|
||||
/**
|
||||
* @brief The read call initializes reading out all registered variables.
|
||||
* It is mandatory to call commit after every read call!
|
||||
* @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. It is mandatory to call commit after a read call,
|
||||
* even if the read operation is not successful!
|
||||
* @return
|
||||
* - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c INVALID_PARAMETER_DEFINITION if a pool entry does not exist or there
|
||||
* is a type conflict.
|
||||
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||
* commit() in between
|
||||
*/
|
||||
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t lockTimeout = 20) 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. Every read call must be followed by a commit 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(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t lockTimeout = 20) 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(
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) 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;
|
||||
|
||||
/**
|
||||
* Can be used to individually protect every read and commit call.
|
||||
* @param protectEveryReadCommit
|
||||
* @param mutexTimeout
|
||||
*/
|
||||
void setReadCommitProtectionBehaviour(bool protectEveryReadCommit,
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t mutexTimeout = 20);
|
||||
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 {
|
||||
STATE_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||
STATE_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::STATE_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;
|
||||
|
||||
void setContainer(PoolVariableIF** variablesContainer);
|
||||
PoolVariableIF** getContainer() const;
|
||||
|
||||
private:
|
||||
bool protectEveryReadCommitCall = false;
|
||||
MutexIF::TimeoutType timeoutTypeForSingleVars = MutexIF::TimeoutType::WAITING;
|
||||
uint32_t mutexTimeoutForSingleVars = 20;
|
||||
|
||||
ReturnValue_t readVariable(uint16_t count);
|
||||
void handleAlreadyReadDatasetCommit(
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20);
|
||||
ReturnValue_t handleUnreadDatasetCommit(
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20);
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */
|
@ -1,36 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||
#define FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||
|
||||
#include "ReadCommitIF.h"
|
||||
#include "DataSetIF.h"
|
||||
|
||||
/**
|
||||
* @brief Extendes the DataSetIF by adding abstract functions to lock
|
||||
* and unlock a data pool and read/commit semantics.
|
||||
*/
|
||||
class PoolDataSetIF:
|
||||
virtual public DataSetIF,
|
||||
virtual public ReadCommitIF {
|
||||
public:
|
||||
virtual~ PoolDataSetIF() {};
|
||||
|
||||
/**
|
||||
* @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(
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) = 0;
|
||||
|
||||
/**
|
||||
* @brief Unlock call corresponding to the lock call.
|
||||
* @return Unlock operation result
|
||||
*/
|
||||
virtual ReturnValue_t unlockDataPool() = 0;
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLDATASETIF_H_ */
|
@ -1,101 +0,0 @@
|
||||
#include "PoolEntry.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../globalfunctions/arrayprinter.h"
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
template <typename T>
|
||||
PoolEntry<T>::PoolEntry(std::initializer_list<T> initValue, bool setValid ):
|
||||
length(static_cast<uint8_t>(initValue.size())), valid(setValid) {
|
||||
this->address = new T[this->length];
|
||||
if(initValue.size() == 0) {
|
||||
std::memset(this->address, 0, this->getByteSize());
|
||||
}
|
||||
else {
|
||||
std::copy(initValue.begin(), initValue.end(), this->address);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PoolEntry<T>::PoolEntry(T* initValue, uint8_t setLength, bool setValid):
|
||||
length(setLength), valid(setValid) {
|
||||
this->address = new T[this->length];
|
||||
if (initValue != nullptr) {
|
||||
std::memcpy(this->address, initValue, this->getByteSize() );
|
||||
} else {
|
||||
std::memset(this->address, 0, this->getByteSize() );
|
||||
}
|
||||
}
|
||||
|
||||
//As the data pool is global, this dtor is only be called on program exit.
|
||||
//Warning! Never copy pool entries!
|
||||
template <typename T>
|
||||
PoolEntry<T>::~PoolEntry() {
|
||||
delete[] this->address;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint16_t PoolEntry<T>::getByteSize() {
|
||||
return ( sizeof(T) * this->length );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint8_t PoolEntry<T>::getSize() {
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void* PoolEntry<T>::getRawData() {
|
||||
return this->address;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PoolEntry<T>::setValid(bool isValid) {
|
||||
this->valid = isValid;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool PoolEntry<T>::getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PoolEntry<T>::print() {
|
||||
const char* validString = nullptr;
|
||||
if(valid) {
|
||||
validString = "Valid";
|
||||
}
|
||||
else {
|
||||
validString = "Invalid";
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "PoolEntry information." << std::endl;
|
||||
sif::info << "PoolEntry validity: " << validString << std::endl;
|
||||
#else
|
||||
sif::printInfo("PoolEntry information.\n");
|
||||
sif::printInfo("PoolEntry validity: %s\n", validString);
|
||||
#endif
|
||||
arrayprinter::print(reinterpret_cast<uint8_t*>(address), getByteSize());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* PoolEntry<T>::getDataPtr() {
|
||||
return this->address;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Type PoolEntry<T>::getType() {
|
||||
return PodTypeConversion<T>::type;
|
||||
}
|
||||
|
||||
template class PoolEntry<uint8_t>;
|
||||
template class PoolEntry<uint16_t>;
|
||||
template class PoolEntry<uint32_t>;
|
||||
template class PoolEntry<uint64_t>;
|
||||
template class PoolEntry<int8_t>;
|
||||
template class PoolEntry<int16_t>;
|
||||
template class PoolEntry<int32_t>;
|
||||
template class PoolEntry<int64_t>;
|
||||
template class PoolEntry<float>;
|
||||
template class PoolEntry<double>;
|
@ -1,137 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLENTRY_H_
|
||||
#define FSFW_DATAPOOL_POOLENTRY_H_
|
||||
|
||||
#include "PoolEntryIF.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This is a small helper class that defines a single data pool entry.
|
||||
* @details
|
||||
* The helper is used to store all information together with the data as a
|
||||
* single data pool entry. The content's type is defined by the template
|
||||
* argument.
|
||||
*
|
||||
* It is prepared for use with plain old data types, but may be
|
||||
* extended to complex types if necessary. It can be initialized with a
|
||||
* certain value, size and validity flag.
|
||||
*
|
||||
* It holds a pointer to the real data and offers methods to access this data
|
||||
* and to acquire additional information (such as validity and array/byte size).
|
||||
* It is NOT intended to be used outside DataPool implementations as it performs
|
||||
* dynamic memory allocation.
|
||||
*
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template <typename T>
|
||||
class PoolEntry : public PoolEntryIF {
|
||||
public:
|
||||
static_assert(not std::is_same<T, bool>::value,
|
||||
"Do not use boolean for the PoolEntry type, use uint8_t "
|
||||
"instead! The ECSS standard defines a boolean as a one bit "
|
||||
"field. Therefore it is preferred to store a boolean as an "
|
||||
"uint8_t");
|
||||
/**
|
||||
* @brief In the classe's constructor, space is allocated on the heap and
|
||||
* potential initialization values are copied to that space.
|
||||
* @details
|
||||
* Not passing any arguments will initialize an non-array pool entry
|
||||
* with an initial invalid state and the value 0.
|
||||
* Please note that if an initializer list is passed, the length of the
|
||||
* initializer list needs to be correct for vector entries because
|
||||
* required allocated space will be deduced from the initializer list length
|
||||
* and the pool entry type.
|
||||
* @param initValue
|
||||
* Initializer list with values to initialize with, for example {0, 0} to
|
||||
* initialize the a pool entry of a vector with two entries to 0.
|
||||
* @param setValid
|
||||
* Sets the initialization flag. It is invalid by default.
|
||||
*/
|
||||
PoolEntry(std::initializer_list<T> initValue = {0}, bool setValid = false);
|
||||
|
||||
/**
|
||||
* @brief In the classe's constructor, space is allocated on the heap and
|
||||
* potential init values are copied to that space.
|
||||
* @param initValue
|
||||
* A pointer to the single value or array that holds the init value.
|
||||
* With the default value (nullptr), the entry is initalized with all 0.
|
||||
* @param setLength
|
||||
* Defines the array length of this entry.
|
||||
* @param setValid
|
||||
* Sets the initialization flag. It is invalid by default.
|
||||
*/
|
||||
PoolEntry(T* initValue, uint8_t setLength = 1, bool setValid = false);
|
||||
|
||||
//! Explicitely deleted copy ctor, copying is not allowed.
|
||||
PoolEntry(const PoolEntry&) = delete;
|
||||
//! Explicitely deleted copy assignment, copying is not allowed.
|
||||
PoolEntry& operator=(const PoolEntry&) = delete;
|
||||
|
||||
/**
|
||||
* @brief The allocated memory for the variable is freed
|
||||
* in the destructor.
|
||||
* @details
|
||||
* As the data pool is global, this dtor is only called on program exit.
|
||||
* PoolEntries shall never be copied, as a copy might delete the variable
|
||||
* on the heap.
|
||||
*/
|
||||
~PoolEntry();
|
||||
|
||||
/**
|
||||
* Return typed pointer to start of data.
|
||||
* @return
|
||||
*/
|
||||
T* getDataPtr();
|
||||
|
||||
/**
|
||||
* @brief getSize returns the array size of the entry.
|
||||
* @details
|
||||
* For non-array pool entries return type size, for vector entries
|
||||
* return type size times the number of entries.
|
||||
*/
|
||||
uint8_t getSize();
|
||||
/**
|
||||
* @brief This operation returns the size in bytes.
|
||||
* @details The size is calculated by sizeof(type) * array_size.
|
||||
*/
|
||||
uint16_t getByteSize();
|
||||
/**
|
||||
* @brief This operation returns a the address pointer casted to void*.
|
||||
*/
|
||||
void* getRawData();
|
||||
/**
|
||||
* @brief This method allows to set the valid information
|
||||
* of the pool entry.
|
||||
*/
|
||||
void setValid( bool isValid );
|
||||
/**
|
||||
* @brief This method allows to get the valid information
|
||||
* of the pool entry.
|
||||
*/
|
||||
bool getValid();
|
||||
/**
|
||||
* @brief This is a debug method that prints all values and the valid
|
||||
* information to the screen. It prints all array entries in a row.
|
||||
*/
|
||||
void print();
|
||||
Type getType();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief This attribute stores the length information.
|
||||
*/
|
||||
uint8_t length;
|
||||
/**
|
||||
* @brief Here, the validity information for a variable is stored.
|
||||
* Every entry (single variable or vector) has one valid flag.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* @brief This is the address pointing to the allocated memory.
|
||||
*/
|
||||
T* address;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLENTRY_H_ */
|
@ -1,63 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||
#define FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||
|
||||
#include "../globalfunctions/Type.h"
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief This interface defines the access possibilities to a
|
||||
* single data pool entry.
|
||||
* @details
|
||||
* The interface provides methods to determine the size and the validity
|
||||
* information of a value. It also defines a method to receive a pointer to the
|
||||
* raw data content. It is mainly used by DataPool itself, but also as a
|
||||
* return pointer.
|
||||
*
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*
|
||||
*/
|
||||
class PoolEntryIF {
|
||||
public:
|
||||
/**
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is required for C++ interfaces.
|
||||
*/
|
||||
virtual ~PoolEntryIF() {
|
||||
}
|
||||
/**
|
||||
* @brief getSize returns the array size of the entry.
|
||||
* A single variable parameter has size 1.
|
||||
*/
|
||||
virtual uint8_t getSize() = 0;
|
||||
/**
|
||||
* @brief This operation returns the size in bytes, which is calculated by
|
||||
* sizeof(type) * array_size.
|
||||
*/
|
||||
virtual uint16_t getByteSize() = 0;
|
||||
/**
|
||||
* @brief This operation returns a the address pointer casted to void*.
|
||||
*/
|
||||
virtual void* getRawData() = 0;
|
||||
/**
|
||||
* @brief This method allows to set the valid information of the pool entry.
|
||||
*/
|
||||
virtual void setValid(bool isValid) = 0;
|
||||
/**
|
||||
* @brief This method allows to set the valid information of the pool entry.
|
||||
*/
|
||||
virtual bool getValid() = 0;
|
||||
/**
|
||||
* @brief This is a debug method that prints all values and the valid
|
||||
* information to the screen. It prints all array entries in a row.
|
||||
* @details
|
||||
* Also displays whether the pool entry is valid or invalid.
|
||||
*/
|
||||
virtual void print() = 0;
|
||||
/**
|
||||
* Returns the type of the entry.
|
||||
*/
|
||||
virtual Type getType() = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */
|
@ -1,62 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLREADHELPER_H_
|
||||
#define FSFW_DATAPOOL_POOLREADHELPER_H_
|
||||
|
||||
#include "ReadCommitIF.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include <FSFWConfig.h>
|
||||
|
||||
/**
|
||||
* @brief Helper class to read data sets or pool variables
|
||||
*/
|
||||
class PoolReadGuard {
|
||||
public:
|
||||
PoolReadGuard(ReadCommitIF* readObject,
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
uint32_t mutexTimeout = 20):
|
||||
readObject(readObject), mutexTimeout(mutexTimeout) {
|
||||
if(readObject != nullptr) {
|
||||
readResult = readObject->read(timeoutType, mutexTimeout);
|
||||
if(readResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_VERBOSE_LEVEL == 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PoolReadHelper: Read failed!" << std::endl;
|
||||
#else
|
||||
sif::printError("PoolReadHelper: Read failed!\n");
|
||||
#endif /* FSFW_PRINT_VERBOSITY_LEVEL == 1 */
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t getReadResult() const {
|
||||
return readResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Can be used to suppress commit on destruction.
|
||||
*/
|
||||
void setNoCommitMode(bool commit) {
|
||||
this->noCommit = commit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default destructor which will take care of commiting changed values.
|
||||
*/
|
||||
~PoolReadGuard() {
|
||||
if(readObject != nullptr and not noCommit) {
|
||||
readObject->commit(timeoutType, mutexTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
ReadCommitIF* readObject = nullptr;
|
||||
ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK;
|
||||
bool noCommit = false;
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||
uint32_t mutexTimeout = 20;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLREADHELPER_H_ */
|
@ -1,29 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLVARLIST_H_
|
||||
#define FSFW_DATAPOOL_POOLVARLIST_H_
|
||||
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
template <class T, uint8_t n_var>
|
||||
class PoolVarList {
|
||||
private:
|
||||
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.
|
||||
if (dataSet == NULL) {
|
||||
return;
|
||||
}
|
||||
for (uint8_t count = 0; count < n_var; count++) {
|
||||
variables[count].dataPoolId = set_id[count];
|
||||
variables[count].readWriteMode = setReadWriteMode;
|
||||
dataSet->registerVariable(&variables[count]);
|
||||
}
|
||||
}
|
||||
|
||||
GlobPoolVar<T> &operator [](int i) { return variables[i]; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLVARLIST_H_ */
|
@ -1,68 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||
#define FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||
|
||||
#include "ReadCommitIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
|
||||
|
||||
/**
|
||||
* @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,
|
||||
public ReadCommitIF {
|
||||
|
||||
public:
|
||||
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 ReturnValue_t INVALID_POOL_ENTRY = MAKE_RETURN_CODE(0xA1);
|
||||
|
||||
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.
|
||||
*/
|
||||
virtual ~PoolVariableIF() {}
|
||||
/**
|
||||
* @brief This method returns if the variable is write-only,
|
||||
* read-write or read-only.
|
||||
*/
|
||||
virtual ReadWriteMode_t getReadWriteMode() const = 0;
|
||||
virtual void setReadWriteMode(ReadWriteMode_t newMode) = 0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual bool isValid() const = 0;
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is set.
|
||||
*/
|
||||
virtual void setValid(bool validity) = 0;
|
||||
};
|
||||
|
||||
using pool_rwm_t = PoolVariableIF::ReadWriteMode_t;
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLVARIABLEIF_H_ */
|
@ -1,34 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_READCOMMITIF_H_
|
||||
#define FSFW_DATAPOOL_READCOMMITIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
|
||||
/**
|
||||
* @brief Common interface for all software objects which employ read-commit
|
||||
* semantics.
|
||||
*/
|
||||
class ReadCommitIF {
|
||||
friend class ReadCommitIFAttorney;
|
||||
public:
|
||||
virtual ~ReadCommitIF() {}
|
||||
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) = 0;
|
||||
virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/* Optional and protected because this is interesting for classes grouping members with commit
|
||||
and read semantics where the lock is only necessary once. */
|
||||
virtual ReturnValue_t readWithoutLock() {
|
||||
return read(MutexIF::TimeoutType::WAITING, 20);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t commitWithoutLock() {
|
||||
return commit(MutexIF::TimeoutType::WAITING, 20);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOL_READCOMMITIF_H_ */
|
@ -1,32 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_
|
||||
#define FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_
|
||||
|
||||
#include <fsfw/datapool/ReadCommitIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
/**
|
||||
* @brief This class determines which members are allowed to access protected members
|
||||
* of the ReadCommitIF.
|
||||
*/
|
||||
class ReadCommitIFAttorney {
|
||||
private:
|
||||
static ReturnValue_t readWithoutLock(ReadCommitIF* readCommitIF) {
|
||||
if(readCommitIF == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return readCommitIF->readWithoutLock();
|
||||
}
|
||||
|
||||
static ReturnValue_t commitWithoutLock(ReadCommitIF* readCommitIF) {
|
||||
if(readCommitIF == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return readCommitIF->commitWithoutLock();
|
||||
}
|
||||
|
||||
friend class PoolDataSetBase;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_ */
|
@ -1,16 +0,0 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
|
||||
#include "PoolDataSetIF.h"
|
||||
|
||||
class SharedDataSetIF {
|
||||
public:
|
||||
virtual ~SharedDataSetIF() {};
|
||||
|
||||
private:
|
||||
virtual ReturnValue_t lockDataset(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t mutexTimeout) = 0;
|
||||
virtual ReturnValue_t unlockDataset() = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_ */
|
@ -1,27 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_
|
||||
#define FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_
|
||||
|
||||
class LocalDataPoolManager;
|
||||
class MutexIF;
|
||||
|
||||
/**
|
||||
* @brief Accessor class which can be used by classes which like to use the pool manager.
|
||||
*/
|
||||
class AccessPoolManagerIF {
|
||||
public:
|
||||
virtual ~AccessPoolManagerIF() {};
|
||||
|
||||
virtual MutexIF* getLocalPoolMutex() = 0;
|
||||
|
||||
/**
|
||||
* Can be used to get a handle to the local data pool manager.
|
||||
* This function is protected because it should only be used by the
|
||||
* class imlementing the interface.
|
||||
*/
|
||||
virtual LocalDataPoolManager* getPoolManagerHandle() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_ */
|
@ -1,186 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_
|
||||
#define FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_
|
||||
|
||||
#include "localPoolDefinitions.h"
|
||||
#include "LocalDataPoolManager.h"
|
||||
|
||||
#include "../datapool/PoolEntryIF.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../housekeeping/HousekeepingMessage.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class AccessPoolManagerIF;
|
||||
class ProvidesDataPoolSubscriptionIF;
|
||||
class LocalPoolDataSetBase;
|
||||
class LocalPoolObjectBase;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* The local data pool can be accessed using helper classes by using the
|
||||
* LocalPoolVariable, LocalPoolVector or LocalDataSet classes. Every local pool variable can
|
||||
* be uniquely identified by a global pool ID (gp_id_t) and every dataset tied
|
||||
* to a pool manager can be uniqely identified by a global structure ID (sid_t).
|
||||
*
|
||||
* All software objects which want to use the local pool of another object shall also use this
|
||||
* interface, for example to get a handle to the subscription interface. The interface
|
||||
* can be retrieved using the object manager, provided the target object is a SystemObject.
|
||||
* For example, the following line of code can be used to retrieve the interface
|
||||
*
|
||||
* HasLocalDataPoolIF* poolIF = objectManager->get<HasLocalDataPoolIF>(objects::SOME_OBJECT);
|
||||
* if(poolIF != nullptr) {
|
||||
* doSomething()
|
||||
* }
|
||||
*/
|
||||
class HasLocalDataPoolIF {
|
||||
friend class HasLocalDpIFManagerAttorney;
|
||||
friend class HasLocalDpIFUserAttorney;
|
||||
public:
|
||||
virtual~ HasLocalDataPoolIF() {};
|
||||
|
||||
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
|
||||
|
||||
virtual object_id_t getObjectId() const = 0;
|
||||
|
||||
/** Command queue for housekeeping messages. */
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
|
||||
/**
|
||||
* Is used by pool owner to initialize the pool map once
|
||||
* The manager instance shall also be passed to this function.
|
||||
* It can be used to subscribe for periodic packets for for updates.
|
||||
*/
|
||||
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) = 0;
|
||||
|
||||
/**
|
||||
* Returns the minimum sampling frequency in milliseconds, which will
|
||||
* usually be the period the pool owner performs its periodic operation.
|
||||
* @return
|
||||
*/
|
||||
virtual dur_millis_t getPeriodicOperationFrequency() const = 0;
|
||||
|
||||
/**
|
||||
* @brief This function will be called by the manager if an update
|
||||
* notification is received.
|
||||
* @details HasLocalDataPoolIF
|
||||
* Can be overriden by the child class to handle changed datasets.
|
||||
* @param sid SID of the updated set
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* the IPC store with this store ID.
|
||||
* @param clearMessage If this is set to true, the pool manager will take care of
|
||||
* clearing the store automatically
|
||||
*/
|
||||
virtual void handleChangedDataset(sid_t sid,
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS,
|
||||
bool* clearMessage = nullptr) {
|
||||
if(clearMessage != nullptr) {
|
||||
*clearMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will be called by the manager if an update
|
||||
* notification is received.
|
||||
* @details
|
||||
* Can be overriden by the child class to handle changed pool variables.
|
||||
* @param gpid GPID of the updated variable.
|
||||
* @param storeId If a snapshot was requested, data will be located inside
|
||||
* the IPC store with this store ID.
|
||||
* @param clearMessage Relevant for snapshots. If the boolean this points to is set to true,
|
||||
* the pool manager will take care of clearing the store automatically
|
||||
* after the callback.
|
||||
*/
|
||||
virtual void handleChangedPoolVariable(gp_id_t gpid,
|
||||
store_address_t storeId = storeId::INVALID_STORE_ADDRESS,
|
||||
bool* clearMessage = nullptr) {
|
||||
if(clearMessage != nullptr) {
|
||||
*clearMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* These function can be implemented by pool owner, if they are required
|
||||
* and used 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, float newIntervalSeconds) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function can be used by data pool consumers to retrieve a handle
|
||||
* which allows subscriptions to dataset and variable updates in form of messages.
|
||||
* The consumers can then read the most recent variable value by calling read with
|
||||
* an own pool variable or set instance or using the deserialized snapshot data.
|
||||
* Returns the HK manager casted to the required interface by default.
|
||||
* @return
|
||||
*/
|
||||
virtual ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() {
|
||||
return getHkManagerHandle();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Every class implementing this interface should have a local data pool manager. This
|
||||
* function will return a reference to the manager.
|
||||
* @return
|
||||
*/
|
||||
virtual LocalDataPoolManager* getHkManagerHandle() = 0;
|
||||
|
||||
/**
|
||||
* Accessor handle required for internal handling. Not intended for users and therefore
|
||||
* declared protected. Users should instead use pool variables, sets or the subscription
|
||||
* interface to access pool entries. Returns the HK manager casted to a different interface
|
||||
* by default.
|
||||
* @return
|
||||
*/
|
||||
virtual AccessPoolManagerIF* getAccessorHandle() {
|
||||
return getHkManagerHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used by the pool manager to get a valid dataset
|
||||
* from a SID. This function is protected to prevent users from
|
||||
* using raw data set pointers which could not be thread-safe. Users
|
||||
* should use the #ProvidesDataPoolSubscriptionIF.
|
||||
* @param sid Corresponding structure ID
|
||||
* @return
|
||||
*/
|
||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0;
|
||||
|
||||
/**
|
||||
* Similar to the function above, but used to get a local pool variable
|
||||
* handle. This is only needed for update notifications, so it is not
|
||||
* defined as abstract. This function is protected to prevent users from
|
||||
* using raw pool variable pointers which could not be thread-safe.
|
||||
* Users should use the #ProvidesDataPoolSubscriptionIF.
|
||||
* @param localPoolId
|
||||
* @return
|
||||
*/
|
||||
virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden. "
|
||||
"Returning nullptr!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: "
|
||||
"Not overriden. Returning nullptr!\n");
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */
|
@ -1,942 +0,0 @@
|
||||
#include "HasLocalDataPoolIF.h"
|
||||
#include "LocalDataPoolManager.h"
|
||||
#include "LocalPoolObjectBase.h"
|
||||
#include "LocalPoolDataSetBase.h"
|
||||
#include "internal/LocalPoolDataSetAttorney.h"
|
||||
#include "internal/HasLocalDpIFManagerAttorney.h"
|
||||
|
||||
#include "../housekeeping/HousekeepingSetPacket.h"
|
||||
#include "../housekeeping/HousekeepingSnapshot.h"
|
||||
#include "../housekeeping/AcceptsHkPacketsIF.h"
|
||||
#include "../timemanager/CCSDSTime.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
#include "../ipc/MutexGuard.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
object_id_t LocalDataPoolManager::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING;
|
||||
|
||||
LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse,
|
||||
bool appendValidityBuffer):
|
||||
appendValidityBuffer(appendValidityBuffer) {
|
||||
if(owner == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"LocalDataPoolManager", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"Invalid supplied owner");
|
||||
return;
|
||||
}
|
||||
this->owner = owner;
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if(mutex == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_ERROR,
|
||||
"LocalDataPoolManager", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"Could not create mutex");
|
||||
}
|
||||
|
||||
hkQueue = queueToUse;
|
||||
}
|
||||
|
||||
LocalDataPoolManager::~LocalDataPoolManager() {
|
||||
if(mutex != nullptr) {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
|
||||
if(queueToUse == nullptr) {
|
||||
/* Error, all destinations invalid */
|
||||
printWarningOrError(sif::OutputTypes::OUT_ERROR, "initialize",
|
||||
QUEUE_OR_DESTINATION_INVALID);
|
||||
}
|
||||
hkQueue = queueToUse;
|
||||
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if(ipcStore == nullptr) {
|
||||
/* Error, all destinations invalid */
|
||||
printWarningOrError(sif::OutputTypes::OUT_ERROR,
|
||||
"initialize", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"Could not set IPC store.");
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
|
||||
if(defaultHkDestination != objects::NO_OBJECT) {
|
||||
AcceptsHkPacketsIF* hkPacketReceiver =
|
||||
objectManager->get<AcceptsHkPacketsIF>(defaultHkDestination);
|
||||
if(hkPacketReceiver != nullptr) {
|
||||
hkDestinationId = hkPacketReceiver->getHkQueue();
|
||||
}
|
||||
else {
|
||||
printWarningOrError(sif::OutputTypes::OUT_ERROR,
|
||||
"initialize", QUEUE_OR_DESTINATION_INVALID);
|
||||
return QUEUE_OR_DESTINATION_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initializeAfterTaskCreation(
|
||||
uint8_t nonDiagInvlFactor) {
|
||||
setNonDiagnosticIntervalFactor(nonDiagInvlFactor);
|
||||
return initializeHousekeepingPoolEntriesOnce();
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
|
||||
if(not mapInitialized) {
|
||||
ReturnValue_t result = owner->initializeLocalDataPool(localPoolMap,
|
||||
*this);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
mapInitialized = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"initialize", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"The map should only be initialized once");
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::performHkOperation() {
|
||||
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||
for(auto& receiver: hkReceivers) {
|
||||
switch(receiver.reportingType) {
|
||||
case(ReportingType::PERIODIC): {
|
||||
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||
/* Periodic packets shall only be generated from datasets */
|
||||
continue;
|
||||
}
|
||||
performPeriodicHkGeneration(receiver);
|
||||
break;
|
||||
}
|
||||
case(ReportingType::UPDATE_HK): {
|
||||
handleHkUpdate(receiver, status);
|
||||
break;
|
||||
}
|
||||
case(ReportingType::UPDATE_NOTIFICATION): {
|
||||
handleNotificationUpdate(receiver, status);
|
||||
break;
|
||||
}
|
||||
case(ReportingType::UPDATE_SNAPSHOT): {
|
||||
handleNotificationSnapshot(receiver, status);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// This should never happen.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
resetHkUpdateResetHelper();
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::handleHkUpdate(HkReceiver& receiver,
|
||||
ReturnValue_t& status) {
|
||||
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||
/* Update packets shall only be generated from datasets. */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner,
|
||||
receiver.dataId.sid);
|
||||
if(dataSet == nullptr) {
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
if(dataSet->hasChanged()) {
|
||||
/* Prepare and send update notification */
|
||||
ReturnValue_t result = generateHousekeepingPacket(
|
||||
receiver.dataId.sid, dataSet, true);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
}
|
||||
handleChangeResetLogic(receiver.dataType, receiver.dataId,
|
||||
dataSet);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(HkReceiver& receiver,
|
||||
ReturnValue_t& status) {
|
||||
MarkChangedIF* toReset = nullptr;
|
||||
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||
LocalPoolObjectBase* poolObj = HasLocalDpIFManagerAttorney::getPoolObjectHandle(owner,
|
||||
receiver.dataId.localPoolId);
|
||||
if(poolObj == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"handleNotificationUpdate", POOLOBJECT_NOT_FOUND);
|
||||
return POOLOBJECT_NOT_FOUND;
|
||||
}
|
||||
if(poolObj->hasChanged()) {
|
||||
/* Prepare and send update notification. */
|
||||
CommandMessage notification;
|
||||
HousekeepingMessage::setUpdateNotificationVariableCommand(¬ification,
|
||||
gp_id_t(owner->getObjectId(), receiver.dataId.localPoolId));
|
||||
ReturnValue_t result = hkQueue->sendMessage(receiver.destinationQueue, ¬ification);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
toReset = poolObj;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner,
|
||||
receiver.dataId.sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"handleNotificationUpdate", DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
if(dataSet->hasChanged()) {
|
||||
/* Prepare and send update notification */
|
||||
CommandMessage notification;
|
||||
HousekeepingMessage::setUpdateNotificationSetCommand(¬ification,
|
||||
receiver.dataId.sid);
|
||||
ReturnValue_t result = hkQueue->sendMessage(
|
||||
receiver.destinationQueue, ¬ification);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
toReset = dataSet;
|
||||
}
|
||||
}
|
||||
if(toReset != nullptr) {
|
||||
handleChangeResetLogic(receiver.dataType, receiver.dataId, toReset);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
|
||||
HkReceiver& receiver, ReturnValue_t& status) {
|
||||
MarkChangedIF* toReset = nullptr;
|
||||
/* Check whether data has changed and send messages in case it has */
|
||||
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||
LocalPoolObjectBase* poolObj = HasLocalDpIFManagerAttorney::getPoolObjectHandle(owner,
|
||||
receiver.dataId.localPoolId);
|
||||
if(poolObj == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"handleNotificationSnapshot", POOLOBJECT_NOT_FOUND);
|
||||
return POOLOBJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (not poolObj->hasChanged()) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
/* Prepare and send update snapshot */
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
CCSDSTime::CDS_short cds;
|
||||
CCSDSTime::convertToCcsds(&cds, &now);
|
||||
HousekeepingSnapshot updatePacket(reinterpret_cast<uint8_t*>(&cds), sizeof(cds),
|
||||
HasLocalDpIFManagerAttorney::getPoolObjectHandle(
|
||||
owner,receiver.dataId.localPoolId));
|
||||
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = addUpdateToStore(updatePacket, storeId);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
CommandMessage notification;
|
||||
HousekeepingMessage::setUpdateSnapshotVariableCommand(¬ification,
|
||||
gp_id_t(owner->getObjectId(), receiver.dataId.localPoolId), storeId);
|
||||
result = hkQueue->sendMessage(receiver.destinationQueue,
|
||||
¬ification);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
toReset = poolObj;
|
||||
}
|
||||
else {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner,
|
||||
receiver.dataId.sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"handleNotificationSnapshot", DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
if(not dataSet->hasChanged()) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
/* Prepare and send update snapshot */
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
CCSDSTime::CDS_short cds;
|
||||
CCSDSTime::convertToCcsds(&cds, &now);
|
||||
HousekeepingSnapshot updatePacket(reinterpret_cast<uint8_t*>(&cds),
|
||||
sizeof(cds), HasLocalDpIFManagerAttorney::getDataSetHandle(owner,
|
||||
receiver.dataId.sid));
|
||||
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = addUpdateToStore(updatePacket, storeId);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
CommandMessage notification;
|
||||
HousekeepingMessage::setUpdateSnapshotSetCommand(
|
||||
¬ification, receiver.dataId.sid, storeId);
|
||||
result = hkQueue->sendMessage(receiver.destinationQueue, ¬ification);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
toReset = dataSet;
|
||||
|
||||
}
|
||||
if(toReset != nullptr) {
|
||||
handleChangeResetLogic(receiver.dataType,
|
||||
receiver.dataId, toReset);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::addUpdateToStore(
|
||||
HousekeepingSnapshot& updatePacket, store_address_t& storeId) {
|
||||
size_t updatePacketSize = updatePacket.getSerializedSize();
|
||||
uint8_t *storePtr = nullptr;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||
updatePacket.getSerializedSize(), &storePtr);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
size_t serializedSize = 0;
|
||||
result = updatePacket.serialize(&storePtr, &serializedSize,
|
||||
updatePacketSize, SerializeIF::Endianness::MACHINE);
|
||||
return result;;
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::handleChangeResetLogic(
|
||||
DataType type, DataId dataId, MarkChangedIF* toReset) {
|
||||
if(hkUpdateResetList == nullptr) {
|
||||
/* Config error */
|
||||
return;
|
||||
}
|
||||
HkUpdateResetList& listRef = *hkUpdateResetList;
|
||||
for(auto& changeInfo: listRef) {
|
||||
if(changeInfo.dataType != type) {
|
||||
continue;
|
||||
}
|
||||
if((changeInfo.dataType == DataType::DATA_SET) and
|
||||
(changeInfo.dataId.sid != dataId.sid)) {
|
||||
continue;
|
||||
}
|
||||
if((changeInfo.dataType == DataType::LOCAL_POOL_VARIABLE) and
|
||||
(changeInfo.dataId.localPoolId != dataId.localPoolId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Only one update recipient, we can reset changes status immediately */
|
||||
if(changeInfo.updateCounter <= 1) {
|
||||
toReset->setChanged(false);
|
||||
}
|
||||
/* All recipients have been notified, reset the changed flag */
|
||||
else if(changeInfo.currentUpdateCounter <= 1) {
|
||||
toReset->setChanged(false);
|
||||
changeInfo.currentUpdateCounter = 0;
|
||||
}
|
||||
/* Not all recipiens have been notified yet, decrement */
|
||||
else {
|
||||
changeInfo.currentUpdateCounter--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::resetHkUpdateResetHelper() {
|
||||
if(hkUpdateResetList == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(auto& changeInfo: *hkUpdateResetList) {
|
||||
changeInfo.currentUpdateCounter = changeInfo.updateCounter;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid,
|
||||
bool enableReporting, float collectionInterval, bool isDiagnostics,
|
||||
object_id_t packetDestination) {
|
||||
AcceptsHkPacketsIF* hkReceiverObject =
|
||||
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
|
||||
if(hkReceiverObject == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"subscribeForPeriodicPacket", QUEUE_OR_DESTINATION_INVALID);
|
||||
return QUEUE_OR_DESTINATION_INVALID;
|
||||
}
|
||||
|
||||
struct HkReceiver hkReceiver;
|
||||
hkReceiver.dataId.sid = sid;
|
||||
hkReceiver.reportingType = ReportingType::PERIODIC;
|
||||
hkReceiver.dataType = DataType::DATA_SET;
|
||||
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
|
||||
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet != nullptr) {
|
||||
LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting);
|
||||
LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics);
|
||||
LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval,
|
||||
owner->getPeriodicOperationFrequency());
|
||||
}
|
||||
|
||||
hkReceivers.push_back(hkReceiver);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(sid_t sid,
|
||||
bool isDiagnostics, bool reportingEnabled,
|
||||
object_id_t packetDestination) {
|
||||
AcceptsHkPacketsIF* hkReceiverObject =
|
||||
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
|
||||
if(hkReceiverObject == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"subscribeForPeriodicPacket", QUEUE_OR_DESTINATION_INVALID);
|
||||
return QUEUE_OR_DESTINATION_INVALID;
|
||||
}
|
||||
|
||||
struct HkReceiver hkReceiver;
|
||||
hkReceiver.dataId.sid = sid;
|
||||
hkReceiver.reportingType = ReportingType::UPDATE_HK;
|
||||
hkReceiver.dataType = DataType::DATA_SET;
|
||||
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
|
||||
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet != nullptr) {
|
||||
LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true);
|
||||
LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics);
|
||||
}
|
||||
|
||||
hkReceivers.push_back(hkReceiver);
|
||||
|
||||
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::subscribeForSetUpdateMessage(
|
||||
const uint32_t setId, object_id_t destinationObject,
|
||||
MessageQueueId_t targetQueueId, bool generateSnapshot) {
|
||||
struct HkReceiver hkReceiver;
|
||||
hkReceiver.dataType = DataType::DATA_SET;
|
||||
hkReceiver.dataId.sid = sid_t(owner->getObjectId(), setId);
|
||||
hkReceiver.destinationQueue = targetQueueId;
|
||||
hkReceiver.objectId = destinationObject;
|
||||
if(generateSnapshot) {
|
||||
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
|
||||
}
|
||||
else {
|
||||
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
|
||||
}
|
||||
|
||||
hkReceivers.push_back(hkReceiver);
|
||||
|
||||
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessage(
|
||||
const lp_id_t localPoolId, object_id_t destinationObject,
|
||||
MessageQueueId_t targetQueueId, bool generateSnapshot) {
|
||||
struct HkReceiver hkReceiver;
|
||||
hkReceiver.dataType = DataType::LOCAL_POOL_VARIABLE;
|
||||
hkReceiver.dataId.localPoolId = localPoolId;
|
||||
hkReceiver.destinationQueue = targetQueueId;
|
||||
hkReceiver.objectId = destinationObject;
|
||||
if(generateSnapshot) {
|
||||
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
|
||||
}
|
||||
else {
|
||||
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
|
||||
}
|
||||
|
||||
hkReceivers.push_back(hkReceiver);
|
||||
|
||||
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType,
|
||||
DataId dataId) {
|
||||
if(hkUpdateResetList == nullptr) {
|
||||
hkUpdateResetList = new std::vector<struct HkUpdateResetHelper>();
|
||||
}
|
||||
|
||||
for(auto& updateResetStruct: *hkUpdateResetList) {
|
||||
if(dataType == DataType::DATA_SET) {
|
||||
if(updateResetStruct.dataId.sid == dataId.sid) {
|
||||
updateResetStruct.updateCounter++;
|
||||
updateResetStruct.currentUpdateCounter++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(updateResetStruct.dataId.localPoolId == dataId.localPoolId) {
|
||||
updateResetStruct.updateCounter++;
|
||||
updateResetStruct.currentUpdateCounter++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
HkUpdateResetHelper hkUpdateResetHelper;
|
||||
hkUpdateResetHelper.currentUpdateCounter = 1;
|
||||
hkUpdateResetHelper.updateCounter = 1;
|
||||
hkUpdateResetHelper.dataType = dataType;
|
||||
if(dataType == DataType::DATA_SET) {
|
||||
hkUpdateResetHelper.dataId.sid = dataId.sid;
|
||||
}
|
||||
else {
|
||||
hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId;
|
||||
}
|
||||
hkUpdateResetList->push_back(hkUpdateResetHelper);
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||
CommandMessage* message) {
|
||||
Command_t command = message->getCommand();
|
||||
sid_t sid = HousekeepingMessage::getSid(message);
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(command) {
|
||||
// Houskeeping interface handling.
|
||||
case(HousekeepingMessage::ENABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
|
||||
result = togglePeriodicGeneration(sid, true, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::DISABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
|
||||
result = togglePeriodicGeneration(sid, false, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::ENABLE_PERIODIC_HK_REPORT_GENERATION): {
|
||||
result = togglePeriodicGeneration(sid, true, false);
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::DISABLE_PERIODIC_HK_REPORT_GENERATION): {
|
||||
result = togglePeriodicGeneration(sid, false, false);
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES): {
|
||||
result = generateSetStructurePacket(sid, true);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES): {
|
||||
result = generateSetStructurePacket(sid, false);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL):
|
||||
case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): {
|
||||
float newCollIntvl = 0;
|
||||
HousekeepingMessage::getCollectionIntervalModificationCommand(message,
|
||||
&newCollIntvl);
|
||||
if(command == HousekeepingMessage::
|
||||
MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL) {
|
||||
result = changeCollectionInterval(sid, newCollIntvl, true);
|
||||
}
|
||||
else {
|
||||
result = changeCollectionInterval(sid, newCollIntvl, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
|
||||
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): {
|
||||
LocalPoolDataSetBase* dataSet =HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT
|
||||
and LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
result = WRONG_HK_PACKET_TYPE;
|
||||
break;
|
||||
}
|
||||
else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT
|
||||
and not LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
result = WRONG_HK_PACKET_TYPE;
|
||||
break;
|
||||
}
|
||||
return generateHousekeepingPacket(HousekeepingMessage::getSid(message),
|
||||
dataSet, true);
|
||||
}
|
||||
|
||||
/* Notification handling */
|
||||
case(HousekeepingMessage::UPDATE_NOTIFICATION_SET): {
|
||||
owner->handleChangedDataset(sid);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE): {
|
||||
gp_id_t globPoolId = HousekeepingMessage::getUpdateNotificationVariableCommand(message);
|
||||
owner->handleChangedPoolVariable(globPoolId);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(HousekeepingMessage::UPDATE_SNAPSHOT_SET): {
|
||||
store_address_t storeId;
|
||||
HousekeepingMessage::getUpdateSnapshotSetCommand(message, &storeId);
|
||||
bool clearMessage = true;
|
||||
owner->handleChangedDataset(sid, storeId, &clearMessage);
|
||||
if(clearMessage) {
|
||||
message->clear();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE): {
|
||||
store_address_t storeId;
|
||||
gp_id_t globPoolId = HousekeepingMessage::getUpdateSnapshotVariableCommand(message,
|
||||
&storeId);
|
||||
bool clearMessage = true;
|
||||
owner->handleChangedPoolVariable(globPoolId, storeId, &clearMessage);
|
||||
if(clearMessage) {
|
||||
message->clear();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
default:
|
||||
return CommandMessageIF::UNKNOWN_COMMAND;
|
||||
}
|
||||
|
||||
CommandMessage reply;
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
HousekeepingMessage::setHkRequestFailureReply(&reply, sid, result);
|
||||
}
|
||||
else {
|
||||
HousekeepingMessage::setHkRequestSuccessReply(&reply, sid);
|
||||
}
|
||||
hkQueue->sendMessage(hkDestinationId, &reply);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::printPoolEntry(
|
||||
lp_id_t localPoolId) {
|
||||
auto poolIter = localPoolMap.find(localPoolId);
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "printPoolEntry",
|
||||
localpool::POOL_ENTRY_NOT_FOUND);
|
||||
return localpool::POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
poolIter->second->print();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MutexIF* LocalDataPoolManager::getMutexHandle() {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
HasLocalDataPoolIF* LocalDataPoolManager::getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||
LocalPoolDataSetBase* dataSet, bool forDownlink,
|
||||
MessageQueueId_t destination) {
|
||||
if(dataSet == nullptr) {
|
||||
/* Configuration error. */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
store_address_t storeId;
|
||||
HousekeepingPacketDownlink hkPacket(sid, dataSet);
|
||||
size_t serializedSize = 0;
|
||||
ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, storeId,
|
||||
forDownlink, &serializedSize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK or serializedSize == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Now we set a HK message and send it the HK packet destination. */
|
||||
CommandMessage hkMessage;
|
||||
if(LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) {
|
||||
HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId);
|
||||
}
|
||||
else {
|
||||
HousekeepingMessage::setHkReportReply(&hkMessage, sid, storeId);
|
||||
}
|
||||
|
||||
if(hkQueue == nullptr) {
|
||||
/* Error, no queue available to send packet with. */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
QUEUE_OR_DESTINATION_INVALID);
|
||||
return QUEUE_OR_DESTINATION_INVALID;
|
||||
}
|
||||
if(destination == MessageQueueIF::NO_QUEUE) {
|
||||
if(hkDestinationId == MessageQueueIF::NO_QUEUE) {
|
||||
/* Error, all destinations invalid */
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateHousekeepingPacket",
|
||||
QUEUE_OR_DESTINATION_INVALID);
|
||||
}
|
||||
destination = hkDestinationId;
|
||||
}
|
||||
|
||||
return hkQueue->sendMessage(destination, &hkMessage);
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
|
||||
HousekeepingPacketDownlink& hkPacket,
|
||||
store_address_t& storeId, bool forDownlink,
|
||||
size_t* serializedSize) {
|
||||
uint8_t* dataPtr = nullptr;
|
||||
const size_t maxSize = hkPacket.getSerializedSize();
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||
maxSize, &dataPtr);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(forDownlink) {
|
||||
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
}
|
||||
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
|
||||
uint8_t nonDiagInvlFactor) {
|
||||
this->nonDiagnosticIntervalFactor = nonDiagInvlFactor;
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
|
||||
sid_t sid = receiver.dataId.sid;
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"performPeriodicHkGeneration",
|
||||
DATASET_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
if(not LocalPoolDataSetAttorney::getReportingEnabled(*dataSet)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PeriodicHousekeepingHelper* periodicHelper =
|
||||
LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet);
|
||||
|
||||
if(periodicHelper == nullptr) {
|
||||
/* Configuration error */
|
||||
return;
|
||||
}
|
||||
|
||||
if(not periodicHelper->checkOpNecessary()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReturnValue_t result = generateHousekeepingPacket(
|
||||
sid, dataSet, true);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
/* Configuration error */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalDataPoolManager::performHkOperation: HK generation failed." <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printWarning("LocalDataPoolManager::performHkOperation: HK generation failed.\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid,
|
||||
bool enable, bool isDiagnostics) {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "togglePeriodicGeneration",
|
||||
DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
if((LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and not isDiagnostics) or
|
||||
(not LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and isDiagnostics)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
}
|
||||
|
||||
if((LocalPoolDataSetAttorney::getReportingEnabled(*dataSet) and enable) or
|
||||
(not LocalPoolDataSetAttorney::getReportingEnabled(*dataSet) and not enable)) {
|
||||
return REPORTING_STATUS_UNCHANGED;
|
||||
}
|
||||
|
||||
LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enable);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
|
||||
float newCollectionInterval, bool isDiagnostics) {
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "changeCollectionInterval",
|
||||
DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
bool targetIsDiagnostics = LocalPoolDataSetAttorney::isDiagnostics(*dataSet);
|
||||
if((targetIsDiagnostics and not isDiagnostics) or
|
||||
(not targetIsDiagnostics and isDiagnostics)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
}
|
||||
|
||||
PeriodicHousekeepingHelper* periodicHelper =
|
||||
LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet);
|
||||
|
||||
if(periodicHelper == nullptr) {
|
||||
/* Configuration error, set might not have a corresponding pool manager */
|
||||
return PERIODIC_HELPER_INVALID;
|
||||
}
|
||||
|
||||
periodicHelper->changeCollectionInterval(newCollectionInterval);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
|
||||
bool isDiagnostics) {
|
||||
/* Get and check dataset first. */
|
||||
LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid);
|
||||
if(dataSet == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"performPeriodicHkGeneration", DATASET_NOT_FOUND);
|
||||
return DATASET_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
bool targetIsDiagnostics = LocalPoolDataSetAttorney::isDiagnostics(*dataSet);
|
||||
if((targetIsDiagnostics and not isDiagnostics) or
|
||||
(not targetIsDiagnostics and isDiagnostics)) {
|
||||
return WRONG_HK_PACKET_TYPE;
|
||||
}
|
||||
|
||||
bool valid = dataSet->isValid();
|
||||
bool reportingEnabled = LocalPoolDataSetAttorney::getReportingEnabled(*dataSet);
|
||||
float collectionInterval = LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet)->
|
||||
getCollectionIntervalInSeconds();
|
||||
|
||||
// Generate set packet which can be serialized.
|
||||
HousekeepingSetPacket setPacket(sid,
|
||||
reportingEnabled, valid, collectionInterval, dataSet);
|
||||
size_t expectedSize = setPacket.getSerializedSize();
|
||||
uint8_t* storePtr = nullptr;
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||
expectedSize,&storePtr);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_ERROR,
|
||||
"generateSetStructurePacket", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"Could not get free element from IPC store.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Serialize set packet into store.
|
||||
size_t size = 0;
|
||||
result = setPacket.serialize(&storePtr, &size, expectedSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if(expectedSize != size) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"generateSetStructurePacket", HasReturnvaluesIF::RETURN_FAILED,
|
||||
"Expected size is not equal to serialized size");
|
||||
}
|
||||
|
||||
// Send structure reporting reply.
|
||||
CommandMessage reply;
|
||||
if(isDiagnostics) {
|
||||
HousekeepingMessage::setDiagnosticsStuctureReportReply(&reply,
|
||||
sid, storeId);
|
||||
}
|
||||
else {
|
||||
HousekeepingMessage::setHkStuctureReportReply(&reply,
|
||||
sid, storeId);
|
||||
}
|
||||
|
||||
hkQueue->reply(&reply);
|
||||
return result;
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::clearReceiversList() {
|
||||
/* Clear the vector completely and releases allocated memory. */
|
||||
HkReceivers().swap(hkReceivers);
|
||||
/* Also clear the reset helper if it exists */
|
||||
if(hkUpdateResetList != nullptr) {
|
||||
HkUpdateResetList().swap(*hkUpdateResetList);
|
||||
}
|
||||
}
|
||||
|
||||
MutexIF* LocalDataPoolManager::getLocalPoolMutex() {
|
||||
return this->mutex;
|
||||
}
|
||||
|
||||
object_id_t LocalDataPoolManager::getCreatorObjectId() const {
|
||||
return owner->getObjectId();
|
||||
}
|
||||
|
||||
void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
|
||||
const char* functionName, ReturnValue_t error, const char* errorPrint) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if(errorPrint == nullptr) {
|
||||
if(error == DATASET_NOT_FOUND) {
|
||||
errorPrint = "Dataset not found";
|
||||
}
|
||||
else if(error == POOLOBJECT_NOT_FOUND) {
|
||||
errorPrint = "Pool Object not found";
|
||||
}
|
||||
else if(error == HasReturnvaluesIF::RETURN_FAILED) {
|
||||
if(outputType == sif::OutputTypes::OUT_WARNING) {
|
||||
errorPrint = "Generic Warning";
|
||||
}
|
||||
else {
|
||||
errorPrint = "Generic error";
|
||||
}
|
||||
}
|
||||
else if(error == QUEUE_OR_DESTINATION_INVALID) {
|
||||
errorPrint = "Queue or destination not set";
|
||||
}
|
||||
else if(error == localpool::POOL_ENTRY_TYPE_CONFLICT) {
|
||||
errorPrint = "Pool entry type conflict";
|
||||
}
|
||||
else if(error == localpool::POOL_ENTRY_NOT_FOUND) {
|
||||
errorPrint = "Pool entry not found";
|
||||
}
|
||||
else {
|
||||
errorPrint = "Unknown error";
|
||||
}
|
||||
}
|
||||
object_id_t objectId = 0xffffffff;
|
||||
if(owner != nullptr) {
|
||||
objectId = owner->getObjectId();
|
||||
}
|
||||
|
||||
if(outputType == sif::OutputTypes::OUT_WARNING) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalDataPoolManager::" << functionName << ": Object ID 0x" <<
|
||||
std::setw(8) << std::setfill('0') << std::hex << objectId << " | " << errorPrint <<
|
||||
std::dec << std::setfill(' ') << std::endl;
|
||||
#else
|
||||
sif::printWarning("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
|
||||
functionName, objectId, errorPrint);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
else if(outputType == sif::OutputTypes::OUT_ERROR) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalDataPoolManager::" << functionName << ": Object ID 0x" <<
|
||||
std::setw(8) << std::setfill('0') << std::hex << objectId << " | " << errorPrint <<
|
||||
std::dec << std::setfill(' ') << std::endl;
|
||||
#else
|
||||
sif::printError("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
|
||||
functionName, objectId, errorPrint);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
#endif /* #if FSFW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
LocalDataPoolManager* LocalDataPoolManager::getPoolManagerHandle() {
|
||||
return this;
|
||||
}
|
@ -1,415 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||
#define FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||
|
||||
#include "ProvidesDataPoolSubscriptionIF.h"
|
||||
#include "AccessLocalPoolF.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../housekeeping/HousekeepingPacketDownlink.h"
|
||||
#include "../housekeeping/HousekeepingMessage.h"
|
||||
#include "../housekeeping/PeriodicHousekeepingHelper.h"
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../ipc/MutexGuard.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace Factory {
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
class LocalPoolDataSetBase;
|
||||
class HousekeepingSnapshot;
|
||||
class HasLocalDataPoolIF;
|
||||
class LocalDataPool;
|
||||
|
||||
/**
|
||||
* @brief This class is the managing instance for the 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 manager class as a member and implement
|
||||
* the HasLocalDataPoolIF.
|
||||
*
|
||||
* The manager offers some adaption points and functions which can be used
|
||||
* by the owning class to simplify data handling significantly.
|
||||
*
|
||||
* Please ensure that both initialize and initializeAfterTaskCreation are
|
||||
* called at some point by the owning class in the respective functions of the
|
||||
* same name!
|
||||
*
|
||||
* 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.
|
||||
* @author R. Mueller
|
||||
*/
|
||||
class LocalDataPoolManager:
|
||||
public ProvidesDataPoolSubscriptionIF,
|
||||
public AccessPoolManagerIF {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
//! Some classes using the pool manager directly need to access class internals of the
|
||||
//! manager. The attorney provides granular control of access to these internals.
|
||||
friend class LocalDpManagerAttorney;
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
|
||||
|
||||
static constexpr ReturnValue_t QUEUE_OR_DESTINATION_INVALID = MAKE_RETURN_CODE(0);
|
||||
static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(1);
|
||||
static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(3);
|
||||
static constexpr ReturnValue_t POOLOBJECT_NOT_FOUND = MAKE_RETURN_CODE(4);
|
||||
static constexpr ReturnValue_t DATASET_NOT_FOUND = MAKE_RETURN_CODE(5);
|
||||
|
||||
|
||||
/**
|
||||
* 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 Specify whether a buffer containing the
|
||||
* validity state is generated when serializing or deserializing packets.
|
||||
*/
|
||||
LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse,
|
||||
bool appendValidityBuffer = true);
|
||||
virtual~ LocalDataPoolManager();
|
||||
|
||||
/**
|
||||
* Assigns the queue to use. Make sure to call this in the #initialize
|
||||
* function of the owner.
|
||||
* @param queueToUse
|
||||
* @param nonDiagInvlFactor See #setNonDiagnosticIntervalFactor doc
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t initialize(MessageQueueIF* queueToUse);
|
||||
|
||||
/**
|
||||
* Initializes the map by calling the map initialization function and
|
||||
* setting the periodic factor for non-diagnostic packets.
|
||||
* Don't forget to call this in the #initializeAfterTaskCreation call of
|
||||
* the owner, otherwise the map will be invalid!
|
||||
* @param nonDiagInvlFactor
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t initializeAfterTaskCreation(
|
||||
uint8_t nonDiagInvlFactor = 5);
|
||||
|
||||
/**
|
||||
* @brief This should be called in the periodic handler of the owner.
|
||||
* @details
|
||||
* This in generally called in the #performOperation function of the owner.
|
||||
* It performs all the periodic functionalities of the data pool manager,
|
||||
* for example generating periodic HK packets.
|
||||
* Marked virtual as an adaption point for custom data pool managers.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t performHkOperation();
|
||||
|
||||
/**
|
||||
* @brief Subscribe for the generation of periodic packets.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used by the data creator
|
||||
* to generate housekeeping packets which are downlinked directly.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting,
|
||||
float collectionInterval, bool isDiagnostics,
|
||||
object_id_t packetDestination = defaultHkDestination) override;
|
||||
|
||||
/**
|
||||
* @brief Subscribe for the generation of packets if the dataset
|
||||
* is marked as changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used by the data creator.
|
||||
* @param sid
|
||||
* @param isDiagnostics
|
||||
* @param packetDestination
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled,
|
||||
bool isDiagnostics,
|
||||
object_id_t packetDestination = defaultHkDestination) override;
|
||||
|
||||
/**
|
||||
* @brief Subscribe for a notification message which will be sent
|
||||
* if a dataset has changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used internally by
|
||||
* other software components.
|
||||
* @param setId Set ID of the set to receive update messages from.
|
||||
* @param destinationObject
|
||||
* @param targetQueueId
|
||||
* @param generateSnapshot If this is set to true, a copy of the current
|
||||
* data with a timestamp will be generated and sent via message.
|
||||
* Otherwise, only an notification message is sent.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId,
|
||||
object_id_t destinationObject,
|
||||
MessageQueueId_t targetQueueId,
|
||||
bool generateSnapshot) override;
|
||||
|
||||
/**
|
||||
* @brief Subscribe for an notification message which will be sent if a
|
||||
* pool variable has changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used internally by
|
||||
* other software components.
|
||||
* @param localPoolId Pool ID of the pool variable
|
||||
* @param destinationObject
|
||||
* @param targetQueueId
|
||||
* @param generateSnapshot If this is set to true, a copy of the current
|
||||
* data with a timestamp will be generated and sent via message.
|
||||
* Otherwise, only an notification message is sent.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId,
|
||||
object_id_t destinationObject,
|
||||
MessageQueueId_t targetQueueId,
|
||||
bool generateSnapshot) override;
|
||||
|
||||
/**
|
||||
* Non-Diagnostics packets usually have a lower minimum sampling frequency
|
||||
* than diagnostic packets.
|
||||
* A factor can be specified to determine the minimum sampling frequency
|
||||
* for non-diagnostic packets. The minimum sampling frequency of the
|
||||
* diagnostics packets,which is usually jusst the period of the
|
||||
* performOperation calls, is multiplied with that factor.
|
||||
* @param factor
|
||||
*/
|
||||
void setNonDiagnosticIntervalFactor(uint8_t nonDiagInvlFactor);
|
||||
|
||||
/**
|
||||
* @brief The manager is also able to handle housekeeping messages.
|
||||
* @details
|
||||
* This most commonly is used to handle messages for the housekeeping
|
||||
* interface, but the manager is also able to handle update notifications
|
||||
* and calls a special function which can be overriden by a child class
|
||||
* to handle data set or pool variable updates. This is relevant
|
||||
* for classes like controllers which have their own local datapool
|
||||
* but pull their data from other local datapools.
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
|
||||
|
||||
/**
|
||||
* Generate a housekeeping packet with a given SID.
|
||||
* @param sid
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t generateHousekeepingPacket(sid_t sid,
|
||||
LocalPoolDataSetBase* dataSet, bool forDownlink,
|
||||
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
|
||||
|
||||
HasLocalDataPoolIF* getOwner();
|
||||
|
||||
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
|
||||
|
||||
/**
|
||||
* Different types of housekeeping reporting are possible.
|
||||
* 1. PERIODIC:
|
||||
* HK packets are generated in fixed intervals and sent to
|
||||
* destination. Fromat will be raw.
|
||||
* 2. UPDATE_NOTIFICATION:
|
||||
* Notification will be sent out if HK data has changed.
|
||||
* 3. UPDATE_SNAPSHOT:
|
||||
* HK packets are only generated if explicitely requested.
|
||||
* Propably not necessary, just use multiple local data sets or
|
||||
* shared datasets.
|
||||
*/
|
||||
enum class ReportingType: uint8_t {
|
||||
//! Periodic generation of HK packets.
|
||||
PERIODIC,
|
||||
//! Housekeeping packet will be generated if values have changed.
|
||||
UPDATE_HK,
|
||||
//! Update notification will be sent out as message.
|
||||
UPDATE_NOTIFICATION,
|
||||
//! Notification will be sent out as message and a snapshot of the
|
||||
//! current data will be generated.
|
||||
UPDATE_SNAPSHOT,
|
||||
};
|
||||
|
||||
/** Different data types are possible in the HK receiver map. For example, updates can be
|
||||
requested for full datasets or for single pool variables. Periodic reporting is only possible
|
||||
for data sets. */
|
||||
enum class DataType: uint8_t {
|
||||
LOCAL_POOL_VARIABLE,
|
||||
DATA_SET
|
||||
};
|
||||
|
||||
/* Copying forbidden */
|
||||
LocalDataPoolManager(const LocalDataPoolManager &) = delete;
|
||||
LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete;
|
||||
|
||||
/**
|
||||
* This function can be used to clear the receivers list. This is
|
||||
* intended for test functions and not for regular operations, because
|
||||
* the insertion operations allocate dynamically.
|
||||
*/
|
||||
void clearReceiversList();
|
||||
|
||||
object_id_t getCreatorObjectId() const;
|
||||
|
||||
/**
|
||||
* Get the pointer to the mutex. Can be used to lock the data pool
|
||||
* externally. Use with care and don't forget to unlock locked mutexes!
|
||||
* For now, only friend classes can accss this function.
|
||||
* @return
|
||||
*/
|
||||
MutexIF* getMutexHandle();
|
||||
|
||||
virtual LocalDataPoolManager* getPoolManagerHandle() override;
|
||||
|
||||
protected:
|
||||
|
||||
/** Core data structure for the actual pool data */
|
||||
localpool::DataPool 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;
|
||||
|
||||
uint8_t nonDiagnosticIntervalFactor = 0;
|
||||
|
||||
/** Default receiver for periodic HK packets */
|
||||
static object_id_t defaultHkDestination;
|
||||
MessageQueueId_t hkDestinationId = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
union DataId {
|
||||
DataId(): sid() {};
|
||||
sid_t sid;
|
||||
lp_id_t localPoolId;
|
||||
};
|
||||
|
||||
/** The data pool manager will keep an internal map of HK receivers. */
|
||||
struct HkReceiver {
|
||||
/** Object ID of receiver */
|
||||
object_id_t objectId = objects::NO_OBJECT;
|
||||
|
||||
DataType dataType = DataType::DATA_SET;
|
||||
DataId dataId;
|
||||
|
||||
ReportingType reportingType = ReportingType::PERIODIC;
|
||||
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
|
||||
};
|
||||
|
||||
/** This vector will contain the list of HK receivers. */
|
||||
using HkReceivers = std::vector<struct HkReceiver>;
|
||||
|
||||
HkReceivers hkReceivers;
|
||||
|
||||
struct HkUpdateResetHelper {
|
||||
DataType dataType = DataType::DATA_SET;
|
||||
DataId dataId;
|
||||
uint8_t updateCounter;
|
||||
uint8_t currentUpdateCounter;
|
||||
};
|
||||
|
||||
using HkUpdateResetList = std::vector<struct HkUpdateResetHelper>;
|
||||
/** This list is used to manage creating multiple update packets and only resetting
|
||||
the update flag if all of them were created. Will only be created when needed. */
|
||||
HkUpdateResetList* hkUpdateResetList = nullptr;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** Global IPC store is used to store all packets. */
|
||||
StorageManagerIF* ipcStore = nullptr;
|
||||
|
||||
/**
|
||||
* 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 classes designated by the LocalDpManagerAttorney may use 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);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
MutexIF* getLocalPoolMutex() override;
|
||||
|
||||
ReturnValue_t serializeHkPacketIntoStore(HousekeepingPacketDownlink& hkPacket,
|
||||
store_address_t& storeId, bool forDownlink, size_t* serializedSize);
|
||||
|
||||
void performPeriodicHkGeneration(HkReceiver& hkReceiver);
|
||||
ReturnValue_t togglePeriodicGeneration(sid_t sid, bool enable, bool isDiagnostics);
|
||||
ReturnValue_t changeCollectionInterval(sid_t sid, float newCollectionInterval,
|
||||
bool isDiagnostics);
|
||||
ReturnValue_t generateSetStructurePacket(sid_t sid, bool isDiagnostics);
|
||||
|
||||
void handleHkUpdateResetListInsertion(DataType dataType, DataId dataId);
|
||||
void handleChangeResetLogic(DataType type,
|
||||
DataId dataId, MarkChangedIF* toReset);
|
||||
void resetHkUpdateResetHelper();
|
||||
|
||||
ReturnValue_t handleHkUpdate(HkReceiver& hkReceiver, ReturnValue_t& status);
|
||||
ReturnValue_t handleNotificationUpdate(HkReceiver& hkReceiver, ReturnValue_t& status);
|
||||
ReturnValue_t handleNotificationSnapshot(HkReceiver& hkReceiver, ReturnValue_t& status);
|
||||
ReturnValue_t addUpdateToStore(HousekeepingSnapshot& updatePacket, store_address_t& storeId);
|
||||
|
||||
void printWarningOrError(sif::OutputTypes outputType, const char* functionName,
|
||||
ReturnValue_t errorCode = HasReturnvaluesIF::RETURN_FAILED,
|
||||
const char* errorPrint = nullptr);
|
||||
};
|
||||
|
||||
|
||||
template<class T> inline
|
||||
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId, PoolEntry<T> **poolEntry) {
|
||||
if(poolEntry == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto poolIter = localPoolMap.find(localPoolId);
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "fetchPoolEntry",
|
||||
localpool::POOL_ENTRY_NOT_FOUND);
|
||||
return localpool::POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
|
||||
if(*poolEntry == nullptr) {
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING, "fetchPoolEntry",
|
||||
localpool::POOL_ENTRY_TYPE_CONFLICT);
|
||||
return localpool::POOL_ENTRY_TYPE_CONFLICT;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ */
|
@ -1,22 +0,0 @@
|
||||
#include "LocalDataSet.h"
|
||||
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner, uint32_t setId,
|
||||
const size_t maxNumberOfVariables):
|
||||
LocalPoolDataSetBase(hkOwner, setId, nullptr, maxNumberOfVariables),
|
||||
poolVarList(maxNumberOfVariables) {
|
||||
this->setContainer(poolVarList.data());
|
||||
}
|
||||
|
||||
LocalDataSet::LocalDataSet(sid_t sid, const size_t maxNumberOfVariables):
|
||||
LocalPoolDataSetBase(sid, nullptr, maxNumberOfVariables),
|
||||
poolVarList(maxNumberOfVariables) {
|
||||
this->setContainer(poolVarList.data());
|
||||
}
|
||||
|
||||
LocalDataSet::~LocalDataSet() {}
|
||||
|
@ -1,323 +0,0 @@
|
||||
#include "LocalPoolDataSetBase.h"
|
||||
#include "HasLocalDataPoolIF.h"
|
||||
#include "internal/HasLocalDpIFUserAttorney.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../globalfunctions/bitutility.h"
|
||||
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||
#include "../housekeeping/PeriodicHousekeepingHelper.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables, bool periodicHandling):
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
if(hkOwner == nullptr) {
|
||||
// Configuration error.
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||
<< "invalid!" << std::endl;
|
||||
#else
|
||||
sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||
"invalid!\n\r");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
return;
|
||||
}
|
||||
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
|
||||
|
||||
if(accessor != nullptr) {
|
||||
poolManager = accessor->getPoolManagerHandle();
|
||||
mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
|
||||
}
|
||||
|
||||
this->sid.objectId = hkOwner->getObjectId();
|
||||
this->sid.ownerSetId = setId;
|
||||
|
||||
/* Data creators get a periodic helper for periodic HK data generation. */
|
||||
if(periodicHandling) {
|
||||
periodicHelper = new PeriodicHousekeepingHelper(this);
|
||||
}
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables):
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||
sid.objectId);
|
||||
if(hkOwner != nullptr) {
|
||||
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
|
||||
if(accessor != nullptr) {
|
||||
mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
|
||||
poolManager = accessor->getPoolManagerHandle();
|
||||
}
|
||||
}
|
||||
|
||||
this->sid = sid;
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase::LocalPoolDataSetBase(PoolVariableIF **registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables, bool protectEveryReadCommitCall):
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
this->setReadCommitProtectionBehaviour(protectEveryReadCommitCall);
|
||||
}
|
||||
|
||||
|
||||
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
||||
/* We only delete objects which were created in the class constructor */
|
||||
if(periodicHelper != nullptr) {
|
||||
delete periodicHelper;
|
||||
}
|
||||
/* In case set was read but not comitted, we commit all variables with an invalid state */
|
||||
if(state == States::STATE_SET_WAS_READ) {
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count] != nullptr) {
|
||||
registeredVariables[count]->setValid(false);
|
||||
registeredVariables[count]->commit(MutexIF::TimeoutType::WAITING, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::lockDataPool(
|
||||
MutexIF::TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
if(mutexIfSingleDataCreator != nullptr) {
|
||||
return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
const uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||
uint8_t* validityPtr = nullptr;
|
||||
#ifdef _MSC_VER
|
||||
/* Use a std::vector here because MSVC will (rightly) not create a fixed size array
|
||||
with a non constant size specifier */
|
||||
std::vector<uint8_t> validityMask(validityMaskSize);
|
||||
validityPtr = validityMask.data();
|
||||
#else
|
||||
uint8_t validityMask[validityMaskSize] = {0};
|
||||
validityPtr = validityMask;
|
||||
#endif
|
||||
uint8_t validBufferIndex = 0;
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count]->isValid()) {
|
||||
/* Set bit at correct position */
|
||||
bitutil::bitSet(validityPtr + 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;
|
||||
}
|
||||
}
|
||||
|
||||
if(*size + validityMaskSize > maxSize) {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
// copy validity buffer to end
|
||||
std::memcpy(*buffer, validityPtr, validityMaskSize);
|
||||
*size += validityMaskSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
|
||||
uint8_t validBufferIndex = 0;
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
// set validity buffer here.
|
||||
bool nextVarValid = bitutil::bitGet(*buffer +
|
||||
validBufferIndex, validBufferIndexBit);
|
||||
registeredVariables[count]->setValid(nextVarValid);
|
||||
|
||||
if(validBufferIndexBit == 7) {
|
||||
validBufferIndex ++;
|
||||
validBufferIndexBit = 0;
|
||||
}
|
||||
else {
|
||||
validBufferIndexBit ++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
||||
if(mutexIfSingleDataCreator != nullptr) {
|
||||
return mutexIfSingleDataCreator->unlockMutex();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness,
|
||||
bool serializeFillCount) const {
|
||||
/* Serialize fill count as uint8_t */
|
||||
uint8_t fillCount = this->fillCount;
|
||||
if(serializeFillCount) {
|
||||
SerializeAdapter::serialize(&fillCount, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
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) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: "
|
||||
<< "Serialization error!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: "
|
||||
"Serialization error!\n\r");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(
|
||||
bool serializeFillCount) const {
|
||||
if(serializeFillCount) {
|
||||
return fillCount * sizeof(lp_id_t) + sizeof(uint8_t);
|
||||
}
|
||||
else {
|
||||
return fillCount * sizeof(lp_id_t);
|
||||
}
|
||||
}
|
||||
|
||||
size_t LocalPoolDataSetBase::getSerializedSize() const {
|
||||
if(withValidityBuffer) {
|
||||
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||
return validityMaskSize + PoolDataSetBase::getSerializedSize();
|
||||
}
|
||||
else {
|
||||
return PoolDataSetBase::getSerializedSize();
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setValidityBufferGeneration(
|
||||
bool withValidityBuffer) {
|
||||
this->withValidityBuffer = withValidityBuffer;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
if(withValidityBuffer) {
|
||||
return this->deSerializeWithValidityBuffer(buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
else {
|
||||
return PoolDataSetBase::deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||
if(withValidityBuffer) {
|
||||
return this->serializeWithValidityBuffer(buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
}
|
||||
else {
|
||||
return PoolDataSetBase::serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) {
|
||||
this->diagnostic = isDiagnostics;
|
||||
}
|
||||
|
||||
bool LocalPoolDataSetBase::isDiagnostics() const {
|
||||
return diagnostic;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) {
|
||||
this->reportingEnabled = reportingEnabled;
|
||||
}
|
||||
|
||||
bool LocalPoolDataSetBase::getReportingEnabled() const {
|
||||
return reportingEnabled;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::initializePeriodicHelper(float collectionInterval,
|
||||
dur_millis_t minimumPeriodicInterval, uint8_t nonDiagIntervalFactor) {
|
||||
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, nonDiagIntervalFactor);
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setChanged(bool changed) {
|
||||
this->changed = changed;
|
||||
}
|
||||
|
||||
bool LocalPoolDataSetBase::hasChanged() const {
|
||||
return changed;
|
||||
}
|
||||
|
||||
sid_t LocalPoolDataSetBase::getSid() const {
|
||||
return sid;
|
||||
}
|
||||
|
||||
bool LocalPoolDataSetBase::isValid() const {
|
||||
return this->valid;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
|
||||
if(setEntriesRecursively) {
|
||||
for(size_t idx = 0; idx < this->getFillCount(); idx++) {
|
||||
registeredVariables[idx]->setValid(valid);
|
||||
}
|
||||
}
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
object_id_t LocalPoolDataSetBase::getCreatorObjectId() {
|
||||
if(poolManager != nullptr) {
|
||||
return poolManager->getCreatorObjectId();
|
||||
}
|
||||
return objects::NO_OBJECT;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setAllVariablesReadOnly() {
|
||||
for(size_t idx = 0; idx < this->getFillCount(); idx++) {
|
||||
registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ);
|
||||
}
|
||||
}
|
||||
|
||||
float LocalPoolDataSetBase::getCollectionInterval() const {
|
||||
if(periodicHelper != nullptr) {
|
||||
return periodicHelper->getCollectionIntervalInSeconds();
|
||||
}
|
||||
else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
|
||||
#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
|
||||
|
||||
#include "MarkChangedIF.h"
|
||||
#include "localPoolDefinitions.h"
|
||||
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapool/PoolDataSetBase.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class LocalDataPoolManager;
|
||||
class HasLocalDataPoolIF;
|
||||
class PeriodicHousekeepingHelper;
|
||||
|
||||
/**
|
||||
* @brief The LocalDataSet class manages a set of locally checked out
|
||||
* variables for local data pools
|
||||
* @details
|
||||
* Extends the PoolDataSetBase class for local data pools by introducing
|
||||
* a validity state, a flag to mark the set as changed, and various other
|
||||
* functions to make it usable by the LocalDataPoolManager class.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Pool variables can be added to the dataset by using the constructor
|
||||
* argument of the pool variable or using the #registerVariable member function.
|
||||
*
|
||||
* An internal state manages usage of this class. Variables may only be
|
||||
* registered before any read call is made, and the commit call can only happen
|
||||
* 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 LocalPoolDataSetBase:
|
||||
public PoolDataSetBase,
|
||||
public MarkChangedIF {
|
||||
friend class LocalPoolDataSetAttorney;
|
||||
friend class PeriodicHousekeepingHelper;
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the creator of local pool data.
|
||||
* @details
|
||||
* This constructor also initializes the components required for
|
||||
* periodic handling.
|
||||
*/
|
||||
LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables, bool periodicHandling = true);
|
||||
|
||||
/**
|
||||
* @brief Constructor for users of the local pool data, which need
|
||||
* to access data created by one HK manager.
|
||||
* @details
|
||||
* Unlike the first constructor, no component for periodic handling
|
||||
* will be initiated.
|
||||
* @param sid Unique identifier of dataset consisting of object ID and
|
||||
* set ID.
|
||||
* @param registeredVariablesArray
|
||||
* @param maxNumberOfVariables
|
||||
*/
|
||||
LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables);
|
||||
|
||||
/**
|
||||
* @brief Simple constructor, if the dataset is not the owner by
|
||||
* a class with a HK manager.
|
||||
* @details
|
||||
* This constructor won't create components required for periodic handling
|
||||
* and it also won't try to deduce the HK manager because no SID is
|
||||
* supplied. This function should therefore be called by classes which need
|
||||
* to access pool variables from different creators.
|
||||
*
|
||||
* If the class is intended to access pool variables from different
|
||||
* creators, the third argument should be set to true. The mutex
|
||||
* properties can be set with #setReadCommitProtectionBehaviour .
|
||||
* @param registeredVariablesArray
|
||||
* @param maxNumberOfVariables
|
||||
* @param protectEveryReadCommitCall If the pool variables are created by
|
||||
* multiple creators, this flag can be set to protect all read and
|
||||
* commit calls separately.
|
||||
*/
|
||||
LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables,
|
||||
bool protectEveryReadCommitCall = true);
|
||||
|
||||
/**
|
||||
* @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".
|
||||
*/
|
||||
~LocalPoolDataSetBase();
|
||||
|
||||
/* The copy constructor and assingment constructor are forbidden for now.
|
||||
The use-cases are limited and the first step would be to implement them properly for the
|
||||
base class */
|
||||
LocalPoolDataSetBase(const LocalPoolDataSetBase& otherSet) = delete;
|
||||
const LocalPoolDataSetBase& operator=(const LocalPoolDataSetBase& otherSet) = delete;
|
||||
|
||||
/**
|
||||
* Helper functions used to set all currently contained variables to read-only.
|
||||
* It is recommended to call this in set constructors intended to be used
|
||||
* by data consumers to prevent accidentally changing pool data.
|
||||
*/
|
||||
void setAllVariablesReadOnly();
|
||||
void setValidityBufferGeneration(bool withValidityBuffer);
|
||||
|
||||
sid_t getSid() const;
|
||||
|
||||
/** SerializeIF overrides */
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const override;
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size,
|
||||
SerializeIF::Endianness streamEndianness) override;
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
/**
|
||||
* 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. (length = ceil(N/8), N = number of pool variables)
|
||||
* @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 deSerializeWithValidityBuffer(const uint8_t** buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness);
|
||||
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness,
|
||||
bool serializeFillCount = true) const;
|
||||
uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const;
|
||||
|
||||
/**
|
||||
* Set the dataset valid or invalid. These calls are mutex protected.
|
||||
* @param setEntriesRecursively
|
||||
* If this is true, all contained datasets will also be set recursively.
|
||||
*/
|
||||
void setValidity(bool valid, bool setEntriesRecursively);
|
||||
bool isValid() const override;
|
||||
|
||||
/**
|
||||
* These calls are mutex protected.
|
||||
* @param changed
|
||||
*/
|
||||
void setChanged(bool changed) override;
|
||||
bool hasChanged() const override;
|
||||
|
||||
object_id_t getCreatorObjectId();
|
||||
|
||||
bool getReportingEnabled() const;
|
||||
|
||||
/**
|
||||
* Returns the current periodic HK generation interval this set
|
||||
* belongs to a HK manager and the interval is not 0. Otherwise,
|
||||
* returns 0.0
|
||||
* @return
|
||||
*/
|
||||
float getCollectionInterval() const;
|
||||
|
||||
protected:
|
||||
sid_t sid;
|
||||
//! This mutex is used if the data is created by one object only.
|
||||
MutexIF* mutexIfSingleDataCreator = nullptr;
|
||||
|
||||
bool diagnostic = false;
|
||||
void setDiagnostic(bool diagnostics);
|
||||
bool isDiagnostics() const;
|
||||
|
||||
/**
|
||||
* Used for periodic generation.
|
||||
*/
|
||||
bool reportingEnabled = false;
|
||||
void setReportingEnabled(bool enabled);
|
||||
|
||||
void initializePeriodicHelper(float collectionInterval, dur_millis_t minimumPeriodicInterval,
|
||||
uint8_t nonDiagIntervalFactor = 5);
|
||||
|
||||
/**
|
||||
* If the valid state of a dataset is always relevant to the whole
|
||||
* data set we can use this flag.
|
||||
*/
|
||||
bool valid = false;
|
||||
|
||||
/**
|
||||
* Can be used to mark the dataset as changed, which is used
|
||||
* by the LocalDataPoolManager to send out update messages.
|
||||
*/
|
||||
bool changed = false;
|
||||
|
||||
/**
|
||||
* Specify whether the validity buffer is serialized too when serializing
|
||||
* or deserializing the packet. Each bit of the validity buffer will
|
||||
* contain the validity state of the pool variables from left to right.
|
||||
* The size of validity buffer thus will be ceil(N / 8) with N = number of
|
||||
* pool variables.
|
||||
*/
|
||||
bool withValidityBuffer = true;
|
||||
|
||||
/**
|
||||
* @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(MutexIF::TimeoutType timeoutType,
|
||||
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;
|
||||
|
||||
PeriodicHousekeepingHelper* periodicHelper = nullptr;
|
||||
LocalDataPoolManager* poolManager = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ */
|
@ -1,141 +0,0 @@
|
||||
#include "LocalPoolObjectBase.h"
|
||||
#include "LocalDataPoolManager.h"
|
||||
#include "AccessLocalPoolF.h"
|
||||
#include "HasLocalDataPoolIF.h"
|
||||
#include "internal/HasLocalDpIFUserAttorney.h"
|
||||
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
|
||||
LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
|
||||
DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
|
||||
localPoolId(poolId), readWriteMode(setReadWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
||||
<< "which is the NO_PARAMETER value!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
if(hkOwner == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPoolVar<T>::LocalPoolVar: The supplied pool "
|
||||
<< "owner is a invalid!" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
|
||||
hkManager = poolManAccessor->getPoolManagerHandle();
|
||||
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet,
|
||||
pool_rwm_t setReadWriteMode):
|
||||
localPoolId(poolId), readWriteMode(setReadWriteMode) {
|
||||
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
||||
"which is the NO_PARAMETER value!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
||||
"which is the NO_PARAMETER value!\n");
|
||||
#endif
|
||||
}
|
||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(poolOwner);
|
||||
if(hkOwner == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPoolVariable: The supplied pool owner did not implement the correct "
|
||||
"interface HasLocalDataPoolIF!" << std::endl;
|
||||
#else
|
||||
sif::printError( "LocalPoolVariable: The supplied pool owner did not implement the correct "
|
||||
"interface HasLocalDataPoolIF!\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
|
||||
if(accessor != nullptr) {
|
||||
hkManager = accessor->getPoolManagerHandle();
|
||||
}
|
||||
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
bool LocalPoolObjectBase::isValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
void LocalPoolObjectBase::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
lp_id_t LocalPoolObjectBase::getDataPoolId() const {
|
||||
return localPoolId;
|
||||
}
|
||||
|
||||
void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) {
|
||||
this->localPoolId = poolId;
|
||||
}
|
||||
|
||||
void LocalPoolObjectBase::setChanged(bool changed) {
|
||||
this->changed = changed;
|
||||
}
|
||||
|
||||
bool LocalPoolObjectBase::hasChanged() const {
|
||||
return changed;
|
||||
}
|
||||
|
||||
void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) {
|
||||
this->readWriteMode = newReadWriteMode;
|
||||
}
|
||||
|
||||
void LocalPoolObjectBase::reportReadCommitError(const char* variableType,
|
||||
ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId) {
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
const char* variablePrintout = variableType;
|
||||
if(variablePrintout == nullptr) {
|
||||
variablePrintout = "Unknown Type";
|
||||
}
|
||||
const char* type = nullptr;
|
||||
if(read) {
|
||||
type = "read";
|
||||
}
|
||||
else {
|
||||
type = "commit";
|
||||
}
|
||||
|
||||
const char* errMsg = nullptr;
|
||||
if(error == localpool::POOL_ENTRY_NOT_FOUND) {
|
||||
errMsg = "Pool entry not found";
|
||||
}
|
||||
else if(error == localpool::POOL_ENTRY_TYPE_CONFLICT) {
|
||||
errMsg = "Pool entry type conflict";
|
||||
}
|
||||
else if(error == PoolVariableIF::INVALID_READ_WRITE_MODE) {
|
||||
errMsg = "Pool variable wrong read-write mode";
|
||||
}
|
||||
else if(error == PoolVariableIF::INVALID_POOL_ENTRY) {
|
||||
errMsg = "Pool entry invalid";
|
||||
}
|
||||
else {
|
||||
errMsg = "Unknown error code";
|
||||
}
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << variablePrintout << ": " << type << " call | " << errMsg << " | Owner: 0x"
|
||||
<< std::hex << std::setw(8) << std::setfill('0') << objectId << std::dec
|
||||
<< " LPID: " << lpId << std::endl;
|
||||
#else
|
||||
sif::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n",
|
||||
variablePrintout, type, errMsg, objectId, lpId);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
|
||||
#define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
|
||||
|
||||
#include "MarkChangedIF.h"
|
||||
#include "localPoolDefinitions.h"
|
||||
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class LocalDataPoolManager;
|
||||
class DataSetIF;
|
||||
class HasLocalDataPoolIF;
|
||||
|
||||
/**
|
||||
* @brief This class serves as a non-template base for pool objects like pool variables
|
||||
* or pool vectors.
|
||||
*/
|
||||
class LocalPoolObjectBase: public PoolVariableIF,
|
||||
public HasReturnvaluesIF,
|
||||
public MarkChangedIF {
|
||||
public:
|
||||
LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet,
|
||||
pool_rwm_t setReadWriteMode);
|
||||
|
||||
LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
|
||||
void setReadWriteMode(pool_rwm_t newReadWriteMode);
|
||||
pool_rwm_t getReadWriteMode() const;
|
||||
|
||||
bool isValid() const override;
|
||||
void setValid(bool valid) override;
|
||||
|
||||
void setChanged(bool changed) override;
|
||||
bool hasChanged() const override;
|
||||
|
||||
lp_id_t getDataPoolId() const override;
|
||||
void setDataPoolId(lp_id_t poolId);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool id is stored.
|
||||
*/
|
||||
uint32_t localPoolId = PoolVariableIF::NO_PARAMETER;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool
|
||||
* is copied to this attribute.
|
||||
*/
|
||||
bool valid = false;
|
||||
|
||||
/**
|
||||
* @brief A local pool variable can be marked as changed.
|
||||
*/
|
||||
bool changed = false;
|
||||
|
||||
/**
|
||||
* @brief The information whether the class is read-write or
|
||||
* read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode = pool_rwm_t::VAR_READ_WRITE;
|
||||
|
||||
//! @brief Pointer to the class which manages the HK pool.
|
||||
LocalDataPoolManager* hkManager = nullptr;
|
||||
|
||||
void reportReadCommitError(const char* variableType,
|
||||
ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId);
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */
|
@ -1,203 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||
|
||||
#include "LocalPoolObjectBase.h"
|
||||
#include "HasLocalDataPoolIF.h"
|
||||
#include "LocalDataPoolManager.h"
|
||||
#include "AccessLocalPoolF.h"
|
||||
#include "internal/LocalDpManagerAttorney.h"
|
||||
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../serviceinterface/ServiceInterface.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../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 LocalPoolVariable: public LocalPoolObjectBase {
|
||||
public:
|
||||
//! Default ctor is forbidden.
|
||||
LocalPoolVariable() = 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 dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
*/
|
||||
LocalPoolVariable(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
|
||||
DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
|
||||
/**
|
||||
* 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 dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
*
|
||||
*/
|
||||
LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId,
|
||||
DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
/**
|
||||
* Variation which takes the global unique identifier of a pool variable.
|
||||
* @param globalPoolId
|
||||
* @param dataSet
|
||||
* @param setReadWriteMode
|
||||
*/
|
||||
LocalPoolVariable(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
|
||||
virtual~ LocalPoolVariable() {};
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
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(MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) 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(MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) override;
|
||||
|
||||
/**
|
||||
* @brief This commit function can be used to set the pool variable valid
|
||||
* as well.
|
||||
* @param setValid
|
||||
* @param timeoutType
|
||||
* @param timeoutMs
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t commit(bool setValid, MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20);
|
||||
|
||||
LocalPoolVariable<T> &operator=(const T& newValue);
|
||||
LocalPoolVariable<T> &operator=(const LocalPoolVariable<T>& newPoolVariable);
|
||||
|
||||
//! Explicit type conversion operator. Allows casting the class to
|
||||
//! its template type to perform operations on value.
|
||||
explicit operator T() const;
|
||||
|
||||
bool operator==(const LocalPoolVariable<T>& other) const;
|
||||
bool operator==(const T& other) const;
|
||||
|
||||
bool operator!=(const LocalPoolVariable<T>& other) const;
|
||||
bool operator!=(const T& other) const;
|
||||
|
||||
bool operator<(const LocalPoolVariable<T>& other) const;
|
||||
bool operator<(const T& other) const;
|
||||
|
||||
bool operator>(const LocalPoolVariable<T>& other) const;
|
||||
bool operator>(const T& other) const;
|
||||
|
||||
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;
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// std::ostream is the type for object std::cout
|
||||
template <typename U>
|
||||
friend std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVariable<U> &var);
|
||||
#endif
|
||||
};
|
||||
|
||||
#include "LocalPoolVariable.tpp"
|
||||
|
||||
template<class T>
|
||||
using lp_var_t = LocalPoolVariable<T>;
|
||||
|
||||
using lp_bool_t = LocalPoolVariable<uint8_t>;
|
||||
using lp_uint8_t = LocalPoolVariable<uint8_t>;
|
||||
using lp_uint16_t = LocalPoolVariable<uint16_t>;
|
||||
using lp_uint32_t = LocalPoolVariable<uint32_t>;
|
||||
using lp_uint64_t = LocalPoolVariable<uint64_t>;
|
||||
using lp_int8_t = LocalPoolVariable<int8_t>;
|
||||
using lp_int16_t = LocalPoolVariable<int16_t>;
|
||||
using lp_int32_t = LocalPoolVariable<int32_t>;
|
||||
using lp_int64_t = LocalPoolVariable<int64_t>;
|
||||
using lp_float_t = LocalPoolVariable<float>;
|
||||
using lp_double_t = LocalPoolVariable<double>;
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */
|
@ -1,188 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||
|
||||
#include "LocalPoolObjectBase.h"
|
||||
#include "internal/LocalDpManagerAttorney.h"
|
||||
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterface.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 LocalPoolObjectBase {
|
||||
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(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
|
||||
DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
|
||||
/**
|
||||
* 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(object_id_t poolOwner, lp_id_t poolId,
|
||||
DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
/**
|
||||
* Variation which takes the unique global identifier of a local pool
|
||||
* vector.
|
||||
* @param globalPoolId
|
||||
* @param dataSet
|
||||
* @param setReadWriteMode
|
||||
*/
|
||||
LocalPoolVector(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr,
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
T& operator [](size_t i);
|
||||
const T &operator [](size_t 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(MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) 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(MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) override;
|
||||
|
||||
/**
|
||||
* @brief This commit call also sets the validity of the pool entry.
|
||||
* @details
|
||||
*/
|
||||
ReturnValue_t commit(bool valid, MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20);
|
||||
|
||||
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:
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// 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);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#include "LocalPoolVector.tpp"
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
using lp_vec_t = LocalPoolVector<T, vectorSize>;
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ */
|
@ -1,70 +0,0 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_
|
||||
#define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_
|
||||
|
||||
#include "localPoolDefinitions.h"
|
||||
#include "../ipc/messageQueueDefinitions.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
|
||||
class ProvidesDataPoolSubscriptionIF {
|
||||
public:
|
||||
virtual ~ProvidesDataPoolSubscriptionIF(){};
|
||||
|
||||
/**
|
||||
* @brief Subscribe for the generation of periodic packets.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used by the data creator
|
||||
* to generate housekeeping packets which are downlinked directly.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting,
|
||||
float collectionInterval, bool isDiagnostics, object_id_t packetDestination) = 0;
|
||||
/**
|
||||
* @brief Subscribe for the generation of packets if the dataset
|
||||
* is marked as changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used by the data creator.
|
||||
* @param sid
|
||||
* @param isDiagnostics
|
||||
* @param packetDestination
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled,
|
||||
bool isDiagnostics, object_id_t packetDestination) = 0;
|
||||
/**
|
||||
* @brief Subscribe for a notification message which will be sent
|
||||
* if a dataset has changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used internally by
|
||||
* other software components.
|
||||
* @param setId Set ID of the set to receive update messages from.
|
||||
* @param destinationObject Object ID of the receiver.
|
||||
* @param targetQueueId Receiver queue ID
|
||||
* @param generateSnapshot If this is set to true, a copy of the current data with a
|
||||
* timestamp will be generated and sent via message.
|
||||
* Otherwise, only an notification message is sent.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId,
|
||||
object_id_t destinationObject, MessageQueueId_t targetQueueId,
|
||||
bool generateSnapshot) = 0;
|
||||
/**
|
||||
* @brief Subscribe for an notification message which will be sent if a
|
||||
* pool variable has changed.
|
||||
* @details
|
||||
* This subscription mechanism will generally be used internally by
|
||||
* other software components.
|
||||
* @param localPoolId Pool ID of the pool variable
|
||||
* @param destinationObject Object ID of the receiver
|
||||
* @param targetQueueId Receiver queue ID
|
||||
* @param generateSnapshot If this is set to true, a copy of the current data with a
|
||||
* timestamp will be generated and sent via message. Otherwise,
|
||||
* only an notification message is sent.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId,
|
||||
object_id_t destinationObject, MessageQueueId_t targetQueueId,
|
||||
bool generateSnapshot) = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user