汽车行驶记录仪C语言编程_第1页
汽车行驶记录仪C语言编程_第2页
汽车行驶记录仪C语言编程_第3页
汽车行驶记录仪C语言编程_第4页
汽车行驶记录仪C语言编程_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、汽车黑匣子项目说明1.汽车黑匣子简介汽车黑匣子,又称汽车工作信息记录仪,汽车安全信息记录仪,也有人将其形象地称为汽车电子警察。它能够完整、准确地记录汽车行驶状态下的有关情况,并通过专用软件在电脑上再现。本项目只是实现的是它的软件部分。2.项目要求1.记录汽车运行时的日期,时间和速度;2.经可能的多存一些信息:使用位段;3.每满10次(可根据用户要求更改)记录向文件中存一次;4.文件大小只有1.2K(可根据用户要求更改);3.分析建模本次项目主要的关键点有不断的采集数据直到汽车停止,将采集到了数据存入到一个大小固定的文件中(此文件大小可以根据用户要求改变),将文件里的数据读出查看汽车行驶时采集到

2、的数据。3.1采集数据集存储通过调用time 和localtime函数来采集日期和时间,(由于目前没有采集速度的设备所以速度采用手动从键盘输入);程序如下;void input(PPER new)int n=0;printf("请输入卡车行驶的速度n");scanf("%d",&n);time_t timep;struct tm *p;time(&timep);p=localtime(&timep);new->year=(1900+p->tm_year);new->mouth=(1+p->tm_mon);n

3、ew->day=p->tm_mday;new->hour=p->tm_hour;new->fen=p->tm_min;new->second=p->tm_sec;new->speed=n;new->next=NULL;由于每条数据有比较多的信息所以我们定义一个结构体来存储采集到的每条数据,数据采用位段存储省空间;程序如下:typedef struct carunsigned int year:12;unsigned int mouth:4;unsigned int day:5;unsigned int hour:5;unsigned

