当前位置: 首页 > wzjs >正文

推荐外贸网站建设的公司公司网站asp源码

推荐外贸网站建设的公司,公司网站asp源码,网站备案 网站建设方案书需要写吗,长沙网站公司背景: 基于君正X2000 MCU Freertoslwip架构 实现HTTP server服务,MCU作为HTTP服务器通过网口进行数据包的传输,提供网页服务。其中设计到LWIP提供的工具makefsdata,常用于将文件或目录结构转换为适合嵌入到固件中的二进制格式。 …

背景:

基于君正X2000 MCU Freertos+lwip架构 实现HTTP server服务,MCU作为HTTP服务器通过网口进行数据包的传输,提供网页服务。其中设计到LWIP提供的工具makefsdata,常用于将文件或目录结构转换为适合嵌入到固件中的二进制格式。

一、 lwip 源码和资源

1. 1 源码资源下载链接

lwip官方网站:https://savannah.nongnu.org/projects/lwip/

lwip官方网站下载地址:https://download.savannah.nongnu.org/releases/lwip/

下载解压打开后文件目录大致是这个样子

在这里插入图片描述

1.2 资源目录介绍:

fs用于存放网页资源诸如HTML、CSS、JavaScript等文件。makefsdata是官网提供的工具用于将fs中网页资源转换为适合嵌入到固件中的二进制格式,使用makefsdata生成fsdata.c方便集成到嵌入式系统当中。其他是一些http实现的接口及头文件。

二 、makefsdata工具使用

2.1 makefsdata转换工具有俩种实现方式:

2. 1. 1使用makefsdata脚本

使用源码makefsdata文件夹下的makefsdata脚本直接解释运行,使用脚本只需要添加运行权限,直接运行即可快捷方便的生成fsdata.c集成到嵌入式系统中。但是缺乏一些扩展功能,使用不够灵活且无法使用压缩,这对于资源有限的嵌入式设备来说是不可接受的。

lwip源码资源下载后存放网页资源的fs脚本在makefsdata脚本的上层目录,而makefsdata脚本默认将当前目录下的文件资源转换生成fsdata.c。故对脚本做一些修改。将脚本中的chdir(“fs”); ——> chdir(“…/fs”);

添加文件复制移动命令将生成的fsdata.c自动替换成上层旧文件方便生成后编译

在这里插入图片描述

下面是修改后的完整makefsdata脚本

#!/usr/bin/perluse File::Copy;open(OUTPUT, "> fsdata.c");chdir("../fs");
open(FILES, "find . -type f |");while($file = <FILES>) {# Do not include files in CVS directories nor backup files.if($file =~ /(CVS|~)/) {next;}chop($file);open(HEADER, "> /tmp/header") || die $!;if($file =~ /404/) {print(HEADER "HTTP/1.0 404 File not found\r\n");} else {print(HEADER "HTTP/1.0 200 OK\r\n");}print(HEADER "Server: lwIP/pre-0.6 (http://www.sics.se/~adam/lwip/)\r\n");if($file =~ /\.html$/) {print(HEADER "Content-type: text/html\r\n");} elsif($file =~ /\.gif$/) {print(HEADER "Content-type: image/gif\r\n");} elsif($file =~ /\.png$/) {print(HEADER "Content-type: image/png\r\n");} elsif($file =~ /\.jpg$/) {print(HEADER "Content-type: image/jpeg\r\n");} elsif($file =~ /\.class$/) {print(HEADER "Content-type: application/octet-stream\r\n");} elsif($file =~ /\.ram$/) {print(HEADER "Content-type: audio/x-pn-realaudio\r\n");    } else {print(HEADER "Content-type: text/plain\r\n");}print(HEADER "\r\n");close(HEADER);unless($file =~ /\.plain$/ || $file =~ /cgi/) {system("cat /tmp/header $file > /tmp/file");} else {system("cp $file /tmp/file");}open(FILE, "/tmp/file");unlink("/tmp/file");unlink("/tmp/header");$file =~ s/\.//;$fvar = $file;$fvar =~ s-/-_-g;$fvar =~ s-\.-_-g;print(OUTPUT "static const unsigned char data".$fvar."[] = {\n");print(OUTPUT "\t/* $file */\n\t");for($j = 0; $j < length($file); $j++) {printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));}printf(OUTPUT "0,\n");$i = 0;while(read(FILE, $data, 1)) {if($i == 0) {print(OUTPUT "\t");}printf(OUTPUT "%#02x, ", unpack("C", $data));$i++;if($i == 10) {print(OUTPUT "\n");$i = 0;}}print(OUTPUT "};\n\n");close(FILE);push(@fvars, $fvar);push(@files, $file);
}for($i = 0; $i < @fvars; $i++) {$file = $files[$i];$fvar = $fvars[$i];if($i == 0) {$prevfile = "NULL";} else {$prevfile = "file" . $fvars[$i - 1];}print(OUTPUT "const struct fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) .", FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT}};\n\n");
}chdir("../makefsdata");
move("fsdata.c", "../fsdata.c");print(OUTPUT "#define FS_ROOT file$fvars[$i - 1]\n\n");
print(OUTPUT "#define FS_NUMFILES $i\n");

2.1.2 编译makefsdata.c后使用可执行文件生成fsdata.c

博主在windows下使用vscode+mingw编译生成makefsdata.exe,进而使用该程序生成fsdata.c。相较于脚本使用多了一步编译生成的步骤,但是多了许多扩展功能且可以进行zlib压缩网页资源文件。对于资源有限的嵌入式设备压缩功能就十分必要。编译好的makefsdata.exe放在置顶,可以直接在windows下命令行运行。

编译参考博客 使用vscode编译makefsdata 如果需要压缩功能需要额外下载第三方库如zlip。压缩转换命令如下,可配合-XC排除不需要压缩的文件。官网提供的网页资源不经压缩转换后fsdata.c大小为21KB,经过-defl:5参数压缩转换后为14KB。压缩比例约为66KB,不同压缩等级,网页资源经过压缩后压缩比例不尽相同。

makefsdata.exe -defl:5   //  Windows下命令行运行,-defl表示使用压缩,5表示压缩等级(1-10)默认10

扩展功能参考资源文件下的readme.txt,更多功能可以参考源码或者makefsdata -help查看user page。

This directory contains a script ('makefsdata') to create C code suitable for
httpd for given html pages (or other files) in a directory.There is also a plain C console application doing the same and extended a bit.Usage: htmlgen [targetdir] [-s] [-i]stargetdir: relative or absolute path to files to convertswitch -s: toggle processing of subdirectories (default is on)switch -e: exclude HTTP header from file (header is created at runtime, default is on)switch -11: include HTTP 1.1 header (1.0 is default)if targetdir not specified, makefsdata will attempt toprocess files in subdirectory 'fs'.The C version of this program can optionally store the none-SSI files in
a compressed form in which they are also sent to the web client (which
must support the Deflate content encoding). Files that grow during compression
(due to being not compressible well), will stored umcompressed automatically.
In order to do so, compile the program with MAKEFS_SUPPORT_DEFLATE set to 1. You must
manually download minizip.c for this to work. As an alternative, you can additionally
define MAKEFS_SUPPORT_DEFLATE_ZLIB to use your system's zlib instead.
Compression of .html, .js, .css and .svg files usually yields very good compression
rates and is a great way of reducing your program's size.

makefsdata.c实现的扩展功能。

static void print_usage(void)
{printf(" Usage: htmlgen [targetdir] [-s] [-e] [-11] [-nossi] [-ssi:<filename>] [-c] [-f:<filename>] [-m] [-svr:<name>] [-x:<ext_list>] [-xc:<ext_list>" USAGE_ARG_DEFLATE NEWLINE NEWLINE);printf("   targetdir: relative or absolute path to files to convert" NEWLINE);printf("   switch -s: toggle processing of subdirectories (default is on)" NEWLINE);printf("   switch -e: exclude HTTP header from file (header is created at runtime, default is off)" NEWLINE);printf("   switch -11: include HTTP 1.1 header (1.0 is default)" NEWLINE);printf("   switch -nossi: no support for SSI (cannot calculate Content-Length for SSI)" NEWLINE);printf("   switch -ssi: ssi filename (ssi support controlled by file list, not by extension)" NEWLINE);printf("   switch -c: precalculate checksums for all pages (default is off)" NEWLINE);printf("   switch -f: target filename (default is \"fsdata.c\")" NEWLINE);printf("   switch -m: include \"Last-Modified\" header based on file time" NEWLINE);printf("   switch -svr: server identifier sent in HTTP response header ('Server' field)" NEWLINE);printf("   switch -x: comma separated list of extensions of files to exclude (e.g., -x:json,txt)" NEWLINE);printf("   switch -xc: comma separated list of extensions of files to not compress (e.g., -xc:mp3,jpg)" NEWLINE);
#if MAKEFS_SUPPORT_DEFLATEprintf("   switch -defl: deflate-compress all non-SSI files (with opt. compr.-level, default=10)" NEWLINE);printf("                 ATTENTION: browser has to support \"Content-Encoding: deflate\"!" NEWLINE);
#endifprintf("   if targetdir not specified, htmlgen will attempt to" NEWLINE);printf("   process files in subdirectory 'fs'" NEWLINE);
}

