Browse Source

2023年4月6日15:11:26 缓存

yxb
wq 2 years ago
parent
commit
b138de366f

+ 6
- 0
static/etc/ATAPI/ArtcBleUtil.js View File

@@ -21,6 +21,7 @@ var connectDevice = function (device, callback, callback_0) {
_bleDeviceId = device.deviceId
_connectCallback = callback
_connectCallback_0 = callback_0
//监听低功耗蓝牙连接状态的改变事件。包括开发者主动连接或断开连接,设备丢失连接异常断开等等
wx.onBLEConnectionStateChange((res) => {
if (res.deviceId == _bleDeviceId) {
if (res.connected == true) {
@@ -31,6 +32,7 @@ var connectDevice = function (device, callback, callback_0) {
}
}
})
//连接低功耗蓝牙设备。
wx.createBLEConnection({
deviceId: _bleDeviceId,
timeout: 20 * 1000,
@@ -46,11 +48,13 @@ var connectDevice = function (device, callback, callback_0) {
* 配置连接外设
*/
var deployBle = function () {
//获取蓝牙设备所有服务(service)。
wx.getBLEDeviceServices({
deviceId: _bleDeviceId,
success: (res) => {
for (let i = 0; i < res.services.length; i ++) {
if ((res.services[i].uuid + "") == SERVICE_UUID) {
//获取蓝牙设备某个服务中所有特征值(characteristic)。
wx.getBLEDeviceCharacteristics({
deviceId: _bleDeviceId,
serviceId: SERVICE_UUID,
@@ -67,6 +71,7 @@ var deployBle = function () {
}
}
if (haveRead == true && haveWrite == true) {
//启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。
wx.notifyBLECharacteristicValueChange({
deviceId: _bleDeviceId,
serviceId: SERVICE_UUID,
@@ -101,6 +106,7 @@ var deployBle = function () {
typeof _connectCallback == FUNCTION && _connectCallback(new DevResult(1006, null, "读取服务失败"))
}
})
//监听低功耗蓝牙设备的特征值变化事件。必须先启用 notifyBLECharacteristicValueChange 接口才能接收到设备推送的 notification。
wx.onBLECharacteristicValueChange((res) =>{
if (res.deviceId == _bleDeviceId && res.serviceId == SERVICE_UUID && res.characteristicId == READ_UUID) {
let hexData = ArtcDataUtil.buf2hex(res.value)

+ 5
- 1
static/etc/JLAPI/JLBleManagerTool.js View File

@@ -178,6 +178,7 @@ export function connectDevice(device, callBack) {
}
})
};
//dis连接设备
export function disConnectDevice(callBack) {
wxDisConnectDevice(function(res) {
callBack.call(this, res)
@@ -324,8 +325,9 @@ export function findDeviceServices(device, callBack1, callBack2) {
};

function getDeviceService(device, callBack) {
//获取蓝牙低功耗设备所有服务 (service)。
wx.getBLEDeviceServices({
deviceId: device.deviceId,
deviceId: device.deviceId, //设备ID
success: function(res) {
var services = res.services;
for (var i = 0; i < services.length; i++) {
@@ -342,6 +344,7 @@ function getDeviceService(device, callBack) {
}

function getDeviceCharacteristics(device, serviceId, callBack1, callBack2) {
//获取蓝牙低功耗设备某个服务中所有特征
wx.getBLEDeviceCharacteristics({
deviceId: device.deviceId,
serviceId: serviceId,
@@ -350,6 +353,7 @@ function getDeviceCharacteristics(device, serviceId, callBack1, callBack2) {
for (var i = 0; i < charactertics.length; i++) {
var charact = charactertics[i];
if (charact.properties.read == true) {
//读取蓝牙低功耗设备特征值的二进制数据。注意:必须设备的特征支持 read 才可以成功调用。
wx.readBLECharacteristicValue({
deviceId: device.deviceId,
serviceId: charact_serviceId,

+ 99
- 1
static/etc/JLAPI/onfire.js View File

@@ -1 +1,99 @@
!function(root,factory){if(typeof module==="object"&&module.exports)module.exports=factory();else root.onfire=factory()}(typeof window!=="undefined"?window:this,function(){var __onfireEvents={},__cnt=0,string_str="string",function_str="function",hasOwnKey=Function.call.bind(Object.hasOwnProperty),slice=Function.call.bind(Array.prototype.slice);function _bind(eventName,callback,is_one,context){if(typeof eventName!==string_str||typeof callback!==function_str){throw new Error("args: "+string_str+", "+function_str+"")}if(!hasOwnKey(__onfireEvents,eventName)){__onfireEvents[eventName]={}}__onfireEvents[eventName][++__cnt]=[callback,is_one,context];return[eventName,__cnt]}function _each(obj,callback){for(var key in obj){if(hasOwnKey(obj,key))callback(key,obj[key])}}function on(eventName,callback,context){return _bind(eventName,callback,0,context)}function one(eventName,callback,context){return _bind(eventName,callback,1,context)}function _fire_func(eventName,args){if(hasOwnKey(__onfireEvents,eventName)){_each(__onfireEvents[eventName],function(key,item){item[0].apply(item[2],args);if(item[1])delete __onfireEvents[eventName][key]})}}function fire(eventName){var args=slice(arguments,1);setTimeout(function(){_fire_func(eventName,args)})}function fireSync(eventName){_fire_func(eventName,slice(arguments,1))}function un(event){var eventName,key,r=false,type=typeof event;if(type===string_str){if(hasOwnKey(__onfireEvents,event)){delete __onfireEvents[event];return true}return false}else if(type==="object"){eventName=event[0];key=event[1];if(hasOwnKey(__onfireEvents,eventName)&&hasOwnKey(__onfireEvents[eventName],key)){delete __onfireEvents[eventName][key];return true}return false}else if(type===function_str){_each(__onfireEvents,function(key_1,item_1){_each(item_1,function(key_2,item_2){if(item_2[0]===event){delete __onfireEvents[key_1][key_2];r=true}})});return r}return true}function clear(){__onfireEvents={}}return{on:on,one:one,un:un,fire:fire,fireSync:fireSync,clear:clear}});
! function(root, factory) {
if (typeof module === "object" && module.exports) module.exports = factory();
else root.onfire = factory()
}(typeof window !== "undefined" ? window : this, function() {
var __onfireEvents = {},
__cnt = 0,
string_str = "string",
function_str = "function",
hasOwnKey = Function.call.bind(Object.hasOwnProperty),
slice = Function.call.bind(Array.prototype.slice);

function _bind(eventName, callback, is_one, context) {
if (typeof eventName !== string_str || typeof callback !== function_str) {
throw new Error("args: " + string_str + ", " + function_str + "")
}
if (!hasOwnKey(__onfireEvents, eventName)) {
__onfireEvents[eventName] = {}
}
__onfireEvents[eventName][++__cnt] = [callback, is_one, context];
return [eventName, __cnt]
}

function _each(obj, callback) {
for (var key in obj) {
if (hasOwnKey(obj, key)) callback(key, obj[key])
}
}

function on(eventName, callback, context) {
return _bind(eventName, callback, 0, context)
}

function one(eventName, callback, context) {
return _bind(eventName, callback, 1, context)
}

function _fire_func(eventName, args) {
if (hasOwnKey(__onfireEvents, eventName)) {
_each(__onfireEvents[eventName], function(key, item) {
item[0].apply(item[2], args);
if (item[1]) delete __onfireEvents[eventName][key]
})
}
}

function fire(eventName) {
var args = slice(arguments, 1);
setTimeout(function() {
_fire_func(eventName, args)
})
}

function fireSync(eventName) {
_fire_func(eventName, slice(arguments, 1))
}

function un(event) {
var eventName, key, r = false,
type = typeof event;
if (type === string_str) {
if (hasOwnKey(__onfireEvents, event)) {
delete __onfireEvents[event];
return true
}
return false
} else if (type === "object") {
eventName = event[0];
key = event[1];
if (hasOwnKey(__onfireEvents, eventName) && hasOwnKey(__onfireEvents[eventName], key)) {
delete __onfireEvents[eventName][key];
return true
}
return false
} else if (type === function_str) {
_each(__onfireEvents, function(key_1, item_1) {
_each(item_1, function(key_2, item_2) {
if (item_2[0] === event) {
delete __onfireEvents[key_1][key_2];
r = true
}
})
});
return r
}
return true
}

function clear() {
__onfireEvents = {}
}
return {
on: on,
one: one,
un: un,
fire: fire,
fireSync: fireSync,
clear: clear
}
});

+ 232
- 1
static/etc/WJAPI/wjBleAPI.js
File diff suppressed because it is too large
View File


+ 269
- 1
static/etc/WJAPI/wjDataAnalysis.js
File diff suppressed because it is too large
View File


+ 83
- 1
static/etc/WJAPI/wjDataDecode.js View File

@@ -1 +1,83 @@
"use strict";var iPackageLen,_wjUtils=require("./wjUtils.js"),_wjUtils2=_interopRequireDefault(_wjUtils);function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}var bleCount,rxCount=0,strTemData="",strRxBuffer="",isPagFinish=!0;function decode_GB(t){var e=0,a={},r=_wjUtils2.default.byteArray2hexStr(t);_wjUtils2.default.showLog("WJ当前接受包的数据:",r);var s=_wjUtils2.default.hexStr2byteArray(r);if(1<s.byteLength&&80==s[0]&&1==isPagFinish?(isPagFinish=!1,iPackageLen=s[3],strTemData=r):strTemData+=r,strTemData.length/2>=iPackageLen+5){rxCount+=1,isPagFinish=!0;var i=_wjUtils2.default.hexStr2byteArray(strTemData);_wjUtils2.default.showLog("接受完第",rxCount,"包数据,内容 ",strTemData);for(var o=0;o<iPackageLen+4;o++)e^=i[o];if(i[strTemData.length/2-1]!=e)return _wjUtils2.default.showError("WJ第",rxCount," 包校验bcc:Error!"),a.serviceCode=-1,a.serviceInfo="校验错误。。。",a;128==(128&i[1])&&(bleCount=((127&i[1])<<8)+i[2],_wjUtils2.default.showLog("总共:",bleCount,"大包")),_wjUtils2.default.showLog("WJ第",rxCount," 包校验bcc:ok!"),strRxBuffer+=strTemData.substring(8,strTemData.length-2)}return bleCount<=rxCount?(a.serviceCode=0,a.serviceInfo="数据接收完成!",a.serviceData={},a.serviceData.strData=strRxBuffer):(a.serviceCode=1,a.serviceInfo="数据接收中。。。"),a}function decode_WX(t){var e=0,a={},r=_wjUtils2.default.byteArray2hexStr(t);_wjUtils2.default.showLog("WJ当前接受包的数据:",r);var s=_wjUtils2.default.hexStr2byteArray(r);if(1<s.byteLength&&254==s[0]&&1==s[1]&&1==isPagFinish?(isPagFinish=!1,iPackageLen=(255&s[2])<<8,iPackageLen+=255&s[3],strTemData=r):strTemData+=r,strTemData.length/2>=iPackageLen){_wjUtils2.default.showLog("大包长度:",iPackageLen,strTemData.length),isPagFinish=!0,rxCount+=1;var i=_wjUtils2.default.hexStr2byteArray(strTemData),o={},u=0,n=0,f=0;for(o.FixHead={},o.FixHead.MagicNumber=strTemData.substr(2*u,2),u++,o.FixHead.Ver=strTemData.substring(2*u,2),u++,o.FixHead.Len=(i[u]<<8)+i[u+1],u+=2,o.FixHead.CmdId=(i[u]<<8)+i[u+1],u+=2,o.FixHead.Seq=(i[u]<<8)+i[u+1],u+=2,o.ProtoBuf={},o.ProtoBuf.BaseRequest={},o.ProtoBuf.BaseRequest.Mark=strTemData.substr(2*u,2),u++,f=n=0;128==(128&i[u]);)n+=(127&i[u])<<7*f,u++,f++;for(n+=(127&i[u])<<7*f,u++,o.ProtoBuf.BaseRequest.Data=strTemData.substr(2*u,2*n),u+=n,o.ProtoBuf.Data={},o.ProtoBuf.Data.Mark=strTemData.substr(2*u,2),u++,f=n=0;128==(128&i[u]);)n+=(127&i[u])<<7*f,u++,f++;for(n+=(127&i[u])<<7*f,u++,o.ProtoBuf.Data.Data=strTemData.substr(2*u,2*n),u+=n,o.ProtoBuf.DataType={},o.ProtoBuf.DataType.Mark=strTemData.substr(2*u,2),u++,f=n=0;128==(128&i[u]);)n+=(127&i[u])<<7*f,u++,f++;n+=(127&i[u])<<7*f,u++,o.ProtoBuf.DataType.Varint=n;for(var l=_wjUtils2.default.hexStr2byteArray(o.ProtoBuf.Data.Data),d=1;d<l.byteLength-1;d++)e^=l[d];if(l[l.byteLength-1]!=e)return _wjUtils2.default.showError("WJ第",rxCount," 包校验bcc:Error!"),a.serviceCode=-1,a.serviceInfo="校验错误。。。",a;128==(128&l[2])&&(bleCount=1+(127&l[2]),_wjUtils2.default.showLog("总共:",bleCount,"大包")),strRxBuffer+=o.ProtoBuf.Data.Data.substr(8,2*l[3]),_wjUtils2.default.showLog("WJ第",rxCount," 包校验bcc:ok!"),_wjUtils2.default.showLog("接受完第",rxCount,"大包数据,内容 ",strTemData)}return bleCount<=rxCount?(a.serviceCode=0,a.serviceInfo="数据接收完成!",a.serviceData={},a.serviceData.strData=strRxBuffer):(a.serviceCode=1,a.serviceInfo="数据接收中。。。"),a}function init(){rxCount=iPackageLen=0,isPagFinish=!(strRxBuffer=strTemData="")}module.exports={decode_GB:decode_GB,decode_WX:decode_WX,init:init};
"use strict";
var iPackageLen, _wjUtils = require("./wjUtils.js"),
_wjUtils2 = _interopRequireDefault(_wjUtils);

function _interopRequireDefault(t) {
return t && t.__esModule ? t : {
default: t
}
}
var bleCount, rxCount = 0,
strTemData = "",
strRxBuffer = "",
isPagFinish = !0;

function decode_GB(t) {
var e = 0,
a = {},
r = _wjUtils2.default.byteArray2hexStr(t);
_wjUtils2.default.showLog("WJ当前接受包的数据:", r);
var s = _wjUtils2.default.hexStr2byteArray(r);
if (1 < s.byteLength && 80 == s[0] && 1 == isPagFinish ? (isPagFinish = !1, iPackageLen = s[3], strTemData = r) :
strTemData += r, strTemData.length / 2 >= iPackageLen + 5) {
rxCount += 1, isPagFinish = !0;
var i = _wjUtils2.default.hexStr2byteArray(strTemData);
_wjUtils2.default.showLog("接受完第", rxCount, "包数据,内容 ", strTemData);
for (var o = 0; o < iPackageLen + 4; o++) e ^= i[o];
if (i[strTemData.length / 2 - 1] != e) return _wjUtils2.default.showError("WJ第", rxCount, " 包校验bcc:Error!"), a
.serviceCode = -1, a.serviceInfo = "校验错误。。。", a;
128 == (128 & i[1]) && (bleCount = ((127 & i[1]) << 8) + i[2], _wjUtils2.default.showLog("总共:", bleCount,
"大包")), _wjUtils2.default.showLog("WJ第", rxCount, " 包校验bcc:ok!"), strRxBuffer += strTemData.substring(8,
strTemData.length - 2)
}
return bleCount <= rxCount ? (a.serviceCode = 0, a.serviceInfo = "数据接收完成!", a.serviceData = {}, a.serviceData
.strData = strRxBuffer) : (a.serviceCode = 1, a.serviceInfo = "数据接收中。。。"), a
}

function decode_WX(t) {
var e = 0,
a = {},
r = _wjUtils2.default.byteArray2hexStr(t);
_wjUtils2.default.showLog("WJ当前接受包的数据:", r);
var s = _wjUtils2.default.hexStr2byteArray(r);
if (1 < s.byteLength && 254 == s[0] && 1 == s[1] && 1 == isPagFinish ? (isPagFinish = !1, iPackageLen = (255 & s[
2]) << 8, iPackageLen += 255 & s[3], strTemData = r) : strTemData += r, strTemData.length / 2 >=
iPackageLen) {
_wjUtils2.default.showLog("大包长度:", iPackageLen, strTemData.length), isPagFinish = !0, rxCount += 1;
var i = _wjUtils2.default.hexStr2byteArray(strTemData),
o = {},
u = 0,
n = 0,
f = 0;
for (o.FixHead = {}, o.FixHead.MagicNumber = strTemData.substr(2 * u, 2), u++, o.FixHead.Ver = strTemData
.substring(2 * u, 2), u++, o.FixHead.Len = (i[u] << 8) + i[u + 1], u += 2, o.FixHead.CmdId = (i[u] << 8) +
i[u + 1], u += 2, o.FixHead.Seq = (i[u] << 8) + i[u + 1], u += 2, o.ProtoBuf = {}, o.ProtoBuf
.BaseRequest = {}, o.ProtoBuf.BaseRequest.Mark = strTemData.substr(2 * u, 2), u++, f = n = 0; 128 == (128 &
i[u]);) n += (127 & i[u]) << 7 * f, u++, f++;
for (n += (127 & i[u]) << 7 * f, u++, o.ProtoBuf.BaseRequest.Data = strTemData.substr(2 * u, 2 * n), u += n, o
.ProtoBuf.Data = {}, o.ProtoBuf.Data.Mark = strTemData.substr(2 * u, 2), u++, f = n = 0; 128 == (128 & i[
u]);) n += (127 & i[u]) << 7 * f, u++, f++;
for (n += (127 & i[u]) << 7 * f, u++, o.ProtoBuf.Data.Data = strTemData.substr(2 * u, 2 * n), u += n, o.ProtoBuf
.DataType = {}, o.ProtoBuf.DataType.Mark = strTemData.substr(2 * u, 2), u++, f = n = 0; 128 == (128 & i[u]);
) n += (127 & i[u]) << 7 * f, u++, f++;
n += (127 & i[u]) << 7 * f, u++, o.ProtoBuf.DataType.Varint = n;
for (var l = _wjUtils2.default.hexStr2byteArray(o.ProtoBuf.Data.Data), d = 1; d < l.byteLength - 1; d++) e ^= l[
d];
if (l[l.byteLength - 1] != e) return _wjUtils2.default.showError("WJ第", rxCount, " 包校验bcc:Error!"), a
.serviceCode = -1, a.serviceInfo = "校验错误。。。", a;
128 == (128 & l[2]) && (bleCount = 1 + (127 & l[2]), _wjUtils2.default.showLog("总共:", bleCount, "大包")),
strRxBuffer += o.ProtoBuf.Data.Data.substr(8, 2 * l[3]), _wjUtils2.default.showLog("WJ第", rxCount,
" 包校验bcc:ok!"), _wjUtils2.default.showLog("接受完第", rxCount, "大包数据,内容 ", strTemData)
}
return bleCount <= rxCount ? (a.serviceCode = 0, a.serviceInfo = "数据接收完成!", a.serviceData = {}, a.serviceData
.strData = strRxBuffer) : (a.serviceCode = 1, a.serviceInfo = "数据接收中。。。"), a
}

function init() {
rxCount = iPackageLen = 0, isPagFinish = !(strRxBuffer = strTemData = "")
}
module.exports = {
decode_GB: decode_GB,
decode_WX: decode_WX,
init: init
};

+ 109
- 1
static/etc/WJAPI/wjDataEncode.js View File

@@ -1 +1,109 @@
"use strict";var _wjUtils=require("./wjUtils.js"),_wjUtils2=_interopRequireDefault(_wjUtils);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function encode(e,t,a){var r=_wjUtils2.default.getProtocolType(),n=getETCData(e,t,a),s={};return 0==r?s=encode_GB(n):1==r&&(s=encode_WX(n)),s}function getETCData(e,t,a){var r="";return r="A0"==a||"A3"==a||"A4"==a||"82"==a?a+t+(r=getCommand(e)):e,_wjUtils2.default.showLog("组拼ETCData完毕:",r.length/2,r),r}function getCommand(e){var t=e,a=_wjUtils2.default.getDATA_TYPE(),r=e.length/2,n=new ArrayBuffer(10),s=new DataView(n);if(0==a)i=256<r?(s.setInt8(0,4+r&255),s.setInt8(1,4+r>>8&255),s.setInt8(2,128),s.setInt8(3,130),s.setInt8(4,r>>8&255),s.setInt8(5,255&r),n.slice(0,6)):128<r&&r<=256?(s.setInt8(0,3+r&255),s.setInt8(1,3+r>>8&255),s.setInt8(2,128),s.setInt8(3,129),s.setInt8(4,r),n.slice(0,5)):(s.setInt8(0,2+r&255),s.setInt8(1,2+r>>8&255),s.setInt8(2,128),s.setInt8(3,r),n.slice(0,4)),t=_wjUtils2.default.byteArray2hexStr(i)+t;else if(1==a){var i;s.setInt8(0,255&r),s.setInt8(1,r>>8&255),i=n.slice(0,2),t=_wjUtils2.default.byteArray2hexStr(i)+t}return t}function encode_GB(e){var t={},a=_wjUtils2.default.getPagLenMax(),r=parseInt(e.length/2/a);e.length/2%a!=0&&(r+=1);var n=new ArrayBuffer(10);new DataView(n);t.serviceCode=0,t.serviceInfo="encode ok",t.serviceData={},t.serviceData.dataEncode=new Array;for(var s=0;s<r-1;s++)t.serviceData.dataEncode[s]=e.substr(s*a*2,2*a),t.serviceData.dataEncode[s]=getGBFrame(t.serviceData.dataEncode[s],s,r);return t.serviceData.dataEncode[r-1]=e.substring((r-1)*a*2),t.serviceData.dataEncode[r-1]=getGBFrame(t.serviceData.dataEncode[r-1],r-1,r),t}function encode_WX(e){var t={},a=_wjUtils2.default.getPagLenMax(),r=parseInt(e.length/2/a);e.length/2%a!=0&&(r+=1),t.serviceCode=0,t.serviceInfo="encode ok",t.serviceData={},t.serviceData.dataEncode=new Array;var n=0;for(n=0;n<r-1;n++)t.serviceData.dataEncode[n]=e.substr(n*a*2,2*a),t.serviceData.dataEncode[n]=getWXFrame(t.serviceData.dataEncode[n],n,r);return t.serviceData.dataEncode[r-1]=e.substring((r-1)*a*2),t.serviceData.dataEncode[r-1]=getWXFrame(t.serviceData.dataEncode[r-1],r-1,r),t}function getWXFrame(e,t,a){var r=e,n=new ArrayBuffer(10),s=new DataView(n),i="",l="",d=0,u=e.length/2;0==t?s.setInt8(0,128+(a-1-t&255)):s.setInt8(0,a-1-t&255),r="3301"+(i=_wjUtils2.default.byteArray2hexStr(n).substring(0,2))+_wjUtils2.default.byte2hexStr(255&u)+r;for(var c=_wjUtils2.default.hexStr2byteArray(r),o=1;o<c.length;o++)d^=c[o];r+=_wjUtils2.default.byte2hexStr(d);var f=_wjUtils2.default.hexStr2byteArray(r).length;if(127<f){s.setInt8(0,128+(f%128&255)),s.setInt8(1,f/128&255),i=_wjUtils2.default.byteArray2hexStr(n).substring(0,4);var w=f+8+4+3;s.setInt8(0,w>>8&255),s.setInt8(1,255&w),l=_wjUtils2.default.byteArray2hexStr(n).substring(0,4)}else{s.setInt8(0,255&f),i=_wjUtils2.default.byteArray2hexStr(n).substring(0,2);w=f+8+4+2;s.setInt8(0,w>>8&255),s.setInt8(1,255&w),l=_wjUtils2.default.byteArray2hexStr(n).substring(0,4)}return r="FE01"+l+"753100000A0012"+i+r+"1800"}function getGBFrame(e,t,a){var r=e,n=new ArrayBuffer(10),s=new DataView(n),i=0,l=e.length/2;0==t?(s.setInt8(0,128+(a>>8&255)),s.setInt8(1,255&a)):(s.setInt8(0,t+1>>8&255),s.setInt8(1,t+1&255)),s.setInt8(2,255&l),r="50"+_wjUtils2.default.byteArray2hexStr(n).substring(0,6)+r;for(var d=_wjUtils2.default.hexStr2byteArray(r),u=0;u<d.length;u++)i^=d[u];return r+=_wjUtils2.default.byte2hexStr(i)}module.exports={encode:encode};
"use strict";
var _wjUtils = require("./wjUtils.js"),
_wjUtils2 = _interopRequireDefault(_wjUtils);

function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}

function encode(e, t, a) {
var r = _wjUtils2.default.getProtocolType(),
n = getETCData(e, t, a),
s = {};
return 0 == r ? s = encode_GB(n) : 1 == r && (s = encode_WX(n)), s
}

function getETCData(e, t, a) {
var r = "";
return r = "A0" == a || "A3" == a || "A4" == a || "82" == a ? a + t + (r = getCommand(e)) : e, _wjUtils2.default
.showLog("组拼ETCData完毕:", r.length / 2, r), r
}

function getCommand(e) {
var t = e,
a = _wjUtils2.default.getDATA_TYPE(),
r = e.length / 2,
n = new ArrayBuffer(10),
s = new DataView(n);
if (0 == a) i = 256 < r ? (s.setInt8(0, 4 + r & 255), s.setInt8(1, 4 + r >> 8 & 255), s.setInt8(2, 128), s.setInt8(
3, 130), s.setInt8(4, r >> 8 & 255), s.setInt8(5, 255 & r), n.slice(0, 6)) : 128 < r && r <= 256 ? (s
.setInt8(0, 3 + r & 255), s.setInt8(1, 3 + r >> 8 & 255), s.setInt8(2, 128), s.setInt8(3, 129), s.setInt8(4,
r), n.slice(0, 5)) : (s.setInt8(0, 2 + r & 255), s.setInt8(1, 2 + r >> 8 & 255), s.setInt8(2, 128), s
.setInt8(3, r), n.slice(0, 4)), t = _wjUtils2.default.byteArray2hexStr(i) + t;
else if (1 == a) {
var i;
s.setInt8(0, 255 & r), s.setInt8(1, r >> 8 & 255), i = n.slice(0, 2), t = _wjUtils2.default.byteArray2hexStr(
i) + t
}
return t
}

function encode_GB(e) {
var t = {},
a = _wjUtils2.default.getPagLenMax(),
r = parseInt(e.length / 2 / a);
e.length / 2 % a != 0 && (r += 1);
var n = new ArrayBuffer(10);
new DataView(n);
t.serviceCode = 0, t.serviceInfo = "encode ok", t.serviceData = {}, t.serviceData.dataEncode = new Array;
for (var s = 0; s < r - 1; s++) t.serviceData.dataEncode[s] = e.substr(s * a * 2, 2 * a), t.serviceData.dataEncode[
s] = getGBFrame(t.serviceData.dataEncode[s], s, r);
return t.serviceData.dataEncode[r - 1] = e.substring((r - 1) * a * 2), t.serviceData.dataEncode[r - 1] = getGBFrame(
t.serviceData.dataEncode[r - 1], r - 1, r), t
}

function encode_WX(e) {
var t = {},
a = _wjUtils2.default.getPagLenMax(),
r = parseInt(e.length / 2 / a);
e.length / 2 % a != 0 && (r += 1), t.serviceCode = 0, t.serviceInfo = "encode ok", t.serviceData = {}, t.serviceData
.dataEncode = new Array;
var n = 0;
for (n = 0; n < r - 1; n++) t.serviceData.dataEncode[n] = e.substr(n * a * 2, 2 * a), t.serviceData.dataEncode[n] =
getWXFrame(t.serviceData.dataEncode[n], n, r);
return t.serviceData.dataEncode[r - 1] = e.substring((r - 1) * a * 2), t.serviceData.dataEncode[r - 1] = getWXFrame(
t.serviceData.dataEncode[r - 1], r - 1, r), t
}

function getWXFrame(e, t, a) {
var r = e,
n = new ArrayBuffer(10),
s = new DataView(n),
i = "",
l = "",
d = 0,
u = e.length / 2;
0 == t ? s.setInt8(0, 128 + (a - 1 - t & 255)) : s.setInt8(0, a - 1 - t & 255), r = "3301" + (i = _wjUtils2.default
.byteArray2hexStr(n).substring(0, 2)) + _wjUtils2.default.byte2hexStr(255 & u) + r;
for (var c = _wjUtils2.default.hexStr2byteArray(r), o = 1; o < c.length; o++) d ^= c[o];
r += _wjUtils2.default.byte2hexStr(d);
var f = _wjUtils2.default.hexStr2byteArray(r).length;
if (127 < f) {
s.setInt8(0, 128 + (f % 128 & 255)), s.setInt8(1, f / 128 & 255), i = _wjUtils2.default.byteArray2hexStr(n)
.substring(0, 4);
var w = f + 8 + 4 + 3;
s.setInt8(0, w >> 8 & 255), s.setInt8(1, 255 & w), l = _wjUtils2.default.byteArray2hexStr(n).substring(0, 4)
} else {
s.setInt8(0, 255 & f), i = _wjUtils2.default.byteArray2hexStr(n).substring(0, 2);
w = f + 8 + 4 + 2;
s.setInt8(0, w >> 8 & 255), s.setInt8(1, 255 & w), l = _wjUtils2.default.byteArray2hexStr(n).substring(0, 4)
}
return r = "FE01" + l + "753100000A0012" + i + r + "1800"
}

function getGBFrame(e, t, a) {
var r = e,
n = new ArrayBuffer(10),
s = new DataView(n),
i = 0,
l = e.length / 2;
0 == t ? (s.setInt8(0, 128 + (a >> 8 & 255)), s.setInt8(1, 255 & a)) : (s.setInt8(0, t + 1 >> 8 & 255), s.setInt8(1,
t + 1 & 255)), s.setInt8(2, 255 & l), r = "50" + _wjUtils2.default.byteArray2hexStr(n).substring(0, 6) + r;
for (var d = _wjUtils2.default.hexStr2byteArray(r), u = 0; u < d.length; u++) i ^= d[u];
return r += _wjUtils2.default.byte2hexStr(i)
}
module.exports = {
encode: encode
};

+ 113
- 1
static/etc/WJAPI/wjDataInteract.js View File

@@ -1 +1,113 @@
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_wjService=require("./wjService.js"),_wjService2=_interopRequireDefault(_wjService),_wjUtils=require("./wjUtils.js"),_wjUtils2=_interopRequireDefault(_wjUtils),_wjDataDecode=require("./wjDataDecode.js"),_wjDataDecode2=_interopRequireDefault(_wjDataDecode);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var TAG_FUNCTION="function",sendCallback=void 0,TimerID=null;function _StartSendData(o,e){var s={},u=0,c=0;null!=TimerID&&(clearTimeout(TimerID),TimerID=null),_wjDataDecode2.default.init(),TimerID=setTimeout(pro_timeout,1e4),_wjUtils2.default.showLog(TimerID,"开启时钟"),sendCallback=e,_wjService2.default._SetDataListenerCallBack(!0,datacallback),function t(){var e="";40*c>=o[u].length&&(u++,c=0);u<o.length&&(e=o[u].length>=40*(c+1)?o[u].substring(40*c,40*(c+1)):o[u].substring(40*c,o[u].length));if(""==e)_wjUtils2.default.showLog("数据发送完毕!");else{for(var a=_wjUtils2.default.hexStr2byteArray(e),l=new ArrayBuffer(a.byteLength),r=new DataView(l),i=0;i<a.byteLength;i++)r.setUint8(i,a[i]);_wjUtils2.default.showLog("发送数据:",e),_wjService2.default._writeBLECharacteristicValue(l,function(e){0==e.serviceCode?(c++,t()):(_wjUtils2.default.showError(TimerID,"数据发送失败,取消时钟"),null!=TimerID&&(clearTimeout(TimerID),TimerID=null),_wjService2.default._SetDataListenerCallBack(!1),s.serviceCode=-2,s.serviceInfo="数据发送失败",(void 0===sendCallback?"undefined":_typeof(sendCallback))==TAG_FUNCTION&&sendCallback(s))})}}()}function datacallback(e){_wjService2.default._SetDataListenerCallBack(!0,datacallback),_ReceiveData(e)}function pro_timeout(){var e={};_wjUtils2.default.showError(TimerID,"数据接收超时,取消时钟"),null!=TimerID&&(clearTimeout(TimerID),TimerID=null),_wjService2.default._SetDataListenerCallBack(!1),e.serviceCode=-3,e.serviceInfo="数据接收超时",(void 0===sendCallback?"undefined":_typeof(sendCallback))==TAG_FUNCTION&&sendCallback(e)}function _ReceiveData(e){var t,a,l={},r=_wjUtils2.default.getProtocolType();0==r?t=_wjDataDecode2.default.decode_GB(e):1==r&&(t=_wjDataDecode2.default.decode_WX(e)),0==t.serviceCode&&(null!=(a=PackageDecode(t.serviceData.strData))?(_wjUtils2.default.showLog(TimerID,"接收数据成功,取消时钟"),null!=TimerID&&(clearTimeout(TimerID),TimerID=null),_wjService2.default._SetDataListenerCallBack(!1),l.serviceCode=0,l.serviceInfo="数据接收成功",l.serviceData={},l.serviceData.dataBuff=a):(_wjUtils2.default.showError(TimerID,"数据解析失败,取消时钟"),null!=TimerID&&(clearTimeout(TimerID),TimerID=null),_wjService2.default._SetDataListenerCallBack(!1),l.serviceCode=-1,l.serviceInfo="数据解析失败"),(void 0===sendCallback?"undefined":_typeof(sendCallback))==TAG_FUNCTION&&sendCallback(l))}function PackageDecode(e){if(null==e||null==e)return _wjUtils2.default.showError("revStrData == null"),null;var t,a=_wjUtils2.default.getDATA_TYPE(),l=_wjUtils2.default.hexStr2byteArray(e),r=0,i=l[1],o=l[0];if(_wjUtils2.default.showLog("WJPackageDecode:",e),0!=i)return _wjUtils2.default.showError("WJ结果码非00"),null;switch(o){case 146:case 176:case 179:case 180:if(0==a){var s=7;129==l[5]&&(129==l[6]?(r=255&l[7],s+=1):130==l[6]?(r=l[7]<<8,r+=255&l[8],s+=2):r=255&l[6]),t=l.slice(s,r+s),c=_wjUtils2.default.byteArray2hexStr(t)}else 1==a&&(t=l.slice(5),c=_wjUtils2.default.APDU2TPDU(_wjUtils2.default.byteArray2hexStr(t)));return _wjUtils2.default.showLog("WJ有效数据长度:",c.length/2,c),_wjUtils2.default.showLog("操作类型ok",o),c;case 145:case 148:case 144:var u=(255&l[3])<<8;u+=l[2],t=l.slice(4,u+4);var c=_wjUtils2.default.byteArray2hexStr(t);return _wjUtils2.default.showLog("WJ有效数据长度:",u,_wjUtils2.default.byteArray2hexStr(t)),_wjUtils2.default.showLog("操作类型ok",o),c;case 181:u=l[2];return t=l.slice(3,u+3),_wjUtils2.default.showLog("WJ有效数据长度:",u,_wjUtils2.default.byteArray2hexStr(t)),_wjUtils2.default.showLog("操作类型ok",o),_wjUtils2.default.byteArray2hexStr(t);default:return _wjUtils2.default.showError("WJ通道类型有误"),null}}module.exports={_StartSendData:_StartSendData,_ReceiveData:_ReceiveData};
"use strict";
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
return typeof e
} : function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" :
typeof e
},
_wjService = require("./wjService.js"),
_wjService2 = _interopRequireDefault(_wjService),
_wjUtils = require("./wjUtils.js"),
_wjUtils2 = _interopRequireDefault(_wjUtils),
_wjDataDecode = require("./wjDataDecode.js"),
_wjDataDecode2 = _interopRequireDefault(_wjDataDecode);

function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
var TAG_FUNCTION = "function",
sendCallback = void 0,
TimerID = null;

function _StartSendData(o, e) {
var s = {},
u = 0,
c = 0;
null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjDataDecode2.default.init(), TimerID = setTimeout(
pro_timeout, 1e4), _wjUtils2.default.showLog(TimerID, "开启时钟"), sendCallback = e, _wjService2.default
._SetDataListenerCallBack(!0, datacallback),
function t() {
var e = "";
40 * c >= o[u].length && (u++, c = 0);
u < o.length && (e = o[u].length >= 40 * (c + 1) ? o[u].substring(40 * c, 40 * (c + 1)) : o[u].substring(
40 * c, o[u].length));
if ("" == e) _wjUtils2.default.showLog("数据发送完毕!");
else {
for (var a = _wjUtils2.default.hexStr2byteArray(e), l = new ArrayBuffer(a.byteLength), r = new DataView(
l), i = 0; i < a.byteLength; i++) r.setUint8(i, a[i]);
_wjUtils2.default.showLog("发送数据:", e), _wjService2.default._writeBLECharacteristicValue(l, function(e) {
0 == e.serviceCode ? (c++, t()) : (_wjUtils2.default.showError(TimerID, "数据发送失败,取消时钟"),
null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjService2.default
._SetDataListenerCallBack(!1), s.serviceCode = -2, s.serviceInfo = "数据发送失败", (
void 0 === sendCallback ? "undefined" : _typeof(sendCallback)) ==
TAG_FUNCTION && sendCallback(s))
})
}
}()
}

function datacallback(e) {
_wjService2.default._SetDataListenerCallBack(!0, datacallback), _ReceiveData(e)
}

function pro_timeout() {
var e = {};
_wjUtils2.default.showError(TimerID, "数据接收超时,取消时钟"), null != TimerID && (clearTimeout(TimerID), TimerID = null),
_wjService2.default._SetDataListenerCallBack(!1), e.serviceCode = -3, e.serviceInfo = "数据接收超时", (void 0 ===
sendCallback ? "undefined" : _typeof(sendCallback)) == TAG_FUNCTION && sendCallback(e)
}

function _ReceiveData(e) {
var t, a, l = {},
r = _wjUtils2.default.getProtocolType();
0 == r ? t = _wjDataDecode2.default.decode_GB(e) : 1 == r && (t = _wjDataDecode2.default.decode_WX(e)), 0 == t
.serviceCode && (null != (a = PackageDecode(t.serviceData.strData)) ? (_wjUtils2.default.showLog(TimerID,
"接收数据成功,取消时钟"), null != TimerID && (clearTimeout(TimerID), TimerID = null), _wjService2.default
._SetDataListenerCallBack(!1), l.serviceCode = 0, l.serviceInfo = "数据接收成功", l.serviceData = {}, l
.serviceData.dataBuff = a) : (_wjUtils2.default.showError(TimerID, "数据解析失败,取消时钟"), null != TimerID && (
clearTimeout(TimerID), TimerID = null), _wjService2.default._SetDataListenerCallBack(!1), l
.serviceCode = -1, l.serviceInfo = "数据解析失败"), (void 0 === sendCallback ? "undefined" : _typeof(
sendCallback)) == TAG_FUNCTION && sendCallback(l))
}

function PackageDecode(e) {
if (null == e || null == e) return _wjUtils2.default.showError("revStrData == null"), null;
var t, a = _wjUtils2.default.getDATA_TYPE(),
l = _wjUtils2.default.hexStr2byteArray(e),
r = 0,
i = l[1],
o = l[0];
if (_wjUtils2.default.showLog("WJPackageDecode:", e), 0 != i) return _wjUtils2.default.showError("WJ结果码非00"), null;
switch (o) {
case 146:
case 176:
case 179:
case 180:
if (0 == a) {
var s = 7;
129 == l[5] && (129 == l[6] ? (r = 255 & l[7], s += 1) : 130 == l[6] ? (r = l[7] << 8, r += 255 & l[8],
s += 2) : r = 255 & l[6]), t = l.slice(s, r + s), c = _wjUtils2.default.byteArray2hexStr(t)
} else 1 == a && (t = l.slice(5), c = _wjUtils2.default.APDU2TPDU(_wjUtils2.default.byteArray2hexStr(t)));
return _wjUtils2.default.showLog("WJ有效数据长度:", c.length / 2, c), _wjUtils2.default.showLog("操作类型ok", o), c;
case 145:
case 148:
case 144:
var u = (255 & l[3]) << 8;
u += l[2], t = l.slice(4, u + 4);
var c = _wjUtils2.default.byteArray2hexStr(t);
return _wjUtils2.default.showLog("WJ有效数据长度:", u, _wjUtils2.default.byteArray2hexStr(t)), _wjUtils2.default
.showLog("操作类型ok", o), c;
case 181:
u = l[2];
return t = l.slice(3, u + 3), _wjUtils2.default.showLog("WJ有效数据长度:", u, _wjUtils2.default.byteArray2hexStr(
t)), _wjUtils2.default.showLog("操作类型ok", o), _wjUtils2.default.byteArray2hexStr(t);
default:
return _wjUtils2.default.showError("WJ通道类型有误"), null
}
}
module.exports = {
_StartSendData: _StartSendData,
_ReceiveData: _ReceiveData
};

+ 243
- 1
static/etc/WJAPI/wjService.js
File diff suppressed because it is too large
View File


+ 1
- 0
utils/network/api.js View File

@@ -7,6 +7,7 @@ export const envs = {
//开发环境配置
development: {
baseUrl: "192.168.100.63",
// baseUrl: "222.85.144.89",
},
//生产环境配置
production: {

Loading…
Cancel
Save