Skip to content
Version 6.1.0
Contact Us

BACnetStack_RegisterCallbackBACnetSCStateChange

void BACnetStack_RegisterCallbackBACnetSCStateChange(
void (*FPCallbackBACnetSCStateChange)(const uint32_t deviceInstance, const uint32_t networkPortInstance, const uint8_t stateMachine, const uint8_t previousState, const uint8_t newState, const char *websocketUri, const uint32_t websocketUriLength));

Registers a purely observational callback the stack invokes whenever a BACnet/SC connection state machine changes state.

Most transitions fire from inside BACnetStack_Tick(), but some fire synchronously inside the call that causes them: a websocket status the host reports with BACnetStack_SetBACnetSCWebSocketStatus() (and a direct-connect initiating-peer transition that report sets off), a hub URI change through BACnetStack_SetBACnetSCHubConnector() that closes the connection to the old hub, the activation of pending BACnet/SC Network Port changes, and a configuration change that ends a direct connection (BACnetStack_SetBACnetSCDirectConnectConfig() turning initiation off, or BACnetStack_SetBACnetSCHelloCapabilities()). It returns void - nothing you do here affects the stack. It is not invoked when the previous and new states are equal.

deviceInstance and networkPortInstance name the BACnet/SC Network Port object configured for that data link, for every transition: a websocket status the host reports with BACnetStack_SetBACnetSCWebSocketStatus(), the transitions the stack drives on the direct-connect websocket, and those the hub connector drives itself (its state, hub-connection status, and its websockets’ status and initiating-peer state). They are 0 and 0 while no BACnet/SC Network Port object is configured for that data link. The websocket URI identifies the socket.

The websocket URI CAN BE NULL, with length 0, for a transition not tied to one socket. When non-NULL it is stack-owned and NUL-terminated, valid only for the duration of the call.

stateMachine names which machine moved: 0 = hub-connector state, 1 = hub-connection status, 2 = initiating-peer connection state, 3 = websocket status. The previous and new state values are within THAT machine’s own enumeration - hub-connection status 0 none / 1 primary / 2 failover; initiating-peer 0 idle / 1 awaiting-websocket / 2 awaiting-accept / 3 connected / 4 disconnecting; websocket status 0 unknown / 1 connecting / 2 connected / 3 disconnected / 4 error.

Registering has no effect if BACnet/SC was not compiled (STACK_OPTION_DATA_LINK_LAYER_SC).

See also: CASBACnetStack::FPCallbackBACnetSCStateChange

Parameter Direction Description
FPCallbackBACnetSCStateChange in The function pointer for the CallbackBACnetSCStateChange function. See CASBACnetStack::FPCallbackBACnetSCStateChange for more info.

FPCallbackBACnetSCStateChange

Topic: BACnet/SC. Declared in CASBACnetStackDLL.h.