蓝牙发送数据需要组成16进制数据帧,我们今天来讲一种优雅高效到组织放式.没有对比就没有伤害,下面我们来伤害一下
原始组帧:
byte[] b = new byte[] { (byte) 0x68, bTypes[0], (byte) frames[0], (byte) frames[1], (byte) frames[2],
(byte) frames[3], (byte) frames[4], (byte) frames[5], (byte) frames[6], (byte) 0x50,
(byte) 0x0A, (byte) 0x0E, (byte) 0x00, (byte) dishuArray[0], (byte) dishuArray[1],
(byte) dishuArray[2], (byte) dishuArray[3], (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE,
(byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, };
StringBuilder ss = new StringBuilder();
for (int i = 0; i < b.length; i++) {
ss.append(String.format("%02X", b[i] & 0xFF));
}
String string2 = CRC16.crc16(ss.toString());
int m3 = Integer.parseInt(string2.substring(0, 2), 16);
int m4 = Integer.parseInt(string2.substring(2), 16);
// 命令帧内容
byte[] outs = new byte[] { (byte) 0x68, bTypes[0], (