Browse Source

【主线待合】增加sendto的lua封装用于测试

master
Lizongdi 1 week ago
parent
commit
d9d70298f0
  1. 7
      RBcore/include/msg_center.h
  2. 4
      RBcore/msg_center.c
  3. 32
      bspMCU/l_stm32.c

7
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 00
*/
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 线

4
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 00
*****************************************************************************/
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)
{

32
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;
}

Loading…
Cancel
Save