1. 协议格式
Package (7~512 bytes)
| 1 byte | 4 bytes | 0~507 bytes | 2 bytes |
|---|---|---|---|
| Magic byte,有效值为0xAB | Header | Value | CRC16 |
Header (4 bytes)
| 1 byte | 4 bits | 4 bits | 2byts |
|---|---|---|---|
| Command id | Version | Reserve | Key header |
Key header (2 bytes)
| 1 byte | 7 bits | 9 bits |
|---|---|---|
| Key | Reserve | Value length |
CRC16 (2 bytes)
(Magic byte + Header + Value)进行CRC16计算
| 1 byte | 1byte |
|---|---|
| 15~8bits | 7~0bits |
2. Command详解
2.1 Command列表
| Command ID | 定义 |
|---|---|
| 0x01 | 固件升级命令 |
| 0x02 | 设置命令 |
| 0x02 | ... |
2.2 固件升级命令(command id 0x01)
2.2.1 协议版本号
当前版本号为0。
2.2.2 固件升级命令key列表
| Key | 定义 |
|---|---|
| 0x01 | 进入固件升级模式请求 |
| 0x02 | 进入固件升级模式返回 |
2.2.3 进入固件升级模式请求Key
2.2.3.1 功能描述
手机端通过这个Key让设备进入固件升级模式。
2.2.3.2 Value 内容描述
Vaule 为空。
例如:
| 1byte | 1 byte | 4 bits | 4 bits | 1 byte | 7 bits | 9 bits | 0 byte | 2 bytes |
|---|---|---|---|---|---|---|---|---|
| Magic byte | Command id | Version | Reserve | Key | Reserve | Value length | Value | CRC16 |
| 0xAB | 0x01 | 0x00 | 0x00 | 0x01 | 0x00 | 0x00 | -- | 0xDB4A |
2.2.4 进入固件升级模式返回Key
2.2.4.1 功能描述
设备通过这个Key返回是否成功进入OTA。
2.2.4.2 Value 内容描述
| 1 byte | 1 byte |
|---|---|
| Status code | Error code |
| Status code | 定义 |
|---|---|
| 0x00 | 进入OTA成功,Error code无意义 |
| 0x01 | 进入OTA失败 |
| Error code | 定义 |
|---|---|
| 0x01 | 电量过低 |
例如:
| 1byte | 1 byte | 4 bits | 4 bits | 1 byte | 7 bits | 9 bits | 2 bytes | 2 bytes |
|---|---|---|---|---|---|---|---|---|
| Magic byte | Command id | Version | Reserve | Key | Reserve | Value length | Value | CRC16 |
| 0xAB | 0x01 | 0x00 | 0x00 | 0x02 | 0x00 | 0x02 | 0x01 0x01 | 0xAB52 |