|
|
@@ -4,137 +4,165 @@ import socket from "./socket";
|
|
|
import icpList from "../../utils/ipc";
|
|
|
import client from "./client";
|
|
|
|
|
|
-const socketStore = socket()
|
|
|
-// 初始化客户端状态管理
|
|
|
+const socketStore = socket();
|
|
|
const clientStore = client();
|
|
|
|
|
|
-export const checkInfo = defineStore('checkInfo',()=>{
|
|
|
-
|
|
|
- //status -1连接失败 0未连接 1连接中 2链接成功 3端口占用
|
|
|
- //拍照设备
|
|
|
- const mcu = reactive({
|
|
|
- status:0,
|
|
|
- msg_type:"mcu",
|
|
|
- msg:"未连接",
|
|
|
- })
|
|
|
-
|
|
|
- //遥控器
|
|
|
- const blueTooth = reactive({
|
|
|
- status:0,
|
|
|
- msg_type:"blue_tooth",
|
|
|
- msg:"未连接",
|
|
|
- })
|
|
|
-
|
|
|
- //camControl 打开digiCamControl 通过端口 5513 来判断是否链接上了
|
|
|
- const camControl = reactive({
|
|
|
- status:0,
|
|
|
- msg_type:"cam_control",
|
|
|
- msg:"未连接",
|
|
|
- })
|
|
|
-
|
|
|
- //相机
|
|
|
- const camera = reactive({
|
|
|
- status:0,
|
|
|
- msg_type:"cam_control",
|
|
|
- msg:"未连接",
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
- const getProgress = computed(()=>{
|
|
|
+export const checkInfo = defineStore('checkInfo', () => {
|
|
|
+ // 定义设备列表
|
|
|
+ const devices = reactive({
|
|
|
+/* mcu: {
|
|
|
+ status: 0,
|
|
|
+ msg_type: "connect_mcu",
|
|
|
+ msg: "未连接",
|
|
|
+ },
|
|
|
+ blue_tooth: {
|
|
|
+ status: 0,
|
|
|
+ msg_type: "connect_bluetooth",
|
|
|
+ msg: "未连接",
|
|
|
+ },*/
|
|
|
+ cam_control: {
|
|
|
+ status: 0,
|
|
|
+ msg_type: "cam_control",
|
|
|
+ msg: "未连接",
|
|
|
+ },
|
|
|
+/* camera: {
|
|
|
+ status: 0,
|
|
|
+ msg_type: "camera",
|
|
|
+ msg: "未连接",
|
|
|
+ },*/
|
|
|
+ });
|
|
|
+
|
|
|
+ const checkTime = ref(0)
|
|
|
+ let CKTimerInterval:any = null
|
|
|
+
|
|
|
+ // 计算完成进度
|
|
|
+ const getProgress = computed(() => {
|
|
|
let completed = 0;
|
|
|
- let total = 4;
|
|
|
- if(mcu.status === 2) completed++;
|
|
|
- if(blueTooth.status === 2) completed++;
|
|
|
- if(camControl.status === 2) completed++;
|
|
|
- if(camera.status === 2) completed++;
|
|
|
- return Number(completed/total)*100
|
|
|
- })
|
|
|
+ const total = Object.keys(devices).length;
|
|
|
+ for (const device of Object.values(devices)) {
|
|
|
+ if (device.status === 2) completed++;
|
|
|
+ }
|
|
|
+ return parseFloat((completed / total * 100).toFixed(2));
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取错误信息
|
|
|
+ const getErrorMsg = computed(() => {
|
|
|
+ for (const device of Object.values(devices)) {
|
|
|
+ if (device.status === -1) {
|
|
|
+ clearInterval(CKTimerInterval)
|
|
|
+ checkTime.value = 0
|
|
|
+ return device.msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
|
|
|
+ const checkcamControl = async ()=>{
|
|
|
|
|
|
- const getErrorMsg = computed(()=>{
|
|
|
- if(mcu.status === -1) return mcu.msg
|
|
|
- if(blueTooth.status === -1) return blueTooth.msg
|
|
|
- if(camControl.status === -1) return camControl.msg
|
|
|
- if(camera.status === -1) return camera.msg
|
|
|
- })
|
|
|
|
|
|
+ clientStore.ipc.removeAllListeners(icpList.camera.connect);
|
|
|
+ clientStore.ipc.send(icpList.camera.connect);
|
|
|
+ clientStore.ipc.on(icpList.camera.connect, async (event, result) => {
|
|
|
|
|
|
|
|
|
- const checkAction = async (data: any) => {
|
|
|
- await socketStore.disconnectSocket()
|
|
|
- await socketStore.connectSocket()
|
|
|
- await checkMCU()
|
|
|
- await checkblueTooth()
|
|
|
+ console.log('icpList.camera.connect');
|
|
|
+ console.log(result);
|
|
|
+ if (result && checkTime.value > 0) {
|
|
|
+ if([-1,0,2].includes(result.status)){
|
|
|
+ devices.cam_control.status = result.status;
|
|
|
+ devices.cam_control.msg = result.msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- await checkCamControl()
|
|
|
- await checkCamera()
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- const checkMCU = async (data: any) => {
|
|
|
- await socketStore.sendMessage({
|
|
|
- type: 'connect_mcu',
|
|
|
- })
|
|
|
- if(clientStore.isClient){
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.check.mcu);
|
|
|
- clientStore.ipc.on(icpList.socket.check.mcu, async (event, result) => {
|
|
|
- if(result){
|
|
|
- mcu.status = result.status
|
|
|
- mcu.msg = result.msg
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- };
|
|
|
- const checkblueTooth = async (data: any) => {
|
|
|
- await socketStore.sendMessage({
|
|
|
- type: 'blueTooth',
|
|
|
- })
|
|
|
- if(clientStore.isClient){
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.check.blueTooth);
|
|
|
- clientStore.ipc.on(icpList.socket.check.blueTooth, async (event, result) => {
|
|
|
- if(result){
|
|
|
- blueTooth.status = result.status
|
|
|
- blueTooth.msg = result.msg
|
|
|
+ const checkcamera = ()=>{
|
|
|
+ clientStore.ipc.removeAllListeners(icpList.camera.hascamera);
|
|
|
+ clientStore.ipc.send(icpList.camera.hascamera);
|
|
|
+ clientStore.ipc.on(icpList.camera.hascamera, (event, result) => {
|
|
|
+ if (result && checkTime.value > 0) {
|
|
|
+ if([-1,0,2].includes(result.status)){
|
|
|
+ devices.cam_control.status = result.status;
|
|
|
+ devices.cam_control.msg = result.msg;
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
- };
|
|
|
- const checkCamControl = async (data: any) => {
|
|
|
+ }
|
|
|
+ console.log(result);
|
|
|
+ });
|
|
|
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.check.camControl);
|
|
|
+ }
|
|
|
|
|
|
- clientStore.ipc.send(icpList.socket.check.camControl);
|
|
|
+ // 通用设备检查函数
|
|
|
+ const checkDevice = async (deviceName: string, messageType: string) => {
|
|
|
+ try {
|
|
|
+ await socketStore.connectSocket();
|
|
|
+ await socketStore.sendMessage({ type: messageType });
|
|
|
+ clientStore.ipc.on(icpList.socket.message+'_'+deviceName, (event, result) => {
|
|
|
+ if (result && checkTime.value > 0) {
|
|
|
+ if([-1,0,2].includes(result.status)){
|
|
|
+ devices[deviceName].status = result.status;
|
|
|
+ devices[deviceName].msg = result.msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`Error checking ${deviceName}:`, error);
|
|
|
+ devices[deviceName].status = -1;
|
|
|
+ devices[deviceName].msg = `检查失败: ${error.message}`;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- clientStore.ipc.on(icpList.socket.check.camControl, async (event, result) => {
|
|
|
- if(result){
|
|
|
- camControl.status = result.status
|
|
|
- camControl.msg = result.msg
|
|
|
+ // 执行所有设备检查
|
|
|
+ const checkAction = async () => {
|
|
|
+ for (const deviceName of Object.keys(devices)) {
|
|
|
+ switch (deviceName){
|
|
|
+ case 'cam_control':
|
|
|
+ await checkcamControl();
|
|
|
+ break;
|
|
|
+ case 'camera':
|
|
|
+ // await checkcamera();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ await checkDevice(deviceName, devices[deviceName].msg_type);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- })
|
|
|
};
|
|
|
- const checkCamera = async (data: any) => {
|
|
|
- clientStore.ipc.removeAllListeners(icpList.socket.check.camera);
|
|
|
|
|
|
- clientStore.ipc.send(icpList.socket.check.camera);
|
|
|
+ // 重新检查所有设备
|
|
|
+ const reCheckAction = async () => {
|
|
|
+ for (const device of Object.values(devices)) {
|
|
|
+ device.status = 0;
|
|
|
+ device.msg = "未连接";
|
|
|
+ }
|
|
|
+ checkTime.value++;
|
|
|
+ CKTimerInterval = setInterval(()=>{
|
|
|
+ checkTime.value++;
|
|
|
+
|
|
|
|
|
|
- clientStore.ipc.on(icpList.socket.check.camera, async (event, result) => {
|
|
|
- if(result){
|
|
|
- camera.status = result.status
|
|
|
- camera.msg = result.msg
|
|
|
+ if(checkTime.value >= 60){
|
|
|
+ if( devices.blue_tooth && devices.blue_tooth.status === 0){
|
|
|
+ devices.blue_tooth.status = -1;
|
|
|
+ devices.blue_tooth.msg = '遥控器未连接。';
|
|
|
+ }
|
|
|
}
|
|
|
+ },1000)
|
|
|
+ await checkAction();
|
|
|
|
|
|
- })
|
|
|
};
|
|
|
|
|
|
+
|
|
|
return {
|
|
|
getProgress,
|
|
|
- mcu,
|
|
|
- blueTooth,
|
|
|
- camControl,
|
|
|
- camera
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
+ getErrorMsg,
|
|
|
+ mcu: devices.mcu,
|
|
|
+ blueTooth: devices.blueTooth,
|
|
|
+ camControl: devices.camControl,
|
|
|
+ camera: devices.camera,
|
|
|
+ checkAction,
|
|
|
+ reCheckAction,
|
|
|
+ };
|
|
|
+});
|
|
|
|
|
|
export default checkInfo;
|