Example #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();
        }
Example #2
0
        internal void ConfigureANT()
        {
            Console.WriteLine("Resetting module 0 ...");
            device0.ResetSystem();
            System.Threading.Thread.Sleep(500);

            Console.WriteLine("Setting network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Console.WriteLine("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            Console.WriteLine("Setting Channel ID...");
            channel0.setChannelSearchTimeout((byte)100, 100);
            if (channel0.setChannelID(0, false, 40, 0, 8192))
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                Console.WriteLine("Error configuring Channel ID");
            }

            radarEquipmentDisplay = new BikeRadarDisplay(channel0, networkAntPlus);

            radarEquipmentDisplay.DataPageReceived          += radarEquipment_DataPageReceived;
            radarEquipmentDisplay.RadarSensorFound          += radarEquipment_Found;
            radarEquipmentDisplay.RadarTargetsAPageReceived += radarEquipment_RadarTargetsAPageReceived;
            radarEquipmentDisplay.RadarTargetsBPageReceived += radarEquipment_RadarTargetsBPageReceived;
            radarEquipmentDisplay.TurnOn();
        }
Example #3
0
 public void Init()
 {
     usbDevice = new ANT_Device();
     usbDevice.ResetSystem();
     usbDevice.setNetworkKey(0, NETWORK_KEY);
     network = new AntPlus.Types.Network(0, NETWORK_KEY, CHANNEL_FREQUENCY);
 }
Example #4
0
 public void Reconnect(ANT_Device previousDevice)
 {
     device = previousDevice;
     device.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
     device.serialError    += new ANT_Device.dSerialErrorHandler(SerialErrorHandler);
     device.ResetSystem();
     device.setNetworkKey(0, NETWORK_KEY, 500);
 }
Example #5
0
    public void Reconnect(ANT_Device previousDevice)
    {
        int usbNum = previousDevice.getOpenedUSBDeviceNum();

        devices[usbNum] = previousDevice;
        previousDevice.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
        previousDevice.serialError    += new ANT_Device.dSerialErrorHandler(SerialErrorHandler);
        previousDevice.ResetSystem();
        previousDevice.setNetworkKey(0, NETWORK_KEY, 500);
    }
Example #6
0
    public void Init()
    {
        messageQueue = new Queue <ANT_Response>(16);
        errorQueue   = new Queue <SerialError>(16);
        channelList  = new List <AntChannel>();

        //init the device
        if (device == null)
        {
            device = new ANT_Device();
            device.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
            device.serialError    += new ANT_Device.dSerialErrorHandler(SerialErrorHandler);
            device.ResetSystem();
            device.setNetworkKey(0, NETWORK_KEY, 500);
        }
    }
