void antChannel_channelResponse_FeSearch(ANT_Response response) { switch ((ANT_ReferenceLibrary.ANTMessageID)response.responseID) { case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E: AntPlus_Connection newConn = deviceList[searchingDeviceIndex]; ANT_Response idResp = null; try { idResp = antStick.requestMessageAndResponse(searchChannel.getChannelNum(), ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 1000); } catch (Exception) { //Don't know what to do if we can't get id...could retry somewhere... break; } lock (newConn) { searchChannel.channelResponse -= antChannel_channelResponse_FeSearch; newConn.dataSource.searchProfile.deviceNumber = (ushort)(idResp.messageContents[1] + ((ushort)idResp.messageContents[2] << 8)); //Save to the search profile so we keep this id after dropouts newConn.connectedChannel = searchChannel; //Note: the low pri search happens before the high pri, so this isn't even doing anything. //newConn.connectedChannel.setChannelSearchTimeout(2, 500); //If we drop, we really want it back soon because it may be in use in a race, but we can't afford to ruin other channels staying in high priority. With the default search waveform, 5s is supposed to give us a really good rate of acquisition newConn.connectedChannel.setLowPrioritySearchTimeout(255, 500); //Search indefinitely newConn.antChannel_channelResponse_DataFetch(response); newConn.connectedChannel.channelResponse += newConn.antChannel_channelResponse_DataFetch; newConn.setConnStatus(AntPlus_Connection.ConnState.Connected); } searchChannel = null; //invalidate this channel as a search channel startNextSearch(); break; case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40: if (response.messageContents[1] == (byte)ANT_ReferenceLibrary.ANTMessageID.EVENT_0x01) { //if(response.messageContents[2] == 0x01) //Search timeout causes close channel, so wait for that if (response.messageContents[2] == (byte)ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07) //Closed channel { startNextSearch(); } } break; } }
public void resetConnection(AntPlus_Connection connToReset, ushort searchForDeviceNum = 0) { lock (connToReset) { if (connToReset.connectedChannel != null) { connToReset.connectedChannel.channelResponse -= connToReset.antChannel_channelResponse_DataFetch; connToReset.connectedChannel.closeChannel(500); connToReset.connectedChannel.unassignChannel(500); connToReset.connectedChannel = null; connToReset.dataSource.isInitialized = false; //Invalidate the buffers connToReset.dataSource.reset(); } connToReset.dataSource.searchProfile.deviceNumber = searchForDeviceNum; connToReset.setConnStatus(AntPlus_Connection.ConnState.Closed); } startNextSearch(); }