diff options
Diffstat (limited to 'rpi2/design.txt')
-rw-r--r-- | rpi2/design.txt | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/rpi2/design.txt b/rpi2/design.txt new file mode 100644 index 0000000..6957ad5 --- /dev/null +++ b/rpi2/design.txt @@ -0,0 +1,105 @@ +Arduino + +RPi modules: + - Serial communication + - Wireless map distribution + - Routing module + +Considerations: + - Disable XON/XOFF or bytes 0x11 and 0x13 get eaten by the RPi. + - RPi off, Uno turns on. Uno does not need to wait for RPi. + - RPi already on, Uno just turns on. RPi needs to wait for Uno and then perform + a reset. + - RPi is basically the client (controlling the server) + - Uno is basically the server + +[RPi]->Uno serial handshake: + 1. Send RESET1 command. + 2. Read a byte. + - If it is ACK1, goto 3. + - Else repeat 1. + 3. Send RESET2 command. + 4. Read a byte. + - If it is ACK1, repeat 4. + - If it is ACK2, finish. + - Else goto 1. + +RPi->[Uno] serial handshake (state = UNKNOWN): + 1. Read a byte. + - If equal to RESET1, goto 2. + - Else write OUTOFSYNC and finish. + 2. Discard buffers and send ACK1. + 3. Wait for byte. + - If it is RESET1, goto 2. + - If it is RESET2, write ACK2, set state = READY and finish. + - Else ignore and finish. + +Protocol (byte-oriented): +Higher-level header (1-2 bytes): +10.. .... + 00 00.. (Handshake, chosen to reduce need to escape signed bytes) + 01 RESET1 ([RPi]->Uno) / ACK1 ([Uno]->RPi) + 10 RESET2 ([RPi]->Uno) / ACK1 ([Uno]->RPi) + 11 OUTOFSYNC, please reset ([Uno]->RPi) + 00 0000 PING ([Uno]->RPi) / PONG ([RPi]->Uno) + 00 0100 00.. .... DATA_ESCAPE ([Uno]->RPi) Read as 10.. .... + 00 1... 101. .... DATA_LEN2 ([Uno]->RPi) max len 256, len=...+1) + .. .... DATA_LEN1 ([Uno]->RPi) max len 56, len=...-7) + +Rationale for no PING from RPi to Uno is because the Pi is helpless if the +Arduino died. +Rationale for DATA_ESCAPE is to avoid interpretation as handshake. +Rationale for DATA_LEN2 encoding is to avoid interpreting as handshake, but +still pass the length definition to the control handler. + +Note: data length describes the length of decoded bytes following the header. +Example for sending the byte sequence for debug print: + + 1111 0000 0111 1111 1011 1111 + aaaa bbbb cccc dddd eeee ffff + +becomes: + + 1000 0110 1111 0000 0111 1111 1000 0000 0011 1111 + (len=3) aaaa bbbb cccc dddd eeee eeee eeee ffff + + +Data is interpreted as follows: + +0... .... .... .... Bits that need to be updated (max 15). The length of the + following data depends on this. +1000 0000 Debug packet, max len is determined by higher-level hdr. + +Serial state machine: + +init -->-- Device unavailable + / \ + | \ + v device connected ^ IO error + | | + \ / + Device available - + +RPi architecture + + main + | + +-----+------+---------------+ + | | | +serial route map sync + I/O finder with others (optional) + +route finder: + - updates map based on data updates + - suggests alternative directions + +serial I/O + - queues map updates from Uno and fwds to route finder + - takes route suggestions and fwds to Uno + +Linear flow: + - I/O (in) has data update + - data update dispatch to route finder + - route finder calculates optimal route to target + - route finder gives next directions + - I/O (out) to Uno |