|
@@ -0,0 +1,1235 @@
|
|
|
+const common = require('./common.js');
|
|
|
+
|
|
|
+import SystemInfoUtil from './SystemInfoUtil.js';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const bluetoothDevices = {
|
|
|
+ ZX16D: require('./bluetooth/ZX16D.js'),
|
|
|
+ FMBMS: require('./bluetooth/FMBMS.js'),
|
|
|
+ LFBMS: require('./bluetooth/LFBMS.js'),
|
|
|
+ JYBMS: require('./bluetooth/LFBMS.js'),
|
|
|
+ BLFM: require('./bluetooth/BLFM.js'),
|
|
|
+ ZXBT: require('./bluetooth/ZXBT.js'),
|
|
|
+ LSBMS: require('./bluetooth/LSBMS.js'),
|
|
|
+ LSCabinet: require('./bluetooth/LSCabinet.js'),
|
|
|
+ ZXBTS: require('./bluetooth/ZXBTS.js'),
|
|
|
+ AD3BTS: require('./bluetooth/AD3BTS.js'),
|
|
|
+ BWJT: require('./bluetooth/ZXBT_JL.js'),
|
|
|
+ JTBMS: require('./bluetooth/ZXBT_JL.js'),
|
|
|
+ ZXZK: require('./bluetooth/ZXCar.js')
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+function initBluetooth() {
|
|
|
+ console.log('initBluetooth');
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ uni.onBluetoothAdapterStateChange((res) => {
|
|
|
+ console.log(app,res,'onBluetoothAdapterStateChange');
|
|
|
+ Object.keys(app.globalData.adapterStateChangeFunc).forEach((n) => app.globalData.adapterStateChangeFunc[n](res));
|
|
|
+ });
|
|
|
+
|
|
|
+ uni.onBLEConnectionStateChange((res) => {
|
|
|
+ console.log('蓝牙状态变化/可能是断开连接',res);
|
|
|
+
|
|
|
+ if (app.globalData.connectionState[res.deviceId]) {
|
|
|
+ app.globalData.connectionState[res.deviceId].connected = res.connected;
|
|
|
+ const device = app.globalData.connectionState[res.deviceId].device;
|
|
|
+ if (app.globalData.connectionStateChangeFunc[device.mac_id]) {
|
|
|
+ Object.keys(app.globalData.connectionStateChangeFunc[device.mac_id]).forEach((p) => app.globalData.connectionStateChangeFunc[device.mac_id][p](res));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ console.log(app,"监听值")
|
|
|
+
|
|
|
+ uni.onBLECharacteristicValueChange((res) => {
|
|
|
+ console.log(res,'restest1111');
|
|
|
+ const car_sn=uni.getStorageSync('car_info').car_sn;
|
|
|
+ if (app.globalData.connectionState[car_sn]) {
|
|
|
+ const device = app.globalData.connectionState[car_sn].device;
|
|
|
+ console.log(res.serviceId.toUpperCase() == bluetoothDeviceConfig(device).readServiceID.toUpperCase(),'00000');
|
|
|
+ if (
|
|
|
+ res.serviceId.toUpperCase() == bluetoothDeviceConfig(device).readServiceID.toUpperCase() &&
|
|
|
+ res.characteristicId.toUpperCase() == bluetoothDeviceConfig(device).readID.toUpperCase()
|
|
|
+ ) {
|
|
|
+ console.log(app.globalData.connectionState[car_sn],bluetoothDeviceConfig(device),'data--------');
|
|
|
+ var data = bluetoothDeviceConfig(device).readData(device, res.value, app.globalData.connectionState[car_sn].data);
|
|
|
+
|
|
|
+ if (data) {
|
|
|
+ const app = getApp();
|
|
|
+ app.globalData.connectionState[car_sn].data = data;
|
|
|
+ if (app.globalData.characteristicStateChangeFunc[device.mac_id]) {
|
|
|
+ Object.keys(app.globalData.characteristicStateChangeFunc[device.mac_id]).forEach((p) =>
|
|
|
+ app.globalData.characteristicStateChangeFunc[device.mac_id][p](data)
|
|
|
+ );
|
|
|
+
|
|
|
+ console.log(app.globalData.connectionState[car_sn].data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function onAdapterStateChange(name, callback) {
|
|
|
+ const app = getApp();
|
|
|
+ app.globalData.adapterStateChangeFunc[name] = callback;
|
|
|
+}
|
|
|
+
|
|
|
+function offAdapterStateChange(name) {
|
|
|
+ const app = getApp();
|
|
|
+ delete app.globalData.adapterStateChangeFunc[name];
|
|
|
+}
|
|
|
+
|
|
|
+function onConnectionStateChange(macid, name, callback) {
|
|
|
+ const app = getApp();
|
|
|
+ if (!app.globalData.connectionStateChangeFunc[macid]) {
|
|
|
+ app.globalData.connectionStateChangeFunc[macid] = {};
|
|
|
+ }
|
|
|
+ app.globalData.connectionStateChangeFunc[macid][name] = callback;
|
|
|
+}
|
|
|
+
|
|
|
+function offConnectionStateChange(macid, name) {
|
|
|
+ const app = getApp();
|
|
|
+ if (app.globalData.connectionStateChangeFunc[macid]) {
|
|
|
+ delete app.globalData.connectionStateChangeFunc[macid][name];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function onCharacteristicStateChange(macid, name, callback) {
|
|
|
+ const app = getApp();
|
|
|
+ if (!app.globalData.characteristicStateChangeFunc[macid]) {
|
|
|
+ app.globalData.characteristicStateChangeFunc[macid] = {};
|
|
|
+ }
|
|
|
+ app.globalData.characteristicStateChangeFunc[macid][name] = callback;
|
|
|
+}
|
|
|
+
|
|
|
+function offCharacteristicStateChange(macid, name) {
|
|
|
+ const app = getApp();
|
|
|
+ if (app.globalData.characteristicStateChangeFunc[macid]) {
|
|
|
+ delete app.globalData.characteristicStateChangeFunc[macid][name];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getAdapterState(callback = () => {}, fail = () => {}) {
|
|
|
+ uni.getBluetoothAdapterState({
|
|
|
+ success: (res) => {
|
|
|
+ callback(res);
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function openBluetoothAdapter(callback = () => {}, fail = () => {}) {
|
|
|
+ uni.openBluetoothAdapter({
|
|
|
+ success: (res) => {
|
|
|
+ console.log('初始化蓝牙模块成功');
|
|
|
+ callback(res);
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function closeBluetoothAdapter(callback = () => {}, fail = () => {}) {
|
|
|
+ uni.closeBluetoothAdapter({
|
|
|
+ success: (res) => {
|
|
|
+ const app = getApp();
|
|
|
+ app.globalData.adapterStateChangeFunc = {};
|
|
|
+ app.globalData.connectionStateChangeFunc = {};
|
|
|
+ app.globalData.characteristicStateChangeFunc = {};
|
|
|
+ app.globalData.connectionState = {};
|
|
|
+ callback(res);
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function acceptDevice(device) {
|
|
|
+
|
|
|
+ return bluetoothDevices[device.bt_type] || (bluetoothDevices[device.device_type] && bluetoothDevices[device.device_type].acceptDevice(device)) ? true : false;
|
|
|
+}
|
|
|
+
|
|
|
+function isSingleBT(device) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device) && bluetoothDeviceConfig(device).isSingleBt) {
|
|
|
+
|
|
|
+ return bluetoothDeviceConfig(device).isSingleBt();
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function isBuzzer(device) {
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device) && bluetoothDeviceConfig(device).isBuzzer) {
|
|
|
+
|
|
|
+ return bluetoothDeviceConfig(device).isBuzzer();
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function isVoltageToEle(device) {
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device) && bluetoothDeviceConfig(device).voltageToEle) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function isSginleBtByMacid(macid) {
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+
|
|
|
+ console.log(app.globalData.connectionState);
|
|
|
+
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isSingleBT(app.globalData.connectionState[deviceId].device);
|
|
|
+}
|
|
|
+function haveBMSForBT(device) {
|
|
|
+ if (bluetoothDeviceConfig(device) && bluetoothDeviceConfig(device).haveBms) {
|
|
|
+ return bluetoothDeviceConfig(device).haveBms();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function findDevice(device, callback = () => {}, fail = () => {}) {
|
|
|
+ console.log('走到了findDevice fun');
|
|
|
+
|
|
|
+ var deviceId = '';
|
|
|
+
|
|
|
+ if (!bluetoothDeviceConfig(device)) {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('查找到为蓝牙设备');
|
|
|
+
|
|
|
+ setTimeout(()=> {
|
|
|
+ uni.startBluetoothDevicesDiscovery({
|
|
|
+
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'startBluetoothDevicesDiscovery');
|
|
|
+
|
|
|
+
|
|
|
+ uni.getBluetoothDevices({
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res,'getBluetoothDevices');
|
|
|
+
|
|
|
+ res.devices.forEach((data) => {
|
|
|
+
|
|
|
+
|
|
|
+ console.log('------',bluetoothDeviceConfig(device).isDevice(device, data));
|
|
|
+ if (bluetoothDeviceConfig(device).isDevice(device, data)) {
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ uni.stopBluetoothDevicesDiscovery();
|
|
|
+ const car_info= uni.getStorageSync('car_info')
|
|
|
+ const deviceIds = data.deviceId;
|
|
|
+ console.log(deviceIds,'deviceIds123');
|
|
|
+ const deviceId = car_info.car_sn;
|
|
|
+ if (app.globalData.connectionState[deviceId]) {
|
|
|
+ app.globalData.connectionState[deviceId].device = device;
|
|
|
+ } else {
|
|
|
+ app.globalData.connectionState[deviceId] = {
|
|
|
+ device: device,
|
|
|
+ deviceName:data.name,
|
|
|
+ deviceId: deviceIds,
|
|
|
+ connected: false,
|
|
|
+ data: {}
|
|
|
+ };
|
|
|
+ }
|
|
|
+ callback(deviceId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(function () {
|
|
|
+ if (!deviceId) {
|
|
|
+
|
|
|
+ uni.stopBluetoothDevicesDiscovery();
|
|
|
+ var res = {
|
|
|
+ errCode: 9000001,
|
|
|
+ errMsg: 'openBluetoothAdapter:find not device',
|
|
|
+ errno: 9000002
|
|
|
+ };
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ }, 5000);
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ uni.stopBluetoothDevicesDiscovery();
|
|
|
+ console.log(res);
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ uni.onBluetoothDeviceFound((res) => {
|
|
|
+ console.log(res,"foundDevice")
|
|
|
+
|
|
|
+
|
|
|
+ res.devices.forEach((data) => {
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device).isDevice(device, data)) {
|
|
|
+
|
|
|
+
|
|
|
+ uni.stopBluetoothDevicesDiscovery();
|
|
|
+ const car_info= uni.getStorageSync('car_info')
|
|
|
+ const deviceIds = data.deviceId;
|
|
|
+ console.log(deviceIds,'deviceIds456');
|
|
|
+ const deviceId = car_info.car_sn;
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ if (app.globalData.connectionState[deviceId]) {
|
|
|
+ app.globalData.connectionState[deviceId].device = device;
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ app.globalData.connectionState[deviceId] = {
|
|
|
+ device: device,
|
|
|
+ deviceName:data.name,
|
|
|
+ deviceId: deviceIds,
|
|
|
+ connected: false,
|
|
|
+ data: {}
|
|
|
+ };
|
|
|
+ console.log(app.globalData.connectionState[deviceId],'datatest--------');
|
|
|
+
|
|
|
+ }
|
|
|
+ callback(deviceId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res);
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 500);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function connectDevice(device, callback = () => {}, fail = () => {}) {
|
|
|
+
|
|
|
+ console.log(device);
|
|
|
+
|
|
|
+ if (!bluetoothDeviceConfig(device) || !bluetoothDeviceConfig(device).acceptDevice(device)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const app = getApp();
|
|
|
+ console.log(app,'连接函数connectDevice deviceId111111');
|
|
|
+
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == device.mac_id);
|
|
|
+ console.log(deviceId,'连接函数connectDevice deviceId');
|
|
|
+
|
|
|
+ if (deviceId == undefined) {
|
|
|
+
|
|
|
+ findDevice(
|
|
|
+ device,
|
|
|
+ (deviceId) => {
|
|
|
+
|
|
|
+ connectDevice(device, callback, fail);
|
|
|
+ },
|
|
|
+ (res) => {
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (app.globalData.connectionState[deviceId].connected) {
|
|
|
+ callback();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const car_sn=uni.getStorageSync('car_info').car_sn
|
|
|
+ const deviceIds = app.globalData.connectionState[car_sn].deviceId
|
|
|
+ console.log(deviceIds,'deviceIds');
|
|
|
+ const device_name=app.globalData.connectionState[car_sn].deviceName
|
|
|
+
|
|
|
+ uni.createBLEConnection({
|
|
|
+ deviceId: deviceIds,
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res,'蓝牙连接成功');
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ app.globalData.connectionState[deviceId] = {
|
|
|
+ device: device,
|
|
|
+ deviceName: device_name,
|
|
|
+ deviceId: deviceIds,
|
|
|
+ connected: true,
|
|
|
+ data: {}
|
|
|
+ };
|
|
|
+
|
|
|
+ alterConnect(
|
|
|
+ device,
|
|
|
+ deviceIds,
|
|
|
+ (res) => {
|
|
|
+ console.log('uni.createBLEConnection');
|
|
|
+ callback(res);
|
|
|
+ },
|
|
|
+ (res) => {
|
|
|
+ console.log(' uni.createBLEConnection');
|
|
|
+
|
|
|
+ closeDevice(deviceId);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ if (res.errCode == -1) {
|
|
|
+ closeDevice(
|
|
|
+ deviceId,
|
|
|
+ (res) => {
|
|
|
+ connectDevice(device, callback, fail);
|
|
|
+ },
|
|
|
+ (res) => {
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function alterConnect(device, deviceId, callback = () => {}, fail = () => {}) {
|
|
|
+
|
|
|
+ console.log("xxxx1")
|
|
|
+ if (!bluetoothDeviceConfig(device) || !bluetoothDeviceConfig(device).acceptDevice(device)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log("xxxx2")
|
|
|
+ console.log(deviceId)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setTimeout(()=>{
|
|
|
+ uni.getBLEDeviceServices({
|
|
|
+ deviceId: deviceId,
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'res1111');
|
|
|
+ console.log(bluetoothDeviceConfig(device).writeServiceID)
|
|
|
+
|
|
|
+ setTimeout(()=>{
|
|
|
+ uni.getBLEDeviceCharacteristics({
|
|
|
+ deviceId: deviceId,
|
|
|
+ serviceId: bluetoothDeviceConfig(device).writeServiceID,
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'res22222');
|
|
|
+
|
|
|
+ uni.getBLEDeviceCharacteristics({
|
|
|
+ deviceId: deviceId,
|
|
|
+ serviceId: bluetoothDeviceConfig(device).readServiceID,
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'res3333');
|
|
|
+
|
|
|
+ uni.notifyBLECharacteristicValueChange({
|
|
|
+ state: true,
|
|
|
+ deviceId: deviceId,
|
|
|
+ serviceId: bluetoothDeviceConfig(device).readServiceID,
|
|
|
+ characteristicId: bluetoothDeviceConfig(device).readID,
|
|
|
+ success(res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device).MTU && SystemInfoUtil.platform == SystemInfoUtil.ANDROID) {
|
|
|
+
|
|
|
+ uni.setBLEMTU({
|
|
|
+ deviceId: deviceId,
|
|
|
+ mtu: bluetoothDeviceConfig(device).MTU,
|
|
|
+ success: (res) => {
|
|
|
+ console.log('setBLEMTU success>>', res);
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device).getNearUnlockSet) {
|
|
|
+ var data = bluetoothDeviceConfig(device).getNearUnlockSet(device, deviceId);
|
|
|
+ console.log(data[0],'data111111');
|
|
|
+
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ setTimeout(()=>{
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ },3000)
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.log('setBLEMTU fail>>', res);
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device).getNearUnlockSet) {
|
|
|
+ var data = bluetoothDeviceConfig(device).getNearUnlockSet(device, deviceId);
|
|
|
+
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (bluetoothDeviceConfig(device).getNearUnlockSet) {
|
|
|
+ var data = bluetoothDeviceConfig(device).getNearUnlockSet(device, deviceId);
|
|
|
+
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log('getBLEDeviceServices fail',res);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },500)
|
|
|
+
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },500)
|
|
|
+}
|
|
|
+
|
|
|
+function closeDevice(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app=getApp()
|
|
|
+
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (!app.globalData.connectionState[deviceId].connected) {
|
|
|
+ callback();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+
|
|
|
+ uni.closeBLEConnection({
|
|
|
+ deviceId: deviceId,
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ if (app.globalData.connectionState[deviceId]) {
|
|
|
+ app.globalData.connectionState[deviceId].connected = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ callback(res);
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+function bmsInfo(macid) {
|
|
|
+ console.log(macid);
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).bmsInfo) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return bluetoothDeviceConfig(device).bmsInfo(device, deviceId, app.globalData.connectionState[deviceId].data);
|
|
|
+}
|
|
|
+function bmsSet(macid, name, vars, callback = () => {}, fail = () => {}) {
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).bmsSet) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).bmsSet(device, deviceId, name, vars);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function writeData(device, deviceId, data, callback = () => {}, fail = () => {}) {
|
|
|
+
|
|
|
+ console.log(data,'data写入---------------------');
|
|
|
+ if (data.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(data,data[0].length);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var byteArray = data.shift()
|
|
|
+ const buffer = new ArrayBuffer(byteArray.length);
|
|
|
+ const dataView = new DataView(buffer);
|
|
|
+
|
|
|
+ for (let i = 0; i < byteArray.length; i++) {
|
|
|
+ dataView.setUint8(i, byteArray[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(data[0],buffer,'buffer写入---------------------');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ plus.bluetooth.writeBLECharacteristicValue({
|
|
|
+
|
|
|
+ deviceId: deviceId,
|
|
|
+ serviceId: bluetoothDeviceConfig(device).writeServiceID,
|
|
|
+ characteristicId: bluetoothDeviceConfig(device).writeID,
|
|
|
+ writeType:'write',
|
|
|
+ value: buffer,
|
|
|
+
|
|
|
+ success(res) {
|
|
|
+ uni.hideLoading();
|
|
|
+ console.log('写入成功');
|
|
|
+
|
|
|
+ if (data.length == 0) {
|
|
|
+ callback(res);
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ }, 150);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fail(res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ fail(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+function stateUpdate(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).stateUpdate) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).stateUpdate(device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function voltageToEle(macid, value, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).voltageToEle) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).voltageToEle(device, value);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function turnOn(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).turnOn) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).turnOn(device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function turnOnBuzzer(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).turnOnBuzzer) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).turnOnBuzzer(device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function turnOffBuzzer(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).turnOffBuzzer) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).turnOffBuzzer(device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function turnOff(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).turnOff) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).turnOff(device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function bmsChargingMOS(macid, value, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).bmsChargingMOS) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).bmsChargingMOS(value - 0, device);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function bmsDischargeMOS(macid, value, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDeviceConfig(device).bmsDischargeMOS) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device).bmsDischargeMOS(value - 0, device);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function isConnected(macid) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return app.globalData.connectionState[deviceId].connected;
|
|
|
+}
|
|
|
+function getData(macid) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return app.globalData.connectionState[deviceId].data;
|
|
|
+}
|
|
|
+function getConnectionState(macid) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return app.globalData.connectionState[deviceId];
|
|
|
+}
|
|
|
+function bluetoothDeviceConfig(device) {
|
|
|
+ if (bluetoothDevices[device.bt_type]) {
|
|
|
+ return bluetoothDevices[device.bt_type];
|
|
|
+ } else if (bluetoothDevices[device.device_type]) {
|
|
|
+ return bluetoothDevices[device.device_type];
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+function isUniversalBluetoothPlugin(device) {
|
|
|
+ if (bluetoothDevices[device.bt_type]) {
|
|
|
+ return bluetoothDevices[device.bt_type];
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+function sendHireCommand(macid, info, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].sendHireCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].sendHireCommand(info);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function sendBackCommand(macid, info, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].sendBackCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].sendBackCommand(info);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function sendExchangeCommand(macid, info, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].sendExchangeCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].sendExchangeCommand(info);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function sendGetCabinetInfoCommand(macid, info, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ console.log(deviceId,'deviceId0000');
|
|
|
+
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ console.log(app.globalData.connectionState[deviceId].device,'device333333');
|
|
|
+ console.log(bluetoothDevices,'deviceId11111');
|
|
|
+ console.log(bluetoothDevices['ZXCAR'].sendGetCabinetInfoCommand,'test333');
|
|
|
+
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+
|
|
|
+ if (!bluetoothDevices[device.device_type].sendGetCabinetInfoCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ console.log(bluetoothDevices[device.device_type].sendGetCabinetInfoCommand(info),'deviceId2222');
|
|
|
+
|
|
|
+ var data = bluetoothDevices[device.device_type].sendGetCabinetInfoCommand(info);
|
|
|
+
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function sendConfirmCommand(macid, value, serialNum, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].sendConfirmCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].sendConfirmCommand(value, serialNum);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function sendCancelCommand(macid, serialNum, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].sendCancelCommand) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].sendCancelCommand(serialNum);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function sendSwitchNormalCommand(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+ if (!bluetoothDevices[device.device_type].switchFactory) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].switchFactory(device,deviceId);
|
|
|
+ if (data) {
|
|
|
+ console.log(data,'写入data');
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function sendOTACommand(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = Object.keys(app.globalData.connectionState).find((i) => app.globalData.connectionState[i].device.mac_id == macid);
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[deviceId].device;
|
|
|
+
|
|
|
+ if ( !bluetoothDevices[device.device_type].otaUpgrade) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDevices[device.device_type].otaUpgrade(device,deviceId);
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ data.then(result => {
|
|
|
+ console.log(result[0],'result');
|
|
|
+ writeData(device, deviceId, [result[0]], callback, fail);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }).catch(error => {
|
|
|
+ console.error(error);
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+function executeDeviceCommand(macid, commandName, callback = () => {}, fail = () => {}) {
|
|
|
+ console.log('test');
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = app.globalData.connectionState[macid].deviceId
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[macid].device;
|
|
|
+ if (!bluetoothDeviceConfig(device)[commandName]) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device)[commandName](device, deviceId);
|
|
|
+ if (data) {
|
|
|
+ setTimeout(()=>{
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ },200)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function turnOnCar(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'turnOnCar', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function turnOffCar(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'turnOffCar', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function findCarCmd(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'findCarCmd', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function openCarSeat(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'openCarSeat', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function openCarTrunk(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'openCarTrunk', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function getCarPressure(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'getCarPressure', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function nearUnlock(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'nearUnlock', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function nearCloseUnlock(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'nearCloseUnlock', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function getSensitivity(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'getSensitivity', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function setSensitivity(macid,type, callback = () => {}, fail = () => {}) {
|
|
|
+ const app = getApp();
|
|
|
+ const deviceId = app.globalData.connectionState[macid].deviceId
|
|
|
+ if (deviceId == undefined) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const device = app.globalData.connectionState[macid].device;
|
|
|
+ if (!bluetoothDeviceConfig(device)[setSensitivity]) {
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var data = bluetoothDeviceConfig(device)[setSensitivity](device, deviceId,type);
|
|
|
+ if (data) {
|
|
|
+ writeData(device, deviceId, data, callback, fail);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fail();
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function setNearUnlock(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'setNearUnlock', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+function getNearUnlockSet(macid, callback = () => {}, fail = () => {}) {
|
|
|
+ return executeDeviceCommand(macid, 'getNearUnlockSet', callback, fail);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ initBluetooth: initBluetooth,
|
|
|
+ onAdapterStateChange: onAdapterStateChange,
|
|
|
+ offAdapterStateChange: offAdapterStateChange,
|
|
|
+ onConnectionStateChange: onConnectionStateChange,
|
|
|
+ offConnectionStateChange: offConnectionStateChange,
|
|
|
+ onCharacteristicStateChange: onCharacteristicStateChange,
|
|
|
+ offCharacteristicStateChange: offCharacteristicStateChange,
|
|
|
+ getAdapterState: getAdapterState,
|
|
|
+ openBluetoothAdapter: openBluetoothAdapter,
|
|
|
+ closeBluetoothAdapter: closeBluetoothAdapter,
|
|
|
+ acceptDevice: acceptDevice,
|
|
|
+ findDevice: findDevice,
|
|
|
+ connectDevice: connectDevice,
|
|
|
+ closeDevice: closeDevice,
|
|
|
+ stateUpdate: stateUpdate,
|
|
|
+ turnOn: turnOn,
|
|
|
+ turnOff: turnOff,
|
|
|
+ turnOnBuzzer: turnOnBuzzer,
|
|
|
+ turnOffBuzzer: turnOffBuzzer,
|
|
|
+ bmsInfo: bmsInfo,
|
|
|
+ bmsSet: bmsSet,
|
|
|
+ isConnected: isConnected,
|
|
|
+ getData: getData,
|
|
|
+ isSingleBT: isSingleBT,
|
|
|
+ isBuzzer: isBuzzer,
|
|
|
+ haveBMSForBT: haveBMSForBT,
|
|
|
+ isSginleBtByMacid: isSginleBtByMacid,
|
|
|
+ getConnectionState: getConnectionState,
|
|
|
+ bmsChargingMOS: bmsChargingMOS,
|
|
|
+ bmsDischargeMOS: bmsDischargeMOS,
|
|
|
+ bluetoothDeviceConfig: bluetoothDeviceConfig,
|
|
|
+ voltageToEle: voltageToEle,
|
|
|
+ isVoltageToEle: isVoltageToEle,
|
|
|
+ isUniversalBluetoothPlugin: isUniversalBluetoothPlugin,
|
|
|
+
|
|
|
+ sendHireCommand: sendHireCommand,
|
|
|
+ sendBackCommand: sendBackCommand,
|
|
|
+ sendExchangeCommand: sendExchangeCommand,
|
|
|
+ sendGetCabinetInfoCommand: sendGetCabinetInfoCommand,
|
|
|
+ sendConfirmCommand: sendConfirmCommand,
|
|
|
+ sendCancelCommand: sendCancelCommand,
|
|
|
+
|
|
|
+ sendSwitchNormalCommand,
|
|
|
+
|
|
|
+
|
|
|
+ sendOTACommand,
|
|
|
+
|
|
|
+ executeDeviceCommand,
|
|
|
+ turnOnCar,
|
|
|
+ turnOffCar,
|
|
|
+ findCarCmd,
|
|
|
+ openCarSeat,
|
|
|
+ openCarTrunk,
|
|
|
+ getCarPressure,
|
|
|
+ nearUnlock,
|
|
|
+ nearCloseUnlock,
|
|
|
+ getSensitivity,
|
|
|
+ setSensitivity,
|
|
|
+ getNearUnlockSet,
|
|
|
+ setNearUnlock,
|
|
|
+
|
|
|
+
|
|
|
+};
|