SafeAPI RBC 2oo2 Generic Application
IL/CTC route and train logic for the safeAPIRBC2oo2 reference RBC
Loading...
Searching...
No Matches
ab_ga_dispatch.c
Go to the documentation of this file.
1
6#include "ab_ga_dispatch.h"
7
8#include "ga_interface.h" /* every ab_gp_register_*() this module calls */
9#include "../il/ab_ga_il.h" /* ab_ga_il_on_route_context_changed()/_apply_envelope()/_build_outputs() */
10#include "../ctc/ab_ga_ctc.h" /* ab_ga_ctc_on_route_context_changed()/_on_train_context_changed()/_build_outputs() */
11
17typedef struct
18{
19 ab_gp_train_session_t *sessions;
20 ab_gp_db_t *db;
22
23static ga_channel_ctx_t g_channel_ctx;
24
26static void on_route_context_changed(const void *context, const ab_gp_route_context_t *ctx,
27 ab_gp_route_update_type_t update_type);
28static void on_train_context_changed(const void *context, const ab_gp_train_context_t *ctx,
29 ab_gp_train_update_type_t update_type);
30static uint8_t il_output_producer_trampoline(const void *context,
31 ab_gp_il_pending_output_t out[AB_GP_IL_MAX_PENDING_OUTPUTS]);
32static uint8_t ctc_output_producer_trampoline(const void *context,
33 ab_gp_ctc_pending_output_t out[AB_GP_CTC_MAX_PENDING_OUTPUTS]);
34
36sapi_status_t ab_ga_dispatch_init(ab_gp_train_session_t *sessions, ab_gp_db_t *db)
37{
38 sapi_status_t status;
39
40 g_channel_ctx.sessions = sessions;
41 g_channel_ctx.db = db;
42
43 status = ab_gp_db_register_route_context_notify(on_route_context_changed, &g_channel_ctx);
44 if (status != SAPI_STATUS_OK)
45 {
46 return status;
47 }
48 status = ab_gp_register_train_context_notify(on_train_context_changed, NULL);
49 if (status != SAPI_STATUS_OK)
50 {
51 return status;
52 }
53 /* ab_ga_il_apply_envelope() itself matches ab_gp_il_envelope_handler_fn's
54 * exact signature now (it takes/ignores the leading context param) -
55 * registered directly, no trampoline needed; GP hands it fresh
56 * sessions/db every call, so this module's own g_channel_ctx capture
57 * above is not what it uses. */
58 status = ab_gp_register_il_envelope_handler(ab_ga_il_apply_envelope, NULL);
59 if (status != SAPI_STATUS_OK)
60 {
61 return status;
62 }
63 status = ab_gp_register_il_output_producer(il_output_producer_trampoline, NULL);
64 if (status != SAPI_STATUS_OK)
65 {
66 return status;
67 }
68 return ab_gp_register_ctc_output_producer(ctc_output_producer_trampoline, &g_channel_ctx);
69}
70
71/****Local functions ****/
72
83static void on_route_context_changed(const void *context, const ab_gp_route_context_t *ctx,
84 ab_gp_route_update_type_t update_type)
85{
86 const ga_channel_ctx_t *ch = (const ga_channel_ctx_t *)context;
87
88 ab_ga_il_on_route_context_changed(ch->sessions, ch->db, ctx, update_type);
89 ab_ga_ctc_on_route_context_changed(ctx, update_type);
90}
91
95static void on_train_context_changed(const void *context, const ab_gp_train_context_t *ctx,
96 ab_gp_train_update_type_t update_type)
97{
98 (void)context;
99 ab_ga_ctc_on_train_context_changed(ctx, update_type);
100}
101
105static uint8_t il_output_producer_trampoline(const void *context,
106 ab_gp_il_pending_output_t out[AB_GP_IL_MAX_PENDING_OUTPUTS])
107{
108 (void)context;
109 return ab_ga_il_build_outputs(out);
110}
111
116static uint8_t ctc_output_producer_trampoline(const void *context,
117 ab_gp_ctc_pending_output_t out[AB_GP_CTC_MAX_PENDING_OUTPUTS])
118{
119 const ga_channel_ctx_t *ch = (const ga_channel_ctx_t *)context;
120
121 if (ch == NULL)
122 {
123 return 0U;
124 }
125 return ab_ga_ctc_build_outputs(ch->sessions, ch->db, out);
126}
uint8_t ab_ga_ctc_build_outputs(ab_gp_train_session_t *sessions, ab_gp_db_t *db, ab_gp_ctc_pending_output_t out[AB_GP_CTC_MAX_PENDING_OUTPUTS])
Decides which trains need a CTC indication THIS cycle and builds all of them - see this file's own mo...
Definition ab_ga_ctc.c:169
void ab_ga_ctc_on_train_context_changed(const ab_gp_train_context_t *ctx, ab_gp_train_update_type_t update_type)
GA's dispatch module fans every train-context change here - stores the received snapshot and marks th...
Definition ab_ga_ctc.c:278
void ab_ga_ctc_on_route_context_changed(const ab_gp_route_context_t *ctx, ab_gp_route_update_type_t update_type)
GA's single dispatch module (safeAPIRBC2oo2GA/src/AB/main/ ab_ga_dispatch.c) is the ONLY thing that r...
Definition ab_ga_ctc.c:264
A/B's own outbound messages to CtcRBCSim. Two layers, same split as AB/GP/train/ab_gp_train....
static void on_route_context_changed(const void *context, const ab_gp_route_context_t *ctx, ab_gp_route_update_type_t update_type)
static uint8_t ctc_output_producer_trampoline(const void *context, ab_gp_ctc_pending_output_t out[AB_GP_CTC_MAX_PENDING_OUTPUTS])
static void on_train_context_changed(const void *context, const ab_gp_train_context_t *ctx, ab_gp_train_update_type_t update_type)
sapi_status_t ab_ga_dispatch_init(ab_gp_train_session_t *sessions, ab_gp_db_t *db)
Registers every GA<->GP subscription this process needs, in one place: route-context notify,...
static uint8_t il_output_producer_trampoline(const void *context, ab_gp_il_pending_output_t out[AB_GP_IL_MAX_PENDING_OUTPUTS])
GA's single GP-notification subscriber AND registration point for everything GP calls into GA with - ...
void ab_ga_il_on_route_context_changed(ab_gp_train_session_t *sessions, ab_gp_db_t *db, const ab_gp_route_context_t *ctx, ab_gp_route_update_type_t update_type)
GA's single dispatch module (ab_ga_dispatch.c) fans every route change here for AB_ROUTE_CONNECTED/AB...
Definition ab_ga_il.c:707
bool ab_ga_il_apply_envelope(const void *context, ab_gp_train_session_t *sessions, ab_gp_db_t *db, const uint8_t env_bytes[RBC_ENVELOPE_WIRE_SIZE], uint32_t cycle, sapi_example_site_t site, const char *role_tag)
THE handler this module registers with GP (ab_gp_register_il_envelope_handler(), ga_interface....
Definition ab_ga_il.c:163
uint8_t ab_ga_il_build_outputs(ab_gp_il_pending_output_t out[AB_GP_IL_MAX_PENDING_OUTPUTS])
Drains this module's own TrainPositionInRoute event queue (populated by this module's own route-conne...
Definition ab_ga_il.c:233
A/B's own route handling against GP's own runtime table (via AB/GP/ga_interface/ga_interface....