Bug fixes

This commit is contained in:
2025-05-31 10:10:18 +02:00
parent f1cfd0c77e
commit 05a8baed4f
6 changed files with 246 additions and 204 deletions
+24 -15
View File
@@ -1,7 +1,8 @@
const csv = require("fast-csv");
const fs = require("fs");
const path = require("path");
const { steps } = require("../config/map.conf");
const map_conf = require("../config/map.conf");
const logger = require("./logger.util");
async function addMap(filename, meta, throttle, motor) {
var total = "";
@@ -24,7 +25,7 @@ async function addMap(filename, meta, throttle, motor) {
const current_values = Object.values(motor["0"]);
const brake_values = Object.values(motor["1"]);
for (let i = 0; i <= steps; i++) {
for (let i = 0; i <= map_conf.steps; i++) {
map[i] = [current_values[i], brake_values[i], throttle_values[i]];
}
}
@@ -146,25 +147,33 @@ async function parseMapJson(filename, mode) {
async function getAvailableMaps() {
// path in app_conf
var files = fs.readdirSync("app/storage");
var available_maps = {};
for (const file of files) {
if (path.extname(file) == ".csv") {
available_maps[file] = {};
try {
let meta = await parseMap(file, 1);
if (meta && meta.length) {
for (const m of meta) {
available_maps[file][m.slice(0, m.indexOf(":")).toLowerCase()] = m.slice(m.indexOf(":") + 1)
try {
var files = fs.readdirSync("app/storage");
for (const file of files) {
if (path.extname(file) == ".csv") {
available_maps[file] = {};
try {
let meta = await parseMap(file, 1);
if (meta && meta.length) {
for (const m of meta) {
available_maps[file][m.slice(0, m.indexOf(":")).toLowerCase()] = m.slice(m.indexOf(":") + 1)
}
}
} catch (error) {
throw new Error(error);
}
} catch (error) {
throw new Error(error);
}
}
} catch (error) {
if (error.code === "ENOENT") {
logger.info("No storage directory found. Creating directory.");
fs.mkdirSync("app/storage");
}
}
return available_maps;