diff --git a/include/param/param.h b/include/param/param.h index dfc872f..4b31782 100644 --- a/include/param/param.h +++ b/include/param/param.h @@ -86,6 +86,12 @@ typedef enum { #define PM_CSP (5 << 16) //! Known as 5 in elfparse and genparamtable #define PM_KEYCONF (6 << 16) //! Known as 6 in elfparse and genparamtable +/** + * Value to indicate an invalid nsec. + * + * This define should be moved to CSP if CSP will have support for invalid nsec + */ +#define CSP_TIMESTAMP_INVALID_NSEC -1 /** * Parameter description structure @@ -140,7 +146,7 @@ typedef struct param_s { #ifdef PARAM_HAVE_TIMESTAMP #define PARAM_TIMESTAMP_DECL(_name) \ - csp_timestamp_t _timestamp_##_name = { .tv_sec = 0, .tv_nsec = 0 }; + csp_timestamp_t _timestamp_##_name = { .tv_sec = 0, .tv_nsec = CSP_TIMESTAMP_INVALID_NSEC }; #define PARAM_TIMESTAMP_INIT(_name) \ .timestamp = &_timestamp_##_name, diff --git a/meson.build b/meson.build index 320bb9d..588bd48 100644 --- a/meson.build +++ b/meson.build @@ -24,6 +24,10 @@ if get_option('have_float') == false conf.set('MPACK_FLOAT', 0) endif +if get_option('serialize_extended_timestamp') == true + conf.set('EXTENDED_TIMESTAMP', 0) +endif + if get_option('have_fopen') == true if get_option('list_dynamic') == true conf.set('MPACK_STDIO', 1) diff --git a/meson_options.txt b/meson_options.txt index a1c5765..ff408a3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -6,4 +6,6 @@ option('list_dynamic', type: 'boolean', value: false, description: 'Compile supp option('list_pool', type: 'integer', value: 0, description: 'Compile support for pre-allocated param list (requres sys/queue.h)') option('have_float', type: 'boolean', value: true, description: 'Support float/double') option('num_publishqueues', type: 'integer', value: 0, description: 'Number of param publish queues required') +option('serialize_extended_timestamp', type: 'boolean', value: false, description: 'Include ns part of timestamps when serializing parameters (network incompatible with libparam older than June 2025') option('test', type: 'boolean', value: false, description: 'Build GoogleTest based tests (requires gtest)') + diff --git a/src/param/param_serializer.c b/src/param/param_serializer.c index 8a42751..24aad67 100644 --- a/src/param/param_serializer.c +++ b/src/param/param_serializer.c @@ -70,14 +70,20 @@ void param_serialize_id(mpack_writer_t *writer, param_t *param, int offset, para int node_flag = (queue->last_node != node) ? 1 : 0; #ifdef PARAM_HAVE_TIMESTAMP int timestamp_flag = (queue->last_timestamp.tv_sec != param->timestamp->tv_sec) ? 1 : 0; + int extendedtimestamp_flag = 0; +#ifdef EXTENDED_TIMESTAMP + extendedtimestamp_flag = (queue->last_timestamp.tv_nsec != param->timestamp->tv_nsec) ? 1 : 0; +#endif /* EXTENDED_TIMESTAMP */ #else int timestamp_flag = 0; + int extendedtimestamp_flag = 0; #endif int extendedid_flag = (param->id > 0x3ff) ? 1 : 0; - uint16_t header = array_flag << PARAM_HEADER_ARRAY_POS + uint16_t header = array_flag << PARAM_HEADER_ARRAY_POS | node_flag << PARAM_HEADER_NODE_POS | timestamp_flag << PARAM_HEADER_TIMESTAMP_POS + | extendedtimestamp_flag << PARAM_HEADER_EXTENDEDTIMESTAMP_POS | extendedid_flag << PARAM_HEADER_EXTENDEDID_POS |(param->id & PARAM_HEADER_ID_MASK); header = htobe16(header); @@ -100,6 +106,12 @@ void param_serialize_id(mpack_writer_t *writer, param_t *param, int offset, para uint32_t _timestamp = htobe32(param->timestamp->tv_sec); mpack_write_bytes(writer, (char*) &_timestamp, 4); } + + if (extendedtimestamp_flag) { + queue->last_timestamp.tv_nsec = param->timestamp->tv_nsec; + uint32_t _timestamp_ns = htobe32(param->timestamp->tv_nsec); + mpack_write_bytes(writer, (char*) &_timestamp_ns, 4); + } #endif if (extendedid_flag) { @@ -168,19 +180,14 @@ void param_deserialize_id(mpack_reader_t *reader, int *id, int *node, csp_timest queue->last_timestamp = queue->client_timestamp; } else { queue->last_timestamp.tv_sec = _timestamp; - if (extendedtimestamp_flag) { - uint32_t _timestamp_ns; - mpack_read_bytes(reader, (char*) &_timestamp_ns, 4); - _timestamp_ns = be32toh(_timestamp_ns); - queue->last_timestamp.tv_nsec = _timestamp_ns; - } else { - queue->last_timestamp.tv_nsec = 0; - } } - } else if (extendedtimestamp_flag) { - /* Invalid header combination, discard header field */ + } + + if (extendedtimestamp_flag) { uint32_t _timestamp_ns; mpack_read_bytes(reader, (char*) &_timestamp_ns, 4); + _timestamp_ns = be32toh(_timestamp_ns); + queue->last_timestamp.tv_nsec = _timestamp_ns; } *timestamp = queue->last_timestamp;