Serial communications often uses vertical redundancy checking (VRC) when it adds a parity bit to the transmitted character. Longitudinal (or horizontal) redundancy checking (LRC) adds a parity bit for all bits in the message at the same bit position. Vertical coding operates on a single character and is known as character error coding. Horizontal checks operate on groups of characters and described as message coding. LRC always uses even parity and the parity bit for the LRC character has the parity of the VRC code.
Longitudinal/vertical redundancy checks (LRC/VRC) |
Outline
Serial communications often uses vertical redundancy checking (VRC) when it adds a parity bit to the transmitted character. Longitudinal (or horizontal) redundancy checking (LRC) adds a parity bit for all bits in the message at the same bit position. Vertical coding operates on a single character and is known as character error coding. Horizontal checks operate on groups of characters and described as message coding. LRC always uses even parity and the parity bit for the LRC character has the parity of the VRC code. In the example given next, the character sent for LRC is thus 10101000 (28h) or a ‘(’. The message sent is ‘F’, ‘r’, ‘e’, ‘d’, ‘d’, ‘y’ and ‘(’.
Without VRC checking, LRC checking detects most errors but does not detect errors where an even number of characters have an error in the same bit position. In the previous example if bit 2 of the ‘F’ and ‘r’ were in error then LRC would be valid. This problem is overcome if LRC and VRC are used together. With VRC/LRC the only time an error goes undetected is when an even number of bits, in an even number of charac-ters, in the same bit positions of each character are in error. This is of course very unlikely. On systems where only single-bit errors occur, the LRC/VRC method can be used to detect and correct the single-bit error. For systems where more than one error can occur it is not possible to locate the bits in error, so the receiver prompts the transmitter to retransmit the message.
Example
communications channel uses ASCII character coding and LRC/VRC bits are added to each word sent. Encode the word ‘Freddy’ and, using odd parity for the VRC and even pari-ty for the LRC; determine the LRC character.
F r e d d y LRC b0 0 0 1 0 0 1 0 b1 1 1 0 0 0 0 0 b2 1 0 1 1 1 0 0 b3 0 0 0 0 0 1 1 b4 0 1 0 0 0 1 0 b5 0 1 1 1 1 1 1 b6 1 1 1 1 1 1 0 VRC 0 1 1 0 0 0 1
Code
The outline Python code is:
import sys val1= 'test' if (len(sys.argv)>1): val1=str(sys.argv[1]) def parityOf(int_type): parity = 0 while (int_type): parity = ~parity int_type = int_type & (int_type-1) if (parity==-1): return(0) return(1) def calcLRC(input): lrc = ord(input[0]) for i in range(1,len(input)): lrc ^= ord(input[i]) return lrc def showLRC(input,res): input = input[:7] print 'Char\tHex\tBinary' print '------------------------------------' for i in range(0,len(input)): print input[i],"\t",hex(ord(input[i])),"\t",bin(ord(input[i])) print '\nBit\tBinary LRC' print '----------------------------' print ' \t', for i in range(0,len(input)): print input[i], print "" mask=1 for bitpos in range(0,7): bit = (res & mask) >> bitpos print "b",bitpos,"\t", for i in range(0,len(input)): bitchar = (ord(input[i]) & mask) >> bitpos print bitchar, print bit mask = mask << 1 # Show VRC print "VRC\t", for i in range(0,len(input)): print parityOf(ord(input[i])), print parityOf(res), return res = calcLRC(val1) print "" print "Input: ",val1," LRC is ",hex(res),"- Char: ",chr(res) print "" showLRC(val1,res)
Sample run
A sample run gives:
Input: Freddy LRC is 0x28 - Char: ( Char Hex Binary ------------------------------------ F 0x46 0b1000110 r 0x72 0b1110010 e 0x65 0b1100101 d 0x64 0b1100100 d 0x64 0b1100100 y 0x79 0b1111001 Bit Binary LRC ---------------------------- F r e d d y b 0 0 0 1 0 0 1 0 b 1 1 1 0 0 0 0 0 b 2 1 0 1 1 1 0 0 b 3 0 0 0 0 0 1 1 b 4 0 1 0 0 0 1 0 b 5 0 1 1 1 1 1 1 b 6 1 1 1 1 1 1 0