Android FM module learning-4 source code analysis (5)

Source: Internet
Author: User

Android FM module learning-4 source code analysis (5)

In the previous chapters, we analyzed several main class files of the FM module. What we want to analyze today is: 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'-Timeout */
   public static final int FMState_Turned_Off   = 0;   public static final int FMState_Rx_Turned_On = 1;   public static final int FMState_Tx_Turned_On = 2;   public static final int FMState_Srch_InProg  = 3;


/* FM status:

* FM is in one of the following four States at any time:

* "0" -- FMState_Turned_Off

* '1'-FMState_Rx_Turned_On

* '2'-FMState_Tx_Turned_On

"3" -- FMState_Srch_InProg

*/

/**

* Allows access to the V4L2 FM device.

* This synchronous call allows the client to use the V4L2 FM device. This must be the first time you call a client released earlier to use any receiver interface.

*

* This is also called the power frequency modulation module.

*

* @ Param device path string, radio device

*

* @ Return true

If the V4L2 FM device is used, if the V4L2 FM device cannot be acquired, it may be acquired by other customers.

* @ See # Release

*

*/


protected boolean acquire(String device){      boolean bStatus = true;      if (sFd <= 0) { // if previous open fails fd will be -ve.         sFd = FmReceiverJNI.acquireFdNative(V4L2_DEVICE);         if (sFd > 0) {            Log.d(TAG, "Opened "+ sFd);            bStatus = true;         }         else {            Log.d(TAG, "Fail to Open "+ sFd);    bStatus = false;         }

/**

* Released an access V4L2 FM device.

* <P>

This synchronous call allows the Client Version to control the V4L2 FM device. This function is not required when it is called an FM device. This should be the last call of the FM customer release. Once called, the client must call # acquire to request the V4L2 device to control the FM device again.

* <P>

Previously, the client can release the FM receiver control interface, which must disable the FM receiver if the client enables it and deregister the registered callback function. If the ownership of the client receiver is exceeded, it is automatically returned to the system.

* <P>

* This is also called the power frequency modulation module.

* <P>

* @ Param radio device path string,

* @ Return true if the V4L2 FM device is released, false if the V4L2 FM device cannot be released

* @ See # acquisition

*/

static boolean release(String device) {      if (sFd!=0)      {         FmReceiverJNI.closeFdNative(sFd);         sFd = 0;         Log.d("FmTransceiver", "Turned off: " + sFd);      } else      {         Log.d("FmTransceiver", "Error turning off");      }      return true;   }

/**
* Register a callback as an FM receiver event notification.
*


* This is an event notification driver for Synchronous call registration for FM receivers. The self-FM driver executes some tasks asynchronously, which allows the client to receive information asynchronously.
*


* When calling this function, the client must use a callback function to Implement Asynchronous events. The callback must be a non-null parameter. If a NULL value is passed to this function, registration fails.
*


* The client can select which events will be sent from the receiver. The driver only needs to implement the functions that the event will receive.
*


@ Param callback Event Callback the frequency modulation receiver that processes the event.
@ Return if the callback registration is true or false if the callback registration fails.
@ See # acquire
@ See # unregisterClient
*
*/

public boolean registerClient(FmRxEvCallbacks callback){      boolean bReturnStatus = false;      if (callback!=null)      {         mRxEvents.startListner(sFd, callback);         bReturnStatus = true;      } else      {         Log.d(TAG, "Null, do nothing");      }      return bReturnStatus;   }
/**
* Event Notification callback for deregistering a customer.
*


* This is an Event Callback that is synchronously called to log out of the customer.
*


* @ Return true always.
* @ See # acquire
* @ See # release
* @ See # registerClient
*

public boolean unregisterClient () {      mRxEvents.stopListener();      return true;   }
/**
* Register a callback as an FM transmitter event notification.
*


* This is a synchronous call to register the driver of the FM transmitter for event notification. The self-FM driver executes some tasks asynchronously, which allows the client to receive information asynchronously.
*


* When calling this function, the client must use a callback function to Implement Asynchronous events. The callback must be a non-null parameter. If a NULL value is passed to this function, registration fails.
*


* The client can select which events will be sent from the receiver. The driver only needs to implement the functions that the event will receive.
*


* @ Param callback Event Callback the FM transmitter that processes the event.
* @ Return true if callback registration fails.
* @ See # acquire
* @ See # unregisterTransmitClient
*
*/

public boolean registerTransmitClient( FmTransmitterCallbacks callback){      boolean bReturnStatus = false;      if (callback!=null)      {         mTxEvents.startListner(sFd, callback);         bReturnStatus = true;      } else      {         Log.d(TAG, "Null, do nothing");      }      return bReturnStatus;   }
/**
* Callback for canceling the transmitter event notification.
*


* This is a synchronous call used to cancel the Event Callback of the consumer of the transmitter.
*


* @ Return true always.
*
* @ See # acquire
* @ See # release
* @ See # registerTransmitClient
*
*/

public boolean unregisterTransmitClient () {      mTxEvents.stopListener();      return true;   }

/**
* Initialize FM.
*


* This is a synchronous call used to initialize the FM tranceiver. If this function has been initialized, intialize tranceiver is set by default. This function can only be used by many FM device interfaces that successfully call this function.
*


* When the receiver is enabled, the client must also provide regional settings for the receiver to operate. These settings (including in configSettings) are generally used to set FM receiver operations in a specific geographic area. After these settings can be changed, enable the FM driver by using the # configuration function.
*


* This phone number can only be issued by the owner of one FM receiver. To issue this call, the client must first successfully call # qcquire.
*


* @ Param configSettings the settings to be applied when
* Turning on the radio
* @ Return true if Initialization succeeded, false if
* Initialization failed.
* @ See # registerClient
* @ See # disable
*
*/

 public boolean enable (FmConfig configSettings, int device){      boolean status;      //Acquire the deviceon Enable      if( !acquire("/dev/radio0")){         return false;      }      Log.d(TAG, "turning on " + device);      mControl.fmOn(sFd, device);      Log.d(TAG, "Calling fmConfigure");      status = FmConfig.fmConfigure (sFd, configSettings);      if (!status) {          Log.d(TAG, "fmConfigure failed");          FmReceiverJNI.closeFdNative(sFd);          sFd = 0;      }      return status;   }

/**
* Disable FM.
*


* This is a synchronous call used to disable the FM device. This function will no longer require the use of FM devices on the client. It was said that the functions provided by most FM devices will be disabled until the client is enabled again through the # device.
*


* @ Return true if disabling succeeded, false if disabling
* Failed.
*


* @ See # enable
* @ See # registerClient
*/

public boolean disable(){      mControl.fmOff(sFd);      return true;   }
/**
* Reconfigure the device region settings.
* (FM Band, De-Emphasis, Channel Spacing, RDS/RBDS mode ).
*


* This is a synchronous call for configuration settings on the FM device. The structure is usually different from one geographic area to another by setting.
*


* @ Param configSettings Contains settings for the FM radio
* (FM band, De-emphasis, channel
* Spacing, RDS/RBDS mode)
*


* @ Return true if configure succeeded, false if
* Configure failed.
*/

 public boolean configure(FmConfig configSettings){      boolean status=true;      int lowerFreq = configSettings.getLowerLimit();      Log.d(TAG, "fmConfigure");      status = FmConfig.fmConfigure (sFd, configSettings);      status = setStation (lowerFreq);      return status;   }
/**
* The FM frequency specified by the music FM device.
*


* In this way, the FM device of the music station provides the specified frequency. You can use this function to enable or set the configuration of the unique effective frequency band. Attempting to adjust bands outside the frequency set will lead to an error.
*


* Once the call is completed and adjusted to the specified frequency, the Event Callback FmRxEvRadioTuneStatus will be called.
*
* @ Param frequencyKHz Frequency (in kHz) to be tuned
* (Example: 96500 = 96.5 Mhz)
* @ Return true if setStation call was placed successfully,
* False if setStation failed.
*/

public boolean setStation (int frequencyKHz) {      int ret;      mControl.setFreq(frequencyKHz);      ret = mControl.setStation(sFd);      if(ret < 0 )      {         return false;      }      else      {         return true;      }   }
/**
* Set the desired WAN to avoid ripple filters.
*


* This method sets the desired ripple filter based on the current WAN band frequency to achieve FM-WAN concurrency. Applications should listen to data call events and call functions in each data call connection to make u, implementing FM-WAN concurrency.
*
*/

 public void setNotchFilter(boolean value) {FmReceiverJNI.setNotchFilterNative(sFd, V4L2_CID_PRIVATE_TAVARUA_SET_NOTCH_FILTER, value);   }

/**
* Enable/disable analog low power mode.
*


* This method enables/disables analog low-power mode.
*
*/

public boolean setAnalogMode(boolean value) {        int re = mControl.setAudioPath(sFd, value);        re = FmReceiverJNI.setAnalogModeNative(value);        if (re == 1)            return true;        return false;   }

/**
* Returns true if the Internal Frequency Modulation Antenna
*
*


* This method returns true if the internal FM antenna is available, otherwise false
*


* @ Return true/false
*/

 public boolean getInternalAntenna()   {       int re = FmReceiverJNI.getControlNative (sFd, V4L2_CID_PRIVATE_TAVARUA_ANTENNA);       if (re == 1)         return true;       return false;   }

/**
* Otherwise, true is returned. If yes, false is returned.
*


* Set the internal antenna type to true/false in this method.
*
* @ Param intAntenna true is internal antenna exists
*
*


* @ Return true/false
*/

public boolean setInternalAntenna(boolean intAnt)   {       int iAntenna ;       if (intAnt)          iAntenna = 1;       else          iAntenna = 0;       int re = FmReceiverJNI.setControlNative (sFd, V4L2_CID_PRIVATE_TAVARUA_ANTENNA, iAntenna);       if (re == 0)         return true;       return false;   }
/**
* Set FM Power status
*
*


* This method sets the FM Power status.

*


*/

static void setFMPowerState(int state)   {      FMState = state;   }
/**
* Returns:
*
* FMOff-If the FM Radio is turned off
* FMRxOn-If the FM operator er is currently turned on
* FMTxOn-If the FM Transmitter is currently turned on
* FMReset-If the FM Radio is reset
*
* Gets the FM power state
*
*


* This method gets the FM power state.
*
*


*/

 public static int getFMPowerState()   {      return FMState;   }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.