Commit c76e67c7 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Added an exclusive block.

Currently only supports ex2, but more can be added similar to andN.

Modified dt.ctrl to use the ex2 block to prevent simultanious activation of
focusbox outputs.

Made and block calculate functions status to prevent conflicts.
parent a1879bf5
...@@ -43,28 +43,28 @@ struct controller_block_private { ...@@ -43,28 +43,28 @@ struct controller_block_private {
bool *i[0]; bool *i[0];
}; };
void calculate_2(struct controller_block *block) static void calculate_2(struct controller_block *block)
{ {
struct controller_block_private *priv = block->private; struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1]; priv->q = *priv->i[0] & *priv->i[1];
} }
void calculate_3(struct controller_block *block) static void calculate_3(struct controller_block *block)
{ {
struct controller_block_private *priv = block->private; struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2]; priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2];
} }
void calculate_4(struct controller_block *block) static void calculate_4(struct controller_block *block)
{ {
struct controller_block_private *priv = block->private; struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2] & *priv->i[3]; priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2] & *priv->i[3];
} }
void calculate_5(struct controller_block *block) static void calculate_5(struct controller_block *block)
{ {
struct controller_block_private *priv = block->private; struct controller_block_private *priv = block->private;
......
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2015
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 <log/log.h>
/*
inputs outputs
nr name nr name
----------------------
| |
---| 0 a 0 q |----
| |
---| 1 b |
| |
----------------------
*/
struct io {
bool q;
bool *i;
};
struct controller_block_private {
struct io io[0];
};
static void calculate_2(struct controller_block *block)
{
struct controller_block_private *priv = block->private;
priv->io[0].q = *priv->io[0].i & !(*priv->io[1].i);
priv->io[1].q = *priv->io[1].i & !(*priv->io[0].i);
}
static struct controller_block_interm_list interms_2[] = {
{ "a", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[0].i) },
{ "b", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[1].i) },
{ NULL }
};
static struct controller_block_outterm_list outterms_2[] = {
{ "qa", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[0].q) },
{ "qb", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[1].q) },
{ NULL }
};
static struct controller_block * block_ex(struct controller_block *block)
{
if (controller_block_add(block))
goto err_block;
return block;
err_block:
controller_block_free(block);
return NULL;
}
static struct controller_block *block_err(struct controller_block *block)
{
controller_block_free(block);
return NULL;
}
static struct controller_block * block_ex2_create(char *name, int argc, va_list val)
{
struct controller_block *block;
if (!(block = controller_block_alloc("ex2", name, sizeof(struct controller_block_private) + sizeof(bool *) * 2)))
return NULL;
if (controller_block_interm_list_init(block, interms_2))
return block_err(block);
if (controller_block_outterm_list_init(block, outterms_2))
return block_err(block);
block->calculate = calculate_2;
return block_ex(block);
}
BLOCK_CREATE(ex2) = {
.create = block_ex2_create,
.args = { NULL },
};
trigger {
{ "immediate" }
}
blocks (100.0, 0.0) {
{ "ex2", "ex2" }
{ "test_input_bool", "test_input_a" }
{ "test_input_bool", "test_input_b" }
{ "test_output_bool", "test_output_qa" }
{ "test_output_bool", "test_output_qb" }
}
links {
{ "test_input_a", "value", "ex2", "a", true }
{ "test_input_b", "value", "ex2", "b", true }
{ "ex2", "qa", "test_output_qa", "value", true }
{ "ex2", "qb", "test_output_qb", "value", true }
}
params {
{ "test_input_a", "value", 4,
(int) { false, true, false, true } }
{ "test_input_b", "value", 4,
(int) { false, false, true, true } }
{ "test_output_qa", "value", 4,
(int) { false, true, false, false } }
{ "test_output_qb", "value", 4,
(int) { false, false, true, false } }
}
set trace_server false
...@@ -14,6 +14,7 @@ BLOCKS := \ ...@@ -14,6 +14,7 @@ BLOCKS := \
counter \ counter \
debug \ debug \
decoder_uint32_bool \ decoder_uint32_bool \
ex \
filter_iir \ filter_iir \
filter_lp \ filter_lp \
friction \ friction \
...@@ -66,6 +67,7 @@ BLOCKS_NO_C := \ ...@@ -66,6 +67,7 @@ BLOCKS_NO_C := \
and3 \ and3 \
and4 \ and4 \
and5 \ and5 \
ex2 \
value_float value_float
ifneq ($(OS), FreeBSD) ifneq ($(OS), FreeBSD)
...@@ -102,6 +104,7 @@ CTRL_TESTS += \ ...@@ -102,6 +104,7 @@ CTRL_TESTS += \
$(DIR)/block_command_bool.test.output \ $(DIR)/block_command_bool.test.output \
$(DIR)/block_command_float.test.output \ $(DIR)/block_command_float.test.output \
$(DIR)/block_command_uint32.test.output \ $(DIR)/block_command_uint32.test.output \
$(DIR)/block_ex.test.output \
$(DIR)/block_gain.test.output \ $(DIR)/block_gain.test.output \
$(DIR)/block_gain_ratio_abs.test.output \ $(DIR)/block_gain_ratio_abs.test.output \
$(DIR)/block_i2t.test.output \ $(DIR)/block_i2t.test.output \
......
...@@ -107,8 +107,9 @@ blocks ($(frequency), $(delay)) { ...@@ -107,8 +107,9 @@ blocks ($(frequency), $(delay)) {
{ "log", "elevation_torsion_range_log" } { "log", "elevation_torsion_range_log" }
{ "log", "elevation_position_safe_log" } { "log", "elevation_position_safe_log" }
{ "command_bool", "focusbox_plus" } { "command_bool", "focusbox_plus" }
{ "command_bool", "focusbox_min" } { "command_bool", "focusbox_min" }
{ "ex2", "focusbox_exclusive" }
{ "value_bool", "false" } { "value_bool", "false" }
{ "value_float", "zero" } { "value_float", "zero" }
...@@ -221,8 +222,10 @@ links { ...@@ -221,8 +222,10 @@ links {
{ "elevation_torque_l", "value", "dt_el_l", "torque" , true } { "elevation_torque_l", "value", "dt_el_l", "torque" , true }
{ "elevation_servo_state", "enable", "dt_el_r", "enable" , true } { "elevation_servo_state", "enable", "dt_el_r", "enable" , true }
{ "elevation_servo_state", "enable", "dt_el_l", "enable" , true } { "elevation_servo_state", "enable", "dt_el_l", "enable" , true }
{ "focusbox_plus", "value", "dt_el_r", "ba1" , true } { "focusbox_plus", "value", "focusbox_exclusive", "a" , true }
{ "focusbox_min", "value", "dt_el_r", "ba2" , true } { "focusbox_min", "value", "focusbox_exclusive", "b" , true }
{ "focusbox_exclusive", "qa", "dt_el_r", "ba1" , true }
{ "focusbox_exclusive", "qb", "dt_el_r", "ba2" , true }
{ "false", "value", "dt_el_l", "ba1" , true } { "false", "value", "dt_el_l", "ba1" , true }
{ "false", "value", "dt_el_l", "ba2" , true } { "false", "value", "dt_el_l", "ba2" , true }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment