Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

createNewChannel code sometimes doesnt capture the channel

Rank

Total Posts: 4

Joined 2010-06-24

PM

Hi,

Ive got the ANT Sample_AcquireChannels app compiling, running on the Android tablet and talking to ANTware.
I have stripped back the UI to the bare bones to work out what I need to add into my own application to support ANT.
Rather than have a button to open a channel, I want to do this as soon as my app starts up. So I added the "addNewChannel(mCreateAntChannelAsMaster);" line into the end of the onServiceConnected function. At this point I had assumed that everything is setup and ready to run. However probably 1 in 5 times it doesnt work and after debugging into the code, I found that in ChannelService.java in createNewChannel, I enter the following IF statement.

if(null == antChannelController)
{
Log.e(TAG, "null == antChannelController");
return null;
}

So my question is, how should i open up the ANT channel without user intervention? Do I just wait one second until after the connection to the service or is there a better way?      
Rank

Total Posts: 4

Joined 2013-05-07

PM

At the end of the onServiceConnected() method, the ANT Radio Service may still be initializing and will have no channels available which is why antChannelController would be null.

Before you addNewChannel(), you should first check if there are channels available by calling the getNumberOfChannelsAvailable() method in AntChannelProvider. A broadcast receiver should also be implemented to receive updates on the number of channels available. Listen for intents with the ACTION_CHANNEL_PROVIDER_STATE_CHANGED action. The received intent contains an extra that you can use to see the number of channels available and is accessible from the intent.getIntExtra() method with the NUM_CHANNELS_AVAILABLE key. If you implement the broadcast receiver and wait to receive an intent that indicates channels are available, addNewChannel() should be able to acquire a channel and construct the antChannelController.

Here is the link to the javadoc for AntChannelProvider:
http://www.thisisant.com/APIassets/Android_ANT_API/com/dsi/ant/channel/AntChannelProvider.html

If you are using an ANT USB stick, you should still wait for the ACTION_CHANNEL_PROVIDER_STATE_CHANGED that indicates channels are available. The following thread may be useful to you as well:
http://www.thisisant.com/forum/viewthread/4010/

Hopefully this helps!      
Avatar
RankRankRankRank

Total Posts: 149

Joined 2014-04-02

PM

When I can’t get a channel due to a ChannelNotAvailable reason where there may be a channel later, I wait for a AntChannelProvider.ACTION_CHANNEL_PROVIDER_STATE_CHANGED Intent, and check the AntChannelProvider.NEW_CHANNELS_AVAILABLE extra when it arrives. If this is true, I try and get a channel again.

However, I am seeing that after getting a ChannelNotAvailable reason of SERVICE_INITIALIZING, the next state changed intent has NEW_CHANNELS_AVAILABLE as false.

Is this correct?

ANT Radio Service version = 4.7.0
ANT API version = 4.7.0 or 4.6.0      

Signature

blackramlabs.com

Avatar
RankRankRankRank

Total Posts: 149

Joined 2014-04-02

PM

My current workaround is to keep a waitingForAntServiceToInitialise flag, and skip the 'new channels' check if it is true. The flag is set true when I get a SERVICE_INITIALIZING failure, and false when I can acquire a channel or get a 'state changed' intent.      

Signature

blackramlabs.com

RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Is this when using a USB stick or built-in adapter?      

Signature

Dynastream Developer

Avatar
RankRankRankRank

Total Posts: 149

Joined 2014-04-02

PM

Built-in. I tried on a couple of different phones. I can test with a USB stick, if that helps?      

Signature

blackramlabs.com

RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Ok, we identified the issue. When new adapters are being initialized this flag is not being set. That means this flag is only set to true right now when an in use channel has been released and is ready for use again. We will fix adapters being added to set this flag in the future.

For right now I suggest you check on the NUM_CHANNELS_AVAILABLE parameter instead of trying to make your own state variable. If you don't have any required capabilities you can attempt to acquire a channel any time the number available is > 0, if you do have required capabilities you will want to try the first time you see it > 0, then if you fail after that only try again if you see it increment higher than the previously seen value.      

Signature

Dynastream Developer

Avatar
RankRankRankRank

Total Posts: 149

Joined 2014-04-02

PM

I am not requiring any Capabilities, but I do need to be prepared to handle the case when the public network is not available. As I only want to acquire one channel, I still need to keep my own state variable.

You are saying that this won't only happen while waiting for the ANT service to finish initializing, but also when you have no channels (no native hardware or USB stick, or all channels are in use) and a USB stick is inserted?      

Signature

blackramlabs.com

RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Yes this will happen when a USB stick is inserted, even if the service is already running.      

Signature

Dynastream Developer