|
@@ -4,11 +4,13 @@ import path from 'path';
|
|
|
import {fileURLToPath} from 'url';
|
|
|
import fs from 'fs';
|
|
|
import axios from 'axios';
|
|
|
+import ProcessManager from './processManager.js'
|
|
|
|
|
|
-
|
|
|
+const processManager = new ProcessManager(); // 创建进程管理器实例
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
+
|
|
|
function createWindow() {
|
|
|
const win = new BrowserWindow({
|
|
|
width: 800,
|
|
@@ -202,10 +204,33 @@ async function uploadFile(filePath, uploadUrl) {
|
|
|
return response.data
|
|
|
} catch (err) {
|
|
|
console.log("Error uploading file:", err);
|
|
|
- return { status: false, code: '', message: '上传stl文件失败', details: '' };
|
|
|
+ return { status: false, code: '', message: '上传件失败', details: '' };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function uploadFileWithRetry(filePath, uploadUrl, maxRetries = 3) {
|
|
|
+ let attempt = 1;
|
|
|
+
|
|
|
+ while (attempt <= maxRetries) {
|
|
|
+ console.log("Uploading file - attempt:", attempt);
|
|
|
+ try {
|
|
|
+ const response = await uploadFile(filePath, uploadUrl);
|
|
|
+ console.log("response", response);
|
|
|
+ if (response.status) { // 上传成功
|
|
|
+ return response;
|
|
|
+ } else { // 上传失败
|
|
|
+ console.log("Fail to upload file - attempt:", attempt);
|
|
|
+ attempt++
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log("Error uploading file - attempt:", attempt);
|
|
|
+ console.log("Error:", error);
|
|
|
+ attempt++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { status: false, code: '', message: '上传文件失败', details: '' };
|
|
|
+}
|
|
|
+
|
|
|
// 导入算法镜像
|
|
|
ipcMain.on('docker-import', (event, filePath, tag) => {
|
|
|
const command = 'bash /home/cicv/work/pji_desktop/docker_import/run_docker_import.sh ' + filePath + ' pji_nav ' + tag
|
|
@@ -289,10 +314,26 @@ ipcMain.on('start-container', (event, {zip_file_path, image_name, container_name
|
|
|
|
|
|
// 执行仿真
|
|
|
ipcMain.on('run-simulation', (event, {random_flag, count, obstacle_flag, default_start_flag, default_end_flag, start_point, end_point}) => {
|
|
|
+
|
|
|
const command = 'bash /home/cicv/work/pji_desktop/simulation/run_simulation.sh ' + random_flag + ' ' + count + ' ' + obstacle_flag + ' ' +
|
|
|
default_start_flag + ' ' + default_end_flag + ' ' + start_point + ' ' + end_point;
|
|
|
console.log('command:', command);
|
|
|
- exec(command, (error, stdout, stderr) => {
|
|
|
+ // exec(command, (error, stdout, stderr) => {
|
|
|
+ // if (error) {
|
|
|
+ // console.error(`exec error: ${error}`);
|
|
|
+ // event.reply('run-simulation-response', { success: false, message: error.message });
|
|
|
+ // } else {
|
|
|
+ // console.log(`stdout: ${stdout}`);
|
|
|
+ // console.error(`stderr: ${stderr}`);
|
|
|
+ // if (stdout.toString().includes('Evaluation finished')) { // 判断结束标志
|
|
|
+ // event.reply('run-simulation-response', { success: true, message: 'Run simulation successfully' });
|
|
|
+ // } else {
|
|
|
+ // event.reply('run-simulation-response', { success: false, message: 'Error running simulation' });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+
|
|
|
+ processManager.startProcess('run-simulation', command, (error, stdout, stderr) => {
|
|
|
if (error) {
|
|
|
console.error(`exec error: ${error}`);
|
|
|
event.reply('run-simulation-response', { success: false, message: error.message });
|
|
@@ -306,6 +347,12 @@ ipcMain.on('run-simulation', (event, {random_flag, count, obstacle_flag, default
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // 设置超时机制(
|
|
|
+ setTimeout(() => {
|
|
|
+ processManager.killProcess('run-simulation');
|
|
|
+ event.reply('run-simulation-response', { success: false, message: 'Script running timeout' });
|
|
|
+ }, 3*60*1000); // 3 分钟
|
|
|
});
|
|
|
|
|
|
// 读取并上传算法评价结果
|
|
@@ -344,12 +391,25 @@ ipcMain.handle('process-evaluation-files', async (event, {N, equipmentNo, sceneN
|
|
|
const parsedData = JSON.parse(jsonData);
|
|
|
console.log("parsedData", parsedData);
|
|
|
// 上传pdf文件
|
|
|
- const uploadPdfResult = await uploadFile(pdfFilePath, uploadPdfUrl);
|
|
|
+ // 查找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}
|
|
|
+ if (!uploadPdfResult.status) {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
// 上传bag文件
|
|
|
+ // 查找bag文件是否存在
|
|
|
+ let bagFileExists = fs.existsSync(bagFilePath)
|
|
|
+ // bag文件不存在
|
|
|
+ if (!bagFileExists) break
|
|
|
+ // bag文件存在
|
|
|
const uploadBagResult = await uploadFile(bagFilePath, uploadBagUrl);
|
|
|
- console.log("uploadBagUrl", uploadBagUrl);
|
|
|
+ console.log("uploadBagResult", uploadBagResult);
|
|
|
if (!uploadBagResult.status) { break}
|
|
|
// 整合结果
|
|
|
result.push({
|