PowermeterData.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Sensors.Bluetooth
  5. {
  6. public readonly struct RawPowermeterData
  7. {
  8. public readonly int instantaniousPower;
  9. public readonly float accumulatedTorque;
  10. public readonly int crankRevolutions;
  11. public readonly float lastCrankEventTime;
  12. public RawPowermeterData(int instantaniousPower, float accumulatedTorque, int crankRevolutions,
  13. float lastCrankEventTime)
  14. {
  15. this.lastCrankEventTime = lastCrankEventTime;
  16. this.crankRevolutions = crankRevolutions;
  17. this.accumulatedTorque = accumulatedTorque;
  18. this.instantaniousPower = instantaniousPower;
  19. }
  20. public static RawPowermeterData FromString(string s)
  21. {
  22. var data = s.Split(';');
  23. if (data.Length != 4) throw new FormatException("HRData String has wrong format");
  24. var pow = int.Parse(data[0]);
  25. var torque = float.Parse(data[1]);
  26. var crankRevs = int.Parse(data[2]);
  27. var lastCrankTime = float.Parse(data[3]);
  28. return new RawPowermeterData(pow, torque, crankRevs, lastCrankTime);
  29. }
  30. }
  31. public struct PowermeterData
  32. {
  33. public readonly int power;
  34. public readonly int cadence;
  35. public readonly float torque;
  36. public PowermeterData(int power, int cadence, float torque)
  37. {
  38. this.power = power;
  39. this.cadence = cadence;
  40. this.torque = torque;
  41. }
  42. }
  43. }