Table download protocol specification (MT protocol)¶
Special constants¶
Here are the protocol constants:
ESC 0x80000000
LIT 0x80000001
C_MASK 0x10000000
C_START 0x20000000
C_CKLOW 0x30000000
C_CKHIGH 0x40000000
C_DATMASK 0x0FFFFFFF
C_CMDMASK 0xF0000000
Special functions¶
There are the definitions of some special functions:
C_MASK(n) 0x10000000 + n
C_CKLOW(n) 0x30000000 + n
C_CKHIGH(n) 0x40000000 + n
C_START(n) 0x20000000 + n
The table of values¶
Table to transmit: X[i] Y[i], i=0..l
checksum= Sum(i=0..l,X[i]+Y[i])
Sender¶
Start transmission (everything with a delay of “T”), all integers are transmitted as little endian integers
axle mask: MASK array length: l
This is the sender pseudo code:
send ESC
send ESC
send C_MASK(MASK)
send C_CKHIGH(checksum >> 16)
send C_CKLOW(checksum & 0xFFFF)
send C_START(l)
last= ESC
for i in 0..l
for val in X[i],Y[i]
if val==ESC or val==LIT or val==last
send LIT
send val
last= val
send ESC
send ESC
Receiver¶
This is the receiver pseudo code:
mode= MODE_COMMAND
is_selected= False
table_checksum= 0
table_status= STATUS_OK
checksum= 0
current_checksum= 0
status= STATUS_OK
length= 0
current_length= 0
transfer_y= True
loop
val= read() // it is ensured that the read value is different each time
if mode==MODE_VALUE or mode==MODE_LITERAL
new_data= true
if mode==MODE_LITERAL
mode= MODE_VALUE
else
if val==ESC
mode= MODE_COMMAND
new_data= false
if is_selected
status= STATUS_OK
if current_checksum != checksum
status= STATUS_CHECKSUM_ERROR
if current_length != length
status= STATUS_LENGTH_ERROR
if status != STATUS_OK
<make table X[i],Y[i], l empty>
else
TABLE_LENGTH= current_length
table_status= status
elsif val==LIT
mode= MODE_LITERAL
new_data= false
if is_selected and new_data
if not transfer_y
X[current_length]= val
transfer_y= true
else
Y[current_length]= val
transfer_y= false
current_length= current_length + 1
current_checksum = current_checksum + val
elsif mode==MODE_COMMAND
code= val & C_CMDMASK
if code==C_MASK
if val & (1<<(my_axle_index-1))
is_selected= true
else
is_selected= false
elsif code==C_CKHIGH
if is_selected
checksum= (val & C_DATMASK)<<16
elsif code==C_CKLOW:
if is_selected
checksum= checksum | (val & C_DATMASK)
elsif code==C_START
if is_selected
length= val & C_DATMASK
current_length= 0
transfer_y= false
current_checksum= 0
status= STATUS_TRANSMITTING
mode= MODE_VALUE