]> git.karo-electronics.de Git - rdstmc.git/blobdiff - decoder/rds.c
Add radio tuning test app
[rdstmc.git] / decoder / rds.c
index bdaee7b9fe76ff0f8e2bb75da20a704a3a18f3d0..ca927b2e9c753364482100031e695b5332c656fe 100644 (file)
@@ -138,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;
@@ -172,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];
@@ -187,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;