Example #1
0
        ////////////////////////////////////////////////////////////////////////////////
        // ChannelResponse
        //
        // Called whenever a channel event is recieved.
        //
        // response: ANT message
        ////////////////////////////////////////////////////////////////////////////////
        public void ChannelResponse(ANT_Response response)
        {
            try
            {
                switch ((ANT_ReferenceLibrary.ANTMessageID)response.responseID)
                {
                case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40:
                {
                    switch (response.getChannelEventCode())
                    {
                    // This event indicates that a message has just been
                    // sent over the air. We take advantage of this event to set
                    // up the data for the next message period.
                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TX_0x03:
                    {
                        txBuffer[0]++;          // Increment the first byte of the buffer

                        // Broadcast data will be sent over the air on
                        // the next message period
                        if (bBroadcasting)
                        {
                            channel0.sendBroadcastData(txBuffer);

                            if (bDisplay)
                            {
                                // Echo what the data will be over the air on the next message period
                                Console.WriteLine("Tx: (" + response.antChannel.ToString() + ")" + BitConverter.ToString(txBuffer));
                            }
                        }
                        else
                        {
                            string[] ac = { "|", "/", "_", "\\" };
                            Console.Write("Tx: " + ac[iIndex++] + "\r");
                            iIndex &= 3;
                        }
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_SEARCH_TIMEOUT_0x01:
                    {
                        Console.WriteLine("Search Timeout");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_0x02:
                    {
                        Console.WriteLine("Rx Fail");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_RX_FAILED_0x04:
                    {
                        Console.WriteLine("Burst receive has failed");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_COMPLETED_0x05:
                    {
                        Console.WriteLine("Transfer Completed");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_FAILED_0x06:
                    {
                        Console.WriteLine("Transfer Failed");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07:
                    {
                        // This event should be used to determine that the channel is closed.
                        Console.WriteLine("Channel Closed");
                        Console.WriteLine("Unassigning Channel...");
                        if (channel0.unassignChannel(500))
                        {
                            Console.WriteLine("Unassigned Channel");
                            Console.WriteLine("Press enter to exit");
                            bDone = true;
                        }
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_GO_TO_SEARCH_0x08:
                    {
                        Console.WriteLine("Go to Search");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_COLLISION_0x09:
                    {
                        Console.WriteLine("Channel Collision");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_START_0x0A:
                    {
                        Console.WriteLine("Burst Started");
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Unhandled Channel Event " + response.getChannelEventCode());
                        break;
                    }
                    }
                    break;
                }

                case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
                case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
                case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_BURST_DATA_0x5F:

                {
                    if (bDisplay)
                    {
                        if (response.isExtended())                              // Check if we are dealing with an extended message
                        {
                            ANT_ChannelID chID = response.getDeviceIDfromExt(); // Channel ID of the device we just received a message from

                            if (chID.deviceTypeID == 120)
                            {
                                this.Heartrate = System.Convert.ToString(response.getDataPayload()[7]);                               // Device type for HR monitor is 120
                            }
                            else if (chID.deviceTypeID == 11)
                            {
                                if (response.getDataPayload()[0] == 10)
                                {
                                    this.pwr     = response.getDataPayload()[7];
                                    this.cadence = response.getDataPayload()[4];
                                }
                            }

                            if (chID.deviceTypeID == 120)
                            {
                                this.Heartrate = System.Convert.ToString(response.getDataPayload()[7]);
                            }
                            Console.Write("Chan ID(" + chID.deviceNumber.ToString() + "," + chID.deviceTypeID.ToString() + "," + chID.transmissionTypeID.ToString() + ") - ");
                        }
                        if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E ||
                            response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D)
                        {
                            Console.Write("Rx:(" + response.antChannel.ToString() + "): ");
                        }
                        else if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F ||
                                 response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E)
                        {
                            Console.Write("Acked Rx:(" + response.antChannel.ToString() + "): ");
                        }
                        else
                        {
                            Console.Write("Burst(" + response.getBurstSequenceNumber().ToString("X2") + ") Rx:(" + response.antChannel.ToString() + "): ");
                        }

                        //Console.Write(BitConverter.ToString(response.getDataPayload()) + Environment.NewLine);  // Display data payload
                        Console.Write("  Heart Rate is: " + this.Heartrate + Environment.NewLine);
                    }
                    else
                    {
                        string[] ac = { "|", "/", "_", "\\" };
                        Console.Write("Rx: " + ac[iIndex++] + "\r");
                        iIndex &= 3;
                    }
                    break;
                }

                default:
                {
                    Console.WriteLine("Unknown Message " + response.responseID);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Channel response processing failed with exception: " + ex.Message);
            }
        }
Example #2
0
File: ANT.cs Project: HubWhale/Bike
        private static void Tramp_ChannelResponse(ANT_Response response)
        {
            try
            {
                ANT_ReferenceLibrary.ANTMessageID responseID = (ANT_ReferenceLibrary.ANTMessageID)response.responseID;
                if (responseID != ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40)
                {
                    switch (responseID)
                    {
                    case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
                    case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
                    case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50:
                        break;

                    default:
                        switch (responseID)
                        {
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D:
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_BURST_DATA_0x5F:
                            break;

                        default:
                            goto IL_226;
                        }
                        break;
                    }
                    bool flag = ANT.bDisplay;
                    if (flag)
                    {
                        bool flag2 = response.isExtended();
                        if (flag2)
                        {
                            ANT_ChannelID chID = response.getDeviceIDfromExt();
                        }
                        bool flag3 = response.responseID == 78 || response.responseID == 93;
                        if (!flag3)
                        {
                            bool flag4 = response.responseID == 79 || response.responseID == 94;
                            if (flag4)
                            {
                            }
                        }
                    }
                    else
                    {
                        string[] expr_1F2 = new string[]
                        {
                            "|",
                            "/",
                            "_",
                            "\\"
                        };
                        ANT.iIndex &= 3;
                    }
                }
                else
                {
                    switch (response.getChannelEventCode())
                    {
                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_SEARCH_TIMEOUT_0x01:
                        MessageBox.Show("Search Timeout");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TX_0x03:
                    {
                        byte[] expr_8A_cp_0 = ANT.txBuffer;
                        int    expr_8A_cp_1 = 0;
                        expr_8A_cp_0[expr_8A_cp_1] += 1;
                        bool flag5 = ANT.bBroadcasting;
                        if (flag5)
                        {
                            ANT.channel1.sendBroadcastData(ANT.txBuffer);
                            bool flag6 = ANT.bDisplay;
                            if (flag6)
                            {
                            }
                        }
                        else
                        {
                            string[] ac = new string[]
                            {
                                "|",
                                "/",
                                "_",
                                "\\"
                            };
                            Console.Write("Tx: " + ac[ANT.iIndex++] + "\r");
                            ANT.iIndex &= 3;
                        }
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_RX_FAILED_0x04:
                        MessageBox.Show("Burst receive has failed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_COMPLETED_0x05:
                        MessageBox.Show("Transfer Completed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_FAILED_0x06:
                        MessageBox.Show("Transfer Failed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07:
                    {
                        bool flag7 = ANT.channel1.unassignChannel(500u);
                        if (flag7)
                        {
                            ANT.bDone = true;
                        }
                        break;
                    }
                    }
                }
                IL_226 :;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Channel response processing failed with exception: " + ex.Message);
            }
        }
Example #3
0
        private static void ChannelResponse(ANT_Response response)
        {
            try
            {
                ANT_ReferenceLibrary.ANTMessageID responseID = (ANT_ReferenceLibrary.ANTMessageID)response.responseID;
                if (responseID != ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40)
                {
                    switch (responseID)
                    {
                    case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
                    case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
                    case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50:
                        break;

                    default:
                        switch (responseID)
                        {
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D:
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
                        case ANT_ReferenceLibrary.ANTMessageID.EXT_BURST_DATA_0x5F:
                            break;

                        default:
                            goto IL_2C9;
                        }
                        break;
                    }
                    bool flag = ANT_TAPING.bDisplay;
                    if (flag)
                    {
                        bool flag2 = response.isExtended();
                        if (flag2)
                        {
                            ANT_ChannelID chID = response.getDeviceIDfromExt();
                        }
                        bool flag3 = response.responseID == 78 || response.responseID == 93;
                        if (!flag3)
                        {
                            bool flag4 = response.responseID == 79 || response.responseID == 94;
                            if (flag4)
                            {
                            }
                        }
                        byte time_MSB  = response.messageContents[6];
                        byte time_LSB  = response.messageContents[5];
                        int  Time      = ((int)time_MSB << 8) + (int)time_LSB;
                        byte count_MSB = response.messageContents[8];
                        byte count_LSB = response.messageContents[7];
                        int  Count     = ((int)count_MSB << 8) + (int)count_LSB;
                        bool flag5     = ANT_TAPING.time_Last == 0 || ANT_TAPING.time_Last == Time;
                        if (flag5)
                        {
                            ANT_TAPING.time_Last  = Time;
                            ANT_TAPING.count_Last = Count;
                        }
                        else
                        {
                            int tramp = (Count - ANT_TAPING.count_Last) * 60 * 1024 / (Time - ANT_TAPING.time_Last);
                            ANT_TAPING.time_Last  = Time;
                            ANT_TAPING.count_Last = Count;
                        }
                        ANT_TAPING.Tramp = ANT_TAPING.Tramp.ToString();
                    }
                    else
                    {
                        string[] expr_295 = new string[]
                        {
                            "|",
                            "/",
                            "_",
                            "\\"
                        };
                        ANT_TAPING.iIndex &= 3;
                    }
                }
                else
                {
                    switch (response.getChannelEventCode())
                    {
                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_SEARCH_TIMEOUT_0x01:
                        MessageBox.Show("Search Timeout");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TX_0x03:
                    {
                        byte[] expr_8A_cp_0 = ANT_TAPING.txBuffer;
                        int    expr_8A_cp_1 = 0;
                        expr_8A_cp_0[expr_8A_cp_1] += 1;
                        bool flag6 = ANT_TAPING.bBroadcasting;
                        if (flag6)
                        {
                            ANT_TAPING.channel0.sendBroadcastData(ANT_TAPING.txBuffer);
                            bool flag7 = ANT_TAPING.bDisplay;
                            if (flag7)
                            {
                            }
                        }
                        else
                        {
                            string[] ac = new string[]
                            {
                                "|",
                                "/",
                                "_",
                                "\\"
                            };
                            Console.Write("Tx: " + ac[ANT_TAPING.iIndex++] + "\r");
                            ANT_TAPING.iIndex &= 3;
                        }
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_RX_FAILED_0x04:
                        MessageBox.Show("Burst receive has failed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_COMPLETED_0x05:
                        MessageBox.Show("Transfer Completed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_TRANSFER_TX_FAILED_0x06:
                        MessageBox.Show("Transfer Failed");
                        break;

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07:
                    {
                        bool flag8 = ANT_TAPING.channel0.unassignChannel(500u);
                        if (flag8)
                        {
                            ANT_TAPING.bDone = true;
                        }
                        break;
                    }
                    }
                }
                IL_2C9 :;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Channel response processing failed with exception: " + ex.Message);
            }
        }
Example #4
0
        void ChannelDataResponse(ANT_Response response)
        {
            if (response.isExtended())                              // Check if we are dealing with an extended message
            {
                ANT_ChannelID chID = response.getDeviceIDfromExt(); // Channel ID of the device we just received a message from
                var           pl   = response.getDataPayload();

                if (POWER_DEVICE_TYPE == HRM_DEVICE_TYPE && chID.deviceTypeID == HRM_DEVICE_TYPE) // to debug
                {
                    byte hr = pl[7];

                    // making mock data
                    debug_rawAccumHeartRate += hr;
                    ushort rawAccumPower       = debug_rawAccumHeartRate;
                    byte   rawUpdateEventCount = lastRawUpdateEventCount;
                    rawUpdateEventCount++;

                    var t = ProcessRollOver(rawAccumPower, rawUpdateEventCount);

                    OnAccumPowerReceived(this, t.Item1, t.Item2);
                }
                else if (chID.deviceTypeID == POWER_DEVICE_TYPE)
                {
                    if (pl[0] == STANDARD_POWER_ONLY_DATA_PAGE)
                    {
                        byte rawUpdateEventCount = pl[STANDARD_POWER_ONLY_MSG_UPDATE_EVENT_COUNT_IDX];

                        if (rawUpdateEventCount != lastRawUpdateEventCount)
                        {
                            ushort rawAccumPower = pl[STANDARD_POWER_ONLY_MSG_ACCUMLATED_POWER_MSB_IDX];
                            rawAccumPower = (ushort)((rawAccumPower << 8) + pl[STANDARD_POWER_ONLY_MSG_ACCUMLATED_POWER_LSB_IDX]);
                            var t = ProcessRollOver(rawAccumPower, rawUpdateEventCount);
                            OnAccumPowerReceived(this, t.Item1, t.Item2);
                        }
                    }
                }
                if (!onceConnected)
                {
                    onceConnected = true;
                    channel.setChannelSearchTimeout(255); // infinite
                    OnSearchEnded(this, true, chID.deviceNumber);
                }
                Debug.Write("Ch ID(" + chID.deviceNumber.ToString() + "," + chID.deviceTypeID.ToString() + "," + chID.transmissionTypeID.ToString() + ") - ");
            }

            switch ((ANTMessageID)response.responseID)
            {
            case ANTMessageID.BROADCAST_DATA_0x4E:
            case ANTMessageID.EXT_BROADCAST_DATA_0x5D:
                Debug.Write("Rx:(" + response.antChannel.ToString() + "): ");
                break;

            case ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
            case ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
                Debug.Write("Acked Rx:(" + response.antChannel.ToString() + "): ");
                break;

            default:
                Debug.Write("Burst(" + response.getBurstSequenceNumber().ToString("X2") + ") Rx:(" + response.antChannel.ToString() + "): ");
                break;
            }

            Debug.WriteLine(BitConverter.ToString(response.getDataPayload()));
        }
Example #5
0
        void ChannelResponseVelocita(ANT_Response response)
        {
            try
            {
                switch ((ANT_ReferenceLibrary.ANTMessageID)response.responseID)
                {
                case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40:
                {
                    switch (response.getChannelEventCode())
                    {
                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_SEARCH_TIMEOUT_0x01:
                    {
                        Console.WriteLine("Search Timeout");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_0x02:
                    {
                        workerDebug.RunWorkerAsync(argument: new object[] { "RX Failed", 1 });
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07:
                    {
                        // This event should be used to determine that the channel is closed.
                        Console.WriteLine("Channel Closed");
                        Console.WriteLine("Unassigning Channel...");
                        if (channel1.unassignChannel(500))
                        {
                            Console.WriteLine("Unassigned Channel");
                            Console.WriteLine("Press enter to exit");
                        }
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_GO_TO_SEARCH_0x08:
                    {
                        Console.WriteLine("Go to Search");
                        break;
                    }

                    case ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_COLLISION_0x09:
                    {
                        Console.WriteLine("Channel Collision");
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Unhandled Channel Event " + response.getChannelEventCode());
                        break;
                    }
                    }
                    break;
                }

                case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
                case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F:
                case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E:
                case ANT_ReferenceLibrary.ANTMessageID.EXT_BURST_DATA_0x5F:
                {
                    if (true)
                    {
                        if (response.isExtended())                              // Check if we are dealing with an extended message
                        {
                            ANT_ChannelID chID = response.getDeviceIDfromExt(); // Channel ID of the device we just received a message from
                            Console.Write("Chan ID(" + chID.deviceNumber.ToString() + "," + chID.deviceTypeID.ToString() + "," + chID.transmissionTypeID.ToString() + ") - ");
                        }
                        if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E ||
                            response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.EXT_BROADCAST_DATA_0x5D)
                        {
                            Console.Write("Rx:(" + response.antChannel.ToString() + "): ");            //questo รจ quello importante
                        }
                        else if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F ||
                                 response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.EXT_ACKNOWLEDGED_DATA_0x5E)
                        {
                            Console.Write("Acked Rx:(" + response.antChannel.ToString() + "): ");
                        }
                        else
                        {
                            Console.Write("Burst(" + response.getBurstSequenceNumber().ToString("X2") + ") Rx:(" + response.antChannel.ToString() + "): ");
                        }

                        isMoving = checkMovement(response.getDataPayload());

                        velocita = calcolaVelocita(response.getDataPayload());

                        if (!worker.IsBusy)
                        {
                            worker.RunWorkerAsync(argument: new object[] { velocita, 1 });
                            Thread.Sleep(100);          //added this to avoid calling the worker while its busy. yeah, i know, its not an elegant solution but this is what i can do at the moment :)
                        }


                        workerDebug.RunWorkerAsync(argument: new object[] { "RX Success", 1 });

                        setPower(calcolaVelocita(response.getDataPayload()));
                    }

                    break;
                }

                default:
                {
                    Console.WriteLine("Unknown Message " + response.responseID);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Channel response processing failed with exception: " + ex.Message);
            }
        }