资源预览内容
第1页 / 共19页
第2页 / 共19页
第3页 / 共19页
第4页 / 共19页
第5页 / 共19页
第6页 / 共19页
第7页 / 共19页
第8页 / 共19页
第9页 / 共19页
第10页 / 共19页
亲,该文档总共19页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
杭 州 电 子 科 技 大 学实 验 报 告学生姓名:韩民杨 学 号:12081420 指导教师:吴端坡实验地点:1#108 实验时间:2015-4-24一、实验室名称:1#108二、实验项目名称:计算机网络实验1Coding on error dectecting algorithms(C+)三、实验学时:四、实验原理:C+编程五、实验目的:利用C+编程CRC16校验及奇偶校验六、实验内容:Coding on error dectecting algorithms(C+)1. Cyclic redundancy checkUsing the polynomials below to encode random generated data stream (40-100bits). Show the FEC, and encoded data frame.CRC-4x4+x+1ITU G.704CRC-16x16+x15+x2+1IBM SDLCCRC-32x32+x26+x23+.+x2+x+1ZIP, RAR, IEEE 802 LAN/FDDI, IEEE 1394, PPP-FCSFor the error patter listed below, what the conclusion does the receiver get? Can the receiver find the errors?CaseError patternNo error00000000One error1000.000Two errors100.001Random errorsRandom error pattern2. Parity check Using even or odd parity check on random generated data stream (8-20bits).Show encoded data frame.For the error patter listed below, what the conclusion does the receiver get? Can the receiver find the errors?CaseError patternNo error00000000One error1000.000Two errors100.001七、实验器材(设备、元器件):PC机一台,装有C+集成开发环境。八、实验步骤:#include#include#include#include#include #include #define NO_ERROR 1#define ONE_ERROR 2#define TWO_ERROR 3#define RANDOM_ERROR 4#define RESULT 1#define CRC 0#define Parity 0#define check 1int flag_parity;/判断奇偶校验void ByteToBit(char* out,const char* in,int bits);void input_message(char*message);int xor(char *p, char *d,int len);char *crc_function(char *str_p,int len,char *dividend,int len_d,int type,char *crc_p );char Parity_check(char *message_output,int length,int mode);void main()int pattern = 0;int channel_way =0;char message8=NULL;/ data that produced by chance char message_output1000 = NULL;char message_crc = NULL;/transportint length; /messages length/*这是固定了为4为的crc,当这里改变是就可以直接改变crc的长度了*/char dividend=10011;char message_input1000=;/*这里可以更改数值当时16为crc的时候,此时的len_d为15*/int len_d=5;/被除数长度设置char flag;while (true)fflush(stdin);/任意输入数据printf(please input the message!n);gets(message);printf(A need to send this message:%sn,message);length = strlen(message);ByteToBit(message_output,message,length*8);for(int k = 0;klength*8;k+)printf(%d,message_outputk);message_inputk = message_outputk+48;pattern = 0;channel_way =0;printf(n);printf(Coding on error dectecting algorithmsn);printf( 1.Cyclic redundancy checkn);printf( 2.Parity check n);printf( please chice pattern: n);/*选择进入的检错模式*/scanf(%d,&pattern);fflush(stdin);/清空缓存区if(pattern = 1)printf(*n);printf( analog channeln);printf( please choice the way of errorn);printf(* 1.No error *n);printf(* 2.One error *n);printf(* 3.Two errors *n);printf(* 4.Random errors *n);scanf(%d,&channel_way);printf(ncrc:);/进行crc检测int len = length*8;/printf(%dn,len);char *crc = NULL;crc = crc_function(message_input,len,dividend,len_d,CRC,NULL);for(int i = 0;i len_d;i+)printf(%c,*crc);message_inputlength*8+i = *crc;crc+=1;printf(n);/*模拟信道Case Error patternNo error 00000000One error 1000.000Two errors 100.001Random errorsRandom error pattern*/if(channel_way = NO_ERROR)char *result = NULL;int flagg=0;printf(信道中传输数据:);for(int f =0;flength*8+len_d-1 ;f+)printf(%c,message_inputf);printf(n);printf(正在检错中.n);printf(检错结果:);fflush(stdin);result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(int i = 0;i len_d-1;i+)printf(%c,*result);if(*result) - 48 != 0)printf(n error! n);flagg =1;break;result+=1;if(flagg = 0)printf(n no error! n);if(channel_way = ONE_ERROR)char *result = NULL;message_input0 = (message_input0 - 48)(1-48) + 48;printf(信道中传输数据:);for(int f =0;flength*8+len_d-1 ;f+)printf(%c,message_inputf);printf(n);printf(正在检错中.);printf(检错结果:);result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(int i = 0;i len_d-1;i+)if(*result = 1)printf(data error! n);break;elsecontinue;result+=1;if(channel_way = TWO_ERROR)cha
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号