summaryrefslogtreecommitdiffstats
path: root/qcom/fmradio/FmReceiver.java
blob: 81b395e495fc57988902ac132e69e4bc399785ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
/*
 * Copyright (c) 2009,2012-2014, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *        * Redistributions of source code must retain the above copyright
 *            notice, this list of conditions and the following disclaimer.
 *        * Redistributions in binary form must reproduce the above copyright
 *            notice, this list of conditions and the following disclaimer in the
 *            documentation and/or other materials provided with the distribution.
 *        * Neither the name of The Linux Foundation nor
 *            the names of its contributors may be used to endorse or promote
 *            products derived from this software without specific prior written
 *            permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON-INFRINGEMENT ARE DISCLAIMED.    IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package qcom.fmradio;

import android.util.Log;
import android.os.SystemProperties;

/**
 * This class contains all interfaces and types needed to
 * Control the FM receiver.
 *    @hide
 */
public class FmReceiver extends FmTransceiver
{

   public static int mSearchState = subSrchLevel_NoSearch;

   static final int STD_BUF_SIZE = 256;
   static final int GRP_3A = 64;
   private static final String TAG = "FMRadio";

   /**
   * Search (seek/scan/searchlist) by decrementing the frequency
   *
   * @see #FM_RX_SEARCHDIR_UP
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   * @see #searchStationList
   */
   public static final int FM_RX_SEARCHDIR_DOWN=0;
   /**
   * Search (seek/scan/searchlist) by inrementing the frequency
   *
   * @see #FM_RX_SEARCHDIR_DOWN
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   * @see #searchStationList
   */
   public static final int FM_RX_SEARCHDIR_UP=1;

   /**
   * Scan dwell (Preview) duration = 0 seconds
   *
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_DWELL_PERIOD_0S=0;
  /**
   * Scan dwell (Preview) duration = 1 second
   *
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_DWELL_PERIOD_1S=1;
   /**
   * Scan dwell (Preview) duration = 2 seconds
   *
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_DWELL_PERIOD_2S=2;
   /**
   * Scan dwell (Preview) duration = 3 seconds
   *
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_DWELL_PERIOD_3S=3;
   /**
   * Scan dwell (Preview) duration = 4 seconds
   *
   * @see #searchStations(int, int, int)
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_DWELL_PERIOD_4S=4;
   /**
    * Scan dwell (Preview) duration = 5 seconds
    *
    * @see #searchStations(int, int, int)
    * @see #searchStations(int, int, int, int, int)
    */
   public static final int FM_RX_DWELL_PERIOD_5S=5;
   /**
    * Scan dwell (Preview) duration = 6 seconds
    *
    * @see #searchStations(int, int, int)
    * @see #searchStations(int, int, int, int, int)
    */
   public static final int FM_RX_DWELL_PERIOD_6S=6;
   /**
    * Scan dwell (Preview) duration = 7 second
    *
    * @see #searchStations(int, int, int)
    * @see #searchStations(int, int, int, int, int)
    */
   public static final int FM_RX_DWELL_PERIOD_7S=7;


   /**
   * Basic Seek Mode Option
   *
   * @see #searchStations(int, int, int)
   */
   public static final int FM_RX_SRCH_MODE_SEEK        =0;
   /**
   * Basic Scan Mode Option
   *
   * @see #searchStations(int, int, int)
   */
   public static final int FM_RX_SRCH_MODE_SCAN        =1;

   /**
   * Search list mode Options to search for Strong stations
   *
   * @see #searchStationList
   */
   public static final int FM_RX_SRCHLIST_MODE_STRONG  =2;
   /**
   * Search list mode Options to search for Weak stations
   *
   * @see #searchStationList
   */
   public static final int FM_RX_SRCHLIST_MODE_WEAK    =3;

   /**
   * Seek by Program Type
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHRDS_MODE_SEEK_PTY =4;
   /**
   * Scan by Program Type
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHRDS_MODE_SCAN_PTY =5;
   /**
   * Seek by Program identification
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHRDS_MODE_SEEK_PI  =6;
   /**
   * Seek Alternate Frequency for the same station
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHRDS_MODE_SEEK_AF  =7;
   /**
   * Search list mode Options to search for Strongest stations
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHLIST_MODE_STRONGEST  =8;
   /**
   * Search list mode Options to search for Weakest stations
   *
   * @see #searchStations(int, int, int, int, int)
   */
   public static final int FM_RX_SRCHLIST_MODE_WEAKEST  =9;

   /**
   * Maximum number of stations the SearchStationList can
   * support
   *
   * @see #searchStationList
   */
   public static final int FM_RX_SRCHLIST_MAX_STATIONS =12;

   /**
    *  Argument option for setMuteMode to unmute FM
    *
    *  @see #setMuteMode
    */
   public static final int FM_RX_UNMUTE     =0;
   /**
    *  Argument option for setMuteMode to Mute FM
    *
    *  @see #setMuteMode
    */
   public static final int FM_RX_MUTE       =1;

   /**
    *  Argument option for setStereoMode to set FM to Stereo
    *  Mode.
    *
    *  @see #setStereoMode
    */
   public static final int FM_RX_AUDIO_MODE_STEREO    =0;
   /**
    *  Argument option for setStereoMode to set FM to "Force
    *  Mono" Mode.
    *
    *  @see #setStereoMode
    */
   public static final int FM_RX_AUDIO_MODE_MONO      =1;

   /**
    *  Signal Strength
    *
    *  @see #setSignalThreshold
    *  @see #getSignalThreshold
    */
   public static final int FM_RX_SIGNAL_STRENGTH_VERY_WEAK  =0;
   public static final int FM_RX_SIGNAL_STRENGTH_WEAK       =1;
   public static final int FM_RX_SIGNAL_STRENGTH_STRONG     =2;
   public static final int FM_RX_SIGNAL_STRENGTH_VERY_STRONG=3;

   /**
    * Power settings
    *
    * @see #setPowerMode
    * @see #getPowerMode
    */
   public static final int FM_RX_NORMAL_POWER_MODE   =0;
   public static final int FM_RX_LOW_POWER_MODE      =1;



   /**
    * RDS Processing Options
    *
    * @see #registerRdsGroupProcessing
    * @see #getPSInfo
    * @see #getRTInfo
    * @see #getAFInfo
    */
   public static final int FM_RX_RDS_GRP_RT_EBL         =1;
   public static final int FM_RX_RDS_GRP_PS_EBL         =2;
   public static final int FM_RX_RDS_GRP_AF_EBL         =4;
   public static final int FM_RX_RDS_GRP_PS_SIMPLE_EBL  =16;


   private static final int V4L2_CID_PRIVATE_BASE = 0x8000000;
   private static final int V4L2_CID_PRIVATE_TAVARUA_SIGNAL_TH = V4L2_CID_PRIVATE_BASE + 8;
   private static final int V4L2_CTRL_CLASS_USER = 0x00980000;
   private static final int V4L2_CID_PRIVATE_IRIS_GET_SPUR_TBL = (V4L2_CTRL_CLASS_USER + 0x92E);


   private static final int TAVARUA_BUF_SRCH_LIST=0;
   private static final int TAVARUA_BUF_EVENTS=1;
   private static final int TAVARUA_BUF_RT_RDS=2;
   private static final int TAVARUA_BUF_PS_RDS=3;
   private static final int TAVARUA_BUF_RAW_RDS=4;
   private static final int TAVARUA_BUF_AF_LIST=5;
   private static final int TAVARUA_BUF_MAX=6;

   private FmRxEvCallbacksAdaptor mCallback;
  /**
    *  Internal Constants for Signal thresholds
    *
    *  @see #setSignalThreshold
    *  @see #getSignalThreshold
    */
   private static final int FM_RX_RSSI_LEVEL_VERY_WEAK   = -105;
   private static final int FM_RX_RSSI_LEVEL_WEAK        = -100;
   private static final int FM_RX_RSSI_LEVEL_STRONG      = -96;
   private static final int FM_RX_RSSI_LEVEL_VERY_STRONG = -90;

   /**
     * BUF_TYPE
     */
   private static final int BUF_ERT = 12;
   private static final int BUF_RTPLUS = 11;

   private static final int LEN_IND = 0;
   private static final int RT_OR_ERT_IND = 1;
   private static final int ENCODE_TYPE_IND = 1;
   private static final int ERT_DIR_IND = 2;

  /**
    * Search Algo type
    */
   private static final int SEARCH_MPXDCC = 0;
   private static final int SEARCH_SINR_INT = 1;

   /**
    * Constructor for the receiver Object
    */
   public FmReceiver(){
      mControl = new FmRxControls();
      mRdsData = new FmRxRdsData (sFd);
      mRxEvents = new FmRxEventListner();
   }

   /**
   *    Constructor for the receiver Object that takes path to
   *    radio and event callbacks.
   *    <p>
   *    @param devicePath FM Device path String.
   *    @param callback the callbacks to handle the events
   *                               events from the FM receiver.
   *
   */
   public FmReceiver(String devicePath,
                     FmRxEvCallbacksAdaptor callback) throws InstantiationException {
      mControl = new FmRxControls();
      mRxEvents = new FmRxEventListner();

      //registerClient(callback);
      mCallback = callback;
   }


   /*==============================================================
   FUNCTION:  registerClient
   ==============================================================*/
   /**
   *    Registers a callback for FM receiver event
   *           notifications.
   *    <p>
   *    This is a synchronous command used to register for event
   *    notifications from the FM receiver driver. Since the FM
   *    driver performs some tasks asynchronously, this function
   *    allows the client to receive information asynchronously.
   *    <p>
   *    When calling this function, the client must pass a callback
   *    function which will be used to deliver asynchronous events.
   *    The argument callback must be a non-NULL value.  If a NULL
   *    value is passed to this function, the registration will
   *    fail.
   *    <p>
   *    The client can choose which events will be sent from the
   *    receiver driver by simply implementing functions for events
   *    it wishes to receive.
   *    <p>
   *    @param callback the callbacks to handle the events
   *                               events from the FM receiver.
   *    @return true if Callback registered, false if Callback
   *            registration failed.
   *    <p>
   *    @see #acquire
   *    @see #unregisterClient
   *
   */
   public boolean registerClient(FmRxEvCallbacks callback){
      boolean status;
      status = super.registerClient(callback);
      /* Do Receiver Specific Stuff here.*/

      return status;
   }

