source: svn/newcon3bcm2_21bu/dta/tests/unit_test/interactive_menu.c @ 45

Last change on this file since 45 was 45, checked in by megakiss, 11 years ago
  • Property svn:executable set to *
File size: 11.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: HD DTA unit test application
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22#include "bstd.h"
23#include "bkni.h"
24#include "bdbg.h"
25
26#include "ministd.h"
27#include "gist.h"
28#include "serial.h"
29#include "test_capture.h"
30#include "bsettop_smessage.h"
31
32#include "test_a56.h"
33
34void menu_level1(void);
35void menu_tune(void);
36void menu_tscap(void);
37void menu_decode(void);
38void menu_a56_test(void);
39
40#ifdef OOB_TUNER_SUPPORT
41#include "test_oob.h"
42void menu_oob_test(void);
43#endif
44
45#include "test_tuner.h"
46
47unsigned int menu_read_number(void);
48
49#define MENU_DELIMETER() BKNI_Printf("*************************************\n")
50
51void do_test(void * para)
52{
53    unsigned int ca_system_id;
54    BERR_Code berr;
55
56    ca_system_id = 0x0;
57    berr = gist_rap_open(ca_system_id, NULL);
58
59    if(BERR_SUCCESS != berr){
60        BKNI_Printf("gist_rap_open failed\n");
61    }
62        /* function name is kind of misleading since it hook whatever the tuner underneath, it can be QAM, VSB, ISDB-T */
63        if (!qam_tuner_init()) {
64        BKNI_Printf("QAM tuner open failed\n");
65        }
66
67        smessage_init(NULL);
68        a56_init();
69
70    menu_level1();
71    __asm__("sdbbp");
72}
73
74void menu_level1(void)
75{
76    int input;
77    int exit_menu = 0;
78    while(0 == exit_menu){
79        MENU_DELIMETER();
80        BKNI_Printf("Menu Level 1\n");
81        BKNI_Printf("1 - PSI Filter Tests\n");
82        BKNI_Printf("2 - Tune\n");
83        BKNI_Printf("3 - Transport Capture\n");
84        BKNI_Printf("4 - Decode Video/Audio\n");
85#ifdef OOB_TUNER_SUPPORT
86        BKNI_Printf("5 - OOB tuner\n");
87#endif
88        BKNI_Printf("6 - A56 Test\n");
89#ifdef CONFIG_NXP_TDA182I4
90        BKNI_Printf("7 - NXP tuner test\n");
91#endif
92        BKNI_Printf("> ");
93        input = serial_getc(CONSOLE_UART, true);
94        BKNI_Printf("%c\n", input);
95        switch(input){
96        case '1':
97                BKNI_Printf("Not implemented yet\n");
98            //menu_psi();
99            break;
100        case '2':
101            menu_tune();
102            break;
103        case '3':
104                BKNI_Printf("Not implemented yet\n");
105            //menu_tscap();
106            break;
107        case '4':
108                BKNI_Printf("Not implemented yet\n");
109            //menu_decode();
110            break;
111#ifdef OOB_TUNER_SUPPORT
112                case '5':
113                        //menu_oob_test();
114                BKNI_Printf("Not implemented yet\n");
115                        break;
116#endif
117
118                case '6':
119                        menu_a56_test();
120                        break;
121
122#ifdef CONFIG_NXP_TDA182I4
123/* implemented in the bsettop_tuner_vsb.c */
124extern void NXP_tuner_test(void);
125                case '7':
126                        NXP_tuner_test();
127                        break; 
128#endif
129        default:
130            break;
131        }
132    }
133}
134
135void menu_psi(void)
136{
137    int input;
138    int exit_menu = 0;
139
140    while(0 == exit_menu){
141        MENU_DELIMETER();
142        BKNI_Printf("Menu Level 2 - PSI\n");
143        BKNI_Printf("1 - Receive PSI filter setup\n");
144        BKNI_Printf("2 - Start PSI filters\n");
145        BKNI_Printf("3 - Stop PSI filters\n");
146        BKNI_Printf("4 - Display statistics\n");
147        BKNI_Printf("5 - Reset statistics\n");
148        BKNI_Printf("6 - Display last 1000 messages\n");
149        BKNI_Printf("7 - Display PSI filter setup\n");
150        BKNI_Printf("0 - Return to previous menu\n");
151        BKNI_Printf("> ");
152        input = serial_getc(CONSOLE_UART, true);
153        BKNI_Printf("%c\n", input);
154        switch(input){
155        case '1':
156            //ft_receive_filters();
157            break;
158        case '2':
159            //ft_start_filters();
160            break;
161        case '3':
162            //ft_stop_filters();
163            break;
164        case '4':
165            //ft_display_stats();
166            break;
167        case '5':
168            //ft_reset_stats();
169            break;
170        case '6':
171            //ft_dump_message();
172            break;
173        case '7':
174            //ft_dump_filters();
175            break;
176        case '0':
177            exit_menu = 1;
178            break;
179        }
180    }
181}
182
183void menu_tune(void)
184{
185    int input;
186    int exit_menu = 0;
187
188    while(0 == exit_menu){
189        MENU_DELIMETER();
190        BKNI_Printf("Menu Level 2 - Tuner\n");
191#ifdef CONFIG_VSB
192        BKNI_Printf("1 - Tune To a VSB Frequency\n");
193        BKNI_Printf("2 - Get Tune Status\n");
194                BKNI_Printf("3 - Start VSB Message Filtering\n");
195                BKNI_Printf("4 - Stop VSB Message Filtering\n");
196                BKNI_Printf("5 - VSB Channel Scan (scan ATSC frequency and get PAT)\n");
197#else
198        BKNI_Printf("1 - Tune To a QAM Frequency\n");
199        BKNI_Printf("2 - Get Tune Status\n");
200                BKNI_Printf("3 - Start QAM Message Filtering\n");
201                BKNI_Printf("4 - Stop QAM Message Filtering\n");
202#endif
203        BKNI_Printf("0 - Return to previous menu\n");
204        BKNI_Printf("> ");
205        input = serial_getc(CONSOLE_UART, true);
206        BKNI_Printf("%c\n", input);
207        switch(input){
208        case '1':
209                        BKNI_Printf("Please input tune frequency in KHz ?\n");
210                        input = menu_read_number();
211                        qam_tune(input * 1000);
212                        break;
213                case '2':
214                        qam_get_status();
215                        break;
216                        break;
217                case '3':
218                        BKNI_Printf("Please input PID to get message from ?\n");
219                        input = menu_read_number();
220                        BKNI_Printf("Pid = %d\n", input);
221                        qam_start_message(input);
222                        break;
223                case '4':
224                        qam_stop_message();
225                        break;
226#ifdef CONFIG_VSB
227                case '5':
228                        break;
229#endif
230                case '0':
231                        qam_stop_message();
232                        exit_menu = 1;
233                }
234        }
235}
236
237void menu_tscap(void)
238{
239        int input;
240        int exit_menu = 0;
241
242        while(0 == exit_menu){
243                MENU_DELIMETER();
244                BKNI_Printf("Menu Level 2 - Transport Capture\n");
245                BKNI_Printf("1 - Enter Capture Parameters\n");
246                BKNI_Printf("2 - Start Capture\n");
247                BKNI_Printf("3 - Stop Capture\n");
248                BKNI_Printf("4 - Display Data\n");
249                BKNI_Printf("0 - Return to previous menu\n");
250                BKNI_Printf("> ");
251                input = serial_getc(CONSOLE_UART, true);
252                BKNI_Printf("%c\n", input);
253                switch(input){
254                        case '1':
255                                //tcap_parameters();
256                                break;
257                        case '2':
258                                //tcap_start();
259                                break;
260                        case '3':
261                                //tcap_stop();
262                                break;
263                        case '4':
264                                //tcap_display();
265                                break;
266                        case '0':
267                                exit_menu = 1;
268                                break;
269                }
270        }
271}
272
273void menu_decode(void)
274{
275        int input;
276        int exit_menu = 0;
277
278        while(0 == exit_menu){
279                MENU_DELIMETER();
280                BKNI_Printf("Menu Level 2 - Program Decode\n");
281                BKNI_Printf("1 - Enter Decode Parameters\n");
282                BKNI_Printf("2 - Start Decode\n");
283                BKNI_Printf("3 - Stop Decode\n");
284                BKNI_Printf("4 - Decode Default Parameters\n");
285                BKNI_Printf("0 - Return to previous menu\n");
286                BKNI_Printf("> ");
287                input = serial_getc(CONSOLE_UART, true);
288                BKNI_Printf("%c\n", input);
289                switch(input){
290                        case '1':
291                                //comm_decode_params();
292                                break;
293                        case '2':
294                                //comm_decode_start();
295                                break;
296                        case '3':
297                                //comm_decode_stop();
298                                break;
299                        case '4':
300                                //comm_decode_params_default();
301                                break;
302                        case '0':
303                                exit_menu = 1;
304                                break;
305                }
306        }
307}
308
309#define MENU_CR '\xd'
310#define MENU_BS '\x8'
311
312enum im_token_t {
313        IMT_OTHER,
314        IMT_DIGIT,
315        IMT_XDIGIT,
316        IMT_CR,
317        IMT_X,
318        IMT_BS
319};
320
321enum im_token_t im_tokenize(int ch)
322{
323        if(('0' <= ch) && ('9' >= ch)){
324                return IMT_DIGIT;
325        }
326        if(('A' <= ch) && ('F' >= ch)){
327                return IMT_XDIGIT;
328        }
329        if(('a' <= ch) && ('f' >= ch)){
330                return IMT_XDIGIT;
331        }
332        switch(ch){
333                case 'x':
334                case 'X':
335                        return IMT_X;
336                case MENU_CR:
337                        return IMT_CR;
338                case MENU_BS:
339                        return IMT_BS;
340        }
341        return IMT_OTHER;
342}
343
344#define IN_MAX 32
345
346extern long strtol(const char *str, char **endptr, int base);
347
348/* read hex or decimal number */
349unsigned int menu_read_number(void)
350{
351        int input;
352        int radix;
353        unsigned value;
354        enum im_token_t tok;
355        int accept;
356        char input_str[IN_MAX];
357        char * input_end;
358
359        value = 0;
360        radix = 10;
361        input_end = input_str;
362        do {
363                accept = 0;
364                input = serial_getc(CONSOLE_UART, true);
365                tok = im_tokenize(input);
366                switch(tok){
367                        case IMT_XDIGIT:
368                                if(0x10 == radix){
369                                        accept = 1;
370                                }
371                                break;
372                        case IMT_DIGIT:
373                                accept = 1;
374                                break;
375                        case IMT_X:
376                                if(10 == radix){
377                                        if((input_str[0] = '0') && (input_end == &input_str[1])){
378                                                accept = 1;
379                                                radix = 0x10;
380                                        }
381                                }
382                                break;
383                        case IMT_BS:
384                                if(input_end != input_str){
385                                        accept = 0;
386                                        BKNI_Printf("\x8 \x8");
387                                        input_end--;
388                                }
389                                break;
390                        case IMT_CR:
391                        case IMT_OTHER:
392                        default:
393                                break;
394                }
395                if(accept){
396                        BKNI_Printf("%c", input);
397                        /* place character in to the input string */
398                        *input_end = (char)input;
399                        input_end++;
400                        if(input_end == &input_str[IN_MAX-1]){
401                                input_end--;
402                        }
403                }
404        }while(input != MENU_CR);
405        *input_end = '\0';
406        value = strtol(input_str, &input_end, radix);
407        return value;
408}
409
410int get_pid(void)
411{
412        int pid;
413
414        do {
415                BKNI_Printf("Please input PID (0 - 0x1ffff) to get message from ?\n");
416                pid = menu_read_number();
417        } while (pid < 0 || pid > 0x1ffff);
418        return pid;
419}
420
421#ifdef OOB_TUNER_SUPPORT
422
423void menu_oob_test(void)
424{
425        bool initialized = false;
426
427        int input;
428        int exit_menu = 0;
429
430        if (!initialized) {
431                if (!oob_init()) {
432                        BKNI_Printf("oob_init failed\n");
433                        return;
434                }
435                initialized = true;
436        }
437        while(0 == exit_menu){
438                MENU_DELIMETER();
439                BKNI_Printf("Menu Level 2 - OOB Tuner Test\n");
440                BKNI_Printf("1 - Tune OOB Frequeny\n");
441                BKNI_Printf("2 - Get OOB Tuner Status\n");
442                BKNI_Printf("3 - Start OOB Message Filtering\n");
443                BKNI_Printf("4 - Stop OOB Message Filtering\n");
444                BKNI_Printf("5 - Loop All Pids\n");
445                BKNI_Printf("6 - Start OOB Message Filtering for ATM Packet Capture\n");
446                BKNI_Printf("0 - Return to previous menu\n");
447                BKNI_Printf("> ");
448                input = serial_getc(CONSOLE_UART, true);
449                BKNI_Printf("%c\n", input);
450                switch(input){
451                        case '1':
452                                oob_tune();
453                                break;
454                        case '2':
455                                oob_get_status();
456                                break;
457                        case '3':
458                                input = get_pid();
459                                BKNI_Printf("Pid = %d\n", input);
460                                oob_start_message(input);
461                                break;
462                        case '4':
463                                oob_stop_message();
464                                break;
465                        case '5':
466                                {
467                                        unsigned int pid;
468
469                                        for (pid = 0; pid < 0x1ffff; pid++) {
470                                                BKNI_Printf("tune to pid %d\n", pid);
471                                                oob_start_message(pid);
472                                                bos_sleep(10 * 1000);
473                                                oob_stop_message();
474                                        }
475                                }
476                                break;
477                        case '6':
478                                {
479                                        /* hardcoding the vpi/vci value first */
480                                        oob_start_amessage(0, 0x3e8);
481                                }
482                                break;
483                        case '0':
484                                oob_stop_message();
485                                exit_menu = 1;
486                                break;
487                }
488        }
489}
490#endif
491
492void menu_a56_test(void)
493{
494        int input;
495        int exit_menu = 0;
496
497#ifdef OOB_TUNER_SUPPORT
498        BKNI_Printf("You need to tune to a frequency before testing A56 use either in band or out of band tuner.\n");
499        BKNI_Printf("If not yet, please use tuner test to tune a freqency first.\n");
500
501        BKNI_Printf("Which tuner to use (0 in band, 1 out of band?)\n");
502        input = serial_getc(CONSOLE_UART, true);
503        a56_test_choose_tuner(input);   
504#else
505        BKNI_Printf("You need to tune to a frequency before testing A56 use in band tuner.\n");
506        BKNI_Printf("If not yet, please use tuner test to tune a freqency first.\n");
507#endif
508
509        while(0 == exit_menu){
510                MENU_DELIMETER();
511                BKNI_Printf("Menu Level 2 - A56 Filter Test\n");
512                BKNI_Printf("1 - Test Network Information Message filter\n");
513                BKNI_Printf("2 - Test Network Text Message filter\n");
514                BKNI_Printf("3 - Test Virtual Channel Message filter\n");
515                BKNI_Printf("4 - Stop filter\n");
516                BKNI_Printf("0 - Return to previous menu\n");
517                BKNI_Printf("> ");
518                input = serial_getc(CONSOLE_UART, true);
519                BKNI_Printf("%c\n", input);
520                switch(input){
521                        case '0':
522                                a56_test_stop();
523                                exit_menu = 1;
524                                continue;       
525                        case '1':
526                                input = get_pid();
527                                a56_test_start(A56_NIM, input);
528                                break;
529                        case '2':
530                                input = get_pid();
531                                a56_test_start(A56_NTM, input);
532                                break;
533                        case '3':
534                                input = get_pid();
535                                a56_test_start(A56_VCM, input);
536                                break;
537                        case '4':
538                                a56_test_stop();
539                                break;
540                }
541        }
542}
543
Note: See TracBrowser for help on using the repository browser.