1 Star 0 Fork 8

Anderson/vtor_elec_module

forked from vtor3478/vtor_elec_module 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vtor_shell.c 4.77 KB
一键复制 编辑 原始数据 按行查看 历史
#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__
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Thomas_Ti/vtor_elec_module.git
git@gitee.com:Thomas_Ti/vtor_elec_module.git
Thomas_Ti
vtor_elec_module
vtor_elec_module
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385