#ifndef BMCLI_GATEWAY_PLUGIN_H #define BMCLI_GATEWAY_PLUGIN_H #include #ifdef _WIN32 #define BMCLI_GW_CALL __cdecl #ifdef BMCLI_GATEWAY_PLUGIN_EXPORT #define BMCLI_GW_EXPORT __declspec(dllexport) #else #define BMCLI_GW_EXPORT #endif #else #define BMCLI_GW_CALL #define BMCLI_GW_EXPORT __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif #define BMCLI_GW_ABI_VERSION 1U #define BMCLI_GW_TRANSFORMATION 1U #define BMCLI_GW_CODEC 2U #define BMCLI_GW_PROCESSOR 3U #define BMCLI_GW_TRANSFORM 1U #define BMCLI_GW_DECODE 2U #define BMCLI_GW_ENCODE 3U #define BMCLI_GW_PROCESS 4U #define BMCLI_GW_BOOL 1U #define BMCLI_GW_INT64 2U #define BMCLI_GW_UINT64 3U #define BMCLI_GW_FLOAT64 4U #define BMCLI_GW_ENUM 5U #define BMCLI_GW_CAN_IDE 1U #define BMCLI_GW_CAN_FDF 2U #define BMCLI_GW_CAN_BRS 4U typedef enum { BMCLI_GW_GOOD = 0, BMCLI_GW_UNOBSERVED, BMCLI_GW_INVALID_RAW, BMCLI_GW_INVALID_FLAG, BMCLI_GW_STALE, BMCLI_GW_DISCONNECTED, BMCLI_GW_INPUT_INVALID, BMCLI_GW_INPUT_SKEW, BMCLI_GW_TRANSFORM_ERROR, BMCLI_GW_ENCODE_ERROR, BMCLI_GW_E2E_ERROR, BMCLI_GW_GAP } BMCLI_GatewayReason; /* Native C ABI. All host pointers, handles and views are borrowed for this * call, on the state executor thread. No background host calls or retained * pointers. The host exposes no bus-open calls; Processor requests use the * host's declared tasks, bounded queue, ownership and normal completion path. * Return nonzero on error; never throw C++ exceptions across this boundary. * User plugins run in-process: a crash/hang is not isolated or interrupted. */ typedef struct { uint32_t struct_size, type, has_value, valid, reason, reserved; union { uint64_t unsigned_value; int64_t signed_value; double float_value; } value; uint64_t observed_us, valid_us, version, epoch; } BMCLI_GatewayValue; typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayRead)(void *host, uint32_t handle, BMCLI_GatewayValue *value); typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayWrite)(void *host, uint32_t handle, const BMCLI_GatewayValue *value); typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayResolve)(void *host, const char *id, uint32_t *handle); typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayStageMessage)(void *host, uint32_t task, const uint8_t *payload, uint32_t length); typedef struct { uint32_t struct_size, endpoint, provider, active; /* provider: 1 CAN, 2 Modbus; active means Runtime enabled. */ uint32_t observed, good, reason, reserved; uint64_t epoch, observed_us; /* Last RX/Poll/physical completion result, not a hardware power probe. */ } BMCLI_GatewayEndpointState; typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayReadEndpoint)(void *host, uint32_t endpoint, BMCLI_GatewayEndpointState *state); typedef struct { uint32_t struct_size, operation; uint64_t now_us, epoch, version; const char *instance_id; const char *config_json; const uint32_t *inputs, *outputs, *reads; uint32_t input_count, output_count, read_count; uint32_t endpoint, message_id, binding_index; const uint8_t *payload; uint32_t payload_length; uint64_t raw_value; /* Decoder input / Encoder output, Binding raw width. */ void *host; BMCLI_GatewayRead read; BMCLI_GatewayWrite write; BMCLI_GatewayResolve resolve; char *error; uint32_t error_capacity; const uint32_t *send_tasks; uint32_t send_task_count; BMCLI_GatewayStageMessage stage_message; const uint32_t *endpoints; uint32_t endpoint_count; BMCLI_GatewayReadEndpoint read_endpoint; uint32_t frame_flags; /* BMCLI_GW_CAN_*; source frame or Codec Message flags. */ } BMCLI_GatewayCall; typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayCreate)(const char *config_json, void **context); typedef void(BMCLI_GW_CALL *BMCLI_GatewayDestroy)(void *context); typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayInvoke)(void *context, BMCLI_GatewayCall *call); typedef struct { uint32_t struct_size, abi_version, kind, reserved; BMCLI_GatewayCreate create; BMCLI_GatewayDestroy destroy; BMCLI_GatewayInvoke invoke; } BMCLI_GatewayPluginApi; typedef int32_t(BMCLI_GW_CALL *BMCLI_GatewayGetApi)(uint32_t host_version, uint32_t caller_size, BMCLI_GatewayPluginApi *api); BMCLI_GW_EXPORT int32_t BMCLI_GW_CALL BMCLI_Gateway_GetPluginApi( uint32_t host_version, uint32_t caller_size, BMCLI_GatewayPluginApi *api); #ifdef __cplusplus } #endif #endif