@irsdk-node/native 4.1.1 → 5.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.
- package/README.md +21 -1
- package/dist/cjs/index.cjs +9454 -0
- package/dist/esm/index.js +9441 -0
- package/dist/types/INativeSDK.d.ts +24 -0
- package/dist/types/MockSdk.d.ts +31 -0
- package/dist/types/index.d.ts +4 -0
- package/lib/irsdk_client.cpp +94 -94
- package/lib/irsdk_client.h +23 -23
- package/lib/irsdk_defines.h +136 -82
- package/lib/irsdk_diskclient.cpp +997 -0
- package/lib/irsdk_diskclient.h +205 -0
- package/lib/irsdk_node.cc +336 -283
- package/lib/irsdk_utils.cpp +71 -71
- package/lib/yaml_parser.cpp +41 -41
- package/lib/yaml_parser.h +1 -1
- package/package.json +27 -29
- package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/dist/INativeSDK.d.ts +0 -28
- package/dist/INativeSDK.js +0 -2
- package/dist/MockSdk.d.ts +0 -43
- package/dist/MockSdk.js +0 -70
- package/dist/mock-data/loader.js +0 -41
- package/dist/mock-data/session.json +0 -4305
- package/dist/mock-data/telemetry.json +0 -4986
- package/index.d.ts +0 -87
- package/index.js +0 -36
- package/scripts/generate-var-types.js +0 -71
- /package/dist/{mock-data → types/mock-data}/loader.d.ts +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BroadcastCommand, BroadcastCommandArgs, TelemetryVariable, TelemetryVarList } from '@irsdk-node/types';
|
|
2
|
+
export type TelemetryTypesDict = Record<string, number>;
|
|
3
|
+
/**
|
|
4
|
+
* Interface of the iRacing SDK native module.
|
|
5
|
+
*
|
|
6
|
+
* This should map 1:1 to the API implemented within the C++ addon, and anything
|
|
7
|
+
* added, changed, or removed from the C++ addon API will be documented here.
|
|
8
|
+
*/
|
|
9
|
+
export interface INativeSDK {
|
|
10
|
+
readonly currDataVersion: number;
|
|
11
|
+
readonly isMocked: boolean;
|
|
12
|
+
enableLogging: boolean;
|
|
13
|
+
startSDK(): boolean;
|
|
14
|
+
stopSDK(): void;
|
|
15
|
+
isRunning(): boolean;
|
|
16
|
+
waitForData(timeout?: number): boolean;
|
|
17
|
+
getSessionData(): string;
|
|
18
|
+
getTelemetryData(): TelemetryVarList;
|
|
19
|
+
getTelemetryVariable<T>(index: number): TelemetryVariable<T>;
|
|
20
|
+
getTelemetryVariable<T>(name: string): TelemetryVariable<T>;
|
|
21
|
+
__getTelemetryTypes(): TelemetryTypesDict;
|
|
22
|
+
broadcast<Command extends BroadcastCommand = BroadcastCommand>(message: Command, ...args: BroadcastCommandArgs<Command>): boolean;
|
|
23
|
+
}
|
|
24
|
+
export type NativeSDKImpl = new () => INativeSDK;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BroadcastCommand, BroadcastCommandArgs, TelemetryVariable, TelemetryVarList } from '@irsdk-node/types';
|
|
2
|
+
import type { INativeSDK, TelemetryTypesDict } from './INativeSDK.js';
|
|
3
|
+
type TelemetryVarKey = keyof TelemetryVarList;
|
|
4
|
+
type TelemetryResultTypes = boolean | number | string;
|
|
5
|
+
/**
|
|
6
|
+
* Mock SDK class intended for use on non-win32 platforms for development.
|
|
7
|
+
* Implements the native sdk interface supplemented with mock data suitable for
|
|
8
|
+
* iterating on projects with.
|
|
9
|
+
*
|
|
10
|
+
* @todo - This should really be handled differently, for example via a wrapper
|
|
11
|
+
* class around the native class that gets exposed.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MockSDK implements INativeSDK {
|
|
14
|
+
currDataVersion: number;
|
|
15
|
+
isMocked: boolean;
|
|
16
|
+
enableLogging: boolean;
|
|
17
|
+
private _isRunning;
|
|
18
|
+
constructor();
|
|
19
|
+
private _loadMockData;
|
|
20
|
+
startSDK(): boolean;
|
|
21
|
+
stopSDK(): void;
|
|
22
|
+
isRunning(): boolean;
|
|
23
|
+
waitForData(_timeout?: number): boolean;
|
|
24
|
+
getSessionData(): string;
|
|
25
|
+
getTelemetryData(): TelemetryVarList;
|
|
26
|
+
getTelemetryVariable<T extends TelemetryResultTypes>(index: number): TelemetryVariable<T[]>;
|
|
27
|
+
getTelemetryVariable<T extends TelemetryResultTypes>(name: TelemetryVarKey): TelemetryVariable<T[]>;
|
|
28
|
+
broadcast<Command extends BroadcastCommand = BroadcastCommand>(message: Command, ...args: BroadcastCommandArgs<Command>): boolean;
|
|
29
|
+
__getTelemetryTypes(): TelemetryTypesDict;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/lib/irsdk_client.cpp
CHANGED
|
@@ -4,14 +4,14 @@ All rights reserved.
|
|
|
4
4
|
|
|
5
5
|
Redistribution and use in source and binary forms, with or without
|
|
6
6
|
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
15
|
|
|
16
16
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
17
17
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
@@ -44,13 +44,13 @@ irsdkClient& irsdkClient::instance()
|
|
|
44
44
|
bool irsdkClient::waitForData(int timeoutMS)
|
|
45
45
|
{
|
|
46
46
|
// wait for start of session or new data
|
|
47
|
-
if(irsdk_waitForDataReady(timeoutMS, m_data) && irsdk_getHeader())
|
|
47
|
+
if (irsdk_waitForDataReady(timeoutMS, m_data) && irsdk_getHeader())
|
|
48
48
|
{
|
|
49
49
|
// if new connection, or data changed lenght then init
|
|
50
|
-
if(!m_data || m_nData != irsdk_getHeader()->bufLen)
|
|
50
|
+
if (!m_data || m_nData != irsdk_getHeader()->bufLen)
|
|
51
51
|
{
|
|
52
52
|
// allocate memory to hold incoming data from sim
|
|
53
|
-
if(m_data) delete
|
|
53
|
+
if (m_data) delete[] m_data;
|
|
54
54
|
m_nData = irsdk_getHeader()->bufLen;
|
|
55
55
|
m_data = new char[m_nData];
|
|
56
56
|
|
|
@@ -61,19 +61,19 @@ bool irsdkClient::waitForData(int timeoutMS)
|
|
|
61
61
|
m_lastSessionCt = -1;
|
|
62
62
|
|
|
63
63
|
// and try to fill in the data
|
|
64
|
-
if(irsdk_getNewData(m_data))
|
|
64
|
+
if (irsdk_getNewData(m_data))
|
|
65
65
|
return true;
|
|
66
66
|
}
|
|
67
|
-
else if(m_data)
|
|
67
|
+
else if (m_data)
|
|
68
68
|
{
|
|
69
69
|
// else we are allready initialized, and data is ready for processing
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
else if(!isConnected())
|
|
73
|
+
else if (!isConnected())
|
|
74
74
|
{
|
|
75
75
|
// else session ended
|
|
76
|
-
if(m_data)
|
|
76
|
+
if (m_data)
|
|
77
77
|
delete[] m_data;
|
|
78
78
|
m_data = NULL;
|
|
79
79
|
|
|
@@ -87,7 +87,7 @@ bool irsdkClient::waitForData(int timeoutMS)
|
|
|
87
87
|
void irsdkClient::shutdown()
|
|
88
88
|
{
|
|
89
89
|
irsdk_shutdown();
|
|
90
|
-
if(m_data)
|
|
90
|
+
if (m_data)
|
|
91
91
|
delete[] m_data;
|
|
92
92
|
m_data = NULL;
|
|
93
93
|
|
|
@@ -100,9 +100,9 @@ bool irsdkClient::isConnected()
|
|
|
100
100
|
return m_data != NULL && irsdk_isConnected();
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
int irsdkClient::getVarIdx(const char*name)
|
|
103
|
+
int irsdkClient::getVarIdx(const char* name)
|
|
104
104
|
{
|
|
105
|
-
if(isConnected())
|
|
105
|
+
if (isConnected())
|
|
106
106
|
{
|
|
107
107
|
return irsdk_varNameToIndex(name);
|
|
108
108
|
}
|
|
@@ -112,10 +112,10 @@ int irsdkClient::getVarIdx(const char*name)
|
|
|
112
112
|
|
|
113
113
|
int /*irsdk_VarType*/ irsdkClient::getVarType(int idx)
|
|
114
114
|
{
|
|
115
|
-
if(isConnected())
|
|
115
|
+
if (isConnected())
|
|
116
116
|
{
|
|
117
|
-
const irsdk_varHeader
|
|
118
|
-
if(vh)
|
|
117
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
118
|
+
if (vh)
|
|
119
119
|
{
|
|
120
120
|
return vh->type;
|
|
121
121
|
}
|
|
@@ -131,10 +131,10 @@ int /*irsdk_VarType*/ irsdkClient::getVarType(int idx)
|
|
|
131
131
|
|
|
132
132
|
int irsdkClient::getVarCount(int idx)
|
|
133
133
|
{
|
|
134
|
-
if(isConnected())
|
|
134
|
+
if (isConnected())
|
|
135
135
|
{
|
|
136
|
-
const irsdk_varHeader
|
|
137
|
-
if(vh)
|
|
136
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
137
|
+
if (vh)
|
|
138
138
|
{
|
|
139
139
|
return vh->count;
|
|
140
140
|
}
|
|
@@ -150,36 +150,36 @@ int irsdkClient::getVarCount(int idx)
|
|
|
150
150
|
|
|
151
151
|
bool irsdkClient::getVarBool(int idx, int entry)
|
|
152
152
|
{
|
|
153
|
-
if(isConnected())
|
|
153
|
+
if (isConnected())
|
|
154
154
|
{
|
|
155
|
-
const irsdk_varHeader
|
|
156
|
-
if(vh)
|
|
155
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
156
|
+
if (vh)
|
|
157
157
|
{
|
|
158
|
-
if(entry >= 0 && entry < vh->count)
|
|
158
|
+
if (entry >= 0 && entry < vh->count)
|
|
159
159
|
{
|
|
160
|
-
const char
|
|
161
|
-
switch(vh->type)
|
|
160
|
+
const char* data = m_data + vh->offset;
|
|
161
|
+
switch (vh->type)
|
|
162
162
|
{
|
|
163
|
-
|
|
163
|
+
// 1 byte
|
|
164
164
|
case irsdk_char:
|
|
165
165
|
case irsdk_bool:
|
|
166
166
|
return (((const char*)data)[entry]) != 0;
|
|
167
167
|
break;
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
// 4 bytes
|
|
170
170
|
case irsdk_int:
|
|
171
171
|
case irsdk_bitField:
|
|
172
172
|
return (((const int*)data)[entry]) != 0;
|
|
173
173
|
break;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
178
|
case irsdk_float:
|
|
179
179
|
return (((const float*)data)[entry]) >= 1.0f;
|
|
180
180
|
break;
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
// 8 bytes
|
|
183
183
|
case irsdk_double:
|
|
184
184
|
return (((const double*)data)[entry]) >= 1.0;
|
|
185
185
|
break;
|
|
@@ -203,33 +203,33 @@ bool irsdkClient::getVarBool(int idx, int entry)
|
|
|
203
203
|
|
|
204
204
|
int irsdkClient::getVarInt(int idx, int entry)
|
|
205
205
|
{
|
|
206
|
-
if(isConnected())
|
|
206
|
+
if (isConnected())
|
|
207
207
|
{
|
|
208
|
-
const irsdk_varHeader
|
|
209
|
-
if(vh)
|
|
208
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
209
|
+
if (vh)
|
|
210
210
|
{
|
|
211
|
-
if(entry >= 0 && entry < vh->count)
|
|
211
|
+
if (entry >= 0 && entry < vh->count)
|
|
212
212
|
{
|
|
213
|
-
const char
|
|
214
|
-
switch(vh->type)
|
|
213
|
+
const char* data = m_data + vh->offset;
|
|
214
|
+
switch (vh->type)
|
|
215
215
|
{
|
|
216
|
-
|
|
216
|
+
// 1 byte
|
|
217
217
|
case irsdk_char:
|
|
218
218
|
case irsdk_bool:
|
|
219
219
|
return (int)(((const char*)data)[entry]);
|
|
220
220
|
break;
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
// 4 bytes
|
|
223
223
|
case irsdk_int:
|
|
224
224
|
case irsdk_bitField:
|
|
225
225
|
return (int)(((const int*)data)[entry]);
|
|
226
226
|
break;
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
case irsdk_float:
|
|
229
229
|
return (int)(((const float*)data)[entry]);
|
|
230
230
|
break;
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
// 8 bytes
|
|
233
233
|
case irsdk_double:
|
|
234
234
|
return (int)(((const double*)data)[entry]);
|
|
235
235
|
break;
|
|
@@ -253,33 +253,33 @@ int irsdkClient::getVarInt(int idx, int entry)
|
|
|
253
253
|
|
|
254
254
|
float irsdkClient::getVarFloat(int idx, int entry)
|
|
255
255
|
{
|
|
256
|
-
if(isConnected())
|
|
256
|
+
if (isConnected())
|
|
257
257
|
{
|
|
258
|
-
const irsdk_varHeader
|
|
259
|
-
if(vh)
|
|
258
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
259
|
+
if (vh)
|
|
260
260
|
{
|
|
261
|
-
if(entry >= 0 && entry < vh->count)
|
|
261
|
+
if (entry >= 0 && entry < vh->count)
|
|
262
262
|
{
|
|
263
|
-
const char
|
|
264
|
-
switch(vh->type)
|
|
263
|
+
const char* data = m_data + vh->offset;
|
|
264
|
+
switch (vh->type)
|
|
265
265
|
{
|
|
266
|
-
|
|
266
|
+
// 1 byte
|
|
267
267
|
case irsdk_char:
|
|
268
268
|
case irsdk_bool:
|
|
269
269
|
return (float)(((const char*)data)[entry]);
|
|
270
270
|
break;
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
// 4 bytes
|
|
273
273
|
case irsdk_int:
|
|
274
274
|
case irsdk_bitField:
|
|
275
275
|
return (float)(((const int*)data)[entry]);
|
|
276
276
|
break;
|
|
277
|
-
|
|
277
|
+
|
|
278
278
|
case irsdk_float:
|
|
279
279
|
return (float)(((const float*)data)[entry]);
|
|
280
280
|
break;
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
// 8 bytes
|
|
283
283
|
case irsdk_double:
|
|
284
284
|
return (float)(((const double*)data)[entry]);
|
|
285
285
|
break;
|
|
@@ -303,33 +303,33 @@ float irsdkClient::getVarFloat(int idx, int entry)
|
|
|
303
303
|
|
|
304
304
|
double irsdkClient::getVarDouble(int idx, int entry)
|
|
305
305
|
{
|
|
306
|
-
if(isConnected())
|
|
306
|
+
if (isConnected())
|
|
307
307
|
{
|
|
308
|
-
const irsdk_varHeader
|
|
309
|
-
if(vh)
|
|
308
|
+
const irsdk_varHeader* vh = irsdk_getVarHeaderEntry(idx);
|
|
309
|
+
if (vh)
|
|
310
310
|
{
|
|
311
|
-
if(entry >= 0 && entry < vh->count)
|
|
311
|
+
if (entry >= 0 && entry < vh->count)
|
|
312
312
|
{
|
|
313
|
-
const char
|
|
314
|
-
switch(vh->type)
|
|
313
|
+
const char* data = m_data + vh->offset;
|
|
314
|
+
switch (vh->type)
|
|
315
315
|
{
|
|
316
|
-
|
|
316
|
+
// 1 byte
|
|
317
317
|
case irsdk_char:
|
|
318
318
|
case irsdk_bool:
|
|
319
319
|
return (double)(((const char*)data)[entry]);
|
|
320
320
|
break;
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
// 4 bytes
|
|
323
323
|
case irsdk_int:
|
|
324
324
|
case irsdk_bitField:
|
|
325
325
|
return (double)(((const int*)data)[entry]);
|
|
326
326
|
break;
|
|
327
|
-
|
|
327
|
+
|
|
328
328
|
case irsdk_float:
|
|
329
329
|
return (double)(((const float*)data)[entry]);
|
|
330
330
|
break;
|
|
331
331
|
|
|
332
|
-
|
|
332
|
+
// 8 bytes
|
|
333
333
|
case irsdk_double:
|
|
334
334
|
return (double)(((const double*)data)[entry]);
|
|
335
335
|
break;
|
|
@@ -352,31 +352,31 @@ double irsdkClient::getVarDouble(int idx, int entry)
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
//path is in the form of "DriverInfo:Drivers:CarIdx:{%d}UserName:"
|
|
355
|
-
int irsdkClient::getSessionStrVal(const char
|
|
355
|
+
int irsdkClient::getSessionStrVal(const char* path, char* val, int valLen)
|
|
356
356
|
{
|
|
357
|
-
if(isConnected() && path && val && valLen > 0)
|
|
357
|
+
if (isConnected() && path && val && valLen > 0)
|
|
358
358
|
{
|
|
359
359
|
// track changes in string
|
|
360
|
-
m_lastSessionCt = getSessionCt();
|
|
360
|
+
m_lastSessionCt = getSessionCt();
|
|
361
361
|
|
|
362
|
-
const char
|
|
362
|
+
const char* tVal = NULL;
|
|
363
363
|
int tValLen = 0;
|
|
364
|
-
if(parseYaml(irsdk_getSessionInfoStr(), path, &tVal, &tValLen))
|
|
364
|
+
if (parseYaml(irsdk_getSessionInfoStr(), path, &tVal, &tValLen))
|
|
365
365
|
{
|
|
366
366
|
// dont overflow out buffer
|
|
367
367
|
int len = tValLen;
|
|
368
|
-
if(len > valLen)
|
|
369
|
-
len = valLen;
|
|
368
|
+
if (len > (valLen - 1)) // reserve space for null termination
|
|
369
|
+
len = (valLen - 1);
|
|
370
370
|
|
|
371
371
|
// copy what we can, even if buffer too small
|
|
372
372
|
memcpy(val, tVal, len);
|
|
373
373
|
val[len] = '\0'; // origional string has no null termination...
|
|
374
374
|
|
|
375
375
|
// if buffer was big enough, return success
|
|
376
|
-
if(valLen >= tValLen)
|
|
376
|
+
if ((valLen - 1) >= tValLen)
|
|
377
377
|
return 1;
|
|
378
378
|
else // return size of buffer needed
|
|
379
|
-
return -tValLen;
|
|
379
|
+
return -(tValLen + 1);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
|
|
@@ -384,12 +384,12 @@ int irsdkClient::getSessionStrVal(const char *path, char *val, int valLen)
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
// get the whole string
|
|
387
|
-
const char* irsdkClient::getSessionStr()
|
|
388
|
-
{
|
|
389
|
-
if(isConnected())
|
|
387
|
+
const char* irsdkClient::getSessionStr()
|
|
388
|
+
{
|
|
389
|
+
if (isConnected())
|
|
390
390
|
{
|
|
391
|
-
m_lastSessionCt = getSessionCt();
|
|
392
|
-
return irsdk_getSessionInfoStr();
|
|
391
|
+
m_lastSessionCt = getSessionCt();
|
|
392
|
+
return irsdk_getSessionInfoStr();
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
return NULL;
|
|
@@ -405,23 +405,23 @@ irsdkCVar::irsdkCVar()
|
|
|
405
405
|
m_name[0] = '\0';
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
irsdkCVar::irsdkCVar(const char
|
|
408
|
+
irsdkCVar::irsdkCVar(const char* name)
|
|
409
409
|
{
|
|
410
410
|
m_name[0] = '\0';
|
|
411
411
|
setVarName(name);
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
-
void irsdkCVar::setVarName(const char
|
|
414
|
+
void irsdkCVar::setVarName(const char* name)
|
|
415
415
|
{
|
|
416
|
-
if(!name || 0 != strncmp(name, m_name, sizeof(m_name)))
|
|
416
|
+
if (!name || 0 != strncmp(name, m_name, sizeof(m_name)))
|
|
417
417
|
{
|
|
418
418
|
m_idx = -1;
|
|
419
419
|
m_statusID = -1;
|
|
420
420
|
|
|
421
|
-
if(name)
|
|
421
|
+
if (name)
|
|
422
422
|
{
|
|
423
423
|
strncpy(m_name, name, max_string);
|
|
424
|
-
m_name[max_string-1] = '\0';
|
|
424
|
+
m_name[max_string - 1] = '\0';
|
|
425
425
|
}
|
|
426
426
|
else
|
|
427
427
|
m_name[0] = '\0';
|
|
@@ -430,9 +430,9 @@ void irsdkCVar::setVarName(const char *name)
|
|
|
430
430
|
|
|
431
431
|
bool irsdkCVar::checkIdx()
|
|
432
432
|
{
|
|
433
|
-
if(irsdkClient::instance().isConnected())
|
|
433
|
+
if (irsdkClient::instance().isConnected())
|
|
434
434
|
{
|
|
435
|
-
if(m_statusID != irsdkClient::instance().getStatusID())
|
|
435
|
+
if (m_statusID != irsdkClient::instance().getStatusID())
|
|
436
436
|
{
|
|
437
437
|
m_statusID = irsdkClient::instance().getStatusID();
|
|
438
438
|
m_idx = irsdkClient::instance().getVarIdx(m_name);
|
|
@@ -446,14 +446,14 @@ bool irsdkCVar::checkIdx()
|
|
|
446
446
|
|
|
447
447
|
int /*irsdk_VarType*/ irsdkCVar::getType()
|
|
448
448
|
{
|
|
449
|
-
if(checkIdx())
|
|
449
|
+
if (checkIdx())
|
|
450
450
|
return irsdkClient::instance().getVarType(m_idx);
|
|
451
451
|
return 0;
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
int irsdkCVar::getCount()
|
|
455
455
|
{
|
|
456
|
-
if(checkIdx())
|
|
456
|
+
if (checkIdx())
|
|
457
457
|
return irsdkClient::instance().getVarCount(m_idx);
|
|
458
458
|
return 0;
|
|
459
459
|
}
|
|
@@ -467,28 +467,28 @@ bool irsdkCVar::isValid()
|
|
|
467
467
|
|
|
468
468
|
bool irsdkCVar::getBool(int entry)
|
|
469
469
|
{
|
|
470
|
-
if(checkIdx())
|
|
470
|
+
if (checkIdx())
|
|
471
471
|
return irsdkClient::instance().getVarBool(m_idx, entry);
|
|
472
472
|
return false;
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
int irsdkCVar::getInt(int entry)
|
|
476
476
|
{
|
|
477
|
-
if(checkIdx())
|
|
477
|
+
if (checkIdx())
|
|
478
478
|
return irsdkClient::instance().getVarInt(m_idx, entry);
|
|
479
479
|
return 0;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
float irsdkCVar::getFloat(int entry)
|
|
483
483
|
{
|
|
484
|
-
if(checkIdx())
|
|
484
|
+
if (checkIdx())
|
|
485
485
|
return irsdkClient::instance().getVarFloat(m_idx, entry);
|
|
486
486
|
return 0.0f;
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
double irsdkCVar::getDouble(int entry)
|
|
490
490
|
{
|
|
491
|
-
if(checkIdx())
|
|
491
|
+
if (checkIdx())
|
|
492
492
|
return irsdkClient::instance().getVarDouble(m_idx, entry);
|
|
493
493
|
return 0.0;
|
|
494
494
|
}
|
package/lib/irsdk_client.h
CHANGED
|
@@ -4,14 +4,14 @@ All rights reserved.
|
|
|
4
4
|
|
|
5
5
|
Redistribution and use in source and binary forms, with or without
|
|
6
6
|
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
15
|
|
|
16
16
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
17
17
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
@@ -43,30 +43,30 @@ public:
|
|
|
43
43
|
bool isConnected();
|
|
44
44
|
int getStatusID() { return m_statusID; }
|
|
45
45
|
|
|
46
|
-
int getVarIdx(const char*name);
|
|
46
|
+
int getVarIdx(const char* name);
|
|
47
47
|
|
|
48
48
|
// what is the base type of the data
|
|
49
49
|
// returns irsdk_VarType as int so we don't depend on irsdk_defines.h
|
|
50
50
|
int getVarType(int idx);
|
|
51
|
-
int getVarType(const char
|
|
51
|
+
int getVarType(const char* name) { return getVarType(getVarIdx(name)); }
|
|
52
52
|
|
|
53
53
|
// how many elements in array, or 1 if not an array
|
|
54
54
|
int getVarCount(int idx);
|
|
55
|
-
int getVarCount(const char
|
|
55
|
+
int getVarCount(const char* name) { return getVarCount(getVarIdx(name)); }
|
|
56
56
|
|
|
57
57
|
// idx is the variables index, entry is the array offset, or 0 if not an array element
|
|
58
58
|
// will convert data to requested type
|
|
59
59
|
bool getVarBool(int idx, int entry = 0);
|
|
60
|
-
bool getVarBool(const char
|
|
60
|
+
bool getVarBool(const char* name, int entry = 0) { return getVarBool(getVarIdx(name), entry); }
|
|
61
61
|
|
|
62
62
|
int getVarInt(int idx, int entry = 0);
|
|
63
|
-
int getVarInt(const char
|
|
64
|
-
|
|
63
|
+
int getVarInt(const char* name, int entry = 0) { return getVarInt(getVarIdx(name), entry); }
|
|
64
|
+
|
|
65
65
|
float getVarFloat(int idx, int entry = 0);
|
|
66
|
-
float getVarFloat(const char
|
|
66
|
+
float getVarFloat(const char* name, int entry = 0) { return getVarFloat(getVarIdx(name), entry); }
|
|
67
67
|
|
|
68
68
|
double getVarDouble(int idx, int entry = 0);
|
|
69
|
-
double getVarDouble(const char
|
|
69
|
+
double getVarDouble(const char* name, int entry = 0) { return getVarDouble(getVarIdx(name), entry); }
|
|
70
70
|
|
|
71
71
|
//---
|
|
72
72
|
|
|
@@ -74,14 +74,14 @@ public:
|
|
|
74
74
|
int getSessionCt() { return irsdk_getSessionInfoStrUpdate(); }
|
|
75
75
|
|
|
76
76
|
// has string changed since we last read any values from it
|
|
77
|
-
bool wasSessionStrUpdated() { return m_lastSessionCt != getSessionCt(); }
|
|
77
|
+
bool wasSessionStrUpdated() { return m_lastSessionCt != getSessionCt(); }
|
|
78
78
|
|
|
79
79
|
// pars string for individual value, 1 success, 0 failure, -n minimum buffer size
|
|
80
80
|
//****Note, this is a linear parser, so it is slow!
|
|
81
|
-
int getSessionStrVal(const char
|
|
81
|
+
int getSessionStrVal(const char* path, char* val, int valLen);
|
|
82
82
|
|
|
83
83
|
// get the whole string
|
|
84
|
-
const char
|
|
84
|
+
const char* getSessionStr();
|
|
85
85
|
|
|
86
86
|
protected:
|
|
87
87
|
|
|
@@ -96,13 +96,13 @@ protected:
|
|
|
96
96
|
|
|
97
97
|
void shutdown();
|
|
98
98
|
|
|
99
|
-
char
|
|
99
|
+
char* m_data;
|
|
100
100
|
int m_nData;
|
|
101
101
|
int m_statusID;
|
|
102
102
|
|
|
103
103
|
int m_lastSessionCt;
|
|
104
104
|
|
|
105
|
-
static irsdkClient
|
|
105
|
+
static irsdkClient* m_instance;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
|
|
@@ -112,9 +112,9 @@ class irsdkCVar
|
|
|
112
112
|
{
|
|
113
113
|
public:
|
|
114
114
|
irsdkCVar();
|
|
115
|
-
irsdkCVar(const char
|
|
115
|
+
irsdkCVar(const char* name);
|
|
116
116
|
|
|
117
|
-
void setVarName(const char
|
|
117
|
+
void setVarName(const char* name);
|
|
118
118
|
|
|
119
119
|
// returns irsdk_VarType as int so we don't depend on irsdk_defines.h
|
|
120
120
|
int getType();
|