Introduction
Using this protocol, data can be securely exchanged between an application on a Personal Computer and Robox controls via serial channel. It differs from serial mode 0 communication (terminated strings) in that both requests and responses are encapsulated and protected by CRC. Only formally correct directives (valid CRC) will be executed.
NOTE: Flash management directives (file upload/download) cannot be used using this protocol.
By enabling this protocol on a serial channel, it is reserved exclusively for the system, so it is not possible for the user to use functions like ser_in(), ser_out().
Protocol enabling
The following directive should be used to enable this protocol: PSER DLE_AscII.
Protocol disabling
To disable this protocol and re-enable the standard AscII protocol, the following directive should be used: PSER AscII.
To disable this protocol and re-enable the BCC3 protocol for communication with the RDE development environment, the following directive should be used: PSER_DLE_BCC3.
Packet format
DLE-AscII transmission does not need the transmission prefixes :DrT: . The transmitted command does not need to be terminated by LF (see ascii communication in mode 0 - terminated string).
The format of request transmission from PC to Robox control has the following structure:
Elem. |
Dim. (byte) |
Value |
Meaning |
---|---|---|---|
I |
1 |
0x10 (DLE) |
Command byte identification character |
II |
1 |
0x02 (STX) |
Buffer start code |
III |
1 |
0x21 |
Code for protocol (DLE-AscII) |
IV |
N Max 256 bytes |
…. |
Terminated ascii directive (string terminated by 0). CR and/or LF terminators are not needed. Any 0x10 (DLE) characters MUST be doubled. NOTE: In CRC calculation only one is considered. |
V |
1 |
0x10 (DLE) |
Command byte identifier character |
VI |
1 |
0x03(ETX) |
End buffer code |
VII |
2 |
Crc16 |
CRC value of elements: III. and IV. (original element IV) |
Requests are only assumed if the structure is recognized and the received CRC matches the calculated CRC. If there is no match, the command is ignored.
Example
"D VE" command
The format of response transmission from Robox control to PC has the following structure:
NOTE: In case of multiresponse, each individual response is encapsulated in the DLE-STX structure ... DLE-ETX CRC. |
Calculation of CRC16
The calculation of crc16 is done with the polynomial 0x1021. The initial value of crc is 0xFFFF. (crc16_be)
Example
Below is the software in C code to be used to calculate the value of CRC:
#define CRC16_POLINOMIAL 0x1021 // (x16+x12+x5+1) #define INITIAL_CRC 0xFFFF // initial value of CRC typedef unsigned short U16 typedef unsigned char U8 U16 TableValues[256]; // table initialization routine void CreateTable (U16 nPolynomial) { int i, j, k; U16 nCRC; memset(TableValues,0, sizeof(U16) *256); // calculate the CRC value for index position n for (i=0;i<256; i++) { k = i << 8; nCRC = 0; for (j=0; j<8; j++) { if ((nCRC ^ K) & 0x8000) nCRC = (U16) ( (nCRC <<1) ^nPolynomial); else nCRC <<=1; k <<= 1; } TableValues[i] = nCRC; } } // CRC calculation routine // want pointer to buffer // number of bytes // initial value of CRC (or previous value if used incrementally) // returns value of CRC U16 CalculateCRC16 (const void* pData, long nCount, U16 InitVal) { U8 *p = U8* (pData); U16 crc = InitVal; while (nCount--) crc = U16( (crc<<8) ^ TableValues[U8( (crc>>8)^*p++ )] ); return crc; } |