嵌入式Linux 下 通用 console(控制台)的实现


前言:

当我们使用嵌入式linux 进行开发时,kernel 跑起来之后,我们希望能通过串口(标准输入、输出),在应用程序正在运行的过程中,进行一些调试工作,例如,对CPU一些寄存进行调整,以观测调整以后的结果,并且,当我们无法把我们的应用程序放在后台运行,那么我们就需要实现一个基础的控制台。

下文中的控制台,虽然简单,但完备的支持 上 下 左 右 backspace del 常用控制台操作,使用 上 下 键可以浏览已经输入过的命令(类似 doskey 这样的功能),支持 光标 左右移动 修改命令

一般我们在 main 函数最后 都会做 while(TRUE) sleep(1000) 这样 阻塞住主线程,用这个控制台的实现,替换这个过程,则应用程序可增加控制台应用功能,各部分的具体实现如下: 

调用代码(main.c):

  1. #include <stdio.h>   
  2. #include "app_console.h"   
  3.   
  4. int main(int argc, char *argv[])  
  5. {  
  6.     // 之前的应用代码   
  7.     ....  
  8.     ....  
  9.     ....  
  10.     App_Console_Start();      
  11.     return 0;  
  12. }  

控制台头文件(app_console.h) 

  1. #ifndef __APP_CONSOLE_H__   
  2. #define __APP_CONSOLE_H__   
  3.   
  4. #ifdef __cplusplus   
  5. extern "C"  
  6. {  
  7. #endif       
  8.   
  9. #include "type_def.h"   
  10.   
  11. void App_Console_Start();  
  12.   
  13.   
  14.   
  15. #ifdef __cplusplus   
  16. }  
  17. #endif   
  18.   
  19. #endif  

