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

Source: Internet
Author: User

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

I have been busy with projects recently and have no time to update documents. I hope you can learn more and use it today!

This chapter also analyzes the source code of the FM module. FmReceiver. java


publicFmReceiver(String devicePath,FmRxEvCallbacksAdaptor callback) throwsInstantiationException {      mControl = new FmRxControls();      mRxEvents = new FmRxEventListner();      //registerClient(callback);      mCallback = callback;   }

/** Register a callback as an FM receiver event notification.
* <P>
* This is a synchronous command used to register events to notify the driver of the FM receiver. The self-FM driver executes some tasks asynchronously, which allows the client to receive information asynchronously.
* <P>
* 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.
* <P>
* 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.
* <P>
* @ Param callback Event Callback refers to the FM receiver that processes the event.

* @ Return if the callback registration is true or false if the callback registration fails.
* Initialization failed.
* <P>
* @ See # acquisition
* @ See # unregisterClient

**/

public boolean registerClient(FmRxEvCallbacks callback){      boolean status;      status = super.registerClient(callback);      /* Do Receiver Specific Stuff here.*/      return status;   }

/**
* Enable the FM device in the receiving mode.
*


* This is a synchronous method used to initialize the FM receiver. If the function has been initialized, use the default settings for the intialize receiver. 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 the configSettings parameter) 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 function {@ link # configuration }.
*

* This command can only generate the owner of one FM receiver. To send this command, the client must first successfully call {@ link # To obtain }.
*


* @ Param configSettings set to apply when the radio is turned on
* @ Return if the initialization is successful, false if the initialization fails.
*


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

public boolean enable (FmConfig configSettings)


/**
* Reset the FM device.
* <P>
* This is an error that cannot be recovered when the synchronization command is used to reset the status of the FM device. This function will be disabled when the client receives unexpected broadcast notifications. It was said that the functions provided by most FM devices will be disabled until the client can enable the device again through {@ link # available }.
* <P>

* @ Return if the reset is successful, false if the reset fails.
@ See # enable
@ See # disable
@ See # registerClient
*/

publicboolean reset()


/**
* The FM device is disabled.
* <P>
* This is a synchronization command 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 can enable the device again through {@ link # available }.
* <P>
* @ Return if it is successfully disabled, false if it fails to be disabled.
@ See # enable
@ See # registerClient


*/

publicboolean disable()


/**
* Obtain the status of the current search operation.
* <P>
This function will use the searchStations () function to check whether the search/scan/automatic selection operation is in progress.
If an ongoing request is sent when a command is being sought, we cancel the request and start a new search operation.
* <P>

* @ Return the current status of the FM search operation:
* SRCH_COMPLETE
* SRCH_INPROGRESS
* SRCH_ABORTED
*/

static int getSearchState()



/**
* Set the current status of the search operation.
* <P>

* This function is used to set the current status of the search operation. If an ongoing search request is sent when a search request is sent, the search request is canceled. The search operation is in the SRCH_ABORTED state and a new search starts.
* <P>
* @ Return no
*/

static void setSearchState(int state)


/**
* Start basic search and scan operations.
*
* <P>
* Use this command to call a basic seek/FM radio frequency scan.

* <P>
* <Ul>
* This API is used: <李> Call Basic Search operations ({@ link # FM_RX_SRCH_MODE_SEEK }) <李> Call basic scan operations ({@ link # FM_RX_SRCH_MODE_SCAN })
* </Ul>

* <P>
* The most basic operation executed by this function is a command of {@ link # FM_RX_SRCH_MODE_SEEK. Increment or decrease of the seek process processing frequency in the predefined channel step (defined by the channel interval) and the measured signal level. Once the station is successfully called, it is found that in order to reach or exceed this signal level, the seeking operation will complete and the FmRxEvSearchComplete event will be returned to the client. If no matching standard site is found, the frequency will return to the initial tuning.
* <P>

* Because seeking always leads to frequency tuning, each seeking operation also returns an FmRxEvRadioTuneStatus event to the client/application layer.
*
* <P>

Just like the {@ link # FM_RX_SRCH_MODE_SEEK}, the {@ link # FM_RX_SRCH_MODE_SCAN} command can be compared to many back-to-back requests seeking to live in every successful pursuit. Once published, the scan defines the channel interval for the increment or decrement frequency until the find Station reaches or exceeds the search threshold set. Once the site is found and successfully adjusted, the FmRxEvRadioTuneStatus event will be returned to the client, and the station will still be adjusted to a specific time indicated by the dwellPeriod parameter. After the time expires, the FmRxEvSearchInProgress event will be sent to the client and a new one will start searching for the next stop to match the search threshold. After scanning the entire band or canceling the search, the FmRxEvRadioTuneStatus event is sent to the client. Similar to the search command, each scan will cause at least one site to be adjusted, even if this is the initial frequency.
* <P>
* Each time the driver starts the search (seeking or scanning) client, a FmRxEvSearchInProgress event notification is sent. Similarly, after each search is complete, the client notifies you through a FmRxEvRadioTuneStatus event.
* <P>
* The search API cancelSearch () can be canceled at any time (). Once canceled, each search will be redirected to the last site and the FmRxEvSearchComplete and FmRxEvRadioTuneStatus events will be generated. Valid parameter value "Mode ":
* <Ul>
*
  • {@ Link # FM_RX_SRCH_MODE_SEEK}
    *
  • {@ Link # FM_RX_SRCH_MODE_SCAN}
    * </Ul>
    * <P>
    * Valid parameter value "dwellPeriod ":
    * <Ul>
    *
  • {@ Link # FM_RX_DWELL_PERIOD_1S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_2S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_3S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_4S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_5S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_6S}
    *
  • {@ Link # FM_RX_DWELL_PERIOD_7S}
    * </Ul>
    * <P>
    * Valid parameter value "direction ":
    * <Ul>
    *
  • {@ Link # FM_RX_SEARCHDIR_DOWN}
    *
  • {@ Link # FM_RX_SEARCHDIR_UP}
    * </Ul>
    * <P>
    * @ Param mode: the FM search mode.
    @ Param dwellPeriod: specifies the time for FM scanning. Only when used
    Mode ={@ link # FM_RX_SRCH_MODE_SCAN}
    @ Param: search direction.


    * <P>
    * @ Return if the search starts successfully, false if the search fails to start.
    @ See # searchStations (int, int)
    @ See # searchStationList
    */

    public boolean searchStations (int mode,int dwellPeriod,int direction)public boolean searchStations (int mode,int dwellPeriod,int direction,int pty,int pi)


    /** Start the Site List search operation.
    * <P> This method starts a search to generate an FM band found in the frequency list of strong and weak radio stations.
    * <P>
    * <Ul>
    * This API is used to generate a site list, including:
    *

  • Strong site (FM_RX_SRCHLIST_MODE_STRONGFM_RX_SRCHLIST_MODE_STRONGEST)
    *
  • Weak site (FM_RX_SRCHLIST_MODE_WEAKFM_RX_SRCHLIST_MODE_WEAKEST)
    * </Ul>
    * <P>

    * The Scan Frequency Range depends on the current band. The driver searches for all valid stations in the band and returns a channel list based on the customer's choice. The client can search for the strongest radio list band, the weakest radio station of the band, or the nth strength. By setting the maximumStations parameter, the client can limit the number of returned frequencies in the list. If you specify the maximumStations 0 parameter, the search will generate the maximum number of sites.


    * <P>

    * Each time the driver starts a list-based search, the client sends a FmRxEvSearchInProgress event notification. Similarly, after each list-based search is complete, the client sends a notification through the FmRxEvSearchListComplete event.
    * <P>
    * After the search is completed, the initial tuning station will tune and generate the event as follows: FmRxEvSearchListComplete -- the search is completed. FmRxEvRadioTuneStatus -- re-tuned initial frequency.


    * <P>
    * Once a search command is issued, multiple commands may not be allowed from the client until the search is completed or canceled.
    * <P>

    The search API cancelSearch () can be canceled at any time (). Canceling a search is deemed to have completed the search and the event will be generated as follows: FmRxEvSearchComplete -- the search is complete. FmRxEvRadioTuneStatus -- re-tuned initial frequency.
    * <P>
    * Valid parameter value "Mode ":
    * <Ul>
    *
  • {@ Link # FM_RX_SRCHLIST_MODE_STRONG}
    *
  • {@ Link # FM_RX_SRCHLIST_MODE_WEAK}
    *
  • {@ Link # FM_RX_SRCHLIST_MODE_STRONGEST}
    *
  • {@ Link # FM_RX_SRCHLIST_MODE_WEAKEST}
    *
  • FM_RX_SRCHLIST_MODE_PTY (will it be implemented in the future)
    * </Ul>
    * <P>
    * Valid parameter value "direction ":

    * <Ul>
    *

  • {@ Link # FM_RX_SEARCHDIR_DOWN}
    *
  • {@ Link # FM_RX_SEARCHDIR_UP}
    * </Ul>
    * <P>
    * Valid parameter values: "maximumStations": 1-12

    <P>
    * @ Param mode: the FM search mode.
    @ Param: search direction.
    @ Param maximumStations the maximum number of stations that can be returned from the search. This parameter is ignored and 12 stations return FM_RX_SRCHLIST_MODE_STRONGEST or FM_RX_SRCHLIST_MODE_WEAKEST if the search mode
    @ Param: Type of the enterprise fm rds search program (not used currently)
    * <P>

    * @ Return if the search starts successfully, false if the search fails to start.
    @ See # searchStations (int, int, int)
    @ See # searchStations (int, int)
    */

    public boolean searchStationList (int mode,int direction,int maximumStations,int pty)


    /**
    * Cancels ongoing search operations (scanning, searching for searchlist, and so on ).
    * <P>

    * This method should be used to cancel the previous search (such as Basic Search/scan, RDS search/scan, search list, and so on ).
    * <P>
    Once completed, this command will generate a FmRxEvSearchCancelledtr event for all registered customers. After this event, the client can also receive the search event and the relevant search is being completed.
    *
    * <P>
    * @ Return if the unsearch is successfully started, if the unsearch fails to start.
    @ See # searchStations (int, int, int)
    @ See # searchStations (int, int, int)
    @ See # searchStationList
    */

    Disable search change status

    publicboolean cancelSearch ()


    /**
    * Allows mute and non-mute of FM receivers.
    * <P>
    * This is a synchronous command for mute or un-mute FM audio. This command weakens the source of the FM audio device. It is important to note that this will only affect the use of FM audio instead of other audio systems.
    * <P>
    * @ Param: sets the application mode in the silent mode.
    * <P>
    @ Return true: If setMuteMode is successfully called, if setMuteMode fails.
    @ See # enable
    @ See # registerClient
    */

    public boolean setMuteMode (int mode)


    /**

    * Set the single-channel/stereo mode of FM.
    *
    * <P>
    * This command allows you to set the single-channel/stereo mode FM device. With this feature, you can allow single-channel/stereo sound mixing or single-channel audio reception.
    @ Param stereoEnable: supports stereo, Mono error: Power
    @ Return true if setStereoMode is successfully called and put, false if setStereoMode fails.
    */

    public boolean setStereoMode (booleanstereoEnable)


    Returns the current apsaradb for RDS/RBDS plan service.

    publicFmRxRdsData  getPSInfo()


    /**
    * This function returns a list of frequencies.
    *
    * <P>
    * The result obtained by this method is {@ link # searchStationList }. This method should be called when FmRxEvSearchListComplete is called.
    * <P>
    * @ Return is an integer array that searches for radio stations at the corresponding frequency.
    @ See # searchStationList
    */

    public int[] getStationList ()


    /**
    * This function returns the signal strength of the current device.

    *
    * <P>
    * This method returns the current signal intensity tuning.
    * <P>
    * Currently, @ return RSSI is tuned.
    */

    public intgetRssi()


  • Related Article

    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.