mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added timestamp option to file node type
This commit is contained in:
parent
b04df56ddc
commit
527ccc7b53
2 changed files with 15 additions and 1 deletions
|
@ -14,17 +14,20 @@
|
|||
|
||||
#include "node.h"
|
||||
|
||||
#define FILE_MAX_PATHLEN 128
|
||||
|
||||
struct file {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
const char *path_in;
|
||||
const char *path_out;
|
||||
char *path_out;
|
||||
|
||||
const char *mode; /**< The mode for fopen() which is used for the out file. */
|
||||
|
||||
double rate; /**< The sending rate. */
|
||||
int tfd; /**< Timer file descriptor. Blocks until 1/rate seconds are elapsed. */
|
||||
int timestamp; /**< Bolean flag, prepend timestamp in front of message */
|
||||
};
|
||||
|
||||
/** @see node_vtable::init */
|
||||
|
|
|
@ -53,6 +53,9 @@ int file_parse(config_setting_t *cfg, struct node *n)
|
|||
if (!config_setting_lookup_float(cfg, "rate", &f->rate))
|
||||
f->rate = 1;
|
||||
|
||||
if (!config_setting_lookup_bool(cfg, "timestamp", &f->timestamp))
|
||||
f->timestamp = 0;
|
||||
|
||||
n->file = f;
|
||||
|
||||
return 0;
|
||||
|
@ -100,6 +103,8 @@ int file_close(struct node *n)
|
|||
if (f->out)
|
||||
fclose(f->out);
|
||||
|
||||
free(f->path_out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -133,6 +138,12 @@ int file_write(struct node *n, struct msg *pool, int poolsize, int first, int cn
|
|||
for (i = 0; i < cnt; i++) {
|
||||
struct msg *m = &pool[(first+i) % poolsize];
|
||||
|
||||
if (f->timestamp) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
fprintf(f->out, "%lu.%06lu\t", ts.tv_sec, (long) (ts.tv_nsec / 1e3));
|
||||
}
|
||||
|
||||
msg_fprint(f->out, m);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue