Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_safechannel.h
Go to the documentation of this file.
1
37#ifndef SAPI_SAFECHANNEL_H
38#define SAPI_SAFECHANNEL_H
39
40#include <stdbool.h>
41#include <stdint.h>
42#include <stddef.h>
43
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
57#define SAPI_SAFECHANNEL_MAX_LINKS 4U
58
69
77
82typedef struct sapi_safechannel_endpoint_s
83{
88 const char *host;
90 uint16_t port;
92
113
140
142typedef struct sapi_safechannel_config_s
143{
146 union
147 {
150 } as;
152
160typedef struct sapi_safechannel_s
161{
163 bool is_open;
164
168 sapi_netlink_storage_t links[SAPI_SAFECHANNEL_MAX_LINKS];
170 uint32_t link_count;
171
172 union
173 {
175 struct
176 {
180 sapi_voter_t voter;
181 } vital;
182 } impl;
184
207
223sapi_status_t sapi_safechannel_send(sapi_safechannel_t *channel, const uint8_t *payload, size_t payload_size);
224
238sapi_status_t sapi_safechannel_receive(sapi_safechannel_t *channel, uint8_t *out_payload, size_t max_size,
239 sapi_duration_ms_t timeout_ms, size_t *out_size);
240
248
257
258#ifdef __cplusplus
259}
260#endif
261
262#endif /* SAPI_SAFECHANNEL_H */
263 /* SAFECHANNEL */
void(*) sapi_dual_channel_status_callback_t(sapi_dual_channel_status_t new_status, sapi_dual_channel_status_t old_status, void *user_ctx)
Optional callback invoked whenever sapi_dual_channel_get_status()'s value changes (ADR-020 section 2'...
sapi_safechannel_type_t
Which underlying channel implementation a sapi_safechannel_t wraps.
#define SAPI_SAFECHANNEL_MAX_LINKS
Maximum number of redundant endpoints one sapi_safechannel_t may be configured with,...
sapi_status_t sapi_safechannel_send(sapi_safechannel_t *channel, const uint8_t *payload, size_t payload_size)
Sends payload on the underlying channel - broadcast-with-ACK- wait for DUAL_REDUNDANT (sapi_dual_chan...
sapi_safechannel_link_status_t sapi_safechannel_get_status(const sapi_safechannel_t *channel)
Aggregate status across every configured endpoint - DOWN before the first send/receive.
sapi_status_t sapi_safechannel_open(sapi_safechannel_t *channel, const sapi_safechannel_config_t *config)
Opens a channel: opens every configured endpoint via the registered sapi_netlink backend,...
sapi_status_t sapi_safechannel_receive(sapi_safechannel_t *channel, uint8_t *out_payload, size_t max_size, sapi_duration_ms_t timeout_ms, size_t *out_size)
Returns the most recent inbound payload, actively polling the underlying channel if nothing was alrea...
sapi_safechannel_link_status_t
Aggregate link status, uniform across both wrapped types.
sapi_status_t sapi_safechannel_close(sapi_safechannel_t *channel)
Closes every endpoint this instance opened and releases the wrapped channel. Safe to call on an alrea...
@ SAPI_SAFECHANNEL_TYPE_VITAL_VOTED
@ SAPI_SAFECHANNEL_TYPE_DUAL_REDUNDANT
@ SAPI_SAFECHANNEL_LINK_DEGRADED
@ SAPI_SAFECHANNEL_LINK_DOWN
@ SAPI_SAFECHANNEL_LINK_FULL
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
uint32_t sapi_duration_ms_t
Definition sapi_types.h:27
sapi_voter_storage_t sapi_voter_t
Opaque handle to a voter instance.
Definition sapi_voter.h:128
sapi_voting_result_t
Outcome of one sapi_voter_receive() call.
Definition sapi_voter.h:45
sapi_voting_strategy_t
Voting strategy: how many registered channels must agree.
Definition sapi_voter.h:33
A single redundant "channel": an opaque transport handle plus send/receive callbacks,...
"DualChannel" layer of ADR-020: wraps 1..N redundant sapi_dual_msgchannel_t links for fault-tolerant,...
Common status/error codes returned by every Safe API Framework function. Shared across all OS Abstrac...
Common fixed-width types and the caller-owned-storage handle pattern used by every OAL service (see A...
N-way voting across registered sapi_channel_t links (2oo2/2oo3/NMR).
One sapi_dual_channel_t instance's state. Caller-owned storage; every field is private - reach it onl...
Configuration for sapi_safechannel_open().
sapi_safechannel_type_t type
Configuration specific to SAPI_SAFECHANNEL_TYPE_DUAL_REDUNDANT.
sapi_duration_ms_t connect_timeout_ms
sapi_safechannel_endpoint_t endpoints[SAPI_SAFECHANNEL_MAX_LINKS]
sapi_dual_channel_status_callback_t status_callback
One remote endpoint to open internally - replaces a caller- supplied sapi_netlink_handle_t (ADR-022 s...
sapi_channel_t channels[SAPI_SAFECHANNEL_MAX_LINKS]
Caller-owned storage for one sapi_safechannel_t instance. Every field is private - reach it only thro...
sapi_netlink_storage_t links[SAPI_SAFECHANNEL_MAX_LINKS]
Configuration specific to SAPI_SAFECHANNEL_TYPE_VITAL_VOTED.
void(*) on_disagreement(void *context, sapi_voting_result_t result)
sapi_safechannel_endpoint_t endpoints[SAPI_SAFECHANNEL_MAX_LINKS]
sapi_voting_strategy_t voting_strategy