12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using Logging.Base;
- using Sensors;
- using UnityEngine;
- namespace Logging.Data
- {
- public readonly struct BikeSensorDataLog : ISerializable
- {
- private readonly long timestamp;
- private readonly float speed;
- private readonly float cadence;
- private readonly int heartRate;
- private readonly float torque;
- private readonly float power;
- public BikeSensorDataLog(long timestamp, float speed, float cadence, int heartRate, float torque, float power)
- {
- this.timestamp = timestamp;
- this.speed = speed;
- this.cadence = cadence;
- this.heartRate = heartRate;
- this.torque = torque;
- this.power = power;
- }
- public KeyValuePair<long, string[]> Serialize() => new KeyValuePair<long, string[]>(timestamp, new[]
- {
- speed.ToString("F4", CultureInfo.InvariantCulture),
- cadence.ToString("F4", CultureInfo.InvariantCulture),
- heartRate.ToString(),
- torque.ToString("F4", CultureInfo.InvariantCulture),
- power.ToString("F4", CultureInfo.InvariantCulture)
- });
- }
- public class BikeSensorDataLogger : SensorDataLogger<BikeSensorDataLog>
- {
- public override string Key => "bike_sensor_data";
- private BikeSensorData bikeSensorData;
- public override void Start()
- {
- base.Start();
- bikeSensorData = BikeSensorData.Instance;
- }
- private void Update()
- {
- var hr = (int) (bikeSensorData.HrData?.HeartRate ?? -1);
- var speed = bikeSensorData.SpeedData?.SpeedKmh ?? -1f;
- var cadence = bikeSensorData.PowermeterData?.InstantaneousCadence ?? -1f;
- var power = bikeSensorData.PowermeterData?.InstantaneousPower ?? -1f;
- var torque = bikeSensorData.PowermeterData?.CrankTorque ?? -1f;
- Log(new BikeSensorDataLog(Helpers.RoundToLong(Time.time * 1000), speed, cadence, hr, torque, power));
- }
-
- public override IEnumerable<BikeSensorDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
- {
- throw new NotImplementedException(); //TODO
- }
- }
- }
|