📄 logterm.c
字号:
log_logprint(message_start, ptr);
if (*ptr & ~0xff)
{
message_start++;
count--;
}
/* skip one more forward, wrapping around the beginning. */
ptr += *ptr;
if (ptr >= sb->end)
ptr -= sb->size;
}
}
void log_emitch(char ch)
{
ST16C552Reg *const serchip = (LOGTERM_PORT == ST16C552_IDENT_A) ?
(ST16C552Reg *)NISA_SER_A : (ST16C552Reg *)NISA_SER_B;
#ifdef LOGTERM_ADD_CR_TO_LF
if (ch == '\n')
{
while (st16c552_TxBuffFull(serchip))
continue;
st16c552_PutChar(serchip, '\r');
}
#endif
while (st16c552_TxBuffFull(serchip))
continue;
st16c552_PutChar(serchip, ch);
}
void log_emitstr(char *str)
{
while(*str)
{
log_emitch(*str++);
}
}
/**************************************************************************/
/* Command Interpreter */
/**************************************************************************/
/*
* Function: log_stat
* Purpose: Print status report; eventually, this should be able to, for
* example, print the number of packets sent, or CRC errors under ADP,
* or whatever else. Needs more work!
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "stat").
*
* Returns: 0.
*/
extern struct StatInfo spk_stat_info[];
static int log_stat(int argc, char **argv)
{
if (argc < 2)
return 1;
if (__rt_strcmp(argv[1], "serpkt") == 0)
{
struct StatInfo *p = spk_stat_info;
while(p->format != NULL)
{
int l;
logterm_PreWarn(WL_INFO);
l = log_printf(p->format, *p->param);
logterm_PostWarn(l);
p++;
}
}
else
log_emitstr("stat: unknown module\n");
return 0;
}
/*
* Function: log_level
* Purpose:
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "level").
*
* Returns: 0.
*/
static int log_level(int argc, char **argv)
{
WarnLevel lvl;
if (argc == 1)
{
lvl = log_get_log_minlevel();
switch(lvl)
{
case WL_INFO:
log_emitstr("level: info\n");
break;
case WL_WARN:
log_emitstr("level: warn\n");
break;
case WL_ERROR:
log_emitstr("level: error\n");
break;
}
}
else if (argc == 2)
{
if (argv[1][0] == 'i')
{
log_set_log_minlevel(WL_INFO);
}
else if (argv[1][0] == 'w')
{
log_set_log_minlevel(WL_WARN);
}
else if (argv[1][0] == 'e')
{
log_set_log_minlevel(WL_ERROR);
}
else
log_emitstr("level: unknown level name\n");
}
else
{
log_emitstr("level: bad syntax\n");
}
return 0;
}
/*
* Function: log_go
* Purpose: UnPause Angel; allow it to progress after a pause.
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "go").
*
* Returns: 0.
*/
volatile static int log_paused = FALSE;
static int log_go(int argc, char **argv)
{
UNUSED(argc);
UNUSED(argv);
if (log_paused)
log_paused = FALSE;
else
log_emitstr("go: not paused\n");
log_deferredprompt = TRUE;
return 0;
}
/*
* Function: log_pause
* Purpose: Pause Angel; don't allow it to progress. Terminated by 'go'
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "pause").
*
* Returns: 0.
*/
static int log_pause(int argc, char **argv)
{
ST16C552Reg *const serchip = (LOGTERM_PORT == ST16C552_IDENT_A) ?
(ST16C552Reg *)NISA_SER_A : (ST16C552Reg *)NISA_SER_B;
int state;
UNUSED(argc);
UNUSED(argv);
if (log_paused)
{
log_emitstr("pause: Already paused\n");
return 1;
}
state = Angel_DisableInterruptsFromSVC();
log_paused = TRUE;
while(log_paused)
{
unsigned char ch;
while(st16c552_RxBuffEmpty(serchip))
continue;
ch = st16c552_GetChar(serchip);
log_processchar(ch, 0);
}
Angel_RestoreInterruptsFromSVC(state);
return 0;
}
/*
* Function: log_echo
* Purpose: Debugging aid.
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "ver").
*
* Returns: 0.
*/
static int log_echo(int argc, char **argv)
{
int i;
for(i = 0; i < argc; i++)
{
log_emitch('\"');
log_emitstr(argv[i]);
log_emitch('\"');
log_emitch(' ');
}
log_emitch('\n');
return 0;
}
/*
* Function: log_dump
* Purpose: Print the contents of memory.
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "ver").
*
* Returns: 0.
*/
static int log_dump(int argc, char **argv)
{
int addr1 = 0, addr2 = 0, len = 0;
char *e;
if (argc == 1 || argc > 3)
{
log_emitstr("dump: addr1 [addr2 | +nbytes]\n");
return 0;
}
if (argc == 2)
{
addr1 = stoi(argv[1], &e);
addr2 = addr1 + 16;
len = 16;
}
else if (argc == 3)
{
if (argv[2][0] == '+')
{
len = stoi(argv[2]+1, &e);
addr2 = addr1 + len;
}
else
{
addr2 = stoi(argv[2], &e);
len = (addr2 - addr1) + 1;
}
}
log_dump_buffer(WL_INFO, LOG_BUFFER, 16, (char*)addr1, len);
return 0;
}
/*
* Function: log_ver
* Purpose: Version command routine. Prints the Angel banner again.
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "ver").
*
* Returns: 0.
*/
static int log_ver(int argc, char **argv)
{
UNUSED(argc);
UNUSED(argv);
log_emitstr(ANGEL_BANNER);
return 0;
}
/*
* Function: log_format
* Purpose: Set the per-message info
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "ver").
*
* Returns: 0.
*/
static int log_format(int argc, char **argv)
{
if (argc == 1)
{
log_emitstr("format: \"");
log_emitstr(log_get_format_string());
log_emitstr("\"\n");
}
else
{
if (argc == 2)
{
log_set_format_string(argv[1]);
}
else
{
log_emitstr("format: too many args\n");
}
}
return 0;
}
/*
* Function: log_help
* Purpose: Help command routine. Given a single arg, prints the help
* string for that command, if it exists.
*
* With no args, prints all help available.
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "help").
*
* Returns: 0 if help found, 1 otherwise.
*/
static int log_help(int argc, char **argv)
{
int i;
if (argc > 1)
{
for (i = 0; i < log_ncmds; i++)
{
switch(__rt_strcmp(argv[1], log_cmds[i].str))
{
case 0: /* match ! */
log_emitstr(log_cmds[i].desc);
log_emitstr(log_cmds[i].helpstr);
return 0;
case -1: /* no match found */
log_emitstr("No help found?\n");
return 1;
}
}
}
else
{
log_emitstr("Help Available:\n");
for (i = 0; i < log_ncmds; i++)
{
log_emitstr(log_cmds[i].str);
log_emitstr(" - ");
log_emitstr(log_cmds[i].desc);
}
}
return 0;
}
/*
* Function: log_trace
* Purpose: The trace action. trace syntax is:
* trace <on>|<off> switch real-time tracing on or off
* trace <lines> show <lines> worth of previous trace history
* trace show currently traced modules
* trace <names> change traced modules; <names> is space separated
* list, with '-' before items to be removed. 'all'
* can be used to specify all modules (so '-all'
* means none).
*
* Pre-conditions: none.
*
* Params:
* Input: argc, argv - "main" argc/argv pair containing args. argv[0]
* is name of command (i.e. "trace").
*
* Returns: 0
*/
static int log_trace(int argc, char **argv)
{
int i, rem, n;
char *p;
if (argc == 1) /* no args */
{
n = log_get_num_ids();
log_emitstr("trace: ");
for(i = 0; i < n; i++)
{
if (log_get_log_id((log_id)i))
{
log_emitstr(log_tracename((log_id)i));
log_emitch(' ');
}
}
log_emitch('\n');
}
else if (argc >= 2) /* at least one arg */
{
if (argv[1][0] >= '0' && argv[1][0] <= '9')
{
int lines;
char *ep;
lines = stoi(argv[1], &ep);
if (ep > argv[1] && lines > 0 && lines < 1000)
{
/*
* don't want current and old output mixed together, do we?
*/
log_output(FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -