You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+38-36Lines changed: 38 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ To install in a virtual environment in your current project:
71
71
Usage Examples
72
72
==============
73
73
74
-
See `examples/ble_file_transfer_simpletest.py` for a client example. A stub server implementation is in `examples/ble_file_transfer_stub_server.py`.
74
+
See `examples/ble_file_transfer_simpletest.py<examples/ble_file_transfer_simpletest.py>`_ for a client example. A stub server implementation is in `examples/ble_file_transfer_stub_server.py<examples/ble_file_transfer_stub_server.py>`_.
75
75
76
76
Protocol
77
77
=========
@@ -81,45 +81,45 @@ The file transfer protocol is meant to be simple and easy to implement. It uses
81
81
GATT Service
82
82
--------------
83
83
84
-
The UUID of the service is `0xfebb`, Adafruit's 16-bit service UUID.
84
+
The UUID of the service is ``0xfebb``, Adafruit's 16-bit service UUID.
85
85
86
-
The base UUID used in characteristics is `ADAFxxxx-4669-6C65-5472-616E73666572`. The 16-bit numbers below are substituted into the `xxxx` portion.
86
+
The base UUID used in characteristics is ``ADAFxxxx-4669-6C65-5472-616E73666572``. The 16-bit numbers below are substituted into the ``xxxx`` portion.
87
87
88
88
The service has two characteristics:
89
89
90
-
* version (`0x0100`) - Simple unsigned 32-bit integer version number. Always 1.
91
-
* raw transfer (`0x0200`) - Bidirectional link with a custom protocol. The client does WRITE_NO_RESPONSE to the characteristic and then server replies via NOTIFY. (This is similar to the Nordic UART Service but on a single characteristic rather than two.) The commands over the transfer characteristic are idempotent and stateless. A disconnect during a command will reset the state.
90
+
* version (``0x0100``) - Simple unsigned 32-bit integer version number. Always 1.
91
+
* raw transfer (``0x0200``) - Bidirectional link with a custom protocol. The client does WRITE_NO_RESPONSE to the characteristic and then server replies via NOTIFY. (This is similar to the Nordic UART Service but on a single characteristic rather than two.) The commands over the transfer characteristic are idempotent and stateless. A disconnect during a command will reset the state.
92
92
93
93
Commands
94
94
---------
95
95
96
96
Commands always start with a fixed header. The first entry is always the command number itself encoded in a single byte. The number of subsequent entries in the header will vary by command. The entire header must be sent as a unit so set the characteristic with the full header packet. You can combine multiple commands into a single write as long as the complete header is in the packet.
97
97
98
-
Paths use `/` as a separator and full paths must start with `/`. Directory paths
99
-
must end with `/` when provided as a full path.
98
+
Paths use ``/`` as a separator and full paths must start with ``/``. Directory paths
99
+
must end with ``/`` when provided as a full path.
100
100
101
101
All numbers are unsigned.
102
102
103
103
All values are aligned with respect to the start of the packet.
104
104
105
-
Status bytes are `0x01` for OK and `0x02` for error. Other values for error may be used for specific commands.
105
+
Status bytes are ``0x01`` for OK and ``0x02`` for error. Other values for error may be used for specific commands.
106
106
107
-
`0x10` - Read a file
108
-
++++++++++++++++++++
107
+
``0x10`` - Read a file
108
+
++++++++++++++++++++++
109
109
110
110
Given a full path, returns the full contents of the file.
111
111
112
112
The header is four fixed entries and a variable length path:
113
113
114
-
* Command: Single byte. Always `0x10`.
114
+
* Command: Single byte. Always ``0x10``.
115
115
* 1 Byte reserved for padding.
116
116
* Path length: 16-bit number encoding the encoded length of the path string.
117
117
* Chunk offset: 32-bit number encoding the offset into the file to start the first chunk.
118
118
* Chunk size: 32-bit number encoding the amount of data that the client can handle in the first reply.
119
119
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
120
120
121
121
The server will respond with:
122
-
* Command: Single byte. Always `0x11`.
122
+
* Command: Single byte. Always ``0x11``.
123
123
* Status: Single byte.
124
124
* 2 Bytes reserved for padding.
125
125
* Chunk offset: 32-bit number encoding the offset into the file of this chunk.
@@ -128,40 +128,40 @@ The server will respond with:
128
128
* Chunk-length contents of the file starting from the current position.
129
129
130
130
If the chunk length is smaller than the total length, then the client will request more data by sending:
131
-
* Command: Single byte. Always `0x12`.
131
+
* Command: Single byte. Always ``0x12``.
132
132
* Status: Single byte. Always OK for now.
133
133
* 2 Bytes reserved for padding.
134
134
* Chunk offset: 32-bit number encoding the offset into the file to start the next chunk.
135
135
* Chunk size: 32-bit number encoding the number of bytes to read. May be different than the original size. Does not need to be limited by the total size.
136
136
137
137
The transaction is complete after the server has replied with all data. (No acknowledgement needed from the client.)
138
138
139
-
`0x20` - Write a file
140
-
+++++++++++++++++++++
139
+
``0x20`` - Write a file
140
+
+++++++++++++++++++++++
141
141
142
142
Writes the content to the given full path. If the file exists, it will be overwritten. Content may be written as received so an interrupted transfer may lead to a truncated file.
143
143
144
144
Offset larger than the existing file size will introduce zeros into the gap.
145
145
146
146
The header is four fixed entries and a variable length path:
147
147
148
-
* Command: Single byte. Always `0x20`.
148
+
* Command: Single byte. Always ``0x20``.
149
149
* 1 Byte reserved for padding.
150
150
* Path length: 16-bit number encoding the encoded length of the path string.
151
151
* Offset: 32-bit number encoding the starting offset to write.
152
152
* Total size: 32-bit number encoding the total length of the file contents.
153
153
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
154
154
155
155
The server will repeatedly respond until the total length has been transferred with:
156
-
* Command: Single byte. Always `0x21`.
157
-
* Status: Single byte. `0x01` if OK. `0x02` if any parent directory is missing or a file.
156
+
* Command: Single byte. Always ``0x21``.
157
+
* Status: Single byte. ``0x01`` if OK. ``0x02`` if any parent directory is missing or a file.
158
158
* 2 Bytes reserved for padding.
159
159
* Offset: 32-bit number encoding the starting offset to write. (Should match the offset from the previous 0x20 or 0x22 message)
160
160
* Free space: 32-bit number encoding the amount of data the client can send.
161
161
162
162
The client will repeatedly respond until the total length has been transferred with:
163
-
* Command: Single byte. Always `0x22`.
164
-
* Status: Single byte. Always `0x01` for OK.
163
+
* Command: Single byte. Always ``0x22``.
164
+
* Status: Single byte. Always ``0x01`` for OK.
165
165
* 2 Bytes reserved for padding.
166
166
* Offset: 32-bit number encoding the offset to write.
167
167
* Data size: 32-bit number encoding the amount of data the client is sending.
@@ -170,61 +170,63 @@ The client will repeatedly respond until the total length has been transferred w
170
170
The transaction is complete after the server has received all data and replied with a status with 0 free space and offset set to the content length.
171
171
172
172
173
-
`0x30` - Delete a file or directory
174
-
+++++++++++++++++++++++++++++++++++
173
+
``0x30`` - Delete a file or directory
174
+
+++++++++++++++++++++++++++++++++++++
175
175
176
176
Deletes the file or directory at the given full path. Directories must be empty to be deleted.
177
177
178
178
The header is two fixed entries and a variable length path:
179
179
180
-
* Command: Single byte. Always `0x30`.
180
+
* Command: Single byte. Always ``0x30``.
181
181
* 1 Byte reserved for padding.
182
182
* Path length: 16-bit number encoding the encoded length of the path string.
183
183
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
184
184
185
185
The server will reply with:
186
-
* Command: Single byte. Always `0x31`.
187
-
* Status: Single byte. `0x01` if the file or directory was deleted or `0x02` if the path is a non-empty directory or non-existent.
186
+
* Command: Single byte. Always ``0x31``.
187
+
* Status: Single byte. ``0x01`` if the file or directory was deleted or ``0x02`` if the path is a non-empty directory or non-existent.
188
188
189
-
`0x40` - Make a directory
190
-
+++++++++++++++++++++++++
189
+
``0x40`` - Make a directory
190
+
+++++++++++++++++++++++++++
191
191
192
192
Creates a new directory at the given full path. If a parent directory does not exist, then it will also be created. If any name conflicts with an existing file, an error will be returned.
193
193
194
194
The header is two fixed entries and a variable length path:
195
195
196
-
* Command: Single byte. Always `0x40`.
196
+
* Command: Single byte. Always ``0x40``.
197
197
* 1 Byte reserved for padding.
198
198
* Path length: 16-bit number encoding the encoded length of the path string.
199
199
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
200
200
201
201
The server will reply with:
202
-
* Command: Single byte. Always `0x41`.
203
-
* Status: Single byte. `0x01` if the directory(s) were created or `0x02` if any parent of the path is an existing file.
202
+
* Command: Single byte. Always ``0x41``.
203
+
* Status: Single byte. ``0x01`` if the directory(s) were created or ``0x02`` if any parent of the path is an existing file.
204
204
205
-
`0x50` - List a directory
206
-
+++++++++++++++++++++++++
205
+
``0x50`` - List a directory
206
+
+++++++++++++++++++++++++++
207
207
208
208
Lists all of the contents in a directory given a full path. Returned paths are *relative* to the given path to reduce duplication.
209
209
210
210
The header is two fixed entries and a variable length path:
211
211
212
-
* Command: Single byte. Always `0x50`.
212
+
* Command: Single byte. Always ``0x50``.
213
213
* 1 Byte reserved for padding.
214
214
* Path length: 16-bit number encoding the encoded length of the path string.
215
215
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
216
216
217
217
The server will reply with n+1 entries for a directory with n files:
218
-
* Command: Single byte. Always `0x51`.
219
-
* Status: Single byte. `0x01` if the directory exists or `0x02` if it doesn't.
218
+
* Command: Single byte. Always ``0x51``.
219
+
* Status: Single byte. ``0x01`` if the directory exists or ``0x02`` if it doesn't.
220
220
* Path length: 16-bit number encoding the encoded length of the path string.
221
221
* Entry number: 32-bit number encoding the entry number.
222
222
* Total entries: 32-bit number encoding the total number of entries.
223
223
* Flags: 32-bit number encoding data about the entries.
224
+
224
225
- Bit 0: Set when the entry is a directory
225
226
- Bits 1-7: Reserved
227
+
226
228
* File size: 32-bit number encoding the size of the file. Ignore for directories. Value may change.
227
-
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.) These paths are relative so they won't contain `/` at all.
229
+
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.) These paths are relative so they won't contain ``/`` at all.
228
230
229
231
The transaction is complete when the final entry is sent from the server. It will have entry number == total entries and zeros for flags, file size and path length.
0 commit comments