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

📄 set.c

📁 自动联想命令行处理代码
💻 C
字号:
#if !BASIC_BIOS

#include <stdio.h>
#include "uart.h"
#include "cli.h"
#include "rtc.h"

static CommandNode CLI_NAME_SET =
{
    "set",                  // node command hint pointer
    "设置类",               // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_KEY,       // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_DATE =
{
    "date",                 // node command hint pointer
    "日期",                 // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_DATE,      // node type
    CLI_SETDATE             // node command value
};

static CommandNode CLI_NAME_TIME =
{
    "time",                 // node command hint pointer
    "时间",                 // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_TIME,      // node type
    CLI_SETTIME             // node command value
};

static CommandNode CLI_NAME_BAUD =
{
    "baudrate",             // node command hint pointer
    "波特率",               // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_ULONG,     // node type
    CLI_SETBAUDRATE         // node command value
};

static CommandNode CLI_NAME_IPADDRESS =
{
    "ip-address",           // node command hint pointer
    "IP地址",               // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_IP,        // node type
    CLI_SETIPADDRESS        // node command value
};

static CommandNode CLI_NAME_MASK =
{
    "mask",                 // node command hint pointer
    "掩码",                 // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_MASK,      // node type
    NULL                    // node command value
};

static CommandNode CLI_NAME_MAC =
{
    "mac",                  // node command hint pointer
    "MAC地址",              // node command help pointer
    NULL,                   // node current input buffer pointer
    NULL,                   // down leaf pointer
    NULL,                   // right leaf pointer
    COMMAND_TYPE_MAC,       // node type
    CLI_SETMAC              // node command value
};

CommandNode *CLI_SetDate[] =
{
    &CLI_NAME_SET,       // set
    &CLI_NAME_DATE,      // date
    NULL
};

CommandNode *CLI_SetTime[] =
{
    &CLI_NAME_SET,        // set
    &CLI_NAME_TIME,       // time
    NULL
};

CommandNode *CLI_SetIpAddress[] =
{
    &CLI_NAME_SET,       // set
    &CLI_NAME_IPADDRESS, // ip-address
    &CLI_NAME_MASK,      // mask
    NULL
};

CommandNode *CLI_SetMac[] =
{
    &CLI_NAME_SET,      // set
    &CLI_NAME_MAC,      // mac
    NULL
};

CommandNode *CLI_SetBaudrate[] =
{
    &CLI_NAME_SET,      // set
    &CLI_NAME_BAUD,     // baudrate
    NULL
};

void CLI_SetProc( unsigned char key )
{
    switch( key )
    {
        case CLI_SETTIME:
            CLI_SetTimeProc();
            break;

        case CLI_SETDATE:
            CLI_SetDateProc();
            break;

        case CLI_SETIPADDRESS:
            CLI_SetIPProc();
            break;

        case CLI_SETMAC:
            CLI_SetMACProc();
            break;

        case CLI_SETBAUDRATE:
            CLI_SetBaudrateProc();
            break;

        default:
            break;
    }
}

void CLI_SetTimeProc( void )
{
    char *str;
    unsigned long hour, minute, second;
    struct reltime time;    

    str = CLI_GetCommandKey( 0 );

    if( str!= NULL )
    {
        if( 3 == sscanf( str, "%d:%d:%d", &hour, &minute, &second ))
        {
            time.hour   = (unsigned char)hour;
            time.minute = (unsigned char)minute;
            time.second = (unsigned char)second;

            RTC_SetTime(&time);
        }
	}
}

void CLI_SetDateProc( void )
{
    char *str;
    unsigned short year, month, day;
    struct reldate date;

    str = CLI_GetCommandKey( 0 );

    if( str!= NULL )
    {
        if( 3 == sscanf( str, "%d-%d-%d", &year, &month, &day ))
        {
            date.year  = year;
            date.month = (unsigned char)month;
            date.day   = (unsigned char)day;

            RTC_SetDate(&date);
        }
	}
}

void CLI_SetIPProc( void )
{
}

void CLI_SetMACProc( void )
{
}

void CLI_SetBaudrateProc( void )
{
    char *str;
	unsigned long baud;

    str = CLI_GetCommandKey( 0 );

    if( str!= NULL )
    {
        if( 1 == sscanf( str, "%ld", &baud ))
        {
        	switch( baud )
        	{
	        	case 2400:
	        		UART_InitSerialPort( 0, BAUD_RATE_2400 );
	        		break;

        		case 4800:
        		   	UART_InitSerialPort( 0, BAUD_RATE_4800 );
        		   	break;

        		case 9600:
        		   	UART_InitSerialPort( 0, BAUD_RATE_9600 );
        		   	break;

        		case 19200:
        		   	UART_InitSerialPort( 0, BAUD_RATE_19200 );
        		   	break;

        		case 38400:
        		   	UART_InitSerialPort( 0, BAUD_RATE_38400 );
        		   	break;

        		case 57600:
        		   	UART_InitSerialPort( 0, BAUD_RATE_57600 );
        		   	break;

        		case 115200:
        		   	UART_InitSerialPort( 0, BAUD_RATE_115200 );
        		   	break;

        		default:
        		    UART_Printf("\r\nInput baudrate error");
        			break;
        	}
        }
	}
}

#endif

⌨️ 快捷键说明

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