private static WorkoutStepMesg CreateWorkoutStepSwim(int messageIndex, float distance, String name = null, String notes = null, Intensity intensity = Intensity.Active, SwimStroke swimStroke = SwimStroke.Invalid, WorkoutEquipment?equipment = null) { var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); if (name != null) { workoutStepMesg.SetWktStepName(name); } if (notes != null) { workoutStepMesg.SetNotes(notes); } workoutStepMesg.SetIntensity(intensity); workoutStepMesg.SetDurationType(WktStepDuration.Distance); workoutStepMesg.SetDurationDistance(distance); workoutStepMesg.SetTargetType(WktStepTarget.SwimStroke); workoutStepMesg.SetTargetStrokeType((byte)swimStroke); if (equipment.HasValue) { workoutStepMesg.SetEquipment(equipment); } return(workoutStepMesg); }
private static WorkoutStepMesg CreateWorkoutStepRepeat(int messageIndex, uint repeatFrom, uint repetitions) { var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); workoutStepMesg.SetDurationType(WktStepDuration.RepeatUntilStepsCmplt); workoutStepMesg.SetDurationValue(repeatFrom); workoutStepMesg.SetTargetType(WktStepTarget.Open); workoutStepMesg.SetTargetValue(repetitions); return(workoutStepMesg); }
private static WorkoutStepMesg CreateWorkoutStepSwimRest(int messageIndex, WktStepDuration durationType = WktStepDuration.Open, float?durationTime = null) { var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); workoutStepMesg.SetDurationType(durationType); workoutStepMesg.SetDurationTime(durationTime); workoutStepMesg.SetTargetType(WktStepTarget.Open); workoutStepMesg.SetIntensity(Intensity.Rest); return(workoutStepMesg); }
private static WorkoutStepMesg CreateWorkoutStep(int messageIndex, String name = null, String notes = null, Intensity intensity = Intensity.Active, WktStepDuration durationType = WktStepDuration.Open, uint?durationValue = null, WktStepTarget targetType = WktStepTarget.Open, uint targetValue = 0, uint?customTargetValueLow = null, uint?customTargetValueHigh = null) { if (durationType == WktStepDuration.Invalid) { return(null); } var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); if (name != null) { workoutStepMesg.SetWktStepName(name); } if (notes != null) { workoutStepMesg.SetNotes(notes); } workoutStepMesg.SetIntensity(intensity); workoutStepMesg.SetDurationType(durationType); if (durationValue.HasValue) { workoutStepMesg.SetDurationValue(durationValue); } if (targetType != WktStepTarget.Invalid && customTargetValueLow.HasValue && customTargetValueHigh.HasValue) { workoutStepMesg.SetTargetType(targetType); workoutStepMesg.SetTargetValue(0); workoutStepMesg.SetCustomTargetValueLow(customTargetValueLow); workoutStepMesg.SetCustomTargetValueHigh(customTargetValueHigh); } else if (targetType != WktStepTarget.Invalid) { workoutStepMesg.SetTargetType(targetType); workoutStepMesg.SetTargetValue(targetValue); workoutStepMesg.SetCustomTargetValueLow(0); workoutStepMesg.SetCustomTargetValueHigh(0); } return(workoutStepMesg); }
private Dictionary <int, Tuple <WorkoutStepMesg, LapMesg> > GetWorkoutStepsAndLaps(WorkoutSamples workoutSamples, Dynastream.Fit.DateTime startTime, Sport sport, SubSport subSport) { var stepsAndLaps = new Dictionary <int, Tuple <WorkoutStepMesg, LapMesg> >(); if (workoutSamples is null) { return(stepsAndLaps); } var cadenceTargets = workoutSamples.Target_Performance_Metrics?.Target_Graph_Metrics?.FirstOrDefault(w => w.Type == "cadence")?.Graph_Data; if (cadenceTargets is null) { return(stepsAndLaps); } uint previousCadenceLower = 0; uint previousCadenceUpper = 0; ushort stepIndex = 0; var duration = 0; float lapDistanceInMeters = 0; WorkoutStepMesg workoutStep = null; LapMesg lapMesg = null; var speedMetrics = GetSpeedSummary(workoutSamples); foreach (var secondSinceStart in workoutSamples.Seconds_Since_Pedaling_Start) { var index = secondSinceStart <= 0 ? 0 : secondSinceStart - 1; duration++; if (speedMetrics is object && index < speedMetrics.Values.Length) { var currentSpeedInMPS = ConvertToMetersPerSecond(speedMetrics.GetValue(index), workoutSamples); lapDistanceInMeters += 1 * currentSpeedInMPS; } var currentCadenceLower = index < cadenceTargets.Lower.Length ? (uint)cadenceTargets.Lower[index] : 0; var currentCadenceUpper = index < cadenceTargets.Upper.Length ? (uint)cadenceTargets.Upper[index] : 0; if (currentCadenceLower != previousCadenceLower || currentCadenceUpper != previousCadenceUpper) { if (workoutStep != null && lapMesg != null) { workoutStep.SetDurationValue((uint)duration * 1000); // milliseconds var lapEndTime = new Dynastream.Fit.DateTime(startTime); lapEndTime.Add(secondSinceStart); lapMesg.SetTotalElapsedTime(duration); lapMesg.SetTotalTimerTime(duration); lapMesg.SetTimestamp(lapEndTime); lapMesg.SetEventType(EventType.Stop); lapMesg.SetTotalDistance(lapDistanceInMeters); stepsAndLaps.Add(stepIndex, new Tuple <WorkoutStepMesg, LapMesg>(workoutStep, lapMesg)); stepIndex++; duration = 0; lapDistanceInMeters = 0; } workoutStep = new WorkoutStepMesg(); workoutStep.SetDurationType(WktStepDuration.Time); workoutStep.SetMessageIndex(stepIndex); workoutStep.SetTargetType(WktStepTarget.Cadence); workoutStep.SetCustomTargetValueHigh(currentCadenceUpper); workoutStep.SetCustomTargetValueLow(currentCadenceLower); workoutStep.SetIntensity(currentCadenceUpper > 60 ? Intensity.Active : Intensity.Rest); lapMesg = new LapMesg(); var lapStartTime = new Dynastream.Fit.DateTime(startTime); lapStartTime.Add(secondSinceStart); lapMesg.SetStartTime(lapStartTime); lapMesg.SetWktStepIndex(stepIndex); lapMesg.SetMessageIndex(stepIndex); lapMesg.SetEvent(Event.Lap); lapMesg.SetLapTrigger(LapTrigger.Time); lapMesg.SetSport(sport); lapMesg.SetSubSport(subSport); previousCadenceLower = currentCadenceLower; previousCadenceUpper = currentCadenceUpper; } } return(stepsAndLaps); }
public void OnMesg(object sender, MesgEventArgs e) { // Notify any subscribers of either our general mesg event or specific profile mesg event if (MesgEvent != null) { MesgEvent(sender, e); } switch (e.mesg.Num) { case (ushort)MesgNum.FileId: if (FileIdMesgEvent != null) { FileIdMesg fileIdMesg = new FileIdMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = fileIdMesg; FileIdMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.FileCreator: if (FileCreatorMesgEvent != null) { FileCreatorMesg fileCreatorMesg = new FileCreatorMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = fileCreatorMesg; FileCreatorMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Software: if (SoftwareMesgEvent != null) { SoftwareMesg softwareMesg = new SoftwareMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = softwareMesg; SoftwareMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.SlaveDevice: if (SlaveDeviceMesgEvent != null) { SlaveDeviceMesg slaveDeviceMesg = new SlaveDeviceMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = slaveDeviceMesg; SlaveDeviceMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Capabilities: if (CapabilitiesMesgEvent != null) { CapabilitiesMesg capabilitiesMesg = new CapabilitiesMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = capabilitiesMesg; CapabilitiesMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.FileCapabilities: if (FileCapabilitiesMesgEvent != null) { FileCapabilitiesMesg fileCapabilitiesMesg = new FileCapabilitiesMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = fileCapabilitiesMesg; FileCapabilitiesMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.MesgCapabilities: if (MesgCapabilitiesMesgEvent != null) { MesgCapabilitiesMesg mesgCapabilitiesMesg = new MesgCapabilitiesMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = mesgCapabilitiesMesg; MesgCapabilitiesMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.FieldCapabilities: if (FieldCapabilitiesMesgEvent != null) { FieldCapabilitiesMesg fieldCapabilitiesMesg = new FieldCapabilitiesMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = fieldCapabilitiesMesg; FieldCapabilitiesMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.DeviceSettings: if (DeviceSettingsMesgEvent != null) { DeviceSettingsMesg deviceSettingsMesg = new DeviceSettingsMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = deviceSettingsMesg; DeviceSettingsMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.UserProfile: if (UserProfileMesgEvent != null) { UserProfileMesg userProfileMesg = new UserProfileMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = userProfileMesg; UserProfileMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.HrmProfile: if (HrmProfileMesgEvent != null) { HrmProfileMesg hrmProfileMesg = new HrmProfileMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = hrmProfileMesg; HrmProfileMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.SdmProfile: if (SdmProfileMesgEvent != null) { SdmProfileMesg sdmProfileMesg = new SdmProfileMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = sdmProfileMesg; SdmProfileMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.BikeProfile: if (BikeProfileMesgEvent != null) { BikeProfileMesg bikeProfileMesg = new BikeProfileMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = bikeProfileMesg; BikeProfileMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.ZonesTarget: if (ZonesTargetMesgEvent != null) { ZonesTargetMesg zonesTargetMesg = new ZonesTargetMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = zonesTargetMesg; ZonesTargetMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Sport: if (SportMesgEvent != null) { SportMesg sportMesg = new SportMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = sportMesg; SportMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.HrZone: if (HrZoneMesgEvent != null) { HrZoneMesg hrZoneMesg = new HrZoneMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = hrZoneMesg; HrZoneMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.SpeedZone: if (SpeedZoneMesgEvent != null) { SpeedZoneMesg speedZoneMesg = new SpeedZoneMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = speedZoneMesg; SpeedZoneMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.CadenceZone: if (CadenceZoneMesgEvent != null) { CadenceZoneMesg cadenceZoneMesg = new CadenceZoneMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = cadenceZoneMesg; CadenceZoneMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.PowerZone: if (PowerZoneMesgEvent != null) { PowerZoneMesg powerZoneMesg = new PowerZoneMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = powerZoneMesg; PowerZoneMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.MetZone: if (MetZoneMesgEvent != null) { MetZoneMesg metZoneMesg = new MetZoneMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = metZoneMesg; MetZoneMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Goal: if (GoalMesgEvent != null) { GoalMesg goalMesg = new GoalMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = goalMesg; GoalMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Activity: if (ActivityMesgEvent != null) { ActivityMesg activityMesg = new ActivityMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = activityMesg; ActivityMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Session: if (SessionMesgEvent != null) { SessionMesg sessionMesg = new SessionMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = sessionMesg; SessionMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Lap: if (LapMesgEvent != null) { LapMesg lapMesg = new LapMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = lapMesg; LapMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Length: if (LengthMesgEvent != null) { LengthMesg lengthMesg = new LengthMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = lengthMesg; LengthMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Record: if (RecordMesgEvent != null) { RecordMesg recordMesg = new RecordMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = recordMesg; RecordMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Event: if (EventMesgEvent != null) { EventMesg eventMesg = new EventMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = eventMesg; EventMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.DeviceInfo: if (DeviceInfoMesgEvent != null) { DeviceInfoMesg deviceInfoMesg = new DeviceInfoMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = deviceInfoMesg; DeviceInfoMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.TrainingFile: if (TrainingFileMesgEvent != null) { TrainingFileMesg trainingFileMesg = new TrainingFileMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = trainingFileMesg; TrainingFileMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Hrv: if (HrvMesgEvent != null) { HrvMesg hrvMesg = new HrvMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = hrvMesg; HrvMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Course: if (CourseMesgEvent != null) { CourseMesg courseMesg = new CourseMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = courseMesg; CourseMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.CoursePoint: if (CoursePointMesgEvent != null) { CoursePointMesg coursePointMesg = new CoursePointMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = coursePointMesg; CoursePointMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Workout: if (WorkoutMesgEvent != null) { WorkoutMesg workoutMesg = new WorkoutMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = workoutMesg; WorkoutMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.WorkoutStep: if (WorkoutStepMesgEvent != null) { WorkoutStepMesg workoutStepMesg = new WorkoutStepMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = workoutStepMesg; WorkoutStepMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Schedule: if (ScheduleMesgEvent != null) { ScheduleMesg scheduleMesg = new ScheduleMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = scheduleMesg; ScheduleMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Totals: if (TotalsMesgEvent != null) { TotalsMesg totalsMesg = new TotalsMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = totalsMesg; TotalsMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.WeightScale: if (WeightScaleMesgEvent != null) { WeightScaleMesg weightScaleMesg = new WeightScaleMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = weightScaleMesg; WeightScaleMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.BloodPressure: if (BloodPressureMesgEvent != null) { BloodPressureMesg bloodPressureMesg = new BloodPressureMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = bloodPressureMesg; BloodPressureMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.MonitoringInfo: if (MonitoringInfoMesgEvent != null) { MonitoringInfoMesg monitoringInfoMesg = new MonitoringInfoMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = monitoringInfoMesg; MonitoringInfoMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Monitoring: if (MonitoringMesgEvent != null) { MonitoringMesg monitoringMesg = new MonitoringMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = monitoringMesg; MonitoringMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.MemoGlob: if (MemoGlobMesgEvent != null) { MemoGlobMesg memoGlobMesg = new MemoGlobMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = memoGlobMesg; MemoGlobMesgEvent(sender, mesgEventArgs); } break; case (ushort)MesgNum.Pad: if (PadMesgEvent != null) { PadMesg padMesg = new PadMesg(e.mesg); MesgEventArgs mesgEventArgs = new MesgEventArgs(); mesgEventArgs.mesg = padMesg; PadMesgEvent(sender, mesgEventArgs); } break; } }