Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/param/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ 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)')
29 changes: 18 additions & 11 deletions src/param/param_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
Loading