Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ignore and $comments tags in profiles + optionnal "single profile" to merge + edits to variables in kianiroev #270

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
62 changes: 61 additions & 1 deletion .vehicle_profiles/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,74 @@ import { readFile, writeFile } from 'fs/promises';
const source_folder = '../vehicle_profiles';
const target = '../vehicle_profiles.json'

const files = await glob(source_folder + '/**/*.json');
var args = process.argv.slice(2);
if (args.length == 1)
var files = await glob(source_folder + '/' + args[0])
else
var files = await glob(source_folder + '/**/*.json')


let result = {
'cars': []
};

function removeSubObjectsWithKey(obj, keyToRemove) { // Thanks to Mistral.AI
// Check if the object is an array
if (Array.isArray(obj)) {
// Iterate over each element in the array
for (let i = 0; i < obj.length; i++) {
// Recursively call the function on each element
obj[i] = removeSubObjectsWithKey(obj[i], keyToRemove);
// Remove null entries from the array
if (obj[i] === null) {
obj.splice(i, 1);
i--; // Adjust the index after removing an element
}
}
} else if (obj !== null && typeof obj === 'object') {
// Check if any child contains the key to remove
let shouldRemoveParent = false;
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (key === keyToRemove) {
shouldRemoveParent = true;
} else {
// Recursively call the function on each value
obj[key] = removeSubObjectsWithKey(obj[key], keyToRemove);
if (obj[key] === null) {
shouldRemoveParent = true;
}
}
}
}
// If any child contains the key to remove, return null to remove the parent object
if (shouldRemoveParent) {
return null;
}
// Remove null entries from the object
for (let key in obj) {
if (obj.hasOwnProperty(key) && obj[key] === null) {
delete obj[key];
}
}
}
// Return the modified object
return obj;
}

function removeComments(obj) {
for (const [key, value] of Object.entries(obj)) {
if (key==='$comments')
delete obj[key];
else if (typeof obj[key] === 'object')
removeComments(obj[key])
}
}

async function add_json(path){
let data = JSON.parse(await readFile(path));
data = removeSubObjectsWithKey(data, '$ignore');
removeComments(data);
result.cars.push(data)
}

Expand Down
170 changes: 163 additions & 7 deletions vehicle_profiles/kia/nirosoulkona-ev.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,188 @@
"pid": "21014",
"parameters": [
{
"name": "GearSelector_Raw",
"expression": "B10",
"name": "VMCU_Gear_Park",
"expression": "B10:0",
"unit": "none",
"class": "none"
},
{
"name": "Speed_Vehicle",
"name": "VMCU_Gear_Reverse",
"expression": "B10:1",
"unit": "none",
"class": "none"
},
{
"name": "VMCU_Gear_Neutral",
"expression": "B10:2",
"unit": "none",
"class": "none"
},
{
"name": "VMCU_Gear_Drive",
"expression": "B10:3",
"unit": "none",
"class": "none"
},
{
"name": "VMCU_Speed",
"expression": "[B19:B20]/100",
"unit": "%",
"class": "battery"
"unit": "km/h",
"class": "speed"
},
{
"name": "Car_Ready",
"name": "VMCU_Car_Ready",
"expression": "B26:3",
"unit": "none",
"class": "none",
"type": "binary_sensor"
},
{
"name": "Car_ParkBreak",
"name": "VMCU_Car_ParkBreak",
"expression": "B26:5",
"unit": "none",
"class": "none",
"type": "binary_sensor"
}
]
},
{
"pid_init": "ATSH7E2;",
"pid": "21026",
"parameters": [
{
"name": "NOK_VMCU_Aux12v_Voltage",
"expression": "[B26:B27]/1000",
"unit": "V",
"class": "voltage"
},
{
"name": "VMCU_Aux12v_SoC",
"expression": "B30",
"unit": "%",
"class": "battery"
}
]
},
{
"pid_init": "ATSH7E5;",
"pid": "21019",
"parameters": [
{
"name": "OBC_Aux12v_Voltage",
"expression": "[B25:B26]/100",
"unit": "V",
"class": "voltage"
},
{
"name": "OBC_Pilot_Cycle_Duty",
"expression": "[B35:B36]/10",
"unit": "%",
"class": "charger"
},
{
"name": "NOK_OBC_AC_Voltage",
"expression": "B56",
"unit": "V",
"class": "voltage"
},
{
"name": "NOK_OBC_Temp",
"expression": "B53/2-40",
"unit": "°C",
"class": "temperature"
}
]
},
{
"pid_init": "ATSH7E5;",
"pid": "21038",
"parameters": [
{
"name": "OBC_AC_Current",
"expression": "[B9:B10]/100",
"unit": "A",
"class": "current"
}
]
},
{
"pid_init": "ATSH7A0;",
"pid": "22C00B4",
"parameters": [
{
"name": "TPMS_FL_PSI",
"expression": "[B10]/5",
"unit": "psi",
"class": "pressure"
},
{
"name": "TPMS_FL_Bar",
"expression": "[B10]/72.52",
"unit": "bar",
"class": "pressure"
},
{
"name": "TPMS_FL_Temp",
"expression": "[B11]-50",
"unit": "°C",
"class": "temperature"
},
{
"name": "TPMS_FR_PSI",
"expression": "[B14]/5",
"unit": "psi",
"class": "pressure"
},
{
"name": "TPMS_FR_Bar",
"expression": "[B14]/72.52",
"unit": "bar",
"class": "pressure"
},
{
"name": "TPMS_FR_Temp",
"expression": "[B15]-50",
"unit": "°C",
"class": "temperature"
},
{
"name": "TPMS_RR_PSI",
"expression": "[B19]/5",
"unit": "psi",
"class": "pressure"
},
{
"name": "TPMS_RR_Bar",
"expression": "[B19]/72.52",
"unit": "bar",
"class": "pressure"
},
{
"name": "TPMS_RR_Temp",
"expression": "[B20]-50",
"unit": "°C",
"class": "temperature"
},
{
"name": "TPMS_RL_PSI",
"expression": "[B23]/5",
"unit": "psi",
"class": "pressure"
},
{
"name": "TPMS_RL_Bar",
"expression": "[B23]/72.52",
"unit": "bar",
"class": "pressure"
},
{
"name": "TPMS_RL_Temp",
"expression": "[B25]-50",
"unit": "°C",
"class": "temperature"
}
]
}
]
}
Loading