/**
* Automatically-generated file. Do not edit!
*/
#include "core_math_clamp.h"
#include "error.h"
#include <eswb/api.h>
#include <eswb/topic_proclaiming_tree.h>
#include <eswb/errors.h>
int core_math_clamp_interface_inputs_init(
core_math_clamp_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");
const char *topic_path_in_min = fspec_find_path2connect(conn_spec,"min");
const char *topic_path_in_max = fspec_find_path2connect(conn_spec,"max");
// 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++;
}
// Connecting mandatory input "min"
if (topic_path_in_min != NULL) {
rv = eswb_connect_nested(mounting_td, topic_path_in_min, &interface->eswb_descriptors.in_min);
if(rv != eswb_e_ok) {
error("failed connect input \"min\" to topic \"%s\": %s", topic_path_in_min, eswb_strerror(rv));
errcnt_no_topic++;
}
} else {
error("mandatory input \"min\" is not speicifed");
errcnt_no_input++;
}
// Connecting mandatory input "max"
if (topic_path_in_max != NULL) {
rv = eswb_connect_nested(mounting_td, topic_path_in_max, &interface->eswb_descriptors.in_max);
if(rv != eswb_e_ok) {
error("failed connect input \"max\" to topic \"%s\": %s", topic_path_in_max, eswb_strerror(rv));
errcnt_no_topic++;
}
} else {
error("mandatory input \"max\" 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_clamp_interface_inputs_update(core_math_clamp_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*/
}
rv = eswb_read(interface->eswb_descriptors.in_min, &interface->i.min);
if(rv != eswb_e_ok) {
/*FIXME nothing to do yet*/
}
rv = eswb_read(interface->eswb_descriptors.in_max, &interface->i.max);
if(rv != eswb_e_ok) {
/*FIXME nothing to do yet*/
}
return 0;
}
fspec_rv_t core_math_clamp_interface_outputs_init(
core_math_clamp_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_clamp_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_clamp_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_clamp_interface_outputs_update(core_math_clamp_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_clamp_interface_update(core_math_clamp_interface_t *interface)
{
core_math_clamp_interface_inputs_update(interface);
core_math_clamp_exec(&interface->i, &interface->o);
core_math_clamp_interface_outputs_update(interface);
}
fspec_rv_t core_math_clamp_call_init_inputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td
)
{
core_math_clamp_interface_t *interface = (core_math_clamp_interface_t*) dh;
return core_math_clamp_interface_inputs_init(interface, conn_spec, mounting_td);
}
fspec_rv_t core_math_clamp_call_init_outputs(
void *dh,
const func_conn_spec_t *conn_spec,
eswb_topic_descr_t mounting_td,
const char *func_name
)
{
core_math_clamp_interface_t *interface = (core_math_clamp_interface_t*) dh;
return core_math_clamp_interface_outputs_init(interface, conn_spec, mounting_td, func_name);
}
void core_math_clamp_call_exec(void *dh)
{
core_math_clamp_interface_t *interface = (core_math_clamp_interface_t*) dh;
core_math_clamp_interface_update(interface);
}