   /*==============================================================
   FUNCTION:  unregisterClient
   ==============================================================*/
   /**
   *    UnRegisters a client's event notification callback.
   *
   *    This is a synchronous command used to unregister a client's
   *    event callback.
   *    <p>
   *    @return true Always returns true.
   *    <p>
   *    @see #acquire
   *    @see #release
   *    @see #registerClient
   *
   */
   public boolean unregisterClient () {
      boolean status;

      status = super.unregisterClient();

      /* Do Receiver Specific Stuff here.*/
      return status;
   }

   /*==============================================================
   FUNCTION:  enable
   ==============================================================*/
   /**
   *    Enables the FM device in Receiver Mode.
   *    <p>
   *    This is a synchronous method used to initialize the FM
   *    receiver. If already initialized this function will
   *    intialize the receiver with default settings. Only after
   *    successfully calling this function can many of the FM device
   *    interfaces be used.
   *    <p>
   *    When enabling the receiver, the client must also provide
   *    the regional settings in which the receiver will operate.
   *    These settings (included in argument configSettings) are
   *    typically used for setting up the FM receiver for operating
   *    in a particular geographical region. These settings can be
   *    changed after the FM driver is enabled through the use of
   *    the function {@link #configure}.
   *    <p>
   *    This command can only be issued by the owner of an FM
   *    receiver.  To issue this command, the client must first
   *    successfully call {@link #acquire}.
   *    <p>
   *    @param configSettings  the settings to be applied when
   *                             turning on the radio
   *    @return true if Initialization succeeded, false if
   *            Initialization failed.
   *    <p>
   *    @see #enable
   *    @see #registerClient
   *    @see #disable
   *
   */
   public boolean enable (FmConfig configSettings){
      boolean status = false;
      /*
       * Check for FM State.
       * If FMRx already on, then return.
      */
      int state = getFMState();
      if (state == FMState_Rx_Turned_On || state == FMState_Srch_InProg) {
         Log.d(TAG, "enable: FM already turned On and running");
         return status;
      }else if (state == subPwrLevel_FMTurning_Off) {
         Log.v(TAG, "FM is in the process of turning off.Pls wait for sometime.");
         return status;
      }else if (state == subPwrLevel_FMRx_Starting) {
         Log.v(TAG, "FM is in the process of turning On.Pls wait for sometime.");
         return status;
      }else if ((state == FMState_Tx_Turned_On)
                || (state == subPwrLevel_FMTx_Starting)) {
         Log.v(TAG, "FM Tx is turned on or in the process of turning on.");
         return status;
      }

      setFMPowerState(subPwrLevel_FMRx_Starting);
      Log.v(TAG, "enable: CURRENT-STATE : FMOff ---> NEW-STATE : FMRxStarting");
      status = super.enable(configSettings, FmTransceiver.FM_RX);

      if( status == true ) {
         /* Do Receiver Specific Enable Stuff here.*/
         status = registerClient(mCallback);
         mRdsData = new FmRxRdsData(sFd);
      }
      else {
         status = false;
         Log.e(TAG, "enable: Error while turning FM On");
         Log.e(TAG, "enable: CURRENT-STATE : FMRxStarting ---> NEW-STATE : FMOff");
         setFMPowerState(FMState_Turned_Off);
      }
      return status;
   }

   /*==============================================================
   FUNCTION:  reset
   ==============================================================*/
   /**
   *    Reset the FM Device.
   *    <p>
   *    This is a synchronous command used to reset the state of FM
   *    device in case of unrecoverable error. This function is
   *    expected to be used when the client receives unexpected
   *    notification of radio disabled. Once called, most
   *    functionality offered by the FM device will be disabled
   *    until the client re-enables the device again via
   *    {@link #enable}.
   *    <p>
   *    @return true if reset succeeded, false if reset failed.
   *    @see #enable
   *    @see #disable
   *    @see #registerClient
   */
   public boolean reset(){
      boolean status = false;
      int state = getFMState();

      if(state == FMState_Turned_Off) {
         Log.d(TAG, "FM already turned Off.");
         return false;
      }

      setFMPowerState(FMState_Turned_Off);
      Log.v(TAG, "reset: NEW-STATE : FMState_Turned_Off");

      status = unregisterClient();

      release("/dev/radio0");

      return status;
   }

   /*==============================================================
   FUNCTION:  disable
   ==============================================================*/
   /**
   *    Disables the FM Device.
   *    <p>
   *    This is a synchronous command used to disable the FM
   *    device. This function is expected to be used when the
   *    client no longer requires use of the FM device. Once
   *    called, most functionality offered by the FM device will be
   *    disabled until the client re-enables the device again via
   *    {@link #enable}.
   *    <p>
   *    @return true if disabling succeeded, false if disabling
   *            failed.
   *    @see #enable
   *    @see #registerClient
   */
   public boolean disable(){
      boolean status = false;
      /*
       * Check for FM State. If search is in progress, then cancel the search prior
       * to disabling FM.
      */
      int state = getFMState();
      switch(state) {
      case FMState_Turned_Off:
         Log.d(TAG, "FM already tuned Off.");
         return false;
      case FMState_Srch_InProg:
         Log.v(TAG, "disable: Cancelling the on going search operation prior to disabling FM");
         setSearchState(subSrchLevel_SrchAbort);
         cancelSearch();
         Log.v(TAG, "disable: Wait for the state to change from : Search ---> FMRxOn");
         try {
            /*
             *    The delay of 50ms here is very important.
             *    This delay is useful for the cleanup purpose
             *    when HS is abruptly plugged out when search
             *    is in progress.
            */
            Thread.sleep(50);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
         break;
      case subPwrLevel_FMRx_Starting:
      /*
       * If, FM is in the process of turning On, then wait for
       * the turn on operation to complete before turning off.
      */
         Log.d(TAG, "disable: FM not yet turned On...");
         try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
         /* Check for the state of FM device */
         state = getFMState();
         if(state == subPwrLevel_FMRx_Starting) {
            Log.e(TAG, "disable: FM in bad state");
            return status;
         }
         break;
      case subPwrLevel_FMTurning_Off:
      /*
       * If, FM is in the process of turning Off, then wait for
       * the turn off operation to complete.
      */
         Log.v(TAG, "disable: FM is getting turned Off.");
            return status;
      }

      setFMPowerState(subPwrLevel_FMTurning_Off);
      Log.v(TAG, "disable: CURRENT-STATE : FMRxOn ---> NEW-STATE : FMTurningOff");
      super.disable();

      return true;
   }

   /*==============================================================
   FUNCTION:  getSearchState
   ==============================================================*/
   /**
   *    Gets the current state of the search operation.
   *    <p>
   *    This function is expected to be used when searchStations()
   *    function wants to know whether any seek/scan/auto-select
   *    operation is already in-progress.
   *    If a seek command is issued when one is already in-progress,
   *    we cancel the on-going seek command and start a new search
   *    operation.
   *    <p>
   *    @return current state of FM Search operation:
   *                SRCH_COMPLETE
   *                SRCH_INPROGRESS
   *                SRCH_ABORTED
   */
   static int getSearchState()
   {
      return mSearchState;
   }

   /*==============================================================
   FUNCTION:  setSearchState
   ==============================================================*/
   /**
   *    Sets the current state of the search operation.
   *    <p>
   *    This function is used to set the current state of the
   *    search operation. If a seek command is issued when one
   *    is already in-progress, we cancel the on-going seek command,
   *    set the state of search operation to SRCH_ABORTED
   *    and start a new search.
   *    <p>
   *    @return none
   */
   static void setSearchState(int state)
   {
      mSearchState = state;
      switch(mSearchState) {
         case subSrchLevel_SeekInPrg:
         case subSrchLevel_ScanInProg:
         case subSrchLevel_SrchListInProg:
            setFMPowerState(FMState_Srch_InProg);
            break;
         case subSrchLevel_SrchComplete:
            /* Update the state of the FM device */
            mSearchState = subSrchLevel_NoSearch;
            setFMPowerState(FMState_Rx_Turned_On);
            break;
         case subSrchLevel_SrchAbort:
            break;
         default:
            mSearchState = subSrchLevel_NoSearch;
            break;
      }
   }

   /*==============================================================
   FUNCTION:  searchStations
   ==============================================================*/
   /**
   *   Initiates basic seek and scan operations.
   *    <p>
   *    This command is used to invoke a basic seek/scan of the FM
   *    radio band.
   *    <p>
   *    <ul>
   *    This API is used to:
   *    <li> Invoke basic seek operations ({@link
   *    #FM_RX_SRCH_MODE_SEEK})
   *    <li> Invoke basic scan operations ({@link
   *    #FM_RX_SRCH_MODE_SCAN})
   *    </ul>
   *    <p>
   *    The most basic operation performed by this function
   *    is a {@link #FM_RX_SRCH_MODE_SEEK} command. The seek
   *    process is handled incrementing or decrementing the
   *    frequency in pre-defined channel steps (defined by the
   *    channel spacing) and measuring the resulting signal level.
   *    Once a station is successfully tuned and found to meet or
   *    exceed this signal level, the seek operation will be
   *    completed and a FmRxEvSearchComplete event will be returned
   *    to the client. If no stations are found to match the search
   *    criteria, the frequency will be returned to the originally
   *    tuned station.
   *    <p>
   *    Since seek always results in a frequency being tuned, each
   *    seek operation will also return a single
   *    FmRxEvRadioTuneStatus event to the client/application
   *    layer.
   *    <p>
   *    Much like {@link #FM_RX_SRCH_MODE_SEEK}, a {@link
   *    #FM_RX_SRCH_MODE_SCAN} command can be likened to many back
   *    to back seeks with a dwell period after each successful
   *    seek. Once issued, a scan will either increment or
   *    decrement frequencies by the defined channel spacing until
   *    a station is found to meet or exceed the set search
   *    threshold. Once this station is found, and is successfully
   *    tuned, an FmRxEvRadioTuneStatus event will be returned to
   *    the client and the station will remain tuned for the
   *    specific period of time indicated by argument dwellPeriod.
   *    After that time expires, an FmRxEvSearchInProgress event
   *    will be sent to the client and a new search will begin for
   *    the next station that meets the search threshold. After
   *    scanning the entire band, or after a cancel search has been
   *    initiated by the client, an FmRxEvRadioTuneStatus event
   *    will be sent to the client. Similar to a seek command, each
   *    scan will result in at least one station being tuned, even
   *    if this is the starting frequency.
   *    <p>
   *    Each time the driver initiates a search (seek or scan) the client
   *    will be notified via an FmRxEvSearchInProgress event.
   *    Similarly, each time a search completes, the client will be notified via an
   *    FmRxEvRadioTuneStatus event.
   *    <p>
   *    Once issuing a search command, several commands from the client
   *    may be disallowed until the search is completed or cancelled.
   *    <p>
   *    The search can be canceled at any time by using API
   *    cancelSearch (). Once cancelled, each search will tune to the
   *    last tuned station and generate both FmRxEvSearchComplete and
   *    FmRxEvRadioTuneStatus events.
   *    Valid Values for argument 'mode':
   *    <ul>
   *    <li>{@link #FM_RX_SRCH_MODE_SEEK}
   *    <li>{@link #FM_RX_SRCH_MODE_SCAN}
   *    </ul>
   *    <p>
   *    Valid Values for argument 'dwellPeriod' :
   *    <ul>
   *    <li>{@link #FM_RX_DWELL_PERIOD_1S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_2S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_3S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_4S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_5S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_6S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_7S}
   *    </ul>
   *    <p>
   *    Valid Values for argument 'direction' :
   *    <ul>
   *    <li>{@link #FM_RX_SEARCHDIR_DOWN}
   *    <li>{@link #FM_RX_SEARCHDIR_UP}
   *    </ul>
   *    <p>
   *
   *    <p>
   *    @param mode the FM search mode.
   *    @param dwellPeriod the FM scan dwell time. Used only when
   *    mode={@link #FM_RX_SRCH_MODE_SCAN}
   *    @param direction the Search Direction.
   *   <p>
   *    @return true if Search Initiate succeeded, false if
   *            Search Initiate  failed.
   *
   *   @see #searchStations(int, int, int, int, int)
   *   @see #searchStationList
   */
   public boolean searchStations (int mode,
                                  int dwellPeriod,
                                  int direction){

      int state = getFMState();
      boolean bStatus = true;
      int re;

      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "searchStations: Device currently busy in executing another command.");
          return false;
      }

