12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using UnityEngine;
- using UnityEngine.Serialization;
- [System.Serializable]
- public struct PolarSensorConfig
- {
- public int port;
- public String ipAddress;
- public PolarSensorConfig(int port = 9099, string ipAddress = "0.0.0.0")
- {
- this.port = port;
- this.ipAddress = ipAddress;
- }
- }
- public struct PolarSensorData
- {
- public Vector3 Acc;
- public float EcgValue;
- }
- public class PolarReceiver
- {
- private UdpConnection connection;
- private PolarSensorData sensorData;
- public PolarSensorConfig SensorConfig { get; private set; }
- public PolarSensorData SensorData => sensorData;
- public PolarReceiver()
- {
- }
- public PolarReceiver(PolarSensorConfig config, bool autoStart = true)
- {
- SensorConfig = config;
- if (autoStart) StartListening();
- }
- public void StartListening()
- {
- connection = new UdpConnection(SensorConfig.ipAddress, SensorConfig.port, OnAccData);
- connection.Listen();
- }
- public void Dispose()
- {
- connection.StopListening();
- }
- private void OnAccData(AccData data)
- {
- //Debug.Log(data.Timestamp);
- sensorData.Acc = data.Values[0]; //TODO: what about rest of array?
- }
- //TODO: OnEcgData
- }
|