diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-09-14 12:03:34 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-09-14 12:06:08 -0300 |
commit | 0507dace6a34e81eb38c72f25bc531510bb5e269 (patch) | |
tree | c73492a89942a5830baa7ed41ae46744ba80a8ad /contrib | |
parent | c4e002f21434decdadb4cc67a52577d0cd28cd5e (diff) |
utils: move rds out of it, placing at contrib
The rds/ dir isn't a core RDS set of utilities, but something else.
Move it to contrib/
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/Makefile.am | 6 | ||||
-rw-r--r-- | contrib/rds-saa6588/.gitignore | 1 | ||||
-rw-r--r-- | contrib/rds-saa6588/Makefile.am | 3 | ||||
-rw-r--r-- | contrib/rds-saa6588/rds-saa6588.c | 137 |
4 files changed, 147 insertions, 0 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 7de015cf..d41dc539 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,5 +1,11 @@ if LINUX_OS SUBDIRS = test xc3028-firmware + +if HAVE_LINUX_I2C_DEV +SUBDIRS += \ + rds-saa6588 +endif + else SUBDIRS = freebsd endif diff --git a/contrib/rds-saa6588/.gitignore b/contrib/rds-saa6588/.gitignore new file mode 100644 index 00000000..101db6e9 --- /dev/null +++ b/contrib/rds-saa6588/.gitignore @@ -0,0 +1 @@ +rds-saa6588 diff --git a/contrib/rds-saa6588/Makefile.am b/contrib/rds-saa6588/Makefile.am new file mode 100644 index 00000000..a551d9fb --- /dev/null +++ b/contrib/rds-saa6588/Makefile.am @@ -0,0 +1,3 @@ +noinst_PROGRAMS = rds-saa6588 + +rds_saa6588_SOURCES = rds-saa6588.c diff --git a/contrib/rds-saa6588/rds-saa6588.c b/contrib/rds-saa6588/rds-saa6588.c new file mode 100644 index 00000000..9f40872f --- /dev/null +++ b/contrib/rds-saa6588/rds-saa6588.c @@ -0,0 +1,137 @@ +/* + * $Id: rds-saa6588.c,v 1.3 2005/06/12 04:19:19 mchehab Exp $ + * + * poll i2c RDS receiver [Philips saa6588] + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <linux/types.h> +#include <linux/i2c.h> +#include <linux/i2c-dev.h> + +int debug; + +/* ----------------------------------------------------------------- */ + +char rds_psn[9]; +char rds_txt[65]; + +static void rds_decode(int blkno,int b1, int b2) +{ + static int group,spare,c1,c2; + + switch (blkno) { + case 0: + if (debug) + fprintf(stderr,"block A - id=%d\n", + (b1 << 8) | b2); + break; + case 1: + if (debug) + fprintf(stderr,"block B - group=%d%c tp=%d pty=%d spare=%d\n", + (b1 >> 4) & 0x0f, + ((b1 >> 3) & 0x01) + 'A', + (b1 >> 2) & 0x01, + ((b1 << 3) & 0x18) | ((b2 >> 5) & 0x07), + b2 & 0x1f); + group = (b1 >> 3) & 0x1f; + spare = b2 & 0x1f; + break; + case 2: + if (debug) + fprintf(stderr,"block C - 0x%02x 0x%02x\n",b1,b2); + c1 = b1; + c2 = b2; + break; + case 3: + if (debug) + fprintf(stderr,"block D - 0x%02x 0x%02x\n",b1,b2); + switch (group) { + case 0: + rds_psn[2*(spare & 0x03)+0] = b1; + rds_psn[2*(spare & 0x03)+1] = b2; + if ((spare & 0x03) == 0x03) + fprintf(stderr,"PSN #>%s<#\n",rds_psn); + break; + case 4: + rds_txt[4*(spare & 0x0f)+0] = c1; + rds_txt[4*(spare & 0x0f)+1] = c2; + rds_txt[4*(spare & 0x0f)+2] = b1; + rds_txt[4*(spare & 0x0f)+3] = b2; + if ((spare & 0x0f) == 0x0f) + fprintf(stderr,"TXT #>%s<#\n",rds_txt); + break; + } + break; + default: + fprintf(stderr,"unknown block [%d]\n",blkno); + } +} + +int +main(int argc, char *argv[]) +{ + int c,f,rc, no, lastno = -1; + unsigned char b[40]; + char *device = "/dev/i2c-0"; + + /* parse options */ + while (-1 != (c=getopt(argc,argv,"hvd:"))) { + switch (c){ + case 'd': + if (optarg) + device = optarg; + break; + case 'v': + debug = 1; + break; + case 'h': + default: + printf("poll i2c RDS receiver [saa6588] via chardev\n"); + printf("usage: %s [ -d i2c-device ]\n",argv[0]); + exit(1); + } + } + + if (-1 == (f = open(device,O_RDWR))) { + fprintf(stderr,"open %s: %s\n",device,strerror(errno)); + exit(1); + } + ioctl(f,I2C_SLAVE,0x20 >> 1); + for (;;) { + memset(b,0,sizeof(b)); + rc = read(f,b,6); + if (6 != rc) { + fprintf(stderr,"oops: read: rc=%d, expected 6 [%s]\n", + rc,strerror(errno)); + break; + } + if (0 == (b[0] & 0x10)) { + fprintf(stderr,"no signal\r"); + continue; + } + if (1 == (b[0] & 0x08)) { + fprintf(stderr,"overflow detected\n"); + } + if (1 == (b[0] & 0x04)) { + fprintf(stderr,"reset detected\n"); + } + if (debug) + fprintf(stderr,"raw: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + b[0],b[1],b[2],b[3],b[4],b[5]); + no = b[0] >> 5; + if (lastno != no) { + rds_decode(no, b[1], b[2]); + lastno = no; + } + usleep(10*1000); + } + close(f); + exit(0); +} |