diff --git a/RBcore/include/msg_center.h b/RBcore/include/msg_center.h index a07e573..9ca6649 100644 --- a/RBcore/include/msg_center.h +++ b/RBcore/include/msg_center.h @@ -44,14 +44,11 @@ extern "C"{ * data structures * *----------------------------------------------*/ -// 消息ID定义(各模块自己的命令字) -typedef uint32_t MsgID_t; - // 消息结构 typedef struct { uint32_t m_uiSrcModule; // 源模块ID uint32_t m_uiDstModule; // 目标模块ID - MsgID_t m_uiMsgID; // 消息ID(命令字) + uint32_t m_uiMsgID; // 消息ID(命令字) uint32_t m_uiDataLen; // 数据长度 uint8_t m_aucData[MSG_CENTER_MAX_DATA_SIZE]; // 消息数据 } Msg_t; @@ -109,7 +106,7 @@ int MsgCenter_Send(const Msg_t *pstMsg); * @param uiDataLen 数据长度 * @return 0成功,非0失败 */ -int MsgCenter_SendTo(const char *pszDstName, MsgID_t uiMsgID, const void *pData, uint32_t uiDataLen); +int MsgCenter_SendTo(const char *pszDstName, uint32_t uiMsgID, const void *pData, uint32_t uiDataLen); /** * @brief 处理当前模块的消息(在模块线程中调用) diff --git a/RBcore/msg_center.c b/RBcore/msg_center.c index 64dc21f..aca5068 100644 --- a/RBcore/msg_center.c +++ b/RBcore/msg_center.c @@ -217,13 +217,13 @@ int MsgCenter_Send(const Msg_t *pstMsg) 函 数 名 : MsgCenter_SendTo 功能描述 : 发送消息给指定模块(便捷函数) 输入参数 : const char *pszDstName 目标模块名称 - MsgID_t uiMsgID 消息ID + uint32_t uiMsgID 消息ID const void *pData 数据指针(可为NULL) uint32_t uiDataLen 数据长度 输出参数 : 无 返 回 值 : int 0成功,非0失败 *****************************************************************************/ -int MsgCenter_SendTo(const char *pszDstName, MsgID_t uiMsgID, const void *pData, uint32_t uiDataLen) +int MsgCenter_SendTo(const char *pszDstName, uint32_t uiMsgID, const void *pData, uint32_t uiDataLen) { if (NULL == pszDstName) { diff --git a/bspMCU/l_stm32.c b/bspMCU/l_stm32.c index 07a972d..230cac7 100644 --- a/bspMCU/l_stm32.c +++ b/bspMCU/l_stm32.c @@ -418,6 +418,34 @@ static int l_lwip(lua_State *L) } #endif +static int l_sendto(lua_State *L) +{ + int MsgCenter_SendTo(const char *pszDstName, uint32_t uiMsgID, const void *pData, uint32_t uiDataLen); + const char *pszDstName = luaL_checkstring(L, 1); + uint32_t uiMsgID = (uint32_t)luaL_checkinteger(L, 2); + const void *pData = NULL; + uint32_t uiDataLen = 0; + + if (lua_istable(L, 3)) + { + uiDataLen = (uint32_t)lua_rawlen(L, 3); + if (uiDataLen > 32) + return luaL_error(L, "data too long (max 32)"); + static uint8_t buf[32]; + for (uint32_t i = 0; i < uiDataLen; i++) + { + lua_rawgeti(L, 3, i + 1); + buf[i] = (uint8_t)luaL_checkinteger(L, -1); + lua_pop(L, 1); + } + pData = buf; + } + + int ret = MsgCenter_SendTo(pszDstName, uiMsgID, pData, uiDataLen); + lua_pushinteger(L, ret); + return 1; +} + #ifdef USE_ONCHIP_FLASH #define LUA_START_ADDR 0x08020000UL @@ -731,6 +759,10 @@ int luaopen_stm32(lua_State *L) lua_pushcfunction(L, l_lwip); lua_setglobal(L, "lwip"); // lwip = l_lwip #endif + + lua_pushcfunction(L, l_sendto); + lua_setglobal(L, "sendto"); // sendto = l_sendto + return 1; }