]> git.kernelconcepts.de Git - rdstmc.git/blobdiff - decoder/rds.c
Add radio tuning test app
[rdstmc.git] / decoder / rds.c
index 27a417c49398053184b816b084fd72c8695d0b37..ca927b2e9c753364482100031e695b5332c656fe 100644 (file)
@@ -95,9 +95,11 @@ unsigned char offset;
 
        rb = read(rds_fd, rbuf, 3);
        if (rb <= 0)
-               exit(0); // just for testing
-       if (rb != 3)
+               return 0;
+       if (rb != 3) {
                printf("#read err rb=%d\n", rb);
+               return 0;
+       }
        block = rbuf[0] | (rbuf[1] << 8);
        offset = rbuf[2] & 0x07;
 
@@ -124,6 +126,7 @@ unsigned char offset;
        }
        if (OutputFlags & RDS_RECEIVE_INDICATOR)
                printf(".");
+
        return 0;
 }
 
@@ -135,10 +138,18 @@ enum RDSGroupType { GROUP_0A=0, GROUP_0B, GROUP_1A, GROUP_1B, GROUP_2A, GROUP_2B
                     GROUP_12A, GROUP_12B, GROUP_13A, GROUP_13B, GROUP_14A, GROUP_14B, 
                     GROUP_15A, GROUP_15B, GROUP_UNKNOWN };
 
+void rds_radio_retuned(void)
+{
+       memset(&rds_info, 0, sizeof(rds_info));
+       rds_info.LTN = -1;
+       memset(&rds_time, 0, sizeof(rds_time));
+}
+
 void rds_decode_group(unsigned short *rdsgroup)
 {
 static unsigned short ogrp[4];
 static unsigned char grp_decoded = 0;
+static unsigned char sname_rcvd = 0;
 unsigned char grp_type = (rdsgroup[1] >> 11);
 unsigned char offs;
 static unsigned char otextAB = 0, newtext = 0;
@@ -169,6 +180,7 @@ int year_, mon_, K;
                rds_info.ccode = (PI & 0xf000) >> 12;
                rds_info.ptype = (PI & 0x0f00) >> 8;
                rds_info.pref = (PI & 0x00ff);
+               sname_rcvd = 0;
                if (rds_info.pref == 0) /* something is wrong here */
                        return;
                rds_info.PI = rdsgroup[0];
@@ -184,10 +196,20 @@ int year_, mon_, K;
                        float AF1=0, AF2=0;
 
                        offs = (rdsgroup[1] & 0x03);
+                       if (offs == 0)
+                               sname_rcvd = 0;
+                       if (offs == 1 && sname_rcvd == 0)
+                               sname_rcvd = 1;
+                       if (offs == 2 && sname_rcvd == 1)
+                               sname_rcvd = 2;
+                       if (offs == 3 && sname_rcvd == 2)
+                               sname_rcvd = 3;
                        rds_info.sname[offs*2] = ((rdsgroup[3] & 0xff00) >> 8);
                        rds_info.sname[(offs*2)+1] = rdsgroup[3] & 0x00ff;
-                       if (_rds_private.rds_sname_cb != NULL)
+                       if (_rds_private.rds_sname_cb != NULL && sname_rcvd == 3) {
                                _rds_private.rds_sname_cb(rds_info.sname, _rds_private.rds_sname_cb_data);
+                               sname_rcvd = 0;
+                       }
 
                        rds_info.TA = (rdsgroup[1] & 0x10) >> 4;
                        rds_info.TP = (rdsgroup[1] & 0x400) >> 10;