cmd.c

来自「基于ARM和uC/OS-II实现的串口控制台」· C语言 代码 · 共 1,090 行 · 第 1/2 页

C
1,090
字号
/*******************************************************************************
* Function:     CmdReset()
* Description:  
*******************************************************************************/
void CmdReset(void)
{
    char tmp;
    
    SendStr("\n\rWARNING: The system will be reload[Confirm]");
    
    DisU0Int();
    tmp = GetC();
    if(tmp != 0x0D && tmp != 'y' && tmp != 'Y')
    {
        EnU0Int();
        CurPrompt();
        PrintBuf();
        return;
    }
    EnU0Int();
    MEMMAP = 1;
    reset();
}

/*******************************************************************************
* Function:     CmdDebug()
* Description:  
*******************************************************************************/
void CmdDebug(void)
{
    char CurCmdBuf[CMD_BUF_MAX];
    uint8 err, ParaID = 0xff;
    
    GetCmd(CurCmdBuf);
    
    if(SearchPara(CurCmdBuf, 1, ParaDebugDB, &ParaID, &err) == ERR_CLI_PARA_OK)
    {
        ParaDebugDB[ParaID].func();
        BufClean();
        CurPrompt();
    }
    else
    {
        CmdErr();
    }
}

void SubDebugDis(void)
{
    char CurCmdBuf[CMD_BUF_MAX], tmp[16];
    
    GetCmd(CurCmdBuf);
    
    if(GetPara(CurCmdBuf, tmp, 2) == TRUE)
    {
        if(strncmp(tmp, "nmp", strlen(tmp)) == 0)
        {
            SendStr("\n\rNMP Packets Debuger is OFF!");
            debug_switch_nmp = FALSE;
        }
        else
        {
            SendStr("\n\rInvalid Parameter!");
        }
    }
    else
    {
        debug_switch = FALSE;
        debug_switch_nmp = FALSE;
        debug_switch_errcnt = FALSE;
        SendStr("\n\rAll Debuger is OFF!");
    }
}

void SubDebugNmp(void)
{
    SendStr("\n\rNMP Packets Debuger is ON!");
    SendStr("\n\rCommand 'debug disable nmp for close debug information.");
    debug_switch = TRUE;
    debug_switch_nmp = TRUE;
}

void SubDebugErrCnt(void)
{
    SendStr("\n\rCommunication Processor Reset Count Debuger is ON!");
    SendStr("\n\rCommand 'debug disable nmp for close debug information.");
    debug_switch = TRUE;
    debug_switch_errcnt = TRUE;
}

/*******************************************************************************
* Function:     CmdDisable()
* Description:  
*******************************************************************************/
void CmdDisable(void)
{
    ChangCmdStatus(USER);
    CurPrompt();
    BufClean();
}

/*******************************************************************************
* Function:     CmdEnable()
* Description:  
*******************************************************************************/
void CmdEnable(void)
{
    char tmp, pass[128], *pConf;
    uint8 i = 0;
    
    SendStr("\n\rPassword:");
    
    DisU0Int();
ERR:
    tmp = GetC();
    while(tmp != 0x0D)
    {
        pass[i++] = tmp;
        goto ERR;
    }
    pass[i] = 0;
    
    pConf = (char *)CLIConfigFile;
    
    if((strcmp(pass, &pConf[CFG_PASSWORD * 4]) == 0) 
        && (strlen(pass) == strlen(&pConf[CFG_PASSWORD * 4])))
    {
        EnU0Int();
        
        ChangCmdStatus(PRIVATE);
        CurPrompt();
        BufClean();
        
        StartTimer1();
    }
    else
    {
        SendStr("\n\r\n\rPassword Error!!!");
        SendStr("\n\rPassword:");
        i = 0;
        goto ERR;
    }
}

/*******************************************************************************
* Function:     CmdExit()
* Description:  
*******************************************************************************/
void CmdExit(void)
{
    switch(GetCmdStatus())
    {
        case CONFIG:
            ChangCmdStatus(PRIVATE);
            break;
                    
        case CONFIG_IF:
            ChangCmdStatus(CONFIG);
            break;
                    
        case CONFIG_LINE:
            ChangCmdStatus(CONFIG);
            break;
                    
        default:
            break;
    }
    
    CurPrompt();
    BufClean();
}

/*******************************************************************************
* Function:     CmdEnd()
* Description:  
*******************************************************************************/
void CmdEnd(void)
{
    ChangCmdStatus(PRIVATE);
    CurPrompt();
    BufClean();
}

