samples: zbus: fix samples to work with iterable sections observers
Replace the `CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE` with the `CONFIG_ZBUS_RUNTIME_OBSERVERS` and add the heap. Add user_data to hello world sample iterator functions. Signed-off-by: Rodrigo Peixoto <rodrigopex@gmail.com>
This commit is contained in:
parent
6880b8501d
commit
4d80338132
|
@ -6,3 +6,4 @@ CONFIG_ZBUS=y
|
|||
CONFIG_ZBUS_LOG_LEVEL_INF=y
|
||||
CONFIG_ZBUS_CHANNEL_NAME=y
|
||||
CONFIG_ZBUS_OBSERVER_NAME=y
|
||||
CONFIG_ZBUS_RUNTIME_OBSERVERS=y
|
||||
|
|
|
@ -26,25 +26,7 @@ tests:
|
|||
- "I: From listener -> Acc x=2, y=2, z=2"
|
||||
- "I: Pub a valid value to a channel with validator successfully."
|
||||
- "I: Pub an invalid value to a channel with validator successfully."
|
||||
arch_exclude:
|
||||
- xtensa
|
||||
platform_exclude: qemu_leon3
|
||||
tags: zbus
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
sample.zbus.hello_world_no_iterable_sections:
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
ordered: false
|
||||
regex:
|
||||
- "I: Sensor sample started raw reading, version 0.1-2!"
|
||||
- "I: From subscriber -> Acc x=1, y=1, z=1"
|
||||
- "I: From listener -> Acc x=1, y=1, z=1"
|
||||
- "I: From subscriber -> Acc x=2, y=2, z=2"
|
||||
- "I: From listener -> Acc x=2, y=2, z=2"
|
||||
- "I: Pub a valid value to a channel with validator successfully."
|
||||
- "I: Pub an invalid value to a channel with validator successfully."
|
||||
arch_allow:
|
||||
- xtensa
|
||||
tags: zbus
|
||||
|
|
|
@ -22,21 +22,21 @@ struct acc_msg {
|
|||
int z;
|
||||
};
|
||||
|
||||
ZBUS_CHAN_DEFINE(version_chan, /* Name */
|
||||
ZBUS_CHAN_DEFINE(version_chan, /* Name */
|
||||
struct version_msg, /* Message type */
|
||||
|
||||
NULL, /* Validator */
|
||||
NULL, /* User data */
|
||||
NULL, /* Validator */
|
||||
NULL, /* User data */
|
||||
ZBUS_OBSERVERS_EMPTY, /* observers */
|
||||
ZBUS_MSG_INIT(.major = 0, .minor = 1,
|
||||
.build = 2) /* Initial value major 0, minor 1, build 2 */
|
||||
);
|
||||
|
||||
ZBUS_CHAN_DEFINE(acc_data_chan, /* Name */
|
||||
ZBUS_CHAN_DEFINE(acc_data_chan, /* Name */
|
||||
struct acc_msg, /* Message type */
|
||||
|
||||
NULL, /* Validator */
|
||||
NULL, /* User data */
|
||||
NULL, /* Validator */
|
||||
NULL, /* User data */
|
||||
ZBUS_OBSERVERS(foo_lis, bar_sub), /* observers */
|
||||
ZBUS_MSG_INIT(.x = 0, .y = 0, .z = 0) /* Initial value */
|
||||
);
|
||||
|
@ -55,12 +55,12 @@ static bool simple_chan_validator(const void *msg, size_t msg_size)
|
|||
}
|
||||
|
||||
ZBUS_CHAN_DEFINE(simple_chan, /* Name */
|
||||
int, /* Message type */
|
||||
int, /* Message type */
|
||||
|
||||
simple_chan_validator, /* Validator */
|
||||
NULL, /* User data */
|
||||
ZBUS_OBSERVERS_EMPTY, /* observers */
|
||||
0 /* Initial value is 0 */
|
||||
NULL, /* User data */
|
||||
ZBUS_OBSERVERS_EMPTY, /* observers */
|
||||
0 /* Initial value is 0 */
|
||||
);
|
||||
|
||||
static void listener_callback_example(const struct zbus_channel *chan)
|
||||
|
@ -89,34 +89,51 @@ static void subscriber_task(void)
|
|||
}
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(subscriber_task_id, CONFIG_MAIN_STACK_SIZE,
|
||||
subscriber_task, NULL, NULL, NULL, 3, 0, 0);
|
||||
K_THREAD_DEFINE(subscriber_task_id, CONFIG_MAIN_STACK_SIZE, subscriber_task, NULL, NULL, NULL, 3, 0,
|
||||
0);
|
||||
|
||||
#if defined(CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS)
|
||||
static int count;
|
||||
|
||||
static bool print_channel_data_iterator(const struct zbus_channel *chan)
|
||||
static bool print_channel_data_iterator(const struct zbus_channel *chan, void *user_data)
|
||||
{
|
||||
LOG_INF("%d - Channel %s:", count, zbus_chan_name(chan));
|
||||
int *count = user_data;
|
||||
|
||||
LOG_INF("%d - Channel %s:", *count, zbus_chan_name(chan));
|
||||
LOG_INF(" Message size: %d", zbus_chan_msg_size(chan));
|
||||
++count;
|
||||
LOG_INF(" Observers:");
|
||||
for (const struct zbus_observer *const *obs = chan->observers; *obs != NULL; ++obs) {
|
||||
LOG_INF(" - %s", (*obs)->name);
|
||||
|
||||
++(*count);
|
||||
|
||||
struct zbus_channel_observation *observation;
|
||||
|
||||
for (int16_t i = chan->data->observers_start_idx, limit = chan->data->observers_end_idx;
|
||||
i < limit; ++i) {
|
||||
STRUCT_SECTION_GET(zbus_channel_observation, i, &observation);
|
||||
|
||||
__ASSERT(observation != NULL, "observation must be not NULL");
|
||||
|
||||
LOG_INF(" - %s", observation->obs->name);
|
||||
}
|
||||
|
||||
struct zbus_observer_node *obs_nd, *tmp;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&chan->data->observers, obs_nd, tmp, node) {
|
||||
LOG_INF(" - %s", obs_nd->obs->name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool print_observer_data_iterator(const struct zbus_observer *obs)
|
||||
static bool print_observer_data_iterator(const struct zbus_observer *obs, void *user_data)
|
||||
{
|
||||
LOG_INF("%d - %s %s", count, obs->queue ? "Subscriber" : "Listener", zbus_obs_name(obs));
|
||||
int *count = user_data;
|
||||
|
||||
++count;
|
||||
LOG_INF("%d - %s %s", *count,
|
||||
obs->type == ZBUS_OBSERVER_LISTENER_TYPE ? "Listener" : "Subscriber",
|
||||
zbus_obs_name(obs));
|
||||
|
||||
++(*count);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif /* CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
@ -127,17 +144,15 @@ int main(void)
|
|||
LOG_INF("Sensor sample started raw reading, version %u.%u-%u!", v->major, v->minor,
|
||||
v->build);
|
||||
|
||||
#if defined(CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS)
|
||||
count = 0;
|
||||
int count = 0;
|
||||
|
||||
LOG_INF("Channel list:");
|
||||
zbus_iterate_over_channels(print_channel_data_iterator);
|
||||
zbus_iterate_over_channels_with_user_data(print_channel_data_iterator, &count);
|
||||
|
||||
count = 0;
|
||||
|
||||
LOG_INF("Observers list:");
|
||||
zbus_iterate_over_observers(print_observer_data_iterator);
|
||||
#endif
|
||||
zbus_iterate_over_observers_with_user_data(print_observer_data_iterator, &count);
|
||||
zbus_chan_pub(&acc_data_chan, &acc1, K_SECONDS(1));
|
||||
|
||||
k_msleep(1000);
|
||||
|
|
|
@ -4,5 +4,6 @@ CONFIG_LOG_MODE_MINIMAL=y
|
|||
CONFIG_BOOT_BANNER=n
|
||||
CONFIG_ZBUS=y
|
||||
CONFIG_ZBUS_LOG_LEVEL_INF=y
|
||||
CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE=2
|
||||
CONFIG_ZBUS_RUNTIME_OBSERVERS=y
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=256
|
||||
CONFIG_MP_MAX_NUM_CPUS=1
|
||||
|
|
|
@ -5,6 +5,7 @@ tests:
|
|||
min_ram: 16
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
arch_exclude: nios2
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
|
|
Loading…
Reference in a new issue