cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
api/vehicle.js
@@ -4,10 +4,11 @@
} from "@/comm/utils.js"
const addLog = (item) => {
   const list = session.getValue("request_log") || []
   list.unshift(item)
   session.setValue("request_log", list)
   http.addLog(item)
}
// 判断ip是否可以连接上
export const checkIpLinkSuccess = (ip) => {
   var url = `http://${ip}:4405/api/mt/battery`;
@@ -75,6 +76,310 @@
}
/**
 * GET 4405/api/shell/version
 * 获取软件版本信息:
 * @param
 * @returns
 */
export const getShellVersion = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/shell/version`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 4405/api/shell/version
 * 更新软件版本
 * @param
 * @returns
 */
export const uploadShellVersion = async (ip, path) => {
   var header = {
      'Content-Type': 'application/octet-stream'
   };
   var url = `http://${ip}:4405/api/shell/version`;
   const buf = await FilePath.readArrayBuffer({
      path: filePath
   });
   const flag = 3
   const flagBuf = new ArrayBuffer(4);
   const view = new DataView(flagBuf);
   view.setUint32(0, flag, false); // 大端
   // 2.3 拼接 POST 体:flag(4B) + 压缩包
   const body = new ArrayBuffer(4 + buf.byteLength);
   const whole = new Uint8Array(body);
   whole.set(new Uint8Array(flagBuf), 0);
   whole.set(new Uint8Array(buf), 4);
   return http.request({
      method: "POST",
      url,
      header,
      dataType: 'arraybuffer', // 关键:让 data 按二进制走
      data: body,
   })
}
export const shellUpgrade = async (ip, filePath, cbSuccess, cbProgress, cbFail) => {
   var url = `http://${ip}:4405/api/shell/upgrade`;
   const uploadTask = uni.uploadFile({
      url,
      name: "upload",
      filePath: filePath,
      formData: {
         'upgrade_flag': 3
      },
      success: (result) => {
         console.log(result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         if (result.statusCode != 200) {
            http.addLog({
               date,
               method: "POST",
               url,
               param: {
                  upload: filePath,
                  upgrade_flag: 3
               },
               statusCode: result.statusCode,
               data: ""
            })
            if (result.statusCode == 404) {
               cbFail("地址不对,请检查该地址:" + url);
            } else
               cbFail("访问失败,状态码:" + result.statusCode);
         } else {
            var ret = result.data
            if (typeof ret == 'string') {
               try {
                  try {
                     try {
                        ret = JSON.parse(ret.replace(/\\"/g, '"'));
                     } catch (ex) {
                        ret = JSON.parse(ret.replace(/\\/g, '\\\\'))
                     }
                  } catch (ex) {
                     ret = JSON.parse(ret.replace(/\\"/g, "'").replace(
                        /[\r\n]/g,
                        '<br>').replace(/[\t]/g, '    '));
                  }
               } catch (ex) {
                  cbFail('将【json string】转换为【json object】失败');
               }
            }
            http.addLog({
               date,
               method: "POST",
               url,
               param: {
                  upload: filePath,
                  upgrade_flag: 3
               },
               statusCode: result.statusCode,
               data: JSON.stringify(ret)
            })
            if (ret.code == 0) {
               cbSuccess(ret.data);
            } else {
               cbFail(ret.msg || ret.message || "");
            }
         }
      },
      fail: (result) => {
         console.log(result)
         cbFail(result);
      },
   })
   uploadTask.onProgressUpdate((res) => {
      cbProgress(res, uploadTask)
   });
}
/**
 * GET 4405/api/error/list
 * 获取实时错误
 * @param
 * @returns
 */
export const getErrorList = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/list?_timestamp=${new Date().getTime()}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 4405/api/mt/clear_fault
 * 清除实时错误
 * @param
 * @returns
 */
export const clearFault = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/mt/clear_fault`;
   return http.request({
      method: "POST",
      url,
      header,
   })
}
/**
 * GET 4405/api/error/history
 * 获取历史错误
 * @param
 * @returns
 */
export const getErrorHistory = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/history?_timestamp=${new Date().getTime()}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 4405/api/error/download_error
 * 下载历史错误日志:
 * @param
 * @returns
 */
export const downloadError = (ip, path, cbSuccess, cbProgress, cbFail) => {
   var url = `http://${ip}:4405/api/error/download_error?path=${encodeURI(path)}`;
   console.log(url)
   // var header = {
   //    "Content-Type": "application/json;charset=UTF-8"
   // };
   // return http.request({
   //    method: "GET",
   //    url,
   //    header,
   // })
   // return
   const downloadTask = uni.downloadFile({
      url: url,
      header: {
         'content-type': 'application/octet-stream',
      },
      success: (result) => {
         console.log("downloadFile", result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         if (result.statusCode === 200) {
            http.addLog({
               date,
               method: `GET`,
               url: url,
               param: {},
               statusCode: result.statusCode,
               data: result
            })
            cbSuccess(result.tempFilePath)
         } else {
            http.addLog({
               date,
               method: `GET`,
               url: url,
               param: {},
               statusCode: result.statusCode,
               data: result.data
            })
            cbFail(result.data || '下载未知错误!');
         }
      },
      fail: (result) => {
         console.log("downloadTaskFile fail", result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         http.addLog({
            date,
            method: `GET`,
            url: url,
            param: {},
            statusCode: -1,
            data: result
         })
         cbFail('下载文件失败!');
      }
   })
   downloadTask.onProgressUpdate((res) => {
      cbProgress(res, downloadTask)
   });
   return downloadTask
}
/**
 * POST 4405/api/mt/error/tar_log
 * 打包下载日志
 * @param
 * @returns
 */
export const tarErrorLog = (ip, start_time, end_time) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/tar_log`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         start_time,
         end_time
      }
   })
}
/**
 * GET 4405/api/error/query_task_status
 * 查询打包后的日志目录(查到后使用4405/api/error/download_error接口下载)
 * @param
 * @returns
 */
export const queryErrorTaskStatus = (ip, task_list) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url =
      `http://${ip}:4405/api/error/query_task_status?_timestamp=${new Date().getTime()}&task_list=${encodeURI(JSON.stringify(task_list))}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/get_agv_state
 * 查询车辆信息
 * @param 
@@ -89,6 +394,7 @@
      method: "GET",
      url,
      header,
   })
@@ -109,6 +415,8 @@
      method: "GET",
      url,
      header,
      timeout: 5000,
   })
}
@@ -128,36 +436,6 @@
      url,
      header,
   })
}
/**
 * POST 5000/api/add_station
 * 获取车辆地图列表
 * @param
 *  stationID, //站台ID
 *   name, //站台名
 * @returns
 */
