📄 funconf.c~
字号:
/*******************************************************************************
文件名:Funconf.c
版权所有:武汉易捷通信有限公司
版本:V1.0
作者:吴友山
描述:功能函数。
日期:
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "config.h"
#include "funconf.h"
#include "login.h"
#include "msgPrint.h"
/* globe */
UINT32 printfState = 0;
/*******************************************************************************
s[MAXLENTH] 是全局变量,登陆时,作为用户名跟密码的校验
的临时缓存区
idletime 是表示空闲时间值,默认是300,当用户空闲超过
300秒,则退出
idletime_tmp 是表示程序运行20ms的次数,作为空闲时间的计时器。
*******************************************************************************/
INT8 s[MAXLENTH+5]; /*存储用户输入的数据*/
UINT32 idletime = 300;/*登陆超时值*/
UINT32 idletime_tmp = 0;/*程序运行20ms的次数,即空闲时间*/
UINT32 osTimer = 0;/*定时器的定时计数器*/
UINT32 osTimerBackup = 0;/*用来产生20ms的辅助计数器*/
#define MAX_COMMAND_LOOP 5 /*最大命令回显个数*/
INT8 backupCommand[MAX_COMMAND_LOOP][MAXLENTH+5];/*用户输入命令的历史记录*/
UINT8 commandLast = 0;/*用户输入的最后一条命令存储在数组backupCommand中的维数*/
/* extern */
extern STATE gnlinkEnable;
extern UINT8 userLogin[10];
extern BOOL printfEnable;
extern UINT8 taskCmd;
extern UINT16 vlanExistNum;
/*******************************************************************************
函数:clear
功能:清屏
参数:
输入--
输出--
返回:
描述:VT100模式下的控制清屏。
*******************************************************************************/
void clear(void)
{
printf("\x1b\x5b\x32\x4a");
}
/*******************************************************************************
函数:sysHelp
功能:打印系统帮助信息
参数:
输入--
输出--
返回:
描述:
*******************************************************************************/
void sysHelp(void)
{
printf("\n1 You can type 'list' or '?', when you want to see all the commands!");
printf("\n2 [] mean that position should be a variable.");
printf("\n3 Enter complete command, follow by '/', then show the use of command.");
printf("\n");
}
/*******************************************************************************
函数:sysMsgShow
功能:显示系统信息
参数:
输入--
输出--
返回:
描述:
*******************************************************************************/
void sysMsgShow( void )
{
//公司
commonMsgPrint(3,TRUE);
//版本
commonMsgPrint(5,TRUE);
//版本日期
commonMsgPrint(6,TRUE);
//用户空闲时间
commonMsgPrint(10,TRUE);
printf("%ld seconds", idletime);
#if 0
//PVID范围
pvid = glbpvidRead();
pvid = pvid<<8;
commonMsgPrint(11,TRUE);
pvidPrint(pvid);
//gnlink状态
commonMsgPrint(12,TRUE);
if (gnlinkEnable == ENABLE)
{
commonMsgPrint(1,FALSE);
}
else
{
commonMsgPrint(2,FALSE);
}
//广播风暴信息
commonMsgPrint(13,TRUE);
if ( BIObIsRegBitsOn(GLOBAL_FUNC_CFG, 0x08))
{
BIOvReadRegW(BSF_XOFF_THRED, &retInt);
printf("on-%d", retInt);
BIOvReadRegW(BSF_XON_THRED, &retInt);
printf(" off-%d", retInt);
BIOvReadRegB(BSF_XOFF, &retChar);
if (retChar == 1)
{
printf(" running");
}
}
else
{
commonMsgPrint(2,FALSE);
}
if (strcmp((INT8*)userLogin, (INT8*)SuperUsrName) == 0)
{
UINT16 powerOn;
//EERead(ADD_SWITCH_RESET_TIME, (UINT8 *)&powerOn, 2);
printf("\n\npwOn : %d", powerOn);
}
#endif
}
/*******************************************************************************
函数:debugPrintf
功能:设置打印配置。
参数:
输入--type:打印类型。
action:=0:减去这个打印类型;其他:增加这个类型。
输出--
返回:
描述:
*******************************************************************************/
void debugPrintf(UINT16 type, UINT8 action)
{
if (action)
{
switch (type)
{
case 0:
printfState = PRINTF_NON;
break;
case 1:
printfState |= PRINTF_EEPROM;
break;
case 2:
printfState |= PRINTF_PACKET;
break;
case 3:
printfState |= PRINTF_VLAN;
break;
case 4:
printfState |= PRINTF_PORT;
break;
case 5:
printfState |= PRINTF_GNLINK;
break;
case 32:
printfState |= PRINTF_ALL;
break;
default:
printfState = 0;
break;
}
}
else
{
switch (type)
{
case 0:
printfState = PRINTF_NON;
break;
case 1:
printfState &= ~PRINTF_EEPROM;
break;
case 2:
printfState &= ~PRINTF_PACKET;
break;
case 3:
printfState &= ~PRINTF_VLAN;
break;
case 4:
printfState &= ~PRINTF_PORT;
break;
case 5:
printfState &= ~PRINTF_GNLINK;
break;
case 32:
printfState &= ~PRINTF_ALL;
break;
default:
printfState = 0;
break;
}
}
}
/*******************************************************************************
函数:setLogoutTime
功能:设置空闲等待时间值
参数:
输入--tvalue:空闲等待时间。
输出--
返回:
描述:idletime是全局变量
*******************************************************************************/
void setLogoutTime(UINT32 tvalue)
{
//如果用户输入的值超出范围,则打印提示信息
if ((tvalue > 3000)||(tvalue<20))
{
commonMsgPrint(17,TRUE);
}
else/*否则修改idletime的值*/
{
idletime = tvalue;
}
}
/*******************************************************************************
函数:bit32
功能:将1左移position位
参数:
输入--
输出--
返回:
描述:
*******************************************************************************/
UINT32 bit32(UINT8 position)
{
return ((UINT32)0x1<<position);
}
/*******************************************************************************
函数:inputStr
功能:用户输入字符串
参数:
输入--string_flag:输入字符的类型。
inputedlen:已经输入字符的个数,也就是下面输入的字符开始的位置。
输出--
返回:输入的字符串的长度
描述:1、支持密码'*'回显,
2、支持提示符'?',
3、支持backspace,
4、支持用户输入命令回显,当前为一条,支持5条。
5、超时或者长度超过预定值才退出此函数。
*******************************************************************************/
UINT8 inputStr(UINT8 string_flag,UINT8 inputedlen)
{
UINT8 str_lenth;
UINT8 r_char;
UINT8 cmdRollBack;
idletime_tmp = 0; /*空闲时间的计数器(20ms的个数)*/
str_lenth = inputedlen; /*用户已经输入字符串的长度*/
cmdRollBack = commandLast;
/*字符串的最大长度MAXLENTH*/
while ( str_lenth < MAXLENTH )
{
/*用户输入的命令过长*/
if (str_lenth>=MAXLENTH)
{
return MAXLENTH;
}
r_char = getchar();
/*超时*/
if ( r_char == 0xff )
{
return 0xff;
}
/*用户输入ctrl+p,取上一以前的命令,支持5条命令回显*/
if (( r_char == 0x10) && (string_flag == GET_COMMAND_FLAG))
{
UINT32 i;
/*擦除原来的命令显示*/
for(i = str_lenth; i> 0; i--)/*for(i = 0; i<str_lenth; i++)*/
{
printf("\b");/*"\b"是退格格式符*/
printf(" ");
printf("\b");
}
if (cmdRollBack == 0)
{
cmdRollBack = MAX_COMMAND_LOOP-1;
}
else
{
cmdRollBack--;
}
strcpy(s, backupCommand[cmdRollBack]);
printf("%s",s);
str_lenth = strlen( s );
continue;
}
/*只处理可见字符*/
if ( ((r_char >= 0x20) && (r_char <= 0x7e)) || (r_char == '\b') || (r_char == '\r') )
{
if ( r_char != '\b' )
{
/*用户输入回车*/
if ( r_char == '\r' )/*"\r"是回车格式符*/
{
s[str_lenth] = '\0';
s[str_lenth+1] = '\0';
s[str_lenth+2] = '\0';
break;
}
/*用户输入密码,回显用'*'表示*/
if(string_flag == PASSWORD_FLAG)
{
putchar('*');
}
else
{
putchar(r_char);
}
/*用户输入提示符'?'*/
if((r_char == '?') && (string_flag == GET_COMMAND_FLAG))
{
s[str_lenth] = '\0';
s[str_lenth+1] = '\0';
s[str_lenth+2] = '?';/*0x3f '?'的ascii码*/
break;
}
/*用户输入提示符'/'*/
if((r_char == 0x2f) && (string_flag == GET_COMMAND_FLAG))
{
s[str_lenth] = '\0';
s[str_lenth+1] = '\0';
s[str_lenth+2] = '/';/*0x2f'/'的ascii码*/
break;
}
/*保存到字符串全局变量*/
if (((r_char>=0x41) && (r_char<=0x5a)) && (string_flag == GET_COMMAND_FLAG))
{
s[str_lenth++] = r_char + 0x20;/*大写字母都变成小写字母*/
}
else
{
s[str_lenth++] = r_char;
}
}
else
{
/*用户输入'backspace'*/
if ( str_lenth != 0 )
{
printf("\b");
printf(" ");
printf("\b");
str_lenth--;
s[str_lenth] = '\0';
}
}
}
}
strcpy(backupCommand[commandLast], s);
commandLast++;
if (commandLast == MAX_COMMAND_LOOP)
{
commandLast = 0;
}
return str_lenth;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -