static int value_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int32_t value; int r; struct segments_ctl_data *mdata = data; if (mdata->needs_clear) { _clear(node); mdata->needs_clear = false; } #define RANGE_MIN (0) #define RANGE_MAX (15) r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); if ((value < RANGE_MIN) || (value > RANGE_MAX)) { sol_flow_send_error_packet(node, ERANGE, "Range invalid, it should be between %d and %d but was %" PRId32, RANGE_MIN, RANGE_MAX, value); return 0; } _write_byte(node, font[value]); return 0; #undef RANGE_MAX #undef RANGE_MIN }
static int abs_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int32_t value, result; int r; r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); result = abs(value); return sol_flow_send_irange_value_packet(node, SOL_FLOW_NODE_TYPE_INT_ABS__OUT__OUT, result); }
static int inrange_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int r; int32_t value; struct sol_irange *mdata = data; r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); return sol_flow_send_boolean_packet(node, SOL_FLOW_NODE_TYPE_INT_INRANGE__OUT__OUT, value >= mdata->min && value <= mdata->max); }
int process_subprocess_signal_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct subprocess_data *mdata = data; int32_t value; int ret; SOL_NULL_CHECK(mdata->fork_run, -EINVAL); ret = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(ret, < 0, ret); sol_platform_linux_fork_run_send_signal(mdata->fork_run, value); return 0; }
static int random_seed_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct random_node_data *mdata = data; int r; int32_t in_value; r = sol_flow_packet_get_irange_value(packet, &in_value); SOL_INT_CHECK(r, < 0, r); sol_random_del(mdata->engine); mdata->engine = sol_random_new(SOL_RANDOM_DEFAULT, in_value); SOL_NULL_CHECK(mdata->engine, -EINVAL); return 0; }
static int irange_buffer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int r; struct irange_buffer_data *mdata = data; r = sol_flow_packet_get_irange_value(packet, &mdata->input_queue[mdata->cur_len]); SOL_INT_CHECK(r, < 0, r); if (mdata->n_samples <= ++mdata->cur_len) { r = _irange_buffer_do(mdata); _reset(data); } return r; }
/* * isodd is a very simplistic type, it only handle a single event and * has no storage/context. All it does is get an integer and send a * boolean true if that number is odd, sending false if it's even. */ static int isodd(struct sol_flow_node *node, const struct sol_flow_simplectype_event *ev, void *data) { int32_t val; int r; /* we only handle events for port input. */ if (ev->type != SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_IN_PROCESS) return 0; /* get the integer value from irange and check if it worked */ r = sol_flow_packet_get_irange_value(ev->packet, &val); if (r < 0) return r; /* we use port index '0' here, after all we have a single port */ return sol_flow_send_boolean_packet(node, 0, (val % 2 != 0)); }
static int duty_cycle_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct servo_motor_data *mdata = data; int r; int32_t in_value; r = sol_flow_packet_get_irange_value(packet, &in_value); SOL_INT_CHECK(r, < 0, r); if (in_value < mdata->duty_cycle_range.min || in_value > mdata->duty_cycle_range.max) { SOL_WRN("Invalid value %" PRId32 "." "It must be >= %" PRId32 " and =< %" PRId32 "", in_value, mdata->duty_cycle_range.min, mdata->duty_cycle_range.max); return -EINVAL; } return set_pulse_width(mdata, in_value); }
static bool comparison_func(struct irange_comparison_data *mdata, struct sol_flow_node *node, uint16_t port, const struct sol_flow_packet *packet, bool *func_ret) { const struct irange_comparison_node_type *type; int r; r = sol_flow_packet_get_irange_value(packet, &mdata->val[port]); SOL_INT_CHECK(r, < 0, r); mdata->val_initialized[port] = true; if (!(mdata->val_initialized[0] && mdata->val_initialized[1])) return false; type = (const struct irange_comparison_node_type *) sol_flow_node_get_type(node); *func_ret = type->func(mdata->val[0], mdata->val[1]); return true; }
static int make_year(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct make_time_data *mdata = data; int32_t value; int r; r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); if (value < 1970) { sol_flow_send_error_packet(node, EINVAL, "Year (%" PRId32 ") out of range. Can't be less than 1970.", value); return 0; } mdata->received_time.tm_year = value - 1900; return send_timestamp(node, port, mdata); }
static int make_nano_second(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct make_time_data *mdata = data; int32_t value; int r; r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); if (value < 0 || value > 999999999) { sol_flow_send_error_packet(node, EINVAL, "Nano second (%" PRId32 ") out of range. Must be from " "0 to 999999999.", value); return 0; } mdata->nsec = value; return send_timestamp(node, port, mdata); }
static int make_minute(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct make_time_data *mdata = data; int32_t value; int r; r = sol_flow_packet_get_irange_value(packet, &value); SOL_INT_CHECK(r, < 0, r); if (value < 0 || value > 59) { sol_flow_send_error_packet(node, EINVAL, "Minute (%" PRId32 ") out of range. Must be from 0 to 59.", value); return 0; } mdata->received_time.tm_min = value; return send_timestamp(node, port, mdata); }
static int min_max_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct irange_min_max_data *mdata = data; int *result; int r; r = sol_flow_packet_get_irange_value(packet, &mdata->val[port]); SOL_INT_CHECK(r, < 0, r); mdata->val_initialized[port] = true; if (!(mdata->val_initialized[0] && mdata->val_initialized[1])) return 0; if (mdata->func(mdata->val[0], mdata->val[1])) result = &mdata->val[0]; else result = &mdata->val[1]; return sol_flow_send_irange_value_packet(node, mdata->port, *result); }
static int value_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int32_t in_value; int r; const int array_size = ARRAY_SIZE(font) - 1; r = sol_flow_packet_get_irange_value(packet, &in_value); SOL_INT_CHECK(r, < 0, r); if ((in_value < 0) || (in_value > array_size)) { sol_flow_send_error_packet(node, ERANGE, "Range invalid, it should be between %d and %d but was %d", 0, array_size, in_value); return 0; } r = write_byte(data, node, font[in_value]); SOL_INT_CHECK(r, < 0, r); return 0; }
static int irange_buffer_timeout(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { int r; int32_t timeout; struct irange_buffer_data *mdata = data; r = sol_flow_packet_get_irange_value(packet, &timeout); SOL_INT_CHECK(r, < 0, r); if (timeout < 0) SOL_WRN("Invalid 'timeout' value: '%" PRId32 "'. Skipping it.", timeout); mdata->timeout = timeout; if (mdata->timer) sol_timeout_del(mdata->timer); if (mdata->timeout) mdata->timer = sol_timeout_add(mdata->timeout, _timeout, mdata); return r; }
static int32_t get_int32_packet_and_log(const struct sol_flow_node *n, uint16_t port, const struct sol_flow_packet *packet) { const struct sol_flow_node_type *type; const struct sol_flow_port_description *port_desc; int32_t value; int err; /* get the struct sol_irange::value member. This function also validates if the * given packet is of requested type (irange), otherise will return an -errno. */ err = sol_flow_packet_get_irange_value(packet, &value); if (err < 0) { fprintf(stderr, "ERROR: could not get irange packet value: %p %s\n", packet, sol_util_strerrora(-err)); return err; } /* log the value to stdout. First we get the node type from * current node (minutes or seconds), then we find the port * description from its index. with that we can get the port name. */ type = sol_flow_node_get_type(n); port_desc = sol_flow_node_get_port_out_description(type, port); if (!port_desc) { fprintf(stderr, "ERROR: no output port description for index %" PRIu16 " of node %p\n", port, n); return -ENOENT; } printf("node type %s port #%" PRIu16 " '%s' (%s): %" PRId32 "\n", type->description->name, port, port_desc->name, port_desc->data_type, value); return value; }
static int mytype_func(struct sol_flow_node *node, const struct sol_flow_simplectype_event *ev, void *data) { struct mytype_context *ctx = data; switch (ev->type) { case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_OPEN: { if (ev->options #ifndef SOL_NO_API_VERSION && ev->options->sub_api == MYTYPE_OPTIONS_SUB_API #endif ) { struct mytype_options *opt = (struct mytype_options *)ev->options; ctx->someint = opt->someint; ctx->somebool = opt->somebool; } /* every 500ms send out a string representing our someint + somebool */ ctx->timer = sol_timeout_add(500, on_timeout, node); if (!ctx->timer) return -ENOMEM; printf("simplectype opened ctx=%p, someint=%d, somebool=%d\n", ctx, ctx->someint, ctx->somebool); return 0; } case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_CLOSE: { printf("simplectype closed ctx=%p\n", ctx); sol_timeout_del(ctx->timer); return 0; } case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_IN_PROCESS: { /* this is to show the port names, ideally one would keep the * indexes and use them here, doing integer comparisons * instead of strcmp() */ if (strcmp(ev->port_name, "IRANGE") == 0) { int32_t val; if (sol_flow_packet_get_irange_value(ev->packet, &val) == 0) { printf("simplectype updated integer from %d to %d\n", ctx->someint, val); ctx->someint = val; return 0; } } else if (strcmp(ev->port_name, "BOOLEAN") == 0) { bool val; if (sol_flow_packet_get_boolean(ev->packet, &val) == 0) { printf("simplectype updated boolean from %d to %d\n", ctx->somebool, val); ctx->somebool = val; return 0; } } printf("simplectype port '%s' got unexpected data!\n", ev->port_name); return -EINVAL; } case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_IN_CONNECT: printf("simplectype port IN '%s' id=%d conn=%d connected ctx=%p\n", ev->port_name, ev->port, ev->conn_id, ctx); return 0; case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_IN_DISCONNECT: printf("simplectype port IN '%s' id=%d conn=%d disconnected ctx=%p\n", ev->port_name, ev->port, ev->conn_id, ctx); return 0; case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_OUT_CONNECT: printf("simplectype port OUT '%s' id=%d conn=%d connected ctx=%p\n", ev->port_name, ev->port, ev->conn_id, ctx); return 0; case SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_PORT_OUT_DISCONNECT: printf("simplectype port OUT '%s' id=%d conn=%d disconnected ctx=%p\n", ev->port_name, ev->port, ev->conn_id, ctx); return 0; } return -EINVAL; }