@irsdk-node/native 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +46 -46
  2. package/binding.gyp +28 -19
  3. package/dist/INativeSDK.d.ts +28 -0
  4. package/dist/INativeSDK.js +2 -0
  5. package/dist/MockSdk.d.ts +43 -0
  6. package/dist/MockSdk.js +70 -0
  7. package/dist/mock-data/loader.d.ts +3 -0
  8. package/dist/mock-data/loader.js +41 -0
  9. package/dist/mock-data/session.json +4305 -0
  10. package/dist/mock-data/telemetry.json +4986 -0
  11. package/{src/index.d.ts → index.d.ts} +5 -35
  12. package/index.js +36 -0
  13. package/lib/irsdk_client.cpp +495 -495
  14. package/lib/irsdk_client.h +139 -139
  15. package/lib/irsdk_defines.h +528 -528
  16. package/{src → lib}/irsdk_node.cc +404 -375
  17. package/{src → lib}/irsdk_node.h +49 -50
  18. package/lib/irsdk_node_mocked.cc +226 -0
  19. package/lib/irsdk_utils.cpp +377 -377
  20. package/lib/yaml_parser.cpp +176 -176
  21. package/lib/yaml_parser.h +34 -34
  22. package/package.json +37 -29
  23. package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
  24. package/prebuilds/linux-x64/@irsdk-node+native.node +0 -0
  25. package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
  26. package/build/Debug/irsdk_node.exp +0 -0
  27. package/build/Debug/irsdk_node.lib +0 -0
  28. package/build/Debug/irsdk_node.node +0 -0
  29. package/build/Debug/irsdk_node.pdb +0 -0
  30. package/build/Debug/obj/irsdk_node/irsdk_node.node.recipe +0 -11
  31. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  32. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  33. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  34. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
  35. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
  36. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  37. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  38. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -3
  39. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  40. package/build/Debug/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  41. package/build/Debug/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  42. package/build/Debug/obj/irsdk_node/src/irsdk_node.obj +0 -0
  43. package/build/Debug/obj/irsdk_node/vcpkg.applocal.log +0 -1
  44. package/build/Debug/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  45. package/build/Release/irsdk_node.exp +0 -0
  46. package/build/Release/irsdk_node.iobj +0 -0
  47. package/build/Release/irsdk_node.ipdb +0 -0
  48. package/build/Release/irsdk_node.lib +0 -0
  49. package/build/Release/irsdk_node.node +0 -0
  50. package/build/Release/irsdk_node.pdb +0 -0
  51. package/build/Release/obj/irsdk_node/irsdk_node.node.recipe +0 -11
  52. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  53. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  54. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  55. package/build/Release/obj/irsdk_node/irsdk_node.tlog/Cl.items.tlog +0 -4
  56. package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +0 -2
  57. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  58. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  59. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.secondary.1.tlog +0 -5
  60. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  61. package/build/Release/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  62. package/build/Release/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  63. package/build/Release/obj/irsdk_node/src/irsdk_node.obj +0 -0
  64. package/build/Release/obj/irsdk_node/vcpkg.applocal.log +0 -1
  65. package/build/Release/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  66. package/build/binding.sln +0 -19
  67. package/build/config.gypi +0 -426
  68. package/build/irsdk_node.vcxproj +0 -157
  69. package/build/irsdk_node.vcxproj.filters +0 -73
  70. package/dist/index.d.ts +0 -1
  71. package/dist/index.js +0 -13
  72. package/src/index.js +0 -11
