@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.
Files changed (56) hide show
  1. package/README.md +46 -0
  2. package/binding.gyp +19 -0
  3. package/build/Debug/irsdk_node.exp +0 -0
  4. package/build/Debug/irsdk_node.lib +0 -0
  5. package/build/Debug/irsdk_node.node +0 -0
  6. package/build/Debug/irsdk_node.pdb +0 -0
  7. package/build/Debug/obj/irsdk_node/irsdk_node.node.recipe +11 -0
  8. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  9. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  10. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  11. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +2 -0
  12. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/irsdk_node.write.1u.tlog +0 -0
  13. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  14. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  15. package/build/Debug/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  16. package/build/Debug/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  17. package/build/Debug/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  18. package/build/Debug/obj/irsdk_node/src/irsdk_node.obj +0 -0
  19. package/build/Debug/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  20. package/build/Release/irsdk_node.exp +0 -0
  21. package/build/Release/irsdk_node.iobj +0 -0
  22. package/build/Release/irsdk_node.ipdb +0 -0
  23. package/build/Release/irsdk_node.lib +0 -0
  24. package/build/Release/irsdk_node.node +0 -0
  25. package/build/Release/irsdk_node.pdb +0 -0
  26. package/build/Release/obj/irsdk_node/irsdk_node.node.recipe +11 -0
  27. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.command.1.tlog +0 -0
  28. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.read.1.tlog +0 -0
  29. package/build/Release/obj/irsdk_node/irsdk_node.tlog/CL.write.1.tlog +0 -0
  30. package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.lastbuildstate +2 -0
  31. package/build/Release/obj/irsdk_node/irsdk_node.tlog/irsdk_node.write.1u.tlog +0 -0
  32. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.command.1.tlog +0 -0
  33. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.read.1.tlog +0 -0
  34. package/build/Release/obj/irsdk_node/irsdk_node.tlog/link.write.1.tlog +0 -0
  35. package/build/Release/obj/irsdk_node/lib/irsdk_utils.obj +0 -0
  36. package/build/Release/obj/irsdk_node/lib/yaml_parser.obj +0 -0
  37. package/build/Release/obj/irsdk_node/src/irsdk_node.obj +0 -0
  38. package/build/Release/obj/irsdk_node/win_delay_load_hook.obj +0 -0
  39. package/build/binding.sln +19 -0
  40. package/build/config.gypi +88 -0
  41. package/build/irsdk_node.vcxproj +155 -0
  42. package/build/irsdk_node.vcxproj.filters +73 -0
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.js +8 -0
  45. package/lib/irsdk_client.cpp +495 -0
  46. package/lib/irsdk_client.h +139 -0
  47. package/lib/irsdk_defines.h +528 -0
  48. package/lib/irsdk_utils.cpp +377 -0
  49. package/lib/yaml_parser.cpp +176 -0
  50. package/lib/yaml_parser.h +34 -0
  51. package/package.json +52 -0
  52. package/scripts/generate-var-types.js +71 -0
  53. package/src/index.d.ts +117 -0
  54. package/src/index.js +5 -0
  55. package/src/irsdk_node.cc +375 -0
  56. package/src/irsdk_node.h +50 -0
