/** * @file can/rpc.h * @brief CAN RPC * @date Aug 25, 2015 * @author rheijden * @copyright 2015 Dual Inventive Technology Centre B.V. * * Descr */ #ifndef INCLUDE_DI_CAN_RPC_H_ #define INCLUDE_DI_CAN_RPC_H_ #include #include #include #include #include #include struct di_can_ctx; struct di_can_msg; #ifdef __cplusplus extern "C" { #endif /** * Start and initialize DI-CAN RPC message writer * @param writer Messagepack writer * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @return DI CAN Message pointer to message to send */ struct di_can_msg *di_can_rpc_send_start(mpack_writer_t *writer, struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type); /** * Finish the written DI-CAN RPC message writer and send the message * @param writer Messagepack writer * @param[in] msg CAN message to finish and send * @return DNOK when send, !DNOK otherwise */ di_errno_t di_can_rpc_send_finish(mpack_writer_t *writer, struct di_can_msg **msg); /** * Send DI-Net RPC device:info result over CAN * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param info Device info array * @param len Amount of info parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_device_info(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_device_info *info, size_t len, const bool rt); /** * Send DI-Net RPC device:data result over CAN * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param data Device data array * @param len Amount of info parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_device_data(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_device_data *data, size_t len, const bool rt); /** * Send DI-Net RPC info result over CAN * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param info RPC info array * @param len Amount of info parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_info(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_info *info, size_t len, const bool rt); /** * Send DI-Net RPC config:info result over CAN * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param info RPC info array * @param len Amount of info parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_config_info(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_config_info *info, size_t len, const bool rt); /** * Send DI-Net RPC data results over CAN with given RPC type (e.g sensor:data) * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param info RPC info array * @param len Amount of info parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_data(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_data *data, size_t len, const bool rt); /** * Send DI-Net RPC log message over CAN * @param ctx CAN context * @param ttype Message Transfertype * @param type RPC message type * @param log RPC info item array * @param len Amount of log parameter items * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_log(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_log *log, size_t len, const bool rt); /** * Send DI-Net RPC device:ping message * @param ctx CAN context * @param ttype Message Transfertype * @param rt Realtime message flag * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_device_ping(struct di_can_ctx *ctx, enum di_can_transfertype ttype, const bool rt); /** * Send DI-Net RPC connection:info message * @param ctx CAN context * @param dst_id Message Transfertype * @param ttype Transfertype * @param info Connection info item * @return DNOK when message is send, !DNOK otherwise */ di_errno_t di_can_rpc_send_connection_info(struct di_can_ctx *ctx, const uint32_t dst_id, enum di_can_transfertype ttype, const struct di_rpc_connection_info *info); /** * Send di_errno_t map object as RPC message * { * "code" : DNE_OPNOTSUPP, * "descr" : "Operation not supported" * } */ di_errno_t di_can_rpc_send_errno(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, di_errno_t error); /** * Send RPC di_device errors as RPC device:errors message */ di_errno_t di_can_rpc_send_device_errors(struct di_can_ctx *ctx, uint32_t dst_id, enum di_can_transfertype ttype); di_errno_t di_can_rpc_pub_log_msg(struct di_can_ctx *ctx, enum di_rpc_types type, const char *msg); di_errno_t di_can_rpc_deserialize_data(const struct di_can_msg *msg, struct di_rpc_data *data); #ifndef __cplusplus /** * Send DI-CAN DI-Net RPC message * @param ctx CAN context * @param ttype Transfertype (enum di_can_transfertype ttype) * @param type DI-Net RPC type (enum di_rpc_types type) * @param value An array to di_rpc_* value(s) * @param len The amount of value parameter items */ #define di_can_rpc_send(ctx, ttype, type, value, len) \ _Generic((value), \ const struct di_rpc_device_info * : di_can_rpc_send_device_info, \ struct di_rpc_device_info * : di_can_rpc_send_device_info, \ const struct di_rpc_device_data * : di_can_rpc_send_device_data, \ struct di_rpc_device_data * : di_can_rpc_send_device_data, \ const struct di_rpc_config_info * : di_can_rpc_send_config_info, \ struct di_rpc_config_info * : di_can_rpc_send_config_info, \ const struct di_rpc_info * : di_can_rpc_send_info, \ struct di_rpc_info * : di_can_rpc_send_info, \ const struct di_rpc_data * : di_can_rpc_send_data, \ struct di_rpc_data * : di_can_rpc_send_data, \ const struct di_rpc_log * : di_can_rpc_send_log, \ struct di_rpc_log * : di_can_rpc_send_log \ )(ctx, ttype, type, value, len, false) /** * Send DI-CAN DI-Net RPC Realtime message * @param ctx CAN context * @param ttype Transfertype (enum di_can_transfertype ttype) * @param type DI-Net RPC type (enum di_rpc_types type) * @param value An array to di_rpc_* value(s) * @param len The amount of value parameter items */ #define di_can_rpc_send_rt(ctx, ttype, type, value, len) \ _Generic((value), \ const struct di_rpc_device_info * : di_can_rpc_send_device_info, \ struct di_rpc_device_info * : di_can_rpc_send_device_info, \ const struct di_rpc_device_data * : di_can_rpc_send_device_data, \ struct di_rpc_device_data * : di_can_rpc_send_device_data, \ const struct di_rpc_config_info * : di_can_rpc_send_config_info, \ struct di_rpc_config_info * : di_can_rpc_send_config_info, \ const struct di_rpc_info * : di_can_rpc_send_info, \ struct di_rpc_info * : di_can_rpc_send_info, \ const struct di_rpc_data * : di_can_rpc_send_data, \ struct di_rpc_data * : di_can_rpc_send_data, \ const struct di_rpc_log * : di_can_rpc_send_log, \ struct di_rpc_log * : di_can_rpc_send_log \ )(ctx, ttype, type, value, len, true) #endif #ifdef __cplusplus } #endif #ifdef __cplusplus static inline di_errno_t di_can_rpc_send(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_device_info *value, size_t len) { return di_can_rpc_send_device_info(ctx, ttype, type, value, len, false); } static inline di_errno_t di_can_rpc_send(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_device_data *value, size_t len) { return di_can_rpc_send_device_data(ctx, ttype, type, value, len, false); } static inline di_errno_t di_can_rpc_send(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_info *value, size_t len) { return di_can_rpc_send_info(ctx, ttype, type, value, len, false); } static inline di_errno_t di_can_rpc_send(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_data *value, size_t len) { return di_can_rpc_send_data(ctx, ttype, type, value, len, false); } static inline di_errno_t di_can_rpc_send(struct di_can_ctx *ctx, enum di_can_transfertype ttype, enum di_rpc_types type, const struct di_rpc_log *value, size_t len) { return di_can_rpc_send_log(ctx, ttype, type, value, len, false); } #endif #endif /* INCLUDE_DI_CAN_RPC_H_ */