@irsdk-node/native 4.1.1 → 5.1.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.
@@ -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