postheadericon Byte Stuffing - Framing Technics


Sender



#include<stdio.h>
#include<fcntl.h>
#include<string.h>


#define FLAG '#'

#define ESC '*'

void main()
{
int j=1,i,pid;

char Frame_Data[50],Targeted_Frame[50];

system("clear");
  system(">pipe");
pid=open("pipe",O_WRONLY);

printf("Enter the Frame Data : ");
  scanf("%s",Frame_Data);

Targeted_Frame[0]=FLAG; //set header FLAG

for(i=0;i<strlen(Frame_Data);i++)
{
    if (Frame_Data[i]==FLAG || Frame_Data[i]==ESC) //check FLAG or ESCAPE charechter is in frame data
{
    Targeted_Frame[j++]=ESC; // if FLAG / ESCAPE Char found add one more ESCAPE char

}
    Targeted_Frame[j++]=Frame_Data[i]; //copy other data

  }
Targeted_Frame[j++]=FLAG; //set tailer FLAG
Targeted_Frame[j]='\0';

printf("\nFrame to be send  : %s",Targeted_Frame);
write(pid,&Targeted_Frame,sizeof(Targeted_Frame));
close(pid);
}


postheadericon Single Bit Parity Check


Sender

/*Single bit Parity check*/

#include<stdio.h>
#include<fcntl.h>
#include<string.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;

}


int getParity(char targeted_frameData[])
{
    //find the even parity
    int i=0,counter=0;
    for(i=0;i<32;i++)
    {
        if(targeted_frameData[i]=='1')    //count total no. of 1
            counter++;      
    }
    if(counter % 2 == 0 )//Even parity
        return 0;
    else  
        return 1;
}
void main()
{
    int frameData,i,k=0,flag,pid,frame_size=32;;
    char targeted_frameData[34];
    pid=open("pipe",O_WRONLY);

    //Enter Frame Data in decimal Number
    printf("\nEnter Frame Data : ");
    scanf("%d",&frameData);

     for(i=frame_size;i>0;i--)
    {
        targeted_frameData[k++]=getBit(frameData,i) + 48;
    }

    //Set Parity bit
    targeted_frameData[k++]=getParity(targeted_frameData) + 48;
    targeted_frameData[k++]='\0';

    printf("\n\nTageted Frame : %s\n",targeted_frameData);

    write(pid,&targeted_frameData,sizeof(targeted_frameData));
    close(pid);
}

postheadericon Character Count - Framing Technics


Sender


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");

system(">pipe");
pid=open("pipe",O_WRONLY);

printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);

write(pid,&targeted_frame,sizeof(targeted_frame));
}
 /*2i5love6india*/

postheadericon 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
}

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.