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
+64-3Lines changed: 64 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,9 +87,18 @@ The base UUID used in characteristics is ``ADAFxxxx-4669-6C65-5472-616E73666572`
87
87
88
88
The service has two characteristics:
89
89
90
-
* version (``0x0100``) - Simple unsigned 32-bit integer version number. Always 1.
90
+
* version (``0x0100``) - Simple unsigned 32-bit integer version number. May be 1 - 4.
91
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
+
Time resolution
94
+
---------------
95
+
96
+
Time resolution varies based filesystem type. FATFS can only get down to the 2 second bound after 1980. Littlefs can do 64-bit nanoseconds after January 1st, 1970.
97
+
98
+
To account for this, the protocol has time in 64-bit nanoseconds after January 1st, 1970. However, the server will respond with a potentially truncated version that is the value stored.
99
+
100
+
Also note that devices serving the file transfer protocol may not have it's own clock so do not rely on time ordering. Any internal writes may set the time incorrectly. So, we only recommend using the value as a cache key.
101
+
93
102
Commands
94
103
---------
95
104
@@ -151,6 +160,7 @@ The header is four fixed entries and a variable length path:
151
160
* 1 Byte reserved for padding.
152
161
* Path length: 16-bit number encoding the encoded length of the path string.
153
162
* Offset: 32-bit number encoding the starting offset to write.
163
+
* Current time: 64-bit number encoding nanoseconds since January 1st, 1970. Used as the file modification time. Not all system will support the full resolution. Use the truncated time response value for caching.
154
164
* Total size: 32-bit number encoding the total length of the file contents.
155
165
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
156
166
@@ -160,6 +170,7 @@ The server will repeatedly respond until the total length has been transferred w
160
170
* Status: Single byte. ``0x01`` if OK. ``0x02`` if any parent directory is missing or a file.
161
171
* 2 Bytes reserved for padding.
162
172
* Offset: 32-bit number encoding the starting offset to write. (Should match the offset from the previous 0x20 or 0x22 message)
173
+
* Truncated time: 64-bit number encoding nanoseconds since January 1st, 1970 as stored by the file system. The resolution may be less that the protocol. It is sent back for use in caching on the host side.
163
174
* Free space: 32-bit number encoding the amount of data the client can send.
164
175
165
176
The client will repeatedly respond until the total length has been transferred with:
@@ -173,11 +184,13 @@ The client will repeatedly respond until the total length has been transferred w
173
184
174
185
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.
175
186
187
+
**NOTE**: Current time was added in version 3. The rest of the packets remained the same.
188
+
176
189
177
190
``0x30`` - Delete a file or directory
178
191
+++++++++++++++++++++++++++++++++++++
179
192
180
-
Deletes the file or directory at the given full path. Directories must be empty to be deleted.
193
+
Deletes the file or directory at the given full path. Non-empty directories will have their contents deleted as well.
181
194
182
195
The header is two fixed entries and a variable length path:
183
196
@@ -189,7 +202,9 @@ The header is two fixed entries and a variable length path:
189
202
The server will reply with:
190
203
191
204
* Command: Single byte. Always ``0x31``.
192
-
* Status: Single byte. ``0x01`` if the file or directory was deleted or ``0x02`` if the path is a non-empty directory or non-existent.
205
+
* Status: Single byte. ``0x01`` if the file or directory was deleted or ``0x02`` if the path is non-existent.
206
+
207
+
**NOTE**: In version 2, this command now deletes contents of a directory as well. It won't error.
193
208
194
209
``0x40`` - Make a directory
195
210
+++++++++++++++++++++++++++
@@ -201,12 +216,16 @@ The header is two fixed entries and a variable length path:
201
216
* Command: Single byte. Always ``0x40``.
202
217
* 1 Byte reserved for padding.
203
218
* Path length: 16-bit number encoding the encoded length of the path string.
219
+
* 4 Bytes reserved for padding.
220
+
* Current time: 64-bit number encoding nanoseconds since January 1st, 1970. Used as the file modification time. Not all system will support the full resolution. Use the truncated time response value for caching.
204
221
* Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
205
222
206
223
The server will reply with:
207
224
208
225
* Command: Single byte. Always ``0x41``.
209
226
* Status: Single byte. ``0x01`` if the directory(s) were created or ``0x02`` if any parent of the path is an existing file.
227
+
* 6 Bytes reserved for padding.
228
+
* Truncated time: 64-bit number encoding nanoseconds since January 1st, 1970 as stored by the file system. The resolution may be less that the protocol. It is sent back for use in caching on the host side.
210
229
211
230
``0x50`` - List a directory
212
231
+++++++++++++++++++++++++++
@@ -232,11 +251,53 @@ The server will reply with n+1 entries for a directory with n files:
232
251
- Bit 0: Set when the entry is a directory
233
252
- Bits 1-7: Reserved
234
253
254
+
* Modification time: 64-bit number of nanoseconds since January 1st, 1970. *However*, files modifiers may not have an accurate clock so do *not* assume it is correct. Instead, only use it to determine cacheability vs a local copy.
235
255
* File size: 32-bit number encoding the size of the file. Ignore for directories. Value may change.
236
256
* 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.
237
257
238
258
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.
239
259
260
+
``0x60`` - Move a file or directory
261
+
+++++++++++++++++++++++++++++++++++
262
+
263
+
Moves a file or directory at a given path to a different path. Can be used to
264
+
rename as well. The two paths are sent separated by a byte so that the server
265
+
may null-terminate the string itself. The client may send anything there.
266
+
267
+
The header is two fixed entries and a variable length path:
268
+
269
+
* Command: Single byte. Always ``0x60``.
270
+
* 1 Byte reserved for padding.
271
+
* Old Path length: 16-bit number encoding the encoded length of the path string.
272
+
* New Path length: 16-bit number encoding the encoded length of the path string.
273
+
* Old Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
274
+
* One padding byte. This can be used to null terminate the old path string.
275
+
* New Path: UTF-8 encoded string that is *not* null terminated. (We send the length instead.)
276
+
277
+
The server will reply with:
278
+
* Command: Single byte. Always ``0x61``.
279
+
* Status: Single byte. ``0x01`` on success or ``0x02`` on error.
280
+
281
+
**NOTE**: This is added in version 4.
282
+
283
+
Versions
284
+
=========
285
+
286
+
Version 2
287
+
---------
288
+
* Changes delete to delete contents of non-empty directories automatically.
289
+
290
+
Version 3
291
+
---------
292
+
* Adds modification time.
293
+
* Adds current time to file write command.
294
+
* Adds current time to make directory command.
295
+
* Adds modification time to directory listing entries.
0 commit comments