Commit fdfb03b7 authored by Skye's avatar Skye

feat: send schedule info api

parent 55ef423c
import { Jensen as Jen } from "./src/jensen"; import { Jensen as Jen } from './src/jensen';
import { Logger } from "./src/utils/utils"; import { Logger } from './src/utils/utils';
export type DeviceInfo = { export type DeviceInfo = {
sn: string; sn: string;
...@@ -8,7 +8,7 @@ export type DeviceInfo = { ...@@ -8,7 +8,7 @@ export type DeviceInfo = {
}; };
export type ReturnStruct = { export type ReturnStruct = {
common: { result: "failed" | "success" }; common: { result: 'failed' | 'success' };
}; };
export type FileInfo = { export type FileInfo = {
...@@ -24,10 +24,8 @@ export type FileInfo = { ...@@ -24,10 +24,8 @@ export type FileInfo = {
export type ScheduleInfo = { export type ScheduleInfo = {
startDate: Date; startDate: Date;
endDate: Date; endDate: Date;
keyAnswer?: string; os: 'Windows' | 'Linux' | 'Mac';
keyHangup?: string; platform: string;
keyReject?: string;
keyMicMute?: string;
}; };
declare class JensenType { declare class JensenType {
...@@ -39,33 +37,20 @@ declare class JensenType { ...@@ -39,33 +37,20 @@ declare class JensenType {
getDeviceInfo: (time?: number) => Promise<DeviceInfo>; getDeviceInfo: (time?: number) => Promise<DeviceInfo>;
listFiles: (time?: number) => Promise<FileInfo[]>; listFiles: (time?: number) => Promise<FileInfo[]>;
tryconnect: (disableOnConnect?: boolean) => Promise<boolean>; tryconnect: (disableOnConnect?: boolean) => Promise<boolean>;
getFile: ( getFile: (fileName: string, length: number, on?: (msg: Uint8Array | 'fail') => void, onprogress?: (size: number) => void) => void;
fileName: string, getFileBlock: (fileName: string, length: number, on?: (msg: Uint8Array | 'fail') => void) => Promise<ReturnStruct['common']>;
length: number,
on?: (msg: Uint8Array | "fail") => void,
onprogress?: (size: number) => void,
) => void;
getFileBlock: (
fileName: string,
length: number,
on?: (msg: Uint8Array | "fail") => void,
) => Promise<ReturnStruct["common"]>;
requestFirmwareUpgrade: ( requestFirmwareUpgrade: (
vn: number, vn: number,
length: number, length: number,
time?: number, time?: number
) => Promise<{ ) => Promise<{
result: "accepted" | "fail"; result: 'accepted' | 'fail';
}>; }>;
beginBNC: (time?: number) => Promise<ReturnStruct["common"]>; beginBNC: (time?: number) => Promise<ReturnStruct['common']>;
endBNC: (time?: number) => Promise<ReturnStruct["common"]>; endBNC: (time?: number) => Promise<ReturnStruct['common']>;
setTime: (date: Date, timeout?: number) => Promise<ReturnStruct["common"]>; setTime: (date: Date, timeout?: number) => Promise<ReturnStruct['common']>;
deleteFile: (fileName: string) => Promise<{ result: string }>; deleteFile: (fileName: string) => Promise<{ result: string }>;
uploadFirmware: ( uploadFirmware: (data: number[], seconds?: number, onProgress?: (cur: number, total: number) => void) => Promise<ReturnStruct['common']>;
data: number[],
seconds?: number,
onProgress?: (cur: number, total: number) => void,
) => Promise<ReturnStruct["common"]>;
getTime: (time?: number) => Promise<{ getTime: (time?: number) => Promise<{
time: string; time: string;
}>; }>;
...@@ -74,19 +59,10 @@ declare class JensenType { ...@@ -74,19 +59,10 @@ declare class JensenType {
autoPlay: boolean; autoPlay: boolean;
notification?: boolean; notification?: boolean;
} | null>; } | null>;
setAutoRecord: ( setAutoRecord: (enable: boolean, time?: number) => Promise<ReturnStruct['common']>;
enable: boolean, setAutoPlay: (enable: boolean, time?: number) => Promise<ReturnStruct['common']>;
time?: number,
) => Promise<ReturnStruct["common"]>;
setAutoPlay: (
enable: boolean,
time?: number,
) => Promise<ReturnStruct["common"]>;
isConnected: () => boolean; isConnected: () => boolean;
setNotification: ( setNotification: (state: boolean, time?: number) => Promise<ReturnStruct['common']>;
state: boolean,
time?: number,
) => Promise<ReturnStruct["common"]>;
ondisconnect?: Function; ondisconnect?: Function;
isStopConnectionCheck: boolean; isStopConnectionCheck: boolean;
getRecordingFile: () => Promise<{ getRecordingFile: () => Promise<{
...@@ -94,29 +70,18 @@ declare class JensenType { ...@@ -94,29 +70,18 @@ declare class JensenType {
createTime: string; createTime: string;
createDate: string; createDate: string;
}>; }>;
getCardInfo: ( getCardInfo: (seconds?: number) => Promise<{ used: number; capacity: number; status: string }>;
seconds?: number, formatCard: (seconds?: number) => Promise<ReturnStruct['common']>;
) => Promise<{ used: number; capacity: number; status: string }>; factoryReset: (seconds?: number) => Promise<ReturnStruct['common']>;
formatCard: (seconds?: number) => Promise<ReturnStruct["common"]>; restoreFactorySettings: (seconds?: number) => Promise<ReturnStruct['common']>;
factoryReset: (seconds?: number) => Promise<ReturnStruct["common"]>;
restoreFactorySettings: (seconds?: number) => Promise<ReturnStruct["common"]>;
getModel: () => string; getModel: () => string;
getFileCount: (seconds?: number) => Promise<{ count: number } | null>; getFileCount: (seconds?: number) => Promise<{ count: number } | null>;
recordTestStart: ( recordTestStart: (type: number, seconds?: number) => Promise<ReturnStruct['common']>;
type: number, recordTestEnd: (type: number, seconds?: number) => Promise<ReturnStruct['common']>;
seconds?: number, test: (seconds?: number) => Promise<ReturnStruct['common']>;
) => Promise<ReturnStruct["common"]>; setBluetoothPromptPlay: (state: boolean, seconds?: number) => Promise<ReturnStruct['common']>;
recordTestEnd: ( writeSerialNumber: (sn: string) => Promise<ReturnStruct['common']>;
type: number, sendScheduleInfo: (info: ScheduleInfo) => Promise<ReturnStruct['common']>;
seconds?: number,
) => Promise<ReturnStruct["common"]>;
test: (seconds?: number) => Promise<ReturnStruct["common"]>;
setBluetoothPromptPlay: (
state: boolean,
seconds?: number,
) => Promise<ReturnStruct["common"]>;
writeSerialNumber: (sn: string) => Promise<ReturnStruct["common"]>;
sendScheduleInfo: (info: ScheduleInfo) => Promise<ReturnStruct["common"]>;
} }
//@ts-ignore //@ts-ignore
......
{ {
"name": "jensen", "name": "jensen",
"version": "1.1.3", "version": "1.0.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "jensen", "name": "jensen",
"version": "1.1.3", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"prettier": "^3.3.3" "prettier": "^3.3.3"
......
import { Logger, Logger as internalLogger, getTimeStr } from './utils/utils'; import { Logger, Logger as internalLogger, getTimeStr, shortcutKeys } from './utils/utils';
const QUERY_DEVICE_INFO = 0x01; const QUERY_DEVICE_INFO = 0x01;
const QUERY_DEVICE_TIME = 0x02; const QUERY_DEVICE_TIME = 0x02;
...@@ -25,7 +25,6 @@ const TEST_SN_WRITE = 0xf007; ...@@ -25,7 +25,6 @@ const TEST_SN_WRITE = 0xf007;
const RECORD_TEST_START = 0xf008; // 录音测试开始 const RECORD_TEST_START = 0xf008; // 录音测试开始
const RECORD_TEST_END = 0xf009; // 录音测试结束 const RECORD_TEST_END = 0xf009; // 录音测试结束
const COMMAND_NAMES = [ const COMMAND_NAMES = [
'invalid-0', 'invalid-0',
'get-device-info', 'get-device-info',
...@@ -46,13 +45,11 @@ const COMMAND_NAMES = [ ...@@ -46,13 +45,11 @@ const COMMAND_NAMES = [
'get-settings', 'get-settings',
'set-settings', 'set-settings',
'get file block', 'get file block',
'factory reset', 'factory reset'
]; ];
function Jensen(log) { function Jensen(log) {
const Logger = log || internalLogger const Logger = log || internalLogger;
let device = null; let device = null;
let actions = {}; let actions = {};
let buffer = []; let buffer = [];
...@@ -131,7 +128,7 @@ function Jensen(log) { ...@@ -131,7 +128,7 @@ function Jensen(log) {
if (r) return; if (r) return;
let conn = await navigator.usb.requestDevice({ let conn = await navigator.usb.requestDevice({
filters: [{ vendorId: 0x10d6 }], filters: [{ vendorId: 0x10d6 }]
}); });
await conn.open(); await conn.open();
self.model = conn.productId == 45069 ? 'hidock-h1e' : 'hidock-h1'; self.model = conn.productId == 45069 ? 'hidock-h1e' : 'hidock-h1';
...@@ -179,8 +176,7 @@ function Jensen(log) { ...@@ -179,8 +176,7 @@ function Jensen(log) {
Logger.info('jensen', 'disconnect', 'disconnect'); Logger.info('jensen', 'disconnect', 'disconnect');
try { try {
await device?.close(); await device?.close();
} catch (e) { } catch (e) {}
}
}; };
this.send = function (cmd, seconds, onprogress) { this.send = function (cmd, seconds, onprogress) {
...@@ -257,7 +253,7 @@ function Jensen(log) { ...@@ -257,7 +253,7 @@ function Jensen(log) {
tag: tag, tag: tag,
resolve: resolve, resolve: resolve,
reject: reject, reject: reject,
timeout: t, timeout: t
}; };
}); });
}; };
...@@ -319,8 +315,7 @@ function Jensen(log) { ...@@ -319,8 +315,7 @@ function Jensen(log) {
if (self.onreceive) { if (self.onreceive) {
try { try {
self.onreceive(totalBytes); self.onreceive(totalBytes);
} catch (e) { } catch (e) {}
}
} else { } else {
// if (self.decodeTimeout) clearTimeout(self.decodeTimeout); // if (self.decodeTimeout) clearTimeout(self.decodeTimeout);
// self.decodeTimeout = setTimeout(function () { // self.decodeTimeout = setTimeout(function () {
...@@ -345,7 +340,7 @@ function Jensen(log) { ...@@ -345,7 +340,7 @@ function Jensen(log) {
sendNext(); sendNext();
const msg = result.message; const msg = result.message;
return result && msg.id === TRANSFER_FILE ? msg.body : null; return result && msg.id === TRANSFER_FILE ? msg.body : null;
} };
const tryDecode = function () { const tryDecode = function () {
// 一个容器,比单独任意一个小包要大一点儿,好像还差一点儿 // 一个容器,比单独任意一个小包要大一点儿,好像还差一点儿
...@@ -388,14 +383,7 @@ function Jensen(log) { ...@@ -388,14 +383,7 @@ function Jensen(log) {
Logger.debug( Logger.debug(
'jensen', 'jensen',
'receive', 'receive',
'recv: ' + 'recv: ' + cname + ', seq: ' + msg.sequence + ', data bytes: ' + msg.body?.byteLength + ', data: ' + heading.join(' ')
cname +
', seq: ' +
msg.sequence +
', data bytes: ' +
msg.body?.byteLength +
', data: ' +
heading.join(' '),
); );
try { try {
let handler = Jensen.handlers[msg.id]; let handler = Jensen.handlers[msg.id];
...@@ -403,11 +391,7 @@ function Jensen(log) { ...@@ -403,11 +391,7 @@ function Jensen(log) {
if (r) trigger(r, msg.id); if (r) trigger(r, msg.id);
} catch (e) { } catch (e) {
trigger(e); trigger(e);
Logger.error( Logger.error('jensen', 'receive', 'recv: ' + COMMAND_NAMES[msg.id] + ', seq: ' + msg.sequence + ', error: ' + String(e));
'jensen',
'receive',
'recv: ' + COMMAND_NAMES[msg.id] + ', seq: ' + msg.sequence + ', error: ' + String(e),
);
} }
sendNext(); sendNext();
} }
...@@ -451,14 +435,14 @@ function Jensen(log) { ...@@ -451,14 +435,14 @@ function Jensen(log) {
dataView[startIndex + idx + 0], dataView[startIndex + idx + 0],
dataView[startIndex + idx + 1], dataView[startIndex + idx + 1],
dataView[startIndex + idx + 2], dataView[startIndex + idx + 2],
dataView[startIndex + idx + 3], dataView[startIndex + idx + 3]
); );
idx += 4; idx += 4;
let len = read_int( let len = read_int(
dataView[startIndex + idx + 0], dataView[startIndex + idx + 0],
dataView[startIndex + idx + 1], dataView[startIndex + idx + 1],
dataView[startIndex + idx + 2], dataView[startIndex + idx + 2],
dataView[startIndex + idx + 3], dataView[startIndex + idx + 3]
); );
let padding = (len >> 24) & 0xff; let padding = (len >> 24) & 0xff;
len = len & 0xffffff; len = len & 0xffffff;
...@@ -621,7 +605,7 @@ Jensen.prototype.listFiles = async function () { ...@@ -621,7 +605,7 @@ Jensen.prototype.listFiles = async function () {
let fnpad = function (v) { let fnpad = function (v) {
return v > 9 ? v : '0' + v; return v > 9 ? v : '0' + v;
}; };
for (let i = start; i < data.length;) { for (let i = start; i < data.length; ) {
let len = 0; let len = 0;
let fname = []; let fname = [];
...@@ -674,7 +658,7 @@ Jensen.prototype.listFiles = async function () { ...@@ -674,7 +658,7 @@ Jensen.prototype.listFiles = async function () {
time: ftime, time: ftime,
duration: duration, duration: duration,
length: flen, length: flen,
signature: sign.join(''), signature: sign.join('')
}); });
} }
// if (fcount == -1 && (fc)) // if (fcount == -1 && (fc))
...@@ -731,7 +715,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -731,7 +715,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
let audio = document.getElementById('test_audio'); let audio = document.getElementById('test_audio');
if (!audio) { if (!audio) {
audio = document.createElement('audio'); audio = document.createElement('audio');
audio.id = 'test_audio' audio.id = 'test_audio';
audio.src = 'https://audionotes.hidock.com/test/test.aac'; audio.src = 'https://audionotes.hidock.com/test/test.aac';
audio.loop = true; audio.loop = true;
audio.controls = false; audio.controls = false;
...@@ -774,10 +758,10 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -774,10 +758,10 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
if (msg != null) { if (msg != null) {
flen += msg.body.length || msg.body.byteLength; flen += msg.body.length || msg.body.byteLength;
ondata(msg.body); ondata(msg.body);
Logger.info('jensen', 'getFile length', `${length} ${flen}`) Logger.info('jensen', 'getFile length', `${length} ${flen}`);
if (flen >= length) { if (flen >= length) {
document.removeEventListener('visibilitychange', visibilitychange); document.removeEventListener('visibilitychange', visibilitychange);
Logger.info('jensen', 'getFile', 'file download finish.') Logger.info('jensen', 'getFile', 'file download finish.');
clearEventAndTask(); clearEventAndTask();
// return OK indicates all file blocks received // return OK indicates all file blocks received
return 'OK'; return 'OK';
...@@ -785,7 +769,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -785,7 +769,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
} else { } else {
document.removeEventListener('visibilitychange', visibilitychange); document.removeEventListener('visibilitychange', visibilitychange);
clearEventAndTask(); clearEventAndTask();
Logger.info('jensen', 'getFile', 'file download fail.') Logger.info('jensen', 'getFile', 'file download fail.');
ondata('fail'); ondata('fail');
} }
}; };
...@@ -833,7 +817,7 @@ Jensen.prototype.setAutoRecord = function (enable, seconds) { ...@@ -833,7 +817,7 @@ Jensen.prototype.setAutoRecord = function (enable, seconds) {
}; };
Jensen.prototype.setAutoPlay = function (enable, seconds) { Jensen.prototype.setAutoPlay = function (enable, seconds) {
if (this.versionNumber < 327714) return { result: false }; if (this.versionNumber < 327714) return { result: false };
return this.send(new Command(SET_SETTINGS).body([0, 0, 0, 0, 0, 0, 0, enable ? 1 : 2,]), seconds); return this.send(new Command(SET_SETTINGS).body([0, 0, 0, 0, 0, 0, 0, enable ? 1 : 2]), seconds);
}; };
Jensen.prototype.setNotification = function (enable, seconds) { Jensen.prototype.setNotification = function (enable, seconds) {
if (this.versionNumber < 327714) return { result: false }; if (this.versionNumber < 327714) return { result: false };
...@@ -842,10 +826,10 @@ Jensen.prototype.setNotification = function (enable, seconds) { ...@@ -842,10 +826,10 @@ Jensen.prototype.setNotification = function (enable, seconds) {
Jensen.prototype.setBluetoothPromptPlay = function (enable, seconds) { Jensen.prototype.setBluetoothPromptPlay = function (enable, seconds) {
// h1e 6.1.4 393476 // h1e 6.1.4 393476
// h1 5.1.4 327940 // h1 5.1.4 327940
if (this.model === 'hidock-h1e' && this.versionNumber < 393476) return { result: false } if (this.model === 'hidock-h1e' && this.versionNumber < 393476) return { result: false };
if (this.model === 'hidock-h1' && this.versionNumber < 327940) return { result: false } if (this.model === 'hidock-h1' && this.versionNumber < 327940) return { result: false };
return this.send(new Command(SET_SETTINGS).body([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, enable ? 2 : 1]), seconds); return this.send(new Command(SET_SETTINGS).body([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, enable ? 2 : 1]), seconds);
} };
Jensen.prototype.getCardInfo = function (seconds) { Jensen.prototype.getCardInfo = function (seconds) {
if (this.versionNumber < 327733) return null; if (this.versionNumber < 327733) return null;
...@@ -872,7 +856,7 @@ Jensen.prototype.test = async function (seconds) { ...@@ -872,7 +856,7 @@ Jensen.prototype.test = async function (seconds) {
}; };
Jensen.prototype.getFileBlock = async function (filename, length, ondata) { Jensen.prototype.getFileBlock = async function (filename, length, ondata) {
if (typeof (length) != 'number') throw new Error('parameter `length` required'); if (typeof length != 'number') throw new Error('parameter `length` required');
if (length <= 0) throw new Error('parameter `length` must greater than zero'); if (length <= 0) throw new Error('parameter `length` must greater than zero');
if (this.fileLength > 0) return null; if (this.fileLength > 0) return null;
...@@ -888,7 +872,7 @@ Jensen.prototype.getFileBlock = async function (filename, length, ondata) { ...@@ -888,7 +872,7 @@ Jensen.prototype.getFileBlock = async function (filename, length, ondata) {
this.fileReadBytes = 0; this.fileReadBytes = 0;
return this.send(new Command(GET_FILE_BLOCK).body(data)); return this.send(new Command(GET_FILE_BLOCK).body(data));
} };
Jensen.prototype.writeSerialNumber = async function (sn) { Jensen.prototype.writeSerialNumber = async function (sn) {
let data = []; let data = [];
...@@ -896,23 +880,28 @@ Jensen.prototype.writeSerialNumber = async function (sn) { ...@@ -896,23 +880,28 @@ Jensen.prototype.writeSerialNumber = async function (sn) {
data.push(sn.charCodeAt(i)); data.push(sn.charCodeAt(i));
} }
return this.send(new Command(TEST_SN_WRITE).body(data)); return this.send(new Command(TEST_SN_WRITE).body(data));
} };
const commonMessageParser = (msg) => { const commonMessageParser = (msg) => {
return { result: msg.body[0] === 0x00 ? 'success' : 'failed' }; return { result: msg.body[0] === 0x00 ? 'success' : 'failed' };
}; };
Jensen.prototype.sendScheduleInfo = function (info) { Jensen.prototype.sendScheduleInfo = function (info) {
const startDate = this.to_bcd(getTimeStr(info.startDate)); let codes = new Array(33).fill(0);
const endDate = this.to_bcd(getTimeStr(info.endDate)); if (shortcutKeys[info.platform] && shortcutKeys[info.platform][info.os]) {
const keyAnswer = [3, 7, 4, 0, 0, 0, 0, 0]; codes = shortcutKeys[info.platform][info.os];
const keyHangup = [3, 7, 5, 0, 0, 0, 0, 0]; }
const keyReject = [3, 7, 6, 0, 0, 0, 0, 0]; let startDate = new Array(7).fill(0);
const keyMicMute = [3, 7, 7, 0, 0, 0, 0, 0]; let endDate = new Array(7).fill(0);
const body = [...startDate, ...endDate, 0, 0, ...keyAnswer, ...keyHangup, ...keyReject, ...keyMicMute]; if (info.startDate && info.endDate) {
startDate = this.to_bcd(getTimeStr(info.startDate));
endDate = this.to_bcd(getTimeStr(info.endDate));
}
const reserved = 0x00; // 预留
const body = [...startDate, ...endDate, 0x00, ...codes];
console.log('send schedule info', info, body); console.log('send schedule info', info, body);
return this.send(new Command(SCHEDULE_INFO).body(body)); return this.send(new Command(SCHEDULE_INFO).body(body));
}; };
Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser); Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser);
Jensen.registerHandler(BNC_DEMO_TEST, commonMessageParser); Jensen.registerHandler(BNC_DEMO_TEST, commonMessageParser);
...@@ -945,7 +934,7 @@ Jensen.registerHandler(QUERY_DEVICE_INFO, (msg, jensen) => { ...@@ -945,7 +934,7 @@ Jensen.registerHandler(QUERY_DEVICE_INFO, (msg, jensen) => {
return { return {
versionCode: vc.join('.'), versionCode: vc.join('.'),
versionNumber: vn, versionNumber: vn,
sn: sn, sn: sn
}; };
}); });
Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => { Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => {
...@@ -956,10 +945,10 @@ Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => { ...@@ -956,10 +945,10 @@ Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => {
msg.body[3] & 0xff, msg.body[3] & 0xff,
msg.body[4] & 0xff, msg.body[4] & 0xff,
msg.body[5] & 0xff, msg.body[5] & 0xff,
msg.body[6] & 0xff, msg.body[6] & 0xff
); );
return { return {
time: time === '00000000000000' ? 'unknown' : time.replace(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/gi, '$1-$2-$3 $4:$5:$6'), time: time === '00000000000000' ? 'unknown' : time.replace(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/gi, '$1-$2-$3 $4:$5:$6')
}; };
}); });
Jensen.registerHandler(QUERY_FILE_COUNT, (msg) => { Jensen.registerHandler(QUERY_FILE_COUNT, (msg) => {
...@@ -1042,7 +1031,7 @@ Jensen.registerHandler(GET_RECORDING_FILE, (msg) => { ...@@ -1042,7 +1031,7 @@ Jensen.registerHandler(GET_RECORDING_FILE, (msg) => {
time: ftime, time: ftime,
duration: 0, duration: 0,
length: 0, length: 0,
signature: '0'.repeat(32), signature: '0'.repeat(32)
}; };
} }
}); });
...@@ -1050,8 +1039,7 @@ Jensen.registerHandler(RECORD_TEST_START, commonMessageParser); ...@@ -1050,8 +1039,7 @@ Jensen.registerHandler(RECORD_TEST_START, commonMessageParser);
Jensen.registerHandler(RECORD_TEST_END, commonMessageParser); Jensen.registerHandler(RECORD_TEST_END, commonMessageParser);
Jensen.registerHandler(DEVICE_MSG_TEST, commonMessageParser); Jensen.registerHandler(DEVICE_MSG_TEST, commonMessageParser);
Jensen.registerHandler(GET_FILE_BLOCK, commonMessageParser); Jensen.registerHandler(GET_FILE_BLOCK, commonMessageParser);
Jensen.registerHandler(TEST_SN_WRITE, commonMessageParser) Jensen.registerHandler(TEST_SN_WRITE, commonMessageParser);
Jensen.registerHandler(SCHEDULE_INFO, commonMessageParser) Jensen.registerHandler(SCHEDULE_INFO, commonMessageParser);
export { Jensen }; export { Jensen };
const Level = { const Level = {
debug: "debug", debug: 'debug',
info: "info", info: 'info',
error: "error", error: 'error'
}; };
export const Logger = { export const Logger = {
...@@ -22,7 +22,7 @@ export const Logger = { ...@@ -22,7 +22,7 @@ export const Logger = {
module, module,
procedure, procedure,
message: String(message), message: String(message),
time: new Date().getTime(), time: new Date().getTime()
}; };
this.messages.push(log); this.messages.push(log);
if (this.consoleOutput) { if (this.consoleOutput) {
...@@ -33,22 +33,20 @@ export const Logger = { ...@@ -33,22 +33,20 @@ export const Logger = {
_print(log) { _print(log) {
let time = new Date(log.time); let time = new Date(log.time);
console.info( console.info(
"[" + '[' +
(log.level === "error" ? "x" : "*") + (log.level === 'error' ? 'x' : '*') +
"][" + '][' +
time.toLocaleString() + time.toLocaleString() +
"](" + '](' +
log.module + log.module +
" - " + ' - ' +
log.procedure + log.procedure +
") " + ') ' +
log.message, log.message
); );
}, },
filter(module, procedure) { filter(module, procedure) {
return this.messages.filter( return this.messages.filter((i) => i.module === module && i.procedure === procedure);
(i) => i.module === module && i.procedure === procedure,
);
}, },
enableConsoleOutput() { enableConsoleOutput() {
this.consoleOutput = true; this.consoleOutput = true;
...@@ -71,25 +69,250 @@ export const Logger = { ...@@ -71,25 +69,250 @@ export const Logger = {
} }
return true; return true;
}); });
}, }
}; };
export const getTimeStr = (date: Date) => { export const getTimeStr = (date: Date) => {
let str = let str =
date.getFullYear() + date.getFullYear() +
"-0" + '-0' +
(date.getMonth() + 1) + (date.getMonth() + 1) +
"-0" + '-0' +
date.getDate() + date.getDate() +
"-0" + '-0' +
date.getHours() + date.getHours() +
"-0" + '-0' +
date.getMinutes() + date.getMinutes() +
"-0" + '-0' +
date.getSeconds(); date.getSeconds();
str = str.replace( str = str.replace(/(\d{4})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})/gi, '$1$2$3$4$5$6');
/(\d{4})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})\-0*(\d{2})/gi,
"$1$2$3$4$5$6",
);
return str; return str;
}; };
const keyMap: { [key: string]: number } = {
A: 0x04,
B: 0x05,
C: 0x06,
D: 0x07,
E: 0x08,
F: 0x09,
G: 0x0a,
H: 0x0b,
I: 0x0c,
J: 0x0d,
K: 0x0e,
L: 0x0f,
M: 0x10,
N: 0x11,
O: 0x12,
P: 0x13,
Q: 0x14,
R: 0x15,
S: 0x16,
T: 0x17,
U: 0x18,
V: 0x19,
W: 0x1a,
X: 0x1b,
Y: 0x1c,
Z: 0x1b,
ENTER: 0x28,
ESCAPE: 0x29,
SPACE: 0x2c
};
const HotKeyBuilder = {
control: false,
shift: false,
alt: false,
guiKey: false,
keys: [],
withControl: () => {
HotKeyBuilder.control = true;
return HotKeyBuilder;
},
withShift: () => {
HotKeyBuilder.shift = true;
return HotKeyBuilder;
},
withAlt: () => {
HotKeyBuilder.alt = true;
return HotKeyBuilder;
},
withGuiKey: () => {
HotKeyBuilder.guiKey = true;
return HotKeyBuilder;
},
withKey: (key: string) => {
if (HotKeyBuilder.keys.length >= 2) throw new Error('exceed max key bindings');
HotKeyBuilder.keys.push(HotKeyBuilder.__mapping(key));
return HotKeyBuilder;
},
__mapping: (key: string) => {
return keyMap[key];
},
build: () => {
let key1 = 0;
if (HotKeyBuilder.control) key1 |= 0x01 << 0;
if (HotKeyBuilder.shift) key1 |= 0x01 << 1;
if (HotKeyBuilder.alt) key1 |= 0x01 << 2;
if (HotKeyBuilder.guiKey) key1 |= 0x01 << 3;
let codes = [
0x03,
key1,
HotKeyBuilder.keys.length ? HotKeyBuilder.keys[0] : 0x00,
HotKeyBuilder.keys.length > 1 ? HotKeyBuilder.keys[1] : 0x00,
0x00,
0x00,
0x00,
0x00
];
HotKeyBuilder.control = false;
HotKeyBuilder.shift = false;
HotKeyBuilder.alt = false;
HotKeyBuilder.guiKey = false;
HotKeyBuilder.keys = [];
return codes;
}
};
const enterKeyCode = (answer: 0 | 1 = 0, hangup: 0 | 1 = 0, reject: 0 | 1 = 0, micMute: 0 | 1 = 0) => {
let code = 0;
if (answer) code |= 0x01 << 0;
if (hangup) code |= 0x01 << 1;
if (reject) code |= 0x01 << 2;
if (micMute) code |= 0x01 << 3;
return code;
};
const emptyCodes = [0, 0, 0, 0, 0, 0, 0, 0];
export const shortcutKeys = {
Zoom: {
Windows: [
enterKeyCode(0, 1),
...emptyCodes,
HotKeyBuilder.withAlt().withKey('Q').build(),
...emptyCodes,
HotKeyBuilder.withAlt().withKey('A').build()
],
Mac: [
enterKeyCode(0, 1),
...emptyCodes,
HotKeyBuilder.withGuiKey().withKey('W').build(),
...emptyCodes,
HotKeyBuilder.withGuiKey().withShift().withKey('A').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Teams: {
Windows: [
enterKeyCode(),
HotKeyBuilder.withControl().withShift().withKey('A').build(),
HotKeyBuilder.withControl().withShift().withKey('H').build(),
HotKeyBuilder.withControl().withShift().withKey('D').build(),
HotKeyBuilder.withControl().withShift().withKey('M').build()
],
Mac: [
enterKeyCode(),
HotKeyBuilder.withGuiKey().withShift().withKey('A').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('H').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('D').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('M').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
'Google Meetings': {
Windows: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withControl().withKey('D').build()],
Mac: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withGuiKey().withKey('D').build()],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Webex: {
Windows: [
enterKeyCode(),
HotKeyBuilder.withControl().withShift().withKey('C').build(),
HotKeyBuilder.withControl().withKey('L').build(),
HotKeyBuilder.withControl().withKey('D').build(),
HotKeyBuilder.withControl().withKey('M').build()
],
Mac: [
enterKeyCode(),
HotKeyBuilder.withControl().withShift().withKey('C').build(),
HotKeyBuilder.withGuiKey().withKey('L').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('D').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('M').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Feishu: {
Windows: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withControl().withShift().withKey('D').build()],
Mac: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withGuiKey().withShift().withKey('D').build()],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Lark: {
Windows: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withControl().withShift().withKey('D').build()],
Mac: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withGuiKey().withShift().withKey('D').build()],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
WeChat: {
Windows: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes],
Mac: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Line: {
Windows: [
enterKeyCode(0, 1, 1),
...emptyCodes,
HotKeyBuilder.withKey('ESCAPE').build(),
HotKeyBuilder.withKey('ESCAPE').build(),
HotKeyBuilder.withControl().withShift().withKey('A').build()
],
Mac: [
enterKeyCode(0, 1, 1),
...emptyCodes,
HotKeyBuilder.withKey('ESCAPE').build(),
HotKeyBuilder.withKey('ESCAPE').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('A').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
WhatsApp: {
Windows: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes],
Mac: [
enterKeyCode(),
...emptyCodes,
HotKeyBuilder.withGuiKey().withKey('W').build(),
HotKeyBuilder.withGuiKey().withKey('W').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('M').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Slack: {
Windows: [
enterKeyCode(),
...emptyCodes,
...emptyCodes,
...emptyCodes,
HotKeyBuilder.withControl().withShift().withKey('SPACE').build()
],
Mac: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, HotKeyBuilder.withGuiKey().withShift().withKey('SPACE').build()],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
},
Discord: {
Windows: [
enterKeyCode(),
HotKeyBuilder.withControl().withKey('ENTER').build(),
...emptyCodes,
HotKeyBuilder.withKey('ESCAPE').build(),
HotKeyBuilder.withControl().withShift().withKey('M').build()
],
Mac: [
enterKeyCode(),
HotKeyBuilder.withGuiKey().withKey('ENTER').build(),
...emptyCodes,
HotKeyBuilder.withGuiKey().withKey('ESCAPE').build(),
HotKeyBuilder.withGuiKey().withShift().withKey('M').build()
],
Linux: [enterKeyCode(), ...emptyCodes, ...emptyCodes, ...emptyCodes, ...emptyCodes]
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment