⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compare.c~

📁 基于嵌入式linux的命令行接口
💻 C~
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************
文件名:compare.c

版权所有:武汉易捷通信有限公司

版本:V1.0

作者:吴友山

描述:命令行的处理流程。

日期:
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>

#include "config.h"
#include "Compare.h"

#include "login.h"
#include "Funconf.h"
#include "msgprint.h"

COMMAND_NODE * pHead;

UINT8 variableDeep;
INT8 variable_string[6][20];
UINT8 variable_string_length[6] = {0,0,0,0,0,0};

UINT8 listDeep = 0;/*显示行计数器*/
UINT8 taskCmd = 1;

extern UINT8 switchMac[6];/*cpu mac地址*/

/*命令编号是从1开始的*/
enum CMD_NUMBER
{
/*1*/ CMD_CLEAR,
/*2*/ CMD_HELP,
/*3*/ CMD_LIST,
/*4*/ CMD_LOGOUT,
/*5*/ CMD_RESET,
/*6*/ CMD_SH_SYS_MESS,
/*7*/ CMD_BCS_CONF,   
/*8*/ CMD_IDLE_SET,
/*9*/ CMD_VLAN_CREATE,
/*10*/CMD_VLAN_DEL,
/*11*/CMD_VLAN_SHOW,
/*12*/CMD_PORT_ENA,
/*13*/CMD_PORT_SHOW,
/*14*/CMD_PORT_SPEED,
/*15*/CMD_PORT_DUP,
/*16*/CMD_PORT_AUTO,
#if 0 /*这个功能没有使用*/
/*17*/CMD_PORT_LOCK,
#endif
/*18*/CMD_PORT_FLOW,
/*19*/CMD_PORT_TAG,
/*20*/CMD_PORT_PVID,
#if 0 /*这个功能没有使用*/
/*21*/CMD_PORT_PRIOR,
#endif

#if 0 /*这个功能没有使用*/
/*22*/CMD_PORT_BASE_PRI,
#endif

#if 0 /*这个功能没有使用*/
/*23*/CMD_TRUNK_EN,
#endif

/*24*/CMD_VLAN_SET_PORT,
/*25*/CMD_AGING_TIME_SET,
/*26*/CMD_MACR_SHOW,
/*27*/CMD_MACR_WRITE,
/*28*/CMD_PHYR_SHOW,
/*29*/CMD_PHYR_WRITE,
/*30*/CMD_VLAN_SET_TAG,

#if 0 /*这个功能没有使用*/
/*31*/CMD_LOAD_OS,
#endif
/*32*/CMD_FDB,
/*33*/CMD_HOSTMAC_SET,
/*34*/CMD_EE_TEST,
/*35*/CMD_EE_WRITE,
/*36*/CMD_EE_READ,
/*37*/CMD_EE_DELAY,
/*38*/CMD_EE_ERASE,
/*39*/CMD_SAVE,
/*40*/CMD_REBOOT,
/*41*/CMD_MACR_SHOW_ALL,
/*42*/CMD_MACADDR_INSERT,
/*43*/CMD_PHYREG_SHOW,
/*44*/CMD_DEBUG_ENA,
/*45*/CMD_GLBPVID_SET,
/*46*/CMD_ISOLATE,
/*47*/CMD_SWITCHNAME_SET,
/*48*/CMD_GNLINK_ENABLE,
/*49*/CMD_USER_CONFIG,
/*50*/CMD_MAC_DEL,
/*51*/CMD_PORT_TEST
#if 0 /*不能使用,否则会影响绑定*/
/*52*/CMD_HUB
#endif
};  
    
struct  cmd_entry
{
    	UINT8 cmdEna;/*1:用户命令;0:超级管理员命令*/
    	UINT8 cmdNum;/*命令编号*/
    	INT8 *cmdString;/*命令字符串*/
};