export const mapInfo = (ip) => {
   // var header = {
   //    "Content-Type": "application/json;charset=UTF-8"
   // };
   // var url = `http://${ip}:4405/api/shell/version`;
   // return http.request({
   //    method: "GET",
   //    url,
   //    header,
   // })
   return new Promise((resolve, reject) => {
      return resolve(
         [{
            name: "地图1",
            img: 'static/map.png',
         }]
      )
   })
}
@@ -583,6 +861,47 @@
}
/**
 * GET 5000/api/split_teaching_mode
 * 切分后的示教查询
 * @param
 * @returns
 */
export const splitTeachingMode = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/split_teaching_mode/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/get_current_teaching_data
 * 获取记录的示教数据
 * @param
 * @returns
 */
export const getCurrentTeachingData = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/get_current_teaching_data/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/teaching_mode_flag
 * 开始/停止示教
 * @param 
@@ -591,6 +910,8 @@
 * name 示教名称
 * teaching_flag # 1 开始示教, 0 停止示教
 * main_road 1,# 1主路,0支路
 * "bidirection": "1", # 1为双向,0为单向,停止示教的时候传值即可( 即"teaching_flag": 0)
 * mode_type # 0默认1双向2智能
 * @returns 
 */
export const teachingModeFlag = (ip, param) => {
@@ -603,6 +924,8 @@
      name,
      teaching_flag,
      main_road,
      bidirection,
      mode_type
   } = param
   var url = `http://${ip}:5000/api/teaching_mode_flag/`;
@@ -615,7 +938,9 @@
         src_dst,
         name,
         teaching_flag,
         main_road
         main_road,
         bidirection,
         mode_type
      }
   })
@@ -647,6 +972,91 @@
   })
}
/**
 * POST 5000/api/delete_teaching_mode_data
 * 删除示教数据
 * @param
 * polygon_points [(0, 0), (0, 3), (3, 3), (3, 0)] #删除区域的四个点
 * @returns
 */
export const delTeachingModeData = (ip, polygonPoints) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/delete_teaching_mode_data/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         polygon_points: polygonPoints
      }
   })
}
/**
 * POST 5000/api/update_split_teaching_data
 * 修改切分示教数据属性
 * @param
 * edge_name # 必传id
 * bidirection # 非必传,修改单双向传递
 * main_road # 非必传,修改主路支路传递
 * name # 必传
 * @returns
 */
export const updateSplitTeachingData = (ip, param) => {
   const {
      edge_name,
      name,
      main_road,
      bidirection
   } = param
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/update_split_teaching_data/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         edge_name,
         name,
         main_road,
         bidirection
      }
   })
}
/**
 * POST 5000/api/delete_split_teaching_data
 * 删除切分示教数据
 * @param
 * edge_name # 必传id
 * name # 必传
 * @returns
 */
