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:

IdentifierTypeMeaningArgmuent
YActively SentStart SYNC Mode
DActively SentEnsure Directory exist/path/to/dir
FActively SentEnsure File has same Hash/path/to/file SHA256
CResponseCHUNK192 Bytes of file
EResponseEnd Of File
NActively SentEnd SYNC Mode
RActively SentRemove File or Directory/path/to/file/or/diretory
PActively SentStart Program (loop() from /__init__.py)
XActively SentStop Program
&Actively SentReboot
=Actively SentSync Communicationtimestamp
>Actively SentEnter REPL
$Actively SentReset State

The Hub can send these Packets, the Host must handle these packets:

IdentifierTypeMeaningArgmuent
KResponseOK
=ResponseSync Communicationgiven timestamp
UResponseRequest File Contents
!Actively SentInternal Errortraceback
EActively SentUser Errortraceback
$Actively SentPlease Reconnect
PActively SentPrintjson-encoded args & kwargs
BActively SentBlocking call, will be inresponsive
DActively SentNo 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 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.