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

网站推广策略网页无法访问游戏

网站推广策略,网页无法访问游戏,最好的网站建设公司哪家好,app推广有哪些渠道Electron使用WebAssembly实现CRC-32 STM32校验 将C/C语言代码,经由WebAssembly编译为库函数,可以在JS语言环境进行调用。这里介绍在Electron工具环境使用WebAssembly调用CRC-32 STM32格式校验的方式。 CRC-32 STM32校验函数WebAssembly源文件 C语言实…

Electron使用WebAssembly实现CRC-32 STM32校验

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

CRC-32 STM32校验函数WebAssembly源文件

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

选择上面介绍文章中的uint32_t PY_CRC_32_T32_STM32(uint32_t *di, uint32_t len)校验函数,建立一个新文件PY_CRC_32_T32_STM32.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>
#include <string.h>EM_PORT_API(void *) mymalloc(uint32_t size) {return malloc(size);
}EM_PORT_API(void) myfree(void * ptr) {free(ptr);
}EM_PORT_API(uint32_t) PY_CRC_32_T32_STM32(uint32_t *di, uint32_t len)
{uint32_t crc_poly = 0x04C11DB7;  //X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+1 total 32 effective bits without X^32.//uint32_t data_t = 0; //CRC registeruint32_t data_t = 0xffffffff; //CRC registerfor(uint32_t i = 0; i < len; i++){data_t ^= di[i]; //32-bit datafor (uint8_t j = 0; j < 32; j++){if (data_t & 0x80000000)data_t = (data_t << 1) ^ crc_poly;elsedata_t <<= 1;}}return (data_t);
}

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

将这个文件进行WebAssembly编译,就会得到两个库文件:
在这里插入图片描述

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

Electron调用WebAssembly CRC-32 STM32函数演示源文件

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

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

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --><link href="./styles.css" rel="stylesheet"><title>Hello World!</title><script>window.$ = window.jQuery = require('./js/jquery-3.3.1.min.js');</script></head><script src="PY_CRC_32_T32_STM32.js"></script><script src="./mainprocess.js"></script>  <body><h1>Hello World!</h1>We are using Node.js <span id="node-version"></span>,Chromium <span id="chrome-version"></span>,and Electron <span id="electron-version"></span>.<!-- You can also require other files to run in this process --><script src="./renderer.js"></script></body>
</html>

主要修改部分为引入了jQuery,引入了PY_CRC_32_T32_STM32.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*4);for (var i = 0; i < count; i++){Module.HEAP32[(ptr>>2) + i] = 1+i;}console.log(Module._PY_CRC_32_T32_STM32(ptr, count));Module._myfree(ptr);},2000);   //Delay is a must for Module initialized! });process.on('uncaughtException', function (){});

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

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

Electron调用WebAssembly CRC-32 STM32准函数演示效果

通过在控制台输入 npm start执行Electron工程,打开console显示:
在这里插入图片描述

174717508是打印出的CRC校验结果,十六进制值为0xA69FA44 。

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

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

–End–

http://www.dtcms.com/wzjs/803963.html

相关文章:

  • 建立可以在线做照片的网站可视化建网站
  • 网络营销具有什么特点seo发帖网站
  • 做职业规划的网站深圳营销网站建设服务
  • wordpress建娱乐站html简单网站开发案例
  • 铁岭 开原网站建设中企动力z云邮登录
  • 网站建设确认书大型网站技术架构演进与性能优化
  • 做网站的镜像是什么意思企业年金退休后如何领取
  • 展厅设计制作网站网站建设属于什么行业分类
  • 个人怎么建立网站经营网站 备案信息管理系统
  • 威海做网站的公司哪家好惠州seo外包v1
  • 太原seo整站优化手机网站建设要多少钱
  • 企业网站模板科技感莱芜网络推广公司排行
  • 网站推广应注意哪些事项表白网页链接在线制作
  • 网站改版分析百度seo排名软件
  • 网站前台需求文档html音乐播放器代码
  • 什么是网站链接优化极速网站制作
  • 怎样说服老板做网站世界技能大赛网站建设
  • 嘉兴企业网站推广谷歌google官方下载
  • 做软装设计找图有什么好的网站wordpress手机登录注册
  • 可以免费做简历的网站做网站包含什么职位
  • 民宿网站建设问卷调查深圳网站开发培训
  • 网站的主色调受雇去建设网站类网站
  • 公交公司网站建设的意义如何做网络营销能成功呢
  • 犀牛云做的网站好不好上海闵行刚刚发生的
  • 手机网站和电脑网站一样吗图书馆网站建设教程
  • 网站设计定制公司响应式网站用什么语言
  • 济南外贸建站网页升级访问中新每天正常更新中在线观看
  • 网络游戏公司排行榜前十名南宁seo产品优化服务
  • 青海小学网站建设简要概括自建网站的优缺点
  • 广州网络公司建站系统软件开发