/*******************************************************************************
* Function:     CmdShow()
* Description:  
*******************************************************************************/
void CmdShow(void)
{
    char CurCmdBuf[CMD_BUF_MAX];
    uint8 err, ParaID = 0xff;
    
    GetCmd(CurCmdBuf);
    
    if(SearchPara(CurCmdBuf, 1, ParaShowDB, &ParaID, &err) == ERR_CLI_PARA_OK)
    {
        ParaShowDB[ParaID].func();
        BufClean();
        CurPrompt();
    }
    else
    {
        CmdErr();
    }
}

void SubShowVer(void)
{
    SendStr("\n\r"VERSION);
}

void SubShowLine(void)
{
    char strTmp[64];
    
    SendStr(BLANKROW);
    SendStr("\t\t\tConsole Information:");
    sprintf(strTmp, "\n\rBits per second....: %d", *conspeed);
    SendStr(strTmp);
    sprintf(strTmp, "\n\rData bits..........: %d", conset->datab);
    SendStr(strTmp);
    
    SendStr("\n\rParity.............: ");
    switch(conset->parity)
    {
        case PARITY_NONE:
            if(conset->enablep)
            {
                SendStr("ODD");
            }
            else
            {
                SendStr("NONE");
            }
            break;
            
        case PARITY_EVEN:
            SendStr("EVEN");
            break;
            
        case PARITY_MARK:
            SendStr("MARK");
            break;
            
        case PARITY_SPACE:
            SendStr("SPACE");
            break;
    }
    
    sprintf(strTmp, "\n\rStop bits..........: %d", conset->stopb);
    SendStr(strTmp);
    SendStr("\n\rFlow control.......: NONE");
    
    sprintf(strTmp, "\n\rEXEC Timeout.......: %dhours  %dminuts", EXECTO / 60, EXECTO % 60);
    SendStr(strTmp);
}

/*******************************************************************************
* Function:     Conf()
* Description:  
*******************************************************************************/
void CmdConf(void)
{
    char CurCmdBuf[CMD_BUF_MAX];
    uint8 err, ParaID = 0xff;
    
    GetCmd(CurCmdBuf);
    
    if(SearchPara(CurCmdBuf, 1, ParaConfDB, &ParaID, &err) == ERR_CLI_PARA_OK)
    {
        ParaConfDB[ParaID].func();
        BufClean();
        CurPrompt();
    }
    else
    {
        CmdErr();
    }
}

/*******************************************************************************
* Function:     SubConfTer()
* Description:  
*******************************************************************************/
void SubConfTer(void)
{
    ChangCmdStatus(CONFIG);
}

/*******************************************************************************
* Function:     CmdLine()
* Description:  
*******************************************************************************/
void CmdLine(void)
{
    char CurCmdBuf[CMD_BUF_MAX];
    uint8 err, ParaID = 0xff;
    
    GetCmd(CurCmdBuf);
    
    if(SearchPara(CurCmdBuf, 1, ParaConfLineDB, &ParaID, &err) == ERR_CLI_PARA_OK)
    {
        ParaConfLineDB[ParaID].func();
        BufClean();
        CurPrompt();
    }
    else
    {
        CmdErr();
    }
}

/*******************************************************************************
* Function:     SubLineCon()
* Description:  
*******************************************************************************/
void SubLineCon(void)
{
    ChangCmdStatus(CONFIG_LINE);
}

/*******************************************************************************
* Function:     CmdLineSpeed()
* Description:  设置串行线路速率
*******************************************************************************/
void CmdLineSpeed(void)
{
    char CurCmdBuf[CMD_BUF_MAX], Tmp[64], tmp;
    int err;
    uint32 speed;

    GetCmd(CurCmdBuf);
    if(GetPara(CurCmdBuf, Tmp, 1))
    {
        speed = Strtou32(Tmp, &err);
        if(speed != 1200 && speed != 2400 && speed != 4800 && speed != 9600 
            && speed != 19200 && speed != 38400 && speed != 57600 
            && speed != 115200)
        {
            SendStr("\n\rInvalid speed!");
            CurPrompt();
            PrintBuf();
            return;
        }
        SendStr("\n\rThe console port parameter will be change[Confirm]");
        
        DisU0Int();
        tmp = GetC();
        if(tmp != 0x0D && tmp != 'y' && tmp != 'Y')
        {
            EnU0Int();
            CurPrompt();
            PrintBuf();
            return;
        }
        EnU0Int();
        
        conspeed = &CLIConfigFile[CFG_CON_SPEED];
        *conspeed = speed;
        U0Set(*conspeed, *conset);
    }
    
    BufClean();
    CurPrompt();
}