三、集成fsdata.c到嵌入式设备

3.1 概述:君正X2000芯片提供2个网口驱动,不同芯片架构平台网口实现大同小异不是本文核心内容不做赘述。本次实验将设备默认静态IP设置为192.168.3.120。将生成的fsdata.c替换后编译生成固件烧录至开发板后即可展示网页资源。

3.2 调用LWIP实现HTTP server

调用LWIP实现最基础的网页展示十分简单,只需要将生成fsdata.c替换后在主程序头部包含LWIP头文件

#include "lwip/apps/httpd.h"

在主程序中调用httpd_init即可启动http server。

httpd_init();		// 初始化 HTTPD SERVER

嵌入式设备通过网线连接到PC,打开浏览器输入192.168.3.120(端口号会默认80)即可展示网页资源左上角图片为替换验证后的图片资源(与LWIP官方提供的默认图片资源不一样)。

在这里插入图片描述

3.3 http server实际应用功能待更新。。。


文章转载自:

http://5ECy21ck.skbhL.cn
http://zEQYJa0v.skbhL.cn
http://7XzupV5x.skbhL.cn
http://KSSZNUbe.skbhL.cn
http://k3SsasSd.skbhL.cn
http://00eULYQn.skbhL.cn
http://ItYjcUWc.skbhL.cn
http://8FGXTmTL.skbhL.cn
http://3c5dcsAf.skbhL.cn
http://CJar0Muf.skbhL.cn
http://HF0Wbz3P.skbhL.cn
http://0MCCd9Ur.skbhL.cn
http://vMPCpdIN.skbhL.cn
http://Kz7VOOnI.skbhL.cn
http://nqgGqAbX.skbhL.cn
http://MjE6Pm7g.skbhL.cn
http://qvmn6HxK.skbhL.cn
http://vayMkhlB.skbhL.cn
http://XKmkbuRF.skbhL.cn
http://VktXSOBI.skbhL.cn
http://BTDSsLPB.skbhL.cn
http://5TNILLoI.skbhL.cn
http://bFoBeveJ.skbhL.cn
http://5tBPBTQ0.skbhL.cn
http://N4O4RoqJ.skbhL.cn
http://UL5FSPfI.skbhL.cn
http://gZW3FO7Q.skbhL.cn
http://lU5jeGh7.skbhL.cn
http://o26hsatG.skbhL.cn
http://4w7SUyaa.skbhL.cn
http://www.dtcms.com/wzjs/699401.html

相关文章:

  • 关于h5的网站模板wordpress文本块
  • 洛阳市住房和城乡建设网站wordpress个人网站模板
  • 做网站重要标签图库素材网站模板
  • 品牌网站 响应式网站视频营销成功的案例
  • 泉州比较好的网站开发建设公司seo搜索引擎优化就业指导
  • 太原网站建设推广服务wordpress学习教程
  • 做破解软件网站赚广告费游戏网站模板免费下载
  • 秦皇岛网站开发报价济南网站建设 小程序
  • 棋牌 彩票网站建设手机网站开发注意的问题
  • 东莞网站建设网站东莞网站设计制作
  • 谷歌怎么推广自己的网站手机制作报价单app
  • 深圳市城乡建设部网站首页在线视频下载网站如何做
  • js网站跳转代码ui网页设计技巧
  • 大同建设银行保安招聘网站做网站服务器什么配置
  • 如何屏蔽网站ip永久免费的财务软件
  • 新手可以自己学做网站设计吗怎么创建网页的快捷方式
  • 网站制作需要多少钱新闻网站推广软文代发
  • 建各企业网站多少钱做打折网站如何
  • 可以做投票的网站网站设计专业公司
  • 深圳做网站(官网)手机微信客户端网站建设
  • 建立网站平台网页设计提升班有哪些
  • 怎么在网上接网站建设前端做网站需要
  • 一般请人做网站和app多少钱wordpress title标签
  • 手机网站建站价格成都网站登记备案查询
  • 建设网站上传代码网站功能建设模块
  • 上海网站建设公司哪个好北京互联网公司排名
  • 陕西省交通建设公司网站wordpress页面怎么切换
  • wordpress php推送惠州seo关键字优化
  • 珠海做网站那家好huntt wordpress主题
  • 请问如何做网站火车头发布模块wordpress5.0