12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using Sensors;
- using UnityEngine;
- namespace Logging
- {
- public class PolarSensorDataLog
- {
- private float timestamp;
- private float accX;
- private float accY;
- private float accZ;
- private float ecg;
- public PolarSensorDataLog(float timestamp, float accX, float accY, float accZ, float ecg)
- {
- this.timestamp = timestamp;
- this.accX = accX;
- this.accY = accY;
- this.accZ = accZ;
- this.ecg = ecg;
- }
- public string[] Serialize() =>
- new[]
- {
- timestamp.ToString("F4", CultureInfo.InvariantCulture),
- accX.ToString("F4", CultureInfo.InvariantCulture),
- accY.ToString("F4", CultureInfo.InvariantCulture),
- accZ.ToString("F4", CultureInfo.InvariantCulture),
- ecg.ToString("F4", CultureInfo.InvariantCulture)
- };
- }
- public class PolarSensorDataLogger : SensorDataLogger<PolarSensorDataLog>
- {
- public override string Key => "polar_sensor_data";
-
- private BikeSensorData bikeSensorData;
- public override void Start()
- {
- base.Start();
- bikeSensorData = BikeSensorData.Instance;
- }
- private void Update()
- {
- var ecg = bikeSensorData.PolarData?.EcgValue ?? -9999f;
- var acc = bikeSensorData.PolarData?.Acc ?? new Vector3(-9999, -9999, -9999);
- Log(new PolarSensorDataLog(Time.time, acc.x, acc.y, acc.z, ecg));
- }
- public override void Log(PolarSensorDataLog value)
- {
- Buffer.Add(value.Serialize());
- }
- public override IEnumerable<PolarSensorDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
- {
- throw new System.NotImplementedException(); //TODO
- }
- }
- }
|