mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 19:00:34 +08:00
orb structs: add padding bytes to align the structs where necessary
This is required for the logger, we just manually add the padding bytes what would otherwise be done by the compiler. Additionally we reorder the fields by type, so that padding is only necessary for nested types.
This commit is contained in:
+5
-12
@@ -46,21 +46,14 @@
|
||||
// Hack until everything is using this header
|
||||
#include <systemlib/visibility.h>
|
||||
|
||||
struct orb_output_buffer {
|
||||
void *data;
|
||||
size_t next;
|
||||
};
|
||||
|
||||
typedef void (*func_ptr)(void *in, struct orb_output_buffer *out);
|
||||
|
||||
/**
|
||||
* Object metadata.
|
||||
*/
|
||||
struct orb_metadata {
|
||||
const char *o_name; /**< unique object name */
|
||||
const size_t o_size; /**< object size */
|
||||
func_ptr serialize; /**< serialization function for this orb topic */
|
||||
const char *o_fields; /**< semicolon separated list of fields */
|
||||
const size_t o_size_no_padding; /**< object size w/o padding at the end (for logger) */
|
||||
const char *o_fields; /**< semicolon separated list of fields (with type) */
|
||||
};
|
||||
|
||||
typedef const struct orb_metadata *orb_id_t;
|
||||
@@ -119,14 +112,14 @@ enum ORB_PRIO {
|
||||
*
|
||||
* @param _name The name of the topic.
|
||||
* @param _struct The structure the topic provides.
|
||||
* @param _func The pointer to a function that serializes this topic
|
||||
* @param _size_no_padding Struct size w/o padding at the end
|
||||
* @param _fields All fields in a semicolon separated list e.g: "float[3] position;bool armed"
|
||||
*/
|
||||
#define ORB_DEFINE(_name, _struct, _func, _fields) \
|
||||
#define ORB_DEFINE(_name, _struct, _size_no_padding, _fields) \
|
||||
const struct orb_metadata __orb_##_name = { \
|
||||
#_name, \
|
||||
sizeof(_struct), \
|
||||
_func, \
|
||||
_size_no_padding, \
|
||||
_fields \
|
||||
}; struct hack
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ struct orb_test {
|
||||
int val;
|
||||
hrt_abstime time;
|
||||
};
|
||||
ORB_DEFINE(orb_test, struct orb_test, nullptr, "ORB_TEST:int val;hrt_abstime time;");
|
||||
ORB_DEFINE(orb_multitest, struct orb_test, nullptr, "ORB_MULTITEST:int val;hrt_abstime time;");
|
||||
ORB_DEFINE(orb_test, struct orb_test, sizeof(orb_test), "ORB_TEST:int val;hrt_abstime time;");
|
||||
ORB_DEFINE(orb_multitest, struct orb_test, sizeof(orb_test), "ORB_MULTITEST:int val;hrt_abstime time;");
|
||||
|
||||
|
||||
struct orb_test_medium {
|
||||
@@ -50,9 +50,10 @@ struct orb_test_medium {
|
||||
hrt_abstime time;
|
||||
char junk[64];
|
||||
};
|
||||
ORB_DEFINE(orb_test_medium, struct orb_test_medium, nullptr, "ORB_TEST_MEDIUM:int val;hrt_abstime time;char[64] junk;");
|
||||
ORB_DEFINE(orb_test_medium_multi, struct orb_test_medium, nullptr,
|
||||
"ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;");
|
||||
ORB_DEFINE(orb_test_medium, struct orb_test_medium, sizeof(orb_test_medium),
|
||||
"ORB_TEST_MEDIUM:int val;hrt_abstime time;char[64] junk;");
|
||||
ORB_DEFINE(orb_test_medium_multi, struct orb_test_medium, sizeof(orb_test_medium),
|
||||
"ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;");
|
||||
|
||||
|
||||
struct orb_test_large {
|
||||
@@ -60,7 +61,8 @@ struct orb_test_large {
|
||||
hrt_abstime time;
|
||||
char junk[512];
|
||||
};
|
||||
ORB_DEFINE(orb_test_large, struct orb_test_large, nullptr, "ORB_TEST_LARGE:int val;hrt_abstime time;char[512] junk;");
|
||||
ORB_DEFINE(orb_test_large, struct orb_test_large, sizeof(orb_test_large),
|
||||
"ORB_TEST_LARGE:int val;hrt_abstime time;char[512] junk;");
|
||||
|
||||
|
||||
namespace uORBTest
|
||||
|
||||
Reference in New Issue
Block a user