Bit Stuffing - Framing Technics
Sender
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
void bitStuffing(char myFrame[])
{
// stuffing procedure
int i=0,k=0,counter=0;
char temp[50];
strcpy(temp,myFrame);
while(temp[i]!='\0')
{
myFrame[k++]=temp[i]; // update Frame data by doing Stufing
if(temp[i]=='1')
{
// if we encounter continues 1 then do increment in counter
counter++;
}
else
{
// if continuty of 1's break, reset counter to ZERO
counter=0;
}
if(counter==5)
{
// after a FIVE consicutive ONE stuff a bit ZERO
myFrame[k++]='0';
}
i++;
}
myFrame[k]='\0';
}
void main()
{
int pid,i,no,k=0,frameData,frame_size=32;
char myFrame[50];
system(">pipe");
pid=open("pipe",O_WRONLY); // open named pipe for write mode
system("clear");
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
myFrame[k++]=getBit(frameData,i)+48;
}
myFrame[k]='\0';
printf("\nBefore Stuffing Frame : %s",myFrame);
bitStuffing(myFrame); // do the process of bit Stuffing
printf("\nAfter Stuffing Frame : %s\n\n",myFrame);
write(pid,&myFrame[0],sizeof(myFrame)); //write frame in to named pipe
}
Receiver
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
void deStuffing(char myFrame[])
{
int i=0,counter=0,k=0;
char temp[50];
//take backup of original Frame Data in temp
strcpy(temp,myFrame);
while(temp[i]!='\0')
{
myFrame[k++]=temp[i]; // update Frame data after deStufing
if(temp[i]=='1')
{
// if we encounter continues 1 then do increment in counter
counter++;
}
else
{
// if continuty of 1's break, reset counter to ZERO
counter=0;
}
if(counter==5)
{
//to omit stuffed bit do increment in index
i++;
}
i++;
}
myFrame[k]='\0';
}
void main()
{
int pid;
char myFrame[50];
system("clear");
pid=open("pipe",O_RDONLY);// open named pipe for READ Only mode
read(pid,&myFrame,sizeof(myFrame)); //read from named pipe
printf("\nBefore destuffing Frame : %s",myFrame);
deStuffing(myFrame);
printf("\nAfter Destuffing Frame : %s\n\n",myFrame);
}
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment