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

sample: remove format field

This commit is contained in:
Steffen Vogel 2018-08-01 17:00:32 +02:00
parent 36c3161fa8
commit 10c02766f5
2 changed files with 4 additions and 52 deletions

View file

@ -47,22 +47,15 @@ struct pool;
/** The offset to the beginning of the data section. */
#define SAMPLE_DATA_OFFSET(smp) ((char *) (smp) + offsetof(struct sample, data))
enum sample_data_format {
SAMPLE_DATA_FORMAT_FLOAT = 0,
SAMPLE_DATA_FORMAT_INT = 1
};
/** Parts of a sample that can be serialized / de-serialized by the IO formats */
enum sample_flags {
SAMPLE_HAS_ORIGIN = (1 << 0), /**< Include origin timestamp in output. */
SAMPLE_HAS_RECEIVED = (1 << 1), /**< Include receive timestamp in output. */
SAMPLE_HAS_OFFSET = (1 << 2), /**< Include offset (received - origin timestamp) in output. */
SAMPLE_HAS_SOURCE = (1 << 3), /**< This sample has a valid sample::source field. */
SAMPLE_HAS_ID = (1 << 4), /**< This sample has a valid sample::id field. */
SAMPLE_HAS_SEQUENCE = (1 << 5), /**< Include sequence number in output. */
SAMPLE_HAS_VALUES = (1 << 6), /**< Include values in output. */
SAMPLE_HAS_FORMAT = (1 << 7), /**< This sample has a valid sample::format field. */
SAMPLE_HAS_ALL = (1 << 7) - 1, /**< Enable all output options. */
SAMPLE_HAS_ID = (1 << 3), /**< This sample has a valid sample::id field. */
SAMPLE_HAS_SEQUENCE = (1 << 4), /**< Include sequence number in output. */
SAMPLE_HAS_VALUES = (1 << 5), /**< Include values in output. */
SAMPLE_HAS_ALL = (1 << 5) - 1, /**< Enable all output options. */
SAMPLE_IS_FIRST = (1 << 16), /**< This sample is the first of a new simulation case */
SAMPLE_IS_LAST = (1 << 17), /**< This sample is the last of a running simulation case */
@ -84,12 +77,6 @@ struct sample {
atomic_int refcnt; /**< Reference counter. */
ptrdiff_t pool_off; /**< This sample belongs to this memory pool (relative pointer). See sample_pool(). */
/** A long bitfield indicating the number representation of the first 64 values in sample::data[].
*
* @see sample_data_format
*/
uint64_t format;
/** All timestamps are seconds / nano seconds after 1.1.1970 UTC */
struct {
struct timespec origin; /**< The point in time when this data was sampled. */
@ -141,12 +128,6 @@ int sample_copy_many(struct sample *dsts[], struct sample *srcs[], int cnt);
int sample_get_many(struct sample *smps[], int cnt);
int sample_put_many(struct sample *smps[], int cnt);
/** Get number representation for a single value of a sample. */
int sample_get_data_format(struct sample *s, int idx);
/** Set number representation for a single value of a sample. */
int sample_set_data_format(struct sample *s, int idx, enum sample_data_format fmt);
#ifdef __cplusplus
}
#endif

View file

@ -34,7 +34,6 @@ int sample_init(struct sample *s)
struct pool *p = sample_pool(s);
s->length = 0;
s->format = 0; /* all sample values are float by default */
s->capacity = (p->blocksz - sizeof(struct sample)) / sizeof(s->data[0]);
s->refcnt = ATOMIC_VAR_INIT(1);
@ -69,7 +68,6 @@ struct sample * sample_alloc_mem(int capacity)
s->pool_off = SAMPLE_NON_POOL;
s->length = 0;
s->format = 0; /* all sample values are float by default */
s->capacity = capacity;
s->refcnt = ATOMIC_VAR_INIT(1);
@ -150,7 +148,6 @@ int sample_copy(struct sample *dst, struct sample *src)
dst->length = MIN(src->length, dst->capacity);
dst->sequence = src->sequence;
dst->format = src->format;
dst->source = src->source;
dst->flags = src->flags;
dst->ts = src->ts;
@ -235,11 +232,6 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags)
return 4;
}
if (a->format != b->format) {
printf("format: %#" PRIx64 " != %#" PRIx64 "\n", a->format, b->format);
return 6;
}
for (int i = 0; i < a->length; i++) {
switch (sample_get_data_format(a, i)) {
case SAMPLE_DATA_FORMAT_FLOAT:
@ -261,24 +253,3 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags)
return 0;
}
int sample_set_data_format(struct sample *s, int idx, enum sample_data_format fmt)
{
if (idx >= sizeof(s->format) * 8)
return 0; /* we currently can only control the format of the first 64 values. */
switch (fmt) {
case SAMPLE_DATA_FORMAT_FLOAT: s->format &= ~(1 << idx); break;
case SAMPLE_DATA_FORMAT_INT: s->format |= (fmt << idx); break;
}
return 0;
}
int sample_get_data_format(struct sample *s, int idx)
{
if (idx >= sizeof(s->format) * 8)
return -1; /* we currently can only control the format of the first 64 values. */
return (s->format >> idx) & 0x1;
}