Mar 27 2014
Block Parity Checker LRC
In this error detection method, a block of bits is organized in a table with rows and columns. Then the parity bit for each column is calculated and a new row of eight bits, which are the parity bits for the whole block, is created. After that the new calculated parity bits are attached to the original data and sends to the receiver.
LRC increases the likelihood of detecting burst error. An LRC of n bits can easily detects a burst error of n bits.
However, if two bits in one data unit are damaged and two bits in exactly the same positions in another data unit are also damaged, the LRC checker will not detect an error.
Notice that although the 5th bit and the 7th bit for 1st and 2 nd data unit have been changed but the LRC calculated by receiver is still the same as the LRC received. Thus the receiver checker cannot detect this burst error.
Block Parity Checker LRC Implementation in Unix C
lrcsen.c (Block Parity LRC Sender)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | //Block Parity LRC Sender Example #include<stdio.h> //Standard Input Functions #include<sys/types.h> //Named Pipes (FIFO) Types #include<sys/stat.h> // Named Pipes (FIFO) Functions #include<fcntl.h> //File Control Unix Functions #include<unistd.h> //Unix Standard Functions int main() { char *myfifo = "myfifo"; //FIFO File Path int fp; //Open Pipe Return Value unsigned char ch[100],parity=0; //Unsigned character string and parity bit int i; // loop variable printf("Creating Pipe...Waiting for receiver for Process...\n"); //Creating Named Pipe //mkfifo(<filepath>,<permission>) if(mkfifo(myfifo,0666) < 0) { perror("FIFO (Named Pipe) could not be created.\n"); exit(-1); } else printf("FIFO (Named Pipe) Created...\n"); //Opening Named Pipe //open(<filepath>,<openingmode>); fp = open(myfifo,O_WRONLY); if(fp < 0) { perror("FIFO (Named Pipe) could not be opened.\n"); exit(-2); } else printf("FIFO (Named Pipe) Opened...\n"); /* LRC LOGIC STARTS */ printf("Enter Any String : "); gets(ch); for(i=0;ch[i]!='\0';i++) { parity ^= ch[i]; } printf("\nOriginal Message => %s",ch); printf("\nParity Character => %c %d",parity,parity); //Adding Parity Bit (Character) at Last ch[i++] = parity; ch[i] = '\0'; printf("\nMessage After LRC => %s\n",ch); /* LRC Logic Ends */ //Writing to Named Pipe //write(<open_pipe_return_value>,<message>,<msgsize>); if(write(fp,ch,sizeof(ch)) < 0) { perror("Error writing to FIFO (Named Pipe)\n"); exit(-3); } else printf("Message has been sent to FIFO (Named Pipe)\n"); //Closing Named Pipe //close(<open_pipe_return_value>); if(close(fp) < 0) { perror("Error closing FIFO (Named Pipe)\n"); exit(-4); } return 0; } |
lrcrec.c (Block Parity LRC Receiver)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | //Block Parity LRC Receiver Example #include<stdio.h> //Standard Input Functions #include<sys/types.h> //Named Pipes (FIFO) Types #include<sys/stat.h> // Named Pipes (FIFO) Functions #include<fcntl.h> //File Control Unix Functions #include<unistd.h> //Unix Standard Functions int main() { char *myfifo = "myfifo"; //FIFO File Path int fp; //Open Pipe Return Value unsigned char ch[100],parity=0,nparity=0; //Here we will take two parity character one which received from sender and one which we will calculate int i; //loop variable int len; // message length //Opening Named Pipe //open(<filepath>,<openingmode>); fp = open(myfifo,O_RDONLY); if(fp < 0) { perror("FIFO (Named Pipe) could not be opened for reading.\n"); exit(-1); } else printf("FIFO (Named Pipe) Opened... Trying to read from\n"); //Reading From Named Pipe //read(<open_pipe_return_value>,<message>,<msgsize>); if(read(fp,ch,sizeof(ch)) < 0) { perror("Error reading from FIFO (Named Pipe)\n"); exit(-2); } else printf("Message Received from FIFO (Named Pipe)\n"); len = strlen(ch)-1; /* LRC Logic Stars */ printf("\nRecieved Message => %s",ch); //Received Parity Character parity = ch[len]; // last character of string added by sender //Now we calculate parity for(i=0;i<len;i++) { nparity ^= ch[i]; } if(parity != nparity){ printf("\nMessage Currupted..."); exit(-5); } ch[len] = '\0'; // replace parity character with null character printf("\nOriginal Message => %s\n",ch); //Closing Named Pipe //close(<open_pipe_return_value>); if(close(fp) < 0) { perror("Error closing FIFO (Named Pipe)\b"); exit(-3); } if(unlink(myfifo) < 0) { perror("Error deleting FIFO (Named Pipe)\b"); exit(-4); } return 0; } |