diff --git a/include/villas/hooks/decimate.h b/include/villas/hooks/decimate.h new file mode 100644 index 000000000..01c747619 --- /dev/null +++ b/include/villas/hooks/decimate.h @@ -0,0 +1,36 @@ +/** Decimate hook. + * + * @author Steffen Vogel + * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#pragma once + +/** @addtogroup hooks Hook functions + * @{ + */ + +/* Forward declarations */ +struct hook; + +int decimate_set_ratio(struct hook *h, int ratio); + +/** + * @} + */ diff --git a/include/villas/hooks/limit_rate.h b/include/villas/hooks/limit_rate.h new file mode 100644 index 000000000..e225520bf --- /dev/null +++ b/include/villas/hooks/limit_rate.h @@ -0,0 +1,36 @@ +/** Rate-limiting hook. + * + * @author Steffen Vogel + * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#pragma once + +/** @addtogroup hooks Hook functions + * @{ + */ + +/* Forward declarations */ +struct hook; + +int limit_rate_set_rate(struct hook *h, double rate); + +/** + * @} + */ diff --git a/lib/hooks/decimate.c b/lib/hooks/decimate.c index 47fbee807..da7181df7 100644 --- a/lib/hooks/decimate.c +++ b/lib/hooks/decimate.c @@ -32,6 +32,15 @@ struct decimate { unsigned counter; }; +int decimate_set_ratio(struct hook *h, int ratio) +{ + struct decimate *p = (struct decimate *) h->_vd; + + p->ratio = ratio; + + return 0; +} + static int decimate_init(struct hook *h) { struct decimate *p = (struct decimate *) h->_vd; diff --git a/lib/hooks/limit_rate.c b/lib/hooks/limit_rate.c index 9c322d0ce..fc27d2d8f 100644 --- a/lib/hooks/limit_rate.c +++ b/lib/hooks/limit_rate.c @@ -42,6 +42,15 @@ struct limit_rate { struct timespec last; }; +int limit_rate_set_rate(struct hook *h, double rate) +{ + struct limit_rate *p = (struct limit_rate *) h->_vd; + + p->deadtime = 1.0 / rate; + + return 0; +} + static int limit_rate_init(struct hook *h) { struct limit_rate *p = (struct limit_rate *) h->_vd;