@irsdk-node/native 3.0.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 +46 -0
- package/binding.gyp +19 -0
- package/build/Debug/irsdk_node.exp +0 -0
- package/build/Debug/irsdk_node.lib +0 -0
- package/build/Debug/irsdk_node.node +0 -0
- package/build/Debug/irsdk_node.pdb +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.node.recipe +11 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +2 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.write.1u.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
- package/build/Debug/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
- package/build/Debug/obj/irsdk_node/lib/yaml_parser.obj +0 -0
- package/build/Debug/obj/irsdk_node/src/irsdk_node.obj +0 -0
- package/build/Debug/obj/irsdk_node/win_delay_load_hook.obj +0 -0
- package/build/Release/irsdk_node.exp +0 -0
- package/build/Release/irsdk_node.iobj +0 -0
- package/build/Release/irsdk_node.ipdb +0 -0
- package/build/Release/irsdk_node.lib +0 -0
- package/build/Release/irsdk_node.node +0 -0
- package/build/Release/irsdk_node.pdb +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.node.recipe +11 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +2 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.write.1u.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
- package/build/Release/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
- package/build/Release/obj/irsdk_node/lib/yaml_parser.obj +0 -0
- package/build/Release/obj/irsdk_node/src/irsdk_node.obj +0 -0
- package/build/Release/obj/irsdk_node/win_delay_load_hook.obj +0 -0
- package/build/binding.sln +19 -0
- package/build/config.gypi +88 -0
- package/build/irsdk_node.vcxproj +155 -0
- package/build/irsdk_node.vcxproj.filters +73 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/lib/irsdk_client.cpp +495 -0
- package/lib/irsdk_client.h +139 -0
- package/lib/irsdk_defines.h +528 -0
- package/lib/irsdk_utils.cpp +377 -0
- package/lib/yaml_parser.cpp +176 -0
- package/lib/yaml_parser.h +34 -0
- package/package.json +52 -0
- package/scripts/generate-var-types.js +71 -0
- package/src/index.d.ts +117 -0
- package/src/index.js +5 -0
- package/src/irsdk_node.cc +375 -0
- package/src/irsdk_node.h +50 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BroadcastMessages,
|
|
3
|
+
CameraState,
|
|
4
|
+
ChatCommand,
|
|
5
|
+
FFBCommand,
|
|
6
|
+
PitCommand,
|
|
7
|
+
ReloadTexturesCommand,
|
|
8
|
+
ReplayPositionCommand,
|
|
9
|
+
ReplaySearchCommand,
|
|
10
|
+
ReplayStateCommand,
|
|
11
|
+
TelemetryCommand,
|
|
12
|
+
VideoCaptureCommand,
|
|
13
|
+
TelemetryVariable,
|
|
14
|
+
TelemetryVarList,
|
|
15
|
+
} from '@irsdk-node/types';
|
|
16
|
+
|
|
17
|
+
type TelemetryTypesDict = {
|
|
18
|
+
[variableName: string]: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface INativeSDK {
|
|
22
|
+
readonly currDataVersion: number;
|
|
23
|
+
enableLogging: boolean;
|
|
24
|
+
|
|
25
|
+
// Main API
|
|
26
|
+
// Control
|
|
27
|
+
startSDK(): boolean;
|
|
28
|
+
stopSDK(): void;
|
|
29
|
+
|
|
30
|
+
// State
|
|
31
|
+
isRunning(): boolean;
|
|
32
|
+
waitForData(timeout?: number): boolean;
|
|
33
|
+
getSessionData(): string; // full yaml
|
|
34
|
+
getTelemetryData(): TelemetryVarList;
|
|
35
|
+
|
|
36
|
+
getTelemetryVariable<T>(index: number): TelemetryVariable<T>;
|
|
37
|
+
getTelemetryVariable<T>(name: string): TelemetryVariable<T>;
|
|
38
|
+
|
|
39
|
+
// Broadcast command overloads
|
|
40
|
+
// This is handled in the cpp side so no need to mess with it in js
|
|
41
|
+
broadcast(message: BroadcastMessages.CameraSwitchPos, pos: number, group: number, camera: number): void;
|
|
42
|
+
broadcast(message: BroadcastMessages.CameraSwitchNum, driver: number, group: number, camera: number): void;
|
|
43
|
+
broadcast(message: BroadcastMessages.CameraSetState, state: CameraState): void;
|
|
44
|
+
broadcast(message: BroadcastMessages.ReplaySetPlaySpeed, speed: number, slowMotion: number): void;
|
|
45
|
+
broadcast(message: BroadcastMessages.ReplaySetPlayPosition, pos: ReplayPositionCommand, frame: number): void;
|
|
46
|
+
broadcast(message: BroadcastMessages.ReplaySearch, mode: ReplaySearchCommand): void;
|
|
47
|
+
broadcast(message: BroadcastMessages.ReplaySetState, state: ReplayStateCommand): void;
|
|
48
|
+
broadcast(message: BroadcastMessages.ReloadTextures, command: ReloadTexturesCommand, carIndex?: number): void;
|
|
49
|
+
broadcast(message: BroadcastMessages.ChatCommand, command: ChatCommand, macro?: number): void;
|
|
50
|
+
broadcast(message: BroadcastMessages.PitCommand, command: PitCommand, param?: number): void;
|
|
51
|
+
broadcast(message: BroadcastMessages.TelemCommand, command: TelemetryCommand): void;
|
|
52
|
+
broadcast(message: BroadcastMessages.FFBCommand, command: FFBCommand, value: number): void;
|
|
53
|
+
broadcast(message: BroadcastMessages.ReplaySearchSessionTime, session: number, time: number): void;
|
|
54
|
+
broadcast(message: BroadcastMessages.VideoCapture, command: VideoCaptureCommand): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class NativeSDK implements INativeSDK {
|
|
58
|
+
public readonly currDataVersion: number;
|
|
59
|
+
|
|
60
|
+
public enableLogging: boolean;
|
|
61
|
+
|
|
62
|
+
constructor();
|
|
63
|
+
|
|
64
|
+
// Main API
|
|
65
|
+
// Control
|
|
66
|
+
public startSDK(): boolean;
|
|
67
|
+
|
|
68
|
+
public stopSDK(): void;
|
|
69
|
+
|
|
70
|
+
// State
|
|
71
|
+
public isRunning(): boolean;
|
|
72
|
+
|
|
73
|
+
public waitForData(timeout?: number): boolean;
|
|
74
|
+
|
|
75
|
+
public getSessionData(): string; // full yaml
|
|
76
|
+
|
|
77
|
+
public getTelemetryData(): TelemetryVarList;
|
|
78
|
+
|
|
79
|
+
public getTelemetryVariable<T extends number | boolean | string>(index: number): TelemetryVariable<T[]>;
|
|
80
|
+
|
|
81
|
+
public getTelemetryVariable<T extends number | boolean | string>(name: string): TelemetryVariable<T[]>;
|
|
82
|
+
|
|
83
|
+
// Private helpers
|
|
84
|
+
public __getTelemetryTypes(): TelemetryTypesDict;
|
|
85
|
+
|
|
86
|
+
// Broadcast command overloads
|
|
87
|
+
// This is handled in the cpp side so no need to mess with it in js
|
|
88
|
+
public broadcast(message: BroadcastMessages.CameraSwitchPos, pos: number, group: number, camera: number): void;
|
|
89
|
+
|
|
90
|
+
public broadcast(message: BroadcastMessages.CameraSwitchNum, driver: number, group: number, camera: number): void;
|
|
91
|
+
|
|
92
|
+
public broadcast(message: BroadcastMessages.CameraSetState, state: CameraState): void;
|
|
93
|
+
|
|
94
|
+
public broadcast(message: BroadcastMessages.ReplaySetPlaySpeed, speed: number, slowMotion: number): void;
|
|
95
|
+
|
|
96
|
+
public broadcast(message: BroadcastMessages.ReplaySetPlayPosition, pos: ReplayPositionCommand, frame: number): void;
|
|
97
|
+
|
|
98
|
+
public broadcast(message: BroadcastMessages.ReplaySearch, mode: ReplaySearchCommand): void;
|
|
99
|
+
|
|
100
|
+
public broadcast(message: BroadcastMessages.ReplaySetState, state: ReplayStateCommand): void;
|
|
101
|
+
|
|
102
|
+
public broadcast(message: BroadcastMessages.ReloadTextures, command: ReloadTexturesCommand, carIndex?: number): void;
|
|
103
|
+
|
|
104
|
+
public broadcast(message: BroadcastMessages.ChatCommand, command: ChatCommand, macro?: number): void;
|
|
105
|
+
|
|
106
|
+
public broadcast(message: BroadcastMessages.PitCommand, command: PitCommand, param?: number): void;
|
|
107
|
+
|
|
108
|
+
public broadcast(message: BroadcastMessages.TelemCommand, command: TelemetryCommand): void;
|
|
109
|
+
|
|
110
|
+
public broadcast(message: BroadcastMessages.FFBCommand, command: FFBCommand, value: number): void;
|
|
111
|
+
|
|
112
|
+
public broadcast(message: BroadcastMessages.ReplaySearchSessionTime, session: number, time: number): void;
|
|
113
|
+
|
|
114
|
+
public broadcast(message: BroadcastMessages.VideoCapture, command: VideoCaptureCommand): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const DebugSDK: typeof NativeSDK;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Import from JS so that we can type the API in a nicer way (without aliases)
|
|
2
|
+
// The alternative would be to somehow get types generated, or use aliases to
|
|
3
|
+
// fake a module and then define that module... but those are gross, so no thanks
|
|
4
|
+
export const NativeSDK = require("../build/Release/irsdk_node.node").iRacingSdkNode;
|
|
5
|
+
export const DebugSDK = require("../build/Debug/irsdk_node.node").iRacingSdkNode;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
#include "./irsdk_node.h"
|
|
2
|
+
#include "../lib/yaml_parser.h"
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Nan::SetPrototypeMethod(tmpl, "getSessionData", GetSessionData);
|
|
6
|
+
Nan::SetPrototypeMethod(tmpl, "getSessionVersionNum", GetSessionVersionNum);
|
|
7
|
+
Nan::SetPrototypeMethod(tmpl, "getTelemetryData", GetTelemetryData);
|
|
8
|
+
Nan::SetPrototypeMethod(tmpl, "broadcast", BroadcastMessage);
|
|
9
|
+
Nan::SetPrototypeMethod(tmpl, "__getTelemetryTypes", __GetTelemetryTypes);
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ---------------------------
|
|
13
|
+
// Constructors
|
|
14
|
+
// ---------------------------
|
|
15
|
+
Napi::Object iRacingSdkNode::Init(Napi::Env env, Napi::Object exports)
|
|
16
|
+
{
|
|
17
|
+
Napi::Function func = DefineClass(env, "iRacingSdkNode", {
|
|
18
|
+
// Properties
|
|
19
|
+
InstanceAccessor<&iRacingSdkNode::GetCurrSessionDataVersion>("currDataVersion"),
|
|
20
|
+
InstanceAccessor<&iRacingSdkNode::GetEnableLogging, &iRacingSdkNode::SetEnableLogging>("enableLogging"),
|
|
21
|
+
// Methods
|
|
22
|
+
//Control
|
|
23
|
+
InstanceMethod<&iRacingSdkNode::StartSdk>("startSDK"),
|
|
24
|
+
InstanceMethod("stopSDK", &iRacingSdkNode::StopSdk),
|
|
25
|
+
InstanceMethod("waitForData", &iRacingSdkNode::WaitForData),
|
|
26
|
+
InstanceMethod("broadcast", &iRacingSdkNode::BroadcastMessage),
|
|
27
|
+
// Getters
|
|
28
|
+
InstanceMethod("isRunning", &iRacingSdkNode::IsRunning),
|
|
29
|
+
InstanceMethod("getSessionVersionNum", &iRacingSdkNode::GetSessionVersionNum),
|
|
30
|
+
InstanceMethod("getSessionData", &iRacingSdkNode::GetSessionData),
|
|
31
|
+
InstanceMethod("getTelemetryData", &iRacingSdkNode::GetTelemetryData),
|
|
32
|
+
InstanceMethod("getTelemetryVariable", &iRacingSdkNode::GetTelemetryVar),
|
|
33
|
+
// Helpers
|
|
34
|
+
InstanceMethod("__getTelemetryTypes", &iRacingSdkNode::__GetTelemetryTypes)
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
Napi::FunctionReference* constructor = new Napi::FunctionReference();
|
|
38
|
+
*constructor = Napi::Persistent(func);
|
|
39
|
+
env.SetInstanceData(constructor);
|
|
40
|
+
|
|
41
|
+
exports.Set("iRacingSdkNode", func);
|
|
42
|
+
return exports;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
iRacingSdkNode::iRacingSdkNode(const Napi::CallbackInfo &info)
|
|
46
|
+
: Napi::ObjectWrap<iRacingSdkNode>(info)
|
|
47
|
+
, _data(NULL)
|
|
48
|
+
, _bufLineLen(0)
|
|
49
|
+
, _sessionStatusID(0)
|
|
50
|
+
, _lastSessionCt(-1)
|
|
51
|
+
, _sessionData(NULL)
|
|
52
|
+
, _loggingEnabled(false)
|
|
53
|
+
{
|
|
54
|
+
printf("Initializing cpp class instance...\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ---------------------------
|
|
58
|
+
// Property implementations
|
|
59
|
+
// ---------------------------
|
|
60
|
+
Napi::Value iRacingSdkNode::GetCurrSessionDataVersion(const Napi::CallbackInfo &info)
|
|
61
|
+
{
|
|
62
|
+
int ver = this->_lastSessionCt;
|
|
63
|
+
return Napi::Number::New(info.Env(), ver);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Napi::Value iRacingSdkNode::GetEnableLogging(const Napi::CallbackInfo &info)
|
|
67
|
+
{
|
|
68
|
+
bool enabled = this->_loggingEnabled;
|
|
69
|
+
return Napi::Boolean::New(info.Env(), enabled);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void iRacingSdkNode::SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value)
|
|
73
|
+
{
|
|
74
|
+
Napi::Boolean enable;
|
|
75
|
+
if (info.Length() <= 0 || !info[0].IsBoolean()) {
|
|
76
|
+
enable = Napi::Boolean::New(info.Env(), false);
|
|
77
|
+
} else {
|
|
78
|
+
enable = info[0].As<Napi::Boolean>();
|
|
79
|
+
}
|
|
80
|
+
printf("Setting logging enabled: %i\n", info[0]);
|
|
81
|
+
this->_loggingEnabled = enable;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------
|
|
85
|
+
// Instance implementations
|
|
86
|
+
// ---------------------------
|
|
87
|
+
// SDK Control
|
|
88
|
+
Napi::Value iRacingSdkNode::StartSdk(const Napi::CallbackInfo &info)
|
|
89
|
+
{
|
|
90
|
+
printf("Starting SDK...\n");
|
|
91
|
+
if (!irsdk_isConnected()) {
|
|
92
|
+
bool result = irsdk_startup();
|
|
93
|
+
printf("Connected at least! %i\n", result);
|
|
94
|
+
return Napi::Boolean::New(info.Env(), result);
|
|
95
|
+
}
|
|
96
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Napi::Value iRacingSdkNode::StopSdk(const Napi::CallbackInfo &info)
|
|
100
|
+
{
|
|
101
|
+
irsdk_shutdown();
|
|
102
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Napi::Value iRacingSdkNode::WaitForData(const Napi::CallbackInfo &info)
|
|
106
|
+
{
|
|
107
|
+
// Figure out the time to wait
|
|
108
|
+
// This will default to the timeout set on the class
|
|
109
|
+
Napi::Number timeout;
|
|
110
|
+
if (info.Length() <= 0 || !info[0].IsNumber()) {
|
|
111
|
+
timeout = Napi::Number::New(info.Env(), 16);
|
|
112
|
+
} else {
|
|
113
|
+
timeout = info[0].As<Napi::Number>();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!irsdk_isConnected() && !irsdk_startup()) {
|
|
117
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// @todo: try to do this async instead
|
|
121
|
+
const irsdk_header* header = irsdk_getHeader();
|
|
122
|
+
|
|
123
|
+
// @todo: This isn't the best way of doing this. Need to improve, but this works for now
|
|
124
|
+
if (!this->_data) {
|
|
125
|
+
this->_data = new char[header->bufLen];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// wait for start of sesh or new data
|
|
129
|
+
bool dataReady = irsdk_waitForDataReady(timeout, this->_data);
|
|
130
|
+
if (dataReady && header)
|
|
131
|
+
{
|
|
132
|
+
if (this->_loggingEnabled) ("Session started or we have new data.\n");
|
|
133
|
+
|
|
134
|
+
// New connection or data changed length
|
|
135
|
+
if (this->_bufLineLen != header->bufLen) {
|
|
136
|
+
if (this->_loggingEnabled) printf("Connection started / data changed length.\n");
|
|
137
|
+
|
|
138
|
+
this->_bufLineLen = header->bufLen;
|
|
139
|
+
|
|
140
|
+
// Increment connection
|
|
141
|
+
this->_sessionStatusID++;
|
|
142
|
+
|
|
143
|
+
// Reset info str status
|
|
144
|
+
this->_lastSessionCt = -1;
|
|
145
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
146
|
+
} else if (this->_data) {
|
|
147
|
+
if (this->_loggingEnabled) printf("Data initialized and ready to process.\n");
|
|
148
|
+
// already initialized and ready to process
|
|
149
|
+
return Napi::Boolean::New(info.Env(), true);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (!(this->_data != NULL && irsdk_isConnected()))
|
|
153
|
+
{
|
|
154
|
+
printf("Session ended. Cleaning up.\n");
|
|
155
|
+
// Session ended
|
|
156
|
+
if (this->_data) delete[] this->_data;
|
|
157
|
+
this->_data = NULL;
|
|
158
|
+
|
|
159
|
+
// Reset Info str
|
|
160
|
+
this->_lastSessionCt = -1;
|
|
161
|
+
}
|
|
162
|
+
printf("Session ended or something went wrong. Not successful.\n");
|
|
163
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
167
|
+
{
|
|
168
|
+
auto env = info.Env();
|
|
169
|
+
|
|
170
|
+
// Determine message type
|
|
171
|
+
if (info.Length() <= 2 || !info[0].IsNumber()) {
|
|
172
|
+
return Napi::Boolean::New(env, false);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (info.Length() == 4 && !info[2].IsNumber()) {
|
|
176
|
+
return Napi::Boolean::New(env, false);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
int msgEnumIndex = info[0].As<Napi::Number>();
|
|
180
|
+
irsdk_BroadcastMsg msgType = static_cast<irsdk_BroadcastMsg>(msgEnumIndex);
|
|
181
|
+
|
|
182
|
+
// Args
|
|
183
|
+
int arg1 = info[1].As<Napi::Number>();
|
|
184
|
+
auto arg2 = info[2].As<Napi::Number>();
|
|
185
|
+
auto arg3 = info[3].As<Napi::Number>();
|
|
186
|
+
|
|
187
|
+
// these defs are in irsdk_defines.cpp
|
|
188
|
+
switch (msgType)
|
|
189
|
+
{
|
|
190
|
+
// irsdk_BroadcastMsg msg, int arg1, int arg2, int var3
|
|
191
|
+
case irsdk_BroadcastCamSwitchPos: // @todo we need to use irsdk_padCarNum for arg1
|
|
192
|
+
case irsdk_BroadcastCamSwitchNum:
|
|
193
|
+
printf("BroadcastMessage(msgType: %d, arg1: %d, arg2: %d, arg3: %d)\n", msgType, arg1, arg2.Int32Value(), arg3.Int32Value());
|
|
194
|
+
irsdk_broadcastMsg(msgType, arg1, arg2, arg3);
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
// irsdk_BroadcastMsg msg, int arg1, int unused, int unused
|
|
198
|
+
case irsdk_BroadcastReplaySearch: // arg1 == irsdk_RpySrchMode
|
|
199
|
+
case irsdk_BroadcastReplaySetState: // arg1 == irsdk_RpyStateMode
|
|
200
|
+
case irsdk_BroadcastCamSetState: // arg1 == irsdk_CameraState
|
|
201
|
+
case irsdk_BroadcastTelemCommand: // arg1 == irsdk_TelemCommandMode
|
|
202
|
+
case irsdk_BroadcastVideoCapture: // arg1 == irsdk_VideoCaptureMode
|
|
203
|
+
printf("BroadcastMessage(msgType: %d, arg1: %d, arg2: -1, arg3: -1)\n", msgType, arg1);
|
|
204
|
+
irsdk_broadcastMsg(msgType, arg1, -1, -1);
|
|
205
|
+
break;
|
|
206
|
+
|
|
207
|
+
// irsdk_BroadcastMsg msg, int arg1, int arg2, int unused
|
|
208
|
+
case irsdk_BroadcastReloadTextures: // arg1 == irsdk_ReloadTexturesMode
|
|
209
|
+
case irsdk_BroadcastChatComand: // arg1 == irsdk_ChatCommandMode
|
|
210
|
+
case irsdk_BroadcastReplaySetPlaySpeed:
|
|
211
|
+
printf("BroadcastMessage(msgType: %d, arg1: %d, arg2: %d, arg3: -1)\n", msgType, arg1, arg2.Int32Value());
|
|
212
|
+
irsdk_broadcastMsg(msgType, arg1, arg2, -1);
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
// irsdk_BroadcastMsg msg, int arg1, float arg2
|
|
216
|
+
case irsdk_BroadcastPitCommand: // arg1 == irsdk_PitCommandMode
|
|
217
|
+
case irsdk_BroadcastFFBCommand: // arg1 == irsdk_FFBCommandMode
|
|
218
|
+
case irsdk_BroadcastReplaySearchSessionTime:
|
|
219
|
+
case irskd_BroadcastReplaySetPlayPosition:
|
|
220
|
+
printf("BroadcastMessage(msgType: %d, arg1: %d, arg2: %f)\n", msgType, arg1, (float)arg2.FloatValue());
|
|
221
|
+
irsdk_broadcastMsg(msgType, arg1, (float)arg2.FloatValue());
|
|
222
|
+
break;
|
|
223
|
+
|
|
224
|
+
default:
|
|
225
|
+
printf("Attempted to broadcast an unsupported message.");
|
|
226
|
+
return Napi::Boolean::New(env, false);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return Napi::Boolean::New(env, true);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// SDK State Getters
|
|
233
|
+
Napi::Value iRacingSdkNode::IsRunning(const Napi::CallbackInfo &info)
|
|
234
|
+
{
|
|
235
|
+
bool result = irsdk_isConnected();
|
|
236
|
+
return Napi::Boolean::New(info.Env(), result);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
Napi::Value iRacingSdkNode::GetSessionVersionNum(const Napi::CallbackInfo &info)
|
|
240
|
+
{
|
|
241
|
+
int sessVer = irsdk_getSessionInfoStrUpdate();
|
|
242
|
+
return Napi::Number::New(info.Env(), sessVer);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
Napi::Value iRacingSdkNode::GetSessionData(const Napi::CallbackInfo &info)
|
|
246
|
+
{
|
|
247
|
+
int latestUpdate = irsdk_getSessionInfoStrUpdate();
|
|
248
|
+
if (this->_lastSessionCt != latestUpdate) {
|
|
249
|
+
printf("Session data has been updated (prev: %d, new: %d)\n", this->_lastSessionCt, latestUpdate);
|
|
250
|
+
this->_lastSessionCt = latestUpdate;
|
|
251
|
+
this->_sessionData = irsdk_getSessionInfoStr();
|
|
252
|
+
}
|
|
253
|
+
const char *session = this->_sessionData;
|
|
254
|
+
if (session == NULL) {
|
|
255
|
+
return Napi::String::New(info.Env(), "");
|
|
256
|
+
}
|
|
257
|
+
return Napi::String::New(info.Env(), session);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Napi::Value iRacingSdkNode::GetTelemetryVar(const Napi::CallbackInfo &info)
|
|
261
|
+
{
|
|
262
|
+
Napi::Env env = info.Env();
|
|
263
|
+
|
|
264
|
+
int varIndex;
|
|
265
|
+
if (info.Length() <= 0) {
|
|
266
|
+
varIndex = 0;
|
|
267
|
+
} else if (!info[0].IsNumber()) {
|
|
268
|
+
if (info[0].IsString()) {
|
|
269
|
+
const char *name = info[0].As<Napi::String>().Utf8Value().c_str();
|
|
270
|
+
return this->GetTelemetryVar(env, name);
|
|
271
|
+
}
|
|
272
|
+
varIndex = 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
Napi::Value iRacingSdkNode::GetTelemetryData(const Napi::CallbackInfo &info)
|
|
279
|
+
{
|
|
280
|
+
const irsdk_header* header = irsdk_getHeader();
|
|
281
|
+
auto env = info.Env();
|
|
282
|
+
auto telemVars = Napi::Object::New(env);
|
|
283
|
+
|
|
284
|
+
int count = header->numVars;
|
|
285
|
+
for (int i = 0; i < count; i++) {
|
|
286
|
+
auto telemVariable = this->GetTelemetryVarByIndex(env, i);
|
|
287
|
+
if (telemVariable.IsObject() && telemVariable.Has("name")) {
|
|
288
|
+
telemVars.Set(telemVariable.Get("name"), telemVariable);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return telemVars;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Helpers
|
|
296
|
+
Napi::Value iRacingSdkNode::__GetTelemetryTypes(const Napi::CallbackInfo &info)
|
|
297
|
+
{
|
|
298
|
+
auto env = info.Env();
|
|
299
|
+
auto result = Napi::Object::New(env);
|
|
300
|
+
|
|
301
|
+
const int count = irsdk_getHeader()->numVars;
|
|
302
|
+
const irsdk_varHeader *varHeader;
|
|
303
|
+
for (int i = 0; i < count; i++) {
|
|
304
|
+
varHeader = irsdk_getVarHeaderEntry(i);
|
|
305
|
+
result.Set(varHeader->name, Napi::Number::New(env, varHeader->type));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
// ---------------------------
|
|
313
|
+
// Helper functions
|
|
314
|
+
// ---------------------------
|
|
315
|
+
bool iRacingSdkNode::GetTelemetryBool(int entry, int index)
|
|
316
|
+
{
|
|
317
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
318
|
+
return *(reinterpret_cast<bool const *>(_data + headerVar->offset) + index);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
int iRacingSdkNode::GetTelemetryInt(int entry, int index)
|
|
322
|
+
{
|
|
323
|
+
// Each int is 4 bytes
|
|
324
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
325
|
+
return *(reinterpret_cast<int const *>(_data + headerVar->offset) + index * 4);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
float iRacingSdkNode::GetTelemetryFloat(int entry, int index)
|
|
329
|
+
{
|
|
330
|
+
// Each float is 4 bytes
|
|
331
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
332
|
+
return *(reinterpret_cast<float const *>(_data + headerVar->offset) + index * 4);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
double iRacingSdkNode::GetTelemetryDouble(int entry, int index)
|
|
336
|
+
{
|
|
337
|
+
// Each double is 8 bytes
|
|
338
|
+
const irsdk_varHeader *headerVar = irsdk_getVarHeaderEntry(entry);
|
|
339
|
+
return *(reinterpret_cast<double const *>(_data + headerVar->offset) + index * 8);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index)
|
|
343
|
+
{
|
|
344
|
+
auto headerVar = irsdk_getVarHeaderEntry(index);
|
|
345
|
+
auto telemVar = Napi::Object::New(env);
|
|
346
|
+
|
|
347
|
+
// Create entry object
|
|
348
|
+
telemVar.Set("countAsTime", headerVar->countAsTime);
|
|
349
|
+
telemVar.Set("length", headerVar->count);
|
|
350
|
+
telemVar.Set("name", headerVar->name);
|
|
351
|
+
telemVar.Set("description", headerVar->desc);
|
|
352
|
+
telemVar.Set("unit", headerVar->unit);
|
|
353
|
+
telemVar.Set("varType", headerVar->type);
|
|
354
|
+
|
|
355
|
+
int dataSize = headerVar->count * irsdk_VarTypeBytes[headerVar->type];
|
|
356
|
+
auto entryVal = Napi::ArrayBuffer::New(env, dataSize);
|
|
357
|
+
memcpy(entryVal.Data(), this->_data + headerVar->offset, dataSize);
|
|
358
|
+
|
|
359
|
+
telemVar.Set("value", entryVal);
|
|
360
|
+
return telemVar;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName)
|
|
364
|
+
{
|
|
365
|
+
int varIndex = irsdk_varNameToIndex(varName);
|
|
366
|
+
return this->GetTelemetryVarByIndex(env, varIndex);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
|
|
370
|
+
{
|
|
371
|
+
iRacingSdkNode::Init(env, exports);
|
|
372
|
+
return exports;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll);
|
package/src/irsdk_node.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#ifndef IRSDK_NODE_H
|
|
2
|
+
#define IRSDK_NODE_H
|
|
3
|
+
|
|
4
|
+
#include <napi.h>
|
|
5
|
+
#include "../lib/irsdk_defines.h"
|
|
6
|
+
#include "../lib/irsdk_client.h"
|
|
7
|
+
|
|
8
|
+
class iRacingSdkNode : public Napi::ObjectWrap<iRacingSdkNode>
|
|
9
|
+
{
|
|
10
|
+
public:
|
|
11
|
+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
12
|
+
iRacingSdkNode(const Napi::CallbackInfo& info);
|
|
13
|
+
|
|
14
|
+
private:
|
|
15
|
+
// Properties
|
|
16
|
+
Napi::Value GetCurrSessionDataVersion(const Napi::CallbackInfo &info);
|
|
17
|
+
Napi::Value GetEnableLogging(const Napi::CallbackInfo &info);
|
|
18
|
+
void SetEnableLogging(const Napi::CallbackInfo &info, const Napi::Value &value);
|
|
19
|
+
|
|
20
|
+
// Methods
|
|
21
|
+
// Control
|
|
22
|
+
Napi::Value StartSdk(const Napi::CallbackInfo &info);
|
|
23
|
+
Napi::Value StopSdk(const Napi::CallbackInfo &info);
|
|
24
|
+
Napi::Value WaitForData(const Napi::CallbackInfo &info);
|
|
25
|
+
Napi::Value BroadcastMessage(const Napi::CallbackInfo &info);
|
|
26
|
+
// Getters
|
|
27
|
+
Napi::Value IsRunning(const Napi::CallbackInfo &info);
|
|
28
|
+
Napi::Value GetSessionVersionNum(const Napi::CallbackInfo &info);
|
|
29
|
+
Napi::Value GetSessionData(const Napi::CallbackInfo &info);
|
|
30
|
+
Napi::Value GetTelemetryData(const Napi::CallbackInfo &info);
|
|
31
|
+
// Helpers
|
|
32
|
+
Napi::Value __GetTelemetryTypes(const Napi::CallbackInfo &info);
|
|
33
|
+
Napi::Value GetTelemetryVar(const Napi::CallbackInfo &info);
|
|
34
|
+
|
|
35
|
+
bool iRacingSdkNode::GetTelemetryBool(int entry, int index);
|
|
36
|
+
int iRacingSdkNode::GetTelemetryInt(int entry, int index);
|
|
37
|
+
float iRacingSdkNode::GetTelemetryFloat(int entry, int index);
|
|
38
|
+
double iRacingSdkNode::GetTelemetryDouble(int entry, int index);
|
|
39
|
+
Napi::Object iRacingSdkNode::GetTelemetryVarByIndex(const Napi::Env env, int index);
|
|
40
|
+
Napi::Object iRacingSdkNode::GetTelemetryVar(const Napi::Env env, const char *varName);
|
|
41
|
+
|
|
42
|
+
bool _loggingEnabled;
|
|
43
|
+
char* _data;
|
|
44
|
+
int _bufLineLen;
|
|
45
|
+
int _sessionStatusID;
|
|
46
|
+
int _lastSessionCt;
|
|
47
|
+
const char* _sessionData;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
#endif
|