/*******************************************************************************
* Function:     CmdLineStop()
* Description:  设置停止位
*******************************************************************************/
void CmdLineStop(void)
{
    char CurCmdBuf[CMD_BUF_MAX], Tmp[64], tmp;
    int err;
    uint32 stopb;

    GetCmd(CurCmdBuf);
    if(GetPara(CurCmdBuf, Tmp, 1))
    {
        stopb = Strtou32(Tmp, &err);
        if(err != 0 && stopb != 1 && stopb != 2)
        {
            SendStr("\n\rInvalid stopbits!");
            CurPrompt();
            PrintBuf();
            return;
        }
        SendStr("\n\rThe console port parameter will be change[Confirm]");
        
        DisU0Int();
        tmp = GetC();
        if(tmp != 0x0D && tmp != 'y' && tmp != 'Y')
        {
            EnU0Int();
            CurPrompt();
            PrintBuf();
            return;
        }
        EnU0Int();
        
        conset = (UARTMODE *)&CLIConfigFile[CFG_CON_SET];
        conset->stopb = stopb;
        U0Set(*conspeed, *conset);
    }
    
    BufClean();
    CurPrompt();
}

/*******************************************************************************
* Function:     CmdLineParity()
* Description:  设置奇偶校验
*******************************************************************************/
void CmdLineParity(void)
{
    char CurCmdBuf[CMD_BUF_MAX], tmp;
    uint8 err, ParaID = 0xff;
    
    GetCmd(CurCmdBuf);
    
    if(SearchPara(CurCmdBuf, 1, ParaParityDB, &ParaID, &err) == ERR_CLI_PARA_OK)
    {
        SendStr("\n\rThe console port parameter will be change[Confirm]");
        
        DisU0Int();
        tmp = GetC();
        if(tmp != 0x0D && tmp != 'y' && tmp != 'Y')
        {
            EnU0Int();
            CurPrompt();
            PrintBuf();
            return;
        }
        EnU0Int();
        
        conset = (UARTMODE *)&CLIConfigFile[CFG_CON_SET];
        ParaParityDB[ParaID].func();
        BufClean();
        CurPrompt();
    }
    else
    {
        CmdErr();
    }
}

/*******************************************************************************
* Function:     SubParityNone()
* Description:  设置为无校验
*******************************************************************************/
void SubParityNone(void)
{
    conset->enablep = 0;
    conset->parity = PARITY_NONE;
    U0Set(*conspeed, *conset);
}

/*******************************************************************************
* Function:     SubParityOdd()
* Description:  设置为奇校验
*******************************************************************************/
void SubParityOdd(void)
{
    conset->enablep = 1;
    conset->parity = PARITY_ODD;
    U0Set(*conspeed, *conset);
}

/*******************************************************************************
* Function:     SubParityEven()
* Description:  设置为偶校验
*******************************************************************************/
void SubParityEven(void)
{
    conset->enablep = 1;
    conset->parity = PARITY_EVEN;
    U0Set(*conspeed, *conset);
}

/*******************************************************************************
* Function:     SubParityMark()
* Description:  
*******************************************************************************/
void SubParityMark(void)
{
    conset->enablep = 1;
    conset->parity = PARITY_MARK;
    U0Set(*conspeed, *conset);
}

/*******************************************************************************
* Function:     SubParitySpace()
* Description:  
*******************************************************************************/
void SubParitySpace(void)
{
    conset->enablep = 1;
    conset->parity = PARITY_SPACE;
    U0Set(*conspeed, *conset);
}

/*******************************************************************************
* Function:     CmdLineDataBits()
* Description:  
*******************************************************************************/
void CmdLineDataBits(void)
{
    char CurCmdBuf[CMD_BUF_MAX], Tmp[64], tmp;
    int err;
    uint32 databits;

    GetCmd(CurCmdBuf);
    if(GetPara(CurCmdBuf, Tmp, 1))
    {
        databits = Strtou32(Tmp, &err);
        if(err != 0 && databits != 5 && databits != 6 
            && databits != 7 && databits != 8)
        {
            SendStr("\n\rInvalid databits!");
            CurPrompt();
            PrintBuf();
            return;
        }
        SendStr("\n\rThe console port parameter will be change[Confirm]");
        
        DisU0Int();
        tmp = GetC();
        if(tmp != 0x0D && tmp != 'y' && tmp != 'Y')
        {
            EnU0Int();
            CurPrompt();
            PrintBuf();
            return;
        }
        EnU0Int();
        
        conset = (UARTMODE *)&CLIConfigFile[CFG_CON_SET];
        conset->datab = databits;
        U0Set(*conspeed, *conset);
    }
    
    BufClean();
    CurPrompt();
}

⌨️ 快捷键说明

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