@irsdk-node/native 5.1.0 → 5.2.1
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/binding.gyp +5 -13
- package/dist/cjs/index.cjs +24 -9
- package/dist/esm/index.js +23 -9
- package/dist/types/INativeSDK.d.ts +11 -0
- package/dist/types/MockSdk.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/install.js +4 -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 -457
- 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/lib/logger.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
#include "./logger.h"
|
|
3
|
+
|
|
4
|
+
#include <cstdarg>
|
|
5
|
+
#include <cstdio>
|
|
6
|
+
#include <string>
|
|
7
|
+
|
|
8
|
+
using namespace irsdk_node;
|
|
9
|
+
|
|
10
|
+
static std::string makeFormatStr(LogLevel aLevel, const char *aFormat)
|
|
11
|
+
{
|
|
12
|
+
std::string str;
|
|
13
|
+
|
|
14
|
+
str += "(irsdk-node)(";
|
|
15
|
+
str += Logger::GetLabelForLevel(aLevel);
|
|
16
|
+
str += ") ";
|
|
17
|
+
str += aFormat;
|
|
18
|
+
|
|
19
|
+
return str;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void Logger::info(const char *aFormat, ...) const
|
|
23
|
+
{
|
|
24
|
+
if (logLevel < LogLevel_Info) return;
|
|
25
|
+
|
|
26
|
+
auto formatStr = makeFormatStr(LogLevel_Info, aFormat);
|
|
27
|
+
|
|
28
|
+
va_list args;
|
|
29
|
+
va_start(args, aFormat);
|
|
30
|
+
vprintf(formatStr.c_str(), args);
|
|
31
|
+
va_end(args);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void Logger::warn(const char *aFormat, ...) const
|
|
35
|
+
{
|
|
36
|
+
if (logLevel < LogLevel_Warn) return;
|
|
37
|
+
|
|
38
|
+
auto formatStr = makeFormatStr(LogLevel_Warn, aFormat);
|
|
39
|
+
|
|
40
|
+
va_list args;
|
|
41
|
+
va_start(args, aFormat);
|
|
42
|
+
vprintf(formatStr.c_str(), args);
|
|
43
|
+
va_end(args);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void Logger::error(const char *aFormat, ...) const
|
|
47
|
+
{
|
|
48
|
+
if (logLevel < LogLevel_Error) return;
|
|
49
|
+
|
|
50
|
+
auto formatStr = makeFormatStr(LogLevel_Error, aFormat);
|
|
51
|
+
|
|
52
|
+
va_list args;
|
|
53
|
+
va_start(args, aFormat);
|
|
54
|
+
vprintf(formatStr.c_str(), args);
|
|
55
|
+
va_end(args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void Logger::debug(const char *aFormat, ...) const
|
|
59
|
+
{
|
|
60
|
+
if (logLevel < LogLevel_Debug) return;
|
|
61
|
+
|
|
62
|
+
auto formatStr = makeFormatStr(LogLevel_Debug, aFormat);
|
|
63
|
+
|
|
64
|
+
va_list args;
|
|
65
|
+
va_start(args, aFormat);
|
|
66
|
+
vprintf(formatStr.c_str(), args);
|
|
67
|
+
va_end(args);
|
|
68
|
+
}
|
package/lib/logger.h
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
namespace irsdk_node
|
|
4
|
+
{
|
|
5
|
+
static const char *K_LOGLEVEL_LABEL_INFO = "INFO";
|
|
6
|
+
static const char *K_LOGLEVEL_LABEL_WARN = "WARN";
|
|
7
|
+
static const char *K_LOGLEVEL_LABEL_ERROR = "ERROR";
|
|
8
|
+
static const char *K_LOGLEVEL_LABEL_DEBUG = "DEBUG";
|
|
9
|
+
static const char *K_LOGLEVEL_LABEL_NONE = "";
|
|
10
|
+
|
|
11
|
+
enum LogLevel
|
|
12
|
+
{
|
|
13
|
+
LogLevel_None = 0,
|
|
14
|
+
LogLevel_Error,
|
|
15
|
+
LogLevel_Warn,
|
|
16
|
+
LogLevel_Info,
|
|
17
|
+
LogLevel_Debug,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
class Logger
|
|
21
|
+
{
|
|
22
|
+
public:
|
|
23
|
+
inline Logger(LogLevel aLogLevel) : logLevel(aLogLevel)
|
|
24
|
+
{}
|
|
25
|
+
|
|
26
|
+
LogLevel logLevel;
|
|
27
|
+
|
|
28
|
+
void info(const char *aFormat, ...) const;
|
|
29
|
+
void warn(const char *aFormat, ...) const;
|
|
30
|
+
void error(const char *aFormat, ...) const;
|
|
31
|
+
void debug(const char *aFormat, ...) const;
|
|
32
|
+
|
|
33
|
+
inline static const char *GetLabelForLevel(LogLevel aLevel)
|
|
34
|
+
{
|
|
35
|
+
switch (aLevel)
|
|
36
|
+
{
|
|
37
|
+
case LogLevel_Error:
|
|
38
|
+
return K_LOGLEVEL_LABEL_ERROR;
|
|
39
|
+
|
|
40
|
+
case LogLevel_Warn:
|
|
41
|
+
return K_LOGLEVEL_LABEL_WARN;
|
|
42
|
+
|
|
43
|
+
case LogLevel_Info:
|
|
44
|
+
return K_LOGLEVEL_LABEL_INFO;
|
|
45
|
+
|
|
46
|
+
case LogLevel_Debug:
|
|
47
|
+
return K_LOGLEVEL_LABEL_DEBUG;
|
|
48
|
+
|
|
49
|
+
default:
|
|
50
|
+
return K_LOGLEVEL_LABEL_NONE;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return K_LOGLEVEL_LABEL_NONE;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
}
|
package/lib/root.cpp
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irsdk-node/native",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"author": "Matt Bengston <bengsfort@gmail.com> (https://bengsfort.dev/)",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"email": "bengsfort@gmail.com",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"package.json",
|
|
14
|
+
"./install.js",
|
|
14
15
|
"./dist",
|
|
15
16
|
"./lib",
|
|
16
|
-
"./index.d.ts",
|
|
17
17
|
"./prebuilds",
|
|
18
18
|
"./scripts",
|
|
19
19
|
"./binding.gyp",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"node-addon-api": "^8.2.1",
|
|
38
38
|
"node-gyp": "^11.5.0",
|
|
39
39
|
"node-gyp-build": "^4.8.4",
|
|
40
|
-
"@irsdk-node/types": "^4.0.
|
|
40
|
+
"@irsdk-node/types": "^4.0.5"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@bengsfort/eslint-config-flat": "^0.2.5",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"install": "node
|
|
54
|
-
"configure": "node-gyp rebuild",
|
|
53
|
+
"install": "node ./install.js",
|
|
54
|
+
"gyp:configure": "node-gyp rebuild",
|
|
55
55
|
"clean": "pnpm run \"/^clean:.*/\"",
|
|
56
56
|
"clean:ts": "rm -rf dist *.tsbuildinfo",
|
|
57
57
|
"clean:cpp": "rm -rf ./prebuilds ./build",
|
|
58
|
-
"build": "pnpm run clean && pnpm run \"/^build:(ts|types
|
|
58
|
+
"build": "pnpm run clean && pnpm run \"/^build:(ts|types)$/\"",
|
|
59
59
|
"build:ts": "node esbuild.js",
|
|
60
60
|
"build:cpp": "prebuildify --napi --electron-compat",
|
|
61
61
|
"build:types": "tsc --emitDeclarationOnly",
|
|
Binary file
|
package/lib/irsdk_node.cc
DELETED
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
#include "./irsdk_defines.h"
|
|
2
|
-
#include "./irsdk_node.h"
|
|
3
|
-
|
|
4
|
-
// ---------------------------
|
|
5
|
-
// Constructors
|
|
6
|
-
// ---------------------------
|
|
7
|
-
Napi::Object iRacingSdkNode::Init(Napi::Env env, Napi::Object exports)
|
|
8
|
-
{
|
|
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;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
39
|
-
: Napi::ObjectWrap<iRacingSdkNode>(info), _data(NULL), _bufLineLen(0), _sessionStatusID(0), _lastSessionCt(-1), _sessionData(NULL), _loggingEnabled(false)
|
|
40
|
-
{
|
|
41
|
-
printf("Initializing iRacingSdkNode\n");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ---------------------------
|
|
45
|
-
// Property implementations
|
|
46
|
-
// ---------------------------
|
|
47
|
-
Napi::Value iRacingSdkNode::GetCurrSessionDataVersion(const Napi::CallbackInfo &info)
|
|
48
|
-
{
|
|
49
|
-
int ver = this->_lastSessionCt;
|
|
50
|
-
return Napi::Number::New(info.Env(), ver);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Napi::Value iRacingSdkNode::GetEnableLogging(const Napi::CallbackInfo &info)
|
|
54
|
-
{
|
|
55
|
-
bool enabled = this->_loggingEnabled;
|
|
56
|
-
return Napi::Boolean::New(info.Env(), enabled);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
void iRacingSdkNode::SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value)
|
|
60
|
-
{
|
|
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");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
Napi::Value iRacingSdkNode::GetIsMocked(const Napi::CallbackInfo &info)
|
|
75
|
-
{
|
|
76
|
-
return Napi::Boolean::New(info.Env(), false);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ---------------------------
|
|
80
|
-
// Instance implementations
|
|
81
|
-
// ---------------------------
|
|
82
|
-
// SDK Control
|
|
83
|
-
Napi::Value iRacingSdkNode::StartSdk(const Napi::CallbackInfo &info)
|
|
84
|
-
{
|
|
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);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
Napi::Value iRacingSdkNode::StopSdk(const Napi::CallbackInfo &info)
|
|
99
|
-
{
|
|
100
|
-
irsdk_shutdown();
|
|
101
|
-
return Napi::Boolean::New(info.Env(), true);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
Napi::Value iRacingSdkNode::WaitForData(const Napi::CallbackInfo &info)
|
|
105
|
-
{
|
|
106
|
-
// Figure out the time to wait
|
|
107
|
-
// This will default to the timeout set on the class
|
|
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);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
177
|
-
{
|
|
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);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// SDK State Getters
|
|
300
|
-
Napi::Value iRacingSdkNode::IsRunning(const Napi::CallbackInfo &info)
|
|
301
|
-
{
|
|
302
|
-
bool result = irsdk_isConnected();
|
|
303
|
-
return Napi::Boolean::New(info.Env(), result);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
Napi::Value iRacingSdkNode::GetSessionVersionNum(const Napi::CallbackInfo &info)
|
|
307
|
-
{
|
|
308
|
-
int sessVer = irsdk_getSessionInfoStrUpdate();
|
|
309
|
-
return Napi::Number::New(info.Env(), sessVer);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
Napi::Value iRacingSdkNode::GetSessionData(const Napi::CallbackInfo &info)
|
|
313
|
-
{
|
|
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);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
Napi::Value iRacingSdkNode::GetTelemetryVar(const Napi::CallbackInfo &info)
|
|
331
|
-
{
|
|
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);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
Napi::Value iRacingSdkNode::GetTelemetryData(const Napi::CallbackInfo &info)
|
|
352
|
-
{
|
|
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;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Helpers
|
|
371
|
-
Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
372
|
-
{
|
|
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;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// ---------------------------
|
|
388
|
-
// Helper functions
|
|
389
|
-
// ---------------------------
|
|
390
|
-
bool iRacingSdkNode::GetTelemetryBool(int entry, int index)
|
|
391
|
-
{
|
|
392
|
-
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
393
|
-
return *(reinterpret_cast<bool const *>(_data + headerVar->offset) + index);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
int iRacingSdkNode::GetTelemetryInt(int entry, int index)
|
|
397
|
-
{
|
|
398
|
-
// Each int is 4 bytes
|
|
399
|
-
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
400
|
-
return *(reinterpret_cast<int const *>(_data + headerVar->offset) + index * 4);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
float iRacingSdkNode::GetTelemetryFloat(int entry, int index)
|
|
404
|
-
{
|
|
405
|
-
// Each float is 4 bytes
|
|
406
|
-
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
407
|
-
return *(reinterpret_cast<float const *>(_data + headerVar->offset) + index * 4);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
double iRacingSdkNode::GetTelemetryDouble(int entry, int index)
|
|
411
|
-
{
|
|
412
|
-
// Each double is 8 bytes
|
|
413
|
-
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
414
|
-
return *(reinterpret_cast<double const *>(_data + headerVar->offset) + index * 8);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index)
|
|
418
|
-
{
|
|
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;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName)
|
|
439
|
-
{
|
|
440
|
-
int varIndex = irsdk_varNameToIndex(varName);
|
|
441
|
-
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// ---------------------------
|
|
445
|
-
// Addon init
|
|
446
|
-
// TODO: This should be standardized/shared across the mocked/unmocked modules.
|
|
447
|
-
// ---------------------------
|
|
448
|
-
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
449
|
-
{
|
|
450
|
-
iRacingSdkNode::Init(env, exports);
|
|
451
|
-
|
|
452
|
-
exports.Set("mockedSdk", false);
|
|
453
|
-
|
|
454
|
-
return exports;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll);
|