|
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 };
|