User Tools

Site Tools


e4s-en

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

e4s-en [2018/11/12 08:56] (current)
Line 1: Line 1:
 +====== 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.\\
 +<code C>
 +byte calcCRC(const byte* msg, byte len) {
 +  byte crc = 0xff;
 +  for( byte i = 0; i < len; i++ ) {
 +    crc ^= msg[i];
 +  }
 +  return crc;
 +}
 +</​code>​
 +
 +===Check====
 +The length should include the checksum byte.\\
 +<code C>
 +bool checkCRC(const byte* msg, byte len) {
 +  byte crc = msg[0];
 +  for( byte i = 1; i < len; i++ ) {
 +    crc ^= msg[i];
 +  }
 +  return (crc == 0xFF ? true:​false);​
 +}
 +</​code>​
e4s-en.txt ยท Last modified: 2018/11/12 08:56 (external edit)