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); } } }
public void newSpeedSensorPacket(DataSourcePacket pckt) { double distDiff = pckt.distance - lastDistance; if (distDiff > 0) { incrementDistanceAndUpdate(distDiff, speedMs: pckt.speed_ms, cadence: calculatedCadence); } lastDistance = pckt.distance; }
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); } }
public virtual void reset() { stop(); distanceTravelled = 0; lastPacketRcvd = null; }