#define MAX_COMMAND 46
const struct cmd_entry commandList[MAX_COMMAND] =
{   
/*1*/  {1, CMD_CLEAR, "clear"},/*clear*/
/*2*/  {1, CMD_HELP, "help"},/*sysHelp*/
/*3*/  {1, CMD_LIST, "list"},/*list*/
/*4*/  {1, CMD_LOGOUT, "logout"},/**/
/*5*/  {1, CMD_RESET, "reset"},/*reset*/
/*6*/  {1, CMD_SH_SYS_MESS, "show message"},/*sysMsgShow*/
/*7*/  {1, CMD_BCS_CONF, "config broadstorm [1-1000,0-disable]"},/*setBroadcast*/
/*8*/  {1, CMD_IDLE_SET, "config logout-time [20-3000(s)]"},/**/
/*9*/  {1, CMD_VLAN_CREATE, "create vlan [vlanid]"},/**/
/*10*/{1, CMD_VLAN_DEL, "delete vlan [all|vlanid]"},/**/
/*11*/{1, CMD_VLAN_SHOW, "show vlan [all|vlanid]"},/**/
/*12*/{1, CMD_PORT_ENA, "config port [all|portlist] enable [enable|disable]"},/**/
/*13*/{1, CMD_PORT_SHOW, "show port [all|portlist] status"},/**/
/*14*/{1, CMD_PORT_SPEED, "config port [all|portlist] speed [100|10]"},/**/
/*15*/{1, CMD_PORT_DUP, "config port [all|portlist] duplex [full|half]"},/**/
/*16*/{1, CMD_PORT_AUTO, "config port [all|portlist] auto [enable|disable]"},/**/
#if 0 /*这个功能没有使用*/
/*17*/{0, CMD_PORT_LOCK, "config port [all|portlist] lock [enable|disable]"},/**/
#endif
/*18*/{1, CMD_PORT_FLOW, "config port [all|portlist] flow [enable|disable]"},/**/
/*19*/{1, CMD_PORT_TAG, "config port [all|portlist] tag [tag|untag]"},/**/
/*20*/{1, CMD_PORT_PVID, "config port [all|portlist] pvid [pvid]"},/**/
#if 0 /*这个功能没有使用*/
/*21*/{0, CMD_PORT_PRIOR, "config port [all|portlist] priority [portbase|vlan|tos]"},/**/
#endif

#if 0 /*这个功能没有使用*/
/*22*/{0, CMD_PORT_BASE_PRI, "config port [all|portlist] portbase_priority [high|low]"},/**/
#endif

#if 0 /*这个功能没有使用*/
/*23*/{0, CMD_TRUNK_EN, "config trunk [group] [enable|disable]"},/**/
#endif

/*24*/{1, CMD_VLAN_SET_PORT, "config vlan [vlanid] [add|delete] port [all|portlist]"},/**/
/*25*/{1, CMD_AGING_TIME_SET, "config aging-time [20-255(s),0-disable]"},/**/
/*26*/{0, CMD_MACR_SHOW, "reg mac [address] show"},
/*27*/{0, CMD_MACR_WRITE, "reg mac [address] write [value]"},
/*28*/{0, CMD_PHYR_SHOW, "reg phy [port] [address] read"},
/*29*/{0, CMD_PHYR_WRITE, "reg phy [port] [address] write [value]"},
/*30*/{0, CMD_VLAN_SET_TAG, "config vlan [vlanid] [add|delete] tag [all|portlist]"},
#if 0 /*这个功能没有使用*/
/*31*/{0, CMD_LOAD_OS, "update new os"},
#endif

/*32*/{1, CMD_FDB, "show mac-address [all|static|dynamic|port|mac|lock]"},
/*33*/{0, CMD_HOSTMAC_SET, "config switch-mac [xx:xx:xx:xx:xx:xx]"},
/*34*/{0, CMD_EE_TEST, "eeprom test [address] [data]"},
/*35*/{0, CMD_EE_WRITE, "eeprom write [address] [data]"},
/*36*/{0, CMD_EE_READ, "eeprom read [address]"},
/*37*/{0, CMD_EE_DELAY, "eeprom delay [time]"},
/*38*/{0, CMD_EE_ERASE, "erase eeprom"},
/*39*/{1, CMD_SAVE, "save"},
/*40*/{1, CMD_REBOOT, "reboot"},
/*41*/{0, CMD_MACR_SHOW_ALL, "show macreg all"},
/*42*/{1, CMD_MACADDR_INSERT, "mac-address add [xx:xx:xx:xx:xx:xx] [port] [lock|static]"},
/*43*/{0, CMD_PHYREG_SHOW, "show phyreg [port] all"},
/*44*/{0, CMD_DEBUG_ENA, "ddebug [add|del] [type]"},
/*45*/{1, CMD_GLBPVID_SET, "config start-pvid"},/**/
/*46*/{1, CMD_ISOLATE, "isolate [uplinkport] [startVlanid]"},
/*47*/{1, CMD_SWITCHNAME_SET, "config lanswitch-name"},
/*48*/{1, CMD_GNLINK_ENABLE, "config egmp [enable|disable]"},
/*49*/{1, CMD_USER_CONFIG, "config user [name]"},
/*50*/{1, CMD_MAC_DEL, "delete mac-address [all|static|dynamic|port|mac|lock]"},
/*51*/{1, CMD_PORT_TEST, "loopback [all|portlist] [external|internal]"},
#if 0 /*不能使用,否则会影响绑定*/
/*52*/{0, CMD_HUB, "config mac-learning [enable|disable]"},
#endif
};    
      
