beautypg.com

Packets in general – Innovate Motorsports OT-2 SDK User Manual

Page 13

background image

13

Packets in General


As covered above, in ‘in band’ (normal) MTS communication, hosts receive two types of
packets, data, and query responses. The packets are almost identical (they are
distinguished by one bit in the header). The basic structure is:


Note that “Word” means two bytes (16 bits), and they are sent in “Big Endian” order, that
is, 0x1234 would be sent in two consecutive bytes, ‘0x12’, then ‘0x34’. For better or
worse, there is no checksum or other form of error checking.

In the Serial 2 document, the header looks a bit daunting:

Header Word

Word

Bit
15

Bit
14

Bit
13

Bit
12

Bit
11

Bit
10

Bit
9

Bit
8

Bit
7

Bit
6

Bit
5

Bit
4

Bit
3

Bit
3

Bit
1

Bit
0

0

1

R

1

D/S HF

X

1

B7

1

B6

B5

B4

B3

B2

B1

B0


But it really breaks down into just a few simple things. First, there are some fixed values:

Word

Bit
15

Bit
14

Bit
13

Bit
12

Bit
11

Bit
10

Bit
9

Bit
8

Bit
7

Bit
6

Bit
5

Bit
4

Bit
3

Bit
3

Bit
1

Bit
0

0

1

R

1

D/S HF

X

1

B7

1

B6

B5

B4

B3

B2

B1

B0



These uniquely identify the header from any other in band data sent. When you start
monitoring the stream of bytes you can begin by AND’ing each byte with 0xA2 and
seeing if the result is 0xA2. If it is, you might have synced to the first byte of a packet. If
you AND the next byte with 0x80 and get 0x80, you can be sure. This test should not
pass at any other point in the data stream except the beginning of a packet.

Next, we have the length (in words) of what is to follow:

Word

Bit
15

Bit
14

Bit
13

Bit
12

Bit
11

Bit
10

Bit
9

Bit
8

Bit
7

Bit
6

Bit
5

Bit
4

Bit
3

Bit
3

Bit
1

Bit
0

0

1

R

1

D/S HF

X

1

B7

1

B6

B5

B4

B3

B2

B1

B0


This is one byte, so the maximum payload size is 255 words, or 510 bytes. One oddness
is that, because of the fixed values, the size is split and has to be reassembled. But, if you
count off received data, this reconstructed length will lead you to the next header.