版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、杭 州 电 子 科 技 大 学实 验 报 告学生姓名:韩民杨 学 号: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 enco
2、de 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 fin
3、d 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
4、get? Can the receiver find the errors?CaseError patternNo error00000000One error1000.000Two errors100.001七、实验器材(设备、元器件):PC机一台,装有C+集成开发环境。八、实验步骤:#include<stdio.h>#include<stdlib.h>#include<memory.h>#include<string.h>#include<conio.h> #include<time.h> #define NO_ERR
5、OR 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 l
6、en,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; /message's l
7、ength/*这是固定了为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
8、message:%sn",message);length = strlen(message);ByteToBit(message_output,message,length*8);for(int k = 0;k<length*8;k+)printf("%d",message_outputk);message_inputk = message_outputk+48;pattern = 0;channel_way =0;printf("n");printf("Coding on error dectecting algorithms
9、n");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(" ple
10、ase 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&qu
11、ot;,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 errorsRand
12、om error pattern*/if(channel_way = NO_ERROR)char *result = NULL;int flagg=0;printf("信道中传输数据:");for(int f =0;f<length*8+len_d-1 ;f+)printf("%c",message_inputf);printf("n");printf("正在检错中.n");printf("检错结果:");fflush(stdin);result = crc_function(messag
13、e_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 = (me
14、ssage_input0 - 48)('1'-48) + 48;printf("信道中传输数据:");for(int f =0;f<length*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(in
15、t i = 0;i < len_d-1;i+)if(*result = '1')printf("data error! n");break;elsecontinue;result+=1;if(channel_way = TWO_ERROR)char *result = NULL;message_input0 = (message_input0 - 48)('1'-48) + 48;message_inputlength*8-1 = (message_inputlength*8-1 - 48)('1'-48) + 48;p
16、rintf("信道中传输数据:");for(int f =0;f<length*8+len_d-1 ;f+)printf("%c",message_inputf);printf("n");printf("正在检错中.");printf("检错结果:");result = crc_function(message_input,len,dividend,len_d,RESULT,crc);for(int i = 0;i < len_d-1;i+)if(*result != '0&
17、#39;)printf(" data error! n");break;elsecontinue;result+=1;if(channel_way = RANDOM_ERROR)char *result = NULL;int no;srand( (unsigned)time( NULL ) ); /初始化随机数no = rand()%length*8;message_inputno = (message_input0 - 48)('1'-48) + 48;printf("信道中传输数据:");for(int f =0;f<lengt
18、h*8+len_d-1 ;f+)printf("%c",message_inputf);printf("n");printf("正在检错中.n");printf("检错结果:");result = crc_function(message_input,len,dividend,len_d,RESULT,crc);for(int i = 0;i < len_d-1;i+)if(*result != '0')printf(" data error! n");break;else
19、continue;result+=1;printf("*n");printf("n");printf("n");elseprintf("Please select the parity moden");printf(" 1.Even parity n");printf(" 2.Odd parityn");scanf("%d",&flag_parity);char m = Parity_check(message_input,length*8,Par
20、ity);printf("在信道中传输的message:");message_inputlength*8 = m ;for(int message_number = 0;message_number<=length*8;message_number+)printf("%c",message_inputmessage_number);printf("n");printf("*n");printf("* analog channel *n");printf("*please choi
21、ce the way of error*n");printf("* 1.No error *n");printf("* 2.One error *n");printf("* 3.Two errors *n");scanf("%d",&channel_way);if(channel_way = NO_ERROR)for(int f =0;f<length*8;f+)printf("%c",message_inputf);printf("正在检错中.n")
22、;printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);if(flag_parity_mode = (message_inputlength*8)printf("no error!n");if(channel_way = ONE_ERROR)message_input0 = (message_input0 - 48)('1'-48) + 48;for(int f =0;f<length*8;f+)printf("
23、%c",message_inputf);printf("正在检错中.n");printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);printf(" error!n");if(channel_way = TWO_ERROR)message_input0 = (message_input0 - 48)('1'-48) + 48;message_inputlength*8-1 = (message_inp
24、utlength*8-1 - 48)('1'-48) + 48;for(int f =0;f<length*8;f+)printf("%c",message_inputf);printf("正在检错中.n");printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);printf("no error!n");printf("*n");printf("n&qu
25、ot;);printf("n");fflush(stdin);printf("do you want to continue?y/nn");scanf("%c",&flag);if(flag = 'y')continue;elsebreak;/*/function: 完成字节转换成位的功能/输入字符:In 输出的二进制:Out*/void ByteToBit(char* out,const char* in,int bits)/char out_11000 = ""int i;/printf
26、("%sn",in);for(i=0;i<bits;+i)outbits-i-1=(ini>>3>>(i&7)&1;/printf("%d:%dn",i,outi);/*/function: 完成异或除法/输入:*p *d /输出:直接将一次异或除法之后的结果覆盖*/int xor(char *p, char *d,int len=5)/p为message,d 为crc检测的中的pint i=0;for(;i<len;i+)*p=(*p-48)(*d-48)+48;*p=*p+1;d=d+1;d=d-l
27、en; /d重新指向最新的/*p=*p-len+1;/p后移一位return 0;/*/function: 完成crc检错以及crc计算/输入:传输字符:str_p 传输字符长度len / 4位的crc的检错方式 len_d是需要填0的个数/ type 用于判断显示计算传输之后的结果还是计算crc/输出:crc或者计算传输之后的结果*/char *crc_function(char *str_p,int len,char *dividend,int len_d,int type,char *crc_p=NULL)int i;int j;char *input_p=(char *)malloc(
28、sizeof(char)*(len+len_d-1); /申请空间char *input_p_tmp=NULL;input_p_tmp=input_p;/向指针指向的内存里存数据for(i=0;i<len;i+)*input_p_tmp=str_pi;input_p_tmp+;/*补零个数为len_d-1*/for(i=0;i<len_d-1;i+)if(type=CRC)/如果是求crc就补0*input_p_tmp='0'input_p_tmp+;else/如果是求结果就补crc*input_p_tmp=*crc_p;crc_p+;input_p_tmp+;in
29、put_p_tmp=NULL;/开始检查如果是1则进行异或除法,如果是0就指针向下移动一位.其中'0'=48for(j=0;j<len;j+)/*把1传入48表示为"0"*/if(*input_p=48)/指针后移一位input_p=input_p+1;elsexor(&input_p,dividend,len_d);return input_p;/*/function: 完成奇偶校验/输入:message_output为需要传输的数据以及数据的长度lengh 奇偶校验的模式/输出:返回奇偶校验的结果*/char Parity_check(char *message
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 幼儿园班级科学活动设计方案
- 物业社区服务人力资源方案
- 上海市松江区2026届八年级物理第一学期期末学业质量监测试题含解析
- 2026届黑龙江省鸡西中学物理八年级第一学期期末监测试题含解析
- 甘肃省武威市第五中学2026届九上物理期中综合测试试题含解析
- 2026届江苏省姜堰实验物理九年级第一学期期末调研模拟试题含解析
- 山东省德州市陵城区江山实验学校2026届物理九上期末综合测试试题含解析
- 湖南省株洲市2026届物理九年级第一学期期末检测模拟试题含解析
- 2026届安徽省亳州市涡阳县石弓中心学校八年级物理第一学期期末综合测试模拟试题含解析
- 北京朝阳区2026届物理八年级第一学期期末达标检测试题含解析
- 2024单位消防安全评估导则
- 《园冶园说解析》课件
- 公务员心理健康与调适讲座
- 2024年中国电气装备集团招聘笔试参考题库含答案解析
- 国开电大本科《当代中国政治制度》在线形考(形考任务一至四)试题及答案
- 【实用文档】生产制造过程流程图
- 2023年度环保管家服务招标文件
- 犬胃切开术的课件资料
- GB/T 42195-2022老年人能力评估规范
- GB/T 9634.4-2007铁氧体磁心表面缺陷极限导则第4部分:环形磁心
- GB/T 18380.11-2022电缆和光缆在火焰条件下的燃烧试验第11部分:单根绝缘电线电缆火焰垂直蔓延试验试验装置
评论
0/150
提交评论