public void ProcessPacket(HRMPacket packet)
        {
            try
            {
                lastPacket = packet;
                bus.Publish(packet);
                logger.Debug(string.Format("published message {0}", packet.ToString()));
                System.Console.WriteLine(string.Format("published message {0}", packet.ToString()));

                var status = new HRMStatus(this, packet);
                bus.Publish(status);
                logger.Debug(string.Format("published message {0}", status.ToString()));
                System.Console.WriteLine(string.Format("published message {0}", status.ToString()));

                this.packetCreated.OnNext(packet);
            }
            catch (Exception exception)
            {
                this.packetCreated.OnError(exception);
            }
        }
示例#2
0
 private static void HandlePacketMessage(HRMPacket obj)
 {
     throw new NotImplementedException();
 }
 private void OnPacketCreated(HRMPacket packet)
 {
     HRMPacket spottedPacket = packet;
 }
        private void ThumpThump()
        {
            lastPacket = new HRMPacket(bpm);

            if (MinHeartRate == null)
            {
                MinHeartRate = (byte)bpm;
            }
            else
            if (bpm < MinHeartRate)
            {
                MinHeartRate = (byte)bpm;
            }

            if (MaxHeartRate == null)
            {
                MaxHeartRate = (byte)bpm;
            }
            else
            if (bpm > MaxHeartRate)
            {
                MaxHeartRate = (byte)bpm;
            }

            if (bpm >= 180)
            {
                maxSlope = 3;
            }
            else if (bpm >= 120)
            {
                maxSlope = 2;
            }
            else
            {
                maxSlope = 1;
            }

            int slopeVar = random.Next(-1, 2);

            slope += slopeVar;
            if (slope > maxSlope)
            {
                slope = maxSlope;
            }
            else if (slope < -maxSlope)
            {
                slope = -maxSlope;
            }
            bpm += slope;

            if (bpm > MAX_BPM)
            {
                bpm   = MAX_BPM;
                slope = 0;
            }
            else if (bpm < MIN_BPM)
            {
                bpm   = MIN_BPM;
                slope = 0;
            }

            TotalPackets++;
            heartBeats += bpm / 60D;
            HeartBeats  = (int)heartBeats;
            ProcessPacket(lastPacket);

#if DEBUG
            logger.Debug("Firing PacketProcessed event, packet = " + lastPacket);
#endif
            base.FirePacketProcessed(new PacketProcessedEventArgs(lastPacket));
        }