@@ -0,0 +1,377 @@
1
+ /*
2
+ Copyright (c) 2013, iRacing.com Motorsport Simulations, LLC.
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
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
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #define MIN_WIN_VER 0x0501
29
+
30
+ #ifndef WINVER
31
+ # define WINVER MIN_WIN_VER
32
+ #endif
33
+
34
+ #ifndef _WIN32_WINNT
35
+ # define _WIN32_WINNT MIN_WIN_VER
36
+ #endif
37
+
38
+ #include <windows.h>
39
+ #include <stdio.h>
40
+ #include <time.h>
41
+ #include <limits.h>
42
+
43
+ #ifdef _MSC_VER
44
+ #include <crtdbg.h>
45
+ #endif
46
+
47
+ #include "irsdk_defines.h"
48
+
49
+ // for timeBeginPeriod()
50
+ #pragma comment(lib, "Winmm")
51
+ // for RegisterWindowMessage() and SendMessage()
52
+ #pragma comment(lib, "User32")
53
+
54
+ // Local memory
55
+
56
+ static HANDLE hDataValidEvent = NULL;
57
+ static HANDLE hMemMapFile = NULL;
58
+
59
+ static const char *pSharedMem = NULL;
60
+ static const irsdk_header *pHeader = NULL;
61
+
62
+ static int lastTickCount = INT_MAX;
63
+ static bool isInitialized = false;
64
+
65
+ static const double timeout = 30.0; // timeout after 30 seconds with no communication
66
+ static time_t lastValidTime = 0;
67
+
68
+ // Function Implementations
69
+
70
+ bool irsdk_startup()
71
+ {
72
+ if(!hMemMapFile)
73
+ {
74
+ hMemMapFile = OpenFileMapping( FILE_MAP_READ, FALSE, IRSDK_MEMMAPFILENAME);
75
+ lastTickCount = INT_MAX;
76
+ }
77
+
78
+ if(hMemMapFile)
79
+ {
80
+ if(!pSharedMem)
81
+ {
82
+ pSharedMem = (const char *)MapViewOfFile(hMemMapFile, FILE_MAP_READ, 0, 0, 0);
83
+ pHeader = (irsdk_header *)pSharedMem;
84
+ lastTickCount = INT_MAX;
85
+ }
86
+
87
+ if(pSharedMem)
88
+ {
89
+ if(!hDataValidEvent)
90
+ {
91
+ hDataValidEvent = OpenEvent(SYNCHRONIZE, false, IRSDK_DATAVALIDEVENTNAME);
92
+ lastTickCount = INT_MAX;
93
+ }
94
+
95
+ if(hDataValidEvent)
96
+ {
97
+ isInitialized = true;
98
+ return isInitialized;
99
+ }
100
+ //else printf("Error opening event: %d\n", GetLastError());
101
+ }
102
+ //else printf("Error mapping file: %d\n", GetLastError());
103
+ }
104
+ //else printf("Error opening file: %d\n", GetLastError());
105
+
106
+ isInitialized = false;
107
+ return isInitialized;
108
+ }
109
+
110
+ void irsdk_shutdown()
111
+ {
112
+ if(hDataValidEvent)
113
+ CloseHandle(hDataValidEvent);
114
+
115
+ if(pSharedMem)
116
+ UnmapViewOfFile(pSharedMem);
117
+
118
+ if(hMemMapFile)
119
+ CloseHandle(hMemMapFile);
120
+
121
+ hDataValidEvent = NULL;
122
+ pSharedMem = NULL;
123
+ pHeader = NULL;
124
+ hMemMapFile = NULL;
125
+
126
+ isInitialized = false;
127
+ lastTickCount = INT_MAX;
128
+ }
129
+
130
+ bool irsdk_getNewData(char *data)
131
+ {
132
+ if(isInitialized || irsdk_startup())
133
+ {
134
+ #ifdef _MSC_VER
135
+ _ASSERTE(NULL != pHeader);
136
+ #endif
137
+
138
+ // if sim is not active, then no new data
139
+ if(!(pHeader->status & irsdk_stConnected))
140
+ {
141
+ lastTickCount = INT_MAX;
142
+ return false;
143
+ }
144
+
145
+ int latest = 0;
146
+ for(int i=1; i<pHeader->numBuf; i++)
147
+ if(pHeader->varBuf[latest].tickCount < pHeader->varBuf[i].tickCount)
148
+ latest = i;
149
+
150
+ // if newer than last recieved, than report new data
151
+ if(lastTickCount < pHeader->varBuf[latest].tickCount)
152
+ {
153
+ // if asked to retrieve the data
154
+ if(data)
155
+ {
156
+ // try twice to get the data out
157
+ for(int count = 0; count < 2; count++)
158
+ {
159
+ int curTickCount = pHeader->varBuf[latest].tickCount;
160
+ memcpy(data, pSharedMem + pHeader->varBuf[latest].bufOffset, pHeader->bufLen);
161
+ if(curTickCount == pHeader->varBuf[latest].tickCount)
162
+ {
163
+ lastTickCount = curTickCount;
164
+ lastValidTime = time(NULL);
165
+ return true;
166
+ }
167
+ }
168
+ // if here, the data changed out from under us.
169
+ return false;
170
+ }
171
+ else
172
+ {
173
+ lastTickCount = pHeader->varBuf[latest].tickCount;
174
+ lastValidTime = time(NULL);
175
+ return true;
176
+ }
177
+ }
178
+ // if older than last recieved, than reset, we probably disconnected
179
+ else if(lastTickCount > pHeader->varBuf[latest].tickCount)
180
+ {
181
+ lastTickCount = pHeader->varBuf[latest].tickCount;
182
+ return false;
183
+ }
184
+ // else the same, and nothing changed this tick
185
+ }
186
+
187
+ return false;
188
+ }
189
+
190
+
191
+ bool irsdk_waitForDataReady(int timeOut, char *data)
192
+ {
193
+ #ifdef _MSC_VER
194
+ _ASSERTE(timeOut >= 0);
195
+ #endif
196
+
197
+ if(isInitialized || irsdk_startup())
198
+ {
199
+ // just to be sure, check before we sleep
200
+ if(irsdk_getNewData(data))
201
+ return true;
202
+
203
+ // sleep till signaled
204
+ WaitForSingleObject(hDataValidEvent, timeOut);
205
+
206
+ // we woke up, so check for data
207
+ if(irsdk_getNewData(data))
208
+ return true;
209
+ else
210
+ return false;
211
+ }
212
+
213
+ // sleep if error
214
+ if(timeOut > 0)
215
+ Sleep(timeOut);
216
+
217
+ return false;
218
+ }
219
+
220
+ bool irsdk_isConnected()
221
+ {
222
+ if(isInitialized)
223
+ {
224
+ int elapsed = (int)difftime(time(NULL), lastValidTime);
225
+ return (pHeader->status & irsdk_stConnected) > 0 && elapsed < timeout;
226
+ }
227
+
228
+ return false;
229
+ }
230
+
231
+ const irsdk_header *irsdk_getHeader()
232
+ {
233
+ if(isInitialized)
234
+ {
235
+ return pHeader;
236
+ }
237
+
238
+ return NULL;
239
+ }
240
+
241
+ // direct access to the data buffer
242
+ // Warnign! This buffer is volitile so read it out fast!
243
+ // Use the cached copy from irsdk_waitForDataReady() or irsdk_getNewData() instead
244
+ const char *irsdk_getData(int index)
245
+ {
246
+ if(isInitialized)
247
+ {
248
+ return pSharedMem + pHeader->varBuf[index].bufOffset;
249
+ }
250
+
251
+ return NULL;
252
+ }
253
+
254
+ const char *irsdk_getSessionInfoStr()
255
+ {
256
+ if(isInitialized)
257
+ {
258
+ return pSharedMem + pHeader->sessionInfoOffset;
259
+ }
260
+ return NULL;
261
+ }
262
+
263
+ int irsdk_getSessionInfoStrUpdate()
264
+ {
265
+ if(isInitialized)
266
+ {
267
+ return pHeader->sessionInfoUpdate;
268
+ }
269
+ return -1;
270
+ }
271
+
272
+ const irsdk_varHeader *irsdk_getVarHeaderPtr()
273
+ {
274
+ if(isInitialized)
275
+ {
276
+ return ((irsdk_varHeader*)(pSharedMem + pHeader->varHeaderOffset));
277
+ }
278
+ return NULL;
279
+ }
280
+
281
+ const irsdk_varHeader *irsdk_getVarHeaderEntry(int index)
282
+ {
283
+ if(isInitialized)
284
+ {
285
+ if(index >= 0 && index < pHeader->numVars)
286
+ {
287
+ return &((irsdk_varHeader*)(pSharedMem + pHeader->varHeaderOffset))[index];
288
+ }
289
+ }
290
+ return NULL;
291
+ }
292
+
293
+ // Note: this is a linear search, so cache the results
294
+ int irsdk_varNameToIndex(const char *name)
295
+ {
296
+ const irsdk_varHeader *pVar;
297
+
298
+ if(name)
299
+ {
300
+ for(int index=0; index<pHeader->numVars; index++)
301
+ {
302
+ pVar = irsdk_getVarHeaderEntry(index);
303
+ if(pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
304
+ {
305
+ return index;
306
+ }
307
+ }
308
+ }
309
+
310
+ return -1;
311
+ }
312
+
313
+ int irsdk_varNameToOffset(const char *name)
314
+ {
315
+ const irsdk_varHeader *pVar;
316
+
317
+ if(name)
318
+ {
319
+ for(int index=0; index<pHeader->numVars; index++)
320
+ {
321
+ pVar = irsdk_getVarHeaderEntry(index);
322
+ if(pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
323
+ {
324
+ return pVar->offset;
325
+ }
326
+ }
327
+ }
328
+
329
+ return -1;
330
+ }
331
+
332
+ unsigned int irsdk_getBroadcastMsgID()
333
+ {
334
+ static unsigned int msgId = RegisterWindowMessage(IRSDK_BROADCASTMSGNAME);
335
+
336
+ return msgId;
337
+ }
338
+
339
+ void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, int var2, int var3)
340
+ {
341
+ irsdk_broadcastMsg(msg, var1, MAKELONG(var2, var3));
342
+ }
343
+
344
+ void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, float var2)
345
+ {
346
+ // multiply by 2^16-1 to move fractional part to the integer part
347
+ int real = (int)(var2 * 65536.0f);
348
+
349
+ irsdk_broadcastMsg(msg, var1, real);
350
+ }
351
+
352
+ void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, int var2)
353
+ {
354
+ static unsigned int msgId = irsdk_getBroadcastMsgID();
355
+
356
+ if(msgId && msg >= 0 && msg < irsdk_BroadcastLast)
357
+ {
358
+ SendNotifyMessage(HWND_BROADCAST, msgId, MAKELONG(msg, var1), var2);
359
+ }
360
+ }
361
+
362
+ int irsdk_padCarNum(int num, int zero)
363
+ {
364
+ int retVal = num;
365
+ int numPlace = 1;
366
+ if(num > 99)
367
+ numPlace = 3;
368
+ else if(num > 9)
369
+ numPlace = 2;
370
+ if(zero)
371
+ {
372
+ numPlace += zero;
373
+ retVal = num + 1000*numPlace;
374
+ }
375
+
376
+ return retVal;
377
+ }
@@ -0,0 +1,176 @@
1
+ /*
2
+ Copyright (c) 2013, iRacing.com Motorsport Simulations, LLC.
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
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
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdio.h>
29
+ #include <string.h>
30
+
31
+ enum yaml_state {
32
+ space,
33
+ key,
34
+ keysep,
35
+ value,
36
+ newline
37
+ };
38
+
39
+ // super simple YAML parser
40
+ bool parseYaml(const char *data, const char* path, const char **val, int *len)
41
+ {
42
+ if(data && path && val && len)
43
+ {
44
+ // make sure we set this to something
45
+ *val = NULL;
46
+ *len = 0;
47
+
48
+ int depth = 0;
49
+ yaml_state state = space;
50
+
51
+ const char *keystr = NULL;
52
+ int keylen = 0;
53
+
54
+ const char *valuestr = NULL;
55
+ int valuelen = 0;
56
+
57
+ const char *pathptr = path;
58
+ int pathdepth = 0;
59
+
60
+ while(*data)
61
+ {
62
+ switch(*data)
63
+ {
64
+ case ' ':
65
+ if(state == newline)
66
+ state = space;
67
+ if(state == space)
68
+ depth++;
69
+ else if(state == key)
70
+ keylen++;
71
+ else if(state == value)
72
+ valuelen++;
73
+ break;
74
+ case '-':
75
+ if(state == newline)
76
+ state = space;
77
+ if(state == space)
78
+ depth++;
79
+ else if(state == key)
80
+ keylen++;
81
+ else if(state == value)
82
+ valuelen++;
83
+ else if(state == keysep)
84
+ {
85
+ state = value;
86
+ valuestr = data;
87
+ valuelen = 1;
88
+ }
89
+ break;
90
+ case ':':
91
+ if(state == key)
92
+ {
93
+ state = keysep;
94
+ keylen++;
95
+ }
96
+ else if(state == keysep)
97
+ {
98
+ state = value;
99
+ valuestr = data;
100
+ }
101
+ else if(state == value)
102
+ valuelen++;
103
+ break;
104
+ case '\n':
105
+ case '\r':
106
+ if(state != newline)
107
+ {
108
+ if(depth < pathdepth)
109
+ {
110
+ return false;
111
+ }
112
+ else if(keylen && 0 == strncmp(keystr, pathptr, keylen))
113
+ {
114
+ bool found = true;
115
+ //do we need to test the value?
116
+ if(*(pathptr+keylen) == '{')
117
+ {
118
+ //search for closing brace
119
+ int pathvaluelen = keylen + 1;
120
+ while(*(pathptr+pathvaluelen) && *(pathptr+pathvaluelen) != '}')
121
+ pathvaluelen++;
122
+
123
+ if(valuelen == pathvaluelen - (keylen+1) && 0 == strncmp(valuestr, (pathptr+keylen+1), valuelen))
124
+ pathptr += valuelen + 2;
125
+ else
126
+ found = false;
127
+ }
128
+
129
+ if(found)
130
+ {
131
+ pathptr += keylen;
132
+ pathdepth = depth;
133
+
134
+ if(*pathptr == '\0')
135
+ {
136
+ *val = valuestr;
137
+ *len = valuelen;
138
+ return true;
139
+ }
140
+ }
141
+ }
142
+
143
+ depth = 0;
144
+ keylen = 0;
145
+ valuelen = 0;
146
+ }
147
+ state = newline;
148
+ break;
149
+ default:
150
+ if(state == space || state == newline)
151
+ {
152
+ state = key;
153
+ keystr = data;
154
+ keylen = 0; //redundant?
155
+ }
156
+ else if(state == keysep)
157
+ {
158
+ state = value;
159
+ valuestr = data;
160
+ valuelen = 0; //redundant?
161
+ }
162
+ if(state == key)
163
+ keylen++;
164
+ if(state == value)
165
+ valuelen++;
166
+ break;
167
+ }
168
+
169
+ // important, increment our pointer
170
+ data++;
171
+ }
172
+
173
+ }
174
+ return false;
175
+ }
176
+
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright (c) 2013, iRacing.com Motorsport Simulations, LLC.
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
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
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #ifndef YAML_PARSER_H
29
+ #define YAML_PARSER_H
30
+
31
+ // super simple YAML parser
32
+ bool parseYaml(const char *data, const char* path, const char **val, int *len);
33
+
34
+ #endif //YAML_PARSER_H
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@irsdk-node/native",
3
+ "version": "3.0.0",
4
+ "author": {
5
+ "name": "Matt Bengston",
6
+ "email": "bengsfort@gmail.com"
7
+ },
8
+ "engines": {
9
+ "node": ">=16"
10
+ },
11
+ "files": [
12
+ "package.json",
13
+ "./build",
14
+ "./dist",
15
+ "./lib",
16
+ "./src",
17
+ "./scripts",
18
+ "./binding.gyp",
19
+ "./README.md"
20
+ ],
21
+ "main": "./dist/index.js",
22
+ "types": "./src/index.d.ts",
23
+ "scripts": {
24
+ "clean": "node-gyp clean && rm -rf dist",
25
+ "build": "yarn run pre-build && concurrently \"yarn:build-ts\" \"yarn:build-cpp\"",
26
+ "pre-build": "node-gyp clean && node-gyp configure",
27
+ "build-ts": "tsc --build --force",
28
+ "build-cpp": "concurrently \"yarn:build-cpp-release\" \"yarn:build-cpp-debug\"",
29
+ "build-cpp-release": "node-gyp build",
30
+ "build-cpp-debug": "node-gyp configure && node-gyp build --debug",
31
+ "watch": "tsc --watch",
32
+ "lint": "eslint ./src --ext .ts",
33
+ "prepack": "yarn build",
34
+ "generate-types": "node ./scripts/generate-var-types.js"
35
+ },
36
+ "packageManager": "yarn@3.1.0",
37
+ "preferUnplugged": false,
38
+ "os": [
39
+ "win32"
40
+ ],
41
+ "dependencies": {
42
+ "@irsdk-node/types": "^3.0.0",
43
+ "bindings": "^1.5.0",
44
+ "node-addon-api": "*",
45
+ "node-gyp": "^8.4.1"
46
+ },
47
+ "devDependencies": {
48
+ "concurrently": "^7.0.0",
49
+ "node-notifier": "^10.0.0",
50
+ "typescript": "^4.5.2"
51
+ }
52
+ }
@@ -0,0 +1,71 @@
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
+ });