@irsdk-node/native 4.1.0 → 5.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/LICENSE.md +9 -0
- package/README.md +90 -21
- package/dist/cjs/index.cjs +9453 -0
- package/dist/esm/index.js +9440 -0
- package/dist/{INativeSDK.d.ts → types/INativeSDK.d.ts} +9 -0
- package/dist/{MockSdk.d.ts → types/MockSdk.d.ts} +2 -1
- package/dist/types/index.d.ts +4 -0
- package/lib/irsdk_client.cpp +94 -94
- package/lib/irsdk_client.h +23 -23
- package/lib/irsdk_defines.h +136 -82
- package/lib/irsdk_diskclient.cpp +997 -0
- package/lib/irsdk_diskclient.h +205 -0
- package/lib/irsdk_node.cc +1 -1
- package/lib/irsdk_utils.cpp +71 -71
- package/lib/yaml_parser.cpp +41 -41
- package/lib/yaml_parser.h +1 -1
- package/package.json +25 -27
- package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/dist/INativeSDK.js +0 -2
- package/dist/MockSdk.js +0 -70
- package/dist/mock-data/loader.js +0 -41
- package/dist/mock-data/session.json +0 -4305
- package/dist/mock-data/telemetry.json +0 -4986
- package/index.d.ts +0 -87
- package/index.js +0 -36
- /package/dist/{mock-data → types/mock-data}/loader.d.ts +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
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 IRSDKDISKCLIENT_H
|
|
29
|
+
#define IRSDKDISKCLIENT_H
|
|
30
|
+
|
|
31
|
+
// A C++ wrapper around the irsdk calls that takes care of reading a .ibt file
|
|
32
|
+
|
|
33
|
+
//****FixMe, rename to irsdkDiskReader
|
|
34
|
+
class irsdkDiskClient
|
|
35
|
+
{
|
|
36
|
+
public:
|
|
37
|
+
|
|
38
|
+
irsdkDiskClient();
|
|
39
|
+
irsdkDiskClient(const char *path);
|
|
40
|
+
~irsdkDiskClient() { closeFile(); }
|
|
41
|
+
|
|
42
|
+
bool isFileOpen() { return m_ibtFile != NULL; }
|
|
43
|
+
bool openFile(const char *path);
|
|
44
|
+
void closeFile();
|
|
45
|
+
|
|
46
|
+
// read next line out of file
|
|
47
|
+
bool getNextData(); //****Note, should be called readLine();
|
|
48
|
+
int getDataCount() { return m_diskSubHeader.sessionRecordCount; }
|
|
49
|
+
|
|
50
|
+
// return how many variables this .ibt file has in the header
|
|
51
|
+
int getNumVars();
|
|
52
|
+
|
|
53
|
+
int getVarIdx(const char *name);
|
|
54
|
+
|
|
55
|
+
// get info on the var
|
|
56
|
+
const char* getVarName(int idx);
|
|
57
|
+
const char* getVarDesc(int idx);
|
|
58
|
+
const char* getVarUnit(int idx);
|
|
59
|
+
|
|
60
|
+
// what is the base type of the data
|
|
61
|
+
irsdk_VarType getVarType(int idx);
|
|
62
|
+
irsdk_VarType getVarType(const char *name) { return getVarType(getVarIdx(name)); }
|
|
63
|
+
|
|
64
|
+
// how many elements in array, or 1 if not an array
|
|
65
|
+
int getVarCount(int idx);
|
|
66
|
+
int getVarCount(const char *name) { return getVarCount(getVarIdx(name)); }
|
|
67
|
+
|
|
68
|
+
// idx is the variables index, entry is the array offset, or 0 if not an array element
|
|
69
|
+
// will convert data to requested type
|
|
70
|
+
bool getVarBool(int idx, int entry = 0);
|
|
71
|
+
bool getVarBool(const char *name, int entry = 0) { return getVarBool(getVarIdx(name), entry); }
|
|
72
|
+
|
|
73
|
+
int getVarInt(int idx, int entry = 0);
|
|
74
|
+
int getVarInt(const char *name, int entry = 0) { return getVarInt(getVarIdx(name), entry); }
|
|
75
|
+
|
|
76
|
+
float getVarFloat(int idx, int entry = 0);
|
|
77
|
+
float getVarFloat(const char *name, int entry = 0) { return getVarFloat(getVarIdx(name), entry); }
|
|
78
|
+
|
|
79
|
+
double getVarDouble(int idx, int entry = 0);
|
|
80
|
+
double getVarDouble(const char *name, int entry = 0) { return getVarDouble(getVarIdx(name), entry); }
|
|
81
|
+
|
|
82
|
+
// 1 success, 0 failure, -n minimum buffer size
|
|
83
|
+
int getSessionStrVal(const char *path, char *val, int valLen);
|
|
84
|
+
// get the whole string
|
|
85
|
+
const char *getSessionStr() { return m_sessionInfoString; }
|
|
86
|
+
|
|
87
|
+
// we track session time and lap count in the disk sub header
|
|
88
|
+
time_t getSessionStartDate() { return m_diskSubHeader.sessionStartDate; }
|
|
89
|
+
double getSessionStartTime_s() { return m_diskSubHeader.sessionStartTime; }
|
|
90
|
+
double getSessionEndTime_s() { return m_diskSubHeader.sessionEndTime; }
|
|
91
|
+
int getSessionLapCount() { return m_diskSubHeader.sessionLapCount; }
|
|
92
|
+
|
|
93
|
+
long getFileSize() { return m_ibtFileSize; }
|
|
94
|
+
|
|
95
|
+
protected:
|
|
96
|
+
|
|
97
|
+
irsdk_header m_header;
|
|
98
|
+
irsdk_diskSubHeader m_diskSubHeader;
|
|
99
|
+
|
|
100
|
+
char *m_sessionInfoString;
|
|
101
|
+
irsdk_varHeader *m_varHeaders;
|
|
102
|
+
char *m_varBuf;
|
|
103
|
+
|
|
104
|
+
FILE *m_ibtFile;
|
|
105
|
+
long m_ibtFileSize;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
class irsdkDiskWriter
|
|
109
|
+
{
|
|
110
|
+
public:
|
|
111
|
+
|
|
112
|
+
irsdkDiskWriter();
|
|
113
|
+
irsdkDiskWriter(const char *path);
|
|
114
|
+
~irsdkDiskWriter() { closeFile(); }
|
|
115
|
+
|
|
116
|
+
bool isFileOpen() { return m_ibtFile != NULL; }
|
|
117
|
+
bool openFile(const char *path);
|
|
118
|
+
void closeFile();
|
|
119
|
+
|
|
120
|
+
int addNewVariable(const char *name, const char *desc, const char *unit, const irsdk_VarType type, int count = 1);
|
|
121
|
+
bool isHeaderFinalized() { return m_isHeaderFinalized; }
|
|
122
|
+
void finalizeHeader();
|
|
123
|
+
|
|
124
|
+
// write next line to file and clear buffers
|
|
125
|
+
void writeLine();
|
|
126
|
+
int getDataCount() { return m_diskSubHeader.sessionRecordCount; }
|
|
127
|
+
|
|
128
|
+
// return how many variables this .ibt file has in the header
|
|
129
|
+
int getNumVars();
|
|
130
|
+
|
|
131
|
+
int getVarIdx(const char *name);
|
|
132
|
+
|
|
133
|
+
// get info on the var
|
|
134
|
+
const char* getVarName(int idx);
|
|
135
|
+
const char* getVarDesc(int idx);
|
|
136
|
+
const char* getVarUnit(int idx);
|
|
137
|
+
|
|
138
|
+
// what is the base type of the data
|
|
139
|
+
irsdk_VarType getVarType(int idx);
|
|
140
|
+
irsdk_VarType getVarType(const char *name) { return getVarType(getVarIdx(name)); }
|
|
141
|
+
|
|
142
|
+
// how many elements in array, or 1 if not an array
|
|
143
|
+
int getVarCount(int idx);
|
|
144
|
+
int getVarCount(const char *name) { return getVarCount(getVarIdx(name)); }
|
|
145
|
+
|
|
146
|
+
// idx is the variables index, entry is the array offset, or 0 if not an array element
|
|
147
|
+
// will convert data to requested type
|
|
148
|
+
bool setVar(bool val, int idx, int entry = 0);
|
|
149
|
+
bool setVar(bool val, const char *name, int entry = 0) { return setVar(val, getVarIdx(name), entry); }
|
|
150
|
+
|
|
151
|
+
bool setVar(int val, int idx, int entry = 0);
|
|
152
|
+
bool setVar(int val, const char *name, int entry = 0) { return setVar(val, getVarIdx(name), entry); }
|
|
153
|
+
|
|
154
|
+
bool setVar(float val, int idx, int entry = 0);
|
|
155
|
+
bool setVar(float val, const char *name, int entry = 0) { return setVar(val, getVarIdx(name), entry); }
|
|
156
|
+
|
|
157
|
+
bool setVar(double val, int idx, int entry = 0);
|
|
158
|
+
bool setVar(double val, const char *name, int entry = 0) { return setVar(val, getVarIdx(name), entry); }
|
|
159
|
+
|
|
160
|
+
// get the whole string
|
|
161
|
+
char* getSessionStr() { return m_sessionInfoString; }
|
|
162
|
+
void setSessionStr(const char* str)
|
|
163
|
+
{
|
|
164
|
+
strncpy_s(m_sessionInfoString, str, MAX_SESSIONSTR_LEN);
|
|
165
|
+
m_sessionInfoString[MAX_SESSIONSTR_LEN-1] = '\0';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// we track session time and lap count in the disk sub header
|
|
169
|
+
time_t getSessionStartDate() { return m_diskSubHeader.sessionStartDate; }
|
|
170
|
+
void setSessionStartDate(const time_t date) { m_diskSubHeader.sessionStartDate = date; }
|
|
171
|
+
|
|
172
|
+
double getSessionStartTime_s() { return m_diskSubHeader.sessionStartTime; }
|
|
173
|
+
void setSessionStartTime_s(const double time) { m_diskSubHeader.sessionStartTime = time; }
|
|
174
|
+
|
|
175
|
+
double getSessionEndTime_s() { return m_diskSubHeader.sessionEndTime; }
|
|
176
|
+
void setSessionEndTime_s(const double time) { m_diskSubHeader.sessionEndTime = time; }
|
|
177
|
+
|
|
178
|
+
int getSessionLapCount() { return m_diskSubHeader.sessionLapCount; }
|
|
179
|
+
void setSessionLapCount(const int lap) { m_diskSubHeader.sessionLapCount = lap; }
|
|
180
|
+
|
|
181
|
+
int getTickRate() { return m_header.tickRate; }
|
|
182
|
+
void setTickRate(int rate) { m_header.tickRate = rate; }
|
|
183
|
+
|
|
184
|
+
protected:
|
|
185
|
+
|
|
186
|
+
void initialize();
|
|
187
|
+
|
|
188
|
+
irsdk_header m_header;
|
|
189
|
+
irsdk_diskSubHeader m_diskSubHeader;
|
|
190
|
+
int m_diskSubHeaderOffset;
|
|
191
|
+
bool m_isHeaderFinalized;
|
|
192
|
+
|
|
193
|
+
//****Note, for now static allocate our buffers
|
|
194
|
+
// could easily aquire these at creation time
|
|
195
|
+
const static int MAX_SESSIONSTR_LEN = 1048576;
|
|
196
|
+
const static int MAX_VAR_COUNT = 1000;
|
|
197
|
+
const static int MAX_VAR_BUF_SIZE = MAX_VAR_COUNT * 32;
|
|
198
|
+
|
|
199
|
+
char m_sessionInfoString[MAX_SESSIONSTR_LEN];
|
|
200
|
+
irsdk_varHeader m_varHeaders[MAX_VAR_COUNT];
|
|
201
|
+
char m_varBuf[MAX_VAR_BUF_SIZE];
|
|
202
|
+
|
|
203
|
+
FILE *m_ibtFile;
|
|
204
|
+
};
|
|
205
|
+
#endif // IRSDKDISKCLIENT_H
|
package/lib/irsdk_node.cc
CHANGED
|
@@ -227,7 +227,7 @@ Napi::Value iRacingSdkNode::BroadcastMessage(const Napi::CallbackInfo &info)
|
|
|
227
227
|
case irsdk_BroadcastPitCommand: // arg1 == irsdk_PitCommandMode
|
|
228
228
|
case irsdk_BroadcastFFBCommand: // arg1 == irsdk_FFBCommandMode
|
|
229
229
|
case irsdk_BroadcastReplaySearchSessionTime:
|
|
230
|
-
case
|
|
230
|
+
case irsdk_BroadcastReplaySetPlayPosition:
|
|
231
231
|
if (this->_loggingEnabled)
|
|
232
232
|
printf("BroadcastMessage(msgType: %d, arg1: %d, arg2: %f)\n", msgType, arg1, (float)arg2.FloatValue());
|
|
233
233
|
irsdk_broadcastMsg(msgType, arg1, (float)arg2.FloatValue());
|
package/lib/irsdk_utils.cpp
CHANGED
|
@@ -4,14 +4,14 @@ All rights reserved.
|
|
|
4
4
|
|
|
5
5
|
Redistribution and use in source and binary forms, with or without
|
|
6
6
|
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
15
|
|
|
16
16
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
17
17
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
@@ -56,8 +56,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
56
56
|
static HANDLE hDataValidEvent = NULL;
|
|
57
57
|
static HANDLE hMemMapFile = NULL;
|
|
58
58
|
|
|
59
|
-
static const char
|
|
60
|
-
static const irsdk_header
|
|
59
|
+
static const char* pSharedMem = NULL;
|
|
60
|
+
static const irsdk_header* pHeader = NULL;
|
|
61
61
|
|
|
62
62
|
static int lastTickCount = INT_MAX;
|
|
63
63
|
static bool isInitialized = false;
|
|
@@ -69,30 +69,30 @@ static time_t lastValidTime = 0;
|
|
|
69
69
|
|
|
70
70
|
bool irsdk_startup()
|
|
71
71
|
{
|
|
72
|
-
if(!hMemMapFile)
|
|
72
|
+
if (!hMemMapFile)
|
|
73
73
|
{
|
|
74
|
-
hMemMapFile = OpenFileMapping(
|
|
74
|
+
hMemMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, IRSDK_MEMMAPFILENAME);
|
|
75
75
|
lastTickCount = INT_MAX;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
if(hMemMapFile)
|
|
78
|
+
if (hMemMapFile)
|
|
79
79
|
{
|
|
80
|
-
if(!pSharedMem)
|
|
80
|
+
if (!pSharedMem)
|
|
81
81
|
{
|
|
82
|
-
pSharedMem = (const char
|
|
83
|
-
pHeader = (irsdk_header
|
|
82
|
+
pSharedMem = (const char*)MapViewOfFile(hMemMapFile, FILE_MAP_READ, 0, 0, 0);
|
|
83
|
+
pHeader = (irsdk_header*)pSharedMem;
|
|
84
84
|
lastTickCount = INT_MAX;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
if(pSharedMem)
|
|
87
|
+
if (pSharedMem)
|
|
88
88
|
{
|
|
89
|
-
if(!hDataValidEvent)
|
|
89
|
+
if (!hDataValidEvent)
|
|
90
90
|
{
|
|
91
91
|
hDataValidEvent = OpenEvent(SYNCHRONIZE, false, IRSDK_DATAVALIDEVENTNAME);
|
|
92
92
|
lastTickCount = INT_MAX;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
if(hDataValidEvent)
|
|
95
|
+
if (hDataValidEvent)
|
|
96
96
|
{
|
|
97
97
|
isInitialized = true;
|
|
98
98
|
return isInitialized;
|
|
@@ -109,13 +109,13 @@ bool irsdk_startup()
|
|
|
109
109
|
|
|
110
110
|
void irsdk_shutdown()
|
|
111
111
|
{
|
|
112
|
-
if(hDataValidEvent)
|
|
112
|
+
if (hDataValidEvent)
|
|
113
113
|
CloseHandle(hDataValidEvent);
|
|
114
114
|
|
|
115
|
-
if(pSharedMem)
|
|
115
|
+
if (pSharedMem)
|
|
116
116
|
UnmapViewOfFile(pSharedMem);
|
|
117
117
|
|
|
118
|
-
if(hMemMapFile)
|
|
118
|
+
if (hMemMapFile)
|
|
119
119
|
CloseHandle(hMemMapFile);
|
|
120
120
|
|
|
121
121
|
hDataValidEvent = NULL;
|
|
@@ -127,38 +127,38 @@ void irsdk_shutdown()
|
|
|
127
127
|
lastTickCount = INT_MAX;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
bool irsdk_getNewData(char
|
|
130
|
+
bool irsdk_getNewData(char* data)
|
|
131
131
|
{
|
|
132
|
-
if(isInitialized || irsdk_startup())
|
|
132
|
+
if (isInitialized || irsdk_startup())
|
|
133
133
|
{
|
|
134
134
|
#ifdef _MSC_VER
|
|
135
135
|
_ASSERTE(NULL != pHeader);
|
|
136
136
|
#endif
|
|
137
137
|
|
|
138
138
|
// if sim is not active, then no new data
|
|
139
|
-
if(!(pHeader->status & irsdk_stConnected))
|
|
139
|
+
if (!(pHeader->status & irsdk_stConnected))
|
|
140
140
|
{
|
|
141
141
|
lastTickCount = INT_MAX;
|
|
142
142
|
return false;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
int latest = 0;
|
|
146
|
-
for(int i=1; i<pHeader->numBuf; i++)
|
|
147
|
-
if(pHeader->varBuf[latest].tickCount < pHeader->varBuf[i].tickCount)
|
|
148
|
-
|
|
146
|
+
for (int i = 1; i < pHeader->numBuf; i++)
|
|
147
|
+
if (pHeader->varBuf[latest].tickCount < pHeader->varBuf[i].tickCount)
|
|
148
|
+
latest = i;
|
|
149
149
|
|
|
150
150
|
// if newer than last recieved, than report new data
|
|
151
|
-
if(lastTickCount < pHeader->varBuf[latest].tickCount)
|
|
151
|
+
if (lastTickCount < pHeader->varBuf[latest].tickCount)
|
|
152
152
|
{
|
|
153
153
|
// if asked to retrieve the data
|
|
154
|
-
if(data)
|
|
154
|
+
if (data)
|
|
155
155
|
{
|
|
156
156
|
// try twice to get the data out
|
|
157
|
-
for(int count = 0; count < 2; count++)
|
|
157
|
+
for (int count = 0; count < 2; count++)
|
|
158
158
|
{
|
|
159
|
-
int curTickCount =
|
|
159
|
+
int curTickCount = pHeader->varBuf[latest].tickCount;
|
|
160
160
|
memcpy(data, pSharedMem + pHeader->varBuf[latest].bufOffset, pHeader->bufLen);
|
|
161
|
-
if(curTickCount ==
|
|
161
|
+
if (curTickCount == pHeader->varBuf[latest].tickCount)
|
|
162
162
|
{
|
|
163
163
|
lastTickCount = curTickCount;
|
|
164
164
|
lastValidTime = time(NULL);
|
|
@@ -170,15 +170,15 @@ bool irsdk_getNewData(char *data)
|
|
|
170
170
|
}
|
|
171
171
|
else
|
|
172
172
|
{
|
|
173
|
-
lastTickCount =
|
|
173
|
+
lastTickCount = pHeader->varBuf[latest].tickCount;
|
|
174
174
|
lastValidTime = time(NULL);
|
|
175
175
|
return true;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
// if older than last recieved, than reset, we probably disconnected
|
|
179
|
-
else if(lastTickCount >
|
|
179
|
+
else if (lastTickCount > pHeader->varBuf[latest].tickCount)
|
|
180
180
|
{
|
|
181
|
-
lastTickCount =
|
|
181
|
+
lastTickCount = pHeader->varBuf[latest].tickCount;
|
|
182
182
|
return false;
|
|
183
183
|
}
|
|
184
184
|
// else the same, and nothing changed this tick
|
|
@@ -188,30 +188,30 @@ bool irsdk_getNewData(char *data)
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
|
|
191
|
-
bool irsdk_waitForDataReady(int timeOut, char
|
|
191
|
+
bool irsdk_waitForDataReady(int timeOut, char* data)
|
|
192
192
|
{
|
|
193
193
|
#ifdef _MSC_VER
|
|
194
194
|
_ASSERTE(timeOut >= 0);
|
|
195
195
|
#endif
|
|
196
196
|
|
|
197
|
-
if(isInitialized || irsdk_startup())
|
|
197
|
+
if (isInitialized || irsdk_startup())
|
|
198
198
|
{
|
|
199
199
|
// just to be sure, check before we sleep
|
|
200
|
-
if(irsdk_getNewData(data))
|
|
200
|
+
if (irsdk_getNewData(data))
|
|
201
201
|
return true;
|
|
202
202
|
|
|
203
203
|
// sleep till signaled
|
|
204
204
|
WaitForSingleObject(hDataValidEvent, timeOut);
|
|
205
205
|
|
|
206
206
|
// we woke up, so check for data
|
|
207
|
-
if(irsdk_getNewData(data))
|
|
207
|
+
if (irsdk_getNewData(data))
|
|
208
208
|
return true;
|
|
209
209
|
else
|
|
210
210
|
return false;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
// sleep if error
|
|
214
|
-
if(timeOut > 0)
|
|
214
|
+
if (timeOut > 0)
|
|
215
215
|
Sleep(timeOut);
|
|
216
216
|
|
|
217
217
|
return false;
|
|
@@ -219,7 +219,7 @@ bool irsdk_waitForDataReady(int timeOut, char *data)
|
|
|
219
219
|
|
|
220
220
|
bool irsdk_isConnected()
|
|
221
221
|
{
|
|
222
|
-
if(isInitialized)
|
|
222
|
+
if (isInitialized)
|
|
223
223
|
{
|
|
224
224
|
int elapsed = (int)difftime(time(NULL), lastValidTime);
|
|
225
225
|
return (pHeader->status & irsdk_stConnected) > 0 && elapsed < timeout;
|
|
@@ -228,9 +228,9 @@ bool irsdk_isConnected()
|
|
|
228
228
|
return false;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
const irsdk_header
|
|
231
|
+
const irsdk_header* irsdk_getHeader()
|
|
232
232
|
{
|
|
233
|
-
if(isInitialized)
|
|
233
|
+
if (isInitialized)
|
|
234
234
|
{
|
|
235
235
|
return pHeader;
|
|
236
236
|
}
|
|
@@ -241,9 +241,9 @@ const irsdk_header *irsdk_getHeader()
|
|
|
241
241
|
// direct access to the data buffer
|
|
242
242
|
// Warnign! This buffer is volitile so read it out fast!
|
|
243
243
|
// Use the cached copy from irsdk_waitForDataReady() or irsdk_getNewData() instead
|
|
244
|
-
const char
|
|
244
|
+
const char* irsdk_getData(int index)
|
|
245
245
|
{
|
|
246
|
-
if(isInitialized)
|
|
246
|
+
if (isInitialized)
|
|
247
247
|
{
|
|
248
248
|
return pSharedMem + pHeader->varBuf[index].bufOffset;
|
|
249
249
|
}
|
|
@@ -251,9 +251,9 @@ const char *irsdk_getData(int index)
|
|
|
251
251
|
return NULL;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
const char
|
|
254
|
+
const char* irsdk_getSessionInfoStr()
|
|
255
255
|
{
|
|
256
|
-
if(isInitialized)
|
|
256
|
+
if (isInitialized)
|
|
257
257
|
{
|
|
258
258
|
return pSharedMem + pHeader->sessionInfoOffset;
|
|
259
259
|
}
|
|
@@ -262,27 +262,27 @@ const char *irsdk_getSessionInfoStr()
|
|
|
262
262
|
|
|
263
263
|
int irsdk_getSessionInfoStrUpdate()
|
|
264
264
|
{
|
|
265
|
-
if(isInitialized)
|
|
265
|
+
if (isInitialized)
|
|
266
266
|
{
|
|
267
267
|
return pHeader->sessionInfoUpdate;
|
|
268
268
|
}
|
|
269
269
|
return -1;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
const irsdk_varHeader
|
|
272
|
+
const irsdk_varHeader* irsdk_getVarHeaderPtr()
|
|
273
273
|
{
|
|
274
|
-
if(isInitialized)
|
|
274
|
+
if (isInitialized)
|
|
275
275
|
{
|
|
276
276
|
return ((irsdk_varHeader*)(pSharedMem + pHeader->varHeaderOffset));
|
|
277
277
|
}
|
|
278
278
|
return NULL;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
const irsdk_varHeader
|
|
281
|
+
const irsdk_varHeader* irsdk_getVarHeaderEntry(int index)
|
|
282
282
|
{
|
|
283
|
-
if(isInitialized)
|
|
283
|
+
if (isInitialized)
|
|
284
284
|
{
|
|
285
|
-
if(index >= 0 && index < pHeader->numVars)
|
|
285
|
+
if (index >= 0 && index < pHeader->numVars)
|
|
286
286
|
{
|
|
287
287
|
return &((irsdk_varHeader*)(pSharedMem + pHeader->varHeaderOffset))[index];
|
|
288
288
|
}
|
|
@@ -291,16 +291,16 @@ const irsdk_varHeader *irsdk_getVarHeaderEntry(int index)
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// Note: this is a linear search, so cache the results
|
|
294
|
-
int irsdk_varNameToIndex(const char
|
|
294
|
+
int irsdk_varNameToIndex(const char* name)
|
|
295
295
|
{
|
|
296
|
-
const irsdk_varHeader
|
|
296
|
+
const irsdk_varHeader* pVar;
|
|
297
297
|
|
|
298
|
-
if(name)
|
|
298
|
+
if (name)
|
|
299
299
|
{
|
|
300
|
-
for(int index=0; index<pHeader->numVars; index++)
|
|
300
|
+
for (int index = 0; index < pHeader->numVars; index++)
|
|
301
301
|
{
|
|
302
302
|
pVar = irsdk_getVarHeaderEntry(index);
|
|
303
|
-
if(pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
|
|
303
|
+
if (pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
|
|
304
304
|
{
|
|
305
305
|
return index;
|
|
306
306
|
}
|
|
@@ -310,16 +310,16 @@ int irsdk_varNameToIndex(const char *name)
|
|
|
310
310
|
return -1;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
int irsdk_varNameToOffset(const char
|
|
313
|
+
int irsdk_varNameToOffset(const char* name)
|
|
314
314
|
{
|
|
315
|
-
const irsdk_varHeader
|
|
315
|
+
const irsdk_varHeader* pVar;
|
|
316
316
|
|
|
317
|
-
if(name)
|
|
317
|
+
if (name)
|
|
318
318
|
{
|
|
319
|
-
for(int index=0; index<pHeader->numVars; index++)
|
|
319
|
+
for (int index = 0; index < pHeader->numVars; index++)
|
|
320
320
|
{
|
|
321
321
|
pVar = irsdk_getVarHeaderEntry(index);
|
|
322
|
-
if(pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
|
|
322
|
+
if (pVar && 0 == strncmp(name, pVar->name, IRSDK_MAX_STRING))
|
|
323
323
|
{
|
|
324
324
|
return pVar->offset;
|
|
325
325
|
}
|
|
@@ -331,14 +331,14 @@ int irsdk_varNameToOffset(const char *name)
|
|
|
331
331
|
|
|
332
332
|
unsigned int irsdk_getBroadcastMsgID()
|
|
333
333
|
{
|
|
334
|
-
static unsigned int msgId = RegisterWindowMessage(IRSDK_BROADCASTMSGNAME);
|
|
334
|
+
static unsigned int msgId = RegisterWindowMessage(IRSDK_BROADCASTMSGNAME);
|
|
335
335
|
|
|
336
336
|
return msgId;
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, int var2, int var3)
|
|
340
340
|
{
|
|
341
|
-
irsdk_broadcastMsg(msg, var1,
|
|
341
|
+
irsdk_broadcastMsg(msg, var1, (int)MAKELONG(var2, var3));
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, float var2)
|
|
@@ -353,7 +353,7 @@ void irsdk_broadcastMsg(irsdk_BroadcastMsg msg, int var1, int var2)
|
|
|
353
353
|
{
|
|
354
354
|
static unsigned int msgId = irsdk_getBroadcastMsgID();
|
|
355
355
|
|
|
356
|
-
if(msgId && msg >= 0 && msg < irsdk_BroadcastLast)
|
|
356
|
+
if (msgId && msg >= 0 && msg < irsdk_BroadcastLast)
|
|
357
357
|
{
|
|
358
358
|
SendNotifyMessage(HWND_BROADCAST, msgId, MAKELONG(msg, var1), var2);
|
|
359
359
|
}
|
|
@@ -363,14 +363,14 @@ int irsdk_padCarNum(int num, int zero)
|
|
|
363
363
|
{
|
|
364
364
|
int retVal = num;
|
|
365
365
|
int numPlace = 1;
|
|
366
|
-
if(num > 99)
|
|
366
|
+
if (num > 99)
|
|
367
367
|
numPlace = 3;
|
|
368
|
-
else if(num > 9)
|
|
368
|
+
else if (num > 9)
|
|
369
369
|
numPlace = 2;
|
|
370
|
-
if(zero)
|
|
370
|
+
if (zero)
|
|
371
371
|
{
|
|
372
372
|
numPlace += zero;
|
|
373
|
-
retVal = num + 1000*numPlace;
|
|
373
|
+
retVal = num + 1000 * numPlace;
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
return retVal;
|