@irsdk-node/native 5.0.0 → 5.2.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 +18 -0
- package/binding.gyp +5 -13
- package/dist/cjs/index.cjs +27 -11
- package/dist/esm/index.js +26 -11
- package/dist/types/INativeSDK.d.ts +13 -15
- package/dist/types/MockSdk.d.ts +6 -16
- package/dist/types/index.d.ts +1 -0
- package/lib/irsdk_node.cpp +533 -0
- package/lib/irsdk_node.h +93 -36
- package/lib/logger.cpp +68 -0
- package/lib/logger.h +57 -0
- package/lib/root.cpp +11 -0
- package/package.json +6 -6
- package/prebuilds/@irsdk-node+native.node +0 -0
- package/lib/irsdk_node.cc +0 -404
- package/lib/irsdk_node_mocked.cc +0 -226
- package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/linux-x64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/scripts/generate-var-types.js +0 -71
package/lib/irsdk_node_mocked.cc
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
#include "./irsdk_node.h"
|
|
2
|
-
#include "./yaml_parser.h"
|
|
3
|
-
|
|
4
|
-
const char *MOCK_PROP_NAME = "__mocked";
|
|
5
|
-
|
|
6
|
-
// ---------------------------
|
|
7
|
-
// Constructors
|
|
8
|
-
// ---------------------------
|
|
9
|
-
Napi::Object iRacingSdkNode::Init(Napi::Env env, Napi::Object exports)
|
|
10
|
-
{
|
|
11
|
-
Napi::Function func = DefineClass(env, "iRacingSdkNode", {
|
|
12
|
-
// Properties
|
|
13
|
-
InstanceAccessor<&iRacingSdkNode::GetCurrSessionDataVersion>("currDataVersion"),
|
|
14
|
-
InstanceAccessor<&iRacingSdkNode::GetEnableLogging, &iRacingSdkNode::SetEnableLogging>("enableLogging"),
|
|
15
|
-
InstanceAccessor<&iRacingSdkNode::GetIsMocked>("isMocked"),
|
|
16
|
-
|
|
17
|
-
// Methods
|
|
18
|
-
// Control
|
|
19
|
-
InstanceMethod<&iRacingSdkNode::StartSdk>("startSDK"),
|
|
20
|
-
InstanceMethod("stopSDK", &iRacingSdkNode::StopSdk),
|
|
21
|
-
InstanceMethod("waitForData", &iRacingSdkNode::WaitForData),
|
|
22
|
-
InstanceMethod("broadcast", &iRacingSdkNode::BroadcastMessage),
|
|
23
|
-
// Getters
|
|
24
|
-
InstanceMethod("isRunning", &iRacingSdkNode::IsRunning),
|
|
25
|
-
InstanceMethod("getSessionVersionNum", &iRacingSdkNode::GetSessionVersionNum),
|
|
26
|
-
InstanceMethod("getSessionData", &iRacingSdkNode::GetSessionData),
|
|
27
|
-
InstanceMethod("getTelemetryData", &iRacingSdkNode::GetTelemetryData),
|
|
28
|
-
InstanceMethod("getTelemetryVariable", &iRacingSdkNode::GetTelemetryVar),
|
|
29
|
-
// Helpers
|
|
30
|
-
InstanceMethod("__getTelemetryTypes", &iRacingSdkNode::__GetTelemetryTypes),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
Napi::FunctionReference *constructor = new Napi::FunctionReference();
|
|
34
|
-
*constructor = Napi::Persistent(func);
|
|
35
|
-
env.SetInstanceData(constructor);
|
|
36
|
-
|
|
37
|
-
exports.Set("iRacingSdkNode", func);
|
|
38
|
-
return exports;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
42
|
-
: Napi::ObjectWrap<iRacingSdkNode>(info), _data(NULL), _bufLineLen(0), _sessionStatusID(0), _lastSessionCt(-1), _sessionData(NULL), _loggingEnabled(false)
|
|
43
|
-
{
|
|
44
|
-
printf("Initializing mock iRacingSdkNode\n");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---------------------------
|
|
48
|
-
// Property implementations
|
|
49
|
-
// ---------------------------
|
|
50
|
-
Napi::Value iRacingSdkNode::GetCurrSessionDataVersion(const Napi::CallbackInfo &info)
|
|
51
|
-
{
|
|
52
|
-
int ver = this->_lastSessionCt;
|
|
53
|
-
return Napi::Number::New(info.Env(), ver);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Napi::Value iRacingSdkNode::GetEnableLogging(const Napi::CallbackInfo &info)
|
|
57
|
-
{
|
|
58
|
-
bool enabled = this->_loggingEnabled;
|
|
59
|
-
return Napi::Boolean::New(info.Env(), enabled);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
void iRacingSdkNode::SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value)
|
|
63
|
-
{
|
|
64
|
-
Napi::Boolean enable;
|
|
65
|
-
if (info.Length() <= 0 || !info[0].IsBoolean())
|
|
66
|
-
{
|
|
67
|
-
enable = Napi::Boolean::New(info.Env(), false);
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
{
|
|
71
|
-
enable = info[0].As<Napi::Boolean>();
|
|
72
|
-
}
|
|
73
|
-
this->_loggingEnabled = enable;
|
|
74
|
-
if (this->_loggingEnabled)
|
|
75
|
-
printf("iRacingSDK Logging enabled\n");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
Napi::Value iRacingSdkNode::GetIsMocked(const Napi::CallbackInfo &info)
|
|
79
|
-
{
|
|
80
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ---------------------------
|
|
84
|
-
// Instance implementations
|
|
85
|
-
// ---------------------------
|
|
86
|
-
// SDK Control
|
|
87
|
-
Napi::Value iRacingSdkNode::StartSdk(const Napi::CallbackInfo &info)
|
|
88
|
-
{
|
|
89
|
-
if (this->_loggingEnabled)
|
|
90
|
-
printf("Starting Mock SDK...\n");
|
|
91
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
Napi::Value iRacingSdkNode::StopSdk(const Napi::CallbackInfo &info)
|
|
95
|
-
{
|
|
96
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Napi::Value iRacingSdkNode::WaitForData(const Napi::CallbackInfo &info)
|
|
100
|
-
{
|
|
101
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
105
|
-
{
|
|
106
|
-
auto env = info.Env();
|
|
107
|
-
|
|
108
|
-
// Determine message type
|
|
109
|
-
if (info.Length() <= 2 || !info[0].IsNumber())
|
|
110
|
-
{
|
|
111
|
-
return Napi::Boolean::New(env, false);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (info.Length() == 4 && !info[2].IsNumber())
|
|
115
|
-
{
|
|
116
|
-
return Napi::Boolean::New(env, false);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return Napi::Boolean::New(env, true);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// SDK State Getters
|
|
123
|
-
Napi::Value iRacingSdkNode::IsRunning(const Napi::CallbackInfo &info)
|
|
124
|
-
{
|
|
125
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
Napi::Value iRacingSdkNode::GetSessionVersionNum(const Napi::CallbackInfo &info)
|
|
129
|
-
{
|
|
130
|
-
return Napi::Number::New(info.Env(), 1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Napi::Value iRacingSdkNode::GetSessionData(const Napi::CallbackInfo &info)
|
|
134
|
-
{
|
|
135
|
-
return Napi::String::New(info.Env(), MOCK_PROP_NAME);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
Napi::Value iRacingSdkNode::GetTelemetryVar(const Napi::CallbackInfo &info)
|
|
139
|
-
{
|
|
140
|
-
Napi::Env env = info.Env();
|
|
141
|
-
|
|
142
|
-
int varIndex;
|
|
143
|
-
if (info.Length() <= 0)
|
|
144
|
-
{
|
|
145
|
-
varIndex = 0;
|
|
146
|
-
}
|
|
147
|
-
else if (!info[0].IsNumber())
|
|
148
|
-
{
|
|
149
|
-
if (info[0].IsString())
|
|
150
|
-
{
|
|
151
|
-
auto obj = Napi::Object::New(env);
|
|
152
|
-
obj.Set(MOCK_PROP_NAME, true);
|
|
153
|
-
return obj;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
varIndex = 0;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
Napi::Value iRacingSdkNode::GetTelemetryData(const Napi::CallbackInfo &info)
|
|
163
|
-
{
|
|
164
|
-
auto env = info.Env();
|
|
165
|
-
auto telemVars = Napi::Object::New(env);
|
|
166
|
-
telemVars.Set(MOCK_PROP_NAME, true);
|
|
167
|
-
return telemVars;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Helpers
|
|
171
|
-
Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
172
|
-
{
|
|
173
|
-
auto env = info.Env();
|
|
174
|
-
auto result = Napi::Object::New(env);
|
|
175
|
-
result.Set(MOCK_PROP_NAME, true);
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ---------------------------
|
|
180
|
-
// Helper functions
|
|
181
|
-
// ---------------------------
|
|
182
|
-
bool iRacingSdkNode::GetTelemetryBool(int entry, int index)
|
|
183
|
-
{
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
int iRacingSdkNode::GetTelemetryInt(int entry, int index)
|
|
188
|
-
{
|
|
189
|
-
return 0;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
float iRacingSdkNode::GetTelemetryFloat(int entry, int index)
|
|
193
|
-
{
|
|
194
|
-
return 0.0f;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
double iRacingSdkNode::GetTelemetryDouble(int entry, int index)
|
|
198
|
-
{
|
|
199
|
-
// Each double is 8 bytes
|
|
200
|
-
return 0.0;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index)
|
|
204
|
-
{
|
|
205
|
-
auto telemVar = Napi::Object::New(env);
|
|
206
|
-
telemVar.Set(MOCK_PROP_NAME, true);
|
|
207
|
-
return telemVar;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName)
|
|
211
|
-
{
|
|
212
|
-
auto obj = Napi::Object::New(env);
|
|
213
|
-
obj.Set(MOCK_PROP_NAME, true);
|
|
214
|
-
return obj;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
218
|
-
{
|
|
219
|
-
iRacingSdkNode::Init(env, exports);
|
|
220
|
-
|
|
221
|
-
exports.Set("mockedSdk", true);
|
|
222
|
-
|
|
223
|
-
return exports;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const NativeSDK = require("../build/Debug/irsdk_node.node").iRacingSdkNode;
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
|
|
5
|
-
const TARGET_FILE = "_GENERATED_telemetry.ts";
|
|
6
|
-
const OUT_PATH = path.resolve(process.cwd(), "../irsdk-node-types/src/", TARGET_FILE);
|
|
7
|
-
|
|
8
|
-
console.log("Generating iRacing telemetry variable types.");
|
|
9
|
-
console.log("Make sure the sim is running!");
|
|
10
|
-
|
|
11
|
-
const sdk = new NativeSDK();
|
|
12
|
-
sdk.startSDK();
|
|
13
|
-
|
|
14
|
-
// Telemetry command, Start Recording
|
|
15
|
-
sdk.broadcast(10, 1);
|
|
16
|
-
// Wait a max of 5s
|
|
17
|
-
if (!sdk.waitForData(5000)) {
|
|
18
|
-
process.stderr.write("No data. Make sure the sim is running and try again.");
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const varTypes = [
|
|
23
|
-
"string",
|
|
24
|
-
"boolean",
|
|
25
|
-
"number",
|
|
26
|
-
"number",
|
|
27
|
-
"number",
|
|
28
|
-
"number",
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
// Get all the types
|
|
32
|
-
const types = sdk.__getTelemetryTypes();
|
|
33
|
-
const out = `
|
|
34
|
-
// ! THIS FILE IS AUTO-GENERATED, EDITS WILL BE OVERRIDDEN !
|
|
35
|
-
// ! Make changes to the generate-var-types in @irsk-node/native !
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A variable included in the telemetry.
|
|
39
|
-
*/
|
|
40
|
-
export interface TelemetryVariable<VarType = number[]> {
|
|
41
|
-
/** The name of the variable. */
|
|
42
|
-
name: string;
|
|
43
|
-
/** The description. */
|
|
44
|
-
description: string;
|
|
45
|
-
/** The unit of the value (ex. "kg/m^2") */
|
|
46
|
-
unit: string;
|
|
47
|
-
/** Should it be treated as a time? */
|
|
48
|
-
countAsTime: boolean;
|
|
49
|
-
/** The number of values provided. */
|
|
50
|
-
length: number;
|
|
51
|
-
/** The native variable type */
|
|
52
|
-
varType: number;
|
|
53
|
-
/** The current value of this variable. */
|
|
54
|
-
value: VarType;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface TelemetryVarList {
|
|
58
|
-
${Object.keys(types).map((varName) =>
|
|
59
|
-
` ${varName}: TelemetryVariable<${varTypes[types[varName]]}[]>`
|
|
60
|
-
).join(";\n")};
|
|
61
|
-
}
|
|
62
|
-
`;
|
|
63
|
-
|
|
64
|
-
fs.writeFile(OUT_PATH, out, "utf-8", (err) => {
|
|
65
|
-
if (err) {
|
|
66
|
-
console.error("There was an error creating the file:", err);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
console.log("Successfully generated types!");
|
|
70
|
-
process.exit(0);
|
|
71
|
-
});
|