/** * TWS-3000 detection unit strike counter and filter (DUU & DUM) */ #ifndef LIBDI_INCLUDE_TWS_DU_STRIKE_H_ #define LIBDI_INCLUDE_TWS_DU_STRIKE_H_ #include #include #include #include #include #include #define DI_TWS_DU_STRIKE_MANUAL_HOLDOFF_TIME_MS 0 #define DI_TWS_DU_STRIKE_ULTRASONIC_HOLDOFF_TIME_MS 5000 struct di_tws_du_strike { di_bsem_t lock; enum di_rpc_du_strike_role role; bool value; bool striked; uint32_t train_counter; di_time_t holdoff_time; di_time_t holdoff_until; }; #ifdef __cplusplus extern "C" { #endif /** * Initialize the strike state * @note May only be called once * @param s Strike state */ void di_tws_du_strike_init(struct di_tws_du_strike *s); /** * Reset the strike state * @param s Strike state * @param role Strike role * @param holdoff_time Hold-off time */ void di_tws_du_strike_reset(struct di_tws_du_strike *s, const enum di_rpc_du_strike_role role, const di_time_t holdoff_time); /** * Update the strike state * @param s Strike state * @param value Next strike value * @return true when update resulted in a strike, false otherwise */ bool di_tws_du_strike_update(struct di_tws_du_strike *s, const bool value); /** * Get current strike role * @return Current strike role */ enum di_rpc_du_strike_role di_tws_du_strike_get_role(struct di_tws_du_strike *s); /** * Get the detection unit strike role from an DI-Net RPC message data. * Only valid strike roles are IN or OUT. * @param role[out] Strike role * @param data[in] DI-Net RPC message data * @return DNOK when strike role is read, !DNOK otherwise */ di_errno_t di_tws_du_strike_rpc_get_role(enum di_rpc_du_strike_role *role, const struct di_rpc_data *data); /** * Get the current incremental train counter * @param s Strike state * @return Incremental train counter */ uint32_t di_tws_du_strike_get_train_counter(struct di_tws_du_strike *s); #ifdef __cplusplus } #endif #endif /* LIBDI_INCLUDE_TWS_DU_STRIKE_H_ */