Komunikation zwischen Hub und Host
GSGR Host2Hub File Sync Protocol
Packet Format
A packet always starts with a colon (:
). This is to filter out unrelated data by e.g. micropython itself.
This is followed by a one byte long identifier specifying the packet type.
Without an argument
Without an argument, the packet is now closed with a closing bracket (]
).
With an argmument
Four digits will specify the length of the following base64 encoded argument.
Packet Types
The Host can send these Packets, the Hub must handle these packets:
Identifier | Type | Meaning | Argmuent |
Y | Actively Sent | Start SYNC Mode | |
D | Actively Sent | Ensure Directory exist | /path/to/dir |
F | Actively Sent | Ensure File has same Hash | /path/to/file SHA256 |
C | Response | CHUNK | 192 Bytes of file |
E | Response | End Of File | |
N | Actively Sent | End SYNC Mode | |
R | Actively Sent | Remove File or Directory | /path/to/file/or/diretory |
P | Actively Sent | Start Program (loop() from /__init__.py) | |
X | Actively Sent | Stop Program | |
& | Actively Sent | Reboot | |
= | Actively Sent | Sync Communication | timestamp |
> | Actively Sent | Enter REPL | |
$ | Actively Sent | Reset State |
The Hub can send these Packets, the Host must handle these packets:
Identifier | Type | Meaning | Argmuent |
K | Response | OK | |
= | Response | Sync Communication | given timestamp |
U | Response | Request File Contents | |
! | Actively Sent | Internal Error | traceback |
E | Actively Sent | User Error | traceback |
$ | Actively Sent | Please Reconnect | |
P | Actively Sent | json-encoded args & kwargs | |
B | Actively Sent | Blocking call, will be inresponsive | |
D | Actively Sent | No more blocking call, will be responsive again |
Routines
Sync all files
If a full tree needs to be synced to the hub, this is the right choice.
- Host sends
Y
to start SYNC Mode.
Hub responds withK
. - Here, Files and Directories are updated.
Refer toUpdate an individual file{{@23#bkmrk-update-an-individual}} and Update an individual directory. - Host sends
N
to stop SYNC Mode.
Hub responds withK
.
The Hub needs to make sure that all files and folders it has, that were not send during sync are deleted.
This can be done by listing all files when Y
is received and removing all files and directories updated via F
and D
.
Finally, when N
is received, all files still on this list are deleted.
Update an individual file
- Host sends
F
. The argument is the file's path and its SHA256 Hash, seperated by a space. The file path needs to start with/
.
Hub responds withK
, or withU
. - If
U
was sent, Host repeatedly sendsC
with 192 bytes of the file as argmuent, orE
if EOF is reached.
Hub responds to each of these packets withK
. Hub can respond withU
toE
if the hash is still not matching.
Update an individual directory
- Host sends
D
with the file path as argument. The file path needs to start with/
.
Hub responds withK
.