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

added first code for new multiplex hooks

This commit is contained in:
Steffen Vogel 2015-04-01 14:27:52 +02:00
parent 50622d1102
commit 4670e946aa
2 changed files with 59 additions and 9 deletions

View file

@ -19,10 +19,9 @@ struct path;
/** Callback type of hook function
*
* @todo Add a way to pass custom data to the hooks
* @param m The message which is forwarded
* @param m The last message which has been received
* @param p The path which is processing this message.
* @retval 0 Success. Continue processing the message.
* @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);
@ -66,4 +65,20 @@ int hook_fir(struct msg *m, struct path *p);
#define HOOK_FIR_INDEX 1
/** Example hook: collect previous messages to send them at once */
int hook_multiplex(struct msg *m, struct path *p);
/** Example hook: inverse multiplex operation */
int hook_demultiplex(struct msg *m, struct path *p);
#define HOOK_MULTIPLEX_RATIO 10
/* Plausability checks */
#if HOOK_MULTIPLEX_RATIO > POOL_SIZE
#error "POOL_SIZE is too small for given HOOK_MULTIPLEX_RATIO"
#endif
/** Example hook: Discrete Fourier Transform */
int hook_dft(struct msg *m, struct path *p);
#endif /* _HOOKS_H_ */

View file

@ -27,6 +27,9 @@ static struct hook_id hook_list[] = {
{ hook_tofixed, "tofixed" },
{ hook_ts, "ts" },
{ hook_fir, "fir" },
{ hook_dft, "dft"},
{ hook_multiplex, "multiplex" },
{ hook_demultiplex, "demultiplex" },
};
hook_cb_t hook_lookup(const char *name)
@ -47,12 +50,6 @@ int hook_print(struct msg *m, struct path *p)
return 0;
}
int hook_decimate(struct msg *m, struct path *p)
{
/* Drop every HOOK_DECIMATE_RATIO'th message */
return (m->sequence % HOOK_DECIMATE_RATIO == 0) ? -1 : 0;
}
int hook_tofixed(struct msg *m, struct path *p)
{
for (int i=0; i<m->length; i++) {
@ -98,3 +95,41 @@ int hook_fir(struct msg *m, struct path *p)
return 0;
}
int hook_decimate(struct msg *m, struct path *p)
{
/* Drop every HOOK_DECIMATE_RATIO'th message */
return (m->sequence % HOOK_DECIMATE_RATIO == 0) ? -1 : 0;
}
int hook_multiplex(struct msg *m, struct path *p)
{
/* Every HOOK_MULTIPLEX_RATIO'th message contains the collection of the previous ones */
if (p->received % HOOK_MULTIPLEX_RATIO == 0) {
struct msg *c = p->current; /* Current message */
for (int i=1; i<HOOK_MULTIPLEX_RATIO && c->length<MSG_VALUES; i++) {
struct msg *m = p->history[p->received-i];
/* Trim amount of values to actual size of msg buffer */
int len = MIN(m->length, MSG_VALUES - c->length);
memcpy(c->data + c->length, m->data, len * sizeof(m->data[0]));
c->length += len;
}
return 0;
}
else
return -1; /* Message will be dropped */
}
int hook_demultiplex(struct msg *m, struct path *p)
{
}
int hook_dft(struct msg *m, struct path *p)
{
/** @todo Implement */
}