gpt4 book ai didi

android - 如何创建指定的帧并通过蓝牙发送?

转载 作者:行者123 更新时间:2023-11-29 01:41:48 26 4
gpt4 key购买 nike

我正在开发一个应用程序,它应该通过蓝牙从非安卓设备发送和接收数据包。我正在使用此处的示例源代码来管理连接和设备配对:

http://www.aimagin.com/learn/index.php/Interfacing_FiO_Board_and_Android_Phone_via_Bluetooth_%28Between_Andriod_and_FiO_-_Closed_Loop%29#Target_Model:Receiver_and_Sender

主机 - 安卓手机
设备 - 我的设备(更不像上面链接中的这个 FiO 板)

现在我想从这个表创建和发送请求(第 1 步):

http://postimg.org/image/4n8yf27qr/

我是这样做的:

byte[] sendingbytes = new byte[6+8]; //byte array for packet

ByteBuffer buff2 = ByteBuffer.wrap(sendingbytes).order(ByteOrder.LITTLE_ENDIAN); //wrapping byte array for modification


// Get ID, Get serial (request)
// ----------------------------------------- //
// 0xAA | 1000 0000 | 2 | 0x83; 0x84 | CRC //
// ----------------------------------------- //
buff2.put((byte) 0xAA); //Header 0xAA
buff2.put((byte) 0x80); //flag 1000 0000

buff2.putInt((byte) 2);

buff2.put((byte) 0x83); //data 0x83
buff2.put((byte) 0x84); //data 0x84

buff2.put((byte) 0xFF); //CRC always FFFFh for testing
buff2.put((byte) 0xFF); //

if (mState == STATE_CONNECTED) mConnectedThread.write(sendingbytes);

我的设备应该像第 2 步那样用数据包响应该请求。

我的问题是:

1.如何像步骤1一样正确创建数据包,
2.当设备发回给我时如何解码数据包(第 2 步)。

提前致谢!

最佳答案

我想通了。一个命令的正确数据包是:

buff2.put((byte) 0xAA); //Header 0xAA
buff2.put((byte) 0x80); //flag 1000 0000

buff2.put((byte) 0x01); //data length
buff2.put((byte) 0x00); //data length

buff2.put((byte) 0x83); //data 0x83

buff2.put((byte) 0xFF); //CRC always FFFFh for testing
buff2.put((byte) 0xFF); //

关于android - 如何创建指定的帧并通过蓝牙发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24077378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com