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

高密做网站的价位门户网站建设统计表

高密做网站的价位,门户网站建设统计表,wordpress好还是dz,做网站接私活怎么收费Electron使用WebAssembly实现CRC-8 MAXIM校验 将C/C语言代码,经由WebAssembly编译为库函数,可以在JS语言环境进行调用。这里介绍在Electron工具环境使用WebAssembly调用CRC-8 MAXIM格式校验的方式。 CRC-8 MAXIM校验函数WebAssembly源文件 C语言实现C…

Electron使用WebAssembly实现CRC-8 MAXIM校验

将C/C++语言代码,经由WebAssembly编译为库函数,可以在JS语言环境进行调用。这里介绍在Electron工具环境使用WebAssembly调用CRC-8 MAXIM格式校验的方式。

CRC-8 MAXIM校验函数WebAssembly源文件

C语言实现CRC-8 MAXIM格式校验的介绍见:《C语言CRC-8 MAXIM格式校验函数》

选择上面介绍文章中的uint8_t PY_CRC_8_T_MAXIM_i(uint8_t *di, uint32_t len)校验函数,建立一个新文件PY_CRC_8_T_MAXIM_i.cc:

#ifndef EM_PORT_API
#	if defined(__EMSCRIPTEN__)
#		include <emscripten.h>
#		if defined(__cplusplus)
#			define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE
#		else
#			define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE
#		endif
#	else
#		if defined(__cplusplus)
#			define EM_PORT_API(rettype) extern "C" rettype
#		else
#			define EM_PORT_API(rettype) rettype
#		endif
#	endif
#endif#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>EM_PORT_API(void *) mymalloc(uint32_t size) {return malloc(size);
}EM_PORT_API(void) myfree(void * ptr) {free(ptr);
}EM_PORT_API(uint8_t) PY_CRC_8_T_MAXIM_i(uint8_t *di, uint32_t len) {    uint8_t crc_poly = 0x8C; //Bit sequence inversion of 0x31uint8_t data_t = 0; //CRC registerfor(uint32_t i = 0; i < len; i++){data_t ^= di[i]; //8-bit datafor (uint8_t j = 0; j < 8; j++){if (data_t & 0x01)data_t = (data_t >> 1) ^ crc_poly;elsedata_t >>= 1;}}return data_t;
}

这个文件有三个函数导出,前两个是获取和释放内存的函数,后一个就是CRC-8 MAXIM校验函数的导出。

将这个文件进行WebAssembly编译,就会得到两个库文件:

在这里插入图片描述

将这几个文件拷贝到后面建立的Electron工程目录,再进行调用。

Electron调用WebAssembly CRC-8 MAXIM函数演示源文件

下载Electron的Hello World!例程,并实现正常运行:
在这里插入图片描述

然后将前面的3个WebAssembly相关文件,放到例程根目录。再引入一个jQuery库。编写index.html文件如下:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>WebAssembly Electron</title><script>window.$ = window.jQuery = require('./js/jquery-3.3.1.min.js');</script></head><body><h1>Hello World!</h1><!-- All of the Node.js APIs are available in this renderer process. -->We are using Node.js <script>document.write(process.versions.node)</script>,Chromium <script>document.write(process.versions.chrome)</script>,Electron <script>document.write(process.versions.electron)</script>,<p> see console </p><script src="PY_CRC_8_T_MAXIM_i.js"></script><script src="./mainprocess.js"></script>  </body><script>// You can also require other files to run in this processrequire('./renderer.js')</script>
</html>

主要修改部分为引入了jQuery,引入了PY_CRC_8_T_MAXIM_i.js以及引入了mainprocess.js,mainprocess.js是在例程根目录下新建的工程文件,内容如下:

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.//增加当前运行状态和当前运行进程/函数信息,控制不产生误触发
window.name="mainwindow";   $(document).ready(function(){Module.onRuntimeInitialized = function() {console.log(Module);}setTimeout(function(){var count = 8;var ptr = Module._mymalloc(count);for (var i = 0; i < count; i++){Module.HEAP8[ptr + i] = 1+i;}console.log(Module._PY_CRC_8_T_MAXIM_i(ptr, count));Module._myfree(ptr);},2000);   //Delay is a must for Module initialized! })

mainprocess.js实现了WebAssembly库文件的导入和使用,Module._mymalloc用于申请内存空间,Module._myfree用于释放内存空间,Module.HEAP8[ptr + i] = 1+i;用于给申请到的内存空间从1开始赋值,这里堆空间为8个字节,因此赋值从1到8。Module._PY_CRC_8_T_MAXIM_i(ptr, count)则进行CRC-8 MAXIM校验函数的调用,提供了内存指针和要校验的字节数量。

整个Electron工程环境的文件如下所示:
在这里插入图片描述

Electron调用WebAssembly CRC-8 MAXIM函数演示效果

通过在控制台输入 npm start执行Electron工程,打开console显示:
在这里插入图片描述
131是打印出的CRC校验结果,十六进制值为0x83, 通过在线工具比较验证:
在这里插入图片描述

Electron使用WebAssembly实现CRC-8 MAXIM校验演示工程下载

Electron Demo工程下载,包含已编译后的WebAssembly库文件:
在这里插入图片描述

–End–

http://www.yayakq.cn/news/592577/

相关文章:

  • 典型网站开发的一般流程wordpress页码颜色
  • 专业搜索引擎seo服务商网站优化及推广方案
  • 无锡网站建设企业学历提升的重要性
  • 国外服务器做网站wordpress可以装在子目录下
  • 美工怎么做网站效果图哪些网站用户体验好
  • 网站体验分享做网站花都区
  • 有免费制作单页的网站吗浙江省住房和城乡建设厅网站查询
  • 网站页面设计欣赏模板天津网站建设设计
  • 网站外包注意事项3d动画制作自学教程
  • 网站如何做单项链接汉中软件开发项目管理
  • 做的比较简约的网站网站建设案例欣赏
  • 网站建设方案封面武清做网站的
  • 电脑做网站空间公众号开发者密码重置
  • 网页设计欣赏英文seo网站页面诊断
  • 中山金舜家庭用品有限公司怎样网站地图大专软件技术好就业吗
  • 企业网站建设合同书盖章页马鞍山人才网
  • 品牌网站推广软件access建网站
  • 辽宁智能网站建设价位wordpress 多分类
  • 免费个人网站空间申请贵州省两学一做网站
  • 信息类网站怎么做网络销售平台有哪些软件
  • 网站设计培训成都哪家好建湖做网站
  • 网站推广易网宣wordpress用户自定义作者
  • 网站开发怎样验收行业网站建设哪家好
  • 含山县建设局网站下载百度我的订单
  • 网站模板怎么进建设网站计入什么科目
  • 织梦怎么设置网站首页网站百度关键词优化
  • 建立企业网站需要什么广告设计与制作包括哪些
  • 人才网站的seo怎么做威海住房和城乡建设厅网站
  • 凡科建站官网登录wordpress 淘宝客赚钱
  • aspcms网站打不开即时聊天app开发