34
chenyc
2024-12-03 41ce1252805212ce336f292a69a8dbdcbf981fc0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { defineStore } from 'pinia'
import { ref } from 'vue'
import {IDeviceCilent, IMsgBody} from "../components/classType"
import { ElMessage } from 'element-plus'
export const clicentStore =defineStore('client',()=>{
    const clientSockerList=ref(<any>[])
 
    const  setClientSockerList=(list:IDeviceCilent[])=>{
        clientSockerList.value=list
    }
     /**更新socket操作状态是否初始化了 0,是没有 1 是有  */
     const updateClientState2=(ip:string,port:number,state:number)=>{
        clientSockerList.value.forEach((element:IDeviceCilent) => {
            if(element.diviceHOST===ip&&element.decicePORT===port){
                element.state=state
                return 
            }
        })
    }
    /**更新socket链接状态 */
    const updateClientState=(ip:string,port:number,state:number)=>{
        clientSockerList.value.forEach((element:IDeviceCilent) => {
            if(element.diviceHOST===ip&&element.decicePORT===port){
                element.connectState=state
                return 
            }
        })
    }
    /**更新socket发送的数据 */
    const updateClientMsg=(ip:string,prot:Number, msgData:IMsgBody)=>{
        clientSockerList.value.forEach((element:IDeviceCilent) => {
            if(element.diviceHOST===ip&&element.decicePORT===prot){
                console.log('写入返回数据')
                element.msgBody=msgData
                return 
            }
        })
    }
    /**更新异常链接消息 */
    const updateClientErrer=(ip:string,prot:Number, errerData:string)=>{
        clientSockerList.value.forEach((element:IDeviceCilent) => {
            if(element.diviceHOST===ip&&element.decicePORT===prot){
                console.log('写入异常数据')
                element.devicErrer=errerData
                return 
            }
        })
    }
    
    return {clientSockerList,setClientSockerList,updateClientState,updateClientState2,updateClientMsg,updateClientErrer}
})
/**解析数据1 */
function parseData(buf: Uint8Array,index1:number,index2:number,index3:number,index4:number): number {
    let data5: number = (buf[index1] << 24) | (buf[index2] << 16) | (buf[index3] << 8) | buf[index4];
    return data5;
}
 
/**返回服务端消息 */
window.ipcRenderer.on('result-data', (_event, ...args) => {
    console.log('返回校验后的数据')
    const row=args[0].data
    const msgBody={
        超滤目标: parseData(row,5,6,7,8),
        已超滤量: parseData(row,9,10,11,12),
        超滤速率: parseData(row,13,14,15,16),
        血泵流量设定: parseData(row,17,18,19,20),
        透析液流量: parseData(row,21,22,23,24),
        透析液温度: parseData(row,25,26,27,28),
        电导度: parseData(row,29,30,31,32),
        静脉压: parseData(row,33,34,35,36),
        透析液压: parseData(row,37,38,39,40),
        跨膜压: parseData(row,41,42,43,44),
        透析时间: parseData(row,45,46,47,48),
        肝素泵流量: parseData(row,49,50,51,52),
        累计注射量: parseData(row,53,54,55,56),
        报警编号: parseData(row,57,58,59,60),
        剩余时间: parseData(row,61,62,63,64),
        血流量: parseData(row,65,66,67,68),
        动脉压: parseData(row,69,70,71,72),
        收缩压: parseData(row,73,74,75,76),
        舒张压: parseData(row,77,78,79,80),
        脉搏: parseData(row,81,82,83,84),
    }
    console.log('解析数据'+args[0].ip)
    console.log(msgBody)
    clicentStore().updateClientMsg(args[0].ip,args[0].prot,msgBody)
   
})
// /**返回服务端连接日志 */
// window.ipcRenderer.on('result-connLog', (_event, ...args) => {
//     console.log('返回服务端连接日志')
//     console.log(args[0].data)
//     // const row=args[0].data
    
   
// })
/**
 * 返回异常信息{}
 */
window.ipcRenderer.on('result-errer', (_event, ...args) => {
    try{
        clicentStore().updateClientErrer(args[0].ip,args[0].prot,args[0].data)
    }catch(err){
      console.log(err)
    }
    
  })
  
/**返回服务端连接状态 */
window.ipcRenderer.on('result-state', (_event, ...args) => {
  try{
    console.log('状态消息',args[0].data)
    clicentStore().updateClientState(args[0].ip,args[0].prot,args[0].data)
  }catch(err){
    console.log(err)
  }
  
})