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.
 
 
 
 
 
 

94 lines
2.3 KiB

/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
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 <controller/controller_block.h>
#include <controller/controller_bus.h>
#include <log/log.h>
#include <packet/packet.h>
struct controller_block_private {
bool value;
uint8_t *data;
struct controller_bus *bus;
};
static void calculate(struct controller_block *in_bool)
{
struct controller_block_private *priv = in_bool->private;
priv->value = *priv->data;
}
static void rx_callback(struct controller_block *block, void *data)
{
block->private->data = data;
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, value) },
{ NULL }
};
static struct controller_block * block_packet_in_bool_byte_create(char *name,
int argc, va_list ap)
{
struct controller_block *in_bool;
char *busname = va_arg(ap, char *);
int offset = va_arg(ap, int);
if (!(in_bool = controller_block_alloc("packet_in_bool_byte", name, sizeof(struct controller_block_private))))
return NULL;
in_bool->calculate = calculate;
if (controller_block_outterm_list_init(in_bool, outterms))
goto err_block;
in_bool->private->bus = controller_bus_find(busname);
if (!in_bool->private->bus)
goto err_bus;
if (packet_bus_add_input(in_bool, in_bool->private->bus,
offset, 4, rx_callback))
goto err_bus_input;
if (controller_block_add(in_bool))
goto err_add;
return in_bool;
err_add:
err_bus_input:
err_bus:
err_block:
controller_block_free(in_bool);
return NULL;
}
BLOCK_CREATE(packet_in_bool_byte) = {
.create = block_packet_in_bool_byte_create,
.args = { "char*,int", NULL },
};