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
channel_callbacks_example.c File Reference

Example: Channel naming and callback-based event handling. More...

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "rte/status/rte_status.h"
Include dependency graph for channel_callbacks_example.c:

Go to the source code of this file.

Data Structures

struct  train_command_t
struct  standby_status_t
struct  app_context_t
struct  channel_registry_entry_t
struct  channel_registry_t

Macros

#define MAX_CHANNELS   16

Typedefs

typedef 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.

Functions

rte_status_t channel_registry_register (const char *name, rte_channel_callback_t callback, void *context)
 Register a named channel with callback.
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_standby_feedback_received (const char *channel_name, const void *data, size_t data_size, void *context)
 Callback: Standby feedback/health received.
void on_telemetry_received (const char *channel_name, const void *data, size_t data_size, void *context)
 Callback: Telemetry received.
void on_config_update_received (const char *channel_name, const void *data, size_t data_size, void *context)
 Callback: Configuration update received.
void simulate_channel_data (const char *channel_name, const void *data, size_t size)
 Simulate data arriving on a channel.
int main (void)

Variables

static channel_registry_t g_channel_registry = {0}

Detailed Description

Example: Channel naming and callback-based event handling.

Demonstrates:

  1. Naming channels for identification
  2. Registering callbacks on channels
  3. Event-driven processing (callbacks instead of polling)
  4. Channel registry for managing multiple channels
  5. Identifying which channel has data in logs

This is more efficient than polling: callbacks are invoked when data arrives.

Definition in file channel_callbacks_example.c.

Macro Definition Documentation

◆ MAX_CHANNELS

#define MAX_CHANNELS   16

Definition at line 76 of file channel_callbacks_example.c.

Typedef Documentation

◆ rte_channel_callback_t

typedef 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.

Parameters
channel_nameUnique identifier (e.g., "online_to_standby_vital")
dataReceived data buffer
data_sizeSize of received data
contextUser-provided context (e.g., app state)

Called by OS OSAdapter when data arrives on the channel. User implements this to handle incoming data.

Definition at line 38 of file channel_callbacks_example.c.

Function Documentation

◆ channel_registry_register()

rte_status_t channel_registry_register ( const char * name,
rte_channel_callback_t callback,
void * context )

Register a named channel with callback.

Definition at line 95 of file channel_callbacks_example.c.

◆ channel_registry_find()

channel_registry_entry_t * channel_registry_find ( const char * name)

Find channel by name.

Definition at line 116 of file channel_callbacks_example.c.

◆ on_vital_command_received()

void on_vital_command_received ( const char * channel_name,
const void * data,
size_t data_size,
void * context )

Callback: Vital command received on channel.

This is invoked by the OS OSAdapter when data arrives on the "online_to_standby_vital" channel. The callback identifies the channel by name and processes the incoming data.

Definition at line 137 of file channel_callbacks_example.c.

◆ on_standby_feedback_received()

void on_standby_feedback_received ( const char * channel_name,
const void * data,
size_t data_size,
void * context )

Callback: Standby feedback/health received.

Invoked on "standby_to_online_feedback" channel. Tracks standby health and detects anomalies.

Definition at line 174 of file channel_callbacks_example.c.

◆ on_telemetry_received()

void on_telemetry_received ( const char * channel_name,
const void * data,
size_t data_size,
void * context )

Callback: Telemetry received.

Invoked on "online_to_diag_telemetry" channel. Non-blocking, non-vital: failures are logged but not critical.

Definition at line 217 of file channel_callbacks_example.c.

◆ on_config_update_received()

void on_config_update_received ( const char * channel_name,
const void * data,
size_t data_size,
void * context )

Callback: Configuration update received.

Invoked on "config_update_channel". Validates and applies new configuration.

Definition at line 239 of file channel_callbacks_example.c.

◆ simulate_channel_data()

void simulate_channel_data ( const char * channel_name,
const void * data,
size_t size )

Simulate data arriving on a channel.

In real implementation, OS OSAdapter would call the callback when actual data arrives. Here we simulate it.

Definition at line 271 of file channel_callbacks_example.c.

◆ main()

int main ( void )

Definition at line 294 of file channel_callbacks_example.c.

Variable Documentation

◆ g_channel_registry

channel_registry_t g_channel_registry = {0}
static

Definition at line 90 of file channel_callbacks_example.c.