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

update format style

This commit is contained in:
Manuel Pitz 2021-10-04 20:58:06 +02:00 committed by Steffen Vogel
parent 1934766664
commit d91f9233d4

View file

@ -30,30 +30,41 @@ using namespace villas::node;
int JsonEdgeflexFormat::packSample(json_t **json_smp, const struct sample *smp)
{
json_error_t err;
json_t *json_root;
json_t *json_value;
json_t *json_data;
json_t *json_created = nullptr;
if (smp->length < 1)
return -1;
struct signal *sig = (struct signal *) vlist_at_safe(smp->signals, 0);
if (!sig)
return -1;
if (sig->type != SignalType::FLOAT)
return -1;
json_data = json_array();
json_value = json_pack_ex(&err, 0, "{ s: f }",
"value", smp->data[0].f
);
if (json_value == nullptr)
return -1;
for (unsigned i = 0; i < smp->length; i++) {
struct signal *sig = (struct signal *) vlist_at_safe(smp->signals, i);
if (!sig)
return -1;
json_value = json_pack_ex(&err, 0, "{ s: f }",
sig->name, smp->data[i].f
);
json_array_append_new(json_data, json_value);
}
if (smp->flags & (int) SampleFlags::HAS_TS_ORIGIN) {
json_t *json_created = json_integer(time_to_double(&smp->ts.origin) * 1e3);
json_created = json_integer(time_to_double(&smp->ts.origin) * 1e3);
json_object_set_new(json_value, "created", json_created);
}
*json_smp = json_value;
json_root = json_pack_ex(&err, 0, "{ s: o }",
"measurement", json_data
);
if (json_root == nullptr)
return -1;
*json_smp = json_root;
return 0;
}