Example #7
0
        public Network()
        {
            device = new ANT_Device();                                                      // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)
            device.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse); // Add device response function to receive protocol event messages

            device.ResetSystem();                                                           // Soft reset
            System.Threading.Thread.Sleep(500);                                             // Delay 500ms after a reset

            // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
            // This function is blocking - the thread will be blocked while waiting for a response.
            // 500ms is usually a safe value to ensure you wait long enough for any response
            // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
            if (!device.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                throw new Exception("Error configuring network key");
            }

            device.enableRxExtendedMessages(true);
        }
        private static void ConfigureANT()
        {
            Console.WriteLine("Resetting module 0 ...");
            device0.ResetSystem();
            System.Threading.Thread.Sleep(500);

            Console.WriteLine("Setting network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Console.WriteLine("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            Console.WriteLine("Setting Channel ID...");
            if (channel0.setChannelID(1, false, 17, 0, 8192))
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            Console.WriteLine("Setting Channel ID...");
            if (channel1.setChannelID(1, false, 11, 5, 8182))
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            fitnessEquipmentDisplay = new FitnessEquipmentDisplay(channel0, networkAntPlus);
            fitnessEquipmentDisplay.SpecificTrainerPageReceived += FitnessEquipmentDisplay_SpecificTrainerPage;
            fitnessEquipmentDisplay.TurnOn();

            bikePowerOnlySensor = new BikePowerOnlySensor(channel1, networkAntPlus);
            bikePowerOnlySensor.TurnOn();
        }
Example #9
0
        /*  public static async void SendDeviceProperties()
         * {
         *    try
         *    {
         *        Console.WriteLine("Sending device properties:");
         *        Random random = new Random();
         *        TwinCollection telemetryConfig = new TwinCollection();
         *        reportedProperties["DeviceProperty"] = random.Next(1, 6);
         *        Console.WriteLine(JsonConvert.SerializeObject(reportedProperties));
         *
         *        await Client.UpdateReportedPropertiesAsync(reportedProperties);
         *    }
         *    catch (Exception ex)
         *    {
         *        Console.WriteLine();
         *        Console.WriteLine("Error in sample: {0}", ex.Message);
         *    }
         * }
         */

        private static async void SendTelemetryAsync(CancellationToken token)
        {
            try
            {
                //ANT Part
                byte USER_RADIOFREQ = 57;                                                     // RF Frequency + 2400 MHz
                //ANTPLUS KEY
                byte[] USER_NETWORK_KEY = { 0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45 }; // key
                byte   USER_NETWORK_NUM = 0;
                //Use USB dongle to connect ANT+ device
                ANT_Device USB_Dongle;
                USB_Dongle = new ANT_Device();
                USB_Dongle.ResetSystem();
                USB_Dongle.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY);
                ANT_Channel      Channel0       = USB_Dongle.getChannel(0);
                Network          AntPlusNetwork = new Network(USER_NETWORK_NUM, USER_NETWORK_KEY, USER_RADIOFREQ);
                HeartRateDisplay HR             = new HeartRateDisplay(Channel0, AntPlusNetwork);
                HR.TurnOn();
                Console.WriteLine(">>ANT+ Tuen on...");

                while (true)
                {
                    byte currentHeartbeat   = HR.HeartRate;
                    var  telemetryDataPoint = new
                    {
                        heartbeat = currentHeartbeat,
                    };
                    var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                    var message       = new Message(Encoding.ASCII.GetBytes(messageString));
                    token.ThrowIfCancellationRequested();
                    await Client.SendEventAsync(message);

                    Console.WriteLine("{0} > Sending heartbeat signal : {1}", DateTime.Now, messageString);
                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("Intentional shutdown: {0}", ex.Message);
            }
        }
Example #10
0
        public void Start()
        {
            try
            {
                usbDevice = new ANT_Device();
                usbDevice.ResetSystem();
                usbDevice.setNetworkKey(0, NETWORK_KEY);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.Read();
                return;
            }

            network = new AntPlus.Types.Network(0, NETWORK_KEY, CHANNEL_FREQUENCY);
            Console.WriteLine(ConfigurationManager.AppSettings["model"]);
            if (ConfigurationManager.AppSettings["ridermodel"] == "fec")
            {
                Console.WriteLine("Using FEC for physical model.");
                bikeModel = BikeModel.FEC;
            }
            else if (ConfigurationManager.AppSettings["ridermodel"] == "physics")
            {
                Console.WriteLine("Using integrated model for physical model.");
                bikeModel = BikeModel.BikePhysics;
            }

            AntManagerState.Initialize(Single.Parse(ConfigurationManager.AppSettings["cp"]));

            InitHRM(0);
            InitCAD(1);
            InitFEC(2);
            InitBP(3);
            InitSC(4);
            InitAC();
            InitFIT();
        }
Example #11
0
        static void Main(string[] args)
        {
            byte USER_RADIOFREQ = 57;           // RF Frequency + 2400 MHz

            //Do not distrubute this key
            byte[] USER_NETWORK_KEY = { 0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45 };
            byte   USER_NETWORK_NUM = 0;

            ANT_Device USB_Dongle;

            USB_Dongle = new ANT_Device();
            USB_Dongle.ResetSystem();
            USB_Dongle.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY);
            ANT_Channel      Channel0       = USB_Dongle.getChannel(0);
            Network          AntPlusNetwork = new Network(USER_NETWORK_NUM, USER_NETWORK_KEY, USER_RADIOFREQ);
            HeartRateDisplay HeartRate      = new HeartRateDisplay(Channel0, AntPlusNetwork);

            HeartRate.TurnOn();
            while (Console.KeyAvailable == false)
            {
                Console.WriteLine("Heart Rate=" + HeartRate.HeartRate);
                System.Threading.Thread.Sleep(500);
            }
        }
