Skip to content

Commit

Permalink
Update irsdk headers, add pit sv status enum
Browse files Browse the repository at this point in the history
  • Loading branch information
apihlaja committed Jul 2, 2019
1 parent c6feee0 commit 16501b7
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 108 deletions.
65 changes: 41 additions & 24 deletions src/cpp/IrSdkBindingHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@
using namespace v8;
using namespace std;

Local<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index)
Local<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar &var, const int &index)
{
switch (var.type) {
switch (var.type)
{
case irsdk_char:
return Nan::New((var.value[index]) + "\0").ToLocalChecked();
case irsdk_bool:
return Nan::New(var.boolValue[index]);
case irsdk_int:
if (strcmp(var.header->unit, "irsdk_SessionState") == 0) {
if (strcmp(var.header->unit, "irsdk_SessionState") == 0)
{
return getStringValue(var.intValue[index], SESSION_STATES);
}
if (strcmp(var.header->unit, "irsdk_TrkLoc") == 0) {
if (strcmp(var.header->unit, "irsdk_TrkLoc") == 0)
{
return getStringValue(var.intValue[index], TRACK_LOCS);
}
if (strcmp(var.header->unit, "irsdk_TrkSurf") == 0) {
if (strcmp(var.header->unit, "irsdk_TrkSurf") == 0)
{
return getStringValue(var.intValue[index], TRACK_SURF);
}
if (strcmp(var.header->unit, "irsdk_PitSvStatus") == 0)
{
return getStringValue(var.intValue[index], PIT_SV_STATUS);
}
return Nan::New(static_cast<int32_t>(var.intValue[index]));
case irsdk_bitField:
return getMaskedValues(var.intValue[index], var.header->unit);
Expand All @@ -34,9 +42,10 @@ Local<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar
}
}

Local<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var)
Local<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar &var)
{
if (var.header->count > 1) {
if (var.header->count > 1)
{
Local<Array> arr = Nan::New<Array>(var.header->count);
for (int i = 0; i < var.header->count; ++i)
{
Expand All @@ -50,14 +59,15 @@ Local<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar&
}
}

void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Local<Object>& obj)
void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar &var, Local<Object> &obj)
{
Nan::Set(obj, Nan::New("name").ToLocalChecked(), Nan::New(var.header->name).ToLocalChecked());
Nan::Set(obj, Nan::New("desc").ToLocalChecked(), Nan::New(var.header->desc).ToLocalChecked());
Nan::Set(obj, Nan::New("unit").ToLocalChecked(), Nan::New(var.header->unit).ToLocalChecked());
Nan::Set(obj, Nan::New("count").ToLocalChecked(), Nan::New(var.header->count));

switch (var.header->type) {
switch (var.header->type)
{
case irsdk_char:
Nan::Set(obj, Nan::New("type").ToLocalChecked(), Nan::New("char").ToLocalChecked());
break;
Expand All @@ -82,51 +92,58 @@ void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Local<
}
}

Local<Value> NodeIrSdk::getMaskedValues(const int& val, char* unit)
Local<Value> NodeIrSdk::getMaskedValues(const int &val, char *unit)
{
if (strcmp(unit,"irsdk_Flags") == 0) {
if (strcmp(unit, "irsdk_Flags") == 0)
{
return getValueArr(val, FLAG_MASKS);
}
if (strcmp(unit, "irsdk_CameraState") == 0) {
if (strcmp(unit, "irsdk_CameraState") == 0)
{
return getValueArr(val, CAMERA_STATE_MASKS);
}
if (strcmp(unit, "irsdk_EngineWarnings") == 0) {
if (strcmp(unit, "irsdk_EngineWarnings") == 0)
{
return getValueArr(val, ENGINE_WARNINGS_MASKS);
}
if (strcmp(unit, "irsdk_PitSvFlags") == 0) {
if (strcmp(unit, "irsdk_PitSvFlags") == 0)
{
return getValueArr(val, PIT_SV_MASKS);
}
if (strcmp(unit, "irsdk_CarLeftRight") == 0) {
return getValueArr(val, CAR_BESIDE);
if (strcmp(unit, "irsdk_CarLeftRight") == 0)
{
return getValueArr(val, CAR_BESIDE);
}
cerr << "Missing converter for bitField: " << unit << endl;
return Nan::New(static_cast<int32_t>(val));
}

Local<Array> NodeIrSdk::getValueArr(const int& val, const std::vector<NodeIrSdk::MaskName> MASKS)
Local<Array> NodeIrSdk::getValueArr(const int &val, const std::vector<NodeIrSdk::MaskName> MASKS)
{
Local<Array> arr = Nan::New<Array>();
int counter = 0;
for (const auto& mask : MASKS)
for (const auto &mask : MASKS)
{
if ((mask.val & val) == mask.val) {
if ((mask.val & val) == mask.val)
{
Nan::Set(arr, counter++, Nan::New(mask.name).ToLocalChecked());
}
}
return arr;
}

Local<Value> NodeIrSdk::getStringValue(const int& val, const std::vector<NodeIrSdk::MaskName>& map)
Local<Value> NodeIrSdk::getStringValue(const int &val, const std::vector<NodeIrSdk::MaskName> &map)
{
for (const auto& mask : map) {
if (mask.val == val) {
for (const auto &mask : map)
{
if (mask.val == val)
{
return Nan::New(mask.name).ToLocalChecked();
}
}
return Nan::Undefined();
}

NodeIrSdk::MaskName::MaskName(int val, const char* name) :
val(val), name(name)
NodeIrSdk::MaskName::MaskName(int val, const char *name) : val(val), name(name)
{
}
152 changes: 79 additions & 73 deletions src/cpp/IrSdkBindingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ using namespace v8;
namespace NodeIrSdk
{

Local<Value> convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index);
Local<Value> convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var);
void convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Local<Object>& obj);
Local<Value> convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar &var, const int &index);
Local<Value> convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar &var);
void convertVarHeaderToObject(IRSDKWrapper::TelemetryVar &var, Local<Object> &obj);

struct MaskName
{
int val;
const char *name;

struct MaskName {
int val;
const char* name;

MaskName(int val, const char* name);
};
MaskName(int val, const char *name);
};

Local<Value> getStringValue(const int& val, const std::vector<MaskName>& map);
Local<Value> getStringValue(const int &val, const std::vector<MaskName> &map);

Local<Value> getMaskedValues(const int& val, char* unit);
Local<Array> getValueArr(const int& val, const std::vector<MaskName> MASKS);
Local<Value> getMaskedValues(const int &val, char *unit);
Local<Array> getValueArr(const int &val, const std::vector<MaskName> MASKS);

const std::vector<MaskName> FLAG_MASKS = {
const std::vector<MaskName> FLAG_MASKS = {
MaskName((int)irsdk_checkered, "Checkered"),
MaskName((int)irsdk_white, "White"),
MaskName((int)irsdk_green, "Green"),
Expand Down Expand Up @@ -56,21 +56,31 @@ namespace NodeIrSdk
MaskName((int)irsdk_startHidden, "StartHidden"),
MaskName((int)irsdk_startReady, "StartReady"),
MaskName((int)irsdk_startSet, "StartSet"),
MaskName((int)irsdk_startGo, "StartGo")
};
MaskName((int)irsdk_startGo, "StartGo")};

const std::vector<MaskName> PIT_SV_MASKS = {
const std::vector<MaskName> PIT_SV_MASKS = {
MaskName((int)irsdk_LFTireChange, "LFTireChange"),
MaskName((int)irsdk_RFTireChange, "RFTireChange"),
MaskName((int)irsdk_LRTireChange, "LRTireChange"),
MaskName((int)irsdk_RRTireChange, "RRTireChange"),

MaskName((int)irsdk_FuelFill, "FuelFill"),
MaskName((int)irsdk_WindshieldTearoff, "WindshieldTearoff"),
MaskName((int)irsdk_FastRepair, "FastRepair")
};
MaskName((int)irsdk_FastRepair, "FastRepair")};

const std::vector<MaskName> PIT_SV_STATUS = {
MaskName((int)irsdk_PitSvNone, "PitSvNone"),
MaskName((int)irsdk_PitSvInProgress, "PitSvInProgress"),
MaskName((int)irsdk_PitSvComplete, "PitSvComplete"),
MaskName((int)irsdk_PitSvTooFarLeft, "PitSvTooFarLeft"),
MaskName((int)irsdk_PitSvTooFarRight, "PitSvTooFarRight"),
MaskName((int)irsdk_PitSvTooFarForward, "PitSvTooFarForward"),
MaskName((int)irsdk_PitSvTooFarBack, "PitSvTooFarBack"),
MaskName((int)irsdk_PitSvBadAngle, "PitSvBadAngle"),
MaskName((int)irsdk_PitSvCantFixThat, "PitSvCantFixThat"),
};

const std::vector<MaskName> CAMERA_STATE_MASKS = {
const std::vector<MaskName> CAMERA_STATE_MASKS = {
MaskName((int)irsdk_IsSessionScreen, "IsSessionScreen"),
MaskName((int)irsdk_IsScenicActive, "IsScenicActive"),

Expand All @@ -81,78 +91,74 @@ namespace NodeIrSdk
MaskName((int)irsdk_UseTemporaryEdits, "UseTemporaryEdits"),
MaskName((int)irsdk_UseKeyAcceleration, "UseKeyAcceleration"),
MaskName((int)irsdk_UseKey10xAcceleration, "UseKey10xAcceleration"),
MaskName((int)irsdk_UseMouseAimMode, "UseMouseAimMode")
};
MaskName((int)irsdk_UseMouseAimMode, "UseMouseAimMode")};

const std::vector<MaskName> ENGINE_WARNINGS_MASKS = {
const std::vector<MaskName> ENGINE_WARNINGS_MASKS = {
MaskName((int)irsdk_waterTempWarning, "WaterTempWarning"),
MaskName((int)irsdk_fuelPressureWarning, "FuelPressureWarning"),
MaskName((int)irsdk_oilPressureWarning, "OilPressureWarning"),
MaskName((int)irsdk_engineStalled, "EngineStalled"),
MaskName((int)irsdk_pitSpeedLimiter, "PitSpeedLimiter"),
MaskName((int)irsdk_revLimiterActive, "RevLimiterActive"),
};
};

const std::vector<MaskName> SESSION_STATES = {
const std::vector<MaskName> SESSION_STATES = {
MaskName((int)irsdk_StateInvalid, "Invalid"),
MaskName((int)irsdk_StateGetInCar, "GetInCar"),
MaskName((int)irsdk_StateWarmup, "Warmup"),
MaskName((int)irsdk_StateParadeLaps, "ParadeLaps"),
MaskName((int)irsdk_StateRacing, "Racing"),
MaskName((int)irsdk_StateCheckered, "Checkered"),
MaskName((int)irsdk_StateCoolDown, "CoolDown")
};
MaskName((int)irsdk_StateCoolDown, "CoolDown")};

const std::vector<MaskName> TRACK_LOCS = {
const std::vector<MaskName> TRACK_LOCS = {
MaskName((int)irsdk_NotInWorld, "NotInWorld"),
MaskName((int)irsdk_OffTrack, "OffTrack"),
MaskName((int)irsdk_InPitStall, "InPitStall"),
MaskName((int)irsdk_AproachingPits, "AproachingPits"),
MaskName((int)irsdk_OnTrack, "OnTrack")
};

const std::vector<MaskName> TRACK_SURF = {
MaskName((int)irsdk_SurfaceNotInWorld, "SurfaceNotInWorld"),
MaskName((int)irsdk_UndefinedMaterial, "UndefinedMaterial"),

MaskName((int)irsdk_Asphalt1Material, "Asphalt1Material"),
MaskName((int)irsdk_Asphalt2Material, "Asphalt2Material"),
MaskName((int)irsdk_Asphalt3Material, "Asphalt3Material"),
MaskName((int)irsdk_Asphalt4Material, "Asphalt4Material"),
MaskName((int)irsdk_Concrete1Material, "Concrete1Material"),
MaskName((int)irsdk_Concrete2Material, "Concrete2Material"),
MaskName((int)irsdk_RacingDirt1Material, "RacingDirt1Material"),
MaskName((int)irsdk_RacingDirt2Material, "RacingDirt2Material"),
MaskName((int)irsdk_Paint1Material, "Paint1Material"),
MaskName((int)irsdk_Paint2Material, "Paint2Material"),
MaskName((int)irsdk_Rumble1Material, "Rumble1Material"),
MaskName((int)irsdk_Rumble2Material, "Rumble2Material"),
MaskName((int)irsdk_Rumble3Material, "Rumble3Material"),
MaskName((int)irsdk_Rumble4Material, "Rumble4Material"),

MaskName((int)irsdk_Grass1Material, "Grass1Material"),
MaskName((int)irsdk_Grass2Material, "Grass2Material"),
MaskName((int)irsdk_Grass3Material, "Grass3Material"),
MaskName((int)irsdk_Grass4Material, "Grass4Material"),
MaskName((int)irsdk_Dirt1Material, "Dirt1Material"),
MaskName((int)irsdk_Dirt2Material, "Dirt2Material"),
MaskName((int)irsdk_Dirt3Material, "Dirt3Material"),
MaskName((int)irsdk_Dirt4Material, "Dirt4Material"),
MaskName((int)irsdk_SandMaterial, "SandMaterial"),
MaskName((int)irsdk_Gravel1Material, "Gravel1Material"),
MaskName((int)irsdk_Gravel2Material, "Gravel2Material"),
MaskName((int)irsdk_GrasscreteMaterial, "GrasscreteMaterial"),
MaskName((int)irsdk_AstroturfMaterial, "AstroturfMaterial"),
};

const std::vector<MaskName> CAR_BESIDE = {
MaskName((int)irsdk_LROff, "LROff"),
MaskName((int)irsdk_LRClear, "LRClear"), // no cars around us.
MaskName((int)irsdk_LRCarLeft, "LRCarLeft"), // there is a car to our left.
MaskName((int)irsdk_LRCarRight, "LRCarRight"), // there is a car to our right.
MaskName((int)irsdk_LRCarLeftRight, "LRCarLeftRight"), // there are cars on each side.
MaskName((int)irsdk_LR2CarsLeft, "LR2CarsLeft"), // there are two cars to our left.
MaskName((int)irsdk_LR2CarsRight, "LR2CarsRight") // there are two cars to our right.
};
MaskName((int)irsdk_OnTrack, "OnTrack")};

const std::vector<MaskName> TRACK_SURF = {
MaskName((int)irsdk_SurfaceNotInWorld, "SurfaceNotInWorld"),
MaskName((int)irsdk_UndefinedMaterial, "UndefinedMaterial"),

MaskName((int)irsdk_Asphalt1Material, "Asphalt1Material"),
MaskName((int)irsdk_Asphalt2Material, "Asphalt2Material"),
MaskName((int)irsdk_Asphalt3Material, "Asphalt3Material"),
MaskName((int)irsdk_Asphalt4Material, "Asphalt4Material"),
MaskName((int)irsdk_Concrete1Material, "Concrete1Material"),
MaskName((int)irsdk_Concrete2Material, "Concrete2Material"),
MaskName((int)irsdk_RacingDirt1Material, "RacingDirt1Material"),
MaskName((int)irsdk_RacingDirt2Material, "RacingDirt2Material"),
MaskName((int)irsdk_Paint1Material, "Paint1Material"),
MaskName((int)irsdk_Paint2Material, "Paint2Material"),
MaskName((int)irsdk_Rumble1Material, "Rumble1Material"),
MaskName((int)irsdk_Rumble2Material, "Rumble2Material"),
MaskName((int)irsdk_Rumble3Material, "Rumble3Material"),
MaskName((int)irsdk_Rumble4Material, "Rumble4Material"),

MaskName((int)irsdk_Grass1Material, "Grass1Material"),
MaskName((int)irsdk_Grass2Material, "Grass2Material"),
MaskName((int)irsdk_Grass3Material, "Grass3Material"),
MaskName((int)irsdk_Grass4Material, "Grass4Material"),
MaskName((int)irsdk_Dirt1Material, "Dirt1Material"),
MaskName((int)irsdk_Dirt2Material, "Dirt2Material"),
MaskName((int)irsdk_Dirt3Material, "Dirt3Material"),
MaskName((int)irsdk_Dirt4Material, "Dirt4Material"),
MaskName((int)irsdk_SandMaterial, "SandMaterial"),
MaskName((int)irsdk_Gravel1Material, "Gravel1Material"),
MaskName((int)irsdk_Gravel2Material, "Gravel2Material"),
MaskName((int)irsdk_GrasscreteMaterial, "GrasscreteMaterial"),
MaskName((int)irsdk_AstroturfMaterial, "AstroturfMaterial"),
};

const std::vector<MaskName> CAR_BESIDE = {
MaskName((int)irsdk_LROff, "LROff"),
MaskName((int)irsdk_LRClear, "LRClear"), // no cars around us.
MaskName((int)irsdk_LRCarLeft, "LRCarLeft"), // there is a car to our left.
MaskName((int)irsdk_LRCarRight, "LRCarRight"), // there is a car to our right.
MaskName((int)irsdk_LRCarLeftRight, "LRCarLeftRight"), // there are cars on each side.
MaskName((int)irsdk_LR2CarsLeft, "LR2CarsLeft"), // there are two cars to our left.
MaskName((int)irsdk_LR2CarsRight, "LR2CarsRight") // there are two cars to our right.
};
}; // namespace NodeIrSdk
Loading

0 comments on commit 16501b7

Please sign in to comment.