|
@@ -145,33 +145,6 @@ ipcMain.on('upload-file', async (event, {filePath, uploadUrl}) => {
|
|
|
event.reply('upload-file-response', {success: false, message: 'File does not exist'});
|
|
|
return;
|
|
|
}
|
|
|
- // 读取文件
|
|
|
- // fs.readFile(filePath, async (err, data) => {
|
|
|
- // if(err) {
|
|
|
- // console.log("Error reading file:", err);
|
|
|
- // event.reply('upload-file-response', { success: false, message: err.message });
|
|
|
- // return;
|
|
|
- // }
|
|
|
- //
|
|
|
- // // 创建formData对象
|
|
|
- // const formData = new FormData();
|
|
|
- // formData.append('file', new Blob([data]), path.basename(filePath));
|
|
|
- //
|
|
|
- // try {
|
|
|
- // // 使用axios上传文件
|
|
|
- // const response = await axios.post(uploadUrl, formData, {
|
|
|
- // headers: {
|
|
|
- // 'Content-Type': 'multipart/form-data'
|
|
|
- // }
|
|
|
- // })
|
|
|
- // console.log('response', response)
|
|
|
- // event.reply('upload-file-response', { success: true, message: 'File uploaded successfully' });
|
|
|
- // } catch (err) {
|
|
|
- // console.log("Error uploading file:", err);
|
|
|
- // event.reply('upload-file-response', { success: false, message: err.message });
|
|
|
- // }
|
|
|
- // })
|
|
|
-
|
|
|
try {
|
|
|
const result = await uploadFile(filePath, uploadUrl);
|
|
|
console.log("result", result);
|
|
@@ -248,6 +221,27 @@ ipcMain.on('docker-import', (event, filePath, tag) => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+// 更新地图
|
|
|
+ipcMain.on('update-map', (event, {container_name, file_path}) => {
|
|
|
+ const command = 'bash /home/cicv/work/pji_desktop/map_update/run_map_update.sh ' + container_name + ' ' + file_path;
|
|
|
+ console.log('command:', command);
|
|
|
+
|
|
|
+ processManager.startProcess('update-map', command, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ console.error(`exec error: ${error}`);
|
|
|
+ // event.reply('update-map-response', { success: false, message: error.message });
|
|
|
+ } else {
|
|
|
+ console.log(`stdout: ${stdout}`);
|
|
|
+ console.error(`stderr: ${stderr}`);
|
|
|
+ if (stdout.toString().includes('Result JSON file created')) { // 判断结束标志
|
|
|
+ event.reply('update-map-response', { success: true, message: 'Update map successfully' });
|
|
|
+ } else {
|
|
|
+ event.reply('update-map-response', { success: false, message: 'Error updating map' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
// 生成world
|
|
|
ipcMain.on('generate-world', (event, {rosbag_path}) => {
|
|
|
const command = 'bash /home/cicv/work/pji_desktop/simulation/generate_world.sh ' + rosbag_path
|
|
@@ -430,4 +424,187 @@ ipcMain.handle('process-evaluation-files', async (event, {N, equipmentNo, sceneN
|
|
|
} else {
|
|
|
return { success: false, message: "Error uploading evaluation results", data: [] }
|
|
|
}
|
|
|
+})
|
|
|
+
|
|
|
+async function uploadMapResult(filePath, uploadUrl) {
|
|
|
+ // 查找文件是否存在
|
|
|
+ let fileExists = fs.existsSync(filePath)
|
|
|
+ let uploadResult = await uploadFileWithRetry(filePath, uploadUrl);
|
|
|
+ if (!fileExists) return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ // console.log("uploadResult", uploadResult);
|
|
|
+ if (!uploadResult.status) {
|
|
|
+ return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ }
|
|
|
+ return { success: true, message: "", data: uploadResult }
|
|
|
+}
|
|
|
+
|
|
|
+// 读取并上传地图更新结果
|
|
|
+ipcMain.handle('process-map-update-files', async (event, {equipmentNo, timeStamp}) => {
|
|
|
+ let result = {}
|
|
|
+ equipmentNo = "pji-test"
|
|
|
+ timeStamp = Date.now()
|
|
|
+ // 记录时间戳
|
|
|
+ console.log("timeStamp", timeStamp);
|
|
|
+ const mapBufDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/mapBuf";
|
|
|
+ const resultDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/result";
|
|
|
+ const updateMapDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/update_map";
|
|
|
+
|
|
|
+ // 读取result*.json
|
|
|
+ // 文件路径 - result*.json
|
|
|
+ const jsonPrefix = "result";
|
|
|
+ let files = fs.readdirSync(resultDir);
|
|
|
+ let matchedFile = files.find(file => file.startsWith(jsonPrefix))
|
|
|
+ let jsonFilePath = ""
|
|
|
+ if (matchedFile) {
|
|
|
+ // 如果找到匹配的文件
|
|
|
+ jsonFilePath = path.join(resultDir, matchedFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log("jsonFilePath", jsonFilePath);
|
|
|
+
|
|
|
+ // 文件路径 - 更新前pgm
|
|
|
+ const prePgmPath = path.join(mapBufDir, "map.pgm");
|
|
|
+ console.log("prePgmPath", prePgmPath);
|
|
|
+ // 文件路径 - 更新后pgm
|
|
|
+ const pgmSuffix = ".pgm";
|
|
|
+ files = fs.readdirSync(updateMapDir);
|
|
|
+ matchedFile = files.find(file => file.endsWith(pgmSuffix))
|
|
|
+ let updatePgmPath = ""
|
|
|
+ if (matchedFile) {
|
|
|
+ // 如果找到匹配的文件
|
|
|
+ updatePgmPath = path.join(updateMapDir, matchedFile);
|
|
|
+ }
|
|
|
+ console.log("updatePgmPath", updatePgmPath);
|
|
|
+ // 文件路径 - 更新前png
|
|
|
+ const prePngPath = path.join(mapBufDir, "map_pre.png");
|
|
|
+ console.log("prePngPath", prePngPath);
|
|
|
+ // 文件路径 - 更新后png
|
|
|
+ const updatePngPath = path.join(mapBufDir, "map_update.png");
|
|
|
+ console.log("updatePngPath", updatePngPath);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 读取json文件
|
|
|
+ const jsonData = fs.readFileSync(jsonFilePath, "utf-8");
|
|
|
+ const parsedData = JSON.parse(jsonData);
|
|
|
+ console.log("parsedData", parsedData);
|
|
|
+
|
|
|
+ const mapId = parsedData["origin_pgm_id"];
|
|
|
+
|
|
|
+ // 上传 更新前pgm
|
|
|
+ let uploadUrl = "http://127.0.0.1:8888/map/upload/map?equipmentNo=" + equipmentNo + "&mapId=" + mapId +
|
|
|
+ "&timeStamp=" + timeStamp ;
|
|
|
+
|
|
|
+ // 上传文件
|
|
|
+ // 上传 更新前pgm
|
|
|
+ let res = await uploadMapResult(prePgmPath, uploadUrl);
|
|
|
+ if (!res.success) {
|
|
|
+ return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ }
|
|
|
+ let prePgmUrl = res.data.details
|
|
|
+ console.log("prePgmUrl", prePgmUrl);
|
|
|
+
|
|
|
+ // 上传 更新前png
|
|
|
+ res = await uploadMapResult(prePngPath, uploadUrl);
|
|
|
+ if (!res.success) {
|
|
|
+ return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ }
|
|
|
+ let prePngUrl = res.data.details
|
|
|
+ console.log("prePngUrl", prePngUrl);
|
|
|
+
|
|
|
+ // 上传 更新后pgm
|
|
|
+ res = await uploadMapResult(updatePgmPath, uploadUrl);
|
|
|
+ if (!res.success) {
|
|
|
+ return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ }
|
|
|
+ let updatePgmUrl = res.data.details
|
|
|
+ console.log("updatePgmUrl", updatePgmUrl);
|
|
|
+
|
|
|
+ // 上传 更新后png
|
|
|
+ res = await uploadMapResult(updatePngPath, uploadUrl);
|
|
|
+ if (!res.success) {
|
|
|
+ return { success: false, message: "Error uploading map results", data: [] }
|
|
|
+ }
|
|
|
+ let updatePngUrl = res.data.details
|
|
|
+ console.log("updatePngUrl", updatePngUrl);
|
|
|
+
|
|
|
+ result = {
|
|
|
+ "jsonData": parsedData,
|
|
|
+ "prePgmUrl": prePgmUrl,
|
|
|
+ "prePngUrl": prePngUrl,
|
|
|
+ "updatePgmUrl": updatePgmUrl,
|
|
|
+ "updatePngUrl": updatePngUrl
|
|
|
+ }
|
|
|
+
|
|
|
+ return { success: true, message: "Evaluation results uploaded successfully", data: result }
|
|
|
+ } catch (error) {
|
|
|
+ console.log("error", error);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // // 遍历评价结果文件夹,读取并上传相关数据
|
|
|
+ // for (let i = 1; i <= N; i++) {
|
|
|
+ // const subDir = path.join(evalDir, `${i}/result`);
|
|
|
+ // console.log("subDir", subDir);
|
|
|
+ // // 文件路径 - report.json
|
|
|
+ // const jsonFilePath = path.join(subDir, "report.json");
|
|
|
+ // console.log("jsonFilePath", jsonFilePath);
|
|
|
+ // // 文件路径 - report.pdf
|
|
|
+ // const pdfFilePath = path.join(subDir, "report.pdf");
|
|
|
+ // console.log("pdfFilePath", pdfFilePath);
|
|
|
+ // // 文件路径 - test-${i}.bag
|
|
|
+ // const bagFilePath = path.join(bagDir, `test-${i}.bag`);
|
|
|
+ // console.log("bagFilePath", bagFilePath);
|
|
|
+ //
|
|
|
+ // const uploadPdfUrl = "http://127.0.0.1:8888/simulation/upload/pdf?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
|
|
|
+ // "&timeStamp=" + timeStamp + "&round=" + i;
|
|
|
+ //
|
|
|
+ // const uploadBagUrl = "http://127.0.0.1:8888/simulation/upload/bag?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
|
|
|
+ // "&timeStamp=" + timeStamp + "&round=" + i;
|
|
|
+ //
|
|
|
+ // try {
|
|
|
+ // // 读取json文件
|
|
|
+ // const jsonData = fs.readFileSync(jsonFilePath, "utf-8");
|
|
|
+ // const parsedData = JSON.parse(jsonData);
|
|
|
+ // console.log("parsedData", parsedData);
|
|
|
+ // // 上传pdf文件
|
|
|
+ // // 查找pdf文件是否存在
|
|
|
+ // let pdfFileExists = fs.existsSync(pdfFilePath)
|
|
|
+ // // pdf文件不存在
|
|
|
+ // if (!pdfFileExists) break
|
|
|
+ // // pdf文件存在
|
|
|
+ // const uploadPdfResult = await uploadFileWithRetry(pdfFilePath, uploadPdfUrl);
|
|
|
+ // console.log("uploadPdfResult", uploadPdfResult);
|
|
|
+ // if (!uploadPdfResult.status) {
|
|
|
+ // break
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 上传bag文件
|
|
|
+ // // 查找bag文件是否存在
|
|
|
+ // let bagFileExists = fs.existsSync(bagFilePath)
|
|
|
+ // // bag文件不存在
|
|
|
+ // if (!bagFileExists) break
|
|
|
+ // // bag文件存在
|
|
|
+ // const uploadBagResult = await uploadFile(bagFilePath, uploadBagUrl);
|
|
|
+ // console.log("uploadBagResult", uploadBagResult);
|
|
|
+ // if (!uploadBagResult.status) { break}
|
|
|
+ // // 整合结果
|
|
|
+ // result.push({
|
|
|
+ // "round": i,
|
|
|
+ // "jsonData": parsedData,
|
|
|
+ // "uploadPdfKey": uploadPdfResult.details,
|
|
|
+ // "uploadBagKey": uploadBagResult.details,
|
|
|
+ // "timeStamp": timeStamp
|
|
|
+ // })
|
|
|
+ // } catch (error) {
|
|
|
+ // console.log("error", error);
|
|
|
+ // return { success: false, message: "Error uploading evaluation results", data: [] }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // 判断数据上传是否完整
|
|
|
+ // if (result.length === N) {
|
|
|
+ // return { success: true, message: "Evaluation results uploaded successfully", data: result }
|
|
|
+ // } else {
|
|
|
+ // return { success: false, message: "Error uploading evaluation results", data: [] }
|
|
|
+ // }
|
|
|
})
|