控制台C文件(app_console.c)

  1. #include "app_console.h"   
  2. #include "ctype.h"   
  3. #include "unistd.h"   
  4. #include "app_test.h"   
  5.   
  6. // 说明   
  7. // read write 使用的是 POSIX 的标准文件读写函数   
  8. // unistd.h 包含了 STDIN_FILENO 等文件描述符的定义   
  9. // ctype.h 包含了 isprint 函数的声明   
  10. // 经过仔细考虑,决定不支持 ESC 键,因为ESC 键的键值为 0x1b 与 上下左右的键值重复   
  11. // 但可以考虑按2下ESC清除本行输入   
  12. // 对不可打印字符的处理仅限于以下已经列出的宏定义   
  13.   
  14. // change:   
  15. // 放弃对 double ESC 的支持,因为可能出现按了 ESC 又按了 方向键 的情况   
  16. // 则用户输入编码为 '/x1b' '/x1b' '[' 'A' (按了ESC 又按了上键)   
  17.   
  18. // change:   
  19. // 为了将应用与控制台应用剥离,则将 #define MAX_CMD_LEN 512 房到 app_test.h 中定义   
  20. // 二维数组作为参数进行传递时,需要明确第二个维度的大小,否则编译器无法正确定位地址   
  21.   
  22.   
  23.   
  24.   
  25. #define KEY_BACKSPACE    '/x08'    // back space    
  26. #define KEY_DEL          '/x7F'    // del    
  27. #define KEY_ENTER        '/x0A'    // 回车   
  28.   
  29. // 以下为 0x1b 开头的键值   
  30. //#define KEY_DOUBLEESC    "/x1B/x1B"// ESC   
  31. //#define KEY_ARROW_UP     "/x1B[A"  // 上   
  32. //#define KEY_ARROW_DOWN   "/x1B[B"  // 下   
  33. //#define KEY_ARROW_LEFT   "/x1B[D"  // 左   
  34. //#define KEY_ARROW_RIGHT  "/x1B[C"  // 右   
  35.   
  36. typedef enum   
  37. {  
  38.     WKS_WAIT,  
  39.     WKS_RECV1B,  
  40.     WKS_UDLR,  
  41. }T_WaitKeyState;  
  42.   
  43. #define MAX_CMD_HISTORY 32   
  44. #define MAX_PAR_COUNT 16   
  45.   
  46. static char szPrompt[] = {"TR_Console> "};  
  47.   
  48. static T_WaitKeyState waitKeyState = WKS_WAIT;  
  49. static char szCmdHistory[MAX_CMD_HISTORY][MAX_CMD_LEN];  
  50. static char szCmdNow[MAX_CMD_LEN] = {0};  
  51.   
  52. static UINT32 nCmdIndex = 0;  
  53. static UINT32 nCmdCursor = 0;  
  54. static UINT32 nCmdInputCount = 0;  
  55. static UINT32 nCmdInputCursor = 0;  
  56.   
  57. static void App_Console_ParseCmd(const char* pCmd);  
  58.   
  59. static UINT32 App_Console_ReadInput(char *input)  
  60. {  
  61.     U32    nRead=0;  
  62.     struct pollfd p;  
  63.     struct termio term,term_old;  
  64.   
  65.     /* Get control of the terminal */  
  66.     ioctl(STDIN_FILENO,TCGETA,(void *)&term);  
  67.     term_old = term;  
  68.     term.c_lflag &= ~ICANON;  
  69.     term.c_lflag &= ~ECHO;  
  70.     ioctl(STDIN_FILENO,TCSETAW,(void *)&term);  
  71.   
  72.     /* Get event we want to know */  
  73.     p.fd     = STDIN_FILENO;  
  74.     p.events = POLLIN;  
  75.   
  76.     /* If we receive one thing, get the byte now */  
  77.     if (poll(&p,1,-1)>0)  
  78.     {  
  79.         if (p.revents==POLLIN)  
  80.         {  
  81.             nRead=read(STDIN_FILENO,input,1);  
  82.         }  
  83.     }  
  84.     /* Purge the byte */  
  85.     /* tcflush(0,TCIOFLUSH); */  
  86.     /* Leave control */  
  87.     ioctl(STDIN_FILENO,TCSETAW,(void *)&term_old);  
  88.     return(nRead);  
  89. }  
  90.   
  91. static void App_Console_BSChar()  
  92. {  
  93.     char szTemp[3];  
  94.     szTemp[0] = '/b';  
  95.     szTemp[1] = ' ';  
  96.     szTemp[2] = '/b';  
  97.     write(STDOUT_FILENO,szTemp,3);    
  98. }  
  99.   
  100. static void App_Console_OnPrintChar(char input)  
  101. {  
  102.     if(nCmdInputCount == MAX_CMD_LEN) return;  
  103.   
  104.     if(nCmdInputCursor < nCmdInputCount) // 光标不在末尾   
  105.     {  
  106.         char szTemp[MAX_CMD_LEN] = {0};  
  107.         char* pCmd = szCmdNow;  
  108.         int nBackCount = nCmdInputCount-nCmdInputCursor;  
  109.         szTemp[0] = input;  
  110.         memcpy(&szTemp[1],&pCmd[nCmdInputCursor],nBackCount);                                         
  111.         write(STDOUT_FILENO,szTemp,nBackCount+1);                                 
  112.         memcpy(&pCmd[nCmdInputCursor],&szTemp,nBackCount+1);  
  113.   
  114.         memset(szTemp,'/b',nBackCount);  
  115.         write(STDOUT_FILENO,szTemp,nBackCount);   
  116.     }  
  117.     else  
  118.     {  
  119.         write(STDOUT_FILENO,&input,1);  
  120.         szCmdNow[nCmdInputCount] = input;  
  121.     }  
  122.   
  123.     nCmdInputCursor++;  
  124.     nCmdInputCount++;  
  125. }  
  126.   
  127. static void App_Console_OnBackspace()  
  128. {  
  129.     if(nCmdInputCursor > 0)  
  130.     {  
  131.         if(nCmdInputCursor == nCmdInputCount) // 光标在末尾   
  132.             App_Console_BSChar();  
  133.         else// 光标不在末尾   
  134.         {  
  135.             char szTemp[MAX_CMD_LEN] = {0};  
  136.             char* pCmd = szCmdNow;  
  137.             int nBackCount = nCmdInputCount-nCmdInputCursor;  
  138.             szTemp[0] = '/b';  
  139.             memcpy(&szTemp[1],&pCmd[nCmdInputCursor],nBackCount);  
  140.             szTemp[nBackCount+1] = ' ';                                   
  141.             write(STDOUT_FILENO,szTemp,nBackCount+2);                                 
  142.             memcpy(&pCmd[nCmdInputCursor-1],&szTemp[1],nBackCount);  
  143.   
  144.             memset(szTemp,'/b',nBackCount+1);  
  145.             write(STDOUT_FILENO,szTemp,nBackCount+1);                 
  146.         }  
  147.         nCmdInputCount --;  
  148.         nCmdInputCursor--;  
  149.     }  
  150. }  
  151.   
  152. static void App_Console_OnDel()  
  153. {  
  154.     if(nCmdInputCursor < nCmdInputCount) // 光标不在末尾   
  155.     {                             
  156.         char szTemp[MAX_CMD_LEN] = {0};  
  157.         char* pCmd = szCmdNow;  
  158.           
  159.         int nBackCount = nCmdInputCount-nCmdInputCursor-1;  
  160.         memcpy(szTemp,&pCmd[nCmdInputCursor+1],nBackCount);  
  161.         szTemp[nBackCount] = ' ';  
  162.         write(STDOUT_FILENO,szTemp,nBackCount+1);                                 
  163.         memcpy(&pCmd[nCmdInputCursor],szTemp,nBackCount);  
  164.   
  165.         memset(szTemp,'/b',nBackCount+1);  
  166.         write(STDOUT_FILENO,szTemp,nBackCount+1);                 
  167.         nCmdInputCount--;                                 
  168.     }  
  169. }  
  170.   
  171. static void App_Console_OnDoubleEsc()  
  172. {  
  173.     if(nCmdInputCount > 0)  
  174.     {  
  175.         char* pCmd = szCmdNow;  
  176.   
  177.         // 将光标移动到最末尾   
  178.         while(nCmdInputCursor < nCmdInputCount)  
  179.         {  
  180.             write(STDOUT_FILENO,&pCmd[nCmdInputCursor],1);  
  181.             nCmdInputCursor++;                                    
  182.         }  
  183.   
  184.         // 清除所有输入的数据   
  185.         int i=0;  
  186.         for(i=0;i<nCmdInputCount;i++) App_Console_BSChar();  
  187.         nCmdInputCount = 0;  
  188.         nCmdInputCursor = 0;  
  189.     }  
  190. }  
  191.   
  192. static void App_Console_OnUp()  
  193. {     
  194.     if(nCmdCursor == 0) return;  
  195.     nCmdCursor --;  
  196.   
  197.     // 清除掉现在所有的输入   
  198.     App_Console_OnDoubleEsc();    
  199.       
  200.     char* pCmdHistory = &szCmdHistory[nCmdCursor][0];     
  201.     memcpy(szCmdNow,pCmdHistory,MAX_CMD_LEN);     
  202.     nCmdInputCount = strlen(szCmdNow);  
  203.     nCmdInputCursor= nCmdInputCount;  
  204.     write(STDOUT_FILENO,szCmdNow,nCmdInputCount);     
  205. }  
  206.   
  207. static void App_Console_OnDown()  
  208. {  
  209.     if(nCmdCursor >= (nCmdIndex-1)) return;  
  210.     nCmdCursor ++;  
  211.       
  212.     // 清除掉现在所有的输入   
  213.     App_Console_OnDoubleEsc();    
  214.       
  215.     char* pCmdHistory = &szCmdHistory[nCmdCursor][0];     
  216.     memcpy(szCmdNow,pCmdHistory,MAX_CMD_LEN);     
  217.     nCmdInputCount = strlen(szCmdNow);  
  218.     nCmdInputCursor= nCmdInputCount;  
  219.     write(STDOUT_FILENO,szCmdNow,nCmdInputCount);     
  220.       
  221. }  
  222.   
  223. static void App_Console_OnLeft()  
  224. {  
  225.     if(nCmdInputCursor > 0)  
  226.     {  
  227.         char c = '/b';  
  228.         write(STDOUT_FILENO,&c,1);  
  229.         nCmdInputCursor--;  
  230.     }  
  231. }  
  232.   
  233. static void App_Console_OnRight()  
  234. {  
  235.     if(nCmdInputCursor < nCmdInputCount)  
  236.     {  
  237.         char* pCmd = szCmdNow;  
  238.         char c = pCmd[nCmdInputCursor];  
  239.         write(STDOUT_FILENO,&c,1);  
  240.         nCmdInputCursor++;  
  241.     }  
  242. }  
  243.   
  244. static void App_Console_OnEnter()  
  245. {     
  246.     szCmdNow[nCmdInputCount] = '/0';  
  247.     char szTemp[] = {"/r/n"};  
  248.     write(STDOUT_FILENO,szTemp,strlen(szTemp));  
  249.     nCmdInputCount = 0;  
  250.     nCmdInputCursor = 0;  
  251.   
  252.     if(strlen(szCmdNow) == 0) return;  
  253.   
  254.     if(nCmdIndex == MAX_CMD_HISTORY) // 命令队列满了,移动   
  255.     {  
  256.         char szTempCmd[MAX_CMD_HISTORY][MAX_CMD_LEN];  
  257.         memcpy(szTempCmd,&szCmdHistory[1][0],MAX_CMD_LEN*(MAX_CMD_HISTORY-1));  
  258.         memcpy(szCmdHistory,szTempCmd,MAX_CMD_LEN*(MAX_CMD_HISTORY-1));  
  259.         nCmdIndex = MAX_CMD_HISTORY-1;  
  260.         nCmdCursor = nCmdIndex;  
  261.     }  
  262.       
  263.   
  264.     memcpy(szCmdHistory[nCmdIndex],szCmdNow,MAX_CMD_LEN);  
  265.       
  266.     nCmdIndex++;  
  267.     nCmdCursor = nCmdIndex;   
  268.   
  269.     // 解析命令   
  270.     App_Console_ParseCmd(szCmdNow);  
  271. }  
  272.   
  273. static void App_Console_CmdLoop()  
  274. {  
  275.     BOOL bGetEnter = FALSE;  
  276.     while(TRUE)  
  277.     {     
  278.         // 读取一个console输入   
  279.         UINT32 nReturn = 0;  
  280.         char input;  
  281.         nReturn = App_Console_ReadInput (&input);  
  282.         if(nReturn > 0)  
  283.         {             
  284.             switch(waitKeyState)  
  285.             {  
  286.                 case WKS_WAIT :  
  287.                     if(isprint(input))// 可打印字符   
  288.                         App_Console_OnPrintChar(input);  
  289.                     else  
  290.                     {  
  291.                         if(input == KEY_BACKSPACE)  
  292.                             App_Console_OnBackspace();  
  293.                         else if(input == KEY_DEL)  
  294.                             App_Console_OnDel();  
  295.                         else if(input == KEY_ENTER)  
  296.                         {  
  297.                             App_Console_OnEnter();  
  298.                             bGetEnter = TRUE;  
  299.                         }  
  300.                         else if(input == '/x1b')  
  301.                             waitKeyState = WKS_RECV1B;  
  302.                         else  
  303.                             waitKeyState = WKS_WAIT;  
  304.                     }                         
  305.                     break;  
  306.                 case WKS_RECV1B:  
  307.                     if(input == '/x1b'// 按了ESC 又按了方向键,或者是 ESC   
  308.                     {  
  309.                         //App_Console_OnDoubleEsc();   
  310.                         waitKeyState = WKS_RECV1B;  
  311.                     }  
  312.                     else   
  313.   
  314.                     if(input == '['//可能为 上下左右 4个键   
  315.                         waitKeyState = WKS_UDLR;  
  316.                     else//下面的情况为 按了 ESC 键之后,按了其他的键的处理   
  317.                     {                         
  318.                         if(isprint(input)) App_Console_OnPrintChar(input);                            
  319.                         waitKeyState = WKS_WAIT;  
  320.                     }  
  321.                     break;  
  322.                 case WKS_UDLR:  
  323.                     if(input == 'A')// 上   
  324.                         App_Console_OnUp();  
  325.                     else if(input == 'B')// 下   
  326.                         App_Console_OnDown();  
  327.                     else if(input == 'D')// 左   
  328.                         App_Console_OnLeft();  
  329.                     else if(input == 'C')// 右   
  330.                         App_Console_OnRight();  
  331.                     else  
  332.                     {  
  333.                         if(isprint(input)) App_Console_OnPrintChar(input);  
  334.                     }  
  335.                     waitKeyState = WKS_WAIT;                      
  336.                     break;  
  337.                 default:  
  338.                     break;  
  339.             }  
  340.         }  
  341.   
  342.         if(bGetEnter)   
  343.         {             
  344.             break;  
  345.         }  
  346.     }  
  347. }  
  348.   
  349. void App_Console_Start()  
  350. {  
  351.     // 清空 sdtout 缓冲   
  352.     fflush(stdout);  
  353.     fflush(stdin);  
  354.   
  355.     char szTemp[] = {"/r/nStart TR Console.../r/n/r/n"};  
  356.     write(STDOUT_FILENO,szTemp,strlen(szTemp));  
  357.   
  358.     while(TRUE)  
  359.     {  
  360.         write(STDOUT_FILENO,szPrompt,strlen(szPrompt));  
  361.         App_Console_CmdLoop();  
  362.     }  
  363. }  
  364.   
  365. // 解析命令   
  366. static void App_Console_ParseCmd(const char* pCmd)  
  367. {  
  368.     int length = strlen(pCmd);   
  369.       
  370.     // 全部转小写   
  371.     int i=0;  
  372.     char szTempCmd[MAX_CMD_LEN];  
  373.     for (i=0; i < length; i++) szTempCmd[i] = tolower(pCmd[i]);   
  374.   
  375.   
  376.     // 将输入的命令各个 part 分开    
  377.     char szPart[MAX_PAR_COUNT][MAX_CMD_LEN];  
  378.     int nPartCount = 0;  
  379.     int nPartCursor = 0;  
  380.     int nCmdCursor = 0;  
  381.     memset(szPart,0,sizeof(szPart));  
  382.   
  383.     while(TRUE)  
  384.     {  
  385.         if(nCmdCursor == length)   
  386.         {  
  387.             if(nPartCursor > 0)  
  388.             {  
  389.                 nPartCount++;  
  390.                 nPartCursor = 0;  
  391.             }  
  392.             break;            
  393.         }  
  394.           
  395.         if( (szTempCmd[nCmdCursor] == ',') || (szTempCmd[nCmdCursor] == ' ') ) // part 分割符   
  396.         {  
  397.             szPart[nPartCount][nPartCursor] = '/0';  
  398.               
  399.             nPartCount++;  
  400.             nPartCursor = 0;  
  401.         }  
  402.         else   
  403.         {  
  404.             szPart[nPartCount][nPartCursor] = szTempCmd[nCmdCursor];  
  405.             nPartCursor++;  
  406.         }  
  407.         nCmdCursor++;         
  408.     }  
  409.     App_Test_OnCmd(szPart,nPartCount);        
  410. }  

 

命令实现头文件(app_test.h)

view plaincopy to clipboardprint?

  1. #ifndef __APP_TEST_H__   
  2. #define __APP_TEST_H__   
  3.   
  4. #ifdef __cplusplus   
  5. extern "C"  
  6. {  
  7. #endif       
  8.   
  9. #include "type_def.h"   
  10.   
  11. #define MAX_CMD_LEN 512   
  12.   
  13. void App_Test_OnCmd(char szPart[][MAX_CMD_LEN],int nPartCount);  
  14.   
  15.   
  16.   
  17. #ifdef __cplusplus   
  18. }  
  19. #endif   
  20.   
  21. #endif  

 

命令实现c文件(app_test.c)

view plaincopy to clipboardprint?

  1. #include "app_test.h"   
  2. #include "stapp_main.h"   
  3. #include "app_qam.h"   
  4. #include "api_av.h"   
  5. #include "api_video.h"   
  6. #include "api_audio.h"   
  7. #include "api_pcr.h"   
  8.   
  9. static void App_Test_OnHelp();  
  10. static void App_Test_OnWriteReg8(char szPart[][MAX_CMD_LEN],int nPartCount);  
  11. static void App_Test_OnReadReg8(char szPart[][MAX_CMD_LEN],int nPartCount);  
  12. static void App_Test_OnQamConnect(char szPart[][MAX_CMD_LEN],int nPartCount);  
  13. static void App_Test_OnAVPlayMpeg(char szPart[][MAX_CMD_LEN],int nPartCount);  
  14. static void App_Test_OnAVStop();  
  15. static void App_Test_OnVolumeSet(char szPart[][MAX_CMD_LEN],int nPartCount);  
  16. static void App_Test_OnMute();  
  17. static void App_Test_OnUnmute();  
  18. static void App_Test_OnDENCRegDum();  
  19. static void App_Test_OnDENCRegSet(char szPart[][MAX_CMD_LEN],int nPartCount);  
  20.   
  21. void App_Test_OnCmd(char szPart[][MAX_CMD_LEN],int nPartCount)  
  22. {  
  23.     // 这里处理私有的命令   
  24.   
  25.     if(nPartCount == 0) return;  
  26.   
  27.     if( strcmp(szPart[0],"help") == 0)  
  28.     {  
  29.         App_Test_OnHelp();  
  30.     }  
  31.     else if( strcmp(szPart[0],"writereg8") == 0)  
  32.     {  
  33.         if(nPartCount > 2) App_Test_OnWriteReg8(szPart,nPartCount);  
  34.     }  
  35.     else if( strcmp(szPart[0],"readreg8") == 0)  
  36.     {  
  37.         if(nPartCount > 1) App_Test_OnReadReg8(szPart,nPartCount);  
  38.     }  
  39.     else if( strcmp(szPart[0],"qamconnect") == 0)  
  40.     {  
  41.         if(nPartCount > 1) App_Test_OnQamConnect(szPart,nPartCount);  
  42.     }  
  43.     else if( strcmp(szPart[0],"avplaympeg") == 0)  
  44.     {  
  45.         if(nPartCount > 1) App_Test_OnAVPlayMpeg(szPart,nPartCount);  
  46.     }  
  47.     else if( strcmp(szPart[0],"avstop") == 0)  
  48.     {  
  49.         App_Test_OnAVStop();  
  50.     }  
  51.     else if( strcmp(szPart[0],"volumeset") == 0)  
  52.     {  
  53.         if(nPartCount > 1) App_Test_OnVolumeSet(szPart,nPartCount);  
  54.     }  
  55.     else if( strcmp(szPart[0],"mute") == 0)  
  56.     {  
  57.         App_Test_OnMute();  
  58.     }  
  59.     else if( strcmp(szPart[0],"unmute") == 0)  
  60.     {  
  61.         App_Test_OnUnmute();  
  62.     }  
  63.     else if( strcmp(szPart[0],"dencregdump") == 0)  
  64.     {  
  65.         App_Test_OnDENCRegDum();  
  66.     }  
  67.     else if( strcmp(szPart[0],"dencregset") == 0)  
  68.     {  
  69.         if(nPartCount > 1) App_Test_OnDENCRegSet(szPart,nPartCount);  
  70.     }  
  71.   
  72. }  
  73.   
  74. static void App_Test_OnHelp()  
  75. {  
  76.     printf("**************************************************************/n");   
  77.     printf("* Help        PARAM MUST 0 MAX 0 Eg. help/n");    
  78.     printf("* WriteReg8   PARAM MUST 2 MAX 2 Eg. WriteReg8 0x1920C114 128/n");  
  79.     printf("* ReadReg8    PARAM MUST 1 MAX 1 Eg. ReadReg8 0x1920C114/n");  
  80.     printf("* QamConnect  PARAM MUST 1 MAX 3 Eg. QamConnect 546000/n");  
  81.     printf("* AVPlayMpeg  PARAM MUST 1 MAX 3 Eg. AVPlayMpeg 64 63 32/n");  
  82.     printf("* AVStop      PARAM MUST 0 MAX 0 Eg. AVStop/n");  
  83.     printf("* VolumeSet   PARAM MUST 1 MAX 1 Eg. VolumeSet 63/n");    
  84.     printf("* Mute        PARAM MUST 0 MAX 0 Eg. Mute/n");  
  85.     printf("* Unmute      PARAM MUST 0 MAX 0 Eg. Unmute/n");  
  86.     printf("* DENCRegDump PARAM MUST 0 MAX 0 Eg. DENCRegDump/n");  
  87.     printf("* DENCRegSet  PARAM MUST 1 MAX 1 Eg. DENCRegSet 1/n");    
  88.     printf("*************************************************************/n");    
  89.       
  90. }  
  91.   
  92. static void App_Test_OnWriteReg8(char szPart[][MAX_CMD_LEN],int nPartCount)  
  93. {  
  94.     char* pAddress = &szPart[1][0];  
  95.     char* pValue = &szPart[2][0];  
  96.   
  97.     DWORD dwAddress = 0;  
  98.     UINT8 nValue = atoi(pValue);  
  99.   
  100.     sscanf(pAddress,"0x%08x",&dwAddress);  
  101.   
  102.     SYS_WriteRegDev8(dwAddress,nValue);   
  103. }  
  104.   
  105. static void App_Test_OnQamConnect(char szPart[][MAX_CMD_LEN],int nPartCount)  
  106. {  
  107.     char* pFreq = &szPart[1][0];  
  108.     UINT32 nFreq = atoi(pFreq);  
  109.     UINT32 nSymbolRate = 6875;  
  110.     T_DMD_Modulation nQAMMode = QAM_64;  
  111.     if(nPartCount > 2)  
  112.     {  
  113.         char* pSymbolRate = &szPart[2][0];  
  114.         nSymbolRate = atoi(pSymbolRate);  
  115.     }  
  116.   
  117.     if(nPartCount > 3)  
  118.     {  
  119.         char* pQAMMode = &szPart[3][0];  
  120.         nQAMMode = atoi(pQAMMode);  
  121.     }  
  122.       
  123.     App_Qam_Locking(TRUE,nFreq,nSymbolRate,nQAMMode);     
  124. }  
  125.   
  126.   
  127. static void App_Test_OnAVPlayMpeg(char szPart[][MAX_CMD_LEN],int nPartCount)  
  128. {  
  129.     UINT16 nVideoPid = 0xFFFF;  
  130.     UINT16 nAudioPid = 0xFFFF;  
  131.     UINT16 nPcrPid = 0xFFFF;  
  132.   
  133.   
  134.     char* pAudioPid = &szPart[1][0];  
  135.     nAudioPid = atoi(pAudioPid);  
  136.   
  137.   
  138.     if(nPartCount > 2)  
  139.     {  
  140.         char* pVideoPid = &szPart[2][0];  
  141.         nVideoPid = atoi(pVideoPid);  
  142.     }  
  143.   
  144.     if(nPartCount > 3)  
  145.     {  
  146.         char* pPcr = &szPart[3][0];  
  147.         nPcrPid = atoi(pPcr);  
  148.     }  
  149.   
  150.     Api_Av_Stop();  
  151.     Api_Av_Start(nAudioPid,STREAMTYPE_MP2A,nVideoPid,STREAMTYPE_MP2V,nPcrPid);  
  152. }  
  153.   
  154. static void App_Test_OnVolumeSet(char szPart[][MAX_CMD_LEN],int nPartCount)  
  155. {  
  156.     UINT16 nVolume = 0;   
  157.     char* pVolume = &szPart[1][0];  
  158.     nVolume = atoi(pVolume);  
  159.   
  160.     Api_Audio_Volume_Set(nVolume);  
  161. }  
  162.   
  163. static void App_Test_OnMute()  
  164. {  
  165.     Api_Audio_Mute();  
  166. }  
  167.   
  168. static void App_Test_OnUnmute()  
  169. {  
  170.     Api_Audio_Unmute();  
  171. }  
  172.   
  173. static void App_Test_OnAVStop()  
  174. {  
  175.     Api_Av_Stop();  
  176. }  
  177.   
  178. static void App_Test_OnDENCRegDum()  
  179. {  
  180.     printf("* Brightness   0x1920C114 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C114));    
  181.     printf("* Contrast     0x1920C118 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C118));    
  182.     printf("* Saturation   0x1920C11c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C11c));  
  183.       
  184.     printf("* CHROMA_COEF0 0x1920C120 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C120));    
  185.     printf("* CHROMA_COEF1 0x1920C124 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C124));    
  186.     printf("* CHROMA_COEF2 0x1920C128 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C128));    
  187.     printf("* CHROMA_COEF3 0x1920C12c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C12c));    
  188.     printf("* CHROMA_COEF4 0x1920C130 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C130));    
  189.     printf("* CHROMA_COEF5 0x1920C134 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C134));    
  190.     printf("* CHROMA_COEF6 0x1920C138 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C138));    
  191.     printf("* CHROMA_COEF7 0x1920C13c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C13c));    
  192.     printf("* CHROMA_COEF8 0x1920C140 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C140));    
  193.   
  194.     printf("* LUM_COEF0    0x1920C148 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C148));    
  195.     printf("* LUM_COEF1    0x1920C14c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C14c));    
  196.     printf("* LUM_COEF2    0x1920C150 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C150));    
  197.     printf("* LUM_COEF3    0x1920C154 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C154));    
  198.     printf("* LUM_COEF4    0x1920C158 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C158));    
  199.     printf("* LUM_COEF5    0x1920C15c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C15c));    
  200.     printf("* LUM_COEF6    0x1920C160 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C160));    
  201.     printf("* LUM_COEF7    0x1920C164 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C164));    
  202.     printf("* LUM_COEF8    0x1920C168 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C168));    
  203.     printf("* LUM_COEF9    0x1920C16c value is 0x%02x/n",SYS_ReadRegDev8(0x1920C16c));    
  204.   
  205.     printf("* CFG9         0x1920C144 value is 0x%02x/n",SYS_ReadRegDev8(0x1920C144));        
  206.       
  207. }  
  208.   
  209. static void App_Test_OnDENCRegSet(char szPart[][MAX_CMD_LEN],int nPartCount)  
  210. {  
  211.     UINT16 nScheme = 1;   
  212.     char* pScheme = &szPart[1][0];  
  213.     nScheme = atoi(pScheme);  
  214.   
  215.     switch(nScheme)  
  216.     {  
  217.         case 1:  
  218.               
  219.             break;  
  220.         case 2:  
  221.               
  222.             break;  
  223.         case 3:  
  224.               
  225.             break;  
  226.         case 4:  
  227.               
  228.             break;  
  229.         default:  
  230.             break;  
  231.     }  
  232.   
  233. }  
  234.   
  235. static void App_Test_OnReadReg8(char szPart[][MAX_CMD_LEN],int nPartCount)  
  236. {  
  237.     char* pAddress = &szPart[1][0];  
  238.     DWORD dwAddress = 0;  
  239.       
  240.     sscanf(pAddress,"0x%08x",&dwAddress);  
  241.     printf("* 0x%08x value is 0x%02x/n",dwAddress,SYS_ReadRegDev8(dwAddress));  
  242. }  

相关内容