Exemplo n.º 1
0
        public void incrementDistanceAndUpdate(double distToAdd, double speedMs = 0xFFFF, double cadence = -1, byte heartRate = 0xFF, ushort powerW = 0xFFFF)
        {
            if (running)
            {
                if (cadence == -1)
                {
                    cadence = calculateCadence(speedMs);
                }

                distanceTravelled += distToAdd;
                lastPacketRcvd     = new DataSourcePacket(distanceTravelled, speedMs, cadence, heartRate, powerW);
                distanceUpdate(lastPacketRcvd);
            }
            else //Just save the last packet for monitoring purposes
            {
                if (lastPacketRcvd == null)
                {
                    lastPacketRcvd = new DataSourcePacket(distToAdd, speedMs, cadence, heartRate, powerW);
                }
                else
                {
                    lastPacketRcvd = new DataSourcePacket(lastPacketRcvd.distance + distToAdd, speedMs, cadence, heartRate, powerW);
                }
            }
        }
Exemplo n.º 2
0
        internal void updateStats(DataSources.DataSourcePacket data)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                if (data.speed_ms < ushort.MaxValue)
                {
                    if (AntPlusRacerConfig.getInstance().displayMph)
                    {
                        Label_Speed.Content = String.Format("{0:0.0}mph", data.speed_ms * 2.237);
                    }
                    else   //else use real measurement units
                    {
                        Label_Speed.Content = String.Format("{0:0.0}kph", data.speed_ms * 3.6);
                    }
                }

                if (data.power != ushort.MaxValue)
                {
                    Label_Power.Content = String.Format("{0:0}W", data.power);
                }

                if (data.cadence != -1)
                {
                    updateCadence(data.cadence);
                }
            }));
        }
        public void newSpeedSensorPacket(DataSourcePacket pckt)
        {
            double distDiff = pckt.distance - lastDistance;

            if (distDiff > 0)
            {
                incrementDistanceAndUpdate(distDiff, speedMs: pckt.speed_ms, cadence: calculatedCadence);
            }
            lastDistance = pckt.distance;
        }
Exemplo n.º 4
0
        public sealed override void handleChannelResponse(ANT_Response response)
        {
            //Watch for collisions or failures, if we miss a message, interpolate from the last known speed
            if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40 &&
                response.messageContents[1] == (byte)ANT_ReferenceLibrary.ANTMessageID.EVENT_0x01 &&
                (response.messageContents[2] == (byte)ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_0x02 ||
                 response.messageContents[2] == (byte)ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_COLLISION_0x09))
            {
                DataSourcePacket lastData = getLastDataRcvd();
                if (lastData != null)
                {
                    DateTime curEventTime = DateTime.Now;
                    double   timeMissed_s = curEventTime.Subtract(lastEventTime).TotalSeconds;
                    double   distMissed_m = timeMissed_s * averageSpeed; //Use the recent average speed so we get a closer estimate
                    interpolatedDistanceDiff += distMissed_m;

                    lastEventTime = curEventTime;
                    base.incrementDistanceAndUpdate(distMissed_m, averageSpeed, lastData.cadence, lastData.heartRate, lastData.power);

                    ////DEBUG
                    //System.Console.Out.WriteLine((ANT_ReferenceLibrary.ANTEventID)response.messageContents[2] + " interpolated " + distMissed_m);
                }
            }
            if (response.messageContents[2] == (byte)ANT_ReferenceLibrary.ANTEventID.EVENT_RX_FAIL_GO_TO_SEARCH_0x08)
            {
                //Sorry, if we drop to search there is not much we can do to recover, let the race display know we are dead
                base.incrementDistanceAndUpdate(0, 0, 0, 0, 0);
            }
            else //If it is not an rx failure, let the derived class handle it
            {
                //Don't worry about isInitialized=false on rx_drop_to_search here, because we hope the broadcast
                //comes back soon enough for it to not matter, if we have to wait long enough for it to matter,
                //we have waited too long anyway

                ////DEBUG
                //if (response.responseID == (byte)ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40)
                //    System.Console.Out.WriteLine((ANT_ReferenceLibrary.ANTEventID)response.messageContents[2]);
                handleNonRxFailChannelResponse(response);
            }
        }
Exemplo n.º 5
0
 public virtual void reset()
 {
     stop();
     distanceTravelled = 0;
     lastPacketRcvd    = null;
 }