Skip to content

Commit

Permalink
ubxcore: introduce block attributes ACTIVE and TRIGGER
Browse files Browse the repository at this point in the history
the first block attributes describe whether a block is a trigger
or/and whether it is active (i.e. spawns a thread internally like
ptrig or webif). This information is useful in different circumstances
such as for determining startup and shutdown order by ubx_launch.

Suggested-by: Enea Scioni <enea.scioni@kuleuven.be>
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
  • Loading branch information
kmarkus committed Nov 14, 2019
1 parent 35dfc40 commit 0cd29e8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions API_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ This file tracks user visible API changes.

## Unreleased

- struct ubx_block: added attributes variable (`attrs`) and defined
first block attributes (`BLOCK_ATTR_TRIGGER` and
`BLOCK_ATTR_ACTIVE`). These will be used by tools such as
ubx_launch, so blocks should be updated to define these
appropriately.

- blockdiagram.load: change to return `system` or fail and exit

- rtlog: enable gcc format checking. This checks the provided
Expand Down
1 change: 1 addition & 0 deletions libubx/ubx.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ static ubx_block_t* ubx_block_clone(ubx_block_t* prot, const char* name)

/* copy attributes of prototype */
newb->type = prot->type;
newb->attrs = prot->attrs;

if((newb->name=strdup(name))==NULL) goto out_free;
if((newb->meta_data=strdup(prot->meta_data))==NULL) goto out_free;
Expand Down
10 changes: 9 additions & 1 deletion libubx/ubx_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef struct ubx_config
} ubx_config_t;

enum {
CONFIG_ATTR_RDWR = 0<<0,
CONFIG_ATTR_RDWR = 0,
CONFIG_ATTR_RDONLY = 1<<0
};

Expand All @@ -186,6 +186,13 @@ enum {
BLOCK_TYPE_INTERACTION
};

/* Block attributes */
enum {
BLOCK_ATTR_TRIGGER = 1<<0, /* block is a trigger */
BLOCK_ATTR_ACTIVE = 1<<1, /* block is active (has a thread) */
};

/* block states */
enum {
BLOCK_STATE_PREINIT,
BLOCK_STATE_INACTIVE,
Expand All @@ -198,6 +205,7 @@ typedef struct ubx_block
const char* name; /* type name */
const char* meta_data; /* doc, etc. */
uint32_t type; /* type, (computation, interaction) */
uint32_t attrs; /* attributes */

ubx_port_t* ports;
ubx_config_t* configs;
Expand Down
30 changes: 24 additions & 6 deletions lua/ubx.lua.source
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
--

local ffi=require "ffi"
local bit=require "bit"
local cdata = require "cdata"
local utils= require "utils"
local ts=tostring
Expand Down Expand Up @@ -100,6 +101,11 @@ local function setup_enums()
[ffi.C.BLOCK_STATE_INACTIVE]='inactive',
[ffi.C.BLOCK_STATE_ACTIVE]='active'
}

M.block_attrs_tostr={
[ffi.C.BLOCK_ATTR_TRIGGER]='trigger',
[ffi.C.BLOCK_ATTR_ACTIVE]='active',
}
end

-- load ubx_types and library
Expand Down Expand Up @@ -144,7 +150,7 @@ void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
]]
]]

local prefix=find_prefix()
load_ubx_ffi(prefix)
Expand Down Expand Up @@ -477,6 +483,13 @@ local function block_state_color(sstr)
end
end

local function block_attr_totab(b)
local t = {}
if bit.band(b.attrs, ffi.C.BLOCK_ATTR_TRIGGER) ~= 0 then t[#t+1] = "trigger" end
if bit.band(b.attrs, ffi.C.BLOCK_ATTR_ACTIVE) ~= 0 then t[#t+1] = "active" end
return t
end

--- Convert block to lua table
-- @param b block to convert to table
-- @return table
Expand All @@ -485,6 +498,7 @@ function M.block_totab(b)

local res = {}
res.name = M.safe_tostr(b.name)
res.attrs = block_attr_totab(b)
res.meta_data = M.safe_tostr(b.meta_data)
res.block_type=M.block_type_tostr[b.type]
res.state = M.block_state_tostr[b.block_state]
Expand Down Expand Up @@ -517,11 +531,14 @@ function M.block_pp(b)

if M.is_block(b) then bt = M.block_totab(b) else bt = b end

local fmt = "%s (type=%s, state=%s, prototype=%s)"
local fmt = "%s [state: %s, steps: %u] (type: %s, prototype: %s, attrs: %s)"

res[#res+1] = fmt:format(green(bt.name), bt.block_type,
res[#res+1] = fmt:format(green(bt.name),
block_state_color(bt.state),
blue(bt.prototype), bt.stat_num_steps)
bt.stat_num_steps,
bt.block_type,
blue(bt.prototype),
table.concat(bt.attrs, ', '))

if #bt.ports > 0 then
res[#res+1] = (" ports:")
Expand Down Expand Up @@ -551,11 +568,12 @@ function M.block_tostr(b)
return ("%s [%s]"):format(green(bt.name), bt.block_type)
end

return ("%s [%s, %s, %s]"):format(
return ("%s [%s, %s, %s, attrs: %s]"):format(
green(bt.name),
bt.block_type,
block_state_color(bt.state),
blue(bt.prototype))
blue(bt.prototype),
table.concat(bt.attrs, ', '))
end

function M.block_port_get (b, n)
Expand Down
1 change: 1 addition & 0 deletions std_blocks/ptrig/ptrig.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ static void ptrig_cleanup(ubx_block_t *b)
ubx_block_t ptrig_comp = {
.name = "std_triggers/ptrig",
.type = BLOCK_TYPE_COMPUTATION,
.attrs = BLOCK_ATTR_TRIGGER | BLOCK_ATTR_ACTIVE,
.meta_data = ptrig_meta,

.configs = ptrig_config,
Expand Down
1 change: 1 addition & 0 deletions std_blocks/trig/trig.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void trig_cleanup(ubx_block_t *b)
ubx_block_t trig_comp = {
.name = "std_triggers/trig",
.type = BLOCK_TYPE_COMPUTATION,
.attrs = BLOCK_ATTR_TRIGGER,
.meta_data = trig_meta,
.configs = trig_config,
.ports = trig_ports,
Expand Down
1 change: 1 addition & 0 deletions std_blocks/webif/webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ static void wi_stop(ubx_block_t *c)
ubx_block_t webif_comp = {
.name = "webif/webif",
.type = BLOCK_TYPE_COMPUTATION,
.attrs = BLOCK_ATTR_ACTIVE,
.meta_data = wi_meta,
.configs = webif_conf,

Expand Down

0 comments on commit 0cd29e8

Please sign in to comment.