export const deleteSplitTeachingData = (ip, edge_name, name) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/delete_split_teaching_data/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         edge_name,
         name,
      }
   })
}
/**
 * POST 5000/api/check_agv_location_distance_error
 * 判断库位和车距离是否过大
@@ -668,4 +1078,400 @@
      }
   })
}
/**
 * POST 5000/api/create_scene
 * 创建/结束场景
 * @param
 * scene_id  场景名称
 * scene_flag  1开始场景,0结束场景
 * @returns
 */
export const createScene = (ip, scene_id, scene_flag) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/create_scene/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         scene_id,
         scene_flag
      }
   })
}
/**
 * POST 5000/api/add_map
 * 开始地图操
 * @param
 * scene_id  场景名称
 * map_type   #新图create扩展extend
 * @returns
 */
export const addMap = (ip, scene_id, map_type = "create") => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/add_map/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         scene_id,
         map_type
      }
   })
}
/**
 * POST 5000/api/stop_map
 *结束地图操
 * @param
 * scene_id  场景名称
 * @returns
 */
export const stopMap = (ip, scene_id) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/stop_map/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         scene_id,
      }
   })
}
/**
 * GET 6000/api/laser_data
 * 返回激光实时数据及底图
 * @param
 *  map_id  地图标识
 * @returns
 */
export const getMapLaserData = (ip, mapId) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/laser_data?map_id=${mapId?mapId:-1}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 6000/api/get_map_server_phase
 * 获取构图程序阶段
 * @param
 * @returns
 * "data": 1,  # 1:未启动2:启动中3:启动完成4:构图保存中5:构图保存完成6:构图保存失败
 */
export const getMapServerPhase = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/get_map_server_phase/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/update_scene_id
 * 修改场景名称
 * @param
 * old_scene_id  需要修改场景名称
 * new_scene_id  修改后的场景名称
 * @returns
 */
export const updateScene = (ip, old_scene_id, new_scene_id) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/update_scene_id/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         old_scene_id,
         new_scene_id
      }
   })
}
/**
 * POST 5000/api/delete_scene
 * 删除场景
 * @param
 * scene_id  场景名称
 * @returns
 */
export const delScene = (ip, scene_id) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/delete_scene/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         scene_id,
      }
   })
}
/**
 * POST 5000/api/handoff_scene
 * 切换场景
 * @param
 * old_scene_id  当前场景名称
 * new_scene_id  需要切换的场景名称
 * @returns
 */
export const handoffScene = (ip, old_scene_id, new_scene_id) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/handoff_scene/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         old_scene_id,
         new_scene_id
      }
   })
}
/**
 * GET 5000/api/save_db_data
 * 获取DB数据
 * @param
 * @returns
 */
export const getDBData = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/get_db_data/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/save_db_data
 * 保存DB数据
 * @param
 * @returns
 */
export const saveDBData = (ip, data) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/save_db_data/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         data
      }
   })
}
/**
 * GET 5000/api/save_db_data_status
 * 获取DB数据保存状态:
 * @param
 * @returns  1保存中 2保存成功 3保存失败
 */
export const getSaveDBDataStatus = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/save_db_data_status/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/cancel_save_db_data
 * 取消保存DB数据:
 * @param
 * @returns
 */
export const cancelSaveDBData = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/cancel_save_db_data/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/check_mapserver_is_start
 * 判断构图程序是否启动
 * @param
 * @returns
 */
export const checkMapServerIsStart = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/check_mapserver_is_start/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/start_or_stop_mapserver
 * 开启或者关闭构图程序: 1开启2关闭
 * @param  status 1开启2关闭
 * @returns
 */
export const startOrStopMapServer = (ip, status) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/start_or_stop_mapserver/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         status
      }
   })
}
/**
 * GET 5000/api/check_mapserver_is_ok
 * 构图程序是否准备到位
 * @param
 * @returns
 */
export const checkMapServerIsOk = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/check_mapserver_is_ok/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/check_save_map_is_ok
 * 结束构图是否保存完成
 * @param
 * @returns
 */
export const checkSaveMapIsOk = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/check_save_map_is_ok/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/get_pallet_size/
 * 获取托盘尺寸:
 * @param
 * @returns
 */
export const getPalletSize = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/get_pallet_size/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/save_pallet_size/
 * 设置托盘尺寸:
 * @param  length 2,#长度/单位m
 * @param  width 2,#长度/单位m
 * @returns
 */
export const savePalletSize = (ip, length, width) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/save_pallet_size/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         length,
         width
      }
   })
}