|
Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
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"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} |
Example: Channel naming and callback-based event handling.
Demonstrates:
This is more efficient than polling: callbacks are invoked when data arrives.
Definition in file channel_callbacks_example.c.
| #define MAX_CHANNELS 16 |
Definition at line 76 of file channel_callbacks_example.c.
| 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.
| channel_name | Unique identifier (e.g., "online_to_standby_vital") |
| data | Received data buffer |
| data_size | Size of received data |
| context | User-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.
| 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_entry_t * channel_registry_find | ( | const char * | name | ) |
Find channel by name.
Definition at line 116 of file channel_callbacks_example.c.
| 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.
| 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.
| 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.
| 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.
| 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.
| int main | ( | void | ) |
Definition at line 294 of file channel_callbacks_example.c.
|
static |
Definition at line 90 of file channel_callbacks_example.c.