mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
pass timestamp when message was received to hook callbacks
This commit is contained in:
parent
219278b31f
commit
b42dd7a466
2 changed files with 17 additions and 14 deletions
|
@ -19,6 +19,8 @@
|
|||
#ifndef _HOOKS_H_
|
||||
#define _HOOKS_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/* The configuration of hook parameters is done in "config.h" */
|
||||
|
||||
struct msg;
|
||||
|
@ -28,10 +30,11 @@ struct path;
|
|||
*
|
||||
* @param m The last message which has been received
|
||||
* @param p The path which is processing this message.
|
||||
* @param ts The timestamp when the message(s) were received.
|
||||
* @retval 0 Success. Continue processing and forwarding the message.
|
||||
* @retval <0 Error. Drop the message.
|
||||
*/
|
||||
typedef int (*hook_cb_t)(struct msg *m, struct path *p);
|
||||
typedef int (*hook_cb_t)(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** This is a static list of available hooks.
|
||||
*
|
||||
|
@ -52,21 +55,21 @@ struct hook_id {
|
|||
hook_cb_t hook_lookup(const char *name);
|
||||
|
||||
/** Example hook: Print the message. */
|
||||
int hook_print(struct msg *m, struct path *p);
|
||||
int hook_print(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** Example hook: Drop messages. */
|
||||
int hook_decimate(struct msg *m, struct path *p);
|
||||
int hook_decimate(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** Example hook: Convert the message values to fixed precision. */
|
||||
int hook_tofixed(struct msg *m, struct path *p);
|
||||
int hook_tofixed(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** Example hook: add timestamp to message. */
|
||||
int hook_ts(struct msg *m, struct path *p);
|
||||
/** Example hook: overwrite timestamp of message. */
|
||||
int hook_ts(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** Example hook: Finite-Impulse-Response (FIR) filter. */
|
||||
int hook_fir(struct msg *m, struct path *p);
|
||||
int hook_fir(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
/** Example hook: Discrete Fourier Transform */
|
||||
int hook_dft(struct msg *m, struct path *p);
|
||||
int hook_dft(struct msg *m, struct path *p, struct timespec *ts);
|
||||
|
||||
#endif /** _HOOKS_H_ @} */
|
||||
|
|
|
@ -48,7 +48,7 @@ hook_cb_t hook_lookup(const char *name)
|
|||
return NULL; /* No matching hook was found */
|
||||
}
|
||||
|
||||
int hook_print(struct msg *m, struct path *p)
|
||||
int hook_print(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
/* Print every message once to stdout */
|
||||
msg_fprint(stdout, m);
|
||||
|
@ -56,7 +56,7 @@ int hook_print(struct msg *m, struct path *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hook_tofixed(struct msg *m, struct path *p)
|
||||
int hook_tofixed(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
for (int i=0; i<m->length; i++) {
|
||||
m->data[i].i = m->data[i].f * 1e3;
|
||||
|
@ -65,7 +65,7 @@ int hook_tofixed(struct msg *m, struct path *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hook_ts(struct msg *m, struct path *p)
|
||||
int hook_ts(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
struct timespec *ts = (struct timespec *) &m->data[HOOK_TS_INDEX];
|
||||
|
||||
|
@ -74,7 +74,7 @@ int hook_ts(struct msg *m, struct path *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hook_fir(struct msg *m, struct path *p)
|
||||
int hook_fir(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
/** Simple FIR-LP: F_s = 1kHz, F_pass = 100 Hz, F_block = 300
|
||||
* Tip: Use MATLAB's filter design tool and export coefficients
|
||||
|
@ -102,14 +102,14 @@ int hook_fir(struct msg *m, struct path *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hook_decimate(struct msg *m, struct path *p)
|
||||
int hook_decimate(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
/* Only sent every HOOK_DECIMATE_RATIO'th message */
|
||||
return m->sequence % HOOK_DECIMATE_RATIO;
|
||||
}
|
||||
|
||||
/** @todo Implement */
|
||||
int hook_dft(struct msg *m, struct path *p)
|
||||
int hook_dft(struct msg *m, struct path *p, struct timespec *ts)
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue