Skip to content
David O'Rourke edited this page May 25, 2018 · 5 revisions

Session (Layer 5)

A Torpedo message is sent as a series of 16-bit values encoded as voltages which vary linearly between 0V and ~+8V The 16-bit value is interpreted as a positive binary integer, this is divided by 8192 and the resulting floating point value is used as the signal voltage.

Each 16-bit value is built as follows:

bits Content
lsb
0-7 Payload
8-11 Counter
12-13 Message part
14-15 Reserved (always 0)
msb

A message has 3-parts a header, body and trailer The message part bits are encoded as follows

bit 13 bit 12 Message part
0 0 No message is being sent
0 1 Header
1 0 Body
1 1 Trailer

The Counter is a 4 bit value. The first packet in a message part has a counter value of 0. The counter value increments for each packet in the part. When the counter reaches a binary value of 1111, the next counter value will be 0000.

Header

The Header is 16 packets long. The payload in the first 4 packets is the 4 character appId which identifies the specific Torpedo Protocol for the message. Where an appId is shorter than 4 characters in length, the first character of the appId will appear in the first packet of the header. A 0 value payload will be used to pad the length of the appId to 4 packets. The payload in the next 4 packets of the header is the length of the message body in packets. This length is a 32-bit binary value encoded across the 4 packets. The 5th packet of the header contains the most significant 8-bits of the message body length. The 8th packet of the header contains the least significant 8-bits of the message body length.

The remaining 8 packets of the header are reserved and should have 0 value payloads.

Body

The Body is exactly long enough for the message that needs to be sent. For a message of n bytes in length, the body will be n packets long and the length n will be encoded as the message length in the header. Each byte of the message is sent in order, that byte being directly encoded in the least significant 8-bits (the payload) of a 16-bit packet.

Trailer

The Trailer follows immediately after the body and is 4 packets long. The payload is a checksum for the message. The payload of first packet of the Trailer is the most significant 8 bits of the 32-bit checksum. The payload final packet of the trailer is the least significant 8 bits of the checksum.

Checksum

Every packet of the header and the body contributes to the checksum using the following algorithm.

The checksum is a 32-bit value which starts at 0. Calculate the value of the counter (bits 8-11 in the packet) modulo 4 Where this modulo reduced value is 0, add the payload to the checksum Where the modulo reduced value is 1, multiply the payload by 256 and add to the checksum Where the modulo reduced value is 2, multiply the payload by 65536 and add to the checksum Where the modulo reduced value is 3, multiply the payload by 16777216 and add to the checksum

If the checksum overflows, any more significant bits above the 32-bit checksum value should be ignored.

Out-Of-Sequence signalling

The Trailer contains only 4 packets. As a result there are 12 values for the counter which cannot occur in a valid Trailer. These are reserved for OOS messaging.

A packet with the binary value msb-0011-1111-0000-0000-lsb is used to signal an abort. On receiving this packet a Torpedo port should silently drop any partially received message and prepare to start receiving the next message.

Example Message

This is an example of the TEXT protocol sending the message 'Hello World!'. All the numbers in the example are hexadecimal

Digital Packet Checksum Meaning
1054 00000054 appId T
1145 00004554 E
1258 00584554 X
1354 54584554 T
1400 54584554 Length (decimal 12)
1500 54584554
1600 54584554
170c 60584554
1800 60584554 Reserved/unused
1900 60584554
1a00 60584554
1b00 60584554
1c00 60584554
1d00 60584554
1e00 60584554
1f00 60584554
2048 6058459c H
2165 6058aa9c e
226c 60c4aa9c l
236c ccc4aa9c l
246f ccc4ab0b o
2520 ccc4cb0b
2657 cd1bcb0b W
276f 3c1bcb0b o
2874 3c1bcb7f r
296c 321c377f l
2a64 3280377f d
2b21 5380377f !
3053 Checksum
3180
3237
337f
Clone this wiki locally