[dvblast-devel] [PATCH 4/4] dvblastctl: Add support for get_pat, get_cat, get_nit and get_sdt commands.

Georgi Chorbadzhiyski gf at unixsol.org
Thu Aug 25 15:00:09 CEST 2011


---
 NEWS         |    1 +
 dvblastctl.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index a31fb80..7de4d63 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Changes between 1.2 and 2.0:
   * Add basic support for ATSC
   * Add support for MRTG statistics
   * Add detailed information for TS errors
+  * Add support for getting PAT/CAT/NIT/SDT tables in dvblastctl
 
 Changes between 1.1 and 1.2:
 ----------------------------
diff --git a/dvblastctl.c b/dvblastctl.c
index 2d5099e..75359ee 100644
--- a/dvblastctl.c
+++ b/dvblastctl.c
@@ -22,11 +22,13 @@
  *****************************************************************************/
 
 #include <stdlib.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
@@ -37,6 +39,11 @@
 #include <errno.h>
 #include <getopt.h>
 
+#include <bitstream/mpeg/psi.h>
+#include <bitstream/dvb/si.h>
+#include <bitstream/dvb/si_print.h>
+#include <bitstream/mpeg/psi_print.h>
+
 #include "dvblast.h"
 #include "en50221.h"
 #include "comm.h"
@@ -45,11 +52,42 @@
 int i_verbose = 3;
 int i_syslog = 0;
 
+print_type_t i_print_type = PRINT_TEXT;
+
+/*****************************************************************************
+ * The following two functinos are from biTStream's examples and are under the
+ * WTFPL (see LICENSE.WTFPL).
+ ****************************************************************************/
+__attribute__ ((format(printf, 2, 3)))
+static void psi_print(void *_unused, const char *psz_format, ...)
+{
+    char psz_fmt[strlen(psz_format) + 2];
+    va_list args;
+    va_start(args, psz_format);
+    strcpy(psz_fmt, psz_format);
+    strcat(psz_fmt, "\n");
+    vprintf(psz_fmt, args);
+}
+
+static char *iconv_append_null(const char *p_string, size_t i_length)
+{
+    char *psz_string = malloc(i_length + 1);
+    memcpy(psz_string, p_string, i_length);
+    psz_string[i_length] = '\0';
+    return psz_string;
+}
+
+char *psi_iconv(void *_unused, const char *psz_encoding,
+                  char *p_string, size_t i_length)
+{
+    return iconv_append_null(p_string, i_length);
+}
+
 void usage()
 {
     msg_Raw( NULL, "DVBlastctl %d.%d.%d%s", VERSION_MAJOR, VERSION_MINOR,
              VERSION_REVISION, VERSION_EXTRA );
-    msg_Raw( NULL, "Usage: dvblastctl -r <remote socket> reload|shutdown|fe_status|mmi_status|mmi_open|mmi_close|mmi_get|mmi_send_text|mmi_send_choice [<CAM slot>] [<text/choice>]" );
+    msg_Raw( NULL, "Usage: dvblastctl -r <remote socket> reload|shutdown|fe_status|mmi_status|mmi_open|mmi_close|mmi_get|mmi_send_text|mmi_send_choice|get_pat|get_cat|get_nit|get_sdt [<CAM slot>] [-x <text|xml>] [<text/choice>]" );
     exit(1);
 }
 
@@ -71,11 +109,12 @@ int main( int i_argc, char **ppsz_argv )
         static const struct option long_options[] =
         {
             {"remote-socket", required_argument, NULL, 'r'},
+            {"print", required_argument, NULL, 'x'},
             {"help", no_argument, NULL, 'h'},
             {0, 0, 0, 0}
         };
 
-        if ( (c = getopt_long(i_argc, ppsz_argv, "r:h", long_options, NULL)) == -1 )
+        if ( (c = getopt_long(i_argc, ppsz_argv, "r:x:h", long_options, NULL)) == -1 )
             break;
 
         switch ( c )
@@ -84,6 +123,17 @@ int main( int i_argc, char **ppsz_argv )
             psz_srv_socket = optarg;
             break;
 
+        case 'x':
+            if ( !strcmp(optarg, "text") )
+                i_print_type = PRINT_TEXT;
+            else if ( !strcmp(optarg, "xml") )
+                i_print_type = PRINT_XML;
+            else
+                msg_Warn( NULL, "unrecognized print type %s", optarg );
+            /* Make stdout line-buffered */
+            setvbuf(stdout, NULL, _IOLBF, 0);
+            break;
+
         case 'h':
         default:
             usage();
@@ -96,6 +146,10 @@ int main( int i_argc, char **ppsz_argv )
     if ( strcmp(ppsz_argv[optind], "reload")
           && strcmp(ppsz_argv[optind], "shutdown")
           && strcmp(ppsz_argv[optind], "fe_status")
+          && strcmp(ppsz_argv[optind], "get_pat")
+          && strcmp(ppsz_argv[optind], "get_cat")
+          && strcmp(ppsz_argv[optind], "get_nit")
+          && strcmp(ppsz_argv[optind], "get_sdt")
           && strcmp(ppsz_argv[optind], "mmi_status")
           && strcmp(ppsz_argv[optind], "mmi_slot_status")
           && strcmp(ppsz_argv[optind], "mmi_open")
@@ -171,6 +225,14 @@ int main( int i_argc, char **ppsz_argv )
         p_buffer[1] = CMD_SHUTDOWN;
     else if ( !strcmp(ppsz_argv[optind], "fe_status") )
         p_buffer[1] = CMD_FRONTEND_STATUS;
+    else if ( !strcmp(ppsz_argv[optind], "get_pat") )
+        p_buffer[1] = CMD_GET_PAT;
+    else if ( !strcmp(ppsz_argv[optind], "get_cat") )
+        p_buffer[1] = CMD_GET_CAT;
+    else if ( !strcmp(ppsz_argv[optind], "get_nit") )
+        p_buffer[1] = CMD_GET_NIT;
+    else if ( !strcmp(ppsz_argv[optind], "get_sdt") )
+        p_buffer[1] = CMD_GET_SDT;
     else if ( !strcmp(ppsz_argv[optind], "mmi_status") )
         p_buffer[1] = CMD_MMI_STATUS;
     else
@@ -275,6 +337,34 @@ int main( int i_argc, char **ppsz_argv )
         exit(255);
         break;
 
+    case RET_NODATA:
+        msg_Err( NULL, "no data" );
+        exit(255);
+        break;
+
+    case RET_PAT:
+    case RET_CAT:
+    case RET_NIT:
+    case RET_SDT:
+    {
+        uint8_t *p_flat_data = p_buffer + COMM_HEADER_SIZE;
+        unsigned int i_flat_data_size = i_size - COMM_HEADER_SIZE;
+        uint8_t **pp_sections = psi_unpack_sections( p_flat_data, i_flat_data_size );
+
+        switch( p_buffer[1] )
+        {
+            case RET_PAT: pat_table_print( pp_sections, psi_print, NULL, i_print_type ); break;
+            case RET_CAT: cat_table_print( pp_sections, psi_print, NULL, i_print_type ); break;
+            case RET_NIT: nit_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break;
+            case RET_SDT: sdt_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break;
+        }
+
+        psi_table_free( pp_sections );
+        free( pp_sections );
+        exit(0);
+        break;
+    }
+
     case RET_FRONTEND_STATUS:
     {
         struct ret_frontend_status *p_ret =
-- 
1.7.5.1



More information about the dvblast-devel mailing list