用于连接 Gambro/Baxter Artis 透析机 TCP 端口并解析 ORU^R31(XML,UTF-16LE/UNICODE)消息中的 OBX 参数。
Set-Location D:\gitData\Jb-Communication
npm install
npm test
预期会打印类似:[7] 温度 (Temp): 37.500000 cel。
当你拿到“原始数据流”(抓包/串流日志)时,优先把数据保存成文件,然后用离线工具解析并复用现有的 parseAndPrintData()。
二进制抓包(推荐):
Set-Location D:\gitData\Jb-Communication
npm run parse:raw -- .\raw.bin
如果你的文件是 hex 文本(例如 00 3C 00 4F ...):
Set-Location D:\gitData\Jb-Communication
npm run parse:raw -- .\raw_hex.txt --hex
如果你的文件是 base64 文本:
Set-Location D:\gitData\Jb-Communication
npm run parse:raw -- .\raw_b64.txt --b64
编码强制(默认会自动猜测,一般不需要):
npm run parse:raw -- .\raw.bin --utf16le
npm run parse:raw -- .\raw.xml --utf8
如果你的文件像 新结果.txt 这样是“RTF 包了一层 + 里面是 3C 00 4F 00 ... 的 hex 字节”,可以直接用 index.js 做提取+解码+解析:
Set-Location D:\gitData\Jb-Communication
node .\index.js --decode-file .\新结果.txt --hex --utf16le
说明:如果抓到的数据被截断,导致没有 </ORU_R31> 闭合,脚本会自动尝试从片段提取完整 <OBX>...</OBX> 并兜底解析。
脚本只会在“收到完整的 XML 帧(包含 </ORU_R31> 或 </ORF_R04>)”后才打印。常见原因是模拟器发的是“文本形式的 hex(字符 3C 00 4F...)”,而不是原始字节流。
推荐做法:把 hex 文本转成二进制,然后用模拟器的“发送文件/原始发送”功能发送。
Set-Location D:\gitData\Jb-Communication
npm run hex:bin -- .\raw_hex.txt .\payload.bin
如果要确认脚本是否真的收到字节/是否形成完整帧,可开启调试:
node .\index.js --debug
当你想在没有真实设备的情况下调试“TCP 粘包/半包分帧 + OBX 解析”,推荐直接用仓库里的 sim_server.js 回放你抓到的真实数据(例如 结果全部.txt)。
终端 A:启动模拟服务端(监听本机端口,按帧回放):
Set-Location D:\gitData\Jb-Communication
npm run sim:server -- --host 127.0.0.1 --port 39023 --hex-file .\结果全部.txt --interval 200
终端 B:启动客户端连接模拟服务端:
Set-Location D:\gitData\Jb-Communication
node .\index.js --host 127.0.0.1 --port 39023 --debug
压测分帧(模拟半包/粘包):把发送模式切到“按字节流拆块写出”。例如每 200 字节写一次:
npm run sim:server -- --host 127.0.0.1 --port 39023 --hex-file .\结果全部.txt --mode bytes --chunk 200 --interval 5
如果只想发送一轮后退出,加 --once。
index.js,修改 CONFIG.host 为透析机 IP。Set-Location D:\gitData\Jb-Communication
node .\index.js
如需“收集”每帧解析结果到文件(NDJSON,一行一条帧):
Set-Location D:\gitData\Jb-Communication
node .\index.js --collect
默认输出到:artis_frames.ndjson(项目目录)。也可以自定义输出路径:
node .\index.js --collect --out .\my_frames.ndjson
默认端口:
3021:自动推送(治疗状态下通常每 60 秒一条)当你需要“一套程序同时连接多台透析机”,并且按设备编号做最新数据缓存 + 分发到不同平台,请使用 gateway.js。
host/port/subscriptionsMSH.4/HD.1)”为 key,只保留最新一条mqtt 与 aliyunIot先复制模板:
Set-Location D:\gitData\Jb-Communication
Copy-Item .\gateway.config.example.json .\gateway.config.json
然后编辑 gateway.config.json:
devices[]:配置多台透析机 IP 和端口(通常 3021)devices[].subscriptions:可选 mqtt / aliyunIotservices.mqtt:MQTT Broker 地址、topic 前缀等services.aliyunIot.tripleApi:通过设备编号换取三元组的接口Set-Location D:\gitData\Jb-Communication
npm install
npm run gateway
指定配置文件启动:
node .\gateway.js --config .\gateway.config.json
gateway.js 已按 阿里物模型.json 做属性映射,并优先按物模型类型做转换(int/text/...):
n <- 设备编号(MSH.4/HD.1)deviceType <- 配置项 services.aliyunIot.deviceType(默认 Artis)IPAddress <- 当前设备连接 IPzljd <- OBX id=0(治疗阶段)sysj <- OBX id=1(剩余时间)A <- OBX id=34(设定超滤量,作为超滤总量)B <- OBX id=2(已超滤量)C <- OBX id=3(超滤率)D <- OBX id=6(血流量)sdxll <- OBX id=32(设定血流速)F <- OBX id=7(温度)J <- OBX id=12(TMP)H <- OBX id=13(静脉压)o <- OBX id=14(动脉压)L <- OBX id=8(透析液流速)G <- OBX id=4(电导率)说明:如果某个属性当前帧没有解析到,网关会跳过该属性,不会发送空值。
默认会把每台设备最新数据缓存到:
./cache/latest-device-cache.json你可在 gateway.config.json 的 cacheFile 修改路径。
utf16le 解码(对应文档中的 UNICODE/UTF-16)。NE),客户端收到数据后不要发送 ACK。artis_protocol_oru_r31.md。