- Atomic functions catalog >
- core.math.value_limiter
core.math.value_limiter¶
Inputs¶
Name |
Type |
Title |
Mandatory |
Description |
---|---|---|---|---|
input |
core.type.f64 |
Input |
True |
None |
Outputs¶
Name |
Type |
Title |
Description |
---|---|---|---|
output |
core.type.f64 |
Output |
None |
Parameters¶
Name |
Type |
Title |
Mandatory |
Default value |
Description |
---|---|---|---|---|---|
min |
core.type.f64 |
Lower bound |
True |
None |
None |
max |
core.type.f64 |
Upper bound |
True |
None |
None |
State variables¶
Function has no state variables
Usage XML code snippet¶
core_math_value_limiter snippet for FLOW configuration file¶
<f name="value_limiter" by_spec="core.math.value_limiter">
<in alias="input">some_block_1/output</in>
<param alias="min">0.0</param>
<param alias="max">0.0</param>
</f>
Function’s artifacts¶
- Declaration for core_math_value_limiter
- Implementation for core_math_value_limiter
- Set parameters code for core_math_value_limiter
- Header of core_math_value_limiter
- Specification of core_math_value_limiter
- Other
declaration.py¶
from fspeclib import *
Function(
name='core.math.value_limiter',
title=LocalizedString(
en='Value limiter'
),
parameters=[
Parameter(
name='min',
title='Lower bound',
value_type='core.type.f64',
tunable=True
),
Parameter(
name='max',
title='Upper bound',
value_type='core.type.f64',
tunable=True
)
],
parameter_constraints=[
ParameterValue('min') < ParameterValue('max')
],
inputs=[
Input(
name='input',
title='Input',
value_type='core.type.f64'
)
],
outputs=[
Output(
name='output',
title='Output',
value_type='core.type.f64'
)
]
)
core_math_value_limiter_exec.c¶
#include "core_math_value_limiter.h"
void core_math_value_limiter_exec(
const core_math_value_limiter_inputs_t *i,
core_math_value_limiter_outputs_t *o,
const core_math_value_limiter_params_t *p
)
{
if (i->input < p->min) {
o->output = p->min;
} else if (i->input > p->max) {
o->output = p->max;
} else {
o->output = i->input;
}
}
core_math_value_limiter_set_params.c¶
#include "core_math_value_limiter.h"
#include "conv.h"
#include <string.h>
#include "error.h"
fspec_rv_t core_math_value_limiter_set_params(
core_math_value_limiter_params_t *params,
const func_param_t *param_pairs,
int initial_call
)
{
// Get parameters
core_math_value_limiter_params_t p = *params;
core_math_value_limiter_params_flags_t flags;
memset(&flags, 0, sizeof(flags));
int violation_count = 0;
conv_rv_t crv = conv_rv_ok;
// Parse parameters
for (int i = 0; param_pairs[i].alias != NULL; i++) {
if (strcmp(param_pairs[i].alias, "min") == 0) {
if ((crv = conv_str_double(param_pairs[i].value, &p.min)) == conv_rv_ok) {
flags.changed_param_min = 1;
}
} else if (strcmp(param_pairs[i].alias, "max") == 0) {
if ((crv = conv_str_double(param_pairs[i].value, &p.max)) == conv_rv_ok) {
flags.changed_param_max = 1;
}
} else {
error("failed unsupported parameter '%s'", param_pairs[i].alias);
violation_count ++;
}
if (crv != conv_rv_ok) {
error("Parameter '%s' format error (%s)", param_pairs[i].alias, param_pairs[i].value);
violation_count++;
}
}
if (initial_call) {
// Check all mandatory parameters are set
if (!flags.changed_param_min) {
error("failed missed mandatory parameter 'min'");
violation_count ++;
}
if (!flags.changed_param_max) {
error("failed missed mandatory parameter 'max'");
violation_count ++;
}
}
if (violation_count > 0) {
return fspec_rv_inval_param;
}
// Validate parameters
if (!(p.min < p.max)) {
error("failed constraint (min < max)");
return fspec_rv_inval_param;
}
// Set parameters
*params = p;
return fspec_rv_ok;
}
core_math_value_limiter.h¶
/**
* Automatically-generated file. Do not edit!
*/
#ifndef FSPEC_CORE_MATH_VALUE_LIMITER_H
#define FSPEC_CORE_MATH_VALUE_LIMITER_H
#include <stdint.h>
#include <eswb/types.h>
#include "function.h"
/* Include declaration of dependency types */
#include "core_type_f64.h"
/**
* @brief Parameters of `core.math.value_limiter` function
*/
typedef struct core_math_value_limiter_params_{
core_type_f64_t min; /// Lower bound
core_type_f64_t max; /// Upper bound
} core_math_value_limiter_params_t;
/**
* @brief Inputs of `core.math.value_limiter` function
*/
typedef struct core_math_value_limiter_inputs_ {
core_type_f64_t input; /// Input
} core_math_value_limiter_inputs_t;
/**
* @brief Outputs of `core.math.value_limiter` function
*/
typedef struct core_math_value_limiter_outputs_ {
core_type_f64_t output; /// Output
} core_math_value_limiter_outputs_t;
/**
* @brief Parameter flags of `core.math.value_limiter` function
*/
typedef struct core_math_value_limiter_params_flags_ {
uint64_t changed_param_min:1;
uint64_t changed_param_max:1;
} core_math_value_limiter_params_flags_t;
typedef struct core_math_value_limiter_eswb_descriptors_ {
eswb_topic_descr_t in_input;
eswb_topic_descr_t out_all;
} core_math_value_limiter_eswb_descriptors_t;
typedef struct core_math_value_limiter_interface_ {
core_math_value_limiter_inputs_t i;
core_math_value_limiter_outputs_t o;
core_math_value_limiter_params_t p;
core_math_value_limiter_eswb_descriptors_t eswb_descriptors;
} core_math_value_limiter_interface_t;
fspec_rv_t core_math_value_limiter_set_params(
core_math_value_limiter_params_t *params,
const func_param_t *param_pairs,
int initial_call
);
void core_math_value_limiter_exec(
const core_math_value_limiter_inputs_t *i,
core_math_value_limiter_outputs_t *o,
const core_math_value_limiter_params_t *p
);
#endif // FSPEC_CORE_MATH_VALUE_LIMITER_H
core_math_value_limiter_spec.c¶
/**
* Automatically-generated file. Do not edit!
*/
#include "core_math_value_limiter.h"
#include <eswb/types.h>
static const param_spec_t param_min = {
.name = "min",
.default_value = "0.0",
.annotation = "Lower bound",
.flags = 0
};
static const param_spec_t param_max = {
.name = "max",
.default_value = "0.0",
.annotation = "Upper bound",
.flags = 0
};
static const param_spec_t *params[3] = {
¶m_min,
¶m_max,
NULL
};
static const input_spec_t i_input = {
.name = "input",
.annotation = "Input",
.flags = 0
};
static const input_spec_t *inputs[2] = {
&i_input,
NULL
};
static const output_spec_t o_output = {
.name = "output",
.annotation = "Output",
.flags = 0
};
static const output_spec_t *outputs[2] = {
&o_output,
NULL
};
fspec_rv_t core_math_value_limiter_call_init_inputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td
);
fspec_rv_t core_math_value_limiter_call_init_outputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td,
const char *func_name
);
void core_math_value_limiter_call_exec(void *dh);
fspec_rv_t core_math_value_limiter_call_set_params(void *dh, const func_param_t *param_pairs, int initial_call);
const function_spec_t atomic_core_math_value_limiter_spec = {
.name = "core.math.value_limiter",
.annotation = "Value limiter",
.inputs = inputs,
.outputs = outputs,
.params = params
};
const function_calls_t atomic_core_math_value_limiter_calls = {
.interface_handle_size = sizeof(core_math_value_limiter_interface_t),
.init = NULL,
.init_inputs = core_math_value_limiter_call_init_inputs,
.init_outputs = core_math_value_limiter_call_init_outputs,
.pre_exec_init = NULL,
.exec = core_math_value_limiter_call_exec,
.set_params = core_math_value_limiter_call_set_params
};
const function_handler_t atomic_core_math_value_limiter_handler = {
.spec = &atomic_core_math_value_limiter_spec,
.calls = &atomic_core_math_value_limiter_calls,
.extension_handler = NULL
};
core_math_value_limiter_interface.c¶
/**
* Automatically-generated file. Do not edit!
*/
#include "core_math_value_limiter.h"
#include "error.h"
#include <eswb/api.h>
#include <eswb/topic_proclaiming_tree.h>
#include <eswb/errors.h>
int core_math_value_limiter_interface_inputs_init(
core_math_value_limiter_interface_t *interface,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td
)
{
eswb_rv_t rv;
int errcnt_no_topic = 0;
int errcnt_no_input = 0;
const char *topic_path_in_input = fspec_find_path2connect(conn_spec,"input");
// Connecting mandatory input "input"
if (topic_path_in_input != NULL) {
rv = eswb_connect_nested(mounting_td, topic_path_in_input, &interface->eswb_descriptors.in_input);
if(rv != eswb_e_ok) {
error("failed connect input \"input\" to topic \"%s\": %s", topic_path_in_input, eswb_strerror(rv));
errcnt_no_topic++;
}
} else {
error("mandatory input \"input\" is not speicifed");
errcnt_no_input++;
}
if ((errcnt_no_input > 0) || (errcnt_no_topic > 0)) {
if (errcnt_no_input > errcnt_no_topic) {
return fspec_rv_no_input;
} else {
return fspec_rv_no_topic;
}
}
return fspec_rv_ok;
}
fspec_rv_t core_math_value_limiter_interface_inputs_update(core_math_value_limiter_interface_t *interface)
{
eswb_rv_t rv;
rv = eswb_read(interface->eswb_descriptors.in_input, &interface->i.input);
if(rv != eswb_e_ok) {
/*FIXME nothing to do yet*/
}
return 0;
}
fspec_rv_t core_math_value_limiter_interface_outputs_init(
core_math_value_limiter_interface_t *interface,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td,
const char *func_name
)
{
TOPIC_TREE_CONTEXT_LOCAL_DEFINE(cntx, 2);
core_math_value_limiter_outputs_t out;
eswb_rv_t rv;
topic_proclaiming_tree_t *rt = usr_topic_set_struct(cntx, out, func_name);
usr_topic_add_struct_child(cntx, rt, core_math_value_limiter_outputs_t, output, "output", tt_double);
rv = eswb_proclaim_tree(mounting_td, rt, cntx->t_num, &interface->eswb_descriptors.out_all);
if (rv != eswb_e_ok) {
return fspec_rv_publish_err;
}
return fspec_rv_ok;
}
fspec_rv_t core_math_value_limiter_interface_outputs_update(core_math_value_limiter_interface_t *interface)
{
eswb_rv_t rv;
rv = eswb_update_topic(interface->eswb_descriptors.out_all, &interface->o);
if (rv != eswb_e_ok) {
return 1;
}
return 0;
}
void core_math_value_limiter_interface_update(core_math_value_limiter_interface_t *interface)
{
core_math_value_limiter_interface_inputs_update(interface);
core_math_value_limiter_exec(&interface->i, &interface->o, &interface->p);
core_math_value_limiter_interface_outputs_update(interface);
}
fspec_rv_t core_math_value_limiter_call_set_params(void *dh, const func_param_t *param_pairs, int initial_call)
{
core_math_value_limiter_interface_t *interface = (core_math_value_limiter_interface_t*) dh;
return core_math_value_limiter_set_params(&interface->p, param_pairs, initial_call);
}
fspec_rv_t core_math_value_limiter_call_init_inputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td
)
{
core_math_value_limiter_interface_t *interface = (core_math_value_limiter_interface_t*) dh;
return core_math_value_limiter_interface_inputs_init(interface, conn_spec, mounting_td);
}
fspec_rv_t core_math_value_limiter_call_init_outputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td,
const char *func_name
)
{
core_math_value_limiter_interface_t *interface = (core_math_value_limiter_interface_t*) dh;
return core_math_value_limiter_interface_outputs_init(interface, conn_spec, mounting_td, func_name);
}
void core_math_value_limiter_call_exec(void *dh)
{
core_math_value_limiter_interface_t *interface = (core_math_value_limiter_interface_t*) dh;
core_math_value_limiter_interface_update(interface);
}