Beispiel #1
0
        private static void ConfigureANT()
        {
            WriteLog("Configuring ANT communication...");
            WriteLog("Resetting ANT USB Dongle...");
            device0.ResetSystem();              // Soft reset
            System.Threading.Thread.Sleep(500); // Delay 500ms after a reset

            WriteLog("Setting ANT network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                WriteLog("ANT network key setting successful");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            WriteLog("Setting Channel ID...");
            //channel0.setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower.RADIO_TX_POWER_0DB_0x03,500);
            if (channel0.setChannelID(USER_DEVICENUM, USER_PAIRINGENABLED, USER_DEVICETYPE, USER_TRANSTYPE, USER_RESPONSEWAITTIME))  // Not using pairing bit
            {
                WriteLog("Channel ID: " + channel0.getChannelNum());
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            genericControllableDevice = new GenericControllableDevice(channel0, networkAntPlus);
            genericControllableDevice.DataPageReceived += GenericControllableDevice_DataPageReceived;
            genericControllableDevice.TurnOn();
            //CheckUsbDongle();
        }
Beispiel #2
0
        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;
            }
        }