NRF52 Java未签名字节问题

发布于 2025-02-09 01:05:15 字数 449 浏览 2 评论 0原文

我正在与NRF52一起使用BLE并从Android带有Java的字节数组命令,如下面

byte[] header=new byte[]{
            (byte )0x5f,
            (byte) 0xf0,
            (byte) 0xf1,
            (byte) 0xf2,
    };

,当我将这些字节登录到控制台时,我会看到以下

[111,-16,-15,-14]

设备获取命令,但不会发送答案,

但是,如果我从iOS发送相同的命令,借助Swift,命令数据如下所示

[111,240,241,242]

,并在Aspected上工作。

什么可能导致这种行为?可能与Java的未命名字节支持有关吗?

I am using ble with nrf52 and sending a byte array command from android with java like below

byte[] header=new byte[]{
            (byte )0x5f,
            (byte) 0xf0,
            (byte) 0xf1,
            (byte) 0xf2,
    };

when I log these bytes to console, I see as below

[111,-16,-15,-14]

Device gots the command but doesn't send answer

However, if I send the same command from iOS with swift, command data showns as below

[111,240,241,242]

and works as aspected.

What may cause this behavior? May it be related java's unsingned byte support?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2025-02-16 01:05:15

您在正确的轨道上。当您的iOS应用程序将收到的数据处理为“未签名字节”时,Android应用将其解释为“签名字节”。您可能需要使用相应的 *无符号方法将它们视为无符号值,例如 byte.compareunsigned

You are on the right track. While your iOS App handles the received data as 'unsigned bytes' the Android App interprets them as 'signed bytes'. You might want to treat them as unsigned values with the corresponding *unsigned methods, for example Byte.compareUnsigned

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文