---
# System prepended metadata

title: E1 Bluetooth Protocol
tags: [' protocol', ' e1', ' bluetooth', airvida]

---

---
tags: airvida, e1, bluetooth, protocol
---
# E1 Bluetooth Protocol

## 封包格式

     0 bytes  1         2        3        4        5        6        7         8         9       len+8
     +--------+---------+--------+--------+--------+--------+--------+--------+ +--------+--------+ +--------+
     |   SOF  | VERSION | FLAGS  | LENGTH |    VENDOR ID    |   COMMAND ID    | | PAYLOAD   ...   | | CHECK  |
     +--------+---------+--------+--------+--------+--------+--------+--------+ +--------+--------+ +--------+

| 欄位       | 說明                | 預設值 |
| ---------- | ------------------- | ------ |
| SOF        | 每個封包的開頭      | `0xff` |
| VERSION    | API 版本號碼        | `0x01` |
| FLAGS      | 封包的設定          | `0x01` |
| LENGTH     | payload 的長度      |        |
| VENDOR ID  | 發行商 ID           | `0x0a` |
| COMMAND ID | 指令 ID             |        |
| PAYLOAD    | 指令的內容          |        |
| CHECK      | 同位檢查 (xor gate) |        |

```java=
/**
 * The mask which represents a command.
 * Mask used to retrieve the command from the packet.
 */
COMMAND_MASK = 0x7FFF
/**
 * The mask which represents an acknowledgement.
 * 
 * COMMAND & ACKNOWLEDGMENT_MASK > 0 to know if the command is an acknowledgement.
 * COMMAND | ACKNOWLEDGMENT_MASK     to build the acknowledgement command of a command.
 */
ACKNOWLEDGMENT_MASK = 0x8000
```

## 指令

### Configuration Commands: `0x01nn`

#### 回復原廠設定

```java=
COMMAND_FACTORY_DEFAULT_RESET = 0x0104
```

### Control Commands: `0x02nn`

#### 震動

```java=
COMMAND_SET_VIBRATOR_CONTROL = 0x0206
COMMAND_GET_VIBRATOR_CONTROL = 0x0286
```

Payload 長度: 1 byte

| Payload | 意義 |
| ------- | ---- |
| 0x00    | 關閉 |
| 0x01    | 開啟 | 

#### EQ

```java=
COMMAND_SET_EQ_CONTROL = 0x0214
COMMAND_GET_EQ_CONTROL = 0x0294
```

Payload 長度: 1 byte

| Payload | 意義     |
| ------- | -------- |
| 0x00    | 標準     | 
| 0x01    | 搖滾     |
| 0x02    | 爵士     |
| 0x03    | 人聲增強 |
| 0x04    | 古典     |
| 0x05    | 流行     |

#### 斷開連接

```java=
COMMAND_DISCONNECT = 0x022D
```

### Polled Status Commands: `0x03nn`

#### 電量

```java=
/**
 * Gets the current battery level from the device.
 * Battery level is specified in mV stored as a uint16,
 * e.g. 3,300mV = 0x0CE4
 */
COMMAND_GET_CURRENT_BATTERY_LEVEL = 0x0302
```

Payload 長度: 2 bytes

| Payload | 意義    |
| ------- | ------- |
| 0x0000  | 0mV     |
| 0x0ce4  | 3300mV  |
| 0xffff  | 65535mV | 

### Feature Control Commands: `0x05nn`

#### 是否正在充電（自定義）

```java=
COMMAND_IS_CHARGING = 0x0510
```

#### 負離子（自定義）

```java=
COMMAND_GET_ION_LEVEL = 0x0511
COMMAND_SET_ION_LEVEL = 0x0512
```

Payload 長度: 1 byte

| Payload | 意義 |
| ------- | ---- |
| 0x00    | 關閉 |
| 0x01    | 弱   |
| 0x02    | 中   |
| 0x03    | 強   | 

#### 降噪狀態（自定義）

```java=
COMMAND_GET_ANC_STATE = 0x0513
```
