diff --git a/server/include/hooks.h b/server/include/hooks.h index 4a2874f01..55ece2ced 100644 --- a/server/include/hooks.h +++ b/server/include/hooks.h @@ -19,6 +19,8 @@ #ifndef _HOOKS_H_ #define _HOOKS_H_ +#include + /* 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_ @} */ diff --git a/server/src/hooks.c b/server/src/hooks.c index ec0330cb8..90342f575 100644 --- a/server/src/hooks.c +++ b/server/src/hooks.c @@ -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; ilength; 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; } \ No newline at end of file