mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
Add endianness setting in config file to nodes
This commit is contained in:
parent
8d7e0074ad
commit
4745a799ff
6 changed files with 34 additions and 3 deletions
|
@ -35,6 +35,7 @@ nodes = {
|
|||
local = "134.130.169.31:12002", # Local ip:port, use '*' for random port
|
||||
remote = "134.130.169.98:12001",
|
||||
header = "gtnet-skt:fake", # 'gtnet-skt' or 'villas'. If not provided, 'villas' header will be used
|
||||
endian = "big", # Can be 'little' or 'small'. If not provided (default), little endianness logic will be applied
|
||||
vectorize = 1, # Number of samples to fetch per iteration from the socket
|
||||
netem = {
|
||||
enabled = false,
|
||||
|
|
|
@ -48,6 +48,8 @@ struct node
|
|||
int vectorize; /**< Number of messages to send / recv at once (scatter / gather) */
|
||||
int affinity; /**< CPU Affinity of this node */
|
||||
|
||||
int endian; /** Endianness of the data sent/received by the node */
|
||||
|
||||
unsigned long sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */
|
||||
|
||||
enum node_state {
|
||||
|
|
|
@ -17,6 +17,14 @@
|
|||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <byteswap.h>
|
||||
#elif defined(__PPC__) /* Xilinx toolchain */
|
||||
#include <xil_io.h>
|
||||
#define bswap_16(x) Xil_EndianSwap16(x)
|
||||
#define bswap_32(x) Xil_EndianSwap32(x)
|
||||
#endif
|
||||
|
||||
/* Forward declarations */
|
||||
struct pool;
|
||||
|
||||
|
@ -45,6 +53,8 @@ struct sample {
|
|||
|
||||
atomic_int refcnt; /**< Reference counter. */
|
||||
struct pool *pool; /**< This sample is belong to this memory pool. */
|
||||
|
||||
int endian; /**< Endianess of data in the sample. */
|
||||
|
||||
/** All timestamps are seconds / nano seconds after 1.1.1970 UTC */
|
||||
struct {
|
||||
|
|
13
lib/cfg.c
13
lib/cfg.c
|
@ -274,7 +274,7 @@ int cfg_parse_nodelist(config_setting_t *cfg, struct list *list, struct list *al
|
|||
|
||||
int cfg_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set)
|
||||
{
|
||||
const char *type, *name;
|
||||
const char *type, *name, *endian;
|
||||
int ret;
|
||||
|
||||
struct node *n;
|
||||
|
@ -314,6 +314,17 @@ int cfg_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *s
|
|||
if (!config_setting_lookup_int(cfg, "affinity", &n->affinity))
|
||||
n->affinity = set->affinity;
|
||||
|
||||
if (!config_setting_lookup_string(cfg, "endian", &endian))
|
||||
n->endian = LITTLE_ENDIAN;
|
||||
else {
|
||||
if(!strcmp(endian, "big"))
|
||||
n->endian = BIG_ENDIAN;
|
||||
else if (!strcmp(endian, "little"))
|
||||
n->endian = LITTLE_ENDIAN;
|
||||
else
|
||||
cerror(cfg, "Invalid endianness type '%s' for node %s", endian, node_name(n));
|
||||
}
|
||||
|
||||
list_push(nodes, n);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -275,6 +275,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt)
|
|||
smp->ts.received.tv_nsec = -1;
|
||||
|
||||
smp->length = length;
|
||||
smp->endian = n->endian;
|
||||
|
||||
received = 1; /* GTNET-SKT sends every sample in a single packet */
|
||||
}
|
||||
|
|
10
lib/sample.c
10
lib/sample.c
|
@ -55,8 +55,14 @@ int sample_print(char *buf, size_t len, struct sample *s, int flags)
|
|||
off += snprintf(buf + off, len - off, "(%u)", s->sequence);
|
||||
|
||||
if (flags & SAMPLE_VALUES) {
|
||||
for (int i = 0; i < s->length; i++)
|
||||
off += snprintf(buf + off, len - off, "\t%.6f", s->data[i].f);
|
||||
for (int i = 0; i < s->length; i++) {
|
||||
float display_float = s->data[i].f;
|
||||
if(s->endian == BIG_ENDIAN) {
|
||||
uint32_t * temp_int = (uint32_t *) &(display_float);
|
||||
*temp_int = bswap_32(*temp_int);
|
||||
}
|
||||
off += snprintf(buf + off, len - off, "\t%.6f", display_float);
|
||||
}
|
||||
}
|
||||
|
||||
off += snprintf(buf + off, len - off, "\n");
|
||||
|
|
Loading…
Add table
Reference in a new issue