@irsdk-node/native 5.2.2 → 5.3.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/LICENSE +21 -0
- package/binding.gyp +2 -2
- package/dist/types/INativeSDK.d.ts +2 -2
- package/lib/{irsdk_client.cpp → irsdk/irsdk_client.cpp} +3 -3
- package/lib/{irsdk_diskclient.cpp → irsdk/irsdk_diskclient.cpp} +3 -3
- package/lib/{irsdk_utils.cpp → irsdk/irsdk_utils.cpp} +1 -1
- package/lib/irsdk_node.cpp +390 -403
- package/lib/irsdk_node.h +95 -90
- package/lib/logger.cpp +39 -35
- package/lib/logger.h +50 -53
- package/lib/root.cpp +2 -2
- package/package.json +5 -3
- package/prebuilds/win32-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/LICENSE.md +0 -9
- /package/lib/{irsdk_client.h → irsdk/irsdk_client.h} +0 -0
- /package/lib/{irsdk_defines.h → irsdk/irsdk_defines.h} +0 -0
- /package/lib/{irsdk_diskclient.h → irsdk/irsdk_diskclient.h} +0 -0
- /package/lib/{yaml_parser.cpp → irsdk/yaml_parser.cpp} +0 -0
- /package/lib/{yaml_parser.h → irsdk/yaml_parser.h} +0 -0
package/lib/irsdk_node.h
CHANGED
|
@@ -4,103 +4,108 @@
|
|
|
4
4
|
#include "./logger.h"
|
|
5
5
|
#include <napi.h>
|
|
6
6
|
|
|
7
|
+
namespace irsdk_node
|
|
8
|
+
{
|
|
9
|
+
|
|
7
10
|
static const int K_DEFAULT_TIMEOUT_MS = 16;
|
|
8
11
|
|
|
9
12
|
class iRacingSdkNode : public Napi::ObjectWrap<iRacingSdkNode>
|
|
10
13
|
{
|
|
11
14
|
public:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
15
|
+
static Napi::Object Init(Napi::Env aEnv, Napi::Object aExports);
|
|
16
|
+
iRacingSdkNode(const Napi::CallbackInfo& aInfo);
|
|
17
|
+
|
|
18
|
+
// Main API ---------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
/// @brief Returns true if the SDK is currently active and connected to a
|
|
21
|
+
/// session, ie, the data buffer is not null and the SDK returns connected.
|
|
22
|
+
/// This means that the user is actively in an iRacing session.
|
|
23
|
+
///
|
|
24
|
+
/// @return If there is an active connection to the SDK.
|
|
25
|
+
bool isConnected() const;
|
|
26
|
+
|
|
27
|
+
/// @brief Triggers closing the SDK memory file, also resetting any cached
|
|
28
|
+
/// internal instance data.
|
|
29
|
+
void shutdown();
|
|
30
|
+
|
|
31
|
+
/// @brief Initializes the SDK, attempting to open the memory file containing
|
|
32
|
+
/// the SDK data. This occurs implicitly during the main data processing loop.
|
|
33
|
+
///
|
|
34
|
+
/// @return True if the SDK memory file was opened successfully.
|
|
35
|
+
bool startup();
|
|
36
|
+
|
|
37
|
+
/// @brief Main SDK data fetching loop tick. Will sleep for the given timeout
|
|
38
|
+
/// if no data is available, then attempt to pull data again.
|
|
39
|
+
///
|
|
40
|
+
/// @param aTimeoutMs The amount of time to wait, in MS.
|
|
41
|
+
/// @return True if data is ready and available, false if not.
|
|
42
|
+
bool waitForData(int aTimeoutMs = K_DEFAULT_TIMEOUT_MS);
|
|
43
|
+
|
|
44
|
+
/// @brief If connected, will return the entire session session string.
|
|
45
|
+
/// @return The YAML session string, in full.
|
|
46
|
+
const char* getSessionStr();
|
|
47
|
+
|
|
48
|
+
// Helper utils -----------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
/// @brief Gets the current session info version number directly from the SDK.
|
|
51
|
+
/// This value increments every time the session info string changes.
|
|
52
|
+
///
|
|
53
|
+
/// (see irsdk_getSessionInfoStrUpdate() in irsdk_defines.h)
|
|
54
|
+
///
|
|
55
|
+
/// @return The current session info version.
|
|
56
|
+
inline int getSessionInfoStrCount();
|
|
57
|
+
|
|
58
|
+
/// @brief Checks the current SDK session info string version vs. this
|
|
59
|
+
/// class instances session info string version.
|
|
60
|
+
///
|
|
61
|
+
/// @return True if the session info string versions do not match.
|
|
62
|
+
inline bool wasSessionStrUpdated();
|
|
60
63
|
|
|
61
64
|
private:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
65
|
+
// Properties
|
|
66
|
+
Napi::Value _napi_prop_getCurrSessionDataVer(const Napi::CallbackInfo& aInfo);
|
|
67
|
+
/** @deprecated in favor of iRacingSdkNode::_napi_prop_getLogLevel */
|
|
68
|
+
Napi::Value _napi_prop_getEnableLogging(const Napi::CallbackInfo& aInfo);
|
|
69
|
+
/** @deprecated in favor of iRacingSdkNode::_napi_prop_setLogLevel */
|
|
70
|
+
void _napi_prop_setEnableLogging(const Napi::CallbackInfo& aInfo, const Napi::Value& aValue);
|
|
71
|
+
Napi::Value _napi_prop_getLogLevel(const Napi::CallbackInfo& aInfo);
|
|
72
|
+
void _napi_prop_setLogLevel(const Napi::CallbackInfo& aInfo, const Napi::Value& aValue);
|
|
73
|
+
Napi::Value _napi_prop_getIsMocked(const Napi::CallbackInfo& aInfo);
|
|
74
|
+
|
|
75
|
+
// Methods
|
|
76
|
+
// Control
|
|
77
|
+
Napi::Value _napi_startSdk(const Napi::CallbackInfo& aInfo);
|
|
78
|
+
Napi::Value _napi_stopSdk(const Napi::CallbackInfo& aInfo);
|
|
79
|
+
Napi::Value _napi_waitForData(const Napi::CallbackInfo& aInfo);
|
|
80
|
+
Napi::Value _napi_broadcastMessage(const Napi::CallbackInfo& aInfo);
|
|
81
|
+
// Getters
|
|
82
|
+
Napi::Value _napi_isRunning(const Napi::CallbackInfo& aInfo);
|
|
83
|
+
Napi::Value _napi_getSessionVersionNum(const Napi::CallbackInfo& aInfo);
|
|
84
|
+
Napi::Value _napi_getSessionConnectionID(const Napi::CallbackInfo& aInfo);
|
|
85
|
+
Napi::Value _napi_getSessionData(const Napi::CallbackInfo& aInfo);
|
|
86
|
+
Napi::Value _napi_getTelemetryData(const Napi::CallbackInfo& aInfo);
|
|
87
|
+
Napi::Value _napi_getTelemetryTypes(const Napi::CallbackInfo& aInfo);
|
|
88
|
+
Napi::Value _napi_getTelemetryVar(const Napi::CallbackInfo& aInfo);
|
|
89
|
+
|
|
90
|
+
// Helpers
|
|
91
|
+
Napi::Object _getTelemetryVarByName(const Napi::Env aEnv, const char* aVarName);
|
|
92
|
+
Napi::Object _getTelemetryVarByIndex(const Napi::Env aEnv, int aIndex);
|
|
93
|
+
bool _getTelemetryBool(int aEntry, int aIndex);
|
|
94
|
+
int _getTelemetryInt(int aEntry, int aIndex);
|
|
95
|
+
float _getTelemetryFloat(int aEntry, int aIndex);
|
|
96
|
+
double _getTelemetryDouble(int aEntry, int aIndex);
|
|
97
|
+
|
|
98
|
+
/// @brief Resets the current session data / session data status count.
|
|
99
|
+
void _resetData();
|
|
100
|
+
|
|
101
|
+
char* _data;
|
|
102
|
+
int _bufLineLen;
|
|
103
|
+
int _sessionStatusID;
|
|
104
|
+
int _lastSessionCt;
|
|
105
|
+
const char* _sessionData;
|
|
106
|
+
Logger _logger;
|
|
104
107
|
};
|
|
105
108
|
|
|
109
|
+
} // namespace irsdk_node
|
|
110
|
+
|
|
106
111
|
#endif
|
package/lib/logger.cpp
CHANGED
|
@@ -7,62 +7,66 @@
|
|
|
7
7
|
|
|
8
8
|
using namespace irsdk_node;
|
|
9
9
|
|
|
10
|
-
static std::string makeFormatStr(LogLevel aLevel, const char
|
|
10
|
+
static std::string makeFormatStr(LogLevel aLevel, const char* aFormat)
|
|
11
11
|
{
|
|
12
|
-
|
|
12
|
+
std::string str;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
str += "(irsdk-node)(";
|
|
15
|
+
str += Logger::GetLabelForLevel(aLevel);
|
|
16
|
+
str += ") ";
|
|
17
|
+
str += aFormat;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
return str;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
void Logger::info(const char
|
|
22
|
+
void Logger::info(const char* aFormat, ...) const
|
|
23
23
|
{
|
|
24
|
-
|
|
24
|
+
if (logLevel < LogLevel_Info)
|
|
25
|
+
return;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
auto formatStr = makeFormatStr(LogLevel_Info, aFormat);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
va_list args;
|
|
30
|
+
va_start(args, aFormat);
|
|
31
|
+
vprintf(formatStr.c_str(), args);
|
|
32
|
+
va_end(args);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
void Logger::warn(const char
|
|
35
|
+
void Logger::warn(const char* aFormat, ...) const
|
|
35
36
|
{
|
|
36
|
-
|
|
37
|
+
if (logLevel < LogLevel_Warn)
|
|
38
|
+
return;
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
auto formatStr = makeFormatStr(LogLevel_Warn, aFormat);
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
va_list args;
|
|
43
|
+
va_start(args, aFormat);
|
|
44
|
+
vprintf(formatStr.c_str(), args);
|
|
45
|
+
va_end(args);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
void Logger::error(const char
|
|
48
|
+
void Logger::error(const char* aFormat, ...) const
|
|
47
49
|
{
|
|
48
|
-
|
|
50
|
+
if (logLevel < LogLevel_Error)
|
|
51
|
+
return;
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
auto formatStr = makeFormatStr(LogLevel_Error, aFormat);
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
va_list args;
|
|
56
|
+
va_start(args, aFormat);
|
|
57
|
+
vprintf(formatStr.c_str(), args);
|
|
58
|
+
va_end(args);
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
void Logger::debug(const char
|
|
61
|
+
void Logger::debug(const char* aFormat, ...) const
|
|
59
62
|
{
|
|
60
|
-
|
|
63
|
+
if (logLevel < LogLevel_Debug)
|
|
64
|
+
return;
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
auto formatStr = makeFormatStr(LogLevel_Debug, aFormat);
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
va_list args;
|
|
69
|
+
va_start(args, aFormat);
|
|
70
|
+
vprintf(formatStr.c_str(), args);
|
|
71
|
+
va_end(args);
|
|
68
72
|
}
|
package/lib/logger.h
CHANGED
|
@@ -2,56 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
namespace irsdk_node
|
|
4
4
|
{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
}
|
|
5
|
+
|
|
6
|
+
static const char* K_LOGLEVEL_LABEL_INFO = "INFO";
|
|
7
|
+
static const char* K_LOGLEVEL_LABEL_WARN = "WARN";
|
|
8
|
+
static const char* K_LOGLEVEL_LABEL_ERROR = "ERROR";
|
|
9
|
+
static const char* K_LOGLEVEL_LABEL_DEBUG = "DEBUG";
|
|
10
|
+
static const char* K_LOGLEVEL_LABEL_NONE = "";
|
|
11
|
+
|
|
12
|
+
enum LogLevel
|
|
13
|
+
{
|
|
14
|
+
LogLevel_None = 0,
|
|
15
|
+
LogLevel_Error,
|
|
16
|
+
LogLevel_Warn,
|
|
17
|
+
LogLevel_Info,
|
|
18
|
+
LogLevel_Debug,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
class Logger
|
|
22
|
+
{
|
|
23
|
+
public:
|
|
24
|
+
inline Logger(LogLevel aLogLevel)
|
|
25
|
+
: logLevel(aLogLevel)
|
|
26
|
+
{ }
|
|
27
|
+
|
|
28
|
+
LogLevel logLevel;
|
|
29
|
+
|
|
30
|
+
void info(const char* aFormat, ...) const;
|
|
31
|
+
void warn(const char* aFormat, ...) const;
|
|
32
|
+
void error(const char* aFormat, ...) const;
|
|
33
|
+
void debug(const char* aFormat, ...) const;
|
|
34
|
+
|
|
35
|
+
inline static const char* GetLabelForLevel(LogLevel aLevel)
|
|
36
|
+
{
|
|
37
|
+
switch (aLevel) {
|
|
38
|
+
case LogLevel_Error:
|
|
39
|
+
return K_LOGLEVEL_LABEL_ERROR;
|
|
40
|
+
case LogLevel_Warn:
|
|
41
|
+
return K_LOGLEVEL_LABEL_WARN;
|
|
42
|
+
case LogLevel_Info:
|
|
43
|
+
return K_LOGLEVEL_LABEL_INFO;
|
|
44
|
+
case LogLevel_Debug:
|
|
45
|
+
return K_LOGLEVEL_LABEL_DEBUG;
|
|
46
|
+
default:
|
|
47
|
+
return K_LOGLEVEL_LABEL_NONE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return K_LOGLEVEL_LABEL_NONE;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace irsdk_node
|
package/lib/root.cpp
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
Napi::Object registerBindings(Napi::Env aEnv, Napi::Object aExports)
|
|
5
5
|
{
|
|
6
|
-
|
|
6
|
+
irsdk_node::iRacingSdkNode::Init(aEnv, aExports);
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
return aExports;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
NODE_API_MODULE(NODE_GYP_MODULE_NAME, registerBindings);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irsdk-node/native",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"author": "Matt Bengston <bengsfort@gmail.com> (https://bengsfort.dev/)",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"email": "bengsfort@gmail.com",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"./prebuilds",
|
|
18
18
|
"./scripts",
|
|
19
19
|
"./binding.gyp",
|
|
20
|
-
"./README.md"
|
|
20
|
+
"./README.md",
|
|
21
|
+
"./LICENSE"
|
|
21
22
|
],
|
|
22
23
|
"type": "module",
|
|
23
24
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
"watch:ts": "node esbuild.js --watch",
|
|
64
65
|
"watch:types": "tsc --watch --emitDeclarationOnly",
|
|
65
66
|
"lint": "eslint",
|
|
66
|
-
"check-types": "tsc --noEmit"
|
|
67
|
+
"check-types": "tsc --noEmit",
|
|
68
|
+
"format:cpp": "clang-format --sort-includes -i --style=file:.clang-format --verbose lib/*.cpp lib/*.h"
|
|
67
69
|
}
|
|
68
70
|
}
|
|
Binary file
|
|
Binary file
|
package/LICENSE.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Matthew Bengston
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|