Direkt zum Hauptinhalt

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 Print 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.

  1. Host sends Y to start SYNC Mode.
    Hub responds with K.
  2. Here, Files and Directories are updated.
    Refer to Update an individual file{{@23#bkmrk-update-an-individual}} and Update an individual directory.
  3. Host sends N to stop SYNC Mode.
    Hub responds with K.

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

  1. 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 with Kor with U.
  2. If U was sent, Host repeatedly sends C with 192 bytes of the file as argmuent, or E if EOF is reached.
    Hub responds to each of these packets with K. Hub can respond with U to E if the hash is still not matching.

Update an individual directory

  1. Host sends D with the file path as argument. The file path needs to start with /.
    Hub responds with K.