JavaScript library for reading and writing IPG Automotive infofiles.
Installation:
npm install --save @ipguk/infofile-utils
Importing the library:
const infofile = require("@ipguk/infofile-utils");
- Windows
- Linux
- A libusb libary is required to be installed on Linux systems. This is usually provided by the https://packages.debian.org/stretch/libusb-0.1-4 package.
getDouble
Returns a double value from an infofile for a given key or an array of keys. The value will be returned as a number.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the double value for the keys "WheelCarrier.fl.mass"
const wheelCarrierValue = infofile.getDouble({file, keys:"WheelCarrier.fl.mass"});
// console.log the value, returns a double e.g. "0.5"
console.log(wheelCarrierValue)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the double values for the keys "WheelCarrier.fl.mass" and "WheelCarrier.fr.mass"
const wheelCarrierValues = infofile.getDouble({file, keys:["WheelCarrier.fl.mass", "WheelCarrier.fr.mass"]});
// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "WheelCarrier.fl.mass", value: 0.5}, {keys: "WheelCarrier.fr.mass", value: 0.5}]
console.log(wheelCarrierValues)
getValue
A universal function for getting values from an infofile. All numerical key values are returned as numbers. All other key values are returned as strings.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the value for the keys "WheelCarrier.fl.mass"
const wheelCarrierValue = infofile.getValue({file, keys:"WheelCarrier.fl.mass"});
// console.log the value (returns an object like this {keys: "WheelCarrier.fl.mass", value: 0.0})
console.log(wheelCarrierValue)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the values for the keys "WheelCarrier.fl.mass" and "SuspF.Spring.Kind"
const values = infofile.getValue({file, keys:["WheelCarrier.fl.mass", "SuspF.Spring.Kind"]});
// console.log the values (returns an array of objects like this [{keys: "WheelCarrier.fl.mass", value: 0.0}, {keys: "SuspF.Spring.Kind", value: "Hookean 1"}])
console.log(values)
getLong
Returns a long value from an infofile for a given key or an array of keys. The value will be returned as a number.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the long value for the keys "Body.mass"
const bodyMassValue = infofile.getLong({file, keys:"Body.mass"});
// console.log the value, returns a long e.g. 1801
console.log(bodyMassValue)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the long values for the keys "Body.mass" and "nAxle"
const longValues = infofile.getLong({file, keys:["Body.mass", "nAxle"]});
// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Body.mass", value: 1801}, {keys: "nAxle", value: 2}]
console.log(longValues)
getString
Returns a string value from an infofile for a given keys or an array of keys.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the string value for the keys "Aero.Crosswind.Kind"
const aeroCrosswindKind = infofile.getString({file, keys:"Aero.Crosswind.Kind"});
// console.log the value, returns a string e.g. "Step"
console.log(aeroCrosswindKind)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the string values for the keys "Body.mass" and "Aero.Kind"
const stringValues = infofile.getString({file, keys:["Aero.Crosswind.Kind", "Aero.Kind"]});
// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Aero.Crosswind.Kind", value: "Step"}, {keys: "Aero.Kind", value: "Coeff6x1 1"}]
console.log(stringValues)
getText
Returns a text value from an infofile for a given keys or an array of keys. This is an array of strings are are split by newlines in the infofile.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the text value for the keys "Description"
const description = infofile.getText({file, keys:"Description"});
// console.log the value, returns an array of strings e.g. ["This is a description", "of the infofile"]
console.log(description)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the text values for the keys "Description" and "Aero.Coeff"
const textValues = infofile.getText({file, keys:["Description", "Aero.Coeff"]});
// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Description", value: ["-180 -0.4 0.0 0.1 0.0 -0.01 0.0","-120 -0.2 -1.4 0.7 -0.2 -0.021 0.06","-90 0.0 -1.7 0.9 -0.2 0.0 0.0","-60 0.0 -1.7 0.9 -0.2 0.0 0.0","-30 0.0 -1.7 0.9 -0.2 0.0 0.0","0.0 0.0 -1.7 0.9 -0.2 0.0 0.0","30 0.0 -1.7 0.9 -0.2 0.0 0.0","60 0.0 -1.7 0.9 -0.2 0.0 0.0","90 0.0 -1.7 0.9 -0.2 0.0 0.0","120 0.0 -1.7 0.9 -0.2 0.0 0.0","180 0.0 -1.7 0.9 -0.2 0.0 0.0"]}]
console.log(textValues)
setDouble
Sets a double value to an infofile for a given keys.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the double value for the keys "SuspF.Spring.l0" to 0.351
status = infofile.setDouble({file, values:{keys: "SuspF.Spring.l0", value: 0.351}});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the double values for the keys "SuspF.Spring.l0" and "Body.mass" to 0.351 and 1830.15
status = infofile.setDouble({file, values:[{keys: SuspF.Spring.l0", value: 0.351}, {keys: "Body.mass", value: 1830.15}]});
// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "SuspF.Spring.l0", status: 0}, {keys: "Body.mass", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setValue
A universal function to set values to an infofile.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the value for the keys "SuspF.Spring.l0" to 0.351
status = infofile.setValue({file, values:{keys: "SuspF.Spring.l0", value: 0.351}});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the values for the keys "SuspF.Spring.l0" and "Aero.Crosswind.Kind" to 0.351 and "Step"
status = infofile.setValue({file, values:[{keys: "SuspF.Spring.l0", value: 0.351}, {keys: "Aero.Crosswind.Kind", value: "Step"}]});
// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "SuspF.Spring.l0", status: 0}, {keys: "Aero.Crosswind.Kind", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setLong
Sets a long value to an infofile for a given keys.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the long value for the keys "Body.mass" to 1801
status = infofile.setLong({file, values:{keys: "Body.mass", value: 1801}});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the long values for the keys "Body.mass" and "nAxle" to 1801 and 2
status = infofile.setLong({file, values:[{keys: "Body.mass", value: 1801}, {keys: "nAxle", value: 2}]});
// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Body.mass", status: 0}, {keys: "nAxle", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setString
Sets a string value to an infofile for a given keys.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the string value for the keys "Aero.Crosswind.Kind" to "Step"
status = infofile.setString({file, values:{keys: "Aero.Crosswind.Kind", value: "Step"}});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the string values for the keys "Aero.Crosswind.Kind" and "Eng.Kind" to "Step" and "Flex"
status = infofile.setString({file, values:[{keys: "Aero.Crosswind.Kind", value: "Step"}, {keys: "Eng.Kind", value: "Flex"}]});
// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Aero.Crosswind.Kind", status: 0}, {keys: "Eng.Kind", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setText
Sets a text value to an infofile for a given keys. This is an array of strings are are split by newlines in the infofile for each item in the string array.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the text value for the keys "Description" to ["This is a description", "This is a description on a second line"]
status = infofile.setText({file, values:{keys: "Description", value: ["This is a description", "This is a description on a second line"]}});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// set the text values for the keys "Description" and "Eng.Description" to ["This is a description", "This is a description on a second line"] and ["This is a description", "This is a description on a second line"]
status = infofile.setText({file, values:[{keys: "Description", value: ["This is a description", "This is a description on a second line"]}, {keys: "Eng.Description", value: ["This is a description", "This is a description on a second line"]}]});
// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Description", status: 0}, {keys: "Eng.Description", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
isValidInfoFile
Returns a boolean value to show whether the file is a valid infofile or not.
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// call the function. The property "type" is an optional property.
// If no type is specified, any valid infofile will be taken as valid. However, files which are not infofiles still be regarded as invalid!
// List of values for type:
// "Vehicle" (for cars, motorcycles and trucks)
// "Car" (for Car infofiles)
// "Motorcycle" (for Motorcycle infofiles)
// "Truck" (for Truck infofiles)
// "TestRun" (for test runs)
// "Road" (for road infofiles)
// "Trailer" (for Trailer infofiles)
// "Tire" (for Tire infofiles)
// "Driver" (for Driver infofiles)
// "TrafficBehavior" (for TrafficBehavior infofiles)
// "TrafficDriver" (for TrafficDriver infofiles)
// "TrafficTemplate" (for TrafficTemplate, e. g. vehicles, pedestrians, buildings, etc. infofiles)
// "SavedSelections" (for SavedSelections infofiles)
// "UserDriver" (for UserDriver infofiles)
// "SuspensionKinematics-skc" (for Suspension Kinematics infofiles with a .skc file extension)
// "SuspensionKinematics-mbs" (for Suspension Kinematics infofiles with a .mbs file extension)
// "ADTF" (for ADTF infofifles)
// "DataDict" (for DataDict infofiles)
// "GPUConfig" (for GPUConfig infofiles)
// "PTBattery-BattECM" (for PTBattery-BattECM infofiles)
// "AirBrake" (for AirBrake infofiles)
// "HydESP" (for HydESP infofiles)
// "HydIPB" (for HydIPB infofiles)
// "Suspension" (for various Suspension infofiles)
// "SuspensionControl" (for various SuspensionControl infofiles)
const validationWithoutType = isValidInfoFile({ file: file });
const validationWithType = isValidInfoFile({ file: file, type: "Vehicle" });
// console.log the status, returns true if valid, false if not
console.log(validationWithType)
getKey
Lists the keys in an infofile, for a given prefix, if no prefix is provided all keys are returned
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// list all keys in the infofile
keys = infofile.getKey({file});
// console.log the keys, returns an array of keys e.g. ["Body.mass", "nAxle"]
console.log(keys)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// list all keys in the infofile for the prefix "Aero"
keys = infofile.getKey({ file, prefix: "Aero" });
// console.log the keys, returns an array of keys e.g. ["Aero.Crosswind.Kind", "Aero.Crosswind.Speed"]
console.log(keys)
getKeyKind
Lists the getKeyKind, returns String_Key, Text_Key or No_Key
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the getKeyKind for the keys "Body.mass"
keyKind = infofile.getKeyKind({file, keys: "Body.mass"});
// console.log the keyKind, returns String_Key if keys is a single line string, Text_Key if keys is a text array and No_Key if keys is not found
console.log(keyKind)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// get the getKeyKind for the keys "Body.mass" and "nAxle"
getKeyKind = infofile.getKeyKind({file, keys: ["Body.mass", "nAxle"]});
// console.log the getKeyKind, returns an array of getKeyKind e.g. ["String_Key", "No_Key"]
console.log(getKeyKind)
deleteKey
Deletes a key from an infofile
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// delete the keys "Body.mass"
status = infofile.deleteKey({file, keys: "Body.mass"});
// console.log the status, returns 0 if successful, -1 if not
console.log(status)
// import the library
const infofile = require("@ipguk/infofile-utils");
// get the absolute path to the infofile
const file = "C:\infofiles\infofile";
// delete the keys "Body.mass" and "nAxle"
status = infofile.deleteKey({file, keys: ["Body.mass", "nAxle"]});
// console.log the status, returns an object with the keys "keys" and "status" e.g. {keys: "Body.mass", status: 0}, {keys: "nAxle", status: 0} where status is 0 if successful, -1 if not
console.log(status)