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;

   }

时间: 2024-10-07 04:38:18

AndroidFM模块学习之四源码分析(十)的相关文章

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

接上一篇,接下来我们看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\PresetList.java 定义一个List列表List<PresetStation>mPresetList = new ArrayList<PresetStation>(); 同步电台数量 public synchronized int getStationCount(){ return mPresetList.size(); }

Android FM模块学习之四源码分析(3)

接着看FM模块的其他几个次要的类的源码.这样来看FM上层的东西不是太多. 请看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\Settings.java protected void onCreate(BundlesavedInstanceState) 从FMRadio.java用使用Intent跳转携带参数过来,在onCreate获取携带数据. protected void onCreate(Bundle savedIn

Android FM模块学习之四源码分析(五)

前几章我们分析了FM模块的几个主要的类文件,今天要分析的是:FMTransceiver.java public class FmTransceiver { /* Primary FM States : * FM will be in one of the 4 states at any point of time * '0' - FMState_Turned_Off * '1' - FMState_Rx_Turned_On * '2' - FMState_Tx_Turned_On * '3' -

AndroidFm模块学习之四源码解析(十一)

接上一篇,接下来看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\FmTags.java 当点击FMRadio.java菜单的全部频道选项,跳转到FmTags.java类 定义了一个ListView控件和一个简单适配器 private ListView la; private ArrayAdapter<String> adapter; 使用Handler刷新UI界面 private final Handler mHan

Android FM模块学习之四源码分析(七)

接上一篇,现在分析android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\StationListActivity.java protectedvoid onCreate(Bundle savedInstanceState)方法里 绑定FMRadioService服务 bindService((newIntent()).setClass(this, FMRadioService.class), osc, 0); 实例化ListVie

Android FM模块学习之四源码解析(二)

上一章我们了解了FM主activity:FMRadio.java,若没查看的,请打开链接Android FM模块学习之四源码解析(一) 查看fmradio.java源码注释.接下来我们来看看FM重要的一个类:FMRadioService.java 由上一章我们已经知道,打开FM时,在OnStart函数中会bindToService来开启服务, public boolean bindToService(Context context, ServiceConnection callback) { L

Android FM模块学习之源码分析(六)

现在是2015年1月啦,得改口说去年了,去年抽时间整理了一些FM模块的主要源码类的东西,今年再整理一下几个次要的类的源码.这样来看FM上层的东西不是太多. 请看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\Settings.java protected void onCreate(BundlesavedInstanceState) 从FMRadio.java用使用Intent跳转携带参数过来,在onCreate获取携带数

Android FM模块学习之四源码解析(三)

由于最近一直忙项目,没有时间来更新文档,今天抽空来写一点,希望大家可以学习使用! 这一章当然还是来分析FM模块的源码.FmReceiver.java publicFmReceiver(String devicePath,FmRxEvCallbacksAdaptor callback) throwsInstantiationException { mControl = new FmRxControls(); mRxEvents = new FmRxEventListner(); //registe

Android FM模块学习之四源码解析(一)

前一章我们了解了FM手动调频,接下来我们要分析FM模块用到的源码.此源码是基于高通平台的,别的平台都大同小异,只不过是平台自己作了些小改动而已. 首先要看的当然是主activity, FMRadio.java fmradio类启动FMRadioService.java类调用FmSharedPreferences类进行存储数据,PresetStation调整频率 setVolumeControlStream(AudioManager.STREAM_MUSIC);音乐回放即媒体音量 LoadedDa