求解读一段JAVA代码(解析数据结果的)

发布于 2022-09-11 14:29:30 字数 4299 浏览 31 评论 0

有一段代码如下

package com.pmi.reader.data.battery_info;

import android.annotation.TargetApi;
import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import com.pmi.reader.data.CharacteristicData;
import com.pmi.reader.helpers.BinaryHelper;

@TargetApi(18)
public class BatteryInformation
  extends CharacteristicData
{
  private static final String TAG = BatteryInformation.class.getSimpleName();
  private Integer chargerBatteryLevel;
  private Integer chargerBatteryTemperature;
  private Integer chargerBatteryVoltage;
  private int flags;
  private Integer holder1BatteryLevel;
  private Integer holder1BatteryTemperature;
  private Integer holder1BatteryVoltage;
  private Integer holder2BatteryLevel;
  private Integer holder2BatteryTemperature;
  private Integer holder2BatteryVoltage;
  
  public BatteryInformation(BluetoothGattCharacteristic paramBluetoothGattCharacteristic)
  {
    Log.d(TAG, BinaryHelper.arrayToHexString(paramBluetoothGattCharacteristic.getValue()));
    this.flags = paramBluetoothGattCharacteristic.getIntValue(18, 0).intValue();
    int j = 0 + 2;
    int i = j;
    if (isFlag(0))
    {
      this.chargerBatteryLevel = paramBluetoothGattCharacteristic.getIntValue(17, j);
      i = j + 1;
    }
    j = i;
    if (isFlag(1))
    {
      this.chargerBatteryTemperature = paramBluetoothGattCharacteristic.getIntValue(17, i);
      j = i + 1;
    }
    i = j;
    if (isFlag(2))
    {
      this.chargerBatteryVoltage = paramBluetoothGattCharacteristic.getIntValue(18, j);
      i = j + 2;
    }
    j = i;
    if (isFlag(3))
    {
      this.holder1BatteryLevel = paramBluetoothGattCharacteristic.getIntValue(17, i);
      j = i + 1;
    }
    i = j;
    if (isFlag(4))
    {
      this.holder1BatteryTemperature = paramBluetoothGattCharacteristic.getIntValue(17, j);
      i = j + 1;
    }
    j = i;
    if (isFlag(5))
    {
      this.holder1BatteryVoltage = paramBluetoothGattCharacteristic.getIntValue(18, i);
      j = i + 2;
    }
    i = j;
    if (isFlag(6))
    {
      this.holder2BatteryLevel = paramBluetoothGattCharacteristic.getIntValue(17, j);
      i = j + 1;
    }
    j = i;
    if (isFlag(7))
    {
      this.holder2BatteryTemperature = paramBluetoothGattCharacteristic.getIntValue(17, i);
      j = i + 1;
    }
    if (isFlag(8)) {
      this.holder2BatteryVoltage = paramBluetoothGattCharacteristic.getIntValue(18, j);
    }
  }
  
  public Integer getChargerBatteryLevel()
  {
    return this.chargerBatteryLevel;
  }
  
  public Integer getChargerBatteryTemperature()
  {
    return this.chargerBatteryTemperature;
  }
  
  public Integer getChargerBatteryVoltage()
  {
    return this.chargerBatteryVoltage;
  }
  
  public int getFlags()
  {
    return this.flags;
  }
  
  public Integer getHolder1BatteryLevel()
  {
    return this.holder1BatteryLevel;
  }
  
  public Integer getHolder1BatteryTemperature()
  {
    return this.holder1BatteryTemperature;
  }
  
  public Integer getHolder1BatteryVoltage()
  {
    return this.holder1BatteryVoltage;
  }
  
  public Integer getHolder2BatteryLevel()
  {
    return this.holder2BatteryLevel;
  }
  
  public Integer getHolder2BatteryTemperature()
  {
    return this.holder2BatteryTemperature;
  }
  
  public Integer getHolder2BatteryVoltage()
  {
    return this.holder2BatteryVoltage;
  }
  
  public boolean isFlag(int paramInt)
  {
    return isFlag(this.flags, paramInt);
  }
  
  public String toString()
  {
    return "BatteryInformation{\n flags (binary)=" + Integer.toBinaryString(this.flags) + ",\n chargerBatteryLevel=" + this.chargerBatteryLevel + ",\n chargerBatteryTemperature=" + this.chargerBatteryTemperature + ",\n chargerBatteryVoltage=" + this.chargerBatteryVoltage + ",\n holder1BatteryLevel=" + this.holder1BatteryLevel + ",\n holder1BatteryTemperature=" + this.holder1BatteryTemperature + ",\n holder1BatteryVoltage=" + this.holder1BatteryVoltage + ",\n holder2BatteryLevel=" + this.holder2BatteryLevel + ",\n holder2BatteryTemperature=" + this.holder2BatteryTemperature + ",\n holder2BatteryVoltage=" + this.holder2BatteryVoltage + "\n}";
  }
}

蓝牙通讯的数据结果是

0f004425400f64 // 这个结果是已经通过数组转字符串的结果

研究了半天,不知道这段代码怎么对应,其他的蓝牙通讯结果都是直接16进制转字符串,这段直接转会是一段无意义的英文字段。

求解读数据结果,和解读的方法

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文