summaryrefslogtreecommitdiffstats
path: root/qcom/fmradio/FmRxRdsData.java
blob: dac419497ff44f15a8412d5e76398819d8d17be4 (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
/*
 * Copyright (c) 2009,2012, 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;
/**
 *
 * @hide
 */
public class FmRxRdsData {


    private String mRadioText = "";
    private String mPrgmServices;
    private String mERadioText = "";
    // false means left-right
    // true means right-left
    private boolean formatting_dir = false;
    private byte []mTagCode = new byte[2];
    private String []mTag = new String[2];
    private int tag_nums = 0;
    private static final int MAX_NUM_TAG = 2;
    private boolean rt_ert_flag;
    private int mPrgmId;
    private int mPrgmType;
    private int mFd;

    /* V4L2 controls */
    private static final int V4L2_CID_PRIVATE_BASE = 0x8000000;
    private static final int V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_MASK = V4L2_CID_PRIVATE_BASE + 6;
    private static final int V4L2_CID_PRIVATE_TAVARUA_RDSON = V4L2_CID_PRIVATE_BASE + 15;
    private static final int V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC = V4L2_CID_PRIVATE_BASE + 16;
    private static final int V4L2_CID_PRIVATE_TAVARUA_RDSD_BUF = V4L2_CID_PRIVATE_BASE + 19;
    private static final int V4L2_CID_PRIVATE_TAVARUA_PSALL = V4L2_CID_PRIVATE_BASE + 20;
    private static final int V4L2_CID_PRIVATE_TAVARUA_AF_JUMP = V4L2_CID_PRIVATE_BASE + 27;


    private static final int RDS_GROUP_RT = 0x1;
    private static final int RDS_GROUP_PS = 1 << 1;
    private static final int RDS_GROUP_AF = 1 << 2;
    private static final int RDS_AF_AUTO  = 1 << 6;
    private static final int RDS_PS_ALL   = 1 << 4;
    private static final int RDS_AF_JUMP  = 0x1;
    private static final int MAX_TAG_CODES = 64;

    private static final String LOGTAG="FmRxRdsData";


    public FmRxRdsData (int fd)
    {
      mFd = fd;
    }

    /* turn on/off RDS processing */
    public int rdsOn (boolean on)
    {

      int ret;

      Log.d(LOGTAG, "In rdsOn: RDS is " + on);

      if (on) {
        ret = FmReceiverJNI.setControlNative (mFd, V4L2_CID_PRIVATE_TAVARUA_RDSON, 1);
      }
      else {
        ret = FmReceiverJNI.setControlNative (mFd, V4L2_CID_PRIVATE_TAVARUA_RDSON, 0);
      }


      return ret;


    }

    /* process raw RDS group filtering */
    public int rdsGrpOptions (int grpMask, int buffSize, boolean rdsFilter)
    {

        int rdsFilt;
        int re;

        byte rds_group_mask = (byte)FmReceiverJNI.getControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC);

        rds_group_mask &= 0xFE;


        if (rdsFilter)
          rdsFilt = 1;
        else
          rdsFilt = 0;

        rds_group_mask |= rdsFilt;

        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC, rds_group_mask);

        if (re != 0)
          return re;

        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSD_BUF, buffSize);

        if (re != 0)
          return re;


        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_MASK, grpMask);

        return re;


    }

    /* configure RT/PS/AF RDS processing */
    public int rdsOptions (int rdsMask)
    {

        int re=0;

        byte rds_group_mask = (byte)FmReceiverJNI.getControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC);
        byte rdsFilt = 0;
        int  psAllVal=rdsMask & RDS_PS_ALL;

        Log.d(LOGTAG, "In rdsOptions: rdsMask: " + rdsMask);


        rds_group_mask &= 0xC7;


        rds_group_mask  |= ((rdsMask & 0x07) << 3);


        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC, rds_group_mask);

        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_PSALL, psAllVal >> 4 );

        return re;

    }

    /* Enable auto seek to alternate frequency */
    public int enableAFjump(boolean AFenable)
    {
      int re;
      int rds_group_mask = 0;

      Log.d(LOGTAG, "In enableAFjump: AFenable : " + AFenable);

      rds_group_mask = FmReceiverJNI.getControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC);
      Log.d(LOGTAG, "Currently set rds_group_mask : " + rds_group_mask);

      if (AFenable)
        re = FmReceiverJNI.setControlNative(mFd ,V4L2_CID_PRIVATE_TAVARUA_AF_JUMP, 1);
      else
        re = FmReceiverJNI.setControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_AF_JUMP, 0);

      rds_group_mask = FmReceiverJNI.getControlNative(mFd, V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_PROC);

      if (AFenable)
        Log.d(LOGTAG, "After enabling the rds_group_mask is : " + rds_group_mask);
      else
        Log.d(LOGTAG, "After disabling the rds_group_mask is : " + rds_group_mask);

      return re;
    }


    public String getRadioText () {
        return mRadioText;
    }

    public void setRadioText (String x) {

        mRadioText = x;
    }

    public String getPrgmServices () {
        return mPrgmServices;
    }
    public void setPrgmServices (String x) {
        mPrgmServices = x;
    }

    public int getPrgmId () {
        return mPrgmId;
    }
    public void setPrgmId (int x) {
        mPrgmId = x;
    }

    public int getPrgmType () {
        return mPrgmType;
    }
    public void setPrgmType (int x) {
         mPrgmType = x;
    }
    public String getERadioText () {
         return mERadioText;
    }
    public void setERadioText (String x) {
         mERadioText = x;
    }
    public boolean getFormatDir() {
         return formatting_dir;
    }
    public void setFormatDir(boolean dir) {
         formatting_dir = dir;
    }
    public void setTagValue (String x, int tag_num) {
        if ((tag_num > 0) && (tag_num <= MAX_NUM_TAG)) {
            mTag[tag_num - 1] = x;
            tag_nums++;
        }
    }
    public void setTagCode (byte tag_code, int tag_num) {
        if ((tag_num > 0) && (tag_num <= MAX_NUM_TAG))
            mTagCode[tag_num - 1] = tag_code;
    }
    public String getTagValue (int tag_num) {
        if ((tag_num > 0) && (tag_num <= MAX_NUM_TAG))
            return mTag[tag_num - 1];
        else
            return "";
    }
    public byte getTagCode (int tag_num) {
        if ((tag_num > 0) && (tag_num <= MAX_NUM_TAG))
            return mTagCode[tag_num - 1];
        else
            return 0;
    }
    public int getTagNums() {
        return tag_nums;
    }
    public void setTagNums(int x) {
        if ((x >= 0) && (x <= MAX_NUM_TAG))
            tag_nums = x;
    }
}