Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
vital_channel_dual_transport.c File Reference

Example: Voted Channel with Dual Transport (Shared Memory + TCP/IP). More...

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "rte/channel_link/rte_channel.h"
#include "rte/voter/rte_voter.h"
#include "rte/status/rte_status.h"
Include dependency graph for vital_channel_dual_transport.c:

Go to the source code of this file.

Data Structures

struct  shm_queue_t
struct  tcp_channel_t
struct  multi_transport_channel_t
struct  train_command_t

Macros

#define CHANNEL_COUNT   2U

Enumerations

enum  channel_type_t { CHANNEL_TYPE_SHARED_MEMORY , CHANNEL_TYPE_TCP }
 Opaque channel type that hides whether it's SHM or TCP. More...

Functions

static rte_status_t shm_send (shm_queue_t *q, const void *data, size_t size)
static rte_status_t shm_recv (shm_queue_t *q, void *data, size_t size)
static rte_status_t tcp_send (tcp_channel_t *ch, const void *data, size_t size)
static rte_status_t tcp_recv (tcp_channel_t *ch, void *data, size_t size)
static rte_status_t channel_backend_send (void *channel_handle, const void *data, size_t size)
 OSAdapter send callback for rte_channel (dispatches to transport).
static rte_status_t channel_backend_recv (void *channel_handle, void *data, size_t size, uint32_t timeout_ms __attribute__((unused)))
 OSAdapter receive callback for rte_channel (dispatches to transport).
static rte_status_t example_setup_dual_redundancy (rte_channel_t channels[CHANNEL_COUNT], rte_voter_t *voter)
 Example: Initialize dual-transport channels plus a 2oo2 voter.
static rte_status_t send_train_command (rte_voter_t *voter, const train_command_t *cmd)
 Send a train command to every registered channel (atomic broadcast).
static rte_status_t receive_train_command (rte_voter_t *voter, train_command_t *cmd_out)
 Receive a train command via the voter (with 2oo2 voting).
static void monitor_channel_health (rte_channel_t channels[CHANNEL_COUNT], rte_voter_t *voter)
 Monitor channel health and detect faults.
int main (void)
 Main example.

Variables

static shm_queue_t shm_queue_0 = {0}
static tcp_channel_t tcp_ch_0 = {.socket = 0, .connected = true}
static multi_transport_channel_t g_channel_0
static multi_transport_channel_t g_channel_1

Detailed Description

Example: Voted Channel with Dual Transport (Shared Memory + TCP/IP).

Demonstrates how to:

  1. Create two redundant communication links using different transports
  2. Register them into a rte_voter_t for 2oo2 voting/redundancy (ADR-025)
  3. Support user selection of online/standby channel configurations
  4. Monitor health for fault detection

This pattern enables:

  • Online process communicates via fast shared memory to local standby
  • Online process communicates via TCP to remote standby (fallback)
  • Voting ensures data consistency across both standbies
  • If one channel fails, voting detects and triggers safe-state

ADR-025 split what used to be a single "vital channel" type (one transport handle + built-in N-way voting) into rte_channel (one link) plus rte_voter (voting across N registered links). This example registers one rte_channel_t per transport into one rte_voter_t configured for RTE_VOTING_2OO2.

Compile: gcc -std=c99 -Wall -Wextra -o vital_dual_transport \ vital_channel_dual_transport.c \ -I../include -L../build -lrte_channels -lrte_oal \ -lrte_core

Definition in file vital_channel_dual_transport.c.

Macro Definition Documentation

◆ CHANNEL_COUNT

#define CHANNEL_COUNT   2U

Definition at line 241 of file vital_channel_dual_transport.c.

Enumeration Type Documentation

◆ channel_type_t

enum channel_type_t

Opaque channel type that hides whether it's SHM or TCP.

This allows each rte_channel_t to wrap ANY transport. The callback functions dispatch based on channel type.

Definition at line 151 of file vital_channel_dual_transport.c.

Function Documentation

◆ shm_send()

rte_status_t shm_send ( shm_queue_t * q,
const void * data,
size_t size )
static

Definition at line 54 of file vital_channel_dual_transport.c.

◆ shm_recv()

rte_status_t shm_recv ( shm_queue_t * q,
void * data,
size_t size )
static

Definition at line 71 of file vital_channel_dual_transport.c.

◆ tcp_send()

rte_status_t tcp_send ( tcp_channel_t * ch,
const void * data,
size_t size )
static

Definition at line 101 of file vital_channel_dual_transport.c.

◆ tcp_recv()

rte_status_t tcp_recv ( tcp_channel_t * ch,
void * data,
size_t size )
static

Definition at line 121 of file vital_channel_dual_transport.c.

◆ channel_backend_send()

rte_status_t channel_backend_send ( void * channel_handle,
const void * data,
size_t size )
static

OSAdapter send callback for rte_channel (dispatches to transport).

Called by rte_channel_send() for one link. The callback hides the specific transport implementation.

Definition at line 180 of file vital_channel_dual_transport.c.

◆ channel_backend_recv()

rte_status_t channel_backend_recv ( void * channel_handle,
void * data,
size_t size,
uint32_t timeout_ms __attribute__(unused) )
static

OSAdapter receive callback for rte_channel (dispatches to transport).

Called by rte_channel_receive() for one link. The callback hides the specific transport implementation.

Definition at line 206 of file vital_channel_dual_transport.c.

◆ example_setup_dual_redundancy()

rte_status_t example_setup_dual_redundancy ( rte_channel_t channels[CHANNEL_COUNT],
rte_voter_t * voter )
static

Example: Initialize dual-transport channels plus a 2oo2 voter.

Configuration:

  • Channel 0: Shared Memory (fast, local standby)
  • Channel 1: TCP/IP (remote standby, reliable backup)
  • Voting: 2oo2 (both must agree)

Definition at line 251 of file vital_channel_dual_transport.c.

◆ send_train_command()

rte_status_t send_train_command ( rte_voter_t * voter,
const train_command_t * cmd )
static

Send a train command to every registered channel (atomic broadcast).

Definition at line 300 of file vital_channel_dual_transport.c.

◆ receive_train_command()

rte_status_t receive_train_command ( rte_voter_t * voter,
train_command_t * cmd_out )
static

Receive a train command via the voter (with 2oo2 voting).

Definition at line 321 of file vital_channel_dual_transport.c.

◆ monitor_channel_health()

void monitor_channel_health ( rte_channel_t channels[CHANNEL_COUNT],
rte_voter_t * voter )
static

Monitor channel health and detect faults.

Definition at line 345 of file vital_channel_dual_transport.c.

◆ main()

int main ( void )

Main example.

Definition at line 378 of file vital_channel_dual_transport.c.

Variable Documentation

◆ shm_queue_0

shm_queue_t shm_queue_0 = {0}
static

Definition at line 52 of file vital_channel_dual_transport.c.

◆ tcp_ch_0

tcp_channel_t tcp_ch_0 = {.socket = 0, .connected = true}
static

Definition at line 99 of file vital_channel_dual_transport.c.

◆ g_channel_0

multi_transport_channel_t g_channel_0
static
Initial value:
= {
.type = CHANNEL_TYPE_SHARED_MEMORY,
.impl.shm = &shm_queue_0,
}

Definition at line 164 of file vital_channel_dual_transport.c.

◆ g_channel_1

multi_transport_channel_t g_channel_1
static
Initial value:
= {
.type = CHANNEL_TYPE_TCP,
.impl.tcp = &tcp_ch_0,
}

Definition at line 169 of file vital_channel_dual_transport.c.