4、int fen:6;unsigned int second:6;unsigned int speed:9;struct car * next;PER,*PPER;由于存储的数据条数比较多且条数不固定所以采用链表将这些结构体链接起来,来的数据往链表末尾一挂程序如下:PPER addlink(PPER head)int i=0;PPER ps=head;while(1)PPER new=calloc(1,sizeof(PER);input(new);if(NULL=head)head=new;ps=head;i+;elsehead->next=new;if(0=new->speed)r

5、eturn ps;head=head->next;i+;if(i>=N)return ps;3.2将数据存入文件中每一次存储数据在文件的位置都要从上一次结束的位置开始,我们定义一个变量n来记录每次文件存储结束的位置,并存入文件的开头,第二次要存储数据的时候先读取n的数据就知道上一次存在哪里,然后接着往后面存;文件的大小我们宏定义一个FILEMAX来控制每一次剩余文件的大小不能存储一条 数据时将文件跳到n后面开始存储程序如下:void inputfile(PPER head)int n=sizeof(int);FILE *fp=fopen("xiangmu.txt"

6、;,"r+");if(NULL=fp)fp=fopen("xiangmu.txt","w");fwrite(&n,sizeof(int),1,fp);elsefread(&n,sizeof(int),1,fp);fseek(fp,n,SEEK_SET);while(1)if(NULL=head)break;if(FILEMAX-ftell(fp)>sizeof(PER)fwrite(head,sizeof(PER),1,fp);head=head->next;elsefseek(fp,sizeof(int)

7、,SEEK_SET);n=ftell(fp);rewind(fp);fwrite(&n,sizeof(int),1,fp);fclose(fp);3.3显示文件由于文件是以二进制代码方式存储,人类无法直接查看所以要先将文件的内容调入PC机内存中显示在显示器上才好查看,文件到内存放在链表中存储程序如下:PPER outputfile(PPER head)FILE *fp=fopen("xiangmu.txt","r");if(NULL=fp)printf("文件打开失败n");return NULL;fseek(fp,sizeo

8、f(int),SEEK_SET);while(1)PPER new=calloc(1,sizeof(PER);fread(new,sizeof(PER),1,fp);new->next=NULL;if(0!=feof(fp)break;head=addlink1(head,new);fclose(fp);return head;PPER output(PPER head)PPER ps=head;if(NULL=head)return head;while(1)show(ps);ps=ps->next;if(NULL=ps)return head;4.画流程图由于时间有限在此就不画

9、电子版的流程图;5.编写程序程序附带在同一个文件夹里,再此就不做编写6.显示程序运行结果主菜单页请输入功能号0-退出1-将采集来的数据输入链表中2-显示链表3-将链表里的数据存入文件中4-释放链表5-把文件里面的数据导入链表中6-求最大速度7求平均速度显示文件记录的所有数据时间2015年8月5日9时36分48秒speed93km/h时间2015年8月5日9时36分49秒speed94km/h时间2015年8月5日9时36分50秒speed95km/h时间2015年8月5日9时36分50秒speed96km/h时间2015年8月5日9时36分52秒speed97km/h时间2015年8月5日9时

10、36分53秒speed98km/h时间2015年8月5日9时36分54秒speed99km/h时间2015年8月5日9时36分56秒speed100km/h时间2015年8月5日9时37分1秒speed101km/h时间2015年8月5日9时37分22秒speed102km/h时间2015年8月5日9时37分24秒speed103km/h时间2015年8月5日9时37分25秒speed104km/h时间2015年8月5日9时37分27秒speed105km/h时间2015年8月5日9时37分28秒speed106km/h时间2015年8月5日9时37分29秒speed107km/h时间2015

11、年8月5日9时37分31秒speed108km/h时间2015年8月5日9时37分33秒speed109km/h时间2015年8月5日9时37分36秒speed110km/h时间2015年8月5日9时37分38秒speed111km/h时间2015年8月5日9时32分15秒speed12km/h时间2015年8月5日9时32分17秒speed13km/h时间2015年8月5日9时32分18秒speed14km/h时间2015年8月5日9时32分19秒speed15km/h时间2015年8月5日9时32分20秒speed16km/h时间2015年8月5日9时32分21秒speed17km/h时间

12、2015年8月5日9时32分22秒speed18km/h时间2015年8月5日9时32分23秒speed19km/h时间2015年8月5日9时32分25秒speed20km/h时间2015年8月5日9时32分27秒speed21km/h时间2015年8月5日9时32分57秒speed22km/h时间2015年8月5日9时32分58秒speed23km/h时间2015年8月5日9时32分59秒speed24km/h时间2015年8月5日9时33分0秒speed25km/h时间2015年8月5日9时33分1秒speed26km/h时间2015年8月5日9时33分2秒speed27km/h时间201

13、5年8月5日9时33分3秒speed28km/h时间2015年8月5日9时33分4秒speed29km/h时间2015年8月5日9时33分6秒speed30km/h时间2015年8月5日9时33分7秒speed31km/h时间2015年8月5日9时33分26秒speed32km/h时间2015年8月5日9时33分28秒speed33km/h时间2015年8月5日9时33分29秒speed34km/h时间2015年8月5日9时33分30秒speed35km/h时间2015年8月5日9时33分31秒speed36km/h时间2015年8月5日9时33分32秒speed37km/h时间2015年8月

14、5日9时33分34秒speed38km/h时间2015年8月5日9时33分35秒speed39km/h时间2015年8月5日9时33分37秒speed40km/h时间2015年8月5日9时33分39秒speed41km/h时间2015年8月5日9时34分2秒speed42km/h时间2015年8月5日9时34分3秒speed43km/h时间2015年8月5日9时34分4秒speed44km/h时间2015年8月5日9时34分6秒speed45km/h时间2015年8月5日9时34分7秒speed46km/h时间2015年8月5日9时34分8秒speed47km/h时间2015年8月5日9时34

15、分9秒speed48km/h时间2015年8月5日9时34分10秒speed49km/h时间2015年8月5日9时34分12秒speed50km/h时间2015年8月5日9时34分13秒speed51km/h时间2015年8月5日9时34分47秒speed52km/h时间2015年8月5日9时34分48秒speed53km/h时间2015年8月5日9时34分50秒speed54km/h时间2015年8月5日9时34分51秒speed55km/h时间2015年8月5日9时34分52秒speed56km/h时间2015年8月5日9时34分53秒speed57km/h时间2015年8月5日9时34分

16、54秒speed58km/h时间2015年8月5日9时34分56秒speed59km/h时间2015年8月5日9时34分57秒speed60km/h时间2015年8月5日9时34分58秒speed61km/h时间2015年8月5日9时35分14秒speed62km/h时间2015年8月5日9时35分15秒speed63km/h时间2015年8月5日9时35分16秒speed64km/h时间2015年8月5日9时35分17秒speed65km/h时间2015年8月5日9时35分18秒speed66km/h时间2015年8月5日9时35分19秒speed67km/h时间2015年8月5日9时35分

17、20秒speed68km/h时间2015年8月5日9时35分21秒speed69km/h时间2015年8月5日9时35分23秒speed70km/h时间2015年8月5日9时35分24秒speed71km/h时间2015年8月5日9时35分38秒speed72km/h时间2015年8月5日9时35分40秒speed73km/h时间2015年8月5日9时35分41秒speed74km/h时间2015年8月5日9时35分42秒speed75km/h时间2015年8月5日9时35分43秒speed76km/h时间2015年8月5日9时35分45秒speed77km/h时间2015年8月5日9时35分46秒speed78km/h时间2015年8月5日9时35分47秒speed79km/h时间2015年8月5日9时35分48秒speed80km/h时间2015年8月5日9时35分49秒speed81km/h时间2015年8月5日9时36分14秒speed82km/h时间2015年8月5日9时36分15秒speed83km/h时间2015年8月5日9时36分16秒speed84km/h时间2015年8月5日9时36分18秒speed85km/h时间2015年8月5日9时36分19秒speed86km/h时间2015年8月5日9时36分20秒speed87km/h时间2015年8月5日9

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论