21#include "rte/status/rte_status.h"
50 uint8_t emergency_stop;
61 uint32_t vital_commands_received;
62 uint32_t feedback_messages_received;
63 uint32_t telemetry_messages_received;
64 uint32_t config_updates_applied;
76#define MAX_CHANNELS 16
99 if (g_channel_registry.count >= MAX_CHANNELS) {
105 entry->callback = callback;
106 entry->context = context;
108 g_channel_registry.count++;
109 printf(
"✓ Registered channel: %s\n", name);
118 for (uint32_t i = 0; i < g_channel_registry.count; i++) {
119 if (strcmp(g_channel_registry.channels[i].name, name) == 0) {
120 return &g_channel_registry.channels[i];
144 printf(
"\n[CALLBACK] Channel: %s\n", channel_name);
145 printf(
" Data size: %zu bytes\n", data_size);
149 printf(
"✗ ERROR: Invalid command size on %s\n", channel_name);
155 printf(
" Command ID: %u\n", cmd->command_id);
156 printf(
" Speed: %u km/h\n", cmd->speed_kmh);
157 printf(
" E-Stop: %s\n", cmd->emergency_stop ?
"YES" :
"NO");
160 app->last_command = *cmd;
161 app->vital_commands_received++;
164 printf(
"✓ Vital command processed (total received: %u)\n",
165 app->vital_commands_received);
181 printf(
"\n[CALLBACK] Channel: %s\n", channel_name);
182 printf(
" Data size: %zu bytes\n", data_size);
185 printf(
"✗ ERROR: Invalid status size on %s\n", channel_name);
190 printf(
" Status code: %u\n", status->status_code);
191 printf(
" Healthy: %s\n", status->is_healthy ?
"YES" :
"NO");
192 printf(
" Error count: %u\n", status->error_count);
195 app->standby_status = *status;
196 app->feedback_messages_received++;
199 if (!status->is_healthy) {
200 printf(
"⚠️ WARNING: Standby unhealthy on %s\n", channel_name);
203 if (status->error_count > 10) {
204 printf(
"⚠️ WARNING: High error count on %s\n", channel_name);
207 printf(
"✓ Feedback processed (total received: %u)\n",
208 app->feedback_messages_received);
224 printf(
"\n[CALLBACK] Channel: %s\n", channel_name);
225 printf(
" Telemetry size: %zu bytes\n", data_size);
228 app->telemetry_messages_received++;
229 printf(
"✓ Telemetry logged (total received: %u)\n",
230 app->telemetry_messages_received);
246 printf(
"\n[CALLBACK] Channel: %s\n", channel_name);
247 printf(
" Config size: %zu bytes\n", data_size);
251 printf(
"✗ ERROR: Invalid config on %s\n", channel_name);
256 app->config_updates_applied++;
257 printf(
"✓ Configuration applied from %s (total: %u)\n",
258 channel_name, app->config_updates_applied);
275 printf(
"\n=== DATA ARRIVING ON CHANNEL ===\n");
280 printf(
"✗ Channel not found: %s\n", channel_name);
286 ch->callback(channel_name, data, size, ch->context);
296 printf(
"========================================\n");
297 printf(
"Channel Callbacks Example\n");
298 printf(
"========================================\n");
302 .vital_commands_received = 0,
303 .feedback_messages_received = 0,
304 .telemetry_messages_received = 0,
305 .config_updates_applied = 0,
313 printf(
"\n--- STEP 1: Register Named Channels ---\n");
317 "online_to_standby_vital",
324 "standby_to_online_feedback",
331 "online_to_diag_telemetry",
338 "config_update_channel",
343 printf(
"\nAll channels registered. Waiting for events...\n");
349 printf(
"\n--- STEP 2: Simulate Channel Events ---\n");
368 uint8_t telemetry_data[100] = {0x42, 0x43};
372 cmd.command_id = 1002;
377 uint8_t config_data[32] = {0xAA, 0xBB};
381 status.is_healthy =
false;
382 status.error_count = 15;
389 printf(
"\n--- STEP 3: Metrics Summary ---\n");
390 printf(
"Vital commands received: %u\n", app.vital_commands_received);
391 printf(
"Feedback messages received: %u\n", app.feedback_messages_received);
392 printf(
"Telemetry messages received: %u\n", app.telemetry_messages_received);
393 printf(
"Config updates applied: %u\n", app.config_updates_applied);
395 printf(
"\nLast command: ID=%u, Speed=%u km/h, E-Stop=%s\n",
396 app.last_command.command_id,
397 app.last_command.speed_kmh,
398 app.last_command.emergency_stop ?
"YES" :
"NO");
400 printf(
"Standby status: Healthy=%s, Errors=%u\n",
401 app.standby_status.is_healthy ?
"YES" :
"NO",
402 app.standby_status.error_count);
404 printf(
"\n========================================\n");
405 printf(
"Key Takeaways\n");
406 printf(
"========================================\n");
407 printf(
"✓ Each channel has a unique name\n");
408 printf(
"✓ Callbacks are registered at startup\n");
409 printf(
"✓ OS osadapter calls callback when data arrives\n");
410 printf(
"✓ Callback identifies channel by name\n");
411 printf(
"✓ No polling needed (event-driven)\n");
412 printf(
"✓ Easy to add/remove channels\n");
413 printf(
"✓ Easy to log and monitor by channel name\n");
void on_telemetry_received(const char *channel_name, const void *data, size_t data_size, void *context)
Callback: Telemetry received.
rte_status_t channel_registry_register(const char *name, rte_channel_callback_t callback, void *context)
Register a named channel with callback.
void on_standby_feedback_received(const char *channel_name, const void *data, size_t data_size, void *context)
Callback: Standby feedback/health received.
void simulate_channel_data(const char *channel_name, const void *data, size_t size)
Simulate data arriving on a channel.
channel_registry_entry_t * channel_registry_find(const char *name)
Find channel by name.
void on_vital_command_received(const char *channel_name, const void *data, size_t data_size, void *context)
Callback: Vital command received on channel.
void on_config_update_received(const char *channel_name, const void *data, size_t data_size, void *context)
Callback: Configuration update received.
void(*) rte_channel_callback_t(const char *channel_name, const void *data, size_t data_size, void *context)
Callback invoked when data is available on a channel.
rte_status_t
Common result/status codes.
@ RTE_STATUS_RESOURCE_EXHAUSTED