You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过NFC获取FreeStyle Libre正确血糖值(解决数值过高问题)

解决FreeStyle Libre血糖值读取异常(数值超1000)问题

我尝试读取FreeStyle Libre设备的血糖值,了解到设备的Trend记录(8小时)和History记录(24小时)包含血糖数据。我参考了多个Android和Flutter相关的GitHub项目:

  • vicktor/FreeStyleLibre-NFC-Reader
  • DorianScholz/OpenLibre
  • cominixo/OpenLibreNFC
  • creepymonster/GlucoseDirect
  • amino-health/quantify-app

基于这些项目编写了读取代码,但得到的血糖值超过1000,而正常范围应该是70-240。以下是我编写的代码:

List getHistoryData(memoryDatafromNFC) {
  List result = [];
  int watchTime = DateTime.now().millisecondsSinceEpoch;
  int indexTrend = memoryDatafromNFC[26];
  int sensorTime = 256 * (memoryDatafromNFC[317]) + (memoryDatafromNFC[316]);
  int sensorStartTime = watchTime - sensorTime * 60000;

  for (int index = 0; index < 32; index++) {
    int i = indexTrend - index - 1;
    if (i < 0) i += 32;
    int time = [0, (((sensorTime - 3) / 15).abs() * 15 - index * 15).round()]
        .reduce(max);
    DateTime readTime =
        DateTime.fromMillisecondsSinceEpoch(sensorStartTime + time * 60000);
    result.add({
      "timeStamp": DateTime(readTime.year, readTime.month, readTime.day, readTime.hour,
            readTime.minute),
      "glucoseValue": getGlucoseValue(
        memoryDatafromNFC[(i * 6 + 125)],
        memoryDatafromNFC[(i * 6 + 124)],
      ),
    });
  }
  return result;
}

double getGlucoseValue(int fstByte, int sndByte) {
  return (((256 * fstByte) + (sndByte)) & 0x0FFF) / 1;
}

问题原因及修正方案

核心问题在于血糖值的计算逻辑:FreeStyle Libre的原始血糖数据是以10倍mg/dL存储的,直接返回原始值会导致数值放大10倍,超出正常范围。

修正后的getGlucoseValue方法:

double getGlucoseValue(int fstByte, int sndByte) {
  // 提取低12位有效数据(过滤状态标识位)
  int rawValue = ((256 * fstByte) + sndByte) & 0x0FFF;
  // 除以10转换为正常mg/dL单位的血糖值
  return rawValue / 10.0;
}

另外需要确认内存偏移位置的正确性:不同版本的FreeStyle Libre设备内存布局可能存在差异,可对比参考项目中的解析逻辑,调整i * 6 + 125这类数据偏移值,确保读取的是正确的血糖数据字节。

内容的提问来源于stack exchange,提问作者Balakumaran P

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 04:57:03