|
本帖最后由 dreampet 于 2012-9-18 14:32 编辑
文件系统用的是Fatfs,存储介质为SD卡,以下代码跟硬件无关,可直接使用
生成的Html文件效果如下所示
代码实现是根据Google Map提供的API实现,我建立了一个最简模板,如下所示,在这个模板中,我们只需要修改、填充这一部分即可 new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx);- <html>
- <head runat="server">
- <title>TraceLog</title>
- <meta name="viewport"content="initial-scale=1.0,user-scalable=no"/>
- <script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=true"></script>
- <script type="text/javascript">
- function initialize()
- {
- var myLatlng = new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx);
- var mapOptions= {
- zoom:14,
- center:myLatlng,
- mapTypeId:google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
- var trackPath = new google.maps.Polyline(
- {path:trackPoints,
- strokeColor:"#FF0000",
- strokeOpacity:1.0,
- strokeWeight:2}
- );
- trackPath.setMap(map);
- }
- //坐标数组
- var trackPoints = [
- new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx),
- new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx)
- ];
- </script>
- </head>
- <body onload="initialize()">
- <form id="form1" runat="server">
- <div id="map_canvas" style="width: 800px; height: 600px; position: relative; "></div>
- </form>
- </body>
- </html>
复制代码 根据以上模板构建4个数组,如下所示- static const int8_t LogTemplet0[]={"<html><head runat="server"><title>TraceLog</title><meta name="viewport"content="initial-scale=1.0,user-scalable=no"/><script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=true"></script><script type="text/javascript">"};
- static const int8_t LogTemplet1[]={"function initialize(){var myLatlng=new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx);var mapOptions={zoom:14,center:myLatlng,mapTypeId:google.maps.MapTypeId.ROADMAP};var map=new google.maps.Map(document.getElementById("map_canvas"),mapOptions);var trackPath=new google.maps.Polyline({path:trackPoints,strokeColor:"#FF0000",strokeOpacity:1.0,strokeWeight:2});trackPath.setMap(map);}"};
- static const int8_t LogTemplet2[]={"var trackPoints = ["};
- static const int8_t LogTemplet3[]={"];</script></head><body onload="initialize()"><form id="form1" runat="server"><div id="map_canvas" style="width: 800px; height: 600px; position: relative;"></div></form></body></html>"};
复制代码 初始化函数如下所示,这个函数在SD卡初始化成功后 会尝试建立一个名称为Trace_xxx.html的记录文件,xxx的取值范围是000至999,文件建立成功后 即按上面的格式建立html文件模块- uint8_t DataLog_Init(void)
- {
- FRESULT res;
- int16_t i;
- uint32_t Len;
- int8_t TmpStr[16];
- res = FR_NO_FILE;
- DataLog_Status = 0;
- CopyStr("Trace_",TmpStr,15);
- if (SD_Init() != SD_Unknown)
- {
- printf("\r\nSDCard Init Success\r\n");
- f_mount(0,&fs);
- for (i=0;i<999;i++)
- {
- Int32ToDecStr(i,&TmpStr[6],3);
- StrCat(TmpStr,".html");
- res = f_open(&logfile,TmpStr,FA_CREATE_NEW|FA_WRITE);
- if (res == FR_OK)
- break;
- }
- }
-
- if (res == FR_OK)
- {
- res = f_write(&logfile,(int8_t*)LogTemplet0,sizeof(LogTemplet0)-1,&Len);
- res |= f_write(&logfile,(int8_t*)LogTemplet1,sizeof(LogTemplet1)-1,&Len);
- res |= f_write(&logfile,(int8_t*)LogTemplet2,sizeof(LogTemplet2)-1,&Len);
- res |= f_write(&logfile,"\r\n",2,&Len);
- res |= f_write(&logfile,(int8_t*)LogTemplet3,sizeof(LogTemplet3)-1,&Len);
- if (res == FR_OK)
- {
- printf("No. %d LogFile Created!\r\n",i);
- f_sync(&logfile);
- DataLog_Status = 1;
- DataLog_NewLog = 1;
- return 1;
- }
- else
- {
- f_close(&logfile);
- f_mount(0,NULL);
- DataLog_Status = 0;
- }
- }
- return 0;
- }
复制代码 构建坐标数组元素的代码如下所示,这个函数将xx.xxxxxx,xxx.xxxxxx 格式的坐标转化成 new google.maps.LatLng(xx.xxxxxx,xxx.xxxxxx) 格式- uint8_t DataLog_BuildRecord(int8_t *pLatLng)
- {
- uint8_t TmpStr[128];
- sprintf(TmpStr,"new google.maps.LatLng(%s)",pLatLng);
- return DataLog_WriteRecord(TmpStr);
- }
复制代码 将坐标元素插入到模板中的代码如下所示,当第一次插入元素时,需进行特殊处理,填充起点坐标,每次填充完毕后,调用f_sync将缓存同步至SD卡,确保数据记录完整- uint8_t DataLog_WriteRecord(uint8_t *pRec)
- {
- int16_t res,RecLen,Len;
- if (!DataLog_Status)
- return 0;
- if (DataLog_NewLog == 1)
- {
- f_lseek(&logfile,275);
- f_write(&logfile,pRec,44,(UINT*)&Len);
- f_lseek(&logfile,(&logfile)->fsize - sizeof(LogTemplet3) + 1);
- DataLog_NewLog = 0;
- }
- else
- {
- f_lseek(&logfile,(&logfile)->fsize - sizeof(LogTemplet3) + 1);
- f_write(&logfile,",\r\n",3,(UINT*)&Len);
- }
- f_write(&logfile,pRec,44,(UINT*)&RecLen);
- f_write(&logfile,(int8_t*)LogTemplet3,sizeof(LogTemplet3)-1,(UINT*)&Len);
- if (44 != RecLen)
- {
- printf("\r\nLog Failure!\r\n");
- f_close(&logfile);
- DataLog_Status = 0;
- return 0;
- }
- else
- {
- f_sync(&logfile); //同步文件至SD卡
- printf("\r\nLog Success!\r\nLog Size:%d\r\n",f_size(&logfile));
- return 1;
- }
- }
复制代码 生成的Html文件如下
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|