www.pudn.com > IEC104_codeamaterial.rar > cmdtbl.c, change:2010-09-21,size:31299b


/*------------------------------------------------------------------------
 Module:		cmdtbl.c
 Author:		solar
 Project:		pas300m 
 Creation Date: 2005-9-29
 Description:	
------------------------------------------------------------------------*/
/*------------------------------------------------------------------------
 $Log: $
------------------------------------------------------------------------*/

#include "syscfg.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mytypes.h"
//#include "pcol.h"
#include "sys.h"

extern 	int g_DispNum;

/*------------------------------------------------------------------------
 Procedure:     clsCmd ID:1
 Purpose:       清除屏幕
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *clsHelp[] = {
		"清除屏幕",
		"",	
		0,
};
int clsCmd(int argc,char *argv[])
{ 
	clrscr();
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     addrCmd ID:1
 Purpose:       地址
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *addrHelp[] = {
		"显示地址",
		"",
		0,
};
int addrCmd(int argc,char *argv[])
{ 
	myprintf("地址:%d\n", g_Sys.AddrInfo.wAddr);
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     faultCmd ID:1
 Purpose:       故障
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *faultHelp[] = {
		"显示故障",
		"",
		0,
};
int faultCmd(int argc,char *argv[])
{ 
	if (g_Sys.dwErrCode == 0) 
	{
	    myprintf("无故障!\n");
		return 0;
	}	
	if (g_Sys.dwErrCode & SYS_ERR_SYS) myprintf("致命故障!\n");
	if (g_Sys.dwErrCode & SYS_ERR_ADDR)  myprintf("地址错误!\n");
	if (g_Sys.dwErrCode & SYS_ERR_CFG) myprintf("未知板卡型号!\n");
	if (g_Sys.dwErrCode & SYS_ERR_COMM)  myprintf("CAN 故障!\n");
	if (g_Sys.dwErrCode & SYS_ERR_GAIN)  myprintf("交采整定文件非法!\n");
	if (g_Sys.dwErrCode & SYS_ERR_LOGIN)   myprintf("登录失败!\n");
	
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     rebootCmd ID:1
 Purpose:       复位
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *rebootHelp[] = {
		"复位",
		"",
		0,
};
int rebootCmd(int argc,char *argv[])
{ 
	reboot();
	return 0;
}

#ifdef INCLUDE_TIMER
/*------------------------------------------------------------------------
 Procedure:     timesetCmd ID:1
 Purpose:       设置系统时间
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *timesetHelp[] = {
		"设置系统时间",
		"年 月 日 时 分 秒[如20010 9 18 9 15 0]",
		0,
};
int timesetCmd(int argc,char *argv[])
{
	struct VSysClock clock;
	if(argc != 7) return -1;

	clock.wYear = (WORD)atoi(argv[1]);
	clock.byMonth = (BYTE)atoi(argv[2]);
	clock.byDay = (BYTE)atoi(argv[3]);
	clock.byHour = (BYTE)atoi(argv[4]);
	clock.byMinute = (BYTE)atoi(argv[5]);
	clock.bySecond = (BYTE)atoi(argv[6]);
	clock.wMSecond = 0;
	clock.byWeek = 0;
	
	SetSysClock(&clock, SYSCLOCK);

	return 0;
}
/*------------------------------------------------------------------------
 Procedure:     timeCmd ID:1
 Purpose:       读取系统时间
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *timeHelp[] = {
		"读取系统时间",
		"",
		0,
};
int timeCmd(int argc,char *argv[])
{
	struct VSysClock clock;

	GetSysClock(&clock, SYSCLOCK);

	myprintf("当前时间:%d-%d-%d  %02d:%02d:%02d:%03d\n",
		    clock.wYear,clock.byMonth,clock.byDay,clock.byHour,clock.byMinute,clock.bySecond, clock.wMSecond);
	return 0;
}
#endif

#if 0
#if ((TYPE_BACK&TYPE_MASK) == BACK_AI)
const char *aiHelp[] = {
		"显示AI: ",
		"循环显示次数",
		0,
};
int aiCmd(int argc,char *argv[])
{
	int j;
	
	if (g_DispNum == 0)     /*first in*/
	{
		if(argc != 2) {
			myprintf("参数个数不对!\n");
			return -1;
		}

		g_DispNum = atoi(argv[1]);
		if(g_DispNum<1 || g_DispNum>10000) {
			g_DispNum = 0;
			return -1;
		}	
		
		clrscr();
	}	
	
    for(j=0; j<AI_NUM; j++)
	{
		myprintf("#%d:%5u\n", j+1, gAI[j].value);
    }

