Bluetooth LE Testing Over UART
来源:互联网 发布:财经数据哪个网站 编辑:程序博客网 时间:2024/05/01 13:18
转载https://waynebayever.wordpress.com/2014/12/17/bluetooth-le-testing-over-uart/
Bluetooth LE Testing Over UART
In Classic Bluetooth, all you need to do to test the RF layer is put your device into DUT (Device Under Test) mode and the Bluetooth test equipment can control your device, the EUT (Equipment Under Test) and run the required tests. Bluetooth LE, or Bluetooth Smart, on the other hand, requires the test equipment to control the EUT over a wired connection. There are several options for controlling your EUT. These options are listed in the Core Specification in Volume 6 Part F. They are:
- 2-wire UART – a simple serial communication protocol
- HCI – Host Controller Interface through a serial port like RS232 (UART) or USB
In this article, I am only going to describe the protocol for using HCI over a UART connection.
The first thing to know about HCI is that the Host sends Commands to the Bluetooth Controller and the Controller responds with Events. Bluetooth LE testing requires only 4 HCI commands: Reset, Transmitter Test, Receiver Test, and Test End. Each of these Commands has an OpCode and some commands have parameters. Events have an Event Code and may also have parameters, depending on the Command to which it is responding.
Now, to understand HCI over UART, you have to know that Commands are preceded by a single byte 0x01 and Events are preceded by 0x04. This is described in Volume 4 Part A.2 of the Core Spec.
Reset
Let’s get into the details. Reset is a simple command, since it has no parameters. See Volume 2 Part E Section 7.3.2. The Reset Command looks like this:
0x01, 0x03, 0x0C, 0x00
- 0x01 – the single byte that precedes all Commands in HCI over UART
- 0x03 0x0C – this is the OpCode for the Reset Command. OpCodes are sent as a 2 byte Little Endian word (low byte is sent first) with the upper 6 bits being the OGF (Opcode Group Field), used to group Commands together, and the lower 10 bits are the OCF (OpCode Command Field). In this case, the OGF is 0x03 (000011b) and the OCF is 0x03 (0000000011b). Together that makes 00001100 00000011b, or 0x0C03, which is 0x03 0x0C in Little Endian. The details can be found in Volume 2 Part E Section 5.4.1 of the Core Spec.
- 0x00 – number of parameter bytes. In this case there are no parameters, so this field is 0.
The Controller sends an Event back to the Host to acknowledge the Reset Command. The format for this Event is
0x04, 0x0E, <Commands Available>, 0x01, 0x03, 0x0C, <status>
- 0x04 – the single byte that precedes all Events in HCI over UART
- 0x0E – Command Complete Event Code
- <Commands Available> – how many commands the Controller is able to receive
- 0x01 0x03 0x0C – these are the HCI over UART byte and the Opcode that are being sent back to the Host
- <status> – 0x00 if the command was successful, any other value indicates an error. See Volume 2 Part D of the Core Spec for a list of error codes.
LE Test End
The LE Test End Command is just as simple as the Reset Command, but the Event is a slightly more complicated. See Volume 2 Part E Section 7.8.30. Here is the command:
0x01, 0x1F, 0x20, 0x00
- 0x01 – HCI over UART Command byte
- 0x1F 0x20 – OpCode. In this case the OGF is 0x08 (001000b) and the OCF is 0x1F (0000011111b) which makes 00100000 00011111b or 0x201F.
- 0x00 – there are no parameters
The Event does have a parameter and that is a 2 byte word indicating the number of packets sent/received by the previous Transmitter Test or Receiver Test Command. The format is as follows:
0x04, 0x0E, <Commands Available>, 0x01, 0x1F, 0x20, <status>, <2-byte number of packets>
- 0x04 – the single byte that precedes all Events in HCI over UART
- 0x0E – Command Complete Event Code
- <Commands Available> – how many commands the Controller is able to receive
- 0x01 0x1F 0x20 – these are the HCI over UART byte and the Opcode that are being sent back to the Host
- <status> – 0x00 if the command was successful, any other value indicates an error. See Volume 2 Part D of the Core Spec for a list of error codes
- <2-byte number of packets> – Little Endian count of number of packets sent or received
LE Receiver Test
The LE Receiver Test Command has one parameter – the receive channel. See Volume 2 Part E Section 7.8.28. Here is the command:
0x01, 0x1D, 0x20, 0x01, <channel>
- 0x01 – HCI over UART Command byte
- 0x1D 0x20 – OpCode. In this case the OGF is 0x08 (001000b) and the OCF is 0x1D (0000011101b) which makes 00100000 00011101b or 0x201D.
- 0x01 – there is one parameter
- <channel> – the formula is N = (F – 2402) / 2, the range is 0x00 to 0x27 (39)
The Event has the same format as the Reset Event with no parameters. The format for this Event is
0x04, 0x0E, <Commands Available>, 0x01, 0x1D, 0x20, <status>
- 0x04 – the single byte that precedes all Events in HCI over UART
- 0x0E – Command Complete Event Code
- <Commands Available> – how many commands the Controller is able to receive
- 0x01 0x1D 0x20 – these are the HCI over UART byte and the Opcode that are being sent back to the Host
- <status> – 0x00 if the command was successful, any other value indicates an error. See Volume 2 Part D of the Core Spec for a list of error codes.
LE Transmitter Test
The LE Transmitter Test Command has 3 parameters – the transmit channel. See Volume 2 Part E Section 7.8.29. Here is the command:
0x01, 0x1E, 0x20, 0x03, <channel>, <data length>, <packet type>
- 0x01 – HCI over UART Command byte
- 0x1E 0x20 – OpCode. In this case the OGF is 0x08 (001000b) and the OCF is 0x1E (0000011110b) which makes 00100000 00011110b or 0x201E.
- 0x03 – there 3 parameters
- <channel> – the formula is N = (F – 2402) / 2, the range is 0x00 to 0x27 (39)
- <data length> – 0x00 to 0xFF (0 to 255 bytes)
- <packet type> – see the following table:
The Event has the same format as the Reset Event with no parameters. The format for this Event is
0x04, 0x0E, <Commands Available>, 0x01, 0x1E, 0x20, <status>
- 0x04 – the single byte that precedes all Events in HCI over UART
- 0x0E – Command Complete Event Code
- <Commands Available> – how many commands the Controller is able to receive
- 0x01 0x1E 0x20 – these are the HCI over UART byte and the Opcode that are being sent back to the Host
- <status> – 0x00 if the command was successful, any other value indicates an error. See Volume 2 Part D of the Core Spec for a list of error codes.
Final Words
Make sure to call LE Test End after a call to LE Transmitter Test or LE Receiver Test before calling the next Command. Also, if your serial port read is asynchronous, make sure to read the full Event from the port since the Event bytes could be sent in multiple asynchronous messages.
- Bluetooth LE Testing Over UART
- About Bluetooth LE
- BlueTooth Over Wince
- ADB Debugging over Bluetooth
- Bluetooth LE(低功耗蓝牙) - 第一部分
- Bluetooth LE(低功耗蓝牙) - 第二部分
- Bluetooth LE(低功耗蓝牙) - 第三部分
- Bluetooth LE(低功耗蓝牙) - 第四部分
- Bluetooth LE(低功耗蓝牙) - 第五部分
- Bluetooth LE SMP的简单流程
- Bluetooth LE(低功耗蓝牙) - 第一部分
- Bluetooth LE(低功耗蓝牙) - 第二部分
- Bluetooth LE(低功耗蓝牙) - 第三部分
- Bluetooth LE(低功耗蓝牙) - 第四部分
- Bluetooth LE(低功耗蓝牙) - 第五部分
- Bluetooth LE(低功耗蓝牙) 系列
- Bluetooth LE(低功耗蓝牙) - 第六部分(完)
- android4.3 Bluetooth(le)分析之startLeScan分析
- maven在myeclipse10中的集成
- String类的获取功能(方法)
- opencv拟合椭圆
- 玩转Android Camera开发(一):Surfaceview预览Camera,基础拍照功能完整demo
- "ld: library not found for -l...."
- Bluetooth LE Testing Over UART
- Objective-c语言的历史及简介
- SQL(十三)-LIKE和MIN
- form表单上传文件返回数据
- JAVA IO流
- String类的转换功能(方法)
- View调用invalidate()和requestLayout()的过程
- Unity Shader Example 22 (Simulate Projector)
- Oracle start with connect by prior 用法(递归查询树形结构)