AndroidFM模块学习之四源码分析(十)

上一篇,今天我们来看看android\vendor\qcom\opensource\fm\qcom\fmradio\FmRxControls.java

/ *

*打开FM Rx / Tx。

* Rx = 1和Tx = 2

* /

public void fmOn(int fd, int device) {
      int re;
      FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_STATE, device );
      setAudioPath(fd, false);
      re = FmReceiverJNI.SetCalibrationNative(fd);
      if (re != 0)
         Log.d(TAG,"Calibration failed");
   }

 

/ *

*关掉FM Rx / Tx

* /

public void fmOff(int fd){
      FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_STATE, 0 );
   }

/ *

*设置静音控制

* /

 public void muteControl(int fd, boolean on) {
      if (on)
      {
         int err = FmReceiverJNI.setControlNative(fd, V4L2_CID_AUDIO_MUTE, 3 );
      } else
      {
         int err = FmReceiverJNI.setControlNative(fd, V4L2_CID_AUDIO_MUTE, 0 );
      }
   }

/ *

*获得干扰通道

* /

public int IovercControl(int fd)
   {
      int ioverc = FmReceiverJNI.getControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_IOVERC);
      Log.d(TAG, "IOVERC value is : "+ioverc);
      return ioverc;
   }

/ *

*获得IntDet

* /

public int IntDet(int fd)
   {
      int intdet =  FmReceiverJNI.getControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_INTDET);
      Log.d(TAG, "IOVERC value is : "+intdet);
      return intdet;
   }

/ *

*获得MPX_DCC

* /

public int Mpx_Dcc(int fd)
   {
      int mpx_dcc =  FmReceiverJNI.getControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_MPX_DCC);
      Log.d(TAG, "MPX_DCC value is : " + mpx_dcc);
      return mpx_dcc;
   }

/ *

*设置Hi-Low注入

* /

 public int setHiLoInj(int fd, int inj)
   {
      int re =  FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_HLSI, inj);
      return re;
   }

/ *

*set打开通道阈值

* /

public int setOnChannelThreshold(int fd, int sBuff)
   {
      int re = FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_ON_CHANNEL_THRESHOLD, sBuff);
      if ( re < 0)
         Log.e(TAG, "Failed to set On channel threshold data");
      return re;
   }

/ *

*set关闭通道阈值

* /

public int setOffChannelThreshold(int fd, int sBuff)
   {
      int re = FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_OFF_CHANNEL_THRESHOLD, sBuff);
      if ( re < 0)
         Log.e(TAG, "Failed to set Off channel Threshold data");
      return re;
   }

/ *

*设置音频路径模拟/数字

* /

public int setAudioPath(int fd, boolean value)
   {
      int mode;
      if (value)
         mode = FM_ANALOG_PATH;
      else
         mode = FM_DIGITAL_PATH;
      int re =  FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_SET_AUDIO_PATH, mode);
      return re;
   }

/ *

*优化调频核心指定的频率。

* /

public int setStation(int fd) {
      Log.d(TAG, "** Tune Using: "+fd);
      int ret = FmReceiverJNI.setFreqNative(fd, mFreq);
      Log.d(TAG, "** Returned: "+ret);
      return ret;
   }

/ *

*获取FM频率

* /

 

public int getTunedFrequency(int fd) {
      int frequency = FmReceiverJNI.getFreqNative(fd);
      Log.d(TAG, "getTunedFrequency: "+frequency);
      return frequency;
   }

/ *

*获得SINR的价值

* /

 public int getSINR(int fd)
   {
      return  FmReceiverJNI.getControlNative(fd, V4L2_CID_PRIVATE_SINR);
   }

/ *

*开始自动搜索预设列表

* /

 public int searchStationList (int fd, int mode, int preset_num,
                                   int dir, int pty )
   {
      int re;


     /* set search mode. */
      re = FmReceiverJNI.setControlNative (fd, V4L2_CID_PRIVATE_TAVARUA_SRCHMODE, mode);
      if (re != 0) {
         return re;
      }

      /* set number of stations to be returned in the list */re = FmReceiverJNI.setControlNative (fd, V4L2_CID_PRIVATE_TAVARUA_SRCH_CNT, preset_num);
      if (re != 0) {
         return re;
      }

      // RDS search list?
      if (pty > 0 ){
        re = FmReceiverJNI.setControlNative (fd, V4L2_CID_PRIVATE_TAVARUA_SRCH_PTY, pty);
      }
      if (re != 0) {
         return re;
      }
      /* This triigers the search and once completed the FM core generates
       * searchListComplete event */
      re = FmReceiverJNI.startSearchNative (fd, dir );
      if (re != 0) {
         return re;
      }
      else {
         return 0;
      }

   }

 

/ *从缓冲区读取搜索列表* /

public int[] stationList (int fd)
   {
         int freq = 0;
         int i=0, j = 0;
         int station_num = 0;
         float real_freq = 0;
         int [] stationList;
         byte [] sList = new byte[100];
         int tmpFreqByte1=0;
         int tmpFreqByte2=0;
         float lowBand, highBand;
         lowBand  = (float) (FmReceiverJNI.getLowerBandNative(fd) / 1000.00);
         highBand = (float) (FmReceiverJNI.getUpperBandNative(fd) / 1000.00);

         Log.d(TAG, "lowBand: " + lowBand);
         Log.d(TAG, "highBand: " + highBand);

         FmReceiverJNI.getBufferNative(fd, sList, 0);

         if ((int)sList[0] >0) {
            station_num = (int)sList[0];
         }
         stationList = new int[station_num+1];Log.d(TAG, "station_num: " + station_num);

         for (i=0;i<station_num;i++) {
            freq = 0;
            Log.d(TAG, " Byte1 = " + sList[i*2+1]);
            Log.d(TAG, " Byte2 = " + sList[i*2+2]);
            tmpFreqByte1 = sList[i*2+1] & 0xFF;
            tmpFreqByte2 = sList[i*2+2] & 0xFF;
            Log.d(TAG, " tmpFreqByte1 = " + tmpFreqByte1);
            Log.d(TAG, " tmpFreqByte2 = " + tmpFreqByte2);
            freq = (tmpFreqByte1 & 0x03) << 8;
            freq |= tmpFreqByte2;
            Log.d(TAG, " freq: " + freq);real_freq  = (float)(freq * 50) + (lowBand * FREQ_MUL);//tuner.rangelow * FREQ_MUL;
            Log.d(TAG, " real_freq: " + real_freq);
            if ( (real_freq < (lowBand * FREQ_MUL)) || (real_freq > (highBand * FREQ_MUL)) ) {
               Log.e(TAG, "Frequency out of band limits");
            }
            else {
               stationList[j] = (int)(real_freq);
               Log.d(TAG, " stationList: " + stationList[j]);
               j++;
            }
         } try {
          // mark end of list
           stationList[station_num] = 0;
        }
        catch (ArrayIndexOutOfBoundsException e) {
           Log.d(TAG, "ArrayIndexOutOfBoundsException !!");
        }

        return stationList;

   }

 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值