mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 09:31:20 -08:00
Implement devices in the protocol (#205)
This commit is contained in:
1 parent
078b140966
commit
c22b5ce421
20 files changed
+328
-100
No files matched your search
@@ -8,6 +8,7 @@ import dev.slimevr.poserecorder.BVHRecorder;
|
||||
import dev.slimevr.protocol.ProtocolAPI;
|
||||
import dev.slimevr.serial.SerialHandler;
|
||||
import dev.slimevr.util.ann.VRServerThread;
|
||||
import dev.slimevr.vr.DeviceManager;
|
||||
import dev.slimevr.vr.processor.HumanPoseProcessor;
|
||||
import dev.slimevr.vr.processor.skeleton.Skeleton;
|
||||
import dev.slimevr.vr.trackers.*;
|
||||
@@ -43,6 +44,7 @@ public class VRServer extends Thread {
|
||||
private final List<Consumer<Tracker>> newTrackersConsumers = new FastList<>();
|
||||
private final List<Runnable> onTick = new FastList<>();
|
||||
private final List<? extends ShareableTracker> shareTrackers;
|
||||
private final DeviceManager deviceManager;
|
||||
private final BVHRecorder bvhRecorder;
|
||||
private final SerialHandler serialHandler;
|
||||
private final AutoBoneHandler autoBoneHandler;
|
||||
@@ -58,6 +60,8 @@ public class VRServer extends Thread {
|
||||
this.configPath = configPath;
|
||||
loadConfig();
|
||||
|
||||
deviceManager = new DeviceManager(this);
|
||||
|
||||
serialHandler = new SerialHandler();
|
||||
autoBoneHandler = new AutoBoneHandler(this);
|
||||
protocolAPI = new ProtocolAPI(this);
|
||||
@@ -368,4 +372,8 @@ public class VRServer extends Thread {
|
||||
public TrackersUDPServer getTrackersServer() {
|
||||
return trackersServer;
|
||||
}
|
||||
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ public class TrackersList extends EJBoxNoStretch {
|
||||
if (t.hasPosition())
|
||||
add(new JLabel("Position"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
|
||||
add(new JLabel("TPS"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
|
||||
if (tracker instanceof IMUTracker) {
|
||||
if (tracker instanceof TrackerWithWireless) {
|
||||
add(new JLabel("Ping"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
|
||||
add(new JLabel("Signal"), c(4, row, 2, GridBagConstraints.FIRST_LINE_START));
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public class TrackersList extends EJBoxNoStretch {
|
||||
position = new JLabel("0 0 0"),
|
||||
c(1, row, 2, GridBagConstraints.FIRST_LINE_START)
|
||||
);
|
||||
if (tracker instanceof IMUTracker) {
|
||||
if (tracker instanceof TrackerWithWireless) {
|
||||
add(ping = new JLabel(""), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
|
||||
add(
|
||||
signalStrength = new JLabel(""),
|
||||
@@ -435,21 +435,21 @@ public class TrackersList extends EJBoxNoStretch {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (tracker instanceof IMUTracker) {
|
||||
if (ping != null)
|
||||
ping.setText(String.valueOf(((IMUTracker) tracker).ping));
|
||||
if (signalStrength != null) {
|
||||
int signal = ((IMUTracker) tracker).signalStrength;
|
||||
if (signal == -1) {
|
||||
signalStrength.setText("N/A");
|
||||
} else {
|
||||
// -40 dBm is excellent, -95 dBm is very poor
|
||||
int percentage = (signal - -95) * (100 - 0) / (-40 - -95) + 0;
|
||||
percentage = Math.max(Math.min(percentage, 100), 0);
|
||||
signalStrength.setText(percentage + "% " + "(" + signal + " dBm" + ")");
|
||||
}
|
||||
|
||||
if (tracker instanceof TrackerWithWireless) {
|
||||
ping.setText(String.valueOf(((TrackerWithWireless) tracker).getPing()));
|
||||
int signal = ((TrackerWithWireless) tracker).getSignalStrength();
|
||||
|
||||
if (signal == -1) {
|
||||
signalStrength.setText("N/A");
|
||||
} else {
|
||||
// -40 dBm is excellent, -95 dBm is very poor
|
||||
int percentage = (signal - -95) * (100 - 0) / (-40 - -95) + 0;
|
||||
percentage = Math.max(Math.min(percentage, 100), 0);
|
||||
signalStrength.setText(percentage + "% " + "(" + signal + " dBm" + ")");
|
||||
}
|
||||
}
|
||||
|
||||
tracker.getRotation(q);
|
||||
q.toAngles(angles);
|
||||
raw
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.slimevr.bridge.ProtobufBridge;
|
||||
import dev.slimevr.bridge.ProtobufMessages.ProtobufMessage;
|
||||
import dev.slimevr.bridge.ProtobufMessages.TrackerAdded;
|
||||
import dev.slimevr.util.ann.VRServerThread;
|
||||
import dev.slimevr.vr.Device;
|
||||
import dev.slimevr.vr.trackers.*;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
|
||||
@@ -105,13 +106,26 @@ public class WindowsNamedPipeBridge extends ProtobufBridge<VRTracker> implements
|
||||
@Override
|
||||
@VRServerThread
|
||||
protected VRTracker createNewTracker(TrackerAdded trackerAdded) {
|
||||
// Todo: We need the manufacturer
|
||||
Device device = Main.vrServer
|
||||
.getDeviceManager()
|
||||
.createDevice(
|
||||
trackerAdded.getTrackerName(),
|
||||
trackerAdded.getTrackerSerial(),
|
||||
"FeederAPP"
|
||||
);
|
||||
|
||||
VRTracker tracker = new VRTracker(
|
||||
trackerAdded.getTrackerId(),
|
||||
trackerAdded.getTrackerSerial(),
|
||||
trackerAdded.getTrackerName(),
|
||||
true,
|
||||
true
|
||||
true,
|
||||
device
|
||||
);
|
||||
|
||||
device.getTrackers().add(tracker);
|
||||
Main.vrServer.getDeviceManager().addDevice(device);
|
||||
TrackerRole role = TrackerRole.getById(trackerAdded.getTrackerRole());
|
||||
if (role != null) {
|
||||
tracker.setBodyPosition(TrackerPosition.getByTrackerRole(role).orElse(null));
|
||||
|
||||
@@ -2,11 +2,11 @@ package dev.slimevr.poserecorder;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
import dev.slimevr.vr.trackers.Tracker;
|
||||
import dev.slimevr.vr.trackers.TrackerConfig;
|
||||
import dev.slimevr.vr.trackers.TrackerPosition;
|
||||
import dev.slimevr.vr.trackers.TrackerStatus;
|
||||
import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
import io.eiren.util.collections.FastList;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -258,7 +258,7 @@ public class PoseFrameTracker implements Tracker, Iterable<TrackerFrame> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDPDevice getDevice() {
|
||||
public IDevice getDevice() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ package dev.slimevr.poserecorder;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
import dev.slimevr.vr.trackers.Tracker;
|
||||
import dev.slimevr.vr.trackers.TrackerConfig;
|
||||
import dev.slimevr.vr.trackers.TrackerPosition;
|
||||
import dev.slimevr.vr.trackers.TrackerStatus;
|
||||
import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
|
||||
|
||||
public final class TrackerFrame implements Tracker {
|
||||
@@ -189,7 +189,7 @@ public final class TrackerFrame implements Tracker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDPDevice getDevice() {
|
||||
public IDevice getDevice() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,9 @@ package dev.slimevr.protocol;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import dev.slimevr.vr.IDevice;
|
||||
import dev.slimevr.vr.processor.skeleton.BoneInfo;
|
||||
import dev.slimevr.vr.trackers.IMUTracker;
|
||||
import dev.slimevr.vr.trackers.Tracker;
|
||||
import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
import dev.slimevr.vr.trackers.*;
|
||||
import solarxr_protocol.data_feed.Bone;
|
||||
import solarxr_protocol.data_feed.DataFeedUpdate;
|
||||
import solarxr_protocol.data_feed.device_data.DeviceData;
|
||||
@@ -29,10 +27,16 @@ import java.util.List;
|
||||
|
||||
public class DataFeedBuilder {
|
||||
|
||||
public static int createHardwareInfo(FlatBufferBuilder fbb, UDPDevice device) {
|
||||
IMUTracker tracker = device.sensors.get(0);
|
||||
public static int createHardwareInfo(FlatBufferBuilder fbb, IDevice device) {
|
||||
Tracker tracker = device.getTrackers().get(0).get();
|
||||
|
||||
int nameOffset = device.getFirmwareVersion() != null
|
||||
? fbb.createString(device.getFirmwareVersion())
|
||||
: 0;
|
||||
|
||||
HardwareInfo.startHardwareInfo(fbb);
|
||||
HardwareInfo.addFirmwareVersion(fbb, nameOffset);
|
||||
|
||||
// BRUH MOMENT
|
||||
// TODO need support: HardwareInfo.addFirmwareVersion(fbb,
|
||||
// firmwareVersionOffset);
|
||||
@@ -149,14 +153,14 @@ public class DataFeedBuilder {
|
||||
public static int createTrackersData(
|
||||
FlatBufferBuilder fbb,
|
||||
DeviceDataMaskT mask,
|
||||
UDPDevice device
|
||||
IDevice device
|
||||
) {
|
||||
if (mask.getTrackerData() == null)
|
||||
return 0;
|
||||
|
||||
List<Integer> trackersOffsets = new ArrayList<>();
|
||||
|
||||
device.sensors.forEach((key, value) -> {
|
||||
device.getTrackers().forEach((value) -> {
|
||||
trackersOffsets
|
||||
.add(DataFeedBuilder.createTrackerData(fbb, mask.getTrackerData(), value));
|
||||
});
|
||||
@@ -172,28 +176,38 @@ public class DataFeedBuilder {
|
||||
FlatBufferBuilder fbb,
|
||||
int id,
|
||||
DeviceDataMaskT mask,
|
||||
UDPDevice device
|
||||
IDevice device
|
||||
) {
|
||||
if (!mask.getDeviceData())
|
||||
return 0;
|
||||
|
||||
IMUTracker tracker = device.sensors.get(0);
|
||||
if (device.getTrackers().size() <= 0)
|
||||
return 0;
|
||||
|
||||
Tracker tracker = device.getTrackers().get(0).get();
|
||||
|
||||
if (tracker == null)
|
||||
return 0;
|
||||
|
||||
int hardwareDataOffset = HardwareStatus
|
||||
.createHardwareStatus(
|
||||
fbb,
|
||||
tracker.getStatus().id,
|
||||
(int) tracker.getTPS(),
|
||||
tracker.ping,
|
||||
(short) tracker.signalStrength,
|
||||
tracker.temperature,
|
||||
tracker.getBatteryVoltage(),
|
||||
(int) tracker.getBatteryLevel(),
|
||||
-1
|
||||
);
|
||||
HardwareStatus.startHardwareStatus(fbb);
|
||||
HardwareStatus.addErrorStatus(fbb, tracker.getStatus().id);
|
||||
|
||||
if (tracker instanceof TrackerWithTPS)
|
||||
HardwareStatus.addTps(fbb, (int) ((TrackerWithTPS) tracker).getTPS());
|
||||
|
||||
if (tracker instanceof TrackerWithBattery) {
|
||||
TrackerWithBattery twb = (TrackerWithBattery) tracker;
|
||||
HardwareStatus.addBatteryVoltage(fbb, twb.getBatteryVoltage());
|
||||
HardwareStatus.addBatteryPctEstimate(fbb, (int) twb.getBatteryLevel());
|
||||
}
|
||||
|
||||
if (tracker instanceof TrackerWithWireless) {
|
||||
TrackerWithWireless tww = (TrackerWithWireless) tracker;
|
||||
HardwareStatus.addPing(fbb, tww.getPing());
|
||||
HardwareStatus.addRssi(fbb, (short) tww.getSignalStrength());
|
||||
}
|
||||
|
||||
int hardwareDataOffset = HardwareStatus.endHardwareStatus(fbb);
|
||||
int hardwareInfoOffset = DataFeedBuilder.createHardwareInfo(fbb, device);
|
||||
int trackersOffset = DataFeedBuilder.createTrackersData(fbb, mask, device);
|
||||
|
||||
@@ -217,7 +231,7 @@ public class DataFeedBuilder {
|
||||
|
||||
List<Integer> trackerOffsets = new ArrayList<>();
|
||||
|
||||
trackers.stream().filter(Tracker::isComputed).forEach((tracker) -> {
|
||||
trackers.forEach((tracker) -> {
|
||||
trackerOffsets.add(DataFeedBuilder.createTrackerData(fbb, trackerDataMaskT, tracker));
|
||||
});
|
||||
|
||||
@@ -231,14 +245,14 @@ public class DataFeedBuilder {
|
||||
public static int createDevicesData(
|
||||
FlatBufferBuilder fbb,
|
||||
DeviceDataMaskT deviceDataMaskT,
|
||||
List<UDPDevice> devices
|
||||
List<IDevice> devices
|
||||
) {
|
||||
if (deviceDataMaskT == null)
|
||||
return 0;
|
||||
|
||||
int[] devicesDataOffsets = new int[devices.size()];
|
||||
for (int i = 0; i < devices.size(); i++) {
|
||||
UDPDevice device = devices.get(i);
|
||||
IDevice device = devices.get(i);
|
||||
devicesDataOffsets[i] = DataFeedBuilder
|
||||
.createDeviceData(fbb, i, deviceDataMaskT, device);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package dev.slimevr.protocol;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import solarxr_protocol.MessageBundle;
|
||||
import solarxr_protocol.data_feed.*;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class DataFeedHandler extends ProtocolHandler<DataFeedMessageHeader> {
|
||||
@@ -71,13 +71,19 @@ public class DataFeedHandler extends ProtocolHandler<DataFeedMessageHeader> {
|
||||
.createDevicesData(
|
||||
fbb,
|
||||
config.getDataMask(),
|
||||
this.api.server.getTrackersServer().getConnections()
|
||||
this.api.server
|
||||
.getDeviceManager()
|
||||
.getDevices()
|
||||
);
|
||||
int trackersOffset = DataFeedBuilder
|
||||
.createSyntheticTrackersData(
|
||||
fbb,
|
||||
config.getSyntheticTrackersMask(),
|
||||
this.api.server.getAllTrackers()
|
||||
this.api.server
|
||||
.getAllTrackers()
|
||||
.stream()
|
||||
.filter(tracker -> tracker.get().getDevice() == null)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
var s = this.api.server.humanPoseProcessor.getSkeleton();
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package dev.slimevr.vr;
|
||||
|
||||
import dev.slimevr.vr.trackers.Tracker;
|
||||
import io.eiren.util.collections.FastList;
|
||||
|
||||
|
||||
public class Device implements IDevice {
|
||||
|
||||
private final int id;
|
||||
private String customName;
|
||||
private String firmwareVersion;
|
||||
private String manufacturer;
|
||||
|
||||
private final FastList<Tracker> trackers = new FastList<>();
|
||||
|
||||
public Device() {
|
||||
this.id = nextLocalDeviceId.incrementAndGet();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setCustomName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManufacturer() {
|
||||
return this.manufacturer;
|
||||
}
|
||||
|
||||
public void setManufacturer(String manufacturer) {
|
||||
this.manufacturer = manufacturer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirmwareVersion() {
|
||||
return this.firmwareVersion;
|
||||
}
|
||||
|
||||
public void setFirmwareVersion(String firmwareVersion) {
|
||||
this.firmwareVersion = firmwareVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return this.customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FastList<Tracker> getTrackers() {
|
||||
return trackers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.slimevr.vr;
|
||||
|
||||
import dev.slimevr.VRServer;
|
||||
import io.eiren.util.collections.FastList;
|
||||
|
||||
|
||||
public class DeviceManager {
|
||||
|
||||
private final FastList<IDevice> devices = new FastList<>();
|
||||
|
||||
public FastList<IDevice> getDevices() {
|
||||
return devices;
|
||||
}
|
||||
|
||||
private final VRServer server;
|
||||
|
||||
public DeviceManager(VRServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public Device createDevice(String name, String version, String manufacturer) {
|
||||
Device device = new Device();
|
||||
|
||||
device.setCustomName(name);
|
||||
device.setFirmwareVersion(version);
|
||||
device.setManufacturer(manufacturer);
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
public void addDevice(IDevice device) {
|
||||
this.server.queueTask(() -> {
|
||||
this.devices.add(device);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.slimevr.vr;
|
||||
|
||||
import dev.slimevr.vr.trackers.Tracker;
|
||||
import io.eiren.util.collections.FastList;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public interface IDevice {
|
||||
public static final AtomicInteger nextLocalDeviceId = new AtomicInteger();
|
||||
|
||||
int getId();
|
||||
|
||||
String getManufacturer();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
String getFirmwareVersion();
|
||||
|
||||
String getCustomName();
|
||||
|
||||
FastList<? extends Tracker> getTrackers();
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
import dev.slimevr.vr.IDevice;
|
||||
import dev.slimevr.vr.trackers.*;
|
||||
import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
import io.eiren.util.BufferedTimer;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ComputedHumanPoseTracker extends ComputedTracker
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDPDevice getDevice() {
|
||||
public IDevice getDevice() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ package dev.slimevr.vr.trackers;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
import dev.slimevr.vr.Device;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
|
||||
|
||||
public class ComputedTracker implements Tracker, TrackerWithTPS {
|
||||
@@ -14,6 +15,7 @@ public class ComputedTracker implements Tracker, TrackerWithTPS {
|
||||
protected final boolean hasRotation;
|
||||
protected final boolean hasPosition;
|
||||
protected final int trackerId;
|
||||
private final Device device;
|
||||
public TrackerPosition bodyPosition = null;
|
||||
protected TrackerStatus status = TrackerStatus.DISCONNECTED;
|
||||
|
||||
@@ -22,17 +24,19 @@ public class ComputedTracker implements Tracker, TrackerWithTPS {
|
||||
String serial,
|
||||
String name,
|
||||
boolean hasRotation,
|
||||
boolean hasPosition
|
||||
boolean hasPosition,
|
||||
Device device
|
||||
) {
|
||||
this.name = name;
|
||||
this.serial = serial;
|
||||
this.hasRotation = hasRotation;
|
||||
this.hasPosition = hasPosition;
|
||||
this.trackerId = trackerId;
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public ComputedTracker(int trackerId, String name, boolean hasRotation, boolean hasPosition) {
|
||||
this(trackerId, name, name, hasRotation, hasPosition);
|
||||
this(trackerId, name, name, hasRotation, hasPosition, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,8 +154,8 @@ public class ComputedTracker implements Tracker, TrackerWithTPS {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UDPDevice getDevice() {
|
||||
return null;
|
||||
public IDevice getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package dev.slimevr.vr.trackers;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public interface Device {
|
||||
|
||||
public static final AtomicInteger nextLocalDeviceId = new AtomicInteger();
|
||||
|
||||
int getId();
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import dev.slimevr.vr.trackers.udp.UDPDevice;
|
||||
import io.eiren.util.BufferedTimer;
|
||||
|
||||
|
||||
public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
|
||||
public class IMUTracker
|
||||
implements Tracker, TrackerWithTPS, TrackerWithBattery, TrackerWithWireless {
|
||||
|
||||
public static final float MAX_MAG_CORRECTION_ACCURACY = 5 * FastMath.RAD_TO_DEG;
|
||||
|
||||
@@ -34,8 +35,8 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
|
||||
public int magCalibrationStatus = 0;
|
||||
public float magnetometerAccuracy = 0;
|
||||
public boolean hasNewCorrectionData = false;
|
||||
public int ping = -1;
|
||||
public int signalStrength = -1;
|
||||
private int ping = -1;
|
||||
private int signalStrength = -1;
|
||||
public float temperature = 0;
|
||||
public TrackerPosition bodyPosition = null;
|
||||
protected CircularArrayList<Quaternion> previousRots;
|
||||
@@ -315,6 +316,24 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPing() {
|
||||
return this.ping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSignalStrength() {
|
||||
return this.signalStrength;
|
||||
}
|
||||
|
||||
public void setPing(int ping) {
|
||||
this.ping = ping;
|
||||
}
|
||||
|
||||
public void setSignalStrength(int signalStrength) {
|
||||
this.signalStrength = signalStrength;
|
||||
}
|
||||
|
||||
public enum CalibrationAccuracy {
|
||||
|
||||
UNRELIABLE(0), LOW(1), MEDIUM(2), HIGH(3),;
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.slimevr.vr.trackers;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
|
||||
|
||||
public class ReferenceAdjustedTracker<E extends Tracker> implements Tracker {
|
||||
@@ -172,7 +173,7 @@ public class ReferenceAdjustedTracker<E extends Tracker> implements Tracker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice() {
|
||||
public IDevice getDevice() {
|
||||
return tracker.getDevice();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.slimevr.vr.trackers;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -50,7 +51,7 @@ public interface Tracker {
|
||||
|
||||
int getTrackerNum();
|
||||
|
||||
Device getDevice();
|
||||
IDevice getDevice();
|
||||
|
||||
/**
|
||||
* Returns the real tracker behind this tracker. In case this tracker
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.slimevr.vr.trackers;
|
||||
|
||||
public interface TrackerWithWireless {
|
||||
|
||||
int getPing();
|
||||
|
||||
int getSignalStrength();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.slimevr.vr.trackers;
|
||||
|
||||
import dev.slimevr.vr.Device;
|
||||
import io.eiren.util.BufferedTimer;
|
||||
|
||||
|
||||
@@ -7,12 +8,19 @@ public class VRTracker extends ComputedTracker {
|
||||
|
||||
protected BufferedTimer timer = new BufferedTimer(1f);
|
||||
|
||||
public VRTracker(int id, String serial, String name, boolean hasRotation, boolean hasPosition) {
|
||||
super(id, serial, name, hasRotation, hasPosition);
|
||||
public VRTracker(
|
||||
int id,
|
||||
String serial,
|
||||
String name,
|
||||
boolean hasRotation,
|
||||
boolean hasPosition,
|
||||
Device device
|
||||
) {
|
||||
super(id, serial, name, hasRotation, hasPosition, device);
|
||||
}
|
||||
|
||||
public VRTracker(int id, String name, boolean hasRotation, boolean hasPosition) {
|
||||
super(id, name, name, hasRotation, hasPosition);
|
||||
super(id, name, name, hasRotation, hasPosition, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -122,6 +122,7 @@ public class TrackersUDPServer extends Thread {
|
||||
}
|
||||
if (connection == null) {
|
||||
connection = new UDPDevice(handshakePacket.getSocketAddress(), addr);
|
||||
Main.vrServer.getDeviceManager().addDevice(connection);
|
||||
connection.firmwareBuild = handshake.firmwareBuild;
|
||||
if (handshake.firmware == null || handshake.firmware.length() == 0) {
|
||||
// Only old owoTrack doesn't report firmware and have different
|
||||
@@ -222,7 +223,7 @@ public class TrackersUDPServer extends Thread {
|
||||
+ " status: "
|
||||
+ sensorStatus
|
||||
);
|
||||
IMUTracker imu = connection.sensors.get(trackerId);
|
||||
IMUTracker imu = connection.getTracker(trackerId);
|
||||
if (imu == null) {
|
||||
imu = new IMUTracker(
|
||||
connection,
|
||||
@@ -233,10 +234,11 @@ public class TrackersUDPServer extends Thread {
|
||||
this,
|
||||
Main.vrServer
|
||||
);
|
||||
connection.sensors.put(trackerId, imu);
|
||||
ReferenceAdjustedTracker<IMUTracker> adjustedTracker = new ReferenceAdjustedTracker<>(
|
||||
imu
|
||||
);
|
||||
|
||||
connection.getTrackers().add(imu);
|
||||
trackersConsumer.accept(adjustedTracker);
|
||||
LogManager
|
||||
.info(
|
||||
@@ -266,7 +268,7 @@ public class TrackersUDPServer extends Thread {
|
||||
try {
|
||||
boolean hasActiveTrackers = false;
|
||||
for (UDPDevice tracker : connections) {
|
||||
if (tracker.sensors.size() > 0) {
|
||||
if (tracker.getTrackers().size() > 0) {
|
||||
hasActiveTrackers = true;
|
||||
break;
|
||||
}
|
||||
@@ -314,7 +316,7 @@ public class TrackersUDPServer extends Thread {
|
||||
parser.write(bb, conn, new UDPPacket1Heartbeat());
|
||||
socket.send(new DatagramPacket(rcvBuffer, bb.position(), conn.address));
|
||||
if (conn.lastPacket + 1000 < System.currentTimeMillis()) {
|
||||
Iterator<IMUTracker> iterator = conn.sensors.values().iterator();
|
||||
Iterator<IMUTracker> iterator = conn.getTrackers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IMUTracker tracker = iterator.next();
|
||||
if (tracker.getStatus() == TrackerStatus.OK)
|
||||
@@ -326,7 +328,7 @@ public class TrackersUDPServer extends Thread {
|
||||
}
|
||||
} else {
|
||||
conn.timedOut = false;
|
||||
Iterator<IMUTracker> iterator = conn.sensors.values().iterator();
|
||||
Iterator<IMUTracker> iterator = conn.getTrackers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IMUTracker tracker = iterator.next();
|
||||
if (tracker.getStatus() == TrackerStatus.DISCONNECTED)
|
||||
@@ -385,7 +387,7 @@ public class TrackersUDPServer extends Thread {
|
||||
UDPPacket1Rotation rotationPacket = (UDPPacket1Rotation) packet;
|
||||
buf.set(rotationPacket.rotation);
|
||||
offset.mult(buf, buf);
|
||||
tracker = connection.sensors.get(rotationPacket.getSensorId());
|
||||
tracker = connection.getTracker(rotationPacket.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
tracker.rotQuaternion.set(buf);
|
||||
@@ -395,7 +397,7 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket17RotationData rotationData = (UDPPacket17RotationData) packet;
|
||||
tracker = connection.sensors.get(rotationData.getSensorId());
|
||||
tracker = connection.getTracker(rotationData.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
buf.set(rotationData.rotation);
|
||||
@@ -418,7 +420,7 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket18MagnetometerAccuracy magAccuracy = (UDPPacket18MagnetometerAccuracy) packet;
|
||||
tracker = connection.sensors.get(magAccuracy.getSensorId());
|
||||
tracker = connection.getTracker(magAccuracy.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
tracker.magnetometerAccuracy = magAccuracy.accuracyInfo;
|
||||
@@ -439,9 +441,13 @@ public class TrackersUDPServer extends Thread {
|
||||
break;
|
||||
UDPPacket10PingPong ping = (UDPPacket10PingPong) packet;
|
||||
if (connection.lastPingPacketId == ping.pingId) {
|
||||
for (IMUTracker imuTracker : connection.sensors.values()) {
|
||||
imuTracker.ping = (int) (System.currentTimeMillis()
|
||||
- connection.lastPingPacketTime) / 2;
|
||||
for (IMUTracker imuTracker : connection.getTrackers()) {
|
||||
imuTracker
|
||||
.setPing(
|
||||
(int) (System.currentTimeMillis()
|
||||
- connection.lastPingPacketTime) / 2
|
||||
);
|
||||
|
||||
imuTracker.dataTick();
|
||||
}
|
||||
} else {
|
||||
@@ -464,9 +470,10 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket12BatteryLevel battery = (UDPPacket12BatteryLevel) packet;
|
||||
if (connection.sensors.size() > 0) {
|
||||
Collection<IMUTracker> trackers = connection.sensors.values();
|
||||
Iterator<IMUTracker> iterator = trackers.iterator();
|
||||
|
||||
if (connection.getTrackers().size() > 0) {
|
||||
Iterator<IMUTracker> iterator = connection.getTrackers().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
IMUTracker tr = iterator.next();
|
||||
tr.setBatteryVoltage(battery.voltage);
|
||||
@@ -478,7 +485,7 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket13Tap tap = (UDPPacket13Tap) packet;
|
||||
tracker = connection.sensors.get(tap.getSensorId());
|
||||
tracker = connection.getTracker(tap.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
LogManager
|
||||
@@ -500,7 +507,7 @@ public class TrackersUDPServer extends Thread {
|
||||
);
|
||||
if (connection == null)
|
||||
break;
|
||||
tracker = connection.sensors.get(error.getSensorId());
|
||||
tracker = connection.getTracker(error.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
tracker.setStatus(TrackerStatus.ERROR);
|
||||
@@ -529,12 +536,12 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket19SignalStrength signalStrength = (UDPPacket19SignalStrength) packet;
|
||||
if (connection.sensors.size() > 0) {
|
||||
Collection<IMUTracker> trackers = connection.sensors.values();
|
||||
Iterator<IMUTracker> iterator = trackers.iterator();
|
||||
|
||||
if (connection.getTrackers().size() > 0) {
|
||||
Iterator<IMUTracker> iterator = connection.getTrackers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IMUTracker tr = iterator.next();
|
||||
tr.signalStrength = signalStrength.signalStrength;
|
||||
tr.setSignalStrength(signalStrength.signalStrength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -542,7 +549,7 @@ public class TrackersUDPServer extends Thread {
|
||||
if (connection == null)
|
||||
break;
|
||||
UDPPacket20Temperature temp = (UDPPacket20Temperature) packet;
|
||||
tracker = connection.sensors.get(temp.getSensorId());
|
||||
tracker = connection.getTracker(temp.getSensorId());
|
||||
if (tracker == null)
|
||||
break;
|
||||
tracker.temperature = temp.temperature;
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package dev.slimevr.vr.trackers.udp;
|
||||
|
||||
import dev.slimevr.NetworkProtocol;
|
||||
import dev.slimevr.vr.trackers.Device;
|
||||
import dev.slimevr.vr.IDevice;
|
||||
import dev.slimevr.vr.trackers.IMUTracker;
|
||||
import io.eiren.util.collections.FastList;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class UDPDevice implements Device {
|
||||
public class UDPDevice implements IDevice {
|
||||
|
||||
public final int id;
|
||||
public Map<Integer, IMUTracker> sensors = new HashMap<>();
|
||||
public SocketAddress address;
|
||||
public InetAddress ipAddress;
|
||||
public long lastPacket = System.currentTimeMillis();
|
||||
@@ -27,6 +25,7 @@ public class UDPDevice implements Device {
|
||||
public NetworkProtocol protocol = null;
|
||||
public int firmwareBuild = 0;
|
||||
public boolean timedOut = false;
|
||||
private final FastList<IMUTracker> trackers = new FastList<>();
|
||||
|
||||
public UDPDevice(SocketAddress address, InetAddress ipAddress) {
|
||||
this.address = address;
|
||||
@@ -50,4 +49,35 @@ public class UDPDevice implements Device {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManufacturer() {
|
||||
return "SlimeVR";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirmwareVersion() {
|
||||
return "v" + firmwareBuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FastList<IMUTracker> getTrackers() {
|
||||
return this.trackers;
|
||||
}
|
||||
|
||||
public IMUTracker getTracker(int id) {
|
||||
if (id >= 0 && id < this.getTrackers().size())
|
||||
return this.getTrackers().get(id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user