You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.0 KiB

/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msg_center.h
: 稿
: radkil
: 2026713
:
: 线
:
1. : 2026713
: radkil
:
******************************************************************************/
#ifndef __MSG_CENTER_H__
#define __MSG_CENTER_H__
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*==============================================*
* include header files *
*----------------------------------------------*/
#include "common.h"
/*==============================================*
* constants or macros define *
*----------------------------------------------*/
#define MSG_CENTER_MAX_MODULES 16 // 最大模块数
#define MSG_CENTER_MAX_NAME_LEN 16 // 模块名称最大长度
#define MSG_CENTER_QUEUE_SIZE 64 // 消息队列大小
#define MSG_CENTER_MAX_DATA_SIZE 64 // 消息数据最大大小
/*==============================================*
* data structures *
*----------------------------------------------*/
// 消息结构
typedef struct {
uint32_t m_uiSrcModule; // 源模块ID
uint32_t m_uiDstModule; // 目标模块ID
uint32_t m_uiMsgID; // 消息ID(命令字)
uint32_t m_uiDataLen; // 数据长度
uint8_t m_aucData[MSG_CENTER_MAX_DATA_SIZE]; // 消息数据
} Msg_t;
// 消息处理回调函数类型
typedef void (*MsgHandler_t)(const Msg_t *pstMsg);
// 模块注册信息
typedef struct {
char m_szName[MSG_CENTER_MAX_NAME_LEN]; // 模块名称
uint32_t m_uiModuleID; // 模块ID
MsgHandler_t m_pfHandler; // 消息处理回调
} MsgModule_t;
/*==============================================*
* project-wide global variables *
*----------------------------------------------*/
/*==============================================*
* routines' or functions' implementations *
*----------------------------------------------*/
/**
* @brief
*/
void MsgCenter_Init(void);
/**
* @brief
* @param pszName
* @param pfHandler
* @return ID0
*/
uint32_t MsgCenter_Register(const char *pszName, MsgHandler_t pfHandler);
/**
* @brief ID
* @param pszName
* @return ID0
*/
uint32_t MsgCenter_FindModule(const char *pszName);
/**
* @brief 线
* @param pstMsg
* @return 00
*/
int MsgCenter_Send(const Msg_t *pstMsg);
/**
* @brief 便
* @param pszDstName
* @param uiMsgID ID
* @param pData NULL
* @param uiDataLen
* @return 00
*/
int MsgCenter_SendTo(const char *pszDstName, uint32_t uiMsgID, const void *pData, uint32_t uiDataLen);
/**
* @brief 线
* @param uiModuleID ID
* @return
*/
int MsgCenter_Process(uint32_t uiModuleID);
/**
* @brief
* @param uiModuleID ID
* @param uiTimeoutMs 0
* @return -1
*/
int MsgCenter_ProcessWait(uint32_t uiModuleID, uint32_t uiTimeoutMs);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __MSG_CENTER_H__ */