AndroidFM模塊學習之四源碼分析(十)

接上一篇,今天咱們來看看android\vendor\qcom\opensource\fm\qcom\fmradio\FmRxControls.javajava

/ *android

*打開FM Rx / Tx。優化

* Rx = 1和Tx = 2get

* /it

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");
   }io

 

/ *event

*關掉FM Rx / Tx音頻

* /List

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;      }  

相關文章
相關標籤/搜索