Example #12
0
        ////////////////////////////////////////////////////////////////////////////////
        // ConfigureANT
        //
        // Resets the system, configures the ANT channel and starts the demo
        ////////////////////////////////////////////////////////////////////////////////
        private static void ConfigureANT()
        {
            Console.WriteLine("Resetting module...");
            device0.ResetSystem();              // Soft reset
            System.Threading.Thread.Sleep(500); // Delay 500ms after a reset

            // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
            // This function is blocking - the thread will be blocked while waiting for a response.
            // 500ms is usually a safe value to ensure you wait long enough for any response
            // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
            Console.WriteLine("Setting network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Console.WriteLine("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            Console.WriteLine("Assigning channel...");
            if (channel0.assignChannel(channelType, USER_NETWORK_NUM, 500))
            {
                Console.WriteLine("Channel assigned");
            }
            else
            {
                throw new Exception("Error assigning channel");
            }

            Console.WriteLine("Setting Channel ID...");
            if (channel0.setChannelID(user_devicenum, false, user_devicetype, USER_TRANSTYPE, 500))  // Not using pairing bit
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            Console.WriteLine("Setting Radio Frequency...");
            if (channel0.setChannelFreq(USER_RADIOFREQ, 500))
            {
                Console.WriteLine("Radio Frequency set");
            }
            else
            {
                throw new Exception("Error configuring Radio Frequency");
            }

            Console.WriteLine("Setting Channel Period...");
            if (channel0.setChannelPeriod(user_channelperiod, 500))
            {
                Console.WriteLine("Channel Period set");
            }
            else
            {
                throw new Exception("Error configuring Channel Period");
            }

            Console.WriteLine("Opening channel...");
            bBroadcasting = true;
            if (channel0.openChannel(500))
            {
                Console.WriteLine("Channel opened");
            }
            else
            {
                bBroadcasting = false;
                throw new Exception("Error opening channel");
            }

#if (ENABLE_EXTENDED_MESSAGES)
            // Extended messages are not supported in all ANT devices, so
            // we will not wait for the response here, and instead will monitor
            // the protocol events
            Console.WriteLine("Enabling extended messages...");
            device0.enableRxExtendedMessages(true);
#endif
        }
Example #13
0
        ////////////////////////////////////////////////////////////////////////////////
        // ConfigureANT
        //
        // Resets the system, configures the ANT channel and starts the demo
        ////////////////////////////////////////////////////////////////////////////////
        private static void ConfigureANT()
        {
            Console.WriteLine("Resetting module...");
            device0.ResetSystem();              // Soft reset
            System.Threading.Thread.Sleep(500); // Delay 500ms after a reset

            // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
            // This function is blocking - the thread will be blocked while waiting for a response.
            // 500ms is usually a safe value to ensure you wait long enough for any response
            // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
            Console.WriteLine("Setting network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Console.WriteLine("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            Console.WriteLine("Assigning channel...");
            if (channel0.assignChannel(channelType, USER_NETWORK_NUM, 500))
            {
                Console.WriteLine("Channel assigned");
            }
            else
            {
                throw new Exception("Error assigning channel");
            }

            Console.WriteLine("Setting Channel ID...");
            if (channel0.setChannelID(USER_DEVICENUM, false, USER_DEVICETYPE, USER_TRANSTYPE, 500))  // Not using pairing bit
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            Console.WriteLine("Setting Radio Frequency...");
            if (channel0.setChannelFreq(USER_RADIOFREQ, 500))
            {
                Console.WriteLine("Radio Frequency set");
            }
            else
            {
                throw new Exception("Error configuring Radio Frequency");
            }

            Console.WriteLine("Setting Channel Period...");
            if (channel0.setChannelPeriod(USER_CHANNELPERIOD, 500))
            {
                Console.WriteLine("Channel Period set");
            }
            else
            {
                throw new Exception("Error configuring Channel Period");
            }

            Console.WriteLine("Opening channel...");
            bBroadcasting = true;
            if (channel0.openChannel(500))
            {
                Console.WriteLine("Channel opened");
            }
            else
            {
                bBroadcasting = false;
                throw new Exception("Error opening channel");
            }
        }