#ifdef __DEBUG__
	myputchar('\n');

    for(j=0; j<AD_CHAN_NUM+1; j++)
	{
		myprintf("#%d:%5d\n", j+1, gAd_Buf_TmRateTemp[j]);
    }

	/*myputchar('\n');

    for(j=0; j<AI_NUM+1; j++)
	{
		myprintf("#%d=%5u\n", j+1, gAd_BufTemp[j]);
    }*/
#endif

	g_DispNum--;
	if (g_DispNum == 0) {
		myputchar('\n');
	}
	else    gotoxy(0,1);
	
	return 0;
}

const char *aicfgHelp[] = {
		"显示AI配置",
		"",
		"",
		0,
};
int aicfgCmd(int argc,char *argv[])
{
	int j;
		
    for(j=0; j<AI_NUM; j++)
	{
        switch (gAI_Cfg[j].cfg)
        {
            case PV_TYPE_AI_DISABLE:
				myprintf("#%d:Disable", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_AI_420MA:
				myprintf("#%d:4-20mA", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;				
            case PV_TYPE_AI_15V:
				myprintf("#%d:1-5V", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_AI_010MA:
				myprintf("#%d:0-10mA", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_AI_020MA:
				myprintf("#%d:0-20mA", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_AI_05V:
				myprintf("#%d:0-5V", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_AI_010V:
				myprintf("#%d:0-10V", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            default:
				myprintf("#%d:invalid", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;					
		}
    }
	
	return 0;
}

const char *aiparaHelp[] = {
		"AI整定,输入20mA对应61439",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示全通道整定",
		0,
};
int aiparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}
	
	WriteAI_Para(no-1);
	
	return 0;
}

const char *aiclearparaHelp[] = {
		"撤消AI整定,使用自整定系数",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示撤消所有通道",
		0,
};
int aiclearparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}
	
	ClearAI_Para(no-1);
	
	return 0;
}

#endif

#if ((TYPE_BACK&TYPE_MASK) == BACK_TC)
const char *tcHelp[] = {
		"显示TC: ",
		"循环显示次数",
		"",
		0,
};
int tcCmd(int argc,char *argv[])
{
	int j;
	
	if (g_DispNum == 0)     /*first in*/
	{
		if(argc != 2) {
			myprintf("参数个数不对!\n");
			return -1;
		}

		g_DispNum = atoi(argv[1]);
		if(g_DispNum<1 || g_DispNum>10000) {
			g_DispNum = 0;
			return -1;
		}	
		
		clrscr();
	}	
	
    for(j=0; j<TC_NUM; j++)
	{
		myprintf("#%d:%7.2f℃\n", j+1, gTC[j].value);
    }

#ifdef __DEBUG__
	/*myputchar('\n');

    for(j=0; j<AD_CHAN_NUM; j++)
	{
		myprintf("#%d:%5d\n", j+1, gAd_Buf_TmRateTemp[j]);
    }*/

	myputchar('\n');
	

    for(j=0; j<AD_CHAN_NUM-1; j++)
	{
		myprintf("#%d=0x%4x\n", j+1, gAd_BufTemp[j]);
		/*myprintf("#%d=%d\n", j+1, gAd_BufTemp[j]-0x8000);*/
    }

	myprintf("#%d=%5u\n", AD_CHAN_NUM-1, gAd_BufTemp[AD_CHAN_NUM-1]);
#endif

	g_DispNum--;
	if (g_DispNum == 0) {
		myputchar('\n');
	}
	else    gotoxy(0,1);
	
	return 0;
}

const char *tccfgHelp[] = {
		"显示TC配置",
		"",
		"",
		0,
};
int tccfgCmd(int argc,char *argv[])
{
	int j;
		
    for(j=0; j<TC_NUM; j++)
	{
        switch (gTC_Cfg[j].cfg)
        {
            case PV_TYPE_TC_DISABLE:
				myprintf("#%d:Disable", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_B:
				myprintf("#%d:B", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;				
            case PV_TYPE_TC_E:
				myprintf("#%d:E", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_J:
				myprintf("#%d:J", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_K:
				myprintf("#%d:K", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_N:
				myprintf("#%d:N", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_R:
				myprintf("#%d:R", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_S:
				myprintf("#%d:S", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_TC_T:
				myprintf("#%d:T", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            default:
				myprintf("#%d:invalid", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;					
		}
    }
	
	return 0;
}

const char *tcparaHelp[] = {
		"TC整定,输入40mV对应16383.75",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示全通道整定",
		0,
};
int tcparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}

	WriteTC_Para(no-1);
	
	return 0;
}

const char *tcclearparaHelp[] = {
		"撤消TC整定,使用自整定系数",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示撤消所有通道",
		0,
};
int tcclearparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}

	ClearTC_Para(no-1);
	
	return 0;
}
#endif

#if ((TYPE_BACK&TYPE_MASK) == BACK_RTD)
const char *rtdHelp[] = {
		"显示RTD",
		"循环显示次数",
		"",
		0,
};
int rtdCmd(int argc,char *argv[])
{
	int j;
	
	if (g_DispNum == 0)     /*first in*/
	{
		if(argc != 2) {
			myprintf("参数个数不对!\n");
			return -1;
		}

		g_DispNum = atoi(argv[1]);
		if(g_DispNum<1 || g_DispNum>10000) {
			g_DispNum = 0;
			return -1;
		}	
		
		clrscr();
	}	
	
    for(j=0; j<RTD_NUM; j++)
	{
		myprintf("#%d:%6.2f℃\n", j+1, gRTD[j].value);
    }

#ifdef __DEBUG__
	myputchar('\n');

    for(j=0; j<AD_CHAN_NUM; j++)
	{
		myprintf("#%d:%5d\n", j+1, gAd_Buf_TmRateTemp[j]);
    }

	/*myputchar('\n');
	

    for(j=0; j<AD_CHAN_NUM; j++)
	{
		myprintf("#%d=%5u\n", j+1, gAd_BufTemp[j]);
    }*/
#endif

	g_DispNum--;
	if (g_DispNum == 0) {
		myputchar('\n');
	}
	else    gotoxy(0,1);
	
	return 0;
}

const char *rtdcfgHelp[] = {
		"显示RTD配置",
		"",
		"",
		0,
};
int rtdcfgCmd(int argc,char *argv[])
{
	int j;
		
    for(j=0; j<RTD_NUM; j++)
	{
        switch (gRTD_Cfg[j].cfg)
        {
            case PV_TYPE_RTD_DISABLE:
				myprintf("#%d:Disable", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_RTD_PT50:
				myprintf("#%d:PT50", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;				
            case PV_TYPE_RTD_PT100:
				myprintf("#%d:PT100", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_RTD_CU50:
				myprintf("#%d:CU50", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            case PV_TYPE_RTD_CU100:
				myprintf("#%d:CU100", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;
            default:
				myprintf("#%d:invalid", j+1);
				if ((gAd_Para[j].flag == 0x5A) && ((gAd_Para[j].type&TYPE_MASK) == (TYPE_BACK&TYPE_MASK)))
					myputchar('\n');
				else
					myputs(" 自整定系数\n");				
				break;					
		}
    }
	
	return 0;
}

const char *rtdparaHelp[] = {
		"RTD整定,以100欧对应0℃",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示全通道整定",
		0,
};
int rtdparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}

	WriteRTD_Para(no-1);
	
	return 0;
}

const char *rtdclearparaHelp[] = {
		"撤消RTD整定,使用自整定系数",
		"通道号 密码",
		"参数1: 通道号",
		"参数2: 密码",		
		"通道号大于通道个数表示撤消所有通道",
		0,
};
int rtdclearparaCmd(int argc,char *argv[])
{
    BYTE no;
	
	if(argc != 3) {
		myprintf("参数个数不对!\n");
		return -1;
	}	

    if (strcmp(argv[2], "pas300m") != 0){
		myprintf("密码错误!\n");
		return -1;
	}	
		
	no = (BYTE)atoi(argv[1]);
	if (no==0){
		myprintf("非法通道号!\n");
		return -1;        
	}

	ClearRTD_Para(no-1);
	
	return 0;
}
#endif
#endif

#ifdef INCLUDE_YX
const char *yxHelp[] = {
		"DI状态显示",
		"循环显示次数",
		0,
};
int yxCmd(int argc,char *argv[])
{
	int i, j, port;
	WORD bit;
	
	if (g_DispNum == 0)     /*first in*/
	{
		if(argc != 2) {
			myprintf("参数个数不对!\n");
			return -1;
		}

		g_DispNum = atoi(argv[1]);
		if(g_DispNum<1 || g_DispNum>10000) {
			g_DispNum = 0;
			return -1;
		}	
		
		clrscr();
	}	

	i = 0;
	for(j=0; j<YX_NUM; j++)
	{
		port = g_YxNo2Port[j].port;
		bit = g_YxNo2Port[j].bit;
		if (g_DiValue[port]&bit)  
			myprintf("#%2d:合   ", j);
		else 
			myprintf("#%2d:分   ", j);
		i++;
		if (i == 4) 
		{
		    myputchar('\n');
			i = 0;
		}			
	}

	g_DispNum--;
	if (g_DispNum == 0) {
		myputchar('\n');
	}
	else    gotoxy(0,1);
	
	return 0;
}

const char *soeHelp[] = {
		"SOE显示",
		"",
		0,
};
int soeCmd(int argc,char *argv[])
{
    int i, j;
	WORD wp;    
	VSOEREC *psoe;
	struct VSysClock soetm;
	
    wp=gSoebuf.wp;

    j=1;
    for (i=wp-1; i>=0; i--)
    {
		psoe=gSoebuf.soe+i; 

		if (psoe->pchn == NULL) return 0;
        else if (psoe->value1) 		
    		myprintf("#%02d: %02d 分->合  ", j, psoe->pchn->yxno);
		else
			myprintf("#%02d: %02d 合->分  ", j, psoe->pchn->yxno);

		CalClockTo(&psoe->chg_tm, &soetm);		
		myprintf("%d-%d-%d  %02d:%02d:%02d:%03d\n",
				soetm.wYear,soetm.byMonth,soetm.byDay,soetm.byHour,soetm.byMinute,soetm.bySecond, soetm.wMSecond);        
		j++;
	}

    for (i=SOE_REC_BUF_SIZE-1; i>=wp; i--)
    {
		psoe=gSoebuf.soe+i; 

		if (psoe->pchn == NULL) return 0;
        else if (psoe->value1) 		
    		myprintf("#%02d: %02d 分->合  ", j, psoe->pchn->yxno);
		else
			myprintf("#%02d: %02d 合->分  ", j, psoe->pchn->yxno);

		CalClockTo(&psoe->chg_tm, &soetm);		
		myprintf("%d-%d-%d  %02d:%02d:%02d:%03d\n",
				soetm.wYear,soetm.byMonth,soetm.byDay,soetm.byHour,soetm.byMinute,soetm.bySecond, soetm.wMSecond);        
		j++;
	}
	
	myputchar('\n');
	
	return 0;
}

/*const char *dicfgHelp[] = {
		"显示DI配置",
		"",
		"",
		0,
};
int dicfgCmd(int argc,char *argv[])
{
	int i,j;
		
    i = 0;
	for(j=0; j<DI_NUM; j++)
	{
		if (gDI_Cfg[j].cfg & DICFG_SOE) 
			myprintf("#%02d:SOE    ", j+1);
		else
			myprintf("#%02d:DI     ", j+1);
		i++;
		if (i == 4) 
		{
		    myputchar('\n');
			i = 0;
		}	
    }	

	myputchar('\n');
	
	return 0;
}*/
#endif

#ifdef INCLUDE_YK
const char *ykHelp[] = {
		"YK命令",
		"YK号 合分选择 ",
		"参数1: 遥控号",
		"参数2: 合分选择",
		0,
};
int ykCmd(int argc,char *argv[])
{
	int no, value, ret;

	if(argc != 3){
		myprintf("命令格式错\n");
		return 0;		
	}

	no = atoi(argv[1]);		
	value = atoi(argv[2]);	
	if (value)
    	myprintf("第%d路:控合...", no);
	else
		myprintf("第%d路:控分...", no);

	ret = ykOutput(no, value);
	
	if (ret == 0)
		myprintf("成功\n");
	else if (ret == 1)
		myprintf("点号非法!\n");
	else if (ret == 2)
		myprintf("该点正在被操作!\n");
	else if (ret == 3)
		myprintf("控制硬件有问题!\n");
	else if (ret == 4)
		myprintf("控制禁止!\n");
	else if (ret == 5)
		myprintf("失败!\n");
		
	return 0;	
}
#endif

extern const char *HelpHelp[];
int Help(int argc,char *argv[]);

const struct monCommand cmdlist[] = {
	{ "?",		    Help,		HelpHelp},
	{ "help",		Help,		HelpHelp, },
	{ "cls",        clsCmd,		clsHelp, },
	{ "addr",		addrCmd, 	addrHelp, },
	{ "fault",		faultCmd, 	faultHelp, },
	{ "reboot",		rebootCmd,	rebootHelp, },
#ifdef INCLUDE_TIMER
	{ "time",       timeCmd,	timeHelp, },
	{ "timeset",    timesetCmd,	timesetHelp, },
#endif	
/*#if ((TYPE_BACK&TYPE_MASK) == BACK_AI)
	{ "ai",     	aiCmd,		aiHelp, },
	{ "aicfg",     	aicfgCmd,	aicfgHelp, },
	{ "#",      	aiparaCmd,	aiparaHelp, },
	{ "&",      	aiclearparaCmd,	aiclearparaHelp, },
#endif	
#if ((TYPE_BACK&TYPE_MASK) == BACK_TC)
	{ "tc", 		tcCmd,		tcHelp, },
	{ "tccfg",		tccfgCmd,	tccfgHelp, },
	{ "#",      	tcparaCmd,	tcparaHelp, },
	{ "&",      	tcclearparaCmd,	tcclearparaHelp, },
#endif	
#if ((TYPE_BACK&TYPE_MASK) == BACK_RTD)
	{ "rtd", 		rtdCmd,		rtdHelp, },
	{ "rtdcfg",		rtdcfgCmd,	rtdcfgHelp, },
	{ "#",      	rtdparaCmd,	rtdparaHelp, },
	{ "&",      	rtdclearparaCmd,	rtdclearparaHelp, },
#endif*/	
#ifdef INCLUDE_YX
	{ "yx", 		yxCmd,		yxHelp, },
	{ "soe", 		soeCmd,		soeHelp, },
	//{ "dicfg",		dicfgCmd,	dicfgHelp, },
#endif	
#ifdef INCLUDE_YK
	{ "ykoutput", 	ykCmd,		ykHelp, },
#endif	
#if 0
	{ "mac", 	    macCmd,  	macHelp, },
	{ "*",		    macsetCmd, 	macsetHelp, },
	{ "cd", 		cdCmd,		cdHelp, },
	{ "del",		delCmd, 	delHelp, }, 
	{ "dir",		dirCmd, 	dirHelp, },
	{ "mkdir",		mkdirCmd,	mkdirHelp, },
	{ "format", 	formatCmd,	formatHelp, },
	{ "rename", 	renameCmd,	renameHelp, },
	{ "get",		getCmd, 	getHelp, }, 
	{ "put",		putCmd, 	putHelp, },
#endif	
	{ 0,0,0, },
};

/* Help():
 * This command displays each commands help text.
 * The help text is assumed to be formatted as an array of strings
 * where...
 *	the first string is the command description;
 *	the second string is command usage;
 *	and all remaining strings up to the NULL are just printable text.
 */
const char *HelpHelp[] = {
		"显示命令列表",
		"-[d] [command]",
		"选项:",
		" -d   列出和描述命令",
		0,
};
/* showhelp():
 *	Called by Help() when it is time to print out some verbosity level of
 *	a command's help text.
 *	if...
 *		verbose == 2, then print all the help text;
 *		verbose == 1, then print the command name and abstract;
 *		verbose == 0, then print only the command name;
 */
int showhelp(const struct monCommand *list,int index,int verbose)
{
	const char **hp;
	struct monCommand *cptr;

	cptr = (struct monCommand *)&list[index];

	if (verbose == 2) {
		myprintf("%s\n", cptr->helptxt[0]);
		myprintf("用法: %s %s\n",cptr->name,cptr->helptxt[1]);

		hp = &cptr->helptxt[2];
		while(*hp)
			myprintf("%s\n",*hp++);
	}
	else if (verbose == 1) {
		/*add by wyj if namelen is only 1, then it is a spec cmd and don't show*/
		if (strlen(cptr->name) <2) return(0);
		myprintf(" %-12s %s\n", cptr->name,cptr->helptxt[0]);
	}
	else {
		/*add by wyj if namelen is only 1, then it is a spec cmd and don't show*/
		if (strlen(cptr->name) <2) return(0);
		myprintf("%-12s",cptr->name);
	}
	return(1);
}

int Help(int argc,char *argv[])
{
	struct	monCommand *cptr;
	char	*p;
	int		i, foundit, opt, descriptions;

	descriptions = 0;
	while((opt=getopt(argc,argv,"d")) != -1) {
		switch(opt) {
		case 'd':
			descriptions = 1;
			break;
		default:
			return(0);
		}
	}
	cptr = (struct	monCommand *)cmdlist;
	if (argc == optind) {
		foundit = 1;
		if (descriptions) {
			while(cptr->name) {
				showhelp(cmdlist,cptr-cmdlist,1);
				cptr++;
			}
			myputchar('\n');
		}
		else {
			i = 0;
			while(1) {
				if (showhelp(cmdlist,cptr-cmdlist,0)) {
					if ((++i%6) == 0)
						myputchar('\n');
				}
				cptr++; 
				if (cptr->name == 0L)
					break;
			}
			myputchar('\n');
		}
	}
	else {
		foundit = 0;
		p = argv[1];
		while(cptr->name) {
			if (strcmp(cptr->name,argv[1]) == 0) {
				foundit = showhelp(cmdlist,cptr-cmdlist,2);
				break;
			}
			cptr++;
		}
	}
	if (!foundit)
		myprintf("\"%s\" 未找到\n",argv[1]);
	return(0);
}

#if 0

/*------------------------------------------------------------------------
 Procedure:     macCmd ID:1
 Purpose:       显示Mac
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *macHelp[] = {
		"显示MAC",
		"",
		0,
};
int macCmd(int argc,char *argv[])
{ 
    int i;
	char *p;
	
    if (TestRunFlag(RUNF_MAC_NOCFG))
	{
        myputs("No valid MAC!\n");
		return 0;
    }	

    p = (char *)g_Mac;
	for (i=0; i<8; i++)
	{
    	myputchar(*p);
	    p++;
	}	

	myputchar('-');
	myputchar('2');
	myputchar('0');

	for (i=8; i<MAC_LEN; i++)
	{
    	myputchar(*p);
	    p++;
	}	

	myputchar('\n');
	
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     macsetCmd ID:1
 Purpose:       设置Mac
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
const char *macsetHelp[] = {
		"设置Mac",
		"",
		0,
};
int macsetCmd(int argc,char *argv[])
{ 
    int i;
	DWORD *value, p;
	BYTE lrccode;

    /*if (TestRunFlag(RUNF_MAC_NOCFG) == FALSE) return 0;*/
	if(argc !=2 ) return -1;

    lrccode = Lrc((BYTE *)argv[1], MAC_LEN);

	value = (DWORD *)argv[1];
	for (i=0; i<MAC_LEN/sizeof(DWORD); i++)
    	writeEEPROM((DWORD *)(g_Mac+i*4), &value[i]);
	
	p = MAKEDWORD(0, MAKEWORD(0x5A, lrccode));
	writeEEPROM((DWORD *)&g_Mac[MAC_LEN], &p);
	
	ClearRunFlag(RUNF_MAC_NOCFG);
	ClearFault(FAULT_MAC);

    myputs("Mac set OK!\n");
	
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     cdCmd ID:1
 Purpose:       改变路径
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *cdHelp[] = {
		"改变路径",
		"目录名",
		0,
};
int cdCmd(int argc,char *argv[])
{
	char name[100];
	DIR		*pDir;
	char   path[100];
	if(argc > 2) return -1;

	if(argc == 1){
		myprintf("%s\n", current_path);
		return 0;
	}
	if( (*argv[1]) == '.' ){
		strcpy(current_path, "/");
		return 0;
	}
	if( (*argv[1]) == '/' ){
		pDir = opendir(argv[1]);
    	if (pDir==NULL){
			myprintf("目录无效: %s\n", argv[1]);
	    	return -1;	
    	}
    	closedir(pDir);
    	strcpy(current_path, argv[1]);
	}
	else{
		strcpy(path,current_path);
		strcat(path, argv[1]);
		pDir = opendir(path);
    	if (pDir==NULL){
			myprintf("目录无效: %s\n", argv[1]);
	    	return -1;	
    	}
    	closedir(pDir);
    	strcpy(current_path, path);
	}	
	return 0;
}
/*------------------------------------------------------------------------
 Procedure:     delCmd ID:1
 Purpose:       删除文件
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *delHelp[] = {
		"删除文件",
		"文件名[区分大小写]",
		"",
		0,
};
int delCmd(int argc,char *argv[])
{
	char name[100];
	int error;
	
	if(argc != 2){
		myprintf("命令格式错\n");
		return 0;		
	}	 
	
	strcpy(name,current_path);
	strcat(name,"/");
	strcat(name, argv[1]);
	
	error = mf_unlink(name);
	if(error < 0)
		myprintf("删除%s文件失败\n", name);
		
	return 0;
}
/*------------------------------------------------------------------------
 Procedure:     dirCmd ID:1
 Purpose:       显示文件信息
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *dirHelp[] = {
		"显示文件信息",
		"",
		0,
};
int dirCmd(int argc,char *argv[])
{
    DIR		*pDir;		/* ptr to directory descriptor */
    struct dirent	*pDirEnt;	/* ptr to dirent */
	struct stat fstat;
	char name[100];
	char *path;

	if(argc > 2) return -1;
	if(argc == 1){
		pDir = opendir(current_path);
		path = current_path;
	}	
	else {
		pDir = opendir(argv[1]);
		path = argv[1];
	}	

    if (pDir==NULL)
    {
		myprintf("打开目录失败: %d\n", pDir);
		return 0;
    }  
    myprintf("文件名\t\t大小\n");
	do 
    {

      pDirEnt = readdir (pDir);
      if (pDirEnt!=NULL)
      {
       	myprintf("%s",pDirEnt->d_name);

		memset(name, 0, 100);
		strcat(name, path);
		if(strcmp(path, "/") != 0)
			strcat(name, "/");	
		strcat(name, pDirEnt->d_name);

        if(stat(name, &fstat) >= 0){
        	if( S_ISDIR (fstat.st_mode) )
				 myprintf("\t\t<DIR>");
       		else myprintf("\t\t%d",fstat.st_size);
        }
        	
      	myprintf("\n");
      }    
    }
    while ((pDirEnt!=NULL));
    
	closedir(pDir);

	myprintf("\n");
	fsstat();

    return 0;
}
/*------------------------------------------------------------------------
 Procedure:     mkdirCmd ID:1
 Purpose:       目录创建
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *mkdirHelp[] = {
		"目录创建",
		"目录名",
		0,
};
int mkdirCmd(int argc,char *argv[])
{
	char name[100];

	if(argc != 2) return 0;

	memset(name, 0, 100);
	strcat(name,"/");	/*TODO:当前路径 */
	strcat(name, argv[1]);

	mf_mkdir(name, 0);
}
/*------------------------------------------------------------------------
 Procedure:     formatCmd ID:1
 Purpose:       格式化磁盘
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *formatHelp[] = { 
		"格式化磁盘",
		"",
		0,
};
int formatCmd(int argc,char *argv[]); /*j_flash.cpp*/
/*------------------------------------------------------------------------
 Procedure:     renameCmd ID:1
 Purpose:       文件更名
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *renameHelp[] = {
		"文件更名[都必须使用全路径]",
		"源名 目标名",
		0,
};
int renameCmd(int argc,char *argv[])
{
	int ret;
	if(argc != 3) return -1;
	
	ret = rename(argv[1], argv[2]);
	if(ret < 0) myprintf("rename 操作失败\n");
	return ret;
}
/*------------------------------------------------------------------------
 Procedure:     getCmd ID:1
 Purpose:       上装文件
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *getHelp[] = {
		"上装文件",
		"文件名",
		0,
};
void UpLoad(char *name);
int getCmd(int argc,char *argv[])
{
#if 0
	char name[100];
	if( argc == 1) {
		myprintf("需要文件名!\n");
		return 1;
	}
	strcpy(name,current_path);
	if(strcmp(name, "/") != 0)
			strcat(name, "/");	
	strcat(name, argv[1]);
	
	UpLoad(name);
#endif	
	return 0;
}
/*------------------------------------------------------------------------
 Procedure:     putCmd ID:1
 Purpose:       下装文件
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *putHelp[] = {
		"下装文件",
		"",
		0,
};
void Download(void);
int putCmd(int argc,char *argv[])
{
#if 0
	myprintf("下装文件开始...\n");
	TPU_Int_Enable_Reg &= ~(1<<3);
	Download();
	TPU_Int_Enable_Reg |= (1<<3);
	return 0;
#endif
}
/*------------------------------------------------------------------------
 Procedure:     rebootCmd ID:1
 Purpose:       系统软件复位命令
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *rebootHelp[] = { 
		"系统软件复位",
		"",
		0,
};
void bspSoftReset(BYTE opt);
int rebootCmd(int argc,char *argv[])
{
	bspSoftReset(2);
	return 0;
}
char *warmrebootHelp[] = { 
		"系统软件热复位",
		"",
		0,
};
int warmrebootCmd(int argc,char *argv[])
{
	warmreset();
	return OK;
}
char *coldrebootHelp[] = { 
		"系统软件冷复位",
		"",
		0,
};
int coldrebootCmd(int argc,char *argv[])
{
	coldreset();
	return 0;
}

/*------------------------------------------------------------------------
 Procedure:     typeCmd ID:1
 Purpose:       显示文件内容
 Input:         
 Output:
 Errors:
------------------------------------------------------------------------*/
char *typeHelp[] = {
		"显示文件内容",
		"-[i] [文件名]",
		"选项:",
		" -i   以二进制格式显示文件, 缺省使用字符格式",
		0,
};
void bspKickDog(void);
int typeCmd(int argc,char *argv[])
{
	int	 opt, bin;
	char name[50];
	BYTE buf[16];
	int count, fd, i;
	
	bin = 0;
	while((opt=getopt(argc,argv,"i")) != -1) {
		switch(opt) {
		case 'i':
			bin = 1;
			break;
		default:
			return -1;
		}
	}
	strcpy(name,current_path);
	strcat(name,"/");
	strcat(name, argv[optind]);

	fd= mf_open(name, 0, 0);
	if(fd<0){
		myprintf("can not open %s!\n", name);
		return -1;
	}
	while((count = mf_read(fd, (char *)buf, 16)) > 0) {
		if(bin){
			for(i=0; i<count; i++) myprintf("%02x ", buf[i]);
			myprintf("\n");
		}	
		else
			for(i=0; i<count; i++) myprintf("%c", buf[i]);

		bspKickDog();	
	}
	return 0;
}
#endif