Commit e5f623cc authored by Skye Yu's avatar Skye Yu

test:

parent 45d95a74
...@@ -11,7 +11,7 @@ declare module 'jensen' { ...@@ -11,7 +11,7 @@ declare module 'jensen' {
name: string; name: string;
createDate: string; createDate: string;
createTime: string; createTime: string;
time: string; time: Date;
duration: number; duration: number;
length: number; length: number;
signature: string; signature: string;
......
...@@ -73,7 +73,7 @@ function Jensen() { ...@@ -73,7 +73,7 @@ function Jensen() {
const RECV_BUFF_SIZE = 51200; const RECV_BUFF_SIZE = 51200;
const _check_conn_status = () => { const _check_conn_status = () => {
if (device?.opened == false) { if (device?.opened === false) {
try { try {
clearTimeout(statusTimeout); clearTimeout(statusTimeout);
if (this.ondisconnect && !this.isStopConnectionCheck) this.ondisconnect(); if (this.ondisconnect && !this.isStopConnectionCheck) this.ondisconnect();
...@@ -292,9 +292,9 @@ function Jensen() { ...@@ -292,9 +292,9 @@ function Jensen() {
}; };
const read_int = function (a, b, c, d) { const read_int = function (a, b, c, d) {
if (arguments.length == 2) { if (arguments.length === 2) {
return ((a & 0xff) << 8) | (b & 0xff); return ((a & 0xff) << 8) | (b & 0xff);
} else if (arguments.length == 4) { } else if (arguments.length === 4) {
return ((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff); return ((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff);
} }
}; };
...@@ -373,12 +373,12 @@ function Jensen() { ...@@ -373,12 +373,12 @@ function Jensen() {
let msg = rst.message; let msg = rst.message;
// WARN: 接下来怎么整 // WARN: 接下来怎么整
let cname = msg.id == FACTORY_RESET ? 'factory-reset' : COMMAND_NAMES[msg.id]; let cname = msg.id === FACTORY_RESET ? 'factory-reset' : COMMAND_NAMES[msg.id];
let heading = []; let heading = [];
for (let x = 0; x < msg.body?.byteLength && x < 32; x++) { for (let x = 0; x < msg.body?.byteLength && x < 32; x++) {
heading.push('0' + (msg.body[x] & 0xff).toString(16).replace(/^0(\w{2})$/gi, '$1')); heading.push('0' + (msg.body[x] & 0xff).toString(16).replace(/^0(\w{2})$/gi, '$1'));
} }
if (msg.id != TRANSFER_FILE) if (msg.id !== TRANSFER_FILE)
Logger.debug( Logger.debug(
'jensen', 'jensen',
'receive', 'receive',
...@@ -435,7 +435,7 @@ function Jensen() { ...@@ -435,7 +435,7 @@ function Jensen() {
const decodeMessage = function (dataView, startIndex, buffLength) { const decodeMessage = function (dataView, startIndex, buffLength) {
let dataLen = buffLength - startIndex; let dataLen = buffLength - startIndex;
if (dataLen < 12) return null; if (dataLen < 12) return null;
if (dataView[startIndex + 0] != 0x12 || dataView[startIndex + 1] != 0x34) throw new Error('invalid header'); if (dataView[startIndex + 0] !== 0x12 || dataView[startIndex + 1] !== 0x34) throw new Error('invalid header');
// 2 字节的指令id // 2 字节的指令id
let idx = 2; let idx = 2;
// let cmdid = this.nextShort(idx); // let cmdid = this.nextShort(idx);
...@@ -482,7 +482,7 @@ function Jensen() { ...@@ -482,7 +482,7 @@ function Jensen() {
}; };
this.to_bcd = function (str) { this.to_bcd = function (str) {
let x = new Array(); let x = [];
for (let i = 0; i < str.length; i += 2) { for (let i = 0; i < str.length; i += 2) {
let h = (str.charCodeAt(i) - 48) & 0xff; let h = (str.charCodeAt(i) - 48) & 0xff;
let l = (str.charCodeAt(i + 1) - 48) & 0xff; let l = (str.charCodeAt(i + 1) - 48) & 0xff;
...@@ -504,7 +504,7 @@ function Jensen() { ...@@ -504,7 +504,7 @@ function Jensen() {
function Command(id) { function Command(id) {
this.command = id; this.command = id;
this.msgBody = new Array(); this.msgBody = [];
this.index = 0; this.index = 0;
this.expireTime = 0; this.expireTime = 0;
this.timeout = 0; this.timeout = 0;
...@@ -778,8 +778,7 @@ Jensen.prototype.setNotification = function (enable, seconds) { ...@@ -778,8 +778,7 @@ Jensen.prototype.setNotification = 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, 0, 0, 0, 0, enable ? 1 : 2], 0, 0, 0, 0), seconds); return this.send(new Command(SET_SETTINGS).body([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, enable ? 1 : 2], 0, 0, 0, 0), seconds);
}; };
Jensen.prototype.setBluetoothPromptPlay = function(enable, seconds) Jensen.prototype.setBluetoothPromptPlay = function(enable, 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 ? 1 : 2]), 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 ? 1 : 2]), seconds);
} }
...@@ -826,17 +825,16 @@ Jensen.prototype.getFileBlock = async function(filename, length, ondata) { ...@@ -826,17 +825,16 @@ Jensen.prototype.getFileBlock = async function(filename, length, ondata) {
return this.send(new Command(GET_FILE_BLOCK).body(data)); return this.send(new Command(GET_FILE_BLOCK).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.registerHandler(SET_DEVICE_TIME, commonMessageParser); Jensen.registerHandler(SET_DEVICE_TIME, commonMessageParser);
Jensen.registerHandler(BNC_DEMO_TEST, commonMessageParser); Jensen.registerHandler(BNC_DEMO_TEST, commonMessageParser);
Jensen.registerHandler(DELETE_FILE, (msg) => { Jensen.registerHandler(DELETE_FILE, (msg) => {
let rst = 'failed'; let rst = 'failed';
if (msg.body[0] == 0x00) rst = 'success'; if (msg.body[0] === 0x00) rst = 'success';
else if (msg.body[0] == 0x01) rst = 'not-exists'; else if (msg.body[0] === 0x01) rst = 'not-exists';
else if (msg.body[0] == 0x02) rst = 'failed'; else if (msg.body[0] === 0x02) rst = 'failed';
return { result: rst }; return { result: rst };
}); });
Jensen.registerHandler(QUERY_DEVICE_INFO, (msg, jensen) => { Jensen.registerHandler(QUERY_DEVICE_INFO, (msg, jensen) => {
...@@ -875,11 +873,11 @@ Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => { ...@@ -875,11 +873,11 @@ Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => {
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) => {
if (msg.body.length == 0) return { count: 0 }; if (msg.body.length === 0) return { count: 0 };
let c = 0; let c = 0;
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
let b = msg.body[i] & 0xff; let b = msg.body[i] & 0xff;
...@@ -891,9 +889,9 @@ Jensen.registerHandler(GET_SETTINGS, (msg) => { ...@@ -891,9 +889,9 @@ Jensen.registerHandler(GET_SETTINGS, (msg) => {
let r1 = msg.body[3]; let r1 = msg.body[3];
let r2 = msg.body[7]; let r2 = msg.body[7];
let r4 = msg.body[15]; let r4 = msg.body[15];
let rst = { autoRecord: r1 == 1, autoPlay: r2 == 1, bluetoothTone: r4 == 1 }; let rst = { autoRecord: r1 === 1, autoPlay: r2 === 1, bluetoothTone: r4 === 1 };
if (msg.body.length >= 12) { if (msg.body.length >= 12) {
let r3 = msg.body[11] == 1; let r3 = msg.body[11] === 1;
rst['notification'] = r3; rst['notification'] = r3;
} }
return rst; return rst;
...@@ -903,15 +901,15 @@ Jensen.registerHandler(FACTORY_RESET, commonMessageParser); ...@@ -903,15 +901,15 @@ Jensen.registerHandler(FACTORY_RESET, commonMessageParser);
Jensen.registerHandler(REQUEST_FIRMWARE_UPGRADE, (msg) => { Jensen.registerHandler(REQUEST_FIRMWARE_UPGRADE, (msg) => {
let rst = ''; let rst = '';
let c = msg.body[0]; let c = msg.body[0];
if (c == 0x00) rst = 'accepted'; if (c === 0x00) rst = 'accepted';
if (c == 0x01) rst = 'wrong-version'; if (c === 0x01) rst = 'wrong-version';
if (c == 0x02) rst = 'busy'; if (c === 0x02) rst = 'busy';
if (c == 0x03) return 'unknown'; if (c === 0x03) return 'unknown';
return { result: rst }; return { result: rst };
}); });
Jensen.registerHandler(FIRMWARE_UPLOAD, (msg) => { Jensen.registerHandler(FIRMWARE_UPLOAD, (msg) => {
let c = msg.body[0]; let c = msg.body[0];
return { result: c == 0x00 ? 'success' : 'failed' }; return { result: c === 0x00 ? 'success' : 'failed' };
}); });
Jensen.registerHandler(READ_CARD_INFO, (msg) => { Jensen.registerHandler(READ_CARD_INFO, (msg) => {
let i = 0; let i = 0;
...@@ -923,9 +921,9 @@ Jensen.registerHandler(READ_CARD_INFO, (msg) => { ...@@ -923,9 +921,9 @@ Jensen.registerHandler(READ_CARD_INFO, (msg) => {
}); });
Jensen.registerHandler(FORMAT_CARD, commonMessageParser); Jensen.registerHandler(FORMAT_CARD, commonMessageParser);
Jensen.registerHandler(GET_RECORDING_FILE, (msg) => { Jensen.registerHandler(GET_RECORDING_FILE, (msg) => {
if (msg.body == null || msg.body.length == 0) return { recording: null }; if (msg.body == null || msg.body.length === 0) return { recording: null };
else { else {
var fname = []; let fname = [];
for (var i = 0; i < msg.body.length; i++) { for (var i = 0; i < msg.body.length; i++) {
fname.push(String.fromCharCode(msg.body[i])); fname.push(String.fromCharCode(msg.body[i]));
} }
......
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