/// <summary>
        /// Calculates the average power in W.
        ///
        /// Under normal conditions with complete RF reception, average power equals instantaneous
        /// power. In conditions where packets are lost, average power accurately calculates power
        /// over the interval between the received messages.
        /// </summary>
        /// <param name="message1">The most recent WheelTorqueDataPage message recieved.</param>
        /// <param name="message2">The second most recent WheelTorqueDataPage message recieved.
        /// </param>
        /// <returns>The average power in W.</returns>
        public static float CalculateAvgPower(PowerOnlyDataPage message1, PowerOnlyDataPage message2)
        {
            // See ANT+ Device Profile - Bicycle Power, page 33 (ver. 4.2)
            // https://www.thisisant.com/resources/bicycle-power/

            return(AntUtilFunctions.rolloverDiff(message1.AccumulatedPower, message2.AccumulatedPower) /
                   ((float)AntUtilFunctions.rolloverDiff(message1.UpdateEventCount, message2.UpdateEventCount)));
        }
        void PowerOnlyReceived(object sender, EventArgs e)
        {
            PowerOnlyDataPage powerOnly = (PowerOnlyDataPage)sender;

            if (lastPowerOnly != null)
            {
                float power = PowerOnlyDataPage.CalculateAvgPower(powerOnly, lastPowerOnly);
                if (!float.IsNaN(power))
                    bikeData.AntPWR = power;
            }

            lastPowerOnly = powerOnly;
        }
        /// <summary>
        /// Calculates the average power in W.
        /// 
        /// Under normal conditions with complete RF reception, average power equals instantaneous
        /// power. In conditions where packets are lost, average power accurately calculates power
        /// over the interval between the received messages.
        /// </summary>
        /// <param name="message1">The most recent WheelTorqueDataPage message recieved.</param>
        /// <param name="message2">The second most recent WheelTorqueDataPage message recieved.
        /// </param>
        /// <returns>The average power in W.</returns>
        public static float CalculateAvgPower(PowerOnlyDataPage message1, PowerOnlyDataPage message2)
        {
            // See ANT+ Device Profile - Bicycle Power, page 33 (ver. 4.2)
            // https://www.thisisant.com/resources/bicycle-power/

            return AntUtilFunctions.rolloverDiff(message1.AccumulatedPower, message2.AccumulatedPower) /
                   ((float) AntUtilFunctions.rolloverDiff(message1.UpdateEventCount, message2.UpdateEventCount));
        }