import BLESDK from './ble' import TASK from './taskQueue' import { aes128Encrypt } from '@/utils/index' export function strInsert(str, length = 2) { if (!str || !str.length) return '' var reg = new RegExp('\\w{1,' + length + '}', 'g') let ma = str.match(reg) return ma.map((item) => `0x${item}`) } // 10进制转16进制 export const hex = (hex) => { hex = Number(hex) return hex < 16 ? '0' + hex.toString(16) : String(hex.toString(16)) } // 握手 export function handshake() { let list = strInsert(aes128Encrypt(`10a1010259414B2D56302E302E310000`)) TASK.addTask(list) } // 同步时间 export function asyncDate() { const now = new Date(); const year = now.getFullYear(); const month = (now.getMonth() + 1).toString(); const day = now.getDate().toString(); const hours = now.getHours().toString(); const minutes = now.getMinutes().toString(); const seconds = now.getSeconds().toString(); const zone = (new Date().getTimezoneOffset() / 60) * -1; let str = [ "10", "a1", "04", "b2", hex(zone & 0xff), hex(year >> 8), hex(year & 0xff), hex(month), hex(day), hex(hours), hex(minutes), hex(seconds), "00", "00", "00", "00", ] .toString() .replaceAll(",", ""); TASK.addTask(strInsert(aes128Encrypt(str))); } // 获取版本号 export function getVersions() { TASK.addTask(strInsert(aes128Encrypt(`10a102b1000000000000000000000000`))); } // 重启 export function restart() { TASK.addTask(strInsert(aes128Encrypt(`0906800000`))); } // 获取新版睡眠 export function getNewSleep() { TASK.addTask(strInsert(aes128Encrypt(`10A31a00ff00000000000000000000`))); } // 新版睡眠-接收回复 export function sleepResReply(type, date, num) { TASK.addTask(strInsert(aes128Encrypt(`10A3${hex(type)}${hex(date)}${hex(num)}0000000000000000000000`))); }