The first few chapters we analyzed the FM module several main class file, today to analyze is:Fmtransceiver.java //Some project name is Fmradioservice.java
public class fmtransceiver{ /* Primary FM states: * FM would be is in one of the 4 states at any point of time *< c5/> ' 0 ' -fmstate_turned_off * ' 1 ' -fmstate_rx_turned_on * ' 2 ' -fmstate_tx_ turned_on * ' 3 ' -fmstate_srch_inprog */<pre name= "code" class= "Java" > 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 at any time in one of the following four states:
* ' 0 '-fmstate_turned_off
* ' 1 '-fmstate_rx_turned_on
* ' 2 '-fmstate_tx_turned_on
* ' 3 '-fmstate_srch_inprog
* /
/ * *
* Allows access to V4L2 FM devices.
* This synchronous call allows the client to use the V4L2 FM device. This must be the first time that the client that was published before the call can use any sink interface.
*
* This is also called the Power of the FM module.
*
* @param device path string, radio device
*
* @return Really
If the V4L2 FM device, FALSE if the V4L2 FM device can not be acquired, may be other customers
* @see #释放
* /
Protected Boolean acquire (String device) { Boolean bstatus = true; if (sFd <= 0) {//If previous open fails FD would 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; }
/ * *
* Release access to V4L2 FM device.
* < p >
This synchronous call allows the client version to control the V4L2 FM device. This function should be called the FM device when it is no longer needed. This should be the last call to FM customer release. Once called, the client must call #acquire to re-request the V4L2 device to control the FM device, which can be used again.
* < p >
Before the client can release the Control FM receiver interface, it must disable the FM receiver if the client enables it and unregisters the registered callback function. If the client receives ownership of the recipient, it is automatically returned to the system.
* < p >
* This is also called the Power of the FM module.
* < p >
* @param the radio device path string,
* @return True if the V4L2 FM device is released, False if the V4L2 FM device cannot be released
* @see #收购
* /
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; }
/**
* Registers a callback for FM receiver event notification.
* <p>
* This is a synchronous call to register the event notification driver for the FM receiver. The self-tuning driver performs some tasks asynchronously, which allows the client to receive information asynchronously.
* <p>
* When the function is called, the client must use a callback function to implement the asynchronous event. A callback that must be a non-null value parameter. If a null value is passed to this function, registration will fail.
* <p>
* The client can select which events will be sent from the receiver to the driver simply to implement the function that the event expects to receive.
* <p>
@param callback event callback FM receiver that handles the event.
@return True if the callback is registered, False if the callback registration failed.
@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; }
/**
* Unregisters the customer's event notification callback.
* <p>
* This is a synchronous call to unregister the client for an event callback.
* <p>
* @return true always.
* @see #acquire
* @see #release
* @see #registerClient
*
public Boolean unregisterclient () { mrxevents.stoplistener (); return true; }
/**
* Registers a callback for FM transmitter event notification.
* <p>
* This is a synchronous call to register the driver for an FM transmitter for event notifications. The self-tuning driver performs some tasks asynchronously, which allows the client to receive information asynchronously.
* <p>
* When the function is called, the client must use a callback function to implement the asynchronous event. A callback that must be a non-null value parameter. If a null value is passed to this function, registration will fail. The
* <p>
* client can select which events will be sent from the receiver to the driver only to implement the functionality that the event expects to receive.
* <p>
* @param callback event callback FM transmitter that handles events.
* @return True if the callback is registered, the false 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; }
/**
* Unregister the transmitter event notification callback.
* <p>
* This is a synchronous call to unregister the transmitter client for an event callback.
* <p>
* @return true always.
*
* @see #acquire
* @see #release
* @see #registerTransmitClient
*
*/
public Boolean unregistertransmitclient () { mtxevents.stoplistener (); return true; }
/**
* Initialize FM.
* <p>
* This is a synchronous call used to initialize the FM tranceiver. If the function has already been initialized, it will intialize tranceiver default settings. Only many FM device interfaces that successfully call this function can be used.
* <p>
* When the recipient is enabled, the client must also provide a locale sink that will operate. These settings (included in the configsettings) are typically used to set the FM receiver operation in a specific geographic area. These settings can be changed after you enable the FM driver by using the # Config feature.
* <p>
* This call can only be issued by the owner of an FM receiver. To issue this call, the client must first successfully invoke #qcquire.
* <p>
* @param configsettings the settings to being 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; }
/**
* FM is disabled.
* <p>
* This is a synchronous call for disabling the FM device. When this function will use the client no longer needs to use the FM device. It has been said that most of the functions provided by FM devices will be disabled until the client is enabled again through the # device.
* <p>
* @return True if disabling succeeded, false if disabling
* Failed.
* <p>
* @see #enable
* @see #registerClient
*/
public boolean disable () { mcontrol.fmoff (sFd); return true; }
/**
* Reconfigure the regional settings of the device
* (FM Band, de-emphasis, Channel Spacing, Rds/rbds mode).
* <p>
* This is a synchronous call for the configuration settings on the FM device. Included in the structure by setting is usually different from one geographic area to another.
* <p>
* @param configsettings Contains settings for the FM radio
* (FM band, De-emphasis, channel
* spacing, Rds/rbds mode)
* <p>
* @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.
* <p>
* In this way, the FM device of the music station provides the specified frequency. The only valid frequency in-band enabled or configured configuration can be tuned through this function. Attempting to adjust bands outside the frequency set will result in an error.
* <p>
* Once you have finished tuning to the specified frequency, The event callback Fmrxevradiotunestatus will be called.
*
* @param frequencykhz Frequency (in kHz) to be t Uned
* (example:96500 = 96.5Mhz)
* @return True if Setstation call is placed successfully,
* & nbsp; 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 the notch filter.
* <p>
* This method sets the desired notch filter to achieve Fm-wan concurrency based on the current WAN band frequency. The application should listen to the data call event and call the function in each data call connection let u, implement 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.
* <p>
* 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 FM antenna
*
* <p>
* The method returns TRUE if the internal FM antenna is available, otherwise false
* <p>
* @return True/false
*/
public boolean Getinternalantenna () { int re = fmreceiverjni.getcontrolnative (SFd, V4l2_cid_private_tavarua_ antenna); if (re = = 1) return true; return false; }
/**
* Otherwise returns true, if successful, returns false
* <p>
* The method internal antenna type is set to True/false
*
* @param Intantenna True is internal antenna exists
*
* <p>
* @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
*
* <p>
* The method sets the FM power state.
* <p>
*/
static void setfmpowerstate (int state) { fmstate = state; }
/**
* Returns:
*
*&NBSP;&NBSP;&NBSP;&NB sp; fmoff -If The FM Radio is turned off
*& nbsp; fmrxon -If The FM Receiver is currently Turned on
* fmtxon - If the FM transmitter is currently turned on
* fmreset & nbsp; -IF The FM Radio is reset
*
* Gets the FM p Ower State
*
* <p>
* This Method gets the FM power state.
*
* <p>
*/
public static int getfmpowerstate () { return fmstate; }
Summary: Overall, relatively single, clear structure, easy to understand.
Android FM Module Learning four source learning (2)