Re: [RFC PATCH 2/2] Add rds-ctl tool (with changes proposed in RFC)
Hi, Comments inline. On 08/07/2012 05:11 PM, Konke Radlow wrote: --- Makefile.am |3 +- configure.ac |1 + utils/rds-ctl/Makefile.am |5 + utils/rds-ctl/rds-ctl.cpp | 959 + 4 files changed, 967 insertions(+), 1 deletion(-) create mode 100644 utils/rds-ctl/Makefile.am create mode 100644 utils/rds-ctl/rds-ctl.cpp diff --git a/Makefile.am b/Makefile.am index 621d8d9..8ef0d00 100644 --- a/Makefile.am +++ b/Makefile.am Snip +static void print_rds_data(const struct v4l2_rds *handle, uint32_t updated_fields) +{ + if (params.options[OptPrintBlock]) + updated_fields = 0x; + + if ((updated_fields V4L2_RDS_PI) + (handle-valid_fields V4L2_RDS_PI)) { + printf(\nPI: %04x, handle-pi); + print_rds_pi(handle); + } + + if (updated_fields V4L2_RDS_PS + handle-valid_fields V4L2_RDS_PS) { + printf(\nPS: ); + for (int i = 0; i 8; ++i) { + /* filter out special characters */ + if (handle-ps[i] = 0x20 handle-ps[i] = 0x7E) + printf(%lc,handle-ps[i]); + else + printf( ); + } Since ps now is a 0 terminated UTF-8 string you should be able to just do: printf(\nPS: %s, handle-ps); And likewise for the other strings. + } + + if (updated_fields V4L2_RDS_PTY handle-valid_fields V4L2_RDS_PTY) + printf(\nPTY: %0u - %s,handle-pty, v4l2_rds_get_pty_str(handle)); + + if (updated_fields V4L2_RDS_PTYN handle-valid_fields V4L2_RDS_PTYN) { + printf(\nPTYN: ); + for (int i = 0; i 8; ++i) { + /* filter out special characters */ + if (handle-ptyn[i] = 0x20 handle-ptyn[i] = 0x7E) + printf(%lc,handle-ptyn[i]); + else + printf( ); + } Likewise. + } + + if (updated_fields V4L2_RDS_TIME) { + printf(\nTime: %s, ctime(handle-time)); + } + if (updated_fields V4L2_RDS_RT handle-valid_fields V4L2_RDS_RT) { + printf(\nRT: ); + for (int i = 0; i handle-rt_length; ++i) { + /* filter out special characters */ + if (handle-rt[i] = 0x20 handle-rt[i] = 0x7E) + printf(%lc,handle-rt[i]); + else + printf( ); + } Likewise. + } + + if (updated_fields V4L2_RDS_TP handle-valid_fields V4L2_RDS_TP) + printf(\nTP: %s TA: %s, (handle-tp)? yes:no, + handle-ta? yes:no); + if (updated_fields V4L2_RDS_MS handle-valid_fields V4L2_RDS_MS) + printf(\nMS Flag: %s, (handle-ms)? Music : Speech); + if (updated_fields V4L2_RDS_ECC handle-valid_fields V4L2_RDS_ECC) + printf(\nECC: %X%x, Country: %u - %s, + handle-ecc 4, handle-ecc 0x0f, handle-pi 12, + v4l2_rds_get_country_str(handle)); + if (updated_fields V4L2_RDS_LC handle-valid_fields V4L2_RDS_LC) + printf(\nLanguage: %u - %s , handle-lc, + v4l2_rds_get_language_str(handle)); + if (updated_fields V4L2_RDS_DI handle-valid_fields V4L2_RDS_DI) + print_decoder_info(handle-di); + if (updated_fields V4L2_RDS_ODA + handle-decode_information V4L2_RDS_ODA) { + for (int i = 0; i handle-rds_oda.size; ++i) + printf(\nODA Group: %02u%c, AID: %08x,handle-rds_oda.oda[i].group_id, + handle-rds_oda.oda[i].group_version, handle-rds_oda.oda[i].aid); + } + if (updated_fields V4L2_RDS_AF handle-valid_fields V4L2_RDS_AF) + print_rds_af(handle-rds_af); + if (params.options[OptPrintBlock]) + printf(\n); +} + +static void read_rds(struct v4l2_rds *handle, const int fd, const int wait_limit) +{ + int byte_cnt = 0; + int error_cnt = 0; + uint32_t updated_fields = 0x00; + struct v4l2_rds_data rds_data; /* read buffer for rds blocks */ + + while (!params.terminate_decoding) { + memset(rds_data, 0, sizeof(rds_data)); + if ((byte_cnt=read(fd, rds_data, 3)) != 3) { + if (byte_cnt == 0) { + printf(\nEnd of input file reached \n); + break; + } else if(++error_cnt 2) { + fprintf(stderr, \nError reading from + device (no RDS data available)\n); +
Re: [RFC PATCH 2/2] Add rds-ctl tool (with changes proposed in RFC)
On Thu, Aug 9, 2012 at 12:05 PM, Hans de Goede hdego...@redhat.com wrote: Hi, Comments inline. On 08/07/2012 05:11 PM, Konke Radlow wrote: --- Makefile.am |3 +- configure.ac |1 + utils/rds-ctl/Makefile.am |5 + utils/rds-ctl/rds-ctl.cpp | 959 + 4 files changed, 967 insertions(+), 1 deletion(-) create mode 100644 utils/rds-ctl/Makefile.am create mode 100644 utils/rds-ctl/rds-ctl.cpp diff --git a/Makefile.am b/Makefile.am index 621d8d9..8ef0d00 100644 --- a/Makefile.am +++ b/Makefile.am Snip +static void print_rds_data(const struct v4l2_rds *handle, uint32_t updated_fields) +{ + if (params.options[OptPrintBlock]) + updated_fields = 0x; + + if ((updated_fields V4L2_RDS_PI) + (handle-valid_fields V4L2_RDS_PI)) { + printf(\nPI: %04x, handle-pi); + print_rds_pi(handle); + } + + if (updated_fields V4L2_RDS_PS + handle-valid_fields V4L2_RDS_PS) { + printf(\nPS: ); + for (int i = 0; i 8; ++i) { + /* filter out special characters */ + if (handle-ps[i] = 0x20 handle-ps[i] = 0x7E) + printf(%lc,handle-ps[i]); + else + printf( ); + } Since ps now is a 0 terminated UTF-8 string you should be able to just do: printf(\nPS: %s, handle-ps); And likewise for the other strings. changed as proposed, and works like a charm :) Other then that this looks good to me. Regards, Hans thank you for the review Regards, Konke -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFC PATCH 2/2] Add rds-ctl tool (with changes proposed in RFC)
--- Makefile.am |3 +- configure.ac |1 + utils/rds-ctl/Makefile.am |5 + utils/rds-ctl/rds-ctl.cpp | 959 + 4 files changed, 967 insertions(+), 1 deletion(-) create mode 100644 utils/rds-ctl/Makefile.am create mode 100644 utils/rds-ctl/rds-ctl.cpp diff --git a/Makefile.am b/Makefile.am index 621d8d9..8ef0d00 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,8 @@ SUBDIRS += \ utils/v4l2-compliance \ utils/v4l2-ctl \ utils/v4l2-dbg \ - utils/v4l2-sysfs-path + utils/v4l2-sysfs-path \ + utils/rds-ctl if LINUX_OS SUBDIRS += \ diff --git a/configure.ac b/configure.ac index 1109c4d..a99f1c6 100644 --- a/configure.ac +++ b/configure.ac @@ -28,6 +28,7 @@ AC_CONFIG_FILES([Makefile utils/v4l2-sysfs-path/Makefile utils/xc3028-firmware/Makefile utils/qv4l2/Makefile + utils/rds-ctl/Makefile contrib/freebsd/Makefile contrib/test/Makefile diff --git a/utils/rds-ctl/Makefile.am b/utils/rds-ctl/Makefile.am new file mode 100644 index 000..9a84257 --- /dev/null +++ b/utils/rds-ctl/Makefile.am @@ -0,0 +1,5 @@ +bin_PROGRAMS = rds-ctl + +rds_ctl_SOURCES = rds-ctl.cpp +rds_ctl_LDADD = ../../lib/libv4l2/libv4l2.la ../../lib/libv4l2rds/libv4l2rds.la + diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp new file mode 100644 index 000..072ffb7 --- /dev/null +++ b/utils/rds-ctl/rds-ctl.cpp @@ -0,0 +1,959 @@ +/* + * rds-ctl.cpp is based on v4l2-ctl.cpp + * + * the following applies for all RDS related parts: + * Copyright 2012 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + * Author: Konke Radlow korad...@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA + */ + +#include unistd.h +#include stdlib.h +#include stdio.h +#include string.h +#include wchar.h +#include locale.h +#include inttypes.h +#include getopt.h +#include sys/types.h +#include fcntl.h +#include errno.h +#include sys/ioctl.h +#include sys/time.h +#include dirent.h +#include config.h +#include signal.h + +#include linux/videodev2.h +#include libv4l2.h +#include libv4l2rds.h + +#include list +#include vector +#include map +#include string +#include algorithm + +#define ARRAY_SIZE(arr) ((int)(sizeof(arr) / sizeof((arr)[0]))) + +typedef std::vectorstd::string dev_vec; +typedef std::mapstd::string, std::string dev_map; + +/* Short option list + + Please keep in alphabetical order. + That makes it easier to see which short options are still free. + + In general the lower case is used to set something and the upper + case is used to retrieve a setting. */ +enum Option { + OptSetDevice = 'd', + OptGetDriverInfo = 'D', + OptGetFreq = 'F', + OptSetFreq = 'f', + OptHelp = 'h', + OptReadRds = 'R', + OptGetTuner = 'T', + OptSetTuner = 't', + OptUseWrapper = 'w', + OptAll = 128, + OptFreqSeek, + OptListDevices, + OptListFreqBands, + OptOpenFile, + OptPrintBlock, + OptSilent, + OptTunerIndex, + OptVerbose, + OptWaitLimit, + OptLast = 256 +}; + +struct ctl_parameters { + bool terminate_decoding; + char options[OptLast]; + char fd_name[80]; + bool filemode_active; + double freq; + uint32_t wait_limit; + uint8_t tuner_index; + struct v4l2_hw_freq_seek freq_seek; +}; + +static struct ctl_parameters params; +static int app_result; + +static struct option long_options[] = { + {all, no_argument, 0, OptAll}, + {device, required_argument, 0, OptSetDevice}, + {file, required_argument, 0, OptOpenFile}, + {freq-seek, required_argument, 0, OptFreqSeek}, + {get-freq, no_argument, 0, OptGetFreq}, + {get-tuner, no_argument, 0, OptGetTuner}, + {help, no_argument, 0, OptHelp}, + {info, no_argument, 0, OptGetDriverInfo}, + {list-devices, no_argument, 0, OptListDevices}, + {list-freq-bands, no_argument, 0, OptListFreqBands}, + {print-block, no_argument, 0, OptPrintBlock}, + {read-rds, no_argument, 0, OptReadRds}, + {set-freq, required_argument, 0, OptSetFreq}, + {tuner-index, required_argument, 0, OptTunerIndex}, + {verbose,