2025-04-14 10:57:27 +08:00

605 lines
23 KiB
JavaScript

"use strict";
const common_vendor = require("../../../common/vendor.js");
const utils_tools = require("../../../utils/tools.js");
const utils_api = require("../../../utils/api.js");
const utils_aes_util = require("../../../utils/aes_util.js");
if (!Array) {
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uni_col2 = common_vendor.resolveComponent("uni-col");
const _easycom_uni_row2 = common_vendor.resolveComponent("uni-row");
const _easycom_bikeCodeScan2 = common_vendor.resolveComponent("bikeCodeScan");
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
const _easycom_uni_list2 = common_vendor.resolveComponent("uni-list");
(_easycom_uni_icons2 + _easycom_uni_col2 + _easycom_uni_row2 + _easycom_bikeCodeScan2 + _easycom_uni_forms_item2 + _easycom_uni_easyinput2 + _easycom_uni_forms2 + _easycom_uni_load_more2 + _easycom_uni_list2)();
}
const _easycom_uni_icons = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-icons/uni-icons.js";
const _easycom_uni_col = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-col/uni-col.js";
const _easycom_uni_row = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-row/uni-row.js";
const _easycom_bikeCodeScan = () => "../../../components/bikeCodeScan/bikeCodeScan.js";
const _easycom_uni_forms_item = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.js";
const _easycom_uni_easyinput = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.js";
const _easycom_uni_forms = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.js";
const _easycom_uni_load_more = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-load-more/uni-load-more.js";
const _easycom_uni_list = () => "../../../node-modules/@dcloudio/uni-ui/lib/uni-list/uni-list.js";
if (!Math) {
(_easycom_uni_icons + _easycom_uni_col + _easycom_uni_row + _easycom_bikeCodeScan + _easycom_uni_forms_item + _easycom_uni_easyinput + _easycom_uni_forms + _easycom_uni_load_more + _easycom_uni_list)();
}
const serviceId = "0000FFF0-0000-1000-8000-00805F9B34FB";
const characteristicId = "0000FFF6-0000-1000-8000-00805F9B34FB";
const _sfc_main = {
__name: "bluetoothscan",
setup(__props) {
const bluetoothForm = common_vendor.ref(null);
const bikeCodeScanRef = common_vendor.ref(null);
const blueTooth = common_vendor.ref({
blueConn: false,
deviceId: "",
bikeCode: "",
ecuCode: "-",
ecuSn: "-",
blueSignal: "-",
autoBlueState: true,
blueState: {
load: "",
btuDisabled: true,
detectionState: "",
msg: "已断开"
},
openLock: {
load: "",
btuDisabled: true,
detectionState: "",
msg: ""
},
closeLock: {
load: "",
btuDisabled: true,
detectionState: "",
msg: ""
},
openBatteryHouse: {
load: "",
btuDisabled: true,
detectionState: "",
msg: ""
},
closeBatteryHouse: {
load: "",
btuDisabled: true,
detectionState: "",
msg: ""
}
});
const contentText = common_vendor.ref({
contentdown: "",
contentrefresh: "读取中",
contentnomore: ""
});
common_vendor.onMounted(() => {
common_vendor.index.openBluetoothAdapter({
success(res) {
if (res.errno == 0) {
blueTooth.value.blueConn = true;
}
},
fail(err) {
err.errMsg;
if (err.errCode == 10001)
;
}
});
common_vendor.index.onBluetoothAdapterStateChange(function(res) {
if (res["available"]) {
blueTooth.value.blueConn = true;
} else {
blueTooth.value.blueConn = false;
}
});
});
let timer;
const bikeCodeScanChange = (data) => {
clearTimeout(timer);
blueTooth.value.bikeCode = data;
if (data != "") {
timer = setTimeout(function() {
getEbikeInfo();
}, 5e3);
}
};
const getEbikeInfo = () => {
if (blueTooth.value.deviceId != "") {
createBLEConnection();
} else {
utils_api.callEbikeInfo("getBikeINfoData?bikeCode=" + blueTooth.value.bikeCode).then((res) => {
if (res.code == 200 && res.data) {
if (res.data.ecuCode != "") {
blueTooth.value.ecuCode = res.data.ecuCode;
blueTooth.value.ecuSn = res.data.ecuSn;
blueTooth.value.blueState.load == "loading";
setTimeout(function() {
startBluetoothDevicesDiscovery("ECU-" + res.data.ecuSn);
}, 2e3);
} else {
utils_tools.showModelMessage("该车辆未绑定中控");
}
} else {
utils_tools.showModelMessage("该车辆未绑定中控");
}
}).catch((err) => {
utils_tools.showModelMessage("该车辆未绑定中控");
});
}
};
const stopBluetoothDevicesDiscovery = () => {
common_vendor.index.stopBluetoothDevicesDiscovery({
success(res) {
}
});
};
const closeConn = () => {
common_vendor.index.closeBLEConnection({
deviceId: blueTooth.value.deviceId,
success(res) {
blueTooth.value.autoBlueState = false;
}
});
};
const execCommon = (comm) => {
switch (comm) {
case "openLock":
var buffer = new ArrayBuffer(5);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735655554);
dataView.setUint8(4, 130);
writeBLECharacteristicValueWithBuff(buffer);
break;
case "closeLock":
var buffer = new ArrayBuffer(5);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735655553);
dataView.setUint8(4, 129);
writeBLECharacteristicValueWithBuff(buffer);
break;
case "openBatteryHouse":
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735655817);
dataView.setUint8(4, 0);
var i;
var bcc;
for (i = 0; i < 2; i++) {
bcc ^= dataView.getInt8(i + 3);
}
dataView.setInt8(5, bcc);
writeBLECharacteristicValueWithBuff(buffer);
break;
case "closeBatteryHouse":
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735655817);
dataView.setUint8(4, 1);
var i;
var bcc;
for (i = 0; i < 2; i++) {
bcc ^= dataView.getInt8(i + 3);
}
dataView.setInt8(5, bcc);
writeBLECharacteristicValueWithBuff(buffer);
break;
}
};
const startBluetoothDevicesDiscovery = (sn) => {
common_vendor.index.startBluetoothDevicesDiscovery({
success(res) {
if (res.errno == 0) {
common_vendor.index.onBluetoothDeviceFound(function(res2) {
const devices = res2.devices;
for (let i = 0; i < devices.length; i++) {
if (devices[i].localName == sn) {
stopBluetoothDevicesDiscovery();
blueTooth.value.deviceId = devices[i].deviceId;
blueTooth.value.blueSignal = devices[i].RSSI;
createBLEConnection();
break;
}
}
});
setTimeout(function() {
stopBluetoothDevicesDiscovery();
}, 12e4);
}
},
fail(err) {
}
});
};
const createBLEConnection = () => {
blueTooth.value.autoBlueState = true;
common_vendor.index.createBLEConnection({
deviceId: blueTooth.value.deviceId,
success(res) {
blueTooth.value.blueState.load == "";
blueTooth.value.blueState.detectionState = "open";
blueTooth.value.blueState.msg = "已连接";
blueTooth.value.blueState.btuDisabled = false;
blueTooth.value.openLock.btuDisabled = false;
blueTooth.value.closeLock.btuDisabled = false;
blueTooth.value.openBatteryHouse.btuDisabled = false;
blueTooth.value.closeBatteryHouse.btuDisabled = false;
common_vendor.index.onBLEConnectionStateChange(function(res2) {
if (!res2.connected && blueTooth.value.autoBlueState) {
blueTooth.value.blueState.btuDisabled = false;
blueTooth.value.openLock.btuDisabled = true;
blueTooth.value.closeLock.btuDisabled = true;
blueTooth.value.openBatteryHouse.btuDisabled = true;
blueTooth.value.closeBatteryHouse.btuDisabled = true;
blueTooth.value.blueState.detectionState = "close";
blueTooth.value.blueState.msg = "已断开";
createBLEConnection();
}
});
startNotify();
},
fail(err) {
blueTooth.value.blueSignal = "-";
blueTooth.value.blueState.btuDisabled = false;
blueTooth.value.openLock.btuDisabled = true;
blueTooth.value.closeLock.btuDisabled = true;
blueTooth.value.openBatteryHouse.btuDisabled = true;
blueTooth.value.closeBatteryHouse.btuDisabled = true;
blueTooth.value.blueState.detectionState = "close";
blueTooth.value.blueState.msg = "已断开";
utils_tools.showModelMessage("蓝牙连接失败");
}
});
};
const startNotify = () => {
common_vendor.index.notifyBLECharacteristicValueChange({
state: true,
deviceId: blueTooth.value.deviceId,
serviceId,
characteristicId,
success(res) {
common_vendor.index.onBLECharacteristicValueChange(function(res2) {
var hex = bufTohex(res2.value);
if (hex.length > 10) {
var header = hex.substring(0, 4);
if (header == "6774") {
var contentL1 = hex.substring(4, 6);
var contentL = parseInt(contentL1, 16);
if ((contentL + 5) * 2 == hex.length) {
distributeCommandsWithDataStr(hex);
} else if ((contentL + 5) * 2 > hex.length) {
self.responseStr = hex;
} else
;
return;
}
}
});
verification();
}
});
};
const verification = (mac, key1, key2) => {
if (mac && key1 && key2) {
var buffer = new ArrayBuffer(20);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735659658);
var sourceKey1 = mac + key1;
var AESEncrypt = utils_aes_util.AES128ECBEncrypt(sourceKey1, key2);
if (AESEncrypt.length != 32) {
return;
}
for (var i = 0; i < 4; i++) {
var subStr = AESEncrypt.substring(i * 8, i * 8 + 8, 16);
dataView.setUint32(i * 4 + 4, parseInt(subStr, 16));
}
var i;
var bcc;
for (i = 0; i < 17; i++) {
bcc ^= dataView.getInt8(i + 3);
}
var buffer2 = new ArrayBuffer(1);
var dataView2 = new DataView(buffer2);
dataView2.setUint8(0, bcc);
common_vendor.index.__f__("log", "at pages/warehouse/bluetooth/bluetoothscan.vue:495", "验证", bufTohex(buffer));
writeBLECharacteristicValueWithBuff(buffer);
setTimeout(() => {
writeBLECharacteristicValueWithBuff(buffer2);
}, 300);
} else {
var buffer = new ArrayBuffer(5);
var dataView = new DataView(buffer);
dataView.setUint32(0, 1735655562);
dataView.setUint8(4, 138);
writeBLECharacteristicValueWithBuff(buffer);
}
};
const writeBLECharacteristicValueWithBuff = (buffer) => {
common_vendor.index.writeBLECharacteristicValue({
deviceId: blueTooth.value.deviceId,
serviceId,
characteristicId,
value: buffer,
success: function(res) {
common_vendor.index.__f__("log", "at pages/warehouse/bluetooth/bluetoothscan.vue:516", "writeBLECharacteristicValue success", res.errMsg);
},
fail: function(res) {
common_vendor.index.__f__("log", "at pages/warehouse/bluetooth/bluetoothscan.vue:519", "writeBLECharacteristicValue fail", res.errMsg);
},
complete: function(res) {
}
});
};
let verificationTimes = 0;
const distributeCommandsWithDataStr = (hex) => {
var cmd = hex.substring(6, 8);
var code = hex.substring(8, 10);
var errCode = code;
var desDic = {};
var des = "";
if (code == "00") {
des = "成功";
errCode = 0;
} else if (code == "ff") {
des = "锁已打开";
errCode = -1;
} else if (code == "fe") {
des = "电量不足";
errCode = -2;
} else if (code == "fd") {
des = "加密验证失败";
errCode = -3;
} else if (code == "fc") {
des = "内存空间不足";
errCode = -4;
} else if (code == "fb") {
des = "格式错误";
errCode = -5;
} else if (code == "fa") {
des = "没有验证或验证失败";
errCode = -6;
desDic["mac"] = hex.substring(10, 22);
desDic["key"] = hex.substring(22, 30);
} else if (code == "f9") {
des = "flash写入失败";
errCode = -7;
} else if (code == "f8") {
des = "数据空";
errCode = -8;
} else if (code == "f7") {
des = "操作失败";
errCode = -9;
} else if (code == "f6") {
des = "运输模式下无法执行该指令";
errCode = -10;
} else if (code == "f5") {
des = "锁车失败,车辆未停止";
errCode = -11;
} else if (code == "f4") {
des = "未检测到道钉信息";
errCode = -12;
} else if (parseInt(code, 16) == 149) {
des = "摄像头正在工作中";
errCode = parseInt(code, 16);
} else if (parseInt(code, 16) == 150) {
des = "摄像头离线";
errCode = parseInt(code, 16);
} else if (parseInt(code, 16) == 151) {
des = "车辆不在使用中(临时停车或是还车中)无法使用摄像头还车";
errCode = parseInt(code, 16);
} else if (parseInt(code, 16) == 152) {
des = "执行命令超时";
errCode = parseInt(code, 16);
} else if (parseInt(code, 16) == 153) {
des = "摄像头执行失败";
errCode = parseInt(code, 16);
} else if (parseInt(code, 16) == 154) {
des = "不在站点中或没有垂直停车";
errCode = parseInt(code, 16);
} else {
des = "未知错误码" + code;
errCode = code;
}
common_vendor.index.__f__("log", "at pages/warehouse/bluetooth/bluetoothscan.vue:596", "distributeCommandsWithDataStr", hex);
desDic["errCode"] = errCode;
desDic["des"] = des;
if (cmd == "4a") {
if (verificationTimes >= 1) {
verificationTimes = 0;
if (errCode == -6) {
verificationTimes = 1;
verification(desDic.mac, desDic.key, "6666660000888888");
return;
}
return;
} else {
verificationTimes += 1;
}
if (errCode == -6) {
verification(desDic.mac, desDic.key, "6666660000888888");
}
} else {
common_vendor.index.__f__("log", "at pages/warehouse/bluetooth/bluetoothscan.vue:721", "未找到对应指令及函数");
}
};
const bufTohex = (buffer) => {
return Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join("");
};
return (_ctx, _cache) => {
return common_vendor.e({
a: !blueTooth.value.blueConn
}, !blueTooth.value.blueConn ? {
b: common_vendor.p({
type: "info",
size: "100",
color: "#b4b4b4"
}),
c: common_vendor.p({
span: 24
}),
d: common_vendor.p({
span: 24
})
} : {}, {
e: blueTooth.value.blueConn
}, blueTooth.value.blueConn ? common_vendor.e({
f: common_vendor.sr(bikeCodeScanRef, "28b8d040-6,28b8d040-5", {
"k": "bikeCodeScanRef"
}),
g: common_vendor.o(bikeCodeScanChange),
h: common_vendor.p({
codeValue: blueTooth.value.bikeCode
}),
i: common_vendor.p({
label: "车辆编号",
name: "bikeCode"
}),
j: common_vendor.o(($event) => blueTooth.value.ecuCode = $event),
k: common_vendor.p({
placeholder: "-",
disabled: true,
modelValue: blueTooth.value.ecuCode
}),
l: common_vendor.p({
label: "中控编号",
name: "ecuCode"
}),
m: common_vendor.o(($event) => blueTooth.value.blueSignal = $event),
n: common_vendor.p({
placeholder: "-",
disabled: true,
modelValue: blueTooth.value.blueSignal
}),
o: common_vendor.p({
label: "蓝牙信号",
name: "blueSignal"
}),
p: common_vendor.sr(bluetoothForm, "28b8d040-4", {
"k": "bluetoothForm"
}),
q: common_vendor.p({
modelValue: blueTooth.value,
labelWidth: "100px"
}),
r: blueTooth.value.blueState.load == "loading"
}, blueTooth.value.blueState.load == "loading" ? {
s: common_vendor.p({
status: blueTooth.value.blueState.load,
iconType: "circle",
["icon-size"]: 20,
["content-text"]: contentText.value
})
} : {}, {
t: blueTooth.value.blueState.detectionState == "close"
}, blueTooth.value.blueState.detectionState == "close" ? {
v: common_vendor.t(blueTooth.value.blueState.msg)
} : {}, {
w: blueTooth.value.blueState.detectionState == "open"
}, blueTooth.value.blueState.detectionState == "open" ? {
x: common_vendor.t(blueTooth.value.blueState.msg)
} : {}, {
y: blueTooth.value.blueState.detectionState != "open"
}, blueTooth.value.blueState.detectionState != "open" ? {
z: blueTooth.value.blueState.btuDisabled,
A: common_vendor.o(getEbikeInfo)
} : {}, {
B: blueTooth.value.blueState.detectionState == "open"
}, blueTooth.value.blueState.detectionState == "open" ? {
C: blueTooth.value.blueState.btuDisabled,
D: common_vendor.o(closeConn)
} : {}, {
E: common_vendor.p({
border: true
}),
F: blueTooth.value.openLock.load == "loading"
}, blueTooth.value.openLock.load == "loading" ? {
G: common_vendor.p({
status: blueTooth.value.openLock.load,
iconType: "circle",
["icon-size"]: 20,
["content-text"]: contentText.value
})
} : {}, {
H: blueTooth.value.openLock.detectionState == "error"
}, blueTooth.value.openLock.detectionState == "error" ? {} : {}, {
I: common_vendor.t(blueTooth.value.openLock.msg),
J: blueTooth.value.openLock.detectionState == "success"
}, blueTooth.value.openLock.detectionState == "success" ? {} : {}, {
K: common_vendor.t(blueTooth.value.openLock.msg),
L: blueTooth.value.openLock.btuDisabled,
M: common_vendor.o(($event) => execCommon("openLock")),
N: common_vendor.p({
border: true
}),
O: blueTooth.value.closeLock.load == "loading"
}, blueTooth.value.closeLock.load == "loading" ? {
P: common_vendor.p({
status: blueTooth.value.closeLock.load,
iconType: "circle",
["icon-size"]: 20,
["content-text"]: contentText.value
})
} : {}, {
Q: blueTooth.value.closeLock.detectionState == "error"
}, blueTooth.value.closeLock.detectionState == "error" ? {} : {}, {
R: common_vendor.t(blueTooth.value.closeLock.msg),
S: blueTooth.value.closeLock.detectionState == "success"
}, blueTooth.value.closeLock.detectionState == "success" ? {} : {}, {
T: common_vendor.t(blueTooth.value.closeLock.msg),
U: blueTooth.value.closeLock.btuDisabled,
V: common_vendor.o(($event) => execCommon("closeLock")),
W: common_vendor.p({
border: true
}),
X: blueTooth.value.openBatteryHouse.load == "loading"
}, blueTooth.value.openBatteryHouse.load == "loading" ? {
Y: common_vendor.p({
status: blueTooth.value.openBatteryHouse.load,
iconType: "circle",
["icon-size"]: 20,
["content-text"]: contentText.value
})
} : {}, {
Z: blueTooth.value.openBatteryHouse.detectionState == "error"
}, blueTooth.value.openBatteryHouse.detectionState == "error" ? {} : {}, {
aa: common_vendor.t(blueTooth.value.openBatteryHouse.msg),
ab: blueTooth.value.openBatteryHouse.detectionState == "success"
}, blueTooth.value.openBatteryHouse.detectionState == "success" ? {} : {}, {
ac: common_vendor.t(blueTooth.value.openBatteryHouse.msg),
ad: blueTooth.value.openBatteryHouse.btuDisabled,
ae: common_vendor.o(($event) => execCommon("openBatteryHouse")),
af: common_vendor.p({
border: true
}),
ag: blueTooth.value.closeBatteryHouse.load == "loading"
}, blueTooth.value.closeBatteryHouse.load == "loading" ? {
ah: common_vendor.p({
status: blueTooth.value.closeBatteryHouse.load,
iconType: "circle",
["icon-size"]: 20,
["content-text"]: contentText.value
})
} : {}, {
ai: blueTooth.value.closeBatteryHouse.detectionState == "error"
}, blueTooth.value.closeBatteryHouse.detectionState == "error" ? {} : {}, {
aj: common_vendor.t(blueTooth.value.closeBatteryHouse.msg),
ak: blueTooth.value.closeBatteryHouse.detectionState == "success"
}, blueTooth.value.closeBatteryHouse.detectionState == "success" ? {} : {}, {
al: common_vendor.t(blueTooth.value.closeBatteryHouse.msg),
am: blueTooth.value.openBatteryHouse.btuDisabled,
an: common_vendor.o(($event) => execCommon("closeBatteryHouse")),
ao: common_vendor.p({
border: true
})
}) : {});
};
}
};
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/warehouse/bluetooth/bluetoothscan.js.map