INT8 *const outputStringList[MAX_COMMAND] =
{
/*1*/  {"Clear sceen."},/*clear*/
/*2*/  {"Get system basic help."},/*sysHelp*/
/*3*/  {"List all command valid."},/*list*/
/*4*/  {"User logout, then relogin."},/**/
/*5*/  {"Reset to default configuration.\nAll the data saved will be deleted, except switch MAC and name.\nThen reboot the switch.\n(Can't recover!!!!!!)"},/*reset switch*/
/*6*/  {"Show switch's message"},/*show message*/
/*7*/  {"Set broadcast storm filter value.\n  [on] - when broadstorm packet number > [on], funtion broadcast storm filter will be turn on\n  [off] - when number < [off], will be turn off.\nIf [off] equal 0 then disable filter"},/*broadstorm config [value]*/
/*8*/  {"Set logout time to [value].\nIf user has no action during logout time, auto logout"},/*logout config [time]*/
/*9*/  {"Create a vlan.\nRange :1-4094"},/**/
/*10*/{"Delete a or all vlan.\nRange 1-4094"},/**/
/*11*/{"Show a or all vlan's port member"},/**/
/*12*/{"Enable ports to recieve and transmit packet.\n[all|portlit]: 1,2,5-16 or all"},/**/
/*13*/{"Show ports' status.\n[all|portlit]: 1,2,5-16 or all"},/**/
/*14*/{"Config ports' speed as 100M or 10M.\n[all|portlit]: 1,2,5-16 or all"},/**/
/*15*/{"Config ports' duplex as full or half.\n[all|portlit]: 1,2,5-16 or all"},/**/
/*16*/{"Config ports'auto-negotiation enable or disable.\n[all|portlit]: 1,2,5-16 or all"},/**/
#if 0 /*这个功能没有使用*/
/*17*/{"port [all|portlist] lock [enable|disable]"},/**/
#endif
/*18*/{"port [all|portlist] flow [enable|disable]"},/**/
/*19*/{"Config ports as tag or untag.\n[all|portlit]: 1,2,5-16 or all"},/**/
/*20*/{"Config ports' pvid. Pvid should be in the range.\nSee command --- config start-pvid\n[all|portlit]: 1,2,5-16 or all."},/**/
#if 0 /*这个功能没有使用*/
/*21*/{"port [all|portlist] priority [portbase|vlan|tos]"},/**/
/*22*/{"port [all|portlist] portbase_priority [high|low]"},/**/
/*23*/{"config trunk [group] [enable|disable]"},/**/
#endif
/*24*/{"Add or delete ports from vlan [vlanid]\n[all|portlit]: 1,2,5-16 or all"},/**/
/*25*/{"Config mac address aging time.\nrange: 60-755 S"},/**/
/*26*/{"reg mac [address] show "},
/*27*/{"reg mac [address] write [value]"},
/*28*/{"reg phy [port] [address] read"},
/*29*/{"reg phy [port] [address] write [value]"},
/*30*/{"vlan [vlannumber] tags [add|delete] [all|taglist]"},
#if 0 /*这个功能没有使用*/
/*31*/{"Load new os from serial port of pc."},
#endif
/*32*/{"Show all MAC in table"},
/*33*/{"Config host's mac as xx:xx:xx:xx:xx:xx\nxx is HEX, if less than 0xf, should add adition 0.\nex -- 01:02:ac:ef:10:bd"},
/*34*/{"eeprom test [address] [data]"},
/*35*/{"eeprom write [address] [data]"},
/*36*/{"eeprom read [address]"},
/*37*/{"eeprom delay [time]"},
/*38*/{"eeprom erase all"},
/*39*/{"Save vlan, port, aging time, gnlink status, pvid range , speed , duplex and so on."},
/*40*/{"Reboot the switch.\nLoad configuration from flash"},
/*41*/{"show all macreg"},
/*42*/{"Inser a static mac address as xx:xx:xx:xx:xx:xx\nxx is HEX, if less than 0xf, should add adition 0.\nex -- 01:02:ac:ef:10:bd \nlock is bind mac"},
/*43*/{"Show all phyreg of [port]"},
/*44*/{"Debug\n0 none\n1 e\n2 pa\n3 v\n4 po\n5 gn\n32 all"},
/*45*/{"The size of pvid range is 256 continuously!"},/**/
/*46*/{"Isolate port, uplinkport range: 1 to 24(16).\nValue 0 means no set isolation.\nstartVlanid range: 2 to (4094 - 24(16))."},
/*47*/{"Set switchname, charactor must be number or letter."},
/*48*/{"Enable or disable egmp"},
/*49*/{"Change the user's name and password at the same time.\nLetter or number allowed."},
/*50*/{"Delete special type of MAC."},
/*51*/{"Test all linkup port"},
#if 0 /*不能使用,否则会影响绑定*/
/*52*/{"Config as a hub"},
#endif
};

