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

unified member variable naming of struct sample and struct msg

This commit is contained in:
Steffen Vogel 2016-07-11 18:19:23 +02:00
parent 8115a9caa2
commit 3880abeb63
15 changed files with 50 additions and 50 deletions

View file

@ -48,11 +48,11 @@
#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data))
/** Initialize a message with default values */
#define MSG_INIT(val, seq) (struct msg) {\
.version = MSG_VERSION, \
.type = MSG_TYPE_DATA, \
.endian = MSG_ENDIAN_HOST, \
.values = val, \
#define MSG_INIT(len, seq) (struct msg) {\
.version = MSG_VERSION, \
.type = MSG_TYPE_DATA, \
.endian = MSG_ENDIAN_HOST, \
.length = len, \
.sequence = seq \
}
@ -81,7 +81,7 @@ struct msg
#endif
unsigned rsvd2 : 8; /**< Reserved bits */
uint16_t values; /**< The number of values in msg::data[]. Endianess is specified in msg::endian. */
uint16_t length; /**< The number of values in msg::data[]. Endianess is specified in msg::endian. */
uint32_t sequence; /**< The sequence number is incremented by one for consecutive messages. Endianess is specified in msg::endian. */
/** A timestamp per message. Endianess is specified in msg::endian. */

View file

@ -33,6 +33,7 @@ struct fpga {
struct vfio_dev vd; /**< VFIO device handle. */
int do_reset; /**< Reset VILLASfpga during startup? */
int affinity; /**< Affinity for MSI interrupts */
struct list ips; /**< List of IP components on FPGA. */

View file

@ -48,7 +48,7 @@ struct path
struct list destinations; /**< List of all outgoing nodes */
struct list hooks; /**< List of function pointers to hooks */
int values; /**< Maximum number of values per sample for this path. */
int samplelen; /**< Maximum number of values per sample for this path. */
int queuelen; /**< Size of sample queue for this path. */
int enabled; /**< Is this path enabled */
int tfd; /**< Timer file descriptor for fixed rate sending */

View file

@ -17,13 +17,13 @@
#include <sys/types.h>
/** The length of a sample datastructure with \p values values in bytes. */
#define SAMPLE_LEN(values) (sizeof(struct sample) + SAMPLE_DATA_LEN(values))
#define SAMPLE_LEN(len) (sizeof(struct sample) + SAMPLE_DATA_LEN(len))
/** The length of a sample data portion of a sample datastructure with \p values values in bytes. */
#define SAMPLE_DATA_LEN(values) ((values) * sizeof(float))
#define SAMPLE_DATA_LEN(len) ((len) * sizeof(float))
/** The offset to the beginning of the data section. */
#define SAMPLE_DATA_OFFSET(smp) ((char *) (smp) + offsetof(struct sample, values))
#define SAMPLE_DATA_OFFSET(smp) ((char *) (smp) + offsetof(struct sample, data))
/** These flags define the format which is used by sample_fscan() and sample_fprint(). */
enum sample_flags {
@ -49,7 +49,7 @@ struct sample {
union {
float f; /**< Floating point values (note msg::endian) */
uint32_t i; /**< Integer values (note msg::endian) */
} values[];
} data[];
};
/** Print a sample in human readable form to a file stream.

View file

@ -181,8 +181,8 @@ int config_parse_path(config_setting_t *cfg,
if (cfg_hook)
config_parse_hooklist(cfg_hook, &p->hooks);
if (!config_setting_lookup_int(cfg, "values", &p->values))
p->values = DEFAULT_VALUES;
if (!config_setting_lookup_int(cfg, "values", &p->samplelen))
p->samplelen = DEFAULT_VALUES;
if (!config_setting_lookup_int(cfg, "queuelen", &p->queuelen))
p->queuelen = DEFAULT_QUEUELEN;
if (!config_setting_lookup_bool(cfg, "reverse", &reverse))

View file

@ -61,8 +61,8 @@ int hook_convert(struct path *p, struct hook *h, int when, struct sample *smps[]
for (int i = 0; i < cnt; i++) {
for (int j = 0; j < smps[0]->length; j++) {
switch (private->mode) {
case TO_FIXED: smps[i]->values[j].i = smps[i]->values[j].f * 1e3; break;
case TO_FLOAT: smps[i]->values[j].f = smps[i]->values[j].i; break;
case TO_FIXED: smps[i]->data[j].i = smps[i]->data[j].f * 1e3; break;
case TO_FLOAT: smps[i]->data[j].f = smps[i]->data[j].i; break;
}
}
}

View file

@ -127,15 +127,15 @@ int hook_stats_send(struct path *p, struct hook *h, int when, struct sample *smp
else
length = -1;
smp->values[0].f = p->in->received;
smp->values[1].f = length;
smp->values[2].f = p->invalid;
smp->values[3].f = p->skipped;
smp->values[4].f = p->dropped;
smp->values[5].f = p->overrun;
smp->values[6].f = p->hist.owd.last,
smp->values[7].f = 1.0 / p->hist.gap_msg.last;
smp->values[8].f = 1.0 / p->hist.gap_recv.last;
smp->data[0].f = p->in->received;
smp->data[1].f = length;
smp->data[2].f = p->invalid;
smp->data[3].f = p->skipped;
smp->data[4].f = p->dropped;
smp->data[5].f = p->overrun;
smp->data[6].f = p->hist.owd.last,
smp->data[7].f = 1.0 / p->hist.gap_msg.last;
smp->data[8].f = 1.0 / p->hist.gap_recv.last;
smp->length = 9;
node_write(private->dest, &smp, 1); /* Send single message with statistics to destination node */

View file

@ -24,12 +24,12 @@
void msg_swap(struct msg *m)
{
m->values = bswap_16(m->values);
m->length = bswap_16(m->length);
m->sequence = bswap_32(m->sequence);
m->ts.sec = bswap_32(m->ts.sec);
m->ts.nsec = bswap_32(m->ts.nsec);
for (int i = 0; i < m->values; i++)
for (int i = 0; i < m->length; i++)
m->data[i].i = bswap_32(m->data[i].i);
m->endian ^= 1;

View file

@ -86,7 +86,7 @@ int cbuilder_read(struct node *n, struct sample *smps[], unsigned cnt)
while (cb->read >= cb->step)
pthread_cond_wait(&cb->cv, &cb->mtx);
smp->length = cb->model->read(&smp->values[0].f, 16);
smp->length = cb->model->read(&smp->data[0].f, 16);
smp->sequence = cb->step;
cb->read = cb->step;
@ -103,7 +103,7 @@ int cbuilder_write(struct node *n, struct sample *smps[], unsigned cnt)
pthread_mutex_lock(&cb->mtx);
cb->model->write(&smp->values[0].f, smp->length);
cb->model->write(&smp->data[0].f, smp->length);
cb->model->code();
cb->step++;

View file

@ -109,7 +109,7 @@ static json_t* ngsi_build_entity(struct ngsi *i, struct sample *smps[], unsigned
for (int k = 0; k < cnt; k++) {
json_array_append_new(values, json_pack("[ f, f, i ]",
time_to_double(&smps[k]->ts.origin),
smps[k]->values[map->index].f,
smps[k]->data[map->index].f,
smps[k]->sequence
));
}
@ -207,7 +207,7 @@ static int ngsi_parse_entity(json_t *entity, struct ngsi *i, struct sample *smps
return -9;
smps[k]->ts.origin = tss;
smps[k]->values[map->index].f = strtof(value, &end);
smps[k]->data[map->index].f = strtof(value, &end);
if (value == end)
return -10;
}

View file

@ -235,7 +235,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt)
if (hdr.endian != MSG_ENDIAN_HOST)
msg_swap(&hdr);
samples = bytes / MSG_LEN(hdr.values);
samples = bytes / MSG_LEN(hdr.length);
if (samples > cnt) {
warn("Received more samples than supported. Dropping %u samples", samples - cnt);
@ -248,7 +248,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt)
iov[2*i+0].iov_len = MSG_LEN(0);
iov[2*i+1].iov_base = SAMPLE_DATA_OFFSET(smps[i]);
iov[2*i+1].iov_len = SAMPLE_DATA_LEN(hdr.values);
iov[2*i+1].iov_len = SAMPLE_DATA_LEN(hdr.length);
mhdr.msg_iovlen += 2;
}
@ -268,14 +268,14 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt)
if (ret)
break;
if (m->values != hdr.values)
if (m->length != hdr.length)
break;
/* Convert message to host endianess */
if (m->endian != MSG_ENDIAN_HOST)
msg_swap(m);
s->length = m->values;
s->length = m->length;
s->sequence = m->sequence;
s->ts.origin = MSG_TS(m);
}

View file

@ -367,8 +367,7 @@ int fpga_read(struct node *n, struct sample *smps[], unsigned cnt)
size_t recvlen;
//size_t len = smp->length * sizeof(smp->values[0]);
size_t len = 64 * sizeof(smp->values[0]);
size_t len = SAMPLE_DATA_LEN(64);
/* We dont get a sequence no from the FPGA. Lets fake it */
smp->sequence = n->received;
@ -385,12 +384,12 @@ int fpga_read(struct node *n, struct sample *smps[], unsigned cnt)
if (ret)
return ret;
memcpy(smp->values, d->dma.base_virt + 0x800, recvlen);
memcpy(smp->data, d->dma.base_virt + 0x800, recvlen);
smp->length = recvlen / 4;
return 1;
case FPGA_DM_FIFO:
recvlen = fifo_read(d->ip, (char *) smp->values, len);
recvlen = fifo_read(d->ip, (char *) smp->data, len);
smp->length = recvlen / 4;
return 1;
@ -406,7 +405,7 @@ int fpga_write(struct node *n, struct sample *smps[], unsigned cnt)
struct sample *smp = smps[0];
size_t sentlen;
size_t len = smp->length * sizeof(smp->values[0]);
size_t len = smp->length * sizeof(smp->data[0]);
//intc_wait(f->intc, 5, 1);
@ -418,7 +417,7 @@ int fpga_write(struct node *n, struct sample *smps[], unsigned cnt)
/* Send data to RTDS */
switch (d->type) {
case FPGA_DM_DMA:
memcpy(d->dma.base_virt, smp->values, len);
memcpy(d->dma.base_virt, smp->data, len);
ret = dma_write(d->ip, d->dma.base_phys, len);
if (ret)
@ -432,8 +431,8 @@ int fpga_write(struct node *n, struct sample *smps[], unsigned cnt)
return 1;
case FPGA_DM_FIFO:
sentlen = fifo_write(d->ip, (char *) smp->values, len);
return sentlen / sizeof(smp->values[0]);
sentlen = fifo_write(d->ip, (char *) smp->data, len);
return sentlen / sizeof(smp->data[0]);
break;
}

View file

@ -255,7 +255,7 @@ int path_prepare(struct path *p)
error("Failed to parse arguments for hooks of path: %s", path_name(p));
/* Initialize queue */
ret = pool_init_mmap(&p->pool, SAMPLE_LEN(p->values), p->queuelen);
ret = pool_init_mmap(&p->pool, SAMPLE_LEN(p->samplelen), p->queuelen);
if (ret)
error("Failed to allocate memory pool for path");

View file

@ -26,7 +26,7 @@ int sample_print(char *buf, size_t len, struct sample *s, int flags)
if (flags & SAMPLE_VALUES) {
for (int i = 0; i < s->length; i++)
off += snprintf(buf + off, len - off, "\t%.6f", s->values[i].f);
off += snprintf(buf + off, len - off, "\t%.6f", s->data[i].f);
}
off += snprintf(buf + off, len - off, "\n");
@ -95,7 +95,7 @@ int sample_scan(const char *line, struct sample *s, int *fl)
s->length++, ptr = end) {
/** @todo We only support floating point values at the moment */
s->values[s->length].f = strtod(ptr, &end);
s->data[s->length].f = strtod(ptr, &end);
if (end == ptr) /* there are no valid FP values anymore */
break;

View file

@ -137,11 +137,11 @@ check: if (optarg == endptr)
for (int i = 0; i < values; i++) {
int rtype = (type != TYPE_MIXED) ? type : i % 4;
switch (rtype) {
case TYPE_RANDOM: s->values[i].f += box_muller(0, stddev); break;
case TYPE_SINE: s->values[i].f = ampl * sin(running * freq * 2 * M_PI); break;
case TYPE_TRIANGLE: s->values[i].f = ampl * (fabs(fmod(running * freq, 1) - .5) - 0.25) * 4; break;
case TYPE_SQUARE: s->values[i].f = ampl * ( (fmod(running * freq, 1) < .5) ? -1 : 1); break;
case TYPE_RAMP: s->values[i].f = fmod(counter, rate / freq); /** @todo send as integer? */ break;
case TYPE_RANDOM: s->data[i].f += box_muller(0, stddev); break;
case TYPE_SINE: s->data[i].f = ampl * sin(running * freq * 2 * M_PI); break;
case TYPE_TRIANGLE: s->data[i].f = ampl * (fabs(fmod(running * freq, 1) - .5) - 0.25) * 4; break;
case TYPE_SQUARE: s->data[i].f = ampl * ( (fmod(running * freq, 1) < .5) ? -1 : 1); break;
case TYPE_RAMP: s->data[i].f = fmod(counter, rate / freq); /** @todo send as integer? */ break;
}
}