22#include "rte/channel_link/rte_channel.h"
23#include "rte/voter/rte_voter.h"
24#include "rte/status/rte_status.h"
36 const char *remote_ip;
51 const char *remote_ip;
63 const char *descriptor_path;
75 const char *fifo_path;
114 if (wrapper == NULL) {
118 switch (wrapper->type) {
119 case CHANNEL_TYPE_TCP:
122 printf(
"[TCP] Sending %zu bytes\n", size);
125 case CHANNEL_TYPE_UDP:
128 printf(
"[UDP] Sending %zu bytes\n", size);
131 case CHANNEL_TYPE_SHM:
134 printf(
"[SHM] Sending %zu bytes\n", size);
137 case CHANNEL_TYPE_FIFO:
140 printf(
"[FIFO] Sending %zu bytes\n", size);
157 if (wrapper == NULL) {
161 switch (wrapper->type) {
162 case CHANNEL_TYPE_TCP:
165 printf(
"[TCP] Receiving up to %zu bytes (timeout %ums)\n", size, timeout_ms);
168 case CHANNEL_TYPE_UDP:
171 printf(
"[UDP] Receiving up to %zu bytes (timeout %ums)\n", size, timeout_ms);
174 case CHANNEL_TYPE_SHM:
177 printf(
"[SHM] Receiving up to %zu bytes (timeout %ums)\n", size, timeout_ms);
180 case CHANNEL_TYPE_FIFO:
183 printf(
"[FIFO] Receiving up to %zu bytes (timeout %ums)\n", size, timeout_ms);
195void example_tcp_based_redundancy(
void)
197 printf(
"\n=== Example 1: TCP/IP Based Online/Standby ===\n");
203 printf(
"\n[ONLINE HOST] Configuration:\n");
207 .name =
"online_to_standby_tcp",
208 .remote_ip =
"192.168.1.100",
212 .server_mode =
false,
215 printf(
" ✓ TCP Config: %s → %s:%u\n", tcp_config_online.name,
216 tcp_config_online.remote_ip, tcp_config_online.remote_port);
217 printf(
" Timeout: %ums\n", tcp_config_online.timeout_ms);
221 .name =
"online_heartbeat_udp",
222 .local_ip =
"192.168.1.50",
224 .remote_ip =
"192.168.1.100",
230 printf(
" ✓ UDP Config: %s (heartbeat)\n", udp_config_online.name);
231 printf(
" Local: %s:%u\n", udp_config_online.local_ip, udp_config_online.local_port);
232 printf(
" Remote: %s:%u\n", udp_config_online.remote_ip, udp_config_online.remote_port);
239 .type = CHANNEL_TYPE_TCP,
240 .impl = (
void *)0x1000,
245 .type = CHANNEL_TYPE_UDP,
246 .impl = (
void *)0x2000,
253 .channel_timeout_ms = 1000,
254 .log_disagreements =
true,
255 .on_disagreement = NULL,
256 .disagreement_context = NULL,
265 .channel_handle = &online_ch0,
270 .channel_handle = &online_ch1,
287 printf(
" ✓ Voter (2oo2) initialized over 2 channels\n");
289 printf(
" ✗ Failed to initialize channels/voter\n");
297 printf(
"\n[STANDBY HOST] Configuration:\n");
301 .name =
"standby_listen_tcp",
302 .remote_ip =
"0.0.0.0",
309 printf(
" ✓ TCP Config: %s (listening)\n", tcp_config_standby.name);
310 printf(
" Listen: %s:%u\n", tcp_config_standby.remote_ip, tcp_config_standby.remote_port);
314 .name =
"standby_heartbeat_udp",
315 .local_ip =
"192.168.1.100",
317 .remote_ip =
"192.168.1.50",
323 printf(
" ✓ UDP Config: %s (receiving)\n", udp_config_standby.name);
324 printf(
" Listen: %s:%u\n", udp_config_standby.local_ip, udp_config_standby.local_port);
328 .type = CHANNEL_TYPE_TCP,
329 .impl = (
void *)0x3000,
334 .type = CHANNEL_TYPE_UDP,
335 .impl = (
void *)0x4000,
345 .channel_handle = &standby_ch0,
350 .channel_handle = &standby_ch1,
367 printf(
" ✓ Voter (2oo2) initialized over 2 channels\n");
374 printf(
"\n[COMMUNICATION] Simulated voting:\n");
376 uint8_t command[256] = {0x42};
378 printf(
" 1. Online broadcasts command via the voter...\n");
380 printf(
" Result: %d (broadcasts via TCP + UDP)\n", rc);
382 printf(
" 2. Standby receives and votes...\n");
383 uint8_t received[256] = {0};
385 size_t bytes_received = 0;
387 printf(
" Result: %d, Voting: %d\n", rc, vote);
389 printf(
" 3. Check health...\n");
392 printf(
" Channel 0 health: sends=%u, errors=%u\n",
400void example_local_redundancy(
void)
402 printf(
"\n=== Example 2: Local Shared Memory (Optional For Same-Board) ===\n");
406 .name =
"vital_ab_shared",
407 .descriptor_path =
"/dev/shm/rail_vital_ab",
413 printf(
" Shared Memory Config:\n");
414 printf(
" Path: %s\n", shm_config.descriptor_path);
415 printf(
" Queue: %zu messages × %zu bytes\n",
416 shm_config.queue_depth, shm_config.message_size);
417 printf(
" Timeout: %ums\n", shm_config.timeout_ms);
420 .type = CHANNEL_TYPE_SHM,
421 .impl = (
void *)0x5000,
425 printf(
" ✓ Channel created\n");
432void example_hybrid_configuration(
void)
434 printf(
"\n=== Example 3: Hybrid (TCP Primary, Local SHM Fallback) ===\n");
435 printf(
" For maximum flexibility: use TCP for remote, SHM for local\n");
436 printf(
" Dispatcher handles both transparently\n");
448 printf(
"========================================\n");
449 printf(
"Channel Configuration Examples\n");
450 printf(
"========================================\n");
452 example_tcp_based_redundancy();
453 example_local_redundancy();
454 example_hybrid_configuration();
456 printf(
"\n========================================\n");
457 printf(
"Configuration Complete\n");
458 printf(
"========================================\n");
459 printf(
"\nKey Points:\n");
460 printf(
" ✓ User provides configuration values (IPs, ports, paths)\n");
461 printf(
" ✓ Framework handles voting and health tracking\n");
462 printf(
" ✓ OS integrator implements actual I/O (send/recv)\n");
463 printf(
" ✓ Dispatcher routes to correct transport\n");
464 printf(
" ✓ Same channel/voter code works with ANY transport\n");
static rte_status_t app_backend_send(void *channel, const void *data, size_t size)
Dispatcher send callback Routes to appropriate transport based on channel type.
static rte_status_t app_backend_recv(void *channel, void *data, size_t size, uint32_t timeout_ms)
Dispatcher receive callback Routes to appropriate transport based on channel type.
rte_status_t
Common result/status codes.
@ RTE_STATUS_INVALID_PARAM
rte_status_t rte_channel_get_health(const rte_channel_t *handle, rte_channel_health_t *out_health)
Queries this channel's health statistics.
rte_channel_storage_t rte_channel_t
Opaque handle to a vital channel instance.
rte_status_t rte_channel_init(rte_channel_storage_t *storage, const rte_channel_config_t *config)
Initializes one vital channel over a caller-supplied transport.
rte_voter_storage_t rte_voter_t
Opaque handle to a voter instance.
rte_status_t rte_voter_register_channel(rte_voter_t *voter, rte_channel_t *channel)
Registers one already-initialized channel with this voter.
rte_voting_result_t
Outcome of one rte_voter_receive() call.
rte_status_t rte_voter_send(rte_voter_t *voter, const void *data, size_t data_size)
Broadcasts data to every registered, healthy channel.
rte_status_t rte_voter_init(rte_voter_storage_t *storage, const rte_voter_config_t *config)
Initializes a voter with zero registered channels.
rte_status_t rte_voter_receive(rte_voter_t *voter, void *data, size_t data_size, rte_voting_result_t *result, size_t *bytes_received)
Receives from every registered, healthy channel and votes.
Configuration for rte_channel_init().
Health statistics for one vital channel.
uint32_t send_error_count
Configuration for rte_voter_init().