# Innovative Model Railroad Control System

### Sidebar

Support

Wiki Documentation

Support Forum

Mobile

DIY

User

Wiki writer

Legal

e4s-en

This is an old revision of the document!

# E4S

Eight4Seven

## Message

Len Cmd Slave# Data block 0…5 CRC
8 bit 7 bit 7 bit 4 x 7 bit + 1 x 7 bit with high bits 7 bit

### Len

The length byte has bit 7 always high to signal the start of a message. All other following bytes must have set bit 7 to low.
The length is calculated by the following formula:

 Len = Len(1) + Cmd(1) + Slave#(1) + Data block(5) * n + CRC(1)

### Cmd

The commands are 6 bits, 0…63.
A response to a command has bit 6 set high.

### Slave#

The slave number range is 7 bits, 0…127.

### Data block

A date block has four 7 bit data bytes and one 7 bit byte containing the high bits of the four data bytes.

The smallest message with a data block is:
Cmd + Len + Slave# + Data block + CRC = 1 + 1 + 1 + 5 + 1 = 9
The largest message with five data blocks is:
Cmd + Len + Slave# + 24 * Data block + CRC = 1 + 1 + 1 + (24 * 5) + 1 = 124
The smallest command message is:
Cmd + Len + Slave# + CRC = 1 + 1 + 1 + 1 = 4

### CRC

#### Calculate

The length should exclude the checksum byte.

```byte calcCRC(const byte* msg, byte len) {
byte crc = 0xff;
for( byte i = 0; i < len; i++ ) {
crc ^= msg[i];
}
return crc;
}```

#### Check

The length should include the checksum byte.

```bool checkCRC(const byte* msg, byte len) {
byte crc = msg;
for( byte i = 1; i < len; i++ ) {
crc ^= msg[i];
}
return (crc == 0xFF ? true:false);
}``` 