/********************************************************************************************************************* *File : cmd_line.c *Description : Include file for Command line interprenter *Version : 1.0 *Create by : yuanguiyou *Date : 2008/03/01 *Note : The original code was graciously shared by Jon Ward.and written for Keil compiler.now to TKStudio IDE ********************************************************************************************************************* *Compiler : SDCC(version >= 2.2.2) ********************************************************************************************************************* **MODIFY INFORMATION *Modify by : *Date : *Reason : **********************************************************************************************************************/ #ifndef CMD_LINE_H_ #define CMD_LINE_H_ #define CMD_TBL_LEN (sizeof (cmd_tbl) / sizeof (cmd_tbl [0])) /* command table length */ #define MAX_CMD_LEN 15 /* max command length */ /* Enum's.this is command ID of every command str,you can add more for you app */ enum { CID_SET_CLK, CID_READ_CLK, CID_SCAN_CLK, CID_SET_ALM, CID_READ_ALM, CID_CLR_ALM, CID_HELP, CID_LAST }; /* End Enum's */ struct cmd_st /* Command structure */ { char *st_cmdstr; /* Command Name string */ unsigned char id; /* Command ID use enums define*/ }; static xdata struct cmd_st cmd_tbl [] = /* Command table */ { { "STCLK", CID_SET_CLK }, { "RDCLK", CID_READ_CLK }, { "SCCLK", CID_SCAN_CLK }, { "STALM", CID_SET_ALM }, { "RDALM", CID_READ_ALM }, { "CLALM", CID_CLR_ALM }, { "HELP", CID_HELP }, }; const char *helptext = /* help string ,to tell help user */ "\r\n" "HELP:\r\n" "STCLK hhmmss -- Set Clock Time\r\n" "RDCLK -- Display Clock Time\r\n" "SCCLK ON|OFF -- Display Clock Time Every Second\r\n" "STALM hhmm -- Set Alarm\r\n" "RDALM -- Display Alarm Time\r\n" "CLALM -- Clear Alarm Time\r\n" "\r\n"; char xdata cmdbuf [1 + MAX_CMD_LEN]; /* command buffer */ unsigned char cmdndx; /* command index */ /******************************************************************************************************************************** *Function : putchar *Description : This is a support function for the printf_small function *Param : c--the char will be send *Return : None *Note : Call lib function ser_putc 19200bps with 11.059MHz crystal *******************************************************************************************************************************/ void putchar(char); /******************************************************************************************************************************* *Function : strupr *Description : change string to upper *Param : src -- string will be case upper *Return : returns string after upper *Note : No programmer's library would be complete without strupr! *******************************************************************************************************************************/ char *strupr (char *); /******************************************************************************************************************************* *Function : cmd_proc *Description : This function processes the cmd command. *Param : cmd -- command string get from UART *Return : None *Note : the function only printf the command name,you can change for you app ******************************************************************************************************************************/ void cmd_proc (char *); /****************************************************************************************************************************** *Function : cmdb_init *Description : Initialize the command buffer and index. *Param : None *Return : None *Note : the function call first before use cmd_proc ******************************************************************************************************************************/ void cmdb_init (void); /****************************************************************************************************************************** *Function : cmdb_prompt *Description : Prompt for a command. *Param : None *Return : None *Note : *****************************************************************************************************************************/ void cmdb_prompt (void); /****************************************************************************************************************************** *Function : cmdb_scan *Description : This functions gets characters from the serial uffer and appends them to the end of the command buffer. *Param : None *Return : If no character is available the function returns NULL. If a newline character is read, a pointer to * : the buffer is returned. *Note : Do NOT reinvoke this function before extracting the command from the buffer. *****************************************************************************************************************************/ char * cmdb_scan (void); #endif