/* extern */
extern INT8 s[MAXLENTH];

extern INT8 userLogin[10]; /*保存登陆的用户名称*/

extern void ggmpEnable(UINT8 flg);

#define WORD_EQUAL 0
#define WORD_SMALLER -1

static BOOL stringCpm(INT8 * command_string, INT8 *retWord);
static UINT8 get2Num(INT8* string);
static UINT8 getNum(INT8 *string);
static UINT8 enableJudge(INT8 * judgeString);

/*******************************************************************************
函数:strToNum
功能:将字符串转换为十进制数字
参数:
    输入--string:要转换的字符串。
    输出--
返回:转换后的数据。
描述:字符串的长度不能大于4。
*******************************************************************************/
UINT16 strToNum(INT8 * string)
{
	UINT32 i,length;
   	UINT32 number;
    	
    	i = strlen(string);	
    	if (i==0)
    	{
        	return NOT_DATA;
    	}
		
    	if (i>4) 
    	{
		return DATA_OVER_RANG;
    	}

	number = 0;		
    	for(length = 0; length<i; length++)
    	{
        	if ((string[length]<=0x39) && (string[length]>=0x30))
        	{
            		number = number*10+(string[length]-0x30);
        	}
        	else
        	{
            		return NOT_DATA;
        	}
    	}

    	return (UINT16)number;
}



/*******************************************************************************
函数:stringCpm
功能:判断单词是否匹配
参数:
    输入--command_string:命令字符串。
                    retWord:是否包含的字符串。
    输出--
返回:OK:包含字符串。
描述:1、判断retWord是否包括在command_string中。
   2、retWord的长度比command_string要小。
		  3、是从第一个字符开始比较的。
*******************************************************************************/
static BOOL stringCpm(INT8 * command_string, INT8 *retWord)
{
    	UINT i,length;

    	length =  strlen(retWord);

	if(strlen(command_string)<length)
	{
		return ERROR;
	}

    	for (i = 0; i< length; i++)
    	{
        	if (command_string[i] != retWord[i])
        	{
            		return ERROR;
        	}
    	}

    	return OK;
}

/*******************************************************************************
函数:get2Num
功能:将字符串的前两个字符转换为2位的十进制数字。
参数:
    输入--string:要输入的字符串。
    输出--
返回:得到转换后的数据。
描述:
*******************************************************************************/
static UINT8 get2Num(INT8* string)
{
    	UINT number;
		
    	number = (*string)-0x30;
    	number = number*10 + (*(string+1)-0x30);
    	return (UINT8)number;
}

/*******************************************************************************
函数:get1Num
功能:将字符串的最前面的字符转换为十进制数字
参数:
    输入--string:要输入的字符串。
    输出--
返回:得到转换后的数据。
描述:字符表示的十进制数字为1位的
*******************************************************************************/
static UINT8 get1Num(INT8* string)
{
    	return (*string)-0x30;
}

/*******************************************************************************
函数:getNum
功能:将字符串转换为十进制数字
参数:
    输入--string:输入的字符串。
    输出--
返回:
描述:字符表示的十进制数字可以为1位或是2位的
*******************************************************************************/
static UINT8 getNum(INT8 *string)
{
    	if((*(string+1)>=0x30)&&(*(string+1)<=0x39))
    	{
        	return get2Num(string);
    	}
    	else
    	{
        	return get1Num(string);
    	}
}

/*******************************************************************************
函数:strToHex
功能:将字符串转换为十六进制数字。
参数:
    输入--
    输出--
返回:DATA_OVER_RANG:字符串超出长度了。
                NOT_DATA:不是数值型。
                number:得到16进制的数据。
描述:1、输入的字符串的前面字节是数据的高字节。
		  2、输入的字符串不包括结尾只能有4个字节长。
*******************************************************************************/
UINT16 strToHex(INT8 * string)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -