java - 使用java识别并分离Datagrampacke的数据包中的数据

标签 java android dataformat

嗨,目前我正在开发通过蓝牙与医疗保健设备通信的 Android。医疗保健设备可以发送如下格式的数据包 enter image description here

现在我想知道,如何分别识别 LSB 、 Acces code、 Header 、 Msb 和 Payload 。以及如何从该数据包中检索数据。确实,我对这种数据包开发很陌生。我用谷歌搜索过,但我只得到了理论解决方案。我还想知道我是否可以使用 Datagrampacket 或其他第 3 方 API。请有人为此建议我一些想法和教程。提前致谢。

最佳答案

尝试使用以下方法:

(2475位?可能应该是2472或2480,或者如果 header 是54位,这里应该是2474位) //读取字节

public byte[] readBytes(InputStream inputStream, int length)
        throws IOException {
    byte[] data = new byte[length];
    int len = inputStream.read(data);
    if (len != length) {
        throw new IOException("Read the end of stream.");
    }
    return data;
}


//Get Header data
byte[] headerData = readBytes(inputStream, 9);

// I think header data need to parse again, its structure should look like the following format:
// | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
// |  Version  | Type  | other values  |
// You can parse them to use headerData


// #######################################
// write bytes
public class ByteWriter {
    private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    public void writeBytes(byte[] data) {
        try {
            outputStream.write(data);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public byte[] getBytes() {
        return outputStream.toByteArray();
    }
}

关于java - 使用java识别并分离Datagrampacke的数据包中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12925918/

相关文章:

java - Cobertura 拒绝承认代码已被覆盖

java - 在 Collection View 中迭代 HashMap

安卓自定义通知声音

Tibco 数据报 (TibrvMsg) 的 JavaDocs?

java - 如何选择 Selenium 中的特定元素?

java - 循环遍历列表 - 当索引到达末尾时,从 0 开始

android -- 将部分线性布局隐藏在屏幕外的右侧

Android Wi-Fi Direct 在连接前发送数据

ios - 将 "standardize"网页内容格式导入应用程序的好方法是什么?

java将字符串数据映射到python中的字典