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_Protocol.md
+38-16Lines changed: 38 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -24,25 +24,47 @@ There are other codes added though:
24
24
* 21 - Ctrl-u - delete line
25
25
* 23 - Ctrl-w - delete word (currently just does the same as Ctrl-u)
26
26
27
-
###Packet Transfer
27
+
## Packet Transfer
28
28
29
-
Added in 2v25:
29
+
Added in 2v25. There is currently an implementation of this in https://github.com/espruino/EspruinoWebTools/blob/master/uart.js
30
30
31
-
```
32
-
DLE[16],SOH[1],TYPE|LENHI,LENLO,DATA...
33
-
```
31
+
### Control Characters
34
32
35
-
If received or timed out (after 1s), will reply with an ACK[6] or NAK[21]
33
+
Packet transfer is initiated by sending the `DOH`[ASCII 16] (Data Link Escape) control character, followed by the `SOH`[ASCII 1] (Start of Heading) control character.
36
34
37
-
TYPE is:
35
+
### Heading Data
38
36
39
-
```
40
-
PT_TYPE_RESPONSE = 0x0000, // Response to an EVAL packet
41
-
PT_TYPE_EVAL = 0x2000, // execute and return the result as RESPONSE packet
42
-
PT_TYPE_EVENT = 0x4000, // parse as JSON and create `E.on('packet', ...)` event
43
-
PT_TYPE_FILE_SEND = 0x6000, // called before DATA, with {fn:"filename",s:123}
44
-
PT_TYPE_DATA = 0x8000, // Sent after FILE_SEND with blocks of data for the file
45
-
PT_TYPE_FILE_RECV = 0xA000 // receive a file - returns a series of PT_TYPE_DATA packets, with a final zero length packet to end
46
-
```
37
+
Following the initial control characters, the next two bytes signal the type and size of packet being sent. The first 3 bits contain the packet type, the following 13 represent an unsigned integer containing the byte length of the data that will follow.
47
38
48
-
There is currently an implementation of this in https://github.com/espruino/EspruinoWebTools/blob/master/uart.js
39
+
| Packet Type | Hex Representation | 16 bit Binary Representation | Notes |
|`RESPONSE`|`0x0000`|`000-------------`| Response to an `EVAL` packet |
42
+
|`EVAL`|`0x2000`|`001-------------`| Execute and return the result as `RESPONSE` packet |
43
+
|`EVENT`|`0x4000`|`010-------------`| Parse data as JSON and create `E.on('packet', ...)` event |
44
+
|`FILE_SEND`|`0x6000`|`011-------------`| Called before `DATA`, with `{fn:"filename",s:123}`|
45
+
|`DATA`|`0x8000`|`100-------------`| Sent after `FILE_SEND` with blocks of data for the file |
46
+
|`FILE_RECV`|`0xA000`|`101-------------`| Receive a file - returns a series of `DATA` packets, with a final zero length packet to end (calling data?) |
| Length (high) |`0x1FFF`|`---1111111111111`| Maximum packet data length, 8191 bytes |
49
+
50
+
### Responses
51
+
52
+
Following transmission of a packet (or after timeout of 1 second), there will be one of two responses that signal successful or unsuccessful packet transmission.
|`60 19`| The `FILE_SEND` packet type is sent initially, and this initial packet will be 19 bytes. |
67
+
|`7b 22 66 6e 22 3a 22 68 65 6c 6c 6f 2e 74 78 74 22 2c 22 73 22 3a 31 31 7d`| The data that follows is the 19 bytes that contain the JSON specifying which file to create, and that the file will be 11 bytes (the length of "Hello World") <br /> `{"fn":"hello.txt","s":11}`|
68
+
|`10 01`| DOH, SOH, to start another packet transfer |
69
+
|`80 11`| Signals this time that the packet type will be `DATA` and it will be 11 bytes. |
70
+
|`48 65 6c 6c 6f 20 57 6f 72 6c 64`| The 11 bytes of data that contain the string `Hello World`|
0 commit comments