| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2011, 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: transport capture test |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | #include "bstd.h" |
|---|
| 24 | #include "bkni.h" |
|---|
| 25 | #include "bdbg.h" |
|---|
| 26 | |
|---|
| 27 | #include "bsettop_smessage.h" |
|---|
| 28 | #include "test_capture.h" |
|---|
| 29 | |
|---|
| 30 | #define CAP_BUFFER_SIZE 188 |
|---|
| 31 | /* must be power of two */ |
|---|
| 32 | #define CAP_BLK_CNT 32 |
|---|
| 33 | typedef struct tcap_context_t { |
|---|
| 34 | smessage_stream_t msg; |
|---|
| 35 | uint16_t pid; |
|---|
| 36 | uint8_t cnt; |
|---|
| 37 | smessage_stream_params_t params; |
|---|
| 38 | uint8_t buffer[CAP_BUFFER_SIZE*CAP_BLK_CNT]; |
|---|
| 39 | } tcap_context_t; |
|---|
| 40 | |
|---|
| 41 | BDBG_MODULE(tcap); |
|---|
| 42 | |
|---|
| 43 | static tcap_context_t tcap_context = {NULL, 0, 0}; |
|---|
| 44 | uint8_t buffer[CAP_BUFFER_SIZE*CAP_BLK_CNT]; |
|---|
| 45 | extern unsigned int menu_read_number(void); |
|---|
| 46 | extern void comm_dump_mem(unsigned char *buff, size_t size); |
|---|
| 47 | |
|---|
| 48 | void *tcap_message_callback(void *context, size_t size) |
|---|
| 49 | { |
|---|
| 50 | unsigned w_idx; |
|---|
| 51 | |
|---|
| 52 | BDBG_ASSERT(size==CAP_BUFFER_SIZE); |
|---|
| 53 | tcap_context.cnt++; |
|---|
| 54 | w_idx = CAP_BUFFER_SIZE * (tcap_context.cnt % CAP_BLK_CNT); |
|---|
| 55 | return (void*)&tcap_context.buffer[w_idx]; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void tcap_parameters(void) |
|---|
| 59 | { |
|---|
| 60 | BKNI_Printf("Enter number in decimal (1234) or hex (0x1234) format.\n"); |
|---|
| 61 | BKNI_Printf("PID to capture "); |
|---|
| 62 | tcap_context.pid = menu_read_number(); |
|---|
| 63 | BKNI_Printf("\n"); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void tcap_start(void) |
|---|
| 67 | { |
|---|
| 68 | if (!tcap_context.pid) { |
|---|
| 69 | BKNI_Printf("PID is not configured, configure it first.\n"); |
|---|
| 70 | return; |
|---|
| 71 | } |
|---|
| 72 | if (tcap_context.msg) { |
|---|
| 73 | BKNI_Printf("Capture is running now for PID 0x%04x.\n", tcap_context.params.pid); |
|---|
| 74 | return; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | BKNI_Printf("Start TS capture for PID 0x%04x\n", tcap_context.pid); |
|---|
| 78 | |
|---|
| 79 | tcap_context.msg = smessage_open(smessage_format_tsc); |
|---|
| 80 | if (tcap_context.msg == NULL) { |
|---|
| 81 | BDBG_ERR(("%s:%d", __FILE__, __LINE__)); |
|---|
| 82 | return; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | tcap_context.cnt = 0; |
|---|
| 86 | smessage_stream_params_init(&tcap_context.params, tcap_context.msg); |
|---|
| 87 | tcap_context.params.band = TUNER_BAND; |
|---|
| 88 | tcap_context.params.pid = tcap_context.pid; |
|---|
| 89 | tcap_context.params.pid_channel = 6; |
|---|
| 90 | tcap_context.params.buffer = tcap_context.buffer; |
|---|
| 91 | tcap_context.params.buffer_size = CAP_BUFFER_SIZE; /* capture one TS packet at a time */ |
|---|
| 92 | tcap_context.params.data_ready_callback = tcap_message_callback; |
|---|
| 93 | tcap_context.params.overflow = NULL; |
|---|
| 94 | tcap_context.params.callback_context = NULL; |
|---|
| 95 | tcap_context.params.crc_disabled = true; |
|---|
| 96 | |
|---|
| 97 | if (b_ok != smessage_start(&tcap_context.params, tcap_context.msg)) { |
|---|
| 98 | BDBG_ERR(("%s:%d", __FILE__, __LINE__)); |
|---|
| 99 | return; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void tcap_stop(void) |
|---|
| 104 | { |
|---|
| 105 | if (tcap_context.msg) { |
|---|
| 106 | if (b_ok != smessage_stop(tcap_context.msg)) { |
|---|
| 107 | BDBG_ERR(("%s:%d", __FILE__, __LINE__)); |
|---|
| 108 | } |
|---|
| 109 | smessage_close(tcap_context.msg); |
|---|
| 110 | tcap_context.msg = NULL; |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | void tcap_display(void) |
|---|
| 115 | { |
|---|
| 116 | int i; |
|---|
| 117 | BKNI_Printf("Accepted TS packet : %d\n", tcap_context.cnt); |
|---|
| 118 | if (tcap_context.cnt>=CAP_BLK_CNT) { |
|---|
| 119 | for (i=(tcap_context.cnt%CAP_BLK_CNT); i<CAP_BLK_CNT; i++) { |
|---|
| 120 | comm_dump_mem(&tcap_context.buffer[i*CAP_BUFFER_SIZE], CAP_BUFFER_SIZE); |
|---|
| 121 | BKNI_Sleep(100); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | for (i=0; i<tcap_context.cnt%CAP_BLK_CNT; i++) { |
|---|
| 125 | comm_dump_mem(&tcap_context.buffer[i*CAP_BUFFER_SIZE], CAP_BUFFER_SIZE); |
|---|
| 126 | BKNI_Sleep(100); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|