@@ -1,495 +1,495 @@
1
- /*
2
- Copyright (c) 2013, iRacing.com Motorsport Simulations, LLC.
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
- * Redistributions of source code must retain the above copyright
8
- notice, this list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright
10
- notice, this list of conditions and the following disclaimer in the
11
- documentation and/or other materials provided with the distribution.
12
- * Neither the name of iRacing.com Motorsport Simulations nor the
13
- names of its contributors may be used to endorse or promote products
14
- derived from this software without specific prior written permission.
15
-
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include <stdio.h>
29
- #include <string.h>
30
-
31
- #include <assert.h>
32
- #include "irsdk_defines.h"
33
- #include "yaml_parser.h"
34
- #include "irsdk_client.h"
35
-
36
- #pragma warning(disable:4996)
37
-
38
- irsdkClient& irsdkClient::instance()
39
- {
40
- static irsdkClient INSTANCE;
41
- return INSTANCE;
42
- }
43
-
44
- bool irsdkClient::waitForData(int timeoutMS)
45
- {
46
- // wait for start of session or new data
47
- if(irsdk_waitForDataReady(timeoutMS, m_data) && irsdk_getHeader())
48
- {
49
- // if new connection, or data changed lenght then init
50
- if(!m_data || m_nData != irsdk_getHeader()->bufLen)
51
- {
52
- // allocate memory to hold incoming data from sim
53
- if(m_data) delete [] m_data;
54
- m_nData = irsdk_getHeader()->bufLen;
55
- m_data = new char[m_nData];
56
-
57
- // indicate a new connection
58
- m_statusID++;
59
-
60
- // reset session info str status
61
- m_lastSessionCt = -1;
62
-
63
- // and try to fill in the data
64
- if(irsdk_getNewData(m_data))
65
- return true;
66
- }
67
- else if(m_data)
68
- {
69
- // else we are allready initialized, and data is ready for processing
70
- return true;
71
- }
72
- }
73
- else if(!isConnected())
74
- {
75
- // else session ended
76
- if(m_data)
77
- delete[] m_data;
78
- m_data = NULL;
79
-
80
- // reset session info str status
81
- m_lastSessionCt = -1;
82
- }
83
-
84
- return false;
85
- }
86
-
87
- void irsdkClient::shutdown()
88
- {
89
- irsdk_shutdown();
90
- if(m_data)
91
- delete[] m_data;
92
- m_data = NULL;
93
-
94
- // reset session info str status
95
- m_lastSessionCt = -1;
96
- }
97
-
98
- bool irsdkClient::isConnected()
99
- {
100
- return m_data != NULL && irsdk_isConnected();
101
- }
102
-
103
- int irsdkClient::getVarIdx(const char*name)
104
- {
105
- if(isConnected())
106
- {
107
- return irsdk_varNameToIndex(name);
108
- }
109
-
110
- return -1;
111
- }
112
-
113
- int /*irsdk_VarType*/ irsdkClient::getVarType(int idx)
114
- {
115
- if(isConnected())
116
- {
117
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
118
- if(vh)
119
- {
120
- return vh->type;
121
- }
122
- else
123
- {
124
- //invalid variable index
125
- assert(false);
126
- }
127
- }
128
-
129
- return irsdk_char;
130
- }
131
-
132
- int irsdkClient::getVarCount(int idx)
133
- {
134
- if(isConnected())
135
- {
136
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
137
- if(vh)
138
- {
139
- return vh->count;
140
- }
141
- else
142
- {
143
- //invalid variable index
144
- assert(false);
145
- }
146
- }
147
-
148
- return 0;
149
- }
150
-
151
- bool irsdkClient::getVarBool(int idx, int entry)
152
- {
153
- if(isConnected())
154
- {
155
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
156
- if(vh)
157
- {
158
- if(entry >= 0 && entry < vh->count)
159
- {
160
- const char * data = m_data + vh->offset;
161
- switch(vh->type)
162
- {
163
- // 1 byte
164
- case irsdk_char:
165
- case irsdk_bool:
166
- return (((const char*)data)[entry]) != 0;
167
- break;
168
-
169
- // 4 bytes
170
- case irsdk_int:
171
- case irsdk_bitField:
172
- return (((const int*)data)[entry]) != 0;
173
- break;
174
-
175
- // test float/double for greater than 1.0 so that
176
- // we have a chance of this being usefull
177
- // technically there is no right conversion...
178
- case irsdk_float:
179
- return (((const float*)data)[entry]) >= 1.0f;
180
- break;
181
-
182
- // 8 bytes
183
- case irsdk_double:
184
- return (((const double*)data)[entry]) >= 1.0;
185
- break;
186
- }
187
- }
188
- else
189
- {
190
- // invalid offset
191
- assert(false);
192
- }
193
- }
194
- else
195
- {
196
- //invalid variable index
197
- assert(false);
198
- }
199
- }
200
-
201
- return false;
202
- }
203
-
204
- int irsdkClient::getVarInt(int idx, int entry)
205
- {
206
- if(isConnected())
207
- {
208
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
209
- if(vh)
210
- {
211
- if(entry >= 0 && entry < vh->count)
212
- {
213
- const char * data = m_data + vh->offset;
214
- switch(vh->type)
215
- {
216
- // 1 byte
217
- case irsdk_char:
218
- case irsdk_bool:
219
- return (int)(((const char*)data)[entry]);
220
- break;
221
-
222
- // 4 bytes
223
- case irsdk_int:
224
- case irsdk_bitField:
225
- return (int)(((const int*)data)[entry]);
226
- break;
227
-
228
- case irsdk_float:
229
- return (int)(((const float*)data)[entry]);
230
- break;
231
-
232
- // 8 bytes
233
- case irsdk_double:
234
- return (int)(((const double*)data)[entry]);
235
- break;
236
- }
237
- }
238
- else
239
- {
240
- // invalid offset
241
- assert(false);
242
- }
243
- }
244
- else
245
- {
246
- //invalid variable index
247
- assert(false);
248
- }
249
- }
250
-
251
- return 0;
252
- }
253
-
254
- float irsdkClient::getVarFloat(int idx, int entry)
255
- {
256
- if(isConnected())
257
- {
258
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
259
- if(vh)
260
- {
261
- if(entry >= 0 && entry < vh->count)
262
- {
263
- const char * data = m_data + vh->offset;
264
- switch(vh->type)
265
- {
266
- // 1 byte
267
- case irsdk_char:
268
- case irsdk_bool:
269
- return (float)(((const char*)data)[entry]);
270
- break;
271
-
272
- // 4 bytes
273
- case irsdk_int:
274
- case irsdk_bitField:
275
- return (float)(((const int*)data)[entry]);
276
- break;
277
-
278
- case irsdk_float:
279
- return (float)(((const float*)data)[entry]);
280
- break;
281
-
282
- // 8 bytes
283
- case irsdk_double:
284
- return (float)(((const double*)data)[entry]);
285
- break;
286
- }
287
- }
288
- else
289
- {
290
- // invalid offset
291
- assert(false);
292
- }
293
- }
294
- else
295
- {
296
- //invalid variable index
297
- assert(false);
298
- }
299
- }
300
-
301
- return 0.0f;
302
- }
303
-
304
- double irsdkClient::getVarDouble(int idx, int entry)
305
- {
306
- if(isConnected())
307
- {
308
- const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
309
- if(vh)
310
- {
311
- if(entry >= 0 && entry < vh->count)
312
- {
313
- const char * data = m_data + vh->offset;
314
- switch(vh->type)
315
- {
316
- // 1 byte
317
- case irsdk_char:
318
- case irsdk_bool:
319
- return (double)(((const char*)data)[entry]);
320
- break;
321
-
322
- // 4 bytes
323
- case irsdk_int:
324
- case irsdk_bitField:
325
- return (double)(((const int*)data)[entry]);
326
- break;
327
-
328
- case irsdk_float:
329
- return (double)(((const float*)data)[entry]);
330
- break;
331
-
332
- // 8 bytes
333
- case irsdk_double:
334
- return (double)(((const double*)data)[entry]);
335
- break;
336
- }
337
- }
338
- else
339
- {
340
- // invalid offset
341
- assert(false);
342
- }
343
- }
344
- else
345
- {
346
- //invalid variable index
347
- assert(false);
348
- }
349
- }
350
-
351
- return 0.0;
352
- }
353
-
354
- //path is in the form of "DriverInfo:Drivers:CarIdx:{%d}UserName:"
355
- int irsdkClient::getSessionStrVal(const char *path, char *val, int valLen)
356
- {
357
- if(isConnected() && path && val && valLen > 0)
358
- {
359
- // track changes in string
360
- m_lastSessionCt = getSessionCt();
361
-
362
- const char *tVal = NULL;
363
- int tValLen = 0;
364
- if(parseYaml(irsdk_getSessionInfoStr(), path, &tVal, &tValLen))
365
- {
366
- // dont overflow out buffer
367
- int len = tValLen;
368
- if(len > valLen)
369
- len = valLen;
370
-
371
- // copy what we can, even if buffer too small
372
- memcpy(val, tVal, len);
373
- val[len] = '\0'; // origional string has no null termination...
374
-
375
- // if buffer was big enough, return success
376
- if(valLen >= tValLen)
377
- return 1;
378
- else // return size of buffer needed
379
- return -tValLen;
380
- }
381
- }
382
-
383
- return 0;
384
- }
385
-
386
- // get the whole string
387
- const char* irsdkClient::getSessionStr()
388
- {
389
- if(isConnected())
390
- {
391
- m_lastSessionCt = getSessionCt();
392
- return irsdk_getSessionInfoStr();
393
- }
394
-
395
- return NULL;
396
- }
397
-
398
-
399
- //----------------------------------
400
-
401
- irsdkCVar::irsdkCVar()
402
- : m_idx(-1)
403
- , m_statusID(-1)
404
- {
405
- m_name[0] = '\0';
406
- }
407
-
408
- irsdkCVar::irsdkCVar(const char *name)
409
- {
410
- m_name[0] = '\0';
411
- setVarName(name);
412
- }
413
-
414
- void irsdkCVar::setVarName(const char *name)
415
- {
416
- if(!name || 0 != strncmp(name, m_name, sizeof(m_name)))
417
- {
418
- m_idx = -1;
419
- m_statusID = -1;
420
-
421
- if(name)
422
- {
423
- strncpy(m_name, name, max_string);
424
- m_name[max_string-1] = '\0';
425
- }
426
- else
427
- m_name[0] = '\0';
428
- }
429
- }
430
-
431
- bool irsdkCVar::checkIdx()
432
- {
433
- if(irsdkClient::instance().isConnected())
434
- {
435
- if(m_statusID != irsdkClient::instance().getStatusID())
436
- {
437
- m_statusID = irsdkClient::instance().getStatusID();
438
- m_idx = irsdkClient::instance().getVarIdx(m_name);
439
- }
440
-
441
- return true;
442
- }
443
-
444
- return false;
445
- }
446
-
447
- int /*irsdk_VarType*/ irsdkCVar::getType()
448
- {
449
- if(checkIdx())
450
- return irsdkClient::instance().getVarType(m_idx);
451
- return 0;
452
- }
453
-
454
- int irsdkCVar::getCount()
455
- {
456
- if(checkIdx())
457
- return irsdkClient::instance().getVarCount(m_idx);
458
- return 0;
459
- }
460
-
461
- bool irsdkCVar::isValid()
462
- {
463
- checkIdx();
464
- return (m_idx > -1);
465
- }
466
-
467
-
468
- bool irsdkCVar::getBool(int entry)
469
- {
470
- if(checkIdx())
471
- return irsdkClient::instance().getVarBool(m_idx, entry);
472
- return false;
473
- }
474
-
475
- int irsdkCVar::getInt(int entry)
476
- {
477
- if(checkIdx())
478
- return irsdkClient::instance().getVarInt(m_idx, entry);
479
- return 0;
480
- }
481
-
482
- float irsdkCVar::getFloat(int entry)
483
- {
484
- if(checkIdx())
485
- return irsdkClient::instance().getVarFloat(m_idx, entry);
486
- return 0.0f;
487
- }
488
-
489
- double irsdkCVar::getDouble(int entry)
490
- {
491
- if(checkIdx())
492
- return irsdkClient::instance().getVarDouble(m_idx, entry);
493
- return 0.0;
494
- }
495
-
1
+ /*
2
+ Copyright (c) 2013, iRacing.com Motorsport Simulations, LLC.
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ * Neither the name of iRacing.com Motorsport Simulations nor the
13
+ names of its contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdio.h>
29
+ #include <string.h>
30
+
31
+ #include <assert.h>
32
+ #include "irsdk_defines.h"
33
+ #include "yaml_parser.h"
34
+ #include "irsdk_client.h"
35
+
36
+ #pragma warning(disable:4996)
37
+
38
+ irsdkClient& irsdkClient::instance()
39
+ {
40
+ static irsdkClient INSTANCE;
41
+ return INSTANCE;
42
+ }
43
+
44
+ bool irsdkClient::waitForData(int timeoutMS)
45
+ {
46
+ // wait for start of session or new data
47
+ if(irsdk_waitForDataReady(timeoutMS, m_data) && irsdk_getHeader())
48
+ {
49
+ // if new connection, or data changed lenght then init
50
+ if(!m_data || m_nData != irsdk_getHeader()->bufLen)
51
+ {
52
+ // allocate memory to hold incoming data from sim
53
+ if(m_data) delete [] m_data;
54
+ m_nData = irsdk_getHeader()->bufLen;
55
+ m_data = new char[m_nData];
56
+
57
+ // indicate a new connection
58
+ m_statusID++;
59
+
60
+ // reset session info str status
61
+ m_lastSessionCt = -1;
62
+
63
+ // and try to fill in the data
64
+ if(irsdk_getNewData(m_data))
65
+ return true;
66
+ }
67
+ else if(m_data)
68
+ {
69
+ // else we are allready initialized, and data is ready for processing
70
+ return true;
71
+ }
72
+ }
73
+ else if(!isConnected())
74
+ {
75
+ // else session ended
76
+ if(m_data)
77
+ delete[] m_data;
78
+ m_data = NULL;
79
+
80
+ // reset session info str status
81
+ m_lastSessionCt = -1;
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ void irsdkClient::shutdown()
88
+ {
89
+ irsdk_shutdown();
90
+ if(m_data)
91
+ delete[] m_data;
92
+ m_data = NULL;
93
+
94
+ // reset session info str status
95
+ m_lastSessionCt = -1;
96
+ }
97
+
98
+ bool irsdkClient::isConnected()
99
+ {
100
+ return m_data != NULL && irsdk_isConnected();
101
+ }
102
+
103
+ int irsdkClient::getVarIdx(const char*name)
104
+ {
105
+ if(isConnected())
106
+ {
107
+ return irsdk_varNameToIndex(name);
108
+ }
109
+
110
+ return -1;
111
+ }
112
+
113
+ int /*irsdk_VarType*/ irsdkClient::getVarType(int idx)
114
+ {
115
+ if(isConnected())
116
+ {
117
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
118
+ if(vh)
119
+ {
120
+ return vh->type;
121
+ }
122
+ else
123
+ {
124
+ //invalid variable index
125
+ assert(false);
126
+ }
127
+ }
128
+
129
+ return irsdk_char;
130
+ }
131
+
132
+ int irsdkClient::getVarCount(int idx)
133
+ {
134
+ if(isConnected())
135
+ {
136
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
137
+ if(vh)
138
+ {
139
+ return vh->count;
140
+ }
141
+ else
142
+ {
143
+ //invalid variable index
144
+ assert(false);
145
+ }
146
+ }
147
+
148
+ return 0;
149
+ }
150
+
151
+ bool irsdkClient::getVarBool(int idx, int entry)
152
+ {
153
+ if(isConnected())
154
+ {
155
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
156
+ if(vh)
157
+ {
158
+ if(entry >= 0 && entry < vh->count)
159
+ {
160
+ const char * data = m_data + vh->offset;
161
+ switch(vh->type)
162
+ {
163
+ // 1 byte
164
+ case irsdk_char:
165
+ case irsdk_bool:
166
+ return (((const char*)data)[entry]) != 0;
167
+ break;
168
+
169
+ // 4 bytes
170
+ case irsdk_int:
171
+ case irsdk_bitField:
172
+ return (((const int*)data)[entry]) != 0;
173
+ break;
174
+
175
+ // test float/double for greater than 1.0 so that
176
+ // we have a chance of this being usefull
177
+ // technically there is no right conversion...
178
+ case irsdk_float:
179
+ return (((const float*)data)[entry]) >= 1.0f;
180
+ break;
181
+
182
+ // 8 bytes
183
+ case irsdk_double:
184
+ return (((const double*)data)[entry]) >= 1.0;
185
+ break;
186
+ }
187
+ }
188
+ else
189
+ {
190
+ // invalid offset
191
+ assert(false);
192
+ }
193
+ }
194
+ else
195
+ {
196
+ //invalid variable index
197
+ assert(false);
198
+ }
199
+ }
200
+
201
+ return false;
202
+ }
203
+
204
+ int irsdkClient::getVarInt(int idx, int entry)
205
+ {
206
+ if(isConnected())
207
+ {
208
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
209
+ if(vh)
210
+ {
211
+ if(entry >= 0 && entry < vh->count)
212
+ {
213
+ const char * data = m_data + vh->offset;
214
+ switch(vh->type)
215
+ {
216
+ // 1 byte
217
+ case irsdk_char:
218
+ case irsdk_bool:
219
+ return (int)(((const char*)data)[entry]);
220
+ break;
221
+
222
+ // 4 bytes
223
+ case irsdk_int:
224
+ case irsdk_bitField:
225
+ return (int)(((const int*)data)[entry]);
226
+ break;
227
+
228
+ case irsdk_float:
229
+ return (int)(((const float*)data)[entry]);
230
+ break;
231
+
232
+ // 8 bytes
233
+ case irsdk_double:
234
+ return (int)(((const double*)data)[entry]);
235
+ break;
236
+ }
237
+ }
238
+ else
239
+ {
240
+ // invalid offset
241
+ assert(false);
242
+ }
243
+ }
244
+ else
245
+ {
246
+ //invalid variable index
247
+ assert(false);
248
+ }
249
+ }
250
+
251
+ return 0;
252
+ }
253
+
254
+ float irsdkClient::getVarFloat(int idx, int entry)
255
+ {
256
+ if(isConnected())
257
+ {
258
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
259
+ if(vh)
260
+ {
261
+ if(entry >= 0 && entry < vh->count)
262
+ {
263
+ const char * data = m_data + vh->offset;
264
+ switch(vh->type)
265
+ {
266
+ // 1 byte
267
+ case irsdk_char:
268
+ case irsdk_bool:
269
+ return (float)(((const char*)data)[entry]);
270
+ break;
271
+
272
+ // 4 bytes
273
+ case irsdk_int:
274
+ case irsdk_bitField:
275
+ return (float)(((const int*)data)[entry]);
276
+ break;
277
+
278
+ case irsdk_float:
279
+ return (float)(((const float*)data)[entry]);
280
+ break;
281
+
282
+ // 8 bytes
283
+ case irsdk_double:
284
+ return (float)(((const double*)data)[entry]);
285
+ break;
286
+ }
287
+ }
288
+ else
289
+ {
290
+ // invalid offset
291
+ assert(false);
292
+ }
293
+ }
294
+ else
295
+ {
296
+ //invalid variable index
297
+ assert(false);
298
+ }
299
+ }
300
+
301
+ return 0.0f;
302
+ }
303
+
304
+ double irsdkClient::getVarDouble(int idx, int entry)
305
+ {
306
+ if(isConnected())
307
+ {
308
+ const irsdk_varHeader *vh = irsdk_getVarHeaderEntry(idx);
309
+ if(vh)
310
+ {
311
+ if(entry >= 0 && entry < vh->count)
312
+ {
313
+ const char * data = m_data + vh->offset;
314
+ switch(vh->type)
315
+ {
316
+ // 1 byte
317
+ case irsdk_char:
318
+ case irsdk_bool:
319
+ return (double)(((const char*)data)[entry]);
320
+ break;
321
+
322
+ // 4 bytes
323
+ case irsdk_int:
324
+ case irsdk_bitField:
325
+ return (double)(((const int*)data)[entry]);
326
+ break;
327
+
328
+ case irsdk_float:
329
+ return (double)(((const float*)data)[entry]);
330
+ break;
331
+
332
+ // 8 bytes
333
+ case irsdk_double:
334
+ return (double)(((const double*)data)[entry]);
335
+ break;
336
+ }
337
+ }
338
+ else
339
+ {
340
+ // invalid offset
341
+ assert(false);
342
+ }
343
+ }
344
+ else
345
+ {
346
+ //invalid variable index
347
+ assert(false);
348
+ }
349
+ }
350
+
351
+ return 0.0;
352
+ }
353
+
354
+ //path is in the form of "DriverInfo:Drivers:CarIdx:{%d}UserName:"
355
+ int irsdkClient::getSessionStrVal(const char *path, char *val, int valLen)
356
+ {
357
+ if(isConnected() && path && val && valLen > 0)
358
+ {
359
+ // track changes in string
360
+ m_lastSessionCt = getSessionCt();
361
+
362
+ const char *tVal = NULL;
363
+ int tValLen = 0;
364
+ if(parseYaml(irsdk_getSessionInfoStr(), path, &tVal, &tValLen))
365
+ {
366
+ // dont overflow out buffer
367
+ int len = tValLen;
368
+ if(len > valLen)
369
+ len = valLen;
370
+
371
+ // copy what we can, even if buffer too small
372
+ memcpy(val, tVal, len);
373
+ val[len] = '\0'; // origional string has no null termination...
374
+
375
+ // if buffer was big enough, return success
376
+ if(valLen >= tValLen)
377
+ return 1;
378
+ else // return size of buffer needed
379
+ return -tValLen;
380
+ }
381
+ }
382
+
383
+ return 0;
384
+ }
385
+
386
+ // get the whole string
387
+ const char* irsdkClient::getSessionStr()
388
+ {
389
+ if(isConnected())
390
+ {
391
+ m_lastSessionCt = getSessionCt();
392
+ return irsdk_getSessionInfoStr();
393
+ }
394
+
395
+ return NULL;
396
+ }
397
+
398
+
399
+ //----------------------------------
400
+
401
+ irsdkCVar::irsdkCVar()
402
+ : m_idx(-1)
403
+ , m_statusID(-1)
404
+ {
405
+ m_name[0] = '\0';
406
+ }
407
+
408
+ irsdkCVar::irsdkCVar(const char *name)
409
+ {
410
+ m_name[0] = '\0';
411
+ setVarName(name);
412
+ }
413
+
414
+ void irsdkCVar::setVarName(const char *name)
415
+ {
416
+ if(!name || 0 != strncmp(name, m_name, sizeof(m_name)))
417
+ {
418
+ m_idx = -1;
419
+ m_statusID = -1;
420
+
421
+ if(name)
422
+ {
423
+ strncpy(m_name, name, max_string);
424
+ m_name[max_string-1] = '\0';
425
+ }
426
+ else
427
+ m_name[0] = '\0';
428
+ }
429
+ }
430
+
431
+ bool irsdkCVar::checkIdx()
432
+ {
433
+ if(irsdkClient::instance().isConnected())
434
+ {
435
+ if(m_statusID != irsdkClient::instance().getStatusID())
436
+ {
437
+ m_statusID = irsdkClient::instance().getStatusID();
438
+ m_idx = irsdkClient::instance().getVarIdx(m_name);
439
+ }
440
+
441
+ return true;
442
+ }
443
+
444
+ return false;
445
+ }
446
+
447
+ int /*irsdk_VarType*/ irsdkCVar::getType()
448
+ {
449
+ if(checkIdx())
450
+ return irsdkClient::instance().getVarType(m_idx);
451
+ return 0;
452
+ }
453
+
454
+ int irsdkCVar::getCount()
455
+ {
456
+ if(checkIdx())
457
+ return irsdkClient::instance().getVarCount(m_idx);
458
+ return 0;
459
+ }
460
+
461
+ bool irsdkCVar::isValid()
462
+ {
463
+ checkIdx();
464
+ return (m_idx > -1);
465
+ }
466
+
467
+
468
+ bool irsdkCVar::getBool(int entry)
469
+ {
470
+ if(checkIdx())
471
+ return irsdkClient::instance().getVarBool(m_idx, entry);
472
+ return false;
473
+ }
474
+
475
+ int irsdkCVar::getInt(int entry)
476
+ {
477
+ if(checkIdx())
478
+ return irsdkClient::instance().getVarInt(m_idx, entry);
479
+ return 0;
480
+ }
481
+
482
+ float irsdkCVar::getFloat(int entry)
483
+ {
484
+ if(checkIdx())
485
+ return irsdkClient::instance().getVarFloat(m_idx, entry);
486
+ return 0.0f;
487
+ }
488
+
489
+ double irsdkCVar::getDouble(int entry)
490
+ {
491
+ if(checkIdx())
492
+ return irsdkClient::instance().getVarDouble(m_idx, entry);
493
+ return 0.0;
494
+ }
495
+