From 887e42ad255e291e8d32d78781c21e5a95978c5d Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Mon, 29 Jun 2020 14:25:08 +0900 Subject: [PATCH] GPS Plugin added --- Assets/Scripts/CustomPlugins/GpsPlugin.cs | 51 +++++++++++++++++++ .../Scripts/CustomPlugins/GpsPlugin.cs.meta | 11 ++++ Assets/Scripts/Devices/GPS.cs | 1 - 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/CustomPlugins/GpsPlugin.cs create mode 100644 Assets/Scripts/CustomPlugins/GpsPlugin.cs.meta diff --git a/Assets/Scripts/CustomPlugins/GpsPlugin.cs b/Assets/Scripts/CustomPlugins/GpsPlugin.cs new file mode 100644 index 00000000..ac8fcc3c --- /dev/null +++ b/Assets/Scripts/CustomPlugins/GpsPlugin.cs @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 LG Electronics Inc. + * + * SPDX-License-Identifier: MIT + */ + +using UnityEngine; +using Stopwatch = System.Diagnostics.Stopwatch; + +public class GpsPlugin : CustomPlugin +{ + public string partName = string.Empty; + + private SensorDevices.GPS gps = null; + + protected override void OnAwake() + { + partName = DeviceHelper.GetPartName(gameObject); + + string hashKey = MakeHashKey(partName); + if (!RegisterTxDevice(hashKey)) + { + Debug.LogError("Failed to register for GpsPlugin - " + hashKey); + } + } + + protected override void OnStart() + { + gps = gameObject.GetComponent(); + + AddThread(Sender); + } + + private void Sender() + { + Stopwatch sw = new Stopwatch(); + while (true) + { + if (gps == null) + { + continue; + } + + var datastreamToSend = gps.PopData(); + sw.Restart(); + Publish(datastreamToSend); + sw.Stop(); + gps.SetTransportTime((float)sw.Elapsed.TotalSeconds); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CustomPlugins/GpsPlugin.cs.meta b/Assets/Scripts/CustomPlugins/GpsPlugin.cs.meta new file mode 100644 index 00000000..4846d47a --- /dev/null +++ b/Assets/Scripts/CustomPlugins/GpsPlugin.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e1da2ef78d772eb49b1356c14ac829af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Devices/GPS.cs b/Assets/Scripts/Devices/GPS.cs index daa7cb3e..78c6950a 100644 --- a/Assets/Scripts/Devices/GPS.cs +++ b/Assets/Scripts/Devices/GPS.cs @@ -27,7 +27,6 @@ public partial class GPS : Device void Awake() { - // sensorVelocity = new Vector3(); gpsLink = transform.parent; deviceName = name;