chenyc
2025-08-07 9b83b704063a0ec9db6c3ed8b0665783f1961c19
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
119
120
121
122
123
124
 
const { crc16 } = require('./crc16'); // 引入上面的文件
/**
 * 
 * @param {*} buffer 
 * @returns 解析数据包
 */
function toModel(buffer) {
    const parsedData = {};
 
    // 跳过前两个字节(0xAA和0xBB)
    let offset = 2;
 
    // CRC16
    parsedData.CRC16 = buffer.readUInt16LE(offset);
    offset += 2;
 
    // 其他字段
    parsedData.治疗剩余时间 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.当前已超滤量 = buffer.readUInt16LE(offset)/1000;
    offset += 2;
 
    parsedData.超滤率 = buffer.readUInt16LE(offset)/1000;
    offset += 2;
 
    parsedData.超滤目标 = buffer.readUInt16LE(offset)/1000;
    offset += 2;
 
    parsedData.设定血流量 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.实际血流量 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.静脉压 = buffer.readInt16LE(offset);
    offset += 2;
 
    parsedData.动脉压 = buffer.readInt16LE(offset);
    offset += 2;
 
    parsedData.跨膜压 = buffer.readInt16LE(offset);
    offset += 2;
 
    parsedData.电导度 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.透析液实际流量 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.透析液实际温度 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.肝素速率 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.肝素停止时间 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.追加量 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.前补液总量 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.前已补液量 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.后补液总量 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.后已补液量 = buffer.readUInt16LE(offset) / 10;
    offset += 2;
 
    parsedData.血压计收缩血压 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.血压计舒张血压 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.血压计脉搏 = buffer.readUInt16LE(offset);
    offset += 1;
    console.log(offset);
    parsedData.模式 = buffer.readUInt8(offset+1);
    offset +=1;
 
    parsedData.KtV = buffer.readUInt8(offset+1)/10;
    offset += 2;
    parsedData.清除率 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.相对血容量 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.设备编号前16位 = buffer.readUInt32LE(offset);
    offset += 2;
 
    parsedData.设备编号后16位 = buffer.readUInt32LE(offset);
    offset += 2;
 
    parsedData.血压计平均血压 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.血氧参数Spo2值 = buffer.readUInt16LE(offset);
    offset += 2;
 
    parsedData.血氧参数脉率 = buffer.readUInt16LE(offset);
    console.log(parsedData);
    return parsedData;
}
function add0(m) { return m < 10 ? '0' + m : m }
function format(shijianchuo) {
    //shijianchuo是整数,否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}
module.exports = { toModel,format };