Skip to content

Commit

Permalink
Updated consts - Update to smoke-test.js to ensure the enum values ar…
Browse files Browse the repository at this point in the history
…e converted to ints
  • Loading branch information
mcalapurge committed Mar 31, 2021
1 parent 986a9e0 commit 0a418ec
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ node_modules/
build/
prebuilds/
npm-debug.log

# Logged telem data
test/*.json
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"targets": [
{
"target_name": "IrSdkNodeBindings",
Expand Down
80 changes: 80 additions & 0 deletions src/IrSdkConsts.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,86 @@ var IrSdkConsts = {
Exciting: -1,
/** Use car number / position instead of this */
Driver: 0
},
/** Camera states
@enum
*/
CamCameraState:
{
IsSessionScreen: 0x0001,
IsScenicActive: 0x0002,
CamToolActive: 0x0004,
UIHidden: 0x0008,
UseAutoShotSelection: 0x0010,
UseTemporaryEdits: 0x0020,
UseKeyAcceleration: 0x0040,
UseKey10xAcceleration: 0x0080,
UseMouseAimMode: 0x0100
},
/** Session states
@enum
*/
SessionState: {
Invalid: 0,
GetInCar: 1,
Warmup: 2,
ParadeLaps: 3,
Racing: 4,
Checkered: 5,
CoolDown: 6
},
/** Engine warnings states
@enum
*/
EngineWarnings: {
waterTempWarning: 0x0001,
fuelPressureWarning: 0x0002,
oilPressureWarning: 0x0004,
engineStalled: 0x0008,
pitSpeedLimiter: 0x0010,
revLimiterActive: 0x0020
},
/** Session Flag states
@enum
*/
Flags: {
checkered: 0x00000001,
white: 0x00000002,
green: 0x00000004,
yellow: 0x00000008,
red: 0x00000010,
blue: 0x00000020,
debris: 0x00000040,
crossed: 0x00000080,
yellowWaving: 0x00000100,
oneLapToGreen: 0x00000200,
greenHeld: 0x00000400,
tenToGo: 0x00000800,
fiveToGo: 0x00001000,
randomWaving: 0x00002000,
caution: 0x00004000,
cautionWaving: 0x00008000,
black: 0x00010000,
disqualify: 0x00020000,
servicible: 0x00040000,
furled: 0x00080000,
repair: 0x00100000,
startHidden: 0x10000000,
startReady: 0x20000000,
startSet: 0x40000000,
startGo: 0x80000000
},
/** Session Pit states
@enum
*/
PitSvFlags: {
LFTireChange: 0x0001,
RFTireChange: 0x0002,
LRTireChange: 0x0004,
RRTireChange: 0x0008,
FuelFill: 0x0010,
WindshieldTearoff: 0x0020,
FastRepair: 0x0040
}
}

Expand Down
44 changes: 26 additions & 18 deletions test/smoke-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// tests if node-irsdk works at all..

var expect = require('chai').expect
var Consts = require('../src/IrSdkConsts')

var irsdk = require('../')
var fs = require('fs')

irsdk.init({
telemetryUpdateInterval: 0,
Expand All @@ -25,6 +27,7 @@ iracing.once('Connected', function () {
console.log('TelemetryDescription event received')
expect(data).to.exist.and.to.be.an('object')
desc = data
fs.writeFileSync('test/TelemetryDescription.json', JSON.stringify(desc, null, 2), 'utf8')
checkTelemetryValues(telemetry, desc)
done('desc')
})
Expand All @@ -35,6 +38,7 @@ iracing.once('Connected', function () {
expect(data).to.have.property('timestamp').that.is.a('date')
expect(data).to.have.property('values').that.is.an('object')
telemetry = data
fs.writeFileSync('test/Telemetry.json', JSON.stringify(telemetry, null, 2), 'utf8')
checkTelemetryValues(telemetry, desc)
done('telemetry')
})
Expand All @@ -58,6 +62,14 @@ var checkTelemetryValues = function (telemetry, desc) {
console.log('got telemetry and its description, validating output..')

for (var telemetryVarName in desc) {
if (typeof telemetry.values[telemetryVarName] === 'string') {
var enumKey = Object.keys(Consts).find(function (key) {
return key.toLowerCase() === telemetryVarName.toLowerCase()
})
if (enumKey) {
return Consts[enumKey]
}
}
if (desc.hasOwnProperty(telemetryVarName)) {
console.log('checking ' + telemetryVarName)
var varDesc = desc[telemetryVarName]
Expand All @@ -79,24 +91,20 @@ var checkTelemetryValues = function (telemetry, desc) {
}
var validateValue = function (val, desc) {
if (desc.type !== 'bitField') {
if (desc.unit.substr(0, 5) === 'irsdk') {
expect(val).to.be.a('string', 'enums should be converted to strings')
} else {
if (desc.type === 'bool') {
expect(val).to.be.a('boolean')
}
if (desc.type === 'int') {
expect(val).to.be.a('number')
}
if (desc.type === 'float') {
expect(val).to.be.a('number')
}
if (desc.type === 'double') {
expect(val).to.be.a('number')
}
if (desc.type === 'char') {
expect(val).to.be.a('string').and.have.length(1)
}
if (desc.type === 'bool') {
expect(val).to.be.a('boolean')
}
if (desc.type === 'int') {
expect(val).to.be.a('number')
}
if (desc.type === 'float') {
expect(val).to.be.a('number')
}
if (desc.type === 'double') {
expect(val).to.be.a('number')
}
if (desc.type === 'char') {
expect(val).to.be.a('string').and.have.length(1)
}
} else {
// expect bitField to be converted to array<string>
Expand Down

0 comments on commit 0a418ec

Please sign in to comment.