      Log.d (TAG, "Basic search...");

      /* Validate the arguments */
      if ( (mode != FM_RX_SRCH_MODE_SEEK) &&
           (mode != FM_RX_SRCH_MODE_SCAN))
      {
         Log.d (TAG, "Invalid search mode: " + mode );
         bStatus = false;
      }
      if ( (dwellPeriod < FM_RX_DWELL_PERIOD_0S ) ||
           (dwellPeriod > FM_RX_DWELL_PERIOD_7S))
      {
         Log.d (TAG, "Invalid dwelling time: " + dwellPeriod);
         bStatus = false;
      }
      if ( (direction != FM_RX_SEARCHDIR_DOWN) &&
           (direction != FM_RX_SEARCHDIR_UP))
      {
         Log.d (TAG, "Invalid search direction: " + direction);
         bStatus = false;
      }

      if (bStatus)
      {
         Log.d (TAG, "searchStations: mode " + mode + "direction:  " + direction);

         if (mode == FM_RX_SRCH_MODE_SEEK)
             setSearchState(subSrchLevel_SeekInPrg);
         else if (mode == FM_RX_SRCH_MODE_SCAN)
             setSearchState(subSrchLevel_ScanInProg);
         Log.v(TAG, "searchStations: CURRENT-STATE : FMRxOn ---> NEW-STATE : SearchInProg");

         re = mControl.searchStations(sFd, mode, dwellPeriod, direction, 0, 0);
         if (re != 0) {
             Log.e(TAG, "search station failed");
             if (getFMState() == FMState_Srch_InProg)
                 setSearchState(subSrchLevel_SrchComplete);
             return false;
         }
         state = getFMState();
         if (state == FMState_Turned_Off) {
             Log.d(TAG, "searchStations: CURRENT-STATE : FMState_Off (unexpected)");
             return false;
         }
      }
      return bStatus;
   }

   /*==============================================================
   FUNCTION:  searchStations
   ==============================================================*/
   /**
   *    Initiates RDS based seek and scan operations.
   *
   *    <p>
   *    This command allows the client to issue seeks and scans similar
   *    to commands found in basic searchStations(mode, scanTime,
   *    direction). However, each command has an additional RDS/RBDS
   *    component which must be satisfied before a station is
   *    successfully tuned. Please see searchStations(mode,
   *    scanTime, direction) for an understanding of how seeks and
   *    scans work.
   *
   *    <p>
   *    <ul>
   *    This API is used to search stations using RDS:
   *    <li> Invokes seek based on program type ({@link
   *    #FM_RX_SRCHRDS_MODE_SEEK_PTY})
   *    <li> Invokes scan based on program type with specified dwell period
   *    ({@link #FM_RX_SRCHRDS_MODE_SCAN_PTY})
   *    <li> Invokes seek based on program identification ({@link
   *    #FM_RX_SRCHRDS_MODE_SEEK_PI})
   *    <li> Invokes seek for alternate frequency ({@link
   *    #FM_RX_SRCHRDS_MODE_SEEK_AF})
   *    </ul>
   *
   *    <p>
   *    Much like {@link #FM_RX_SRCH_MODE_SEEK} in searchStations,
   *    {@link #FM_RX_SRCHRDS_MODE_SEEK_PTY} allows the client to
   *    seek to stations which are broadcasting RDS/RBDS groups
   *    with a particular Program Type that matches the supplied
   *    Program Type (PTY). The behavior and events generated for a
   *    {@link #FM_RX_SRCHRDS_MODE_SEEK_PTY} are very similar to
   *    that of {@link #FM_RX_SRCH_MODE_SEEK}, however only
   *    stations meeting the set search signal threshold and are
   *    also broadcasting the specified RDS Program Type (PTY) will
   *    be tuned. If no matching stations can be found, the
   *    original station will be re-tuned.
   *
   *    <p>
   *    Just as {@link #FM_RX_SRCHRDS_MODE_SEEK_PTY}'s
   *    functionality matches {@link #FM_RX_SRCH_MODE_SEEK}, so
   *    does {@link #FM_RX_SRCHRDS_MODE_SCAN_PTY} match {@link
   *    #FM_RX_SRCH_MODE_SCAN}. The one of the differences between
   *    the two is that only stations meeting the set search
   *    threshold and are also broadcasting a RDS Program Type
   *    (PTY) matching tucRdsSrchPty are found and tuned. If no
   *    station is found to have the PTY as specified by argument
   *    "pty", then the original station will be re-tuned.
   *
   *    <p> {@link #FM_RX_SRCHRDS_MODE_SEEK_PI} is used the same
   *    way as {@link #FM_RX_SRCHRDS_MODE_SEEK_PTY}, but only
   *    stations which meet the set search threshold and are also
   *    broadcasting the Program Identification matching the
   *    argument "pi" are tuned.
   *
   *    <p>
   *    Lastly, {@link #FM_RX_SRCHRDS_MODE_SEEK_AF} functionality
   *    differs slightly compared to the other commands in this
   *    function. This command only seeks to stations which are
   *    known ahead of time to be Alternative Frequencies for the
   *    currently tune station. If no alternate frequencies are
   *    known, or if the Alternative Frequencies have weaker signal
   *    strength than the original frequency, the original
   *    frequency will be re-tuned.
   *
   *    <p>
   *    Each time the driver initiates an RDS-based search, the client will be
   *    notified via a FmRxEvSearchInProgress event. Similarly, each
   *    time an RDS-based search completes, the client will be notified via a
   *    FmRxEvSearchComplete event.
   *
   *    <p>
   *    Once issuing a search command, several commands from the client may be
   *    disallowed until the search is completed or canceled.
   *
   *    <p>
   *    The search can be canceled at any time by using API
   *    cancelSearch (). Once canceled, each search will tune to the
   *    last tuned station and generate both
   *    FmRxEvSearchComplete and FmRxEvRadioTuneStatus events.
   *
   *    Valid Values for argument 'mode':
   *    <ul>
   *    <li>{@link #FM_RX_SRCHRDS_MODE_SEEK_PTY}
   *    <li>{@link #FM_RX_SRCHRDS_MODE_SCAN_PTY}
   *    <li>{@link #FM_RX_SRCHRDS_MODE_SEEK_PI}
   *    <li>{@link #FM_RX_SRCHRDS_MODE_SEEK_AF}
   *    </ul>
   *    <p>
   *    Valid Values for argument 'dwellPeriod' :
   *    <ul>
   *    <li>{@link #FM_RX_DWELL_PERIOD_1S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_2S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_3S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_4S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_5S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_6S}
   *    <li>{@link #FM_RX_DWELL_PERIOD_7S}
   *    </ul>
   *    <p>
   *    Valid Values for argument 'direction' :
   *    <ul>
   *    <li>{@link #FM_RX_SEARCHDIR_DOWN}
   *    <li>{@link #FM_RX_SEARCHDIR_UP}
   *    </ul>
   *    <p>
   *    @param mode the FM search mode.
   *    @param dwellPeriod the FM scan dwell time. Used only when
   *    mode={@link #FM_RX_SRCHRDS_MODE_SCAN_PTY}
   *    @param direction the Search Direction.
   *    @param pty the FM RDS search Program Type
   *    @param pi the FM RDS search Program Identification Code
   *    <p>
   *    @return true if Search Initiate succeeded, false if
   *            Search Initiate  failed.
   *
   *   @see #searchStations(int, int, int)
   *   @see #searchStationList
   */
   public boolean searchStations (int mode,
                                  int dwellPeriod,
                                  int direction,
                                  int pty,
                                  int pi) {
      boolean bStatus = true;
      int state = getFMState();
      int re;

      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "searchStations: Device currently busy in executing another command.");
          return false;
      }

      Log.d (TAG, "RDS search...");

      /* Validate the arguments */
      if ( (mode != FM_RX_SRCHRDS_MODE_SEEK_PTY)
           && (mode != FM_RX_SRCHRDS_MODE_SCAN_PTY)
           && (mode != FM_RX_SRCHRDS_MODE_SEEK_PI)
           && (mode != FM_RX_SRCHRDS_MODE_SEEK_AF)
         )
      {
         Log.d (TAG, "Invalid search mode: " + mode );
         bStatus = false;
      }
      if ( (dwellPeriod < FM_RX_DWELL_PERIOD_1S) ||
           (dwellPeriod > FM_RX_DWELL_PERIOD_7S))
      {
         Log.d (TAG, "Invalid dwelling time: " + dwellPeriod);
         bStatus = false;
      }
      if ( (direction != FM_RX_SEARCHDIR_DOWN) &&
           (direction != FM_RX_SEARCHDIR_UP))
      {
         Log.d (TAG, "Invalid search direction: " + direction);
         bStatus = false;
      }

      if (bStatus)
      {
         Log.d (TAG, "searchStations: mode " + mode);
         Log.d (TAG, "searchStations: dwellPeriod " + dwellPeriod);
         Log.d (TAG, "searchStations: direction " + direction);
         Log.d (TAG, "searchStations: pty " + pty);
         Log.d (TAG, "searchStations: pi " + pi);
         setSearchState(subSrchLevel_ScanInProg);
         re = mControl.searchStations(sFd, mode, dwellPeriod, direction, pty, pi);
         if (re != 0) {
             Log.e(TAG, "scan station failed");
             if (getFMState() == FMState_Srch_InProg)
                 setSearchState(subSrchLevel_SrchComplete);
             bStatus = false;
         }
      }
      return bStatus;
   }

   /*==============================================================
   FUNCTION:  searchStationList
   ==============================================================*/
   /** Initiates station list search operations.
   *    <p> This method will initate a search that will generate
   *    frequency lists based on strong and weak stations found in
   *    the FM band.
   *    <p>
   *    <ul>
   *    This API is used to generate station lists which consist of:
   *    <li>strong stations (FM_RX_SRCHLIST_MODE_STRONG,FM_RX_SRCHLIST_MODE_STRONGEST)
   *    <li>weak stations   (FM_RX_SRCHLIST_MODE_WEAK, FM_RX_SRCHLIST_MODE_WEAKEST)
   *    </ul>
   *    <p>
   *    The range of frequencies scanned depends on the currently set band.
   *    The driver searches for all valid stations in the band and when complete,
   *    returns a channel list based on the client's selection. The client can
   *    choose to search for a list of the strongest stations in the band, the
   *    weakest stations in the band, or the first N strong or weak
   *    stations. By setting the maximumStations argument, the
   *    client can constrain the number of frequencies returned in
   *    the list. If user specifies argument maximumStations to be
   *    0, the search will generate the maximum number of stations
   *    possible.
   *    <p>
   *    Each time the driver initiates a list-based search, the client will be
   *    notified via an FmRxEvSearchInProgress event. Similarly, each
   *    time a list-based search completes, the client will be
   *    notified via an FmRxEvSearchListComplete event.
   *    <p>
   *    On completion of the search, the originally tuned station
   *    will be tuned and the following events will be generated:
   *    FmRxEvSearchListComplete - The search has completed.
   *    FmRxEvRadioTuneStatus - The original frequency has been
   *    re-tuned.
   *    <p>
   *    Once issuing a search command, several commands from the client may be
   *    disallowed until the search is completed or cancelled.
   *    <p>
   *    The search can be canceled at any time by using API
   *    cancelSearch (). A cancelled search is treated as a completed
   *    search and the following events will be generated:
   *    FmRxEvSearchComplete  - The search has completed.
   *    FmRxEvRadioTuneStatus - The original frequency has been re-tuned.
   *    <p>
   *    Valid Values for argument 'mode':
   *    <ul>
   *    <li>{@link #FM_RX_SRCHLIST_MODE_STRONG}
   *    <li>{@link #FM_RX_SRCHLIST_MODE_WEAK}
   *    <li>{@link #FM_RX_SRCHLIST_MODE_STRONGEST}
   *    <li>{@link #FM_RX_SRCHLIST_MODE_WEAKEST}
   *    <li>FM_RX_SRCHLIST_MODE_PTY (Will be implemented in the
   *    future)
   *    </ul>
   *    <p>
   *    Valid Values for argument 'direction' :
   *    <ul>
   *    <li>{@link #FM_RX_SEARCHDIR_DOWN}
   *    <li>{@link #FM_RX_SEARCHDIR_UP}
   *    </ul>
   *    <p>
   *    Valid Values for argument 'maximumStations' : 1-12
   *    <p>
   *    @param mode the FM search mode.
   *    @param direction the Search Direction.
   *    @param maximumStations the maximum number of stations that
   *                           can be returned from a search. This parameter is
   *                           ignored and 12 stations are returned if the
   *                           search mode is either FM_RX_SRCHLIST_MODE_STRONGEST or
   *                           FM_RX_SRCHLIST_MODE_WEAKEST
   *
   *    @param pty the FM RDS search Program Type (Not used
   *               currently)
   *   <p>
   *    @return true if Search Initiate succeeded, false if
   *            Search Initiate  failed.
   *
   *   @see #searchStations(int, int, int)
   *   @see #searchStations(int, int, int, int, int)
   */
   public boolean searchStationList (int mode,
                                     int direction,
                                     int maximumStations,
                                     int pty){

      int state = getFMState();
      boolean bStatus = true;
      int re = 0;

      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "searchStationList: Device currently busy in executing another command.");
          return false;
      }

      Log.d (TAG, "searchStations: mode " + mode);
      Log.d (TAG, "searchStations: direction " + direction);
      Log.d (TAG, "searchStations: maximumStations " + maximumStations);
      Log.d (TAG, "searchStations: pty " + pty);

      /* Validate the arguments */
      if ( (mode != FM_RX_SRCHLIST_MODE_STRONG)
           && (mode != FM_RX_SRCHLIST_MODE_WEAK )
           && (mode != FM_RX_SRCHLIST_MODE_STRONGEST )
           && (mode != FM_RX_SRCHLIST_MODE_WEAKEST )
         )
      {
         bStatus = false;
      }
      if ( (maximumStations < 0) ||
           (maximumStations > FM_RX_SRCHLIST_MAX_STATIONS))
      {
         bStatus = false;
      }
      if ( (direction != FM_RX_SEARCHDIR_DOWN) &&
           (direction != FM_RX_SEARCHDIR_UP))
      {
         bStatus = false;
      }

      if (bStatus)
      {
         setSearchState(subSrchLevel_SrchListInProg);
         Log.v(TAG, "searchStationList: CURRENT-STATE : FMRxOn ---> NEW-STATE : SearchInProg");
         if ((mode == FM_RX_SRCHLIST_MODE_STRONGEST) || (mode == FM_RX_SRCHLIST_MODE_WEAKEST)) {
             mode = (mode == FM_RX_SRCHLIST_MODE_STRONGEST)?
                               FM_RX_SRCHLIST_MODE_STRONG: FM_RX_SRCHLIST_MODE_WEAK;
            re = mControl.searchStationList(sFd, mode, 0, direction, pty);
         }
         else
            re = mControl.searchStationList(sFd, mode, maximumStations, direction, pty);

         if (re != 0) {
             Log.e(TAG, "search station list failed");
             if (getFMState() == FMState_Srch_InProg)
                 setSearchState(subSrchLevel_SrchComplete);
             bStatus =  false;
         }
      }

      return bStatus;
   }



   /*==============================================================
   FUNCTION:  cancelSearch
   ==============================================================*/
   /**
   *  Cancels an ongoing search operation
   *  (seek, scan, searchlist, etc).
   * <p>
   * This method should be used to cancel a previously initiated
   * search (e.g. Basic Seek/Scan, RDS Seek/Scans, Search list,
   * etc...).
   * <p>
   * Once completed, this command will generate an
   * FmRxEvSearchCancelledtr event to all registered clients.
   * Following this event, the client may also receive search events related
   * to the ongoing search now being complete.
   *
   *   <p>
   *    @return true if Cancel Search initiate succeeded, false if
   *            Cancel Search initiate failed.
   *   @see #searchStations(int, int, int)
   *   @see #searchStations(int, int, int)
   *   @see #searchStationList
   */
   public boolean cancelSearch () {
      boolean status = false;
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Srch_InProg) {
         Log.v(TAG, "cancelSearch: Cancelling the on going search operation");
         setSearchState(subSrchLevel_SrchAbort);
         mControl.cancelSearch(sFd);
         return true;
      } else
         Log.d(TAG, "cancelSearch: No on going search operation to cancel");
      return status;
   }

   /*==============================================================
   FUNCTION:  setMuteMode
   ==============================================================*/
   /**
   *    Allows the muting and un-muting of the audio coming
   *    from the FM receiver.
   *    <p>
   *    This is a synchronous command used to mute or un-mute the
   *    FM audio. This command mutes the audio coming from the FM
   *    device. It is important to note that this only affects the
   *    FM audio and not any other audio system being used.
   *    <p>
   *    @param mode the mute Mode setting to apply
   *    <p>
   *    @return true if setMuteMode call was placed successfully,
   *           false if setMuteMode failed.
   *
   *    @see #enable
   *    @see #registerClient
   *
   */
   public boolean setMuteMode (int mode) {
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "setMuteMode: Device currently busy in executing another command.");
          return false;
      }
      switch (mode)
      {
      case FM_RX_UNMUTE:
         mControl.muteControl(sFd, false);
         break;
      case FM_RX_MUTE:
         mControl.muteControl(sFd, true);
         break;
      default:
         break;
      }

      return true;

   }

   /*==============================================================
   FUNCTION:  setStereoMode
   ==============================================================*/
   /**
   *    Sets the mono/stereo mode of the FM device.
   *
   *    <p>
   *    This command allows the user to set the mono/stereo mode
   *    of the FM device. Using this function,
   *    the user can allow mono/stereo mixing or force the reception
   *    of mono audio only.
   *
   *    @param stereoEnable true: Enable Stereo, false: Force Mono
   *
   *   @return true if setStereoMode call was placed successfully,
   *           false if setStereoMode failed.
   */
   public boolean setStereoMode (boolean stereoEnable) {
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "setStereoMode: Device currently busy in executing another command.");
          return false;
      }
      int re = mControl.stereoControl(sFd, stereoEnable);

      if (re == 0)
        return true;
      return false;
   }

   /*==============================================================
   FUNCTION:  setSignalThreshold
   ==============================================================*/
   /**
   *    This function sets the threshold which the FM driver
   *    uses to determine which stations have service available.
   *
   *    <p>
   *    This information is used to determine which stations are
   *    tuned during searches and Alternative Frequency jumps, as
   *    well as at what threshold FmRxEvServiceAvailable event
   *    callback are generated.
   *    <p>
   *    This is a command used to set the threshold used by the FM driver
   *    and/or hardware to determine which stations are "good" stations.
   *    Using this function, the client can allow very weak stations,
   *    relatively weak stations, relatively strong stations, or very.
   *    strong stations to be found during searches. Additionally,
   *    this threshold will be used to determine at what threshold a
   *    FmRxEvServiceAvailable event callback is generated.
   *    <p>
   *    @param threshold the new signal threshold.
   *    @return true if setSignalThreshold call was placed
   *           successfully, false if setSignalThreshold failed.
   */
   public boolean setSignalThreshold (int threshold) {

      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "setSignalThreshold: Device currently busy in executing another command.");
          return false;
      }
      boolean bStatus = true;
      int re;
      Log.d(TAG, "Signal Threshhold input: "+threshold );
      int rssiLev = 0;

      switch(threshold)
      {
      case FM_RX_SIGNAL_STRENGTH_VERY_WEAK:
         rssiLev = FM_RX_RSSI_LEVEL_VERY_WEAK;
         break;
      case FM_RX_SIGNAL_STRENGTH_WEAK:
         rssiLev = FM_RX_RSSI_LEVEL_WEAK;
         break;
      case FM_RX_SIGNAL_STRENGTH_STRONG:
         rssiLev = FM_RX_RSSI_LEVEL_STRONG;
         break;
      case FM_RX_SIGNAL_STRENGTH_VERY_STRONG:
         rssiLev = FM_RX_RSSI_LEVEL_VERY_STRONG;
         break;
      default:
         /* Should never reach here */
         bStatus = false;
         Log.d (TAG, "Invalid threshold: " + threshold );
         return bStatus;
      }

      if (bStatus) {
        re=FmReceiverJNI.setControlNative (sFd, V4L2_CID_PRIVATE_TAVARUA_SIGNAL_TH, rssiLev);

        if (re !=0)
          bStatus = false;
      }

      return bStatus;
   }

   /*==============================================================
   FUNCTION:  getStationParameters
   ==============================================================*
   /**
   *     Returns various Paramaters related to the currently
   *    tuned station.
   *
   *    <p>
   *    This is method retreives various parameters and statistics
   *    related to the currently tuned station. Included in these
   *    statistics are the currently tuned frequency, the RDS/RBDS
   *    sync status, the RSSI level, current mute settings and the
   *    stereo/mono status.
   *
   *    <p>
   *    Once completed, this command will generate an asynchronous
   *    FmRxEvStationParameters event to the registered client.
   *    This event will contain the station parameters.
   *
   *    <p>
   *    @return      FmStationParameters: Object that contains
   *                    all the station parameters
   public FmStationParameters getStationParameters () {
      return mStationParameters;
   }

   */

   /*==============================================================
   FUNCTION:  getTunedFrequency
   ==============================================================*/
   /**
   *    Get the Frequency of the Tuned Station
   *
   *    @return frequencyKHz: Tuned Station Frequency (in kHz)
   *                          (Example: 96500 = 96.5Mhz)
   *            ERROR       : If device is currently executing another command
   */
   public int getTunedFrequency () {

      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "getTunedFrequency: Device currently busy in executing another command.");
          return ERROR;
      }

      int frequency = FmReceiverJNI.getFreqNative(sFd);

      Log.d(TAG, "getFrequency: "+frequency);

      return frequency;
   }

   /*==============================================================
   FUNCTION:  getPSInfo
   ==============================================================*/
   /**
   *    Returns the current RDS/RBDS Program Service
   *            Information.
   *    <p>
   *    This is a command which returns the last complete RDS/RBDS
   *    Program Service information for the currently tuned station.
   *    To use this command, the client must first register for
   *    Program Service info by receiving either the
   *    FM_RX_RDS_GRP_PS_EBL or FM_RX_RDS_GRP_PS_SIMPLE_EBL event.
   *    Under normal operating mode, this information will
   *    automatically be sent to the client. However, if the client
   *    requires this information be sent again, this function can be
   *    used.
   *
   *    Typicaly this method needs to be called when "FmRxEvRdsPsInfo"
   *    callback is invoked.
   *
   *    <p>
   *    @return  the RDS data including the Program Service
   *             Information
   *
   */
   public FmRxRdsData  getPSInfo() {

      byte [] buff = new byte[STD_BUF_SIZE];
      int piLower = 0;
      int piHigher = 0;

      FmReceiverJNI.getBufferNative(sFd, buff, 3);
      /* byte is signed ;(
      *  knock down signed bits
      */
      piLower = buff[3] & 0xFF;
      piHigher = buff[2] & 0xFF;
      int pi = ((piHigher << 8) | piLower);
      mRdsData.setPrgmId (pi);
      mRdsData.setPrgmType ( (int)( buff[1] & 0x1F));
      int numOfPs = (int)(buff[0] & 0x0F);
      try
      {

	 String rdsStr = new String(buff, 5, numOfPs*8 );
         mRdsData.setPrgmServices (rdsStr);

      } catch (StringIndexOutOfBoundsException x)
      {
         Log.d (TAG, "Number of PS names " + numOfPs);
      }
      return mRdsData;
   }

   /*==============================================================
   FUNCTION:  getRTInfo
   ==============================================================*/
   /**
   *    Returns the current RDS/RBDS RadioText Information.
   *
   *    <p>
   *    This is a command which returns the last complete RadioText information
   *    for the currently tuned station. For this command to return meaningful
   *    information, the client must first register for RadioText events by registerring
   *    the FM_RX_RDS_GRP_RT_EBL callback function. Under normal operating mode, this information
   *    will automatically be sent to the client. However, if the client requires
   *    this information be sent again, this function can be used.
   *
   *    <p>
   *    Typicaly this method needs to be called when
   *    "FmRxEvRdsRtInfo" callback is invoked.
   *
   *    <p>
   *    @return  the RDS data including the Radio Text Information
   */
   public FmRxRdsData getRTInfo () {

      byte [] buff = new byte[STD_BUF_SIZE];
      int piLower = 0;
      int piHigher = 0;

      FmReceiverJNI.getBufferNative(sFd, buff, 2);
      String rdsStr = new String(buff);
      /* byte is signed ;(
      *  knock down signed bit
      */
      piLower = buff[3] & 0xFF;
      piHigher = buff[2] & 0xFF;
      int pi = ((piHigher << 8) | piLower);
      mRdsData.setPrgmId (pi);
      mRdsData.setPrgmType ( (int)( buff[1] & 0x1F));
      try
      {
         rdsStr = rdsStr.substring(5, (int) buff[0]+ 5);
         mRdsData.setRadioText (rdsStr);

      } catch (StringIndexOutOfBoundsException x)
      {
         Log.d (TAG, "StringIndexOutOfBoundsException ...");
      }
      return mRdsData;
   }

   public FmRxRdsData getRTPlusInfo() {
      byte []rt_plus = new byte[STD_BUF_SIZE];
      int bytes_read;
      String rt = "";
      int rt_len;
      int i, count, avail_tag_num = 0;
      byte tag_code, tag_len, tag_start_pos;

      bytes_read = FmReceiverJNI.getBufferNative(sFd, rt_plus, BUF_RTPLUS);
      if (bytes_read > 0) {
          if (rt_plus[RT_OR_ERT_IND] == 0)
              rt = mRdsData.getRadioText();
          else
              rt = mRdsData.getERadioText();
          if ((rt != "") && (rt != null)) {
              rt_len = rt.length();
              mRdsData.setTagNums(0);
              avail_tag_num = (rt_plus[LEN_IND] - 2)/3;
              if (avail_tag_num > 2) {
                avail_tag_num = 2;
              }
              count = 1;
              for (i = 0; i < avail_tag_num; i++) {
                  tag_code = rt_plus[2+3*i];
                  tag_start_pos = rt_plus[3+3*i];
                  tag_len = rt_plus[4+3*i];
                  if (((tag_len + tag_start_pos) <= rt_len) && (tag_code > 0)) {
                      mRdsData.setTagValue(rt.substring(tag_start_pos,
                                            (tag_len + tag_start_pos)), count);
                      mRdsData.setTagCode(tag_code, count);
                      count++;
                  }
              }
          } else {
              mRdsData.setTagNums(0);
          }
      } else {
              mRdsData.setTagNums(0);
      }
      return mRdsData;
   }

   public FmRxRdsData getERTInfo() {
      byte [] raw_ert = new byte[STD_BUF_SIZE];
      byte [] ert_text;
      int i;
      String s = "";
      String encoding_type = "UCS-2";
      int bytes_read;

      bytes_read = FmReceiverJNI.getBufferNative(sFd, raw_ert, BUF_ERT);
      if (bytes_read > 0) {
          ert_text = new byte[raw_ert[LEN_IND]];
          for(i = 3; (i - 3) < raw_ert[LEN_IND]; i++) {
              ert_text[i - 3] = raw_ert[i];
          }
          if (raw_ert[ENCODE_TYPE_IND] == 1)
              encoding_type = "UTF-8";
          try {
               s = new String (ert_text, encoding_type);
          } catch (Exception e) {
               e.printStackTrace();
          }
          mRdsData.setERadioText(s);
          if (raw_ert[ERT_DIR_IND] == 0)
              mRdsData.setFormatDir(false);
          else
              mRdsData.setFormatDir(true);
          Log.d(TAG, "eRT: " + s + "dir: " +raw_ert[ERT_DIR_IND]);
      }
      return mRdsData;
   }

   public boolean IsSmdTransportLayer() {
       String transportLayer = SystemProperties.get("ro.qualcomm.bt.hci_transport");
       if (transportLayer.equals("smd"))
           return true;
       else
           return false;
   }

   public boolean IsRomeChip() {
       String chip = SystemProperties.get("qcom.bluetooth.soc");
       if (chip.equals("rome"))
           return true;
       else
           return false;
   }
   /*==============================================================
   FUNCTION:  getAFInfo
   ==============================================================*/
   /**
   *   Returns the current RDS/RBDS Alternative Frequency
   *          Information.
   *
   *    <p>
   *    This is a command which returns the last known Alternative Frequency
   *    information for the currently tuned station. For this command to return
   *    meaningful information, the client must first register for Alternative
   *    Frequency events by registering an FM_RX_RDS_GRP_AF_EBL call back function.
   *    Under normal operating mode, this information will automatically be
   *    sent to the client. However, if the client requires this information
   *    be sent again, this function can be used.
   *
   *    <p>
   *    Typicaly this method needs to be called when
   *    "FmRxEvRdsAfInfo" callback is invoked.
   *
   *    @return  the RDS data including the AF Information
   */
   public int[] getAFInfo() {

      byte [] buff = new byte[STD_BUF_SIZE];
      int  [] AfList = new int [50];
      int lowerBand, i;
      int tunedFreq, PI, size_AFLIST;

      FmReceiverJNI.getBufferNative(sFd, buff, TAVARUA_BUF_AF_LIST);

      if (IsSmdTransportLayer() || IsRomeChip()) {
          Log.d(TAG, "SMD transport layer or Rome chip");

          tunedFreq = (buff[0] & 0xFF) |
                      ((buff[1] & 0xFF) << 8) |
                      ((buff[2] & 0xFF) << 16) |
                      ((buff[3] & 0xFF) << 24) ;
          Log.d(TAG, "tunedFreq = " +tunedFreq);

          PI = (buff[4] & 0xFF) |
               ((buff[5] & 0xFF) << 8);
          Log.d(TAG, "PI: " + PI);

          size_AFLIST = buff[6] & 0xFF;
          Log.d(TAG, "size_AFLIST : " +size_AFLIST);

          for (i = 0;i < size_AFLIST;i++) {
                AfList[i] = (buff[6 + i * 4 + 1] & 0xFF) |
                           ((buff[6 + i * 4 + 2] & 0xFF) << 8) |
                           ((buff[6 + i * 4 + 3] & 0xFF) << 16) |
                           ((buff[6 + i * 4 + 4] & 0xFF) << 24) ;
                Log.d(TAG, "AF: " + AfList[i]);
          }
      } else {

          if ((buff[4] <= 0) || (buff[4] > 25))
              return null;

          lowerBand = FmReceiverJNI.getLowerBandNative(sFd);
          Log.d (TAG, "Low band " + lowerBand);

          Log.d (TAG, "AF_buff 0: " + (buff[0] & 0xff));
          Log.d (TAG, "AF_buff 1: " + (buff[1] & 0xff));
          Log.d (TAG, "AF_buff 2: " + (buff[2] & 0xff));
          Log.d (TAG, "AF_buff 3: " + (buff[3] & 0xff));
          Log.d (TAG, "AF_buff 4: " + (buff[4] & 0xff));

          for (i=0; i<buff[4]; i++) {
               AfList[i] = ((buff[i+4] & 0xFF) * 1000) + lowerBand;
               Log.d (TAG, "AF : " + AfList[i]);
          }
      }

      return AfList;

   }

   /*==============================================================
   FUNCTION:  setPowerMode
   ==============================================================*/
   /**
   *    Puts the driver into or out of low power mode.
   *
   *    <p>
   *    This is an synchronous command which can put the FM
   *    device and driver into and out of low power mode. Low power mode
   *    should be used when the receiver is tuned to a station and only
   *    the FM audio is required. The typical scenario for low power mode
   *    is when the FM application is no longer visible.
   *
   *    <p>
   *    While in low power mode, all normal FM and RDS indications from
   *    the FM driver will be suppressed. By disabling these indications,
   *    low power mode can result in fewer interruptions and this may lead
   *    to a power savings.
   *
   *    <p>
   *    @param powerMode the new driver operating mode.
   *
   *    @return true if setPowerMode succeeded, false if
   *            setPowerMode failed.
   */
   public boolean setPowerMode(int powerMode){

      int re;

      if (powerMode == FM_RX_LOW_POWER_MODE) {
        re = mControl.setLowPwrMode (sFd, true);
      }
      else {
        re = mControl.setLowPwrMode (sFd, false);
      }

      if (re == 0)
         return true;
      return false;
   }

   /*==============================================================
  FUNCTION:  getPowerMode
  ==============================================================*/
   /**
   *    Get FM device low power mode.
   *    <p>
   *    This is an synchronous method that will read the power mode
   *    of the FM device and driver.
   *    <p>
   *       @return true if the FM Device is in Low power mode and
   *               false if the FM Device in Normal power mode.
   *
   *    @see #setPowerMode
   */
   public int getPowerMode(){

      return  mControl.getPwrMode (sFd);

   }

   /*==============================================================
   FUNCTION:  getRssiLimit
   ==============================================================*/
   /**
   *    Returns the RSSI thresholds for the FM driver.
   *
   *    <p>
   *    This method returns the RSSI thresholds for the FM driver.
   *    This function returns a structure containing the minimum RSSI needed
   *    for reception and the minimum RSSI value where reception is perfect.
   *    The minimum RSSI value for reception is the recommended threshold where
   *    an average user would consider the station listenable. Similarly,
   *    the minimum RSSI threshold for perfect reception is the point where
   *    reception quality will improve only marginally even if the RSSI level
   *    improves greatly.
   *
   *    <p>
   *    These settings should only be used as a guide for describing
   *    the RSSI values returned by the FM driver. Used in conjunction
   *    with getRssiInfo, the client can use the values from this
   *    function to give meaning to the RSSI levels returned by the driver.
   *
   *    <p>
   *       @return the RSSI level
   */
   public int[] getRssiLimit () {

      int[] rssiLimits = {0, 100};

      return rssiLimits;
   }

   /*==============================================================
   FUNCTION:  getSignalThreshold
   ==============================================================*/
   /**
   *   This function returns:
   *          currently set signal threshold - if API invocation
   *                                           is successful
   *          ERROR                          - if device is currently
   *                                           executing another command
   *    <p>
   *    This value used by the FM driver/hardware to determine which
   *    stations are tuned during searches and Alternative Frequency jumps.
   *    Additionally, this level is used to determine at what
   *    threshold FmRxEvServiceAvailable are generated.
   *
   *    <p>
   *    This is a command used to return the currently set signal
   *    threshold used by the FM driver and/or hardware. This
   *    value is used to determine. which stations are tuned
   *    during searches and Alternative Frequency jumps as well as
   *    when Service available events are generated.
   *
   *    <p>
   *    Once completed, this command will generate an asynchronous
   *    FmRxEvGetSignalThreshold event to the registered client.
   *    This event will contain the current signal threshold
   *    level.
   *
   *    <p>
   *    @return the signal threshold
   */
   public int getSignalThreshold () {
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "getSignalThreshold: Device currently busy in executing another command.");
          return ERROR;
      }
     int threshold = FM_RX_SIGNAL_STRENGTH_VERY_WEAK, signalStrength;
     int rmssiThreshold = FmReceiverJNI.getControlNative (sFd, V4L2_CID_PRIVATE_TAVARUA_SIGNAL_TH);
     Log.d(TAG, "Signal Threshhold: "+rmssiThreshold );

     if ( (FM_RX_RSSI_LEVEL_VERY_WEAK < rmssiThreshold) && (rmssiThreshold <= FM_RX_RSSI_LEVEL_WEAK) )
     {
       signalStrength = FM_RX_RSSI_LEVEL_WEAK;
     }
     else if ( (FM_RX_RSSI_LEVEL_WEAK < rmssiThreshold) && (rmssiThreshold  <= FM_RX_RSSI_LEVEL_STRONG))
     {
       signalStrength = FM_RX_RSSI_LEVEL_STRONG;
     }
     else if ((FM_RX_RSSI_LEVEL_STRONG < rmssiThreshold))
     {
       signalStrength = FM_RX_RSSI_LEVEL_VERY_STRONG;
     }
     else
     {
       signalStrength = FM_RX_RSSI_LEVEL_VERY_WEAK;
     }

     switch(signalStrength)
     {
     case FM_RX_RSSI_LEVEL_VERY_WEAK:
        threshold = FM_RX_SIGNAL_STRENGTH_VERY_WEAK;
        break;
     case FM_RX_RSSI_LEVEL_WEAK:
        threshold = FM_RX_SIGNAL_STRENGTH_WEAK;
        break;
     case FM_RX_RSSI_LEVEL_STRONG:
        threshold = FM_RX_SIGNAL_STRENGTH_STRONG;
        break;
     case FM_RX_RSSI_LEVEL_VERY_STRONG:
        threshold = FM_RX_SIGNAL_STRENGTH_VERY_STRONG;
        break;
     default:
        /* Should never reach here */
        break;
     }

     return threshold;
   }

   public int getAFJumpRmssiTh() {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getAFJumpThreshold: Device currently busy in executing another command.");
          return ERROR;
      }
      return mControl.getAFJumpRmssiTh(sFd);
   }

   public boolean setAFJumpRmssiTh(int th) {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setAFJumpThreshold: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setAFJumpRmssiTh(sFd, th);
   }

   public int getAFJumpRmssiSamples() {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getAFJumpRmssiSamples: Device currently busy in executing another command.");
          return ERROR;
      }
      return mControl.getAFJumpRmssiSamples(sFd);
   }

   public boolean setAFJumpRmssiSamples(int samples) {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setAFJumpRmssiSamples: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setAFJumpRmssiSamples(sFd, samples);
   }

   public int getGdChRmssiTh() {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getGdChRmssiTh: Device currently busy in executing another command.");
          return ERROR;
      }
      return mControl.getGdChRmssiTh(sFd);
   }

   public boolean setGdChRmssiTh(int th) {
      int state = getFMState();
      /* Check current state of FM device */
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setGdChRmssiTh: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setGdChRmssiTh(sFd, th);
   }

   public int getSearchAlgoType() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getSearchAlgoType: Device currently busy in executing another command.");
          return Integer.MAX_VALUE;
      }
      return mControl.getSearchAlgoType(sFd);
   }

   public boolean setSearchAlgoType(int searchType) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setSearchAlgoType: Device currently busy in executing another command.");
          return false;
      }
      if((searchType != SEARCH_MPXDCC) && (searchType != SEARCH_SINR_INT)) {
          Log.d(TAG, "Search Algo is invalid");
          return false;
      }else {
          return mControl.setSearchAlgoType(sFd, searchType);
      }
   }

   public int getSinrFirstStage() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getSinrFirstStage: Device currently busy in executing another command.");
          return Integer.MAX_VALUE;
      }
      return mControl.getSinrFirstStage(sFd);
   }

   public boolean setSinrFirstStage(int sinr) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setSinrFirstStage: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setSinrFirstStage(sFd, sinr);
   }

   public int getRmssiFirstStage() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getRmssiFirstStage: Device currently busy in executing another command.");
          return Integer.MAX_VALUE;
      }
      return mControl.getRmssiFirstStage(sFd);
   }

   public boolean setRmssiFirstStage(int rmssi) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setRmssiFirstStage: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setRmssiFirstStage(sFd, rmssi);
   }

   public int getCFOMeanTh() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getCF0Th12: Device currently busy in executing another command.");
          return Integer.MAX_VALUE;
      }
      return mControl.getCFOMeanTh(sFd);
   }

   public boolean setCFOMeanTh(int th) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setRmssiFirstStage: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setCFOMeanTh(sFd, th);
   }

   public boolean setPSRxRepeatCount(int count) {
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off){
          Log.d(TAG, "setRxRepeatcount failed");
          return false;
      }
      return mControl.setPSRxRepeatCount(sFd, count);
   }

   public byte getBlendSinr() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getBlendSinr: Device currently busy in executing another command.");
          return Byte.MAX_VALUE;
      }
      return mControl.getBlendSinr(sFd);
   }

   public boolean setBlendSinr(byte sinrHi) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setBlendSinr: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setBlendSinr(sFd, sinrHi);
   }

   public byte getBlendRmssi() {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "getBlendRmssi: Device currently busy in executing another command.");
          return Byte.MAX_VALUE;
      }
      return mControl.getBlendRmssi(sFd);
   }

   public boolean setBlendRmssi(byte rmssiHi) {
      int state = getFMState();
      if ((state == FMState_Turned_Off) || (state == FMState_Srch_InProg)) {
          Log.d(TAG, "setBlendRmssi: Device currently busy in executing another command.");
          return false;
      }
      return mControl.setBlendRmssi(sFd, rmssiHi);
   }

   /*==============================================================
   FUNCTION:  setRdsGroupOptions
   ==============================================================*/
   /**
   *
   *    This function enables or disables various RDS/RBDS
   *    group filtering and buffering features.
   *
   *    <p>
   *    Included in these features are the RDS group enable mask, RDS/RBDS group
   *    change filter, and the RDS/RBDS group buffer size.
   *    <p>
   *    This is a function used to set or unset various Rx RDS/RBDS group filtering
   *    and buffering options in the FM driver.
   *    <p>
   *    Included in these options is the ability for the client to select
   *    which RDS/RBDS groups should be sent to the client. By default, all
   *    RDS/RBDS groups are filtered out before reaching the client. To allow one
   *    or more specific groups to be received, the client must set one or mors bits
   *    within the argument enRdsGrpsMask bitmask. Each bit in this
   *    mask corresponds to a specific RDS/RBDS group type. Once a
   *    group is enabled, and when a buffer holding those groups
   *    reaches the threshold defined by argument rdsBuffSize, the
   *    group or groups will be sent to the client as a
   *    FmRxEvRdsGroupData callback.
   *
   *    <p>
   *    Additionally, this function also allows the client to enable or
   *    disable the RDS/RBDS group change filter. This filter allows the client
   *    to prevent duplicate groups of the same group type from being received.
   *    This filter only applies to consecutive groups, so
   *    identical groups received in different order will not be
   *    filtered out.
   *
   *    <p>
   *    @param enRdsGrpsMask the bitMask that enables the RT/PS/AF.
   *
   *    @param rdsBuffSize the number of RDS/RBDS groups the FM
   *                        driver should buffer  before sending to
   *                        the client.
   *
   *    @param enRdsChangeFilter the Flag used to determine whether
   *                              the RDS/RBDS change filter
   *                              should be enabled.
   *
   *    @return true if the command was placed successfully, false
   *            if command failed.
   *
   */
   public boolean setRdsGroupOptions (int enRdsGrpsMask,
                                      int rdsBuffSize,
                                      boolean enRdsChangeFilter)
   {

      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "setRdsGroupOptions: Device currently busy in executing another command.");
          return false;
      }
      // Enable RDS
      int re = mRdsData.rdsOn(true);

      if (re != 0)
        return false;

      re = mRdsData.rdsGrpOptions (enRdsGrpsMask, rdsBuffSize, enRdsChangeFilter);

      if (re ==0)
        return true;

      return false;

   }

   public boolean setRawRdsGrpMask()
   {
      return super.setRDSGrpMask(GRP_3A);
   }
   /*==============================================================
   FUNCTION:  registerRdsGroupProcessing
   ==============================================================*/
   /**
   *
   *    This function enables or disables RDS/RBDS group processing features.
   *
   *    <p>
   *    Included in these features is the ability for the FM driver
   *    to return Program Service, RadioText, and Alternative
   *    Frequency information.
   *
   *    <p>
   *    These options free the client from the burden of collecting a continuous
   *    stream of RDS/RBDS groups and processing them. By setting the
   *    FM_RX_RDS_GRP_RT_EBL bit in argument fmGrpsToProc, the FM
   *    hardware or driver will collect RDS/RBDS 2A/2B groups and
   *    return complete RadioText strings and information in the
   *    form of a FmRxEvRdsRtInfo event. This event will be
   *    generated only when the RadioText information changes.
   *
   *    <p>
   *    Similarly, by setting either the FM_RX_RDS_GRP_PS_EBL or
   *    FM_RX_RDS_GRP_PS_SIMPLE_EBL bit in argument fmGrpsToProc,
   *    the FM hardware or driver will collect RDS/RBDS 0A/0B
   *    groups and return Program Service information in the form
   *    of a FmRxEvRdsPsInfo event. This event will be generated
   *    whenever the Program Service information changes. This
   *    event will include one or more collected Program Service
   *    strings which can be continuously displayed by the client.
   *
   *    <p>
   *    Additionally, by setting the FM_RX_RDS_GRP_AF_EBL bit in
   *    argument FmGrpsToProc, the FM hardware or driver will
   *    collect RDS/RBDS 0A/0B groups and return Alternative
   *    Frequency information in the form of a FmRxEvRdsAfInfo
   *    event. This event will be generated when the Alternative
   *    Frequency information changes and will include an up to
   *    date list of all known Alternative Frequencies.
   *
   *    <p>
   *    Lastly, by setting the FM_RX_RDS_GRP_AF_JUMP_EBL bit in
   *    argument FmGrpsToProc, the FM hardware or driver will
   *    collect RDS/RBDS 0A/0B groups and automatically tune to a
   *    stronger alternative frequency when the signal level falls
   *    below the search threshold.
   *
   *    @param fmGrpsToProc the bitMask that enables the RT/PS/AF.
   *
   *    @return true if the command was placed successfully, false
   *            if command failed.
   *
   */
   public boolean registerRdsGroupProcessing (int fmGrpsToProc){

      if (mRdsData == null)
         return false;

      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "registerRdsGroupProcessing: Device currently busy in executing another command.");
          return false;
      }

      // Enable RDS
      int re = mRdsData.rdsOn(true);

      if (re != 0)
        return false;

      re = mRdsData.rdsOptions (fmGrpsToProc);

      if (re ==0)
        return true;

      return false;
   }


   /*==============================================================
   FUNCTION:  enableAFjump
   ==============================================================*/
   /**
   *    Enables automatic jump to alternative frequency
   *
   *    <p>
   *    This method enables automatic seeking to stations which are
   *    known ahead of time to be Alternative Frequencies for the
   *    currently tuned station. If no alternate frequencies are
   *    known, or if the Alternative Frequencies have weaker signal
   *    strength than the original frequency, the original frequency
   *    will be re-tuned.
   *
   *    <p>
   *    @return     true if successful false otherwise.
   */
   public boolean enableAFjump (boolean enable) {

      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "enableAFjump: Device currently busy in executing another command.");
          return false;
      }
      // Enable RDS
      int re = mRdsData.rdsOn(true);

      if (re != 0)
        return false;

      re = mRdsData.enableAFjump(enable);

      if (re == 0)
        return true;

      return false;
   }

   /*==============================================================
   FUNCTION:  getStationList
   ==============================================================*/
   /**
   *    Returns a frequency List of the searched stations.
   *
   *    <p>
   *    This method retreives the results of the {@link
   *    #searchStationList}. This method should be called when the
   *    FmRxEvSearchListComplete is invoked.
   *
   *    <p>
   *    @return      An array of integers that corresponds to the
   *                    frequency of the searched Stations
   *    @see #searchStationList
   */
   public int[] getStationList ()
   {
      int state = getFMState();
      /* Check current state of FM device */
      if (state == FMState_Turned_Off || state == FMState_Srch_InProg) {
          Log.d(TAG, "getStationList: Device currently busy in executing another command.");
          return null;
      }
      int[] stnList = new int [100];

      stnList = mControl.stationList (sFd);

      return stnList;

   }


   /*==============================================================
   FUNCTION:  getRssi
   ==============================================================*/
   /**
   *    Returns the signal strength of the currently tuned station
   *
   *    <p>
   *    This method returns the signal strength of the currently
   *    tuned station.
   *
   *    <p>
   *    @return    RSSI of currently tuned station
   */
   public int getRssi()
   {

       int rssi = FmReceiverJNI.getRSSINative (sFd);

       return rssi;
   }

   /*==============================================================
   FUNCTION:  getIoverc
   ==============================================================*/
   /**
   *    Returns the Estimated Interference Over Carrier of the currently tuned station
   *
   *    <p>
   *    This method returns the Estimated Interference Over Carrier of the currently
   *    tuned station.
   *
   *    <p>
   *    @return    IOVERC of currently tuned station on Success.
   *		   -1 on failure to retrieve the current IoverC.
   */
   public int getIoverc()
   {
      int re;
      re = mControl.IovercControl(sFd);
      return re;
   }

   /*==============================================================
   FUNCTION:  getIntDet
   ==============================================================*/
   /**
   *    Returns the IntDet the currently tuned station
   *
   *    <p>
   *    This method returns the IntDet of the currently
   *    tuned station.
   *
   *    <p>
   *    @return    IntDet of currently tuned station.
   *		   -1 on failure to retrieve the current IntDet
   */
   public int getIntDet()
   {
      int re;

      re = mControl.IntDet(sFd);
      return re;
   }


   /*==============================================================
   FUNCTION:  getMpxDcc
   ==============================================================*/
   /**
   *    Returns the MPX_DCC of the currently tuned station
   *
   *    <p>
   *    This method returns the MPX_DCC of the currently
   *    tuned station.
   *
   *    <p>
   *    @return    MPX_DCC value of currently tuned station.
   *               -1 on failure to retrieve the current MPX_DCC
   */
   public int getMpxDcc()
   {
      int re;

      re = mControl.Mpx_Dcc(sFd);
      return re;
   }
