-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathclient_commandline.cpp
More file actions
619 lines (591 loc) · 23.5 KB
/
Copy pathclient_commandline.cpp
File metadata and controls
619 lines (591 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#include "client_commandline.h"
#include <iostream>
#include <openvr.h>
#include <vrinputemulator.h>
#include <openvr_math.h>
void listDevices(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe listdevices";
throw std::runtime_error(ss.str());
}
vr::EVRInitError vrInitError;
vr::VR_Init(&vrInitError, vr::EVRApplicationType::VRApplication_Background);
if (vrInitError != vr::VRInitError_None) {
std::cout << "OpenVR error: " << vr::VR_GetVRInitErrorAsEnglishDescription(vrInitError) << std::endl;
exit(2);
}
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i) {
auto deviceClass = vr::VRSystem()->GetTrackedDeviceClass(i);
if (deviceClass != vr::TrackedDeviceClass_Invalid) {
vr::ETrackedPropertyError pError;
char serial[1028] = { '\0' };
vr::VRSystem()->GetStringTrackedDeviceProperty(i, vr::Prop_SerialNumber_String, serial, 1028, &pError);
char manufacturer[1028] = { '\0' };
vr::VRSystem()->GetStringTrackedDeviceProperty(i, vr::Prop_ManufacturerName_String, manufacturer, 1028, &pError);
char model[1028] = { '\0' };
vr::VRSystem()->GetStringTrackedDeviceProperty(i, vr::Prop_ModelNumber_String, model, 1028, &pError);
std::string deviceClassStr;
if (deviceClass == vr::TrackedDeviceClass_HMD) {
deviceClassStr = "HMD";
} else if (deviceClass == vr::TrackedDeviceClass_Controller) {
deviceClassStr = "Controller";
} else if (deviceClass == vr::TrackedDeviceClass_GenericTracker) {
deviceClassStr = "GenericTracker";
} else if (deviceClass == vr::TrackedDeviceClass_TrackingReference) {
deviceClassStr = "TrackingReference";
} else {
deviceClassStr = "Unknown";
}
std::cout << "Device " << i << " [" << deviceClassStr << "]: " << manufacturer << " - " << model
<< " [" << serial << "] (connected: " << vr::VRSystem()->IsTrackedDeviceConnected(i) << ")" << std::endl;
}
}
vr::VR_Shutdown();
}
void buttonEvent(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe buttonevent [press|pressandhold|unpress|touch|touchandhold|untouch] <openvrId> <buttonId> [pressTime]";
throw std::runtime_error(ss.str());
} else if (argc < 5) {
throw std::runtime_error("Error: Too few arguments.");
}
bool noHold = false;
vrinputemulator::ButtonEventType eventType;
if (std::strcmp(argv[2], "press") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonPressed;
noHold = true;
} else if (std::strcmp(argv[2], "pressandhold") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonPressed;
} else if (std::strcmp(argv[2], "unpress") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonUnpressed;
} else if (std::strcmp(argv[2], "touch") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonTouched;
noHold = true;
} else if (std::strcmp(argv[2], "touchandhold") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonTouched;
} else if (std::strcmp(argv[2], "untouch") == 0) {
eventType = vrinputemulator::ButtonEventType::ButtonUntouched;
} else {
throw std::runtime_error( std::string("Error: Unknown button event type ") + std::string(argv[2]));
}
uint32_t holdTime = 50;
if (noHold) {
if (argc > 5) {
holdTime = std::atoi(argv[5]);
}
}
uint32_t deviceId = std::atoi(argv[3]);
vr::EVRButtonId buttonId = (vr::EVRButtonId)std::atoi(argv[4]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
inputEmulator.openvrButtonEvent(eventType, deviceId, buttonId, 0.0);
if (noHold) {
std::this_thread::sleep_for(std::chrono::milliseconds(holdTime));
if (eventType == vrinputemulator::ButtonEventType::ButtonPressed) {
eventType = vrinputemulator::ButtonEventType::ButtonUnpressed;
} else {
eventType = vrinputemulator::ButtonEventType::ButtonUntouched;
}
inputEmulator.openvrButtonEvent(eventType, deviceId, buttonId, 0.0);
}
}
void axisEvent(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe axisevent <openvrId> <axisId> <x> <y>";
throw std::runtime_error(ss.str());
} else if (argc < 6) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
uint32_t axisId = std::atoi(argv[3]);
vr::VRControllerAxis_t axisState;
axisState.x = (float)std::atof(argv[4]);
axisState.y = (float)std::atof(argv[5]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
inputEmulator.openvrAxisEvent(deviceId, axisId, axisState);
}
void proximitySensorEvent(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe proximitysensor <openvrId> [0|1]";
throw std::runtime_error(ss.str());
} else if (argc < 4) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
bool triggered = std::atoi(argv[3]) != 0;
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
inputEmulator.openvrProximitySensorEvent(deviceId, triggered);
}
void listVirtual(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe listvirtual";
throw std::runtime_error(ss.str());
}
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
auto deviceCount = inputEmulator.getVirtualDeviceCount();
for (unsigned i = 0; i < deviceCount; ++i) {
auto deviceInfo = inputEmulator.getVirtualDeviceInfo(i);
std::string deviceType;
switch (deviceInfo.deviceType) {
case vrinputemulator::VirtualDeviceType::TrackedController:
deviceType = "TrackedController";
break;
default:
deviceType = "Unknown";
break;
}
std::string openVRIdStr;
if (deviceInfo.openvrDeviceId == vr::k_unTrackedDeviceIndexInvalid) {
openVRIdStr = "<none>";
} else {
openVRIdStr = std::to_string(deviceInfo.openvrDeviceId);
}
std::cout << "Virtual Device " << i << " [" << deviceType << "]: Serial " << deviceInfo.deviceSerial << ", OpenVR Id " << openVRIdStr << std::endl;
}
}
void addTrackedController(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe addcontroller <serialnumber>";
throw std::runtime_error(ss.str());
} else if (argc < 3) {
throw std::runtime_error("Error: Too few arguments.");
}
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
std::cout << inputEmulator.addVirtualDevice(vrinputemulator::VirtualDeviceType::TrackedController, argv[2], false);
}
void publishTrackedDevice(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe publishdevice <virtualId>";
throw std::runtime_error(ss.str());
} else if (argc < 3) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
inputEmulator.publishVirtualDevice(deviceId);
}
void setDeviceProperty(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe setdeviceproperty <virtualId> <property> [int32|uint64|float|bool|string] <value>";
throw std::runtime_error(ss.str());
} else if (argc < 6) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
vr::ETrackedDeviceProperty deviceProperty = (vr::ETrackedDeviceProperty)std::atoi(argv[3]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
if (std::strcmp(argv[4], "int32") == 0) {
inputEmulator.setVirtualDeviceProperty(deviceId, deviceProperty, (int32_t)std::atoi(argv[5]));
} else if (std::strcmp(argv[4], "uint64") == 0) {
inputEmulator.setVirtualDeviceProperty(deviceId, deviceProperty, (uint64_t)std::atoll(argv[5]));
} else if (std::strcmp(argv[4], "float") == 0) {
inputEmulator.setVirtualDeviceProperty(deviceId, deviceProperty, (float)std::atof(argv[5]));
} else if (std::strcmp(argv[4], "bool") == 0) {
inputEmulator.setVirtualDeviceProperty(deviceId, deviceProperty, std::atoi(argv[5]) != 0);
} else if (std::strcmp(argv[4], "string") == 0) {
inputEmulator.setVirtualDeviceProperty(deviceId, deviceProperty, argv[5]);
} else {
throw std::runtime_error("Unknown value type.");
}
}
void getDeviceProperty(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe getdeviceproperty <openvrId> scan" << std::endl
<< " client_commandline.exe getdeviceproperty <openvrId> <property> [int32|uint64|float|bool|string]";
throw std::runtime_error(ss.str());
} else if (argc < 4) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
vr::EVRInitError vrInitError;
vr::VR_Init(&vrInitError, vr::EVRApplicationType::VRApplication_Background);
if (vrInitError != vr::VRInitError_None) {
std::cout << "OpenVR error: " << vr::VR_GetVRInitErrorAsEnglishDescription(vrInitError) << std::endl;
exit(2);
}
if (std::strcmp(argv[3], "scan") == 0) {
for (int p = 1; p < 20000; p++) {
vr::ETrackedPropertyError error;
auto valueInt32 = vr::VRSystem()->GetInt32TrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tint32\t" << valueInt32 << std::endl;
continue;
}
auto valueUint64 = vr::VRSystem()->GetUint64TrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tuint64\t" << valueUint64 << std::endl;
continue;
}
auto valueBool = vr::VRSystem()->GetBoolTrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tbool\t" << valueBool << std::endl;
continue;
}
auto valueFloat = vr::VRSystem()->GetFloatTrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tfloat\t" << valueFloat << std::endl;
continue;
}
char buffer[1024] = { '\0' };
vr::VRSystem()->GetStringTrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, buffer, 1024, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tstring\t" << buffer << std::endl;
continue;
}
auto valueMatrix34 = vr::VRSystem()->GetMatrix34TrackedDeviceProperty(deviceId, (vr::ETrackedDeviceProperty)p, &error);
if (error == vr::TrackedProp_Success) {
std::cout << p << "\tmatrix34\t{";
for (int i = 0; i < 3; ++i) {
std::cout << "{";
bool isFirst = true;
for (int j = 0; j < 4; ++j) {
if (isFirst) {
isFirst = false;
} else {
std::cout << ", ";
}
std::cout << valueMatrix34.m[i][j];
}
std::cout << "}";
}
std::cout << "}" << std::endl;
continue;
}
}
} else {
if (argc < 5) {
throw std::runtime_error("Error: Too few arguments.");
}
vr::ETrackedDeviceProperty deviceProperty = (vr::ETrackedDeviceProperty)std::atoi(argv[3]);
if (std::strcmp(argv[4], "int32") == 0) {
vr::ETrackedPropertyError error;
auto value = vr::VRSystem()->GetInt32TrackedDeviceProperty(deviceId, deviceProperty, &error);
if (error == vr::TrackedProp_Success) {
std::cout << value;
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else if (std::strcmp(argv[4], "uint64") == 0) {
vr::ETrackedPropertyError error;
auto value = vr::VRSystem()->GetUint64TrackedDeviceProperty(deviceId, deviceProperty, &error);
if (error == vr::TrackedProp_Success) {
std::cout << value;
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else if (std::strcmp(argv[4], "float") == 0) {
vr::ETrackedPropertyError error;
auto value = vr::VRSystem()->GetFloatTrackedDeviceProperty(deviceId, deviceProperty, &error);
if (error == vr::TrackedProp_Success) {
std::cout << value;
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else if (std::strcmp(argv[4], "bool") == 0) {
vr::ETrackedPropertyError error;
auto value = vr::VRSystem()->GetBoolTrackedDeviceProperty(deviceId, deviceProperty, &error);
if (error == vr::TrackedProp_Success) {
std::cout << (value ? "true" : "false");
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else if (std::strcmp(argv[4], "string") == 0) {
vr::ETrackedPropertyError error;
char buffer[1024] = { '\0' };
vr::VRSystem()->GetStringTrackedDeviceProperty(deviceId, deviceProperty, buffer, 1024, &error);
if (error == vr::TrackedProp_Success) {
std::cout << buffer;
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else if (std::strcmp(argv[4], "matrix34") == 0) {
vr::ETrackedPropertyError error;
auto value = vr::VRSystem()->GetMatrix34TrackedDeviceProperty(deviceId, deviceProperty, &error);
if (error == vr::TrackedProp_Success) {
std::cout << "{";
for (int i = 0; i < 3; ++i) {
std::cout << "{";
bool isFirst = true;
for (int j = 0; j < 4; ++j) {
if (isFirst) {
isFirst = false;
} else {
std::cout << ", ";
}
std::cout << value.m[i][j];
}
std::cout << "}";
}
std::cout << "}";
} else {
std::stringstream ss;
ss << "Could not get device property: " << vr::VRSystem()->GetPropErrorNameFromEnum(error);
throw std::runtime_error(ss.str());
}
} else {
throw std::runtime_error("Unknown value type.");
}
}
vr::VR_Shutdown();
}
void removeDeviceProperty(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe removedeviceproperty <virtualId> <property>";
throw std::runtime_error(ss.str());
} else if (argc < 4) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
vr::ETrackedDeviceProperty deviceProperty = (vr::ETrackedDeviceProperty)std::atoi(argv[3]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
inputEmulator.removeVirtualDeviceProperty(deviceId, deviceProperty);
}
void setDeviceConnection(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe setdeviceconnection <virtualId> [0|1]";
throw std::runtime_error(ss.str());
} else if (argc < 4) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
bool connected = std::atoi(argv[3]) != 0;
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
auto pose = inputEmulator.getVirtualDevicePose(deviceId);
if (pose.deviceIsConnected != connected) {
pose.deviceIsConnected = connected;
pose.poseIsValid = connected;
inputEmulator.setVirtualDevicePose(deviceId, pose);
}
}
void setDevicePosition(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe setdeviceposition <virtualId> <x> <y> <z>";
throw std::runtime_error(ss.str());
} else if (argc < 6) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
float x = (float)std::atof(argv[3]);
float y = (float)std::atof(argv[4]);
float z = (float)std::atof(argv[5]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
auto pose = inputEmulator.getVirtualDevicePose(deviceId);
pose.vecPosition[0] = x;
pose.vecPosition[1] = y;
pose.vecPosition[2] = z;
pose.poseIsValid = true;
pose.result = vr::TrackingResult_Running_OK;
inputEmulator.setVirtualDevicePose(deviceId, pose);
}
void setDeviceRotation(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe setdevicerotation <virtualId> <yaw> <pitch> <roll>";
throw std::runtime_error(ss.str());
} else if (argc < 6) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
float yaw = (float)std::atof(argv[3]);
float pitch = (float)std::atof(argv[4]);
float roll = (float)std::atof(argv[5]);
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
auto pose = inputEmulator.getVirtualDevicePose(deviceId);
pose.qRotation = vrmath::quaternionFromYawPitchRoll(yaw, pitch, roll);
pose.poseIsValid = true;
pose.result = vr::TrackingResult_Running_OK;
inputEmulator.setVirtualDevicePose(deviceId, pose);
}
void deviceOffsets(int argc, const char * argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe deviceoffsets <openvrId> [enable|disable]" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set worldPosOffset <x> <y> <z>" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set worldRotOffset <yaw> <pitch> <roll>" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set driverPosOffset <x> <y> <z>" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set driverRotOffset <yaw> <pitch> <roll>" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set devicePosOffset <x> <y> <z>" << std::endl
<< " client_commandline.exe deviceoffsets <openvrId> set deviceRotOffset <yaw> <pitch> <roll>";
throw std::runtime_error(ss.str());
} else if (argc < 4) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t deviceId = std::atoi(argv[2]);
uint32_t enable = 0;
bool offsetValid = false;
int universe = 0;
int type = 0;
double offset[3];
if (std::strcmp(argv[3], "enable") == 0) {
enable = 1;
} else if (std::strcmp(argv[3], "disable") == 0) {
enable = 2;
} else if (std::strcmp(argv[3], "set") == 0) {
if (argc < 8) {
throw std::runtime_error("Error: Too few arguments.");
}
if (std::strcmp(argv[4], "worldPosOffset") == 0) {
universe = 1;
type = 2;
} else if (std::strcmp(argv[4], "worldRotOffset") == 0) {
universe = 1;
type = 1;
} else if (std::strcmp(argv[4], "driverPosOffset") == 0) {
universe = 2;
type = 2;
} else if (std::strcmp(argv[4], "driverRotOffset") == 0) {
universe = 2;
type = 1;
} else if (std::strcmp(argv[4], "deviceRotOffset") == 0) {
universe = 3;
type = 1;
} else if (std::strcmp(argv[4], "devicePosOffset") == 0) {
universe = 3;
type = 2;
} else {
throw std::runtime_error("Error: Unknown argument.");
}
offset[0] = std::atof(argv[5]);
offset[1] = std::atof(argv[6]);
offset[2] = std::atof(argv[7]);
offsetValid = true;
} else {
throw std::runtime_error("Error: Unknown pose offset command");
}
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
if (enable > 0) {
inputEmulator.enableDeviceOffsets(deviceId, enable == 1 ? true : false);
} else if (offsetValid) {
if (type == 1) {
vr::HmdQuaternion_t rot = vrmath::quaternionFromYawPitchRoll(offset[0], offset[1], offset[2]);
switch (universe) {
case 1:
inputEmulator.setWorldFromDriverRotationOffset(deviceId, rot);
break;
case 2:
inputEmulator.setDriverFromHeadRotationOffset(deviceId, rot);
break;
case 3:
inputEmulator.setDriverRotationOffset(deviceId, rot);
break;
default:
throw std::runtime_error("Error: Unknown universe");
}
} else if (type == 2) {
vr::HmdVector3d_t pos = {offset[0], offset[1], offset[2]};
switch (universe) {
case 1:
inputEmulator.setWorldFromDriverTranslationOffset(deviceId, pos);
break;
case 2:
inputEmulator.setDriverFromHeadTranslationOffset(deviceId, pos);
break;
case 3:
inputEmulator.setDriverTranslationOffset(deviceId, pos);
break;
default:
throw std::runtime_error("Error: Unknown universe");
}
} else {
throw std::runtime_error("Error: Unknown type");
}
}
}
void benchmarkIPC(int argc, const char* argv[]) {
if (argc > 2 && std::strcmp(argv[2], "help") == 0) {
std::stringstream ss;
ss << "Usage: client_commandline.exe benchmarkipc [all|roundtrip|throughput1|throughput2|throughput]";
throw std::runtime_error(ss.str());
} else if (argc < 3) {
throw std::runtime_error("Error: Too few arguments.");
}
uint32_t benchmarkMask = 0;
if (std::strcmp(argv[2], "all") == 0) {
benchmarkMask = 0xFFFFFFFF;
} else if (std::strcmp(argv[2], "roundtrip") == 0) {
benchmarkMask = 1;
} else if (std::strcmp(argv[2], "throughput1") == 0) {
benchmarkMask = 1 << 1;
} else if (std::strcmp(argv[2], "throughput2") == 0) {
benchmarkMask = 1 << 2;
} else if (std::strcmp(argv[2], "throughput") == 0) {
benchmarkMask = (1 << 2) | (1 << 1);
} else {
throw std::runtime_error("Error: Unknown benchmark");
}
unsigned loopCounterMax = 1000;
if (argc > 3) {
loopCounterMax = std::atoi(argv[3]);
}
std::cout << "Message count: " << loopCounterMax << std::endl;
vrinputemulator::VRInputEmulator inputEmulator;
inputEmulator.connect();
if (benchmarkMask & 1) {
auto startTime = std::chrono::system_clock::now();
for (unsigned i = 0; i < loopCounterMax; ++i) {
inputEmulator.ping();
}
auto stopTime = std::chrono::system_clock::now();
auto timeDiff = stopTime - startTime;
double timeMillis = (double)std::chrono::duration_cast <std::chrono::milliseconds>(timeDiff).count();
std::cout << "Average IPC round-trip time: " << timeMillis / (double)loopCounterMax << " ms (total time: " << timeMillis << " ms)" << std::endl;
std::cout << "Average IPC round-trip messages/s: " << 1000.0 * (double)loopCounterMax / timeMillis << " msg/s" << std::endl;
}
if (benchmarkMask & (1 << 1)) {
auto startTime = std::chrono::system_clock::now();
for (unsigned i = 0; i < loopCounterMax; ++i) {
inputEmulator.ping(false, true);
}
inputEmulator.ping(); // wait till queue is empty
auto stopTime = std::chrono::system_clock::now();
auto timeDiff = stopTime - startTime;
double timeMillis = (double)std::chrono::duration_cast <std::chrono::milliseconds>(timeDiff).count();
std::cout << "Average IPC two-way messages/s: " << 1000.0 * (double)loopCounterMax / timeMillis << " msg/s (total time: " << timeMillis << " ms)" << std::endl;
}
if (benchmarkMask & (1 << 2)) {
auto startTime = std::chrono::system_clock::now();
for (unsigned i = 0; i < loopCounterMax; ++i) {
inputEmulator.ping(false, false);
}
inputEmulator.ping(); // wait till queue is empty
auto stopTime = std::chrono::system_clock::now();
auto timeDiff = stopTime - startTime;
double timeMillis = (double)std::chrono::duration_cast <std::chrono::milliseconds>(timeDiff).count();
std::cout << "Average IPC one-way messages/s: " << 1000.0 * (double)loopCounterMax / timeMillis << " msg/s (total time: " << timeMillis << " ms)" << std::endl;
}
std::cout << "IPC request size: " << sizeof(vrinputemulator::ipc::Request) << " bytes" << std::endl;
std::cout << "IPC reply size: " << sizeof(vrinputemulator::ipc::Reply) << " bytes" << std::endl;
}