通用串行通信協議(串口&藍牙Ble等)

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章