Ward Christensen developed XMODEM, a straightforward file transfer protocol, in 1977. It frequently finds application between two computers employing the XMODEM protocol. The protocol initiates transmission with the ‘C’ character, followed by packets. The receiver provides proper acknowledgment (ACK) for each packet. Identification of the last packet is facilitated by EOT, and the completion of transmission is signaled by ETB.
Contents
Packet Format
Byte-1 | Byte-2 | Byte-3 | Byte 4-129 | Byte 130-131 |
Start of Header | Packet Number | Inverse Packet Number | Packet Data | 16-bit CRC |
Here Byte-1,2,3 are consider as XMODEM protocol Headers. XMODEM Transmission Reception : Image Link
Packet Size and Range
Total size of the packet is 132 Bytes and payload size is 128bytes.
- Start of the header: Size – 1Byte, Value – (0x01).
- Packet Number: Size – 1Byte, Value – 0 to 255, Packet numbering starts with 1, not Zero.
- Inverse of Packet Number: Size – 1Byte, Value – 255 to 0.
- Packet Data: Size – 128Byte.
- CRC XMODEM Size – 2Byte.
Control Characters Definitions
Control Character | Description | Value |
SOH | Start of the Header | 0x01 |
EOT | End of Transmission | 0x04 |
ACK | Acknowledge | 0x06 |
NAK | Not Acknowledge | 0x15 |
ETB | End of Transmission Block | 0x17 |
CAN | Cancel | 0x18 |
C | ASCII “C” | 0x43C |
XMODEM CRC Calculation Code
CRC16 (XMODEM) information’s
- Check = 0x31C3.
- Poly = 0x1021.
- Init = 0x0000.
- RefIn = False.
- RefOut = False.
- XorOut = 0x0000.
int calcrc(char *ptr, int count) { int crc; char i; crc = 0; while (--count >= 0) { crc = crc ^ (int) *ptr++ << 8; i = 8; do { if (crc & 0x8000) crc = crc << 1 ^ 0x1021; else crc = crc << 1; } while(--i); } return (crc); }
Function Name | Parameters | Description |
---|---|---|
calcrc | char *ptr, int count | Calculates the cyclic redundancy check (CRC) value for a given data block. |
Explanation:
- *char ptr: A pointer to the data block for which the CRC is to be calculated.
- int count: Specifies the length of the data block.
The function initializes the CRC value to 0 and iterates over each byte in the data block. For each byte, it XORs the CRC value with the byte left-shifted by 8 bits (multiplied by 256). Then, it performs a bitwise left shift on the CRC value by 1 bit and checks the most significant bit.If the most significant bit is set, the function performs an XOR operation with the polynomial 0x1021. This process continues for 8 iterations (for each bit in the byte). After processing all the bytes in the data block, the function returns the calculated CRC value.