You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
2.5 KiB

/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007
Copyright Stichting C.A. Muller Radioastronomiestation, 2007
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
(at your option) 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <log/log.h>
#include <controller/controller_block.h>
/*
inputs outputs
nr name nr name
---------------------------------
---| 0 positive |
| 0 difference |----
---| 1 negative |
---------------------------------
*/
struct controller_block_private {
float *input0;
float *input1;
float error;
};
static void subtract_calculate(struct controller_block *sub)
{
struct controller_block_private *priv = sub->private;
/* out = positive - negative */
priv->error = *priv->input0 - *priv->input1;
}
static struct controller_block_interm_list interms[] = {
{ "positive", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ "negative", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input1) },
{ NULL }
};
static struct controller_block_outterm_list outterms[] = {
{ "difference", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, error) },
{ NULL }
};
static struct controller_block * block_subtract_create(char *name, int argc, va_list val)
{
struct controller_block *sub;
if (!(sub = controller_block_alloc("subtract", name, sizeof(struct controller_block_private))))
return NULL;
sub->private->error = 0.0;
if (controller_block_interm_list_init(sub, interms))
goto err_block;
if (controller_block_outterm_list_init(sub, outterms))
goto err_block;
sub->calculate = subtract_calculate;
if (controller_block_add(sub))
goto err_block;
return sub;
err_block:
controller_block_free(sub);
return NULL;
}
BLOCK_CREATE(subtract) = {
.create = block_subtract_create,
.args = { NULL },
};