/// <inheritdoc /> public void SetVariableWorkout(string serialNumber, IEnumerable <Interval> intervals) { if (string.IsNullOrWhiteSpace(serialNumber)) { _logger.LogError("Serial number must not be null. No workout has been set."); return; } if (intervals == null) { _logger.LogError("Intervals must be defined. No workout has been set."); return; } IEnumerable <ICommand>?commands = BuildVariableWorkout(intervals); if (commands == null) { _logger.LogError("An error occurred while building commands for variable workout. No workout has been set."); return; } ICommandList commandList = _commandListFactory.Create(commands); commandList.Prepare(); _pmCommunicator.Send(serialNumber, commandList); }
/// <summary> /// Actually polls the device /// </summary> /// <param name="serialNumber">The serial number</param> /// <param name="pollIntervals">The intervals to poll for</param> /// <returns>The populated commands</returns> private ICommandList?ExecutePoll(string serialNumber, IEnumerable <PollInterval> pollIntervals) { ICommandList commands = _commandListFactory.Create(); foreach (PollInterval pollInterval in pollIntervals) { try { commands.AddRange(_pollIntervals[pollInterval]); } catch (Exception e) { _logger.LogCritical("Could not add poll intervals"); } } commands.Prepare(); try { _pmCommunicator.Send(serialNumber, commands); return(commands); } catch (Exception e) { _logger.LogError(e, "Exception occurred while sending poll commands to serial number [{SerialNumber}]", serialNumber); } return(null); }
/// <inheritdoc /> public void TerminateWorkout(string serialNumber) { ICommandList commandList = _commandListFactory.Create(); commandList.Add(new SetScreenStateCommand(ScreenType.Workout, ScreenValueWorkout.TerminateWorkout)); commandList.Prepare(); _pmCommunicator.Send(serialNumber, commandList); }
/// <inheritdoc /> public void SetJustRowWorkout(string serialNumber, bool splits) { if (string.IsNullOrWhiteSpace(serialNumber)) { _logger.LogError("Serial number must not be null. No workout has been set."); return; } IEnumerable <ICommand> commands = BuildJustRowWorkout(splits); ICommandList commandList = _commandListFactory.Create(commands); commandList.Prepare(); _pmCommunicator.Send(serialNumber, commandList); }
/// <inheritdoc /> public void SetFixedWorkout(string serialNumber, Interval interval) { if (string.IsNullOrWhiteSpace(serialNumber)) { _logger.LogError("Serial number must not be null. No workout has been set."); return; } if (interval == null) { _logger.LogError("Interval must be defined when setting a fixed workout. No workout has been set."); return; } switch (interval.WorkoutType) { case WorkoutType.FixedCalorieInterval: case WorkoutType.FixedCalorieWithSplits: case WorkoutType.FixedDistanceInterval: case WorkoutType.FixedDistanceNoSplits: case WorkoutType.FixedDistanceWithSplits: case WorkoutType.FixedTimeInterval: case WorkoutType.FixedTimeNoSplits: case WorkoutType.FixedTimeWithSplits: case WorkoutType.FixedWattMinuteWithSplits: break; default: _logger.LogError("Only fixed interval workout types with defined rest can be provided when setting a fixed workout. Now workout has been set."); return; } IEnumerable <ICommand>?commands = BuildFixedWorkout(interval); if (commands == null) { _logger.LogError("An error occurred while building commands for fixed workout. No workout has been set."); return; } ICommandList commandList = _commandListFactory.Create(commands); commandList.Prepare(); _pmCommunicator.Send(serialNumber, commandList); }
/// <inheritdoc /> public bool IsReadyToProgramWorkout(string serialNumber) { if (string.IsNullOrWhiteSpace(serialNumber)) { _logger.LogError("Serial number must be defined when determining state."); return(false); } GetOperationalStateCommand operationalStateCommand = new(); GetWorkoutStateCommand workoutStateCommand = new(); ICommandList commandList = _commandListFactory.Create(); commandList.Add(operationalStateCommand); commandList.Add(workoutStateCommand); commandList.Prepare(); _pmCommunicator.Send(serialNumber, commandList); OperationalState?operationalState = operationalStateCommand.Value; if (!operationalState.HasValue) { _logger.LogWarning("Operational state is unknown."); return(false); } if (operationalState.Value != OperationalState.Ready && operationalState.Value != OperationalState.Workout) { return(false); } WorkoutState?workoutState = workoutStateCommand.Value; if (!workoutState.HasValue) { _logger.LogWarning("Workout state is unknown."); return(false); } return(workoutState.Value == WorkoutState.WaitingToBegin); }
/// <summary> /// Gets the current workout state for a specified location /// </summary> /// <param name="serialNumber">The serial number</param> /// <returns>The current workout state</returns> private WorkoutState?GetWorkoutState(string serialNumber) { ICommandList commands = _commandListFactory.Create(); commands.Add(new GetWorkoutStateCommand()); commands.Prepare(); try { _pmCommunicator.Send(serialNumber, commands); } catch (Exception e) { _logger.LogWarning(e, "Error occurred while checking workout state prior to polling"); return(WorkoutState.WaitingToBegin); } return(commands.FirstOrDefault()?.Value); }