/*==============================================================
   FUNCTION:  setHiLoInj
   ==============================================================*/
   /**
   *    Sets the Hi-Lo injection
   *
   *    <p>
   *    This method sets the hi-low injection.
   *
   *    <p>
   */
   public void setHiLoInj(int inj)
   {
      int re =  mControl.setHiLoInj(sFd, inj);
   }

/*==============================================================
   FUNCTION:  getRmssiDelta
   ==============================================================*/
   /**
   *    Gets the value of currently set RMSSI Delta
   *
   *    <p>
   *    This method gets the currently set RMSSI Delta value.
   *
   *    <p>
   */
   public int getRmssiDelta()
   {
      int re =  mControl.getRmssiDelta(sFd);
      Log.d (TAG, "The value of RMSSI Delta is " + re);
      return re;
   }

/*==============================================================
   FUNCTION:  setRmssiDel
   ==============================================================*/
   /**
   *    Sets the RMSSI Delta
   *
   *    <p>
   *    This method sets the RMSSI Delta.
   *
   *    <p>
   */
   public void setRmssiDel(int delta)
   {
      int re =  mControl.setRmssiDel(sFd, delta);
   }

   /*==============================================================
   FUNCTION:  getRawRDS
   ==============================================================*/
   /**
   *    Returns array of Raw RDS data
   *
   *    <p>
   *    This is a non-blocking call and it returns raw RDS data.
   *    The data is packed in groups of three bytes. The lsb and
   *    msb bytes contain RDS block while the third byte contains
   *    Block description. This call is wrapper around V4L2 read
   *    system call. The FM driver collects RDS/RBDS groups to meet
   *    the threshold described by setRdsGroupOptions() method.
   *    The call returns when one or more groups have been enabled
   *    by setRdsGroupOptions() method.
   *
   *    @param numBlocks Number of blocks of RDS data
   *
   *    <p>
   *    @return    byte[]
   */

   public byte[] getRawRDS (int numBlocks)
   {

        byte[] rawRds = new byte [numBlocks*3];
        int re;

        re = FmReceiverJNI.getRawRdsNative (sFd, rawRds, numBlocks*3);

        if (re == (numBlocks*3))
            return rawRds;

        if (re <= 0)
          return null;

        byte[] buff = new byte [re];

        System.arraycopy (rawRds, 0, buff, 0 , re);

        return buff;

   }

   /*
    * getFMState() returns:
    *     '0' if FM State  is OFF
    *     '1' if FM Rx     is On
    *     '2' if FM Tx     is On
    *     '3' if FM device is Searching
   */
   public int getFMState()
   {
      /* Current State of FM device */
      int currFMState = FmTransceiver.getFMPowerState();
      return currFMState;

   }
/*==============================================================
   FUNCTION:  setOnChannelThreshold
   ==============================================================*/
   /**
   *    Sets the On channel threshold value
   *
   *    <p>
   *    This method sets the On channel threshold value.
   *
   *    <p>
   */
   public boolean setOnChannelThreshold(int data)
   {
      int re =  mControl.setOnChannelThreshold(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getOnChannelThreshold
   ==============================================================*/
   /**
   *    Gets the On channel threshold value
   *
   *    <p>
   *    This method gets the currently set On channel threshold value.
   *
   *    <p>
   */
   public int getOnChannelThreshold()
   {
      return mControl.getOnChannelThreshold(sFd);
   }

/*==============================================================
   FUNCTION:  setOffChannelThreshold
   ==============================================================*/
   /**
   *    Sets the Off channel threshold value
   *
   *    <p>
   *    This method sets the Off channel threshold value.
   *
   *    <p>
   */
   public boolean setOffChannelThreshold(int data)
   {
      int re =  mControl.setOffChannelThreshold(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }
/*==============================================================
   FUNCTION:  getOffChannelThreshold
   ==============================================================*/
   /**
   *    Gets the Off channel threshold value
   *
   *    <p>
   *    This method gets the currently set Off channel threshold value.
   *
   *    <p>
   */
   public int getOffChannelThreshold()
   {
      return mControl.getOffChannelThreshold(sFd);
   }
/*===============================================================
   FUNCTION:  getSINR
   ==============================================================*/
   /**
   *    Gets the SINR value of currently tuned station
   *
   *    <p>
   *    This method gets the SINR value for  currently tuned station.
   *
   *    <p>
   */
   public int getSINR()
   {
      int re =  mControl.getSINR(sFd);
      Log.d (TAG, "The value of SINR is " + re);
      return re;
   }

/*==============================================================
   FUNCTION:  setSINRThreshold
   ==============================================================*/
   /**
   *    Sets the SINR threshold value
   *
   *    <p>
   *    This method sets the SINR threshold value.
   *
   *    <p>
   */
   public boolean setSINRThreshold(int data)
   {
      int re =  mControl.setSINRThreshold(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getSINRThreshold
   ==============================================================*/
   /**
   *    Gets the SINR threshold value
   *
   *    <p>
   *    This method gets the currently set SINR threshold value.
   *
   *    <p>
   */
   public int getSINRThreshold()
   {
      return mControl.getSINRThreshold(sFd);
   }

/*==============================================================
   FUNCTION:  setRssiThreshold
   ==============================================================*/
   /**
   *    Sets the RSSI threshold value
   *
   *    <p>
   *    This method sets the RSSI threshold value.
   *
   *    <p>
   */
   public boolean setRssiThreshold(int data)
   {
      int re =  mControl.setRssiThreshold(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getRssiThreshold
   ==============================================================*/
   /**
   *    Gets the Rssi threshold value
   *
   *    <p>
   *    This method gets the currently set Rssi threshold value.
   *
   *    <p>
   */
   public int getRssiThreshold()
   {
      return mControl.getRssiThreshold(sFd);
   }

/*==============================================================
   FUNCTION:  setAfJumpRssiThreshold
   ==============================================================*/
   /**
   *    Sets the Af jump RSSI threshold value
   *
   *    <p>
   *    This method sets the AF jump RSSI threshold value.
   *
   *    <p>
   */
   public boolean setAfJumpRssiThreshold(int data)
   {
      int re =  mControl.setAfJumpRssiThreshold(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getAfJumpRssiThreshold
   ==============================================================*/
   /**
   *    Gets the Af jump RSSI threshold value
   *
   *    <p>
   *    This method gets the currently set AF jump RSSI threshold value.
   *
   *    <p>
   */
   public int getAfJumpRssiThreshold()
   {
      return mControl.getAfJumpRssiThreshold(sFd);
   }

/*==============================================================
   FUNCTION: setRdsFifoCnt
   ==============================================================*/
   /**
   *    Sets the RDS FIFO count value
   *
   *    <p>
   *    This method sets the RDS FIFO count value.
   *
   *    <p>
   */
   public boolean setRdsFifoCnt(int data)
   {
      int re =  mControl.setRdsFifoCnt(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getRdsFifoCnt
   ==============================================================*/
   /**
   *    Gets the RDS FIFO count value
   *
   *    <p>
   *    This method gets the currently set RDS FIFO count value.
   *
   *    <p>
   */
   public int getRdsFifoCnt()
   {
      return mControl.getRdsFifoCnt(sFd);
   }

/*==============================================================
   FUNCTION:  setSINRsamples
   ==============================================================*/
   /**
   *    Sets the SINR samples
   *
   *    <p>
   *    This method sets the number of SINR samples to calculate the SINR value.
   *
   *    <p>
   */
   public boolean setSINRsamples(int data)
   {
      int re =  mControl.setSINRsamples(sFd, data);
      if (re < 0)
          return false;
      else
          return true;
   }

/*==============================================================
   FUNCTION:  getSINRsamples
   ==============================================================*/
   /**
   *    Gets the SINR samples value
   *
   *    <p>
   *    This method gets the number of currently set SINR samples.
   *
   *    <p>
   */
   public int getSINRsamples()
   {
      return mControl.getSINRsamples(sFd);
   }

   public int updateSpurFreq(int freq, int rmssi, boolean enable)
   {
       return mControl.updateSpurTable(sFd, freq, rmssi, enable);
   }

   public int configureSpurTable()
   {
       return mControl.configureSpurTable(sFd);
   }

   public static int getSpurConfiguration(int freq)
   {
       int retval;

       retval = FmReceiverJNI.setControlNative(sFd, V4L2_CID_PRIVATE_IRIS_GET_SPUR_TBL, freq);

        if (retval !=0)
            Log.d(TAG, "Failed/No Spurs for " +freq);
       return retval;
   }

   public static void getSpurTableData()
   {
     int freq;
     byte no_of_spurs;
     int rotation_value;
     byte lsbOfLen;
     byte filterCoe;
     byte isEnbale;
     byte [] buff = new byte[STD_BUF_SIZE];
     int i = 0;
     FmReceiverJNI.getBufferNative(sFd, buff, 13);

     freq = buff[0] & 0xFF;
     freq |= ((buff[1] & 0xFF) << 8);
     freq |= ((buff[2] & 0xFF) << 16);
     Log.d (TAG, "freq = " +freq);
     no_of_spurs =  buff[3];
     Log.d (TAG, "no_of_spurs = " + no_of_spurs);
     for(i = 0; i < FmConfig.no_Of_Spurs_For_Entry; i++) {
         rotation_value =  buff[(i * 4) + 4] & 0xFF;
         rotation_value |= ((buff[(i * 4) + 5] & 0xFF) << 8);
         rotation_value |= ((buff[(i * 4) + 6] & 0x0F) << 12);
         Log.d (TAG, "rotation_value = " +rotation_value);
         lsbOfLen = (byte) (((buff[(i * 4) + 6] & 0xF0) >> 4) & 0x01);
         Log.d (TAG, "lsbOfLen = "+lsbOfLen);
         filterCoe = (byte) (((buff[(i * 4) + 6] & 0xF0) >> 5) & 0x03);
         Log.d (TAG, "filterCoe = " +filterCoe);
         isEnbale = (byte) (((buff[(i * 4) + 6] & 0xF0) >> 7) & 0x01);
         Log.d (TAG, "spur level: " +buff[(i * 4) + 7]);
     }
     return;
   }
}