Skip to content

Commit 89415c0

Browse files
authored
Merge pull request #4 from taichunmin/mermaid-packet
use mermaid packet to describe frame and two cmds
2 parents 6e2f7c7 + 7569740 commit 89415c0

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

protocol.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Global firmware+CLI versions are following the [semantic versioning](https://semver.org/) logic mostly regarding the protocol version, so third party clients (GUIs, mobile apps, SDKs) can rely on firmware version to know their level of compatibility.
66

77
Given a version number MAJOR.MINOR.PATCH, we will increment the:
8+
89
* MAJOR version when we are breaking the existing protocol format
910
* MINOR version when we are extending the protocol format in a backward compatible manner (new commands,...)
1011
* PATCH version when we are releasing bugfixes not affecting the protocol description
@@ -18,15 +19,29 @@ For the development channel, a client compatible with versions X.y.z can accept
1819
Cf [GET_APP_VERSION](#1000-get_app_version) and [GET_GIT_VERSION](#1017-get_git_version).
1920

2021
When `GET_GIT_VERSION` returns only a tag and no commit hash info (on a release tag), one can query the corresponding hash with the GitHub API, e.g.
22+
2123
```
2224
"4747d3884d21e0df8549e3029a920ea390e0b00a"
2325
```
26+
2427
## Frame format
2528

2629
The communication between the firmware and the client is made of frames structured as follows:
2730

2831
![](images/protocol-packet.png)
2932

33+
```mermaid
34+
packet
35+
+8: "SOF"
36+
+8: "LRC1"
37+
+16: "CMD"
38+
+16: "STATUS"
39+
+16: "LEN"
40+
+8: "LRC2"
41+
+48: "DATA (variable length)"
42+
+8: "LRC3"
43+
```
44+
3045
- **SOF**: `1 byte`, "**S**tart-**O**f-**F**rame byte" represents the start of a packet, and must be equal to `0x11`.
3146
- **LRC1**: `1 byte`, LRC over `SOF` byte, therefore must be equal to `0xEF`.
3247
- **CMD**: `2 bytes`, each command have been assigned a unique number (e.g. `DATA_CMD_SET_SLOT_TAG_NICK` = `1007`).
@@ -58,13 +73,80 @@ Beware, slots in protocol count from 0 to 7 (and from 1 to 8 in the CLI...).
5873
In the following list, "CLI" refers to one typical CLI command using the described protocol command. But it's not a 1:1 match, there can be other protocol commands used by the CLI command and there can be other CLI commands using the same protocol command...
5974

6075
### 1000: GET_APP_VERSION
76+
77+
* CLI: cf `hw version`
78+
79+
```mermaid
80+
---
81+
title: "Command Packet"
82+
---
83+
packet
84+
+8: "SOF"
85+
+8: "LRC1"
86+
+16: "CMD (=1000)"
87+
+16: "STATUS"
88+
+16: "LEN (=0)"
89+
+8: "LRC2"
90+
+8: "LRC3"
91+
```
92+
6193
* Command: no data
94+
95+
```mermaid
96+
---
97+
title: "Response Packet"
98+
---
99+
packet
100+
+8: "SOF"
101+
+8: "LRC1"
102+
+16: "CMD (=1000)"
103+
+16: "STATUS"
104+
+16: "LEN (=2)"
105+
+8: "LRC2"
106+
+8: "major version"
107+
+8: "minor version"
108+
+8: "LRC3"
109+
```
110+
62111
* Response: 2 bytes: `version_major|version_minor`
63-
* CLI: cf `hw version`
112+
64113
### 1001: CHANGE_DEVICE_MODE
65-
* Command: 1 byte. `0x00`=emulator mode, `0x01`=reader mode
66-
* Response: no data
114+
67115
* CLI: cf `hw mode`
116+
117+
```mermaid
118+
---
119+
title: "Command Packet"
120+
---
121+
packet
122+
+8: "SOF"
123+
+8: "LRC1"
124+
+16: "CMD (=1001)"
125+
+16: "STATUS"
126+
+16: "LEN (=1)"
127+
+8: "LRC2"
128+
+8: "new device mode"
129+
+8: "LRC3"
130+
```
131+
132+
* device mode: `0x00`=emulator mode, `0x01`=reader mode
133+
134+
```mermaid
135+
---
136+
title: "Response Packet"
137+
---
138+
packet
139+
+8: "SOF"
140+
+8: "LRC1"
141+
+16: "CMD (=1001)"
142+
+16: "STATUS"
143+
+16: "LEN (=0)"
144+
+8: "LRC2"
145+
+8: "LRC3"
146+
```
147+
148+
* Response: no data
149+
68150
### 1002: GET_DEVICE_MODE
69151
* Command: no data
70152
* Response: data: 1 byte. `0x00`=emulator mode, `0x01`=reader mode

0 commit comments

Comments
 (0)