Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

[Android] USB Ant Stick-RequestAccess return SEARCH_TIMEOUT

Rank

Total Posts: 1

Joined 2021-01-12

PM

Hi all,
i have implemented an android app when found and connect the sensors with the Ant+ SDK , the code work fine with the device with ant hardware, but i have problem when use the usb ant stick.

The problem is the following:
after create a MultiDeviceSearch object, the SearchCallbacks found the sensors, but when i call the specific requestAccess, the IPluginAccessResultReceiver return a SEARCH_TIMEOUT result.

This is the code for request a FitnessMachine sensor (but the problem is for all device type):

val multiDeviceSearch MultiDeviceSearch(contextdevicesTypecallbacksrssiCallback)

val callbacks object SearchCallbacks {
        override fun onSearchStarted
(p0MultiDeviceSearch.RssiSupport?) {
        }

        override fun onDeviceFound
(p0MultiDeviceSearchResult?) {
            p0
?.let {
                onNewDeviceFound
(p0)
            
}
        }

        override fun onSearchStopped
(p0RequestAccessResult?) {
        }
    }

private fun onNewDeviceFound(multiDeviceSearchResultMultiDeviceSearchResult{

        val id 
multiDeviceSearchResult.antDeviceNumber.toString()
        
val name =
            
"${multiDeviceSearchResult.deviceDisplayName}_${multiDeviceSearchResult.antDeviceType}"


        
val device when (multiDeviceSearchResult.antDeviceType{
            DeviceType
.FITNESS_EQUIPMENT -> {
                AntFitnessEquipmentDevice
(
                    
name name,
                    
id id,
                    
multiDeviceSearchResult multiDeviceSearchResult,
                    
context context
                
)
            
}
            
else -> {
                
//nothing for now
                
null
            }
        }
    } 


this is the AntFitnessEquipmentDevice class

class AntFitnessEquipmentDevice(
    
override val nameString,
    
override val idString,
    
override val multiDeviceSearchResultMultiDeviceSearch.MultiDeviceSearchResult,
    private 
val contextContext
{

    
private var fitnessEquipmentPccAntPlusFitnessEquipmentPcc? = null
    
private var handlePccReleaseHandle<AntPlusFitnessEquipmentPcc>? = null

    
var equipmentTypeAntPlusFitnessEquipmentPcc.EquipmentType UNRECOGNIZED


    
//region Parent Methods
    
override fun requestAccess() {
        handle
?.close()
        
handle AntPlusFitnessEquipmentPcc.requestNewOpenAccess(
            
context,
            
multiDeviceSearchResult.antDeviceNumber,
            
0,
            
resultReceiver,
            
stateChangeReceiver,
            
fitnessEquipmentStateReceiver
        
)
    
}

    override fun release
() {
        fitnessEquipmentPcc
?.releaseAccess()
    
}

    override fun close
() {
        handle
?.close()
    
}

    
//endregion

    //region Private Methods

    
private fun onPcc() {
        fitnessEquipmentPcc
?.let {
            subscribeCommonReceiver
(it)
        
}
    }

    
//endregion

    //region Callback

    //    AntPlusBikeCadencePcc var1,
    //    RequestAccessResult var2,
    //    DeviceState var3
    
private val resultReceiver =
        
AntPluginPcc.IPluginAccessResultReceiver<AntPlusFitnessEquipmentPcc{ pccrequestAccessResultdeviceState ->
            
when (requestAccessResult{
                SUCCESS 
-> {
                    fitnessEquipmentPcc 
pcc
                    actualState 
deviceState
                    onPcc
()
                
}
                DEPENDENCY_NOT_INSTALLED 
-> {
                    
// TODO alert??
                
}
                SEARCH_TIMEOUT 
-> {
                    retryRequestAccess
()
                
}
//                USER_CANCELLED -> {}
//                CHANNEL_NOT_AVAILABLE -> {}
//                OTHER_FAILURE -> {}
//                DEVICE_ALREADY_IN_USE -> {}
//                ALREADY_SUBSCRIBED -> {}
//                BAD_PARAMS -> {}
//                ADAPTER_NOT_DETECTED -> {}
//                UNRECOGNIZED -> {}
                
else -> {
                    
// nothing
                
}
            }
        }

    
private val stateChangeReceiver IDeviceStateChangeReceiver { deviceState ->
        
actualState deviceState
        onChangeState
(deviceState)
    
}

    
//    estTimestamp: Long,
//    eventFlags: EnumSet<EventFlag>?,
//    equipmentType: AntPlusFitnessEquipmentPcc.EquipmentType?,
//    equipmentState: AntPlusFitnessEquipmentPcc.EquipmentState?
    
private val fitnessEquipmentStateReceiver =
        
AntPlusFitnessEquipmentPcc.IFitnessEquipmentStateReceiver { __equipmentTypeequipmentState ->

            
fitnessEquipmentPcc?.let { pcc ->

                
this.equipmentType equipmentType

            }

        }

    
//   estTimestamp: Long,
//   eventFlags: EnumSet<EventFlag>?,
//   capabilities: AntPlusFitnessEquipmentPcc.Capabilities?
    
private val capabilitiesReceiver =
        
AntPlusFitnessEquipmentPcc.ICapabilitiesReceiver { __capabilities ->

            
        
}


//endregion


Can you help me?
Thanks