@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
package/lib/irsdk_node.cc
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
#include "./irsdk_node.h"
|
|
2
|
-
#include "./yaml_parser.h"
|
|
3
1
|
#include "./irsdk_defines.h"
|
|
4
|
-
#include "./
|
|
2
|
+
#include "./irsdk_node.h"
|
|
5
3
|
|
|
6
4
|
// ---------------------------
|
|
7
5
|
// Constructors
|
|
8
6
|
// ---------------------------
|
|
9
7
|
Napi::Object iRacingSdkNode::Init(Napi::Env env, Napi::Object exports)
|
|
10
8
|
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
Napi::Function func = DefineClass(env, "iRacingSdkNode", {
|
|
10
|
+
// Properties
|
|
11
|
+
InstanceAccessor<&iRacingSdkNode::GetCurrSessionDataVersion>("currDataVersion"),
|
|
12
|
+
InstanceAccessor<&iRacingSdkNode::GetEnableLogging, &iRacingSdkNode::SetEnableLogging>("enableLogging"),
|
|
13
|
+
InstanceAccessor<&iRacingSdkNode::GetIsMocked>("isMocked"),
|
|
14
|
+
|
|
15
|
+
// Methods
|
|
16
|
+
// Control
|
|
17
|
+
InstanceMethod<&iRacingSdkNode::StartSdk>("startSDK"),
|
|
18
|
+
InstanceMethod("stopSDK", &iRacingSdkNode::StopSdk),
|
|
19
|
+
InstanceMethod("waitForData", &iRacingSdkNode::WaitForData),
|
|
20
|
+
InstanceMethod("broadcast", &iRacingSdkNode::BroadcastMessage),
|
|
21
|
+
// Getters
|
|
22
|
+
InstanceMethod("isRunning", &iRacingSdkNode::IsRunning),
|
|
23
|
+
InstanceMethod("getSessionVersionNum", &iRacingSdkNode::GetSessionVersionNum),
|
|
24
|
+
InstanceMethod("getSessionData", &iRacingSdkNode::GetSessionData),
|
|
25
|
+
InstanceMethod("getTelemetryData", &iRacingSdkNode::GetTelemetryData),
|
|
26
|
+
InstanceMethod("getTelemetryVariable", &iRacingSdkNode::GetTelemetryVar),
|
|
27
|
+
// Helpers
|
|
28
|
+
InstanceMethod("__getTelemetryTypes", &iRacingSdkNode::__GetTelemetryTypes)});
|
|
29
|
+
|
|
30
|
+
Napi::FunctionReference *constructor = new Napi::FunctionReference();
|
|
31
|
+
*constructor = Napi::Persistent(func);
|
|
32
|
+
env.SetInstanceData(constructor);
|
|
33
|
+
|
|
34
|
+
exports.Set("iRacingSdkNode", func);
|
|
35
|
+
return exports;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
31
|
-
|
|
39
|
+
: Napi::ObjectWrap<iRacingSdkNode>(info), _data(NULL), _bufLineLen(0), _sessionStatusID(0), _lastSessionCt(-1), _sessionData(NULL), _loggingEnabled(false)
|
|
32
40
|
{
|
|
33
|
-
|
|
41
|
+
printf("Initializing iRacingSdkNode\n");
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
// ---------------------------
|
|
@@ -38,35 +46,34 @@ iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
|
38
46
|
// ---------------------------
|
|
39
47
|
Napi::Value iRacingSdkNode::GetCurrSessionDataVersion(const Napi::CallbackInfo &info)
|
|
40
48
|
{
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
int ver = this->_lastSessionCt;
|
|
50
|
+
return Napi::Number::New(info.Env(), ver);
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
Napi::Value iRacingSdkNode::GetEnableLogging(const Napi::CallbackInfo &info)
|
|
46
54
|
{
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
bool enabled = this->_loggingEnabled;
|
|
56
|
+
return Napi::Boolean::New(info.Env(), enabled);
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
void iRacingSdkNode::SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value)
|
|
52
60
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
printf("iRacingSDK Logging enabled\n");
|
|
61
|
+
Napi::Boolean enable;
|
|
62
|
+
if (info.Length() <= 0 || !info[0].IsBoolean())
|
|
63
|
+
{
|
|
64
|
+
enable = Napi::Boolean::New(info.Env(), false);
|
|
65
|
+
} else
|
|
66
|
+
{
|
|
67
|
+
enable = info[0].As<Napi::Boolean>();
|
|
68
|
+
}
|
|
69
|
+
this->_loggingEnabled = enable;
|
|
70
|
+
if (this->_loggingEnabled)
|
|
71
|
+
printf("iRacingSDK Logging enabled\n");
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
Napi::Value iRacingSdkNode::GetIsMocked(const Napi::CallbackInfo &info)
|
|
68
75
|
{
|
|
69
|
-
|
|
76
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
// ---------------------------
|
|
@@ -75,260 +82,306 @@ Napi::Value iRacingSdkNode::GetIsMocked(const Napi::CallbackInfo &info)
|
|
|
75
82
|
// SDK Control
|
|
76
83
|
Napi::Value iRacingSdkNode::StartSdk(const Napi::CallbackInfo &info)
|
|
77
84
|
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (this->_loggingEnabled)
|
|
86
|
+
printf("Starting SDK...\n");
|
|
87
|
+
|
|
88
|
+
if (!irsdk_isConnected())
|
|
89
|
+
{
|
|
90
|
+
bool result = irsdk_startup();
|
|
91
|
+
if (this->_loggingEnabled)
|
|
92
|
+
printf("Connected to iRacing SDK (%i)\n", result);
|
|
93
|
+
return Napi::Boolean::New(info.Env(), result);
|
|
94
|
+
}
|
|
95
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
Napi::Value iRacingSdkNode::StopSdk(const Napi::CallbackInfo &info)
|
|
92
99
|
{
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
irsdk_shutdown();
|
|
101
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
Napi::Value iRacingSdkNode::WaitForData(const Napi::CallbackInfo &info)
|
|
98
105
|
{
|
|
99
106
|
// Figure out the time to wait
|
|
100
107
|
// This will default to the timeout set on the class
|
|
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
|
-
if (this->_loggingEnabled)
|
|
168
|
-
printf("Session ended or something went wrong. Not successful.\n");
|
|
169
|
-
return Napi::Boolean::New(info.Env(), false);
|
|
108
|
+
Napi::Number timeout;
|
|
109
|
+
if (info.Length() <= 0 || !info[0].IsNumber())
|
|
110
|
+
{
|
|
111
|
+
timeout = Napi::Number::New(info.Env(), 16);
|
|
112
|
+
} else
|
|
113
|
+
{
|
|
114
|
+
timeout = info[0].As<Napi::Number>();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!irsdk_isConnected() && !irsdk_startup())
|
|
118
|
+
{
|
|
119
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// @todo: try to do this async instead
|
|
123
|
+
const irsdk_header *header = irsdk_getHeader();
|
|
124
|
+
|
|
125
|
+
// @todo: This isn't the best way of doing this. Need to improve, but this works for now
|
|
126
|
+
if (!this->_data)
|
|
127
|
+
{
|
|
128
|
+
this->_data = new char[header->bufLen];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// wait for start of sesh or new data
|
|
132
|
+
bool dataReady = irsdk_waitForDataReady(timeout, this->_data);
|
|
133
|
+
if (dataReady && header)
|
|
134
|
+
{
|
|
135
|
+
if (this->_loggingEnabled)
|
|
136
|
+
("Session started or we have new data.\n");
|
|
137
|
+
|
|
138
|
+
// New connection or data changed length
|
|
139
|
+
if (this->_bufLineLen != header->bufLen)
|
|
140
|
+
{
|
|
141
|
+
if (this->_loggingEnabled)
|
|
142
|
+
printf("Connection started / data changed length.\n");
|
|
143
|
+
|
|
144
|
+
this->_bufLineLen = header->bufLen;
|
|
145
|
+
|
|
146
|
+
// Increment connection
|
|
147
|
+
this->_sessionStatusID++;
|
|
148
|
+
|
|
149
|
+
// Reset info str status
|
|
150
|
+
this->_lastSessionCt = -1;
|
|
151
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
152
|
+
} else if (this->_data)
|
|
153
|
+
{
|
|
154
|
+
if (this->_loggingEnabled)
|
|
155
|
+
printf("Data initialized and ready to process.\n");
|
|
156
|
+
// already initialized and ready to process
|
|
157
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
158
|
+
}
|
|
159
|
+
} else if (!(this->_data != NULL && irsdk_isConnected()))
|
|
160
|
+
{
|
|
161
|
+
if (this->_loggingEnabled)
|
|
162
|
+
printf("Session ended. Cleaning up.\n");
|
|
163
|
+
// Session ended
|
|
164
|
+
if (this->_data)
|
|
165
|
+
delete[] this->_data;
|
|
166
|
+
this->_data = NULL;
|
|
167
|
+
|
|
168
|
+
// Reset Info str
|
|
169
|
+
this->_lastSessionCt = -1;
|
|
170
|
+
}
|
|
171
|
+
if (this->_loggingEnabled)
|
|
172
|
+
printf("Session ended or something went wrong. Not successful.\n");
|
|
173
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
173
177
|
{
|
|
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
|
-
|
|
178
|
+
auto env = info.Env();
|
|
179
|
+
|
|
180
|
+
// Determine message type
|
|
181
|
+
if (info.Length() <= 2 || !info[0].IsNumber())
|
|
182
|
+
{
|
|
183
|
+
return Napi::Boolean::New(env, false);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (info.Length() == 4 && !info[2].IsNumber())
|
|
187
|
+
{
|
|
188
|
+
return Napi::Boolean::New(env, false);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Napi::Number msgEnumIndex = info[0].As<Napi::Number>();
|
|
192
|
+
irsdk_BroadcastMsg msgType = static_cast<irsdk_BroadcastMsg>(msgEnumIndex.Int32Value());
|
|
193
|
+
|
|
194
|
+
// Args
|
|
195
|
+
Napi::Number arg1 = info[1].As<Napi::Number>();
|
|
196
|
+
Napi::Number arg2 = info[2].As<Napi::Number>();
|
|
197
|
+
Napi::Number arg3 = info[3].As<Napi::Number>();
|
|
198
|
+
|
|
199
|
+
irsdk_ChatCommandMode chatCommand = irsdk_ChatCommand_Cancel;
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
// Handle each message independently.
|
|
203
|
+
//
|
|
204
|
+
// This could be consolidated, but then it becomes way too difficult to easily
|
|
205
|
+
// grep what each messages expected API is, as some are not necessarily what
|
|
206
|
+
switch (msgType)
|
|
207
|
+
{
|
|
208
|
+
// BroadcastCamSwitchPos: car position, group, camera
|
|
209
|
+
// BroadcastCamSwitchNum: driver #, group, camera
|
|
210
|
+
case irsdk_BroadcastCamSwitchPos:
|
|
211
|
+
case irsdk_BroadcastCamSwitchNum:
|
|
212
|
+
// First arg can be irsdk_csMode enum.
|
|
213
|
+
// Any value above -1 equates to focusing on a specific driver.
|
|
214
|
+
irsdk_broadcastMsg(msgType, arg1.Int32Value(), arg2.Int32Value(), arg3.Int32Value());
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
// irsdk_CameraState, unused, unused
|
|
218
|
+
case irsdk_BroadcastCamSetState:
|
|
219
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_CameraState>(arg1.Int32Value()), 0);
|
|
220
|
+
break;
|
|
221
|
+
|
|
222
|
+
// speed, slowMotion, unused
|
|
223
|
+
case irsdk_BroadcastReplaySetPlaySpeed:
|
|
224
|
+
// Speed (arg1) should be multiples of 2 (0, 1, 2, 4, 8, 16), can be negative
|
|
225
|
+
// Slow mo (arg2) should be 1 | 0
|
|
226
|
+
irsdk_broadcastMsg(msgType, arg1.Int32Value(), arg2.ToBoolean().Value());
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
// irsdk_RpyPosMode, Frame Number (high, low)
|
|
230
|
+
case irsdk_BroadcastReplaySetPlayPosition:
|
|
231
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_RpyPosMode>(arg1.Int32Value()), arg2.Int32Value());
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
// irsdk_RpySrchMode, unused, unused
|
|
235
|
+
case irsdk_BroadcastReplaySearch:
|
|
236
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_RpySrchMode>(arg1.Int32Value()), 0, 0);
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
// irsdk_RpyStateMode, unused, unused
|
|
240
|
+
case irsdk_BroadcastReplaySetState:
|
|
241
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_RpyStateMode>(arg1.Int32Value()), 0);
|
|
242
|
+
break;
|
|
243
|
+
|
|
244
|
+
// irsdk_ReloadTexturesMode, carIdx, unused
|
|
245
|
+
case irsdk_BroadcastReloadTextures:
|
|
246
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_ReloadTexturesMode>(arg1.Int32Value()), arg2.Int32Value(), 0);
|
|
247
|
+
break;
|
|
248
|
+
|
|
249
|
+
// irsdk_ChatCommandMode, subCommand, unused
|
|
250
|
+
case irsdk_BroadcastChatComand:
|
|
251
|
+
chatCommand = static_cast<irsdk_ChatCommandMode>(arg1.Int32Value());
|
|
252
|
+
if (chatCommand != irsdk_ChatCommand_Macro)
|
|
253
|
+
{
|
|
254
|
+
irsdk_broadcastMsg(msgType, chatCommand, 0);
|
|
255
|
+
break;
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// If the chat command is to use a macro, parse the macro id (1 - 15) (2nd arg)
|
|
260
|
+
irsdk_broadcastMsg(msgType, chatCommand, arg2.Int32Value(), 0);
|
|
261
|
+
break;
|
|
262
|
+
|
|
263
|
+
// irsdk_PitCommandMode, parameter
|
|
264
|
+
case irsdk_BroadcastPitCommand:
|
|
265
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_PitCommandMode>(arg1.Int32Value()), arg2.Int32Value());
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
// irsdk_TelemCommandMode, unused, unused
|
|
269
|
+
case irsdk_BroadcastTelemCommand:
|
|
270
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_TelemCommandMode>(arg1.Int32Value()), 0, 0);
|
|
271
|
+
break;
|
|
272
|
+
|
|
273
|
+
// irsdk_FFBCommandMode, value (float, high, low)
|
|
274
|
+
case irsdk_BroadcastFFBCommand:
|
|
275
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_FFBCommandMode>(arg1.Int32Value()), arg2.FloatValue());
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
// This does a search and not a direct jump, so it may take a while
|
|
279
|
+
// sessionNum, sessionTimeMS (high, low)
|
|
280
|
+
case irsdk_BroadcastReplaySearchSessionTime:
|
|
281
|
+
irsdk_broadcastMsg(msgType, arg1.Int32Value(), arg2.Int32Value());
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
// irsdk_VideoCaptureMode, unused, unused
|
|
285
|
+
case irsdk_BroadcastVideoCapture:
|
|
286
|
+
irsdk_broadcastMsg(msgType, static_cast<irsdk_VideoCaptureMode>(arg1.Int32Value()), 0);
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
// Unused + out-of-bounds
|
|
290
|
+
default:
|
|
291
|
+
if (this->_loggingEnabled)
|
|
292
|
+
printf("Attempted to broadcast an unsupported message.\n");
|
|
293
|
+
return Napi::Boolean::New(env, false);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return Napi::Boolean::New(env, true);
|
|
243
297
|
}
|
|
244
298
|
|
|
245
299
|
// SDK State Getters
|
|
246
300
|
Napi::Value iRacingSdkNode::IsRunning(const Napi::CallbackInfo &info)
|
|
247
301
|
{
|
|
248
|
-
|
|
249
|
-
|
|
302
|
+
bool result = irsdk_isConnected();
|
|
303
|
+
return Napi::Boolean::New(info.Env(), result);
|
|
250
304
|
}
|
|
251
305
|
|
|
252
306
|
Napi::Value iRacingSdkNode::GetSessionVersionNum(const Napi::CallbackInfo &info)
|
|
253
307
|
{
|
|
254
|
-
|
|
255
|
-
|
|
308
|
+
int sessVer = irsdk_getSessionInfoStrUpdate();
|
|
309
|
+
return Napi::Number::New(info.Env(), sessVer);
|
|
256
310
|
}
|
|
257
311
|
|
|
258
312
|
Napi::Value iRacingSdkNode::GetSessionData(const Napi::CallbackInfo &info)
|
|
259
313
|
{
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
314
|
+
int latestUpdate = irsdk_getSessionInfoStrUpdate();
|
|
315
|
+
if (this->_lastSessionCt != latestUpdate)
|
|
316
|
+
{
|
|
317
|
+
if (this->_loggingEnabled)
|
|
318
|
+
printf("Session data has been updated (prev: %d, new: %d)\n", this->_lastSessionCt, latestUpdate);
|
|
319
|
+
this->_lastSessionCt = latestUpdate;
|
|
320
|
+
this->_sessionData = irsdk_getSessionInfoStr();
|
|
321
|
+
}
|
|
322
|
+
const char *session = this->_sessionData;
|
|
323
|
+
if (session == NULL)
|
|
324
|
+
{
|
|
325
|
+
return Napi::String::New(info.Env(), "");
|
|
326
|
+
}
|
|
327
|
+
return Napi::String::New(info.Env(), session);
|
|
274
328
|
}
|
|
275
329
|
|
|
276
330
|
Napi::Value iRacingSdkNode::GetTelemetryVar(const Napi::CallbackInfo &info)
|
|
277
331
|
{
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
332
|
+
Napi::Env env = info.Env();
|
|
333
|
+
|
|
334
|
+
int varIndex;
|
|
335
|
+
if (info.Length() <= 0)
|
|
336
|
+
{
|
|
337
|
+
varIndex = 0;
|
|
338
|
+
} else if (!info[0].IsNumber())
|
|
339
|
+
{
|
|
340
|
+
if (info[0].IsString())
|
|
341
|
+
{
|
|
342
|
+
const char *name = info[0].As<Napi::String>().Utf8Value().c_str();
|
|
343
|
+
return this->GetTelemetryVar(env, name);
|
|
344
|
+
}
|
|
345
|
+
varIndex = 0;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
296
349
|
}
|
|
297
350
|
|
|
298
351
|
Napi::Value iRacingSdkNode::GetTelemetryData(const Napi::CallbackInfo &info)
|
|
299
352
|
{
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
353
|
+
const irsdk_header *header = irsdk_getHeader();
|
|
354
|
+
auto env = info.Env();
|
|
355
|
+
auto telemVars = Napi::Object::New(env);
|
|
356
|
+
|
|
357
|
+
int count = header->numVars;
|
|
358
|
+
for (int i = 0; i < count; i++)
|
|
359
|
+
{
|
|
360
|
+
auto telemVariable = this->GetTelemetryVarByIndex(env, i);
|
|
361
|
+
if (telemVariable.IsObject() && telemVariable.Has("name"))
|
|
362
|
+
{
|
|
363
|
+
telemVars.Set(telemVariable.Get("name"), telemVariable);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return telemVars;
|
|
315
368
|
}
|
|
316
369
|
|
|
317
370
|
// Helpers
|
|
318
371
|
Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
319
372
|
{
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
373
|
+
auto env = info.Env();
|
|
374
|
+
auto result = Napi::Object::New(env);
|
|
375
|
+
|
|
376
|
+
const int count = irsdk_getHeader()->numVars;
|
|
377
|
+
const irsdk_varHeader *varHeader;
|
|
378
|
+
for (int i = 0; i < count; i++)
|
|
379
|
+
{
|
|
380
|
+
varHeader = irsdk_getVarHeaderEntry(i);
|
|
381
|
+
result.Set(varHeader->name, Napi::Number::New(env, varHeader->type));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return result;
|
|
332
385
|
}
|
|
333
386
|
|
|
334
387
|
// ---------------------------
|
|
@@ -336,56 +389,56 @@ Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
|
336
389
|
// ---------------------------
|
|
337
390
|
bool iRacingSdkNode::GetTelemetryBool(int entry, int index)
|
|
338
391
|
{
|
|
339
|
-
|
|
340
|
-
|
|
392
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
393
|
+
return *(reinterpret_cast<bool const *>(_data + headerVar->offset) + index);
|
|
341
394
|
}
|
|
342
395
|
|
|
343
396
|
int iRacingSdkNode::GetTelemetryInt(int entry, int index)
|
|
344
397
|
{
|
|
345
398
|
// Each int is 4 bytes
|
|
346
|
-
|
|
347
|
-
|
|
399
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
400
|
+
return *(reinterpret_cast<int const *>(_data + headerVar->offset) + index * 4);
|
|
348
401
|
}
|
|
349
402
|
|
|
350
403
|
float iRacingSdkNode::GetTelemetryFloat(int entry, int index)
|
|
351
404
|
{
|
|
352
405
|
// Each float is 4 bytes
|
|
353
|
-
|
|
354
|
-
|
|
406
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
407
|
+
return *(reinterpret_cast<float const *>(_data + headerVar->offset) + index * 4);
|
|
355
408
|
}
|
|
356
409
|
|
|
357
410
|
double iRacingSdkNode::GetTelemetryDouble(int entry, int index)
|
|
358
411
|
{
|
|
359
412
|
// Each double is 8 bytes
|
|
360
|
-
|
|
361
|
-
|
|
413
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
414
|
+
return *(reinterpret_cast<double const *>(_data + headerVar->offset) + index * 8);
|
|
362
415
|
}
|
|
363
416
|
|
|
364
417
|
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index)
|
|
365
418
|
{
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
419
|
+
auto headerVar = irsdk_getVarHeaderEntry(index);
|
|
420
|
+
auto telemVar = Napi::Object::New(env);
|
|
421
|
+
|
|
422
|
+
// Create entry object
|
|
423
|
+
telemVar.Set("countAsTime", headerVar->countAsTime);
|
|
424
|
+
telemVar.Set("length", headerVar->count);
|
|
425
|
+
telemVar.Set("name", headerVar->name);
|
|
426
|
+
telemVar.Set("description", headerVar->desc);
|
|
427
|
+
telemVar.Set("unit", headerVar->unit);
|
|
428
|
+
telemVar.Set("varType", headerVar->type);
|
|
429
|
+
|
|
430
|
+
int dataSize = headerVar->count * irsdk_VarTypeBytes[headerVar->type];
|
|
431
|
+
auto entryVal = Napi::ArrayBuffer::New(env, dataSize);
|
|
432
|
+
memcpy(entryVal.Data(), this->_data + headerVar->offset, dataSize);
|
|
433
|
+
|
|
434
|
+
telemVar.Set("value", entryVal);
|
|
435
|
+
return telemVar;
|
|
383
436
|
}
|
|
384
437
|
|
|
385
438
|
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName)
|
|
386
439
|
{
|
|
387
|
-
|
|
388
|
-
|
|
440
|
+
int varIndex = irsdk_varNameToIndex(varName);
|
|
441
|
+
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
389
442
|
}
|
|
390
443
|
|
|
391
444
|
// ---------------------------
|
|
@@ -394,11 +447,11 @@ Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *va
|
|
|
394
447
|
// ---------------------------
|
|
395
448
|
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
396
449
|
{
|
|
397
|
-
|
|
450
|
+
iRacingSdkNode::Init(env, exports);
|
|
398
451
|
|
|
399
|
-
|
|
452
|
+
exports.Set("mockedSdk", false);
|
|
400
453
|
|
|
401
|
-
|
|
454
|
+
return exports;
|
|
402
455
|
}
|
|
403
456
|
|
|
404
457
|
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll);
|