代码拉取完成,页面将自动刷新
同步操作将从 vtor3478/vtor_elec_module 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "vtor_shell.h"
#include "vtor_string.h"
#include "vtor_timer.h"
#ifdef __VTOR_SHELL__
VtorShellStruct* vtorShellHeader = NULL;
void VtorShell_Void(void)
{
}
void VtorShell_Help(void)
{
VtorString_Print("VtorShell_Help(void)\r\n");
VtorString_Print("VtorShell designed by vtor3478@qq.com\r\n");
VtorString_Print("current date 2023-10-31\r\n");
VtorString_Print("parameter must be int32_t\r\n");
VtorString_Print("user determeter parameters number\r\n\r\n");
}
void VtorShell_List(void)
{
VtorShellStruct* shell = vtorShellHeader;
VtorString_Print("VtorShell_List(void)\r\n");
while(NULL != shell->fun)
{
int8_t shellListBuf[50] = {0};
VtorString_AppendString(shellListBuf, shell->name);
VtorString_AppendString(shellListBuf, "\r\n");
VtorString_Print(shellListBuf);
shell++;
}
}
void VtorShell_Int(int32_t num)
{
int8_t buf[50] = { 0 };
VtorString_AppendString(buf, "VtorShell_Int(");
VtorString_AppendInt(buf, num);
VtorString_AppendString(buf, ") = hex(");
VtorString_AppendHex(buf, num);
VtorString_AppendString(buf, ")\r\n");
VtorString_Print(buf);
}
int32_t VtorShell_CallAddress(void)
{
return 0;
}
void VtorShell_WriteMem(int32_t addr, int32_t val)
{
*(int32_t*)addr = val;
}
int32_t VtorShell_ReadMem(int32_t addr)
{
return *(int32_t*)addr;
}
#ifdef __VTOR_SHELL_CONFIG_GET_TIME_RESERVE__
int32_t VtorShell_GetTime()
{
return 0;
}
#endif // __VTOR_SHELL_CONFIG_GET_TIME_RESERVE__
#ifdef __VTOR_SHELL_CONFIG_GET_TIME_BY_VTOR_TIMER__
int32_t VtorShell_GetTime()
{
return VtorTimer_GetTick();
}
#endif // __VTOR_SHELL_CONFIG_GET_TIME_BY_VTOR_TIMER__
VtorShellStruct* VtorShell_GetShell(int8_t* str)
{
VtorShellStruct* shell = vtorShellHeader;
while(shell->fun)
{
if(0 == VtorString_CmpString(shell->name, str))
{
// 找到匹配的程序,退出循环,即将执行
return shell;
}
shell++;
}
return NULL;
}
int32_t VtorShell_GetArg(int8_t* str, int32_t* argv)
{
//char* splitArray = {" (),"};
int8_t argc = 0;
int8_t* argStr = VtorString_FindString(str, "(");
while(*argStr)
{
argStr = VtorString_FindInt(argStr, argv);
// 成功读到数据,参数个数与参数数据才增加
if (*argStr)
{
argv++;
argc++;
}
}
return argc;
}
void VtorShell_PrintShellInfo(VtorShellStruct* shell, uint8_t argc, int32_t* argv)
{
uint8_t i = 0;
int8_t shellInfoBuf[50] = {0};
VtorString_AppendString(shellInfoBuf, shell->name);
VtorString_AppendString(shellInfoBuf, "(");
if(argc >= 1)
{
VtorString_AppendInt(shellInfoBuf, argv[i]);
}
for(i = 1; i < argc; i++)
{
VtorString_AppendString(shellInfoBuf, ", ");
VtorString_AppendInt(shellInfoBuf, argv[i]);
}
VtorString_AppendString(shellInfoBuf, ")\r\n{\r\n");
VtorString_Print(shellInfoBuf);
}
void VtorShell_PrintExeInfo(int32_t ret, int32_t time)
{
int8_t shellInfoBuf[50] = {0};
VtorString_AppendString(shellInfoBuf, " return ");
VtorString_AppendInt(shellInfoBuf, ret);
VtorString_AppendString(shellInfoBuf, "; // elapsed ");
VtorString_AppendInt(shellInfoBuf, time);
VtorString_AppendString(shellInfoBuf, " ms\r\n}\r\n\r\n");
VtorString_Print(shellInfoBuf);
}
int32_t VtorShell_Scan(int8_t* str)
{
VtorShellStruct* shell = VtorShell_GetShell(str);
if(shell)
{
#ifdef __VTOR_SHELL_TINY__
shell->fun();
#else
int32_t argv[10] = { 0 };
int32_t* pargv = argv;
uint8_t argc = VtorShell_GetArg(str, argv);
VtorShell_PrintShellInfo(shell, argc, argv);
if(0 == VtorString_CmpString(shell->name, "VtorShell_CallAddress"))
{
shell->fun = (VtorShellFun)argv[0];
pargv++;
argc--;
}
uint32_t time = VtorShell_GetTime();
int32_t ret = VtorShell_Exec(shell, argc, pargv);
time = VtorShell_GetTime() - time;
VtorShell_PrintExeInfo(ret, time);
return ret;
#endif
}
return 0;
}
int32_t VtorShell_Exec(VtorShellStruct* shell, uint8_t argc, int32_t* argv)
{
int32_t ret = 0;
switch (argc)
{
case 0:
ret = shell->fun();
break;
case 1:
ret = shell->fun(argv[0]);
break;
case 2:
ret = shell->fun(argv[0], argv[1]);
break;
case 3:
ret = shell->fun(argv[0], argv[1], argv[2]);
break;
case 4:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3]);
break;
case 5:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3], argv[4]);
break;
case 6:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
break;
case 7:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
break;
case 8:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
break;
case 9:
ret = shell->fun(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
break;
case 10:
ret = shell->fun(argv[0], argv[1], argv[2], argv[2], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
break;
default:
break;
}
return ret;
}
#endif // __VTOR_SHELL__
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。