1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

protobuf: Add support for new frame flag

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel 2024-03-26 11:35:21 +01:00 committed by pipeacosta
parent 05b979049d
commit 785fe651c2
2 changed files with 40 additions and 29 deletions

View file

@ -66,14 +66,14 @@ int ProtobufFormat::sprint(char *buf, size_t len, size_t *wbytes,
}
if (flags & smp->flags & (int)SampleFlags::HAS_TS_ORIGIN) {
pb_smp->timestamp = new Villas__Node__Timestamp;
if (!pb_smp->timestamp)
pb_smp->ts_origin = new Villas__Node__Timestamp;
if (!pb_smp->ts_origin)
throw MemoryAllocationError();
villas__node__timestamp__init(pb_smp->timestamp);
villas__node__timestamp__init(pb_smp->ts_origin);
pb_smp->timestamp->sec = smp->ts.origin.tv_sec;
pb_smp->timestamp->nsec = smp->ts.origin.tv_nsec;
pb_smp->ts_origin->sec = smp->ts.origin.tv_sec;
pb_smp->ts_origin->nsec = smp->ts.origin.tv_nsec;
}
pb_smp->n_values = smp->length;
@ -81,6 +81,11 @@ int ProtobufFormat::sprint(char *buf, size_t len, size_t *wbytes,
if (!pb_smp->values)
throw MemoryAllocationError();
if (smp->flags & (int)SampleFlags::NEW_FRAME) {
pb_smp->has_new_frame = 1;
pb_smp->new_frame = 1;
}
for (unsigned j = 0; j < pb_smp->n_values; j++) {
Villas__Node__Value *pb_val = pb_smp->values[j] = new Villas__Node__Value;
if (!pb_val)
@ -161,15 +166,19 @@ int ProtobufFormat::sscan(const char *buf, size_t len, size_t *rbytes,
if (pb_smp->type != VILLAS__NODE__SAMPLE__TYPE__DATA)
throw RuntimeError("Parsed non supported message type. Skipping");
if (pb_smp->has_new_frame && pb_smp->new_frame) {
smp->flags |= (int)SampleFlags::NEW_FRAME;
}
if (pb_smp->has_sequence) {
smp->flags |= (int)SampleFlags::HAS_SEQUENCE;
smp->sequence = pb_smp->sequence;
}
if (pb_smp->timestamp) {
if (pb_smp->ts_origin) {
smp->flags |= (int)SampleFlags::HAS_TS_ORIGIN;
smp->ts.origin.tv_sec = pb_smp->timestamp->sec;
smp->ts.origin.tv_nsec = pb_smp->timestamp->nsec;
smp->ts.origin.tv_sec = pb_smp->ts_origin->sec;
smp->ts.origin.tv_nsec = pb_smp->ts_origin->nsec;
}
for (j = 0; j < MIN(pb_smp->n_values, smp->capacity); j++) {
@ -229,5 +238,6 @@ static char d[] = "Google Protobuf";
static FormatPlugin<ProtobufFormat, n, d,
(int)SampleFlags::HAS_TS_ORIGIN |
(int)SampleFlags::HAS_SEQUENCE |
(int)SampleFlags::HAS_DATA>
(int)SampleFlags::HAS_DATA |
(int)SampleFlags::NEW_FRAME>
p;

View file

@ -10,37 +10,38 @@ syntax = "proto2";
package villas.node;
message Message {
repeated Sample samples = 1;
repeated Sample samples = 1;
}
message Sample {
enum Type {
DATA = 1; // Message contains float / integer data values
START = 2; // Message marks the beginning of a new simulation case
STOP = 3; // Message marks the end of a simulation case
};
enum Type {
DATA = 1; // Message contains float / integer data values
START = 2; // Message marks the beginning of a new simulation case
STOP = 3; // Message marks the end of a simulation case
};
required Type type = 1 [default = DATA];
optional uint64 sequence = 2; // The sequence number is incremented by one for consecutive messages.
optional Timestamp timestamp = 4;
repeated Value values = 5;
required Type type = 1 [default = DATA];
optional uint64 sequence = 2; // The sequence number is incremented for consecutive samples.
optional Timestamp ts_origin = 4;
repeated Value values = 5;
optional bool new_frame = 6;
}
message Timestamp {
required uint32 sec = 1; // Seconds since 1970-01-01 00:00:00
required uint32 nsec = 2; // Nanoseconds of the current second.
required uint32 sec = 1; // Seconds since 1970-01-01 00:00:00
required uint32 nsec = 2; // Nanoseconds of the current second.
}
message Value {
oneof value {
double f = 1; // Floating point values.
int64 i = 2; // Integer values.
bool b = 3; // Boolean values.
Complex z = 4; // Complex values.
}
oneof value {
double f = 1; // Floating point values.
int64 i = 2; // Integer values.
bool b = 3; // Boolean values.
Complex z = 4; // Complex values.
}
}
message Complex {
required float real = 1; // Real component
required float imag = 2; // Imaginary component
required float real = 1; // Real component
required float imag = 2; // Imaginary component
}