Commit e5f623cc authored by Skye Yu's avatar Skye Yu

test:

parent 45d95a74
......@@ -11,7 +11,7 @@ declare module 'jensen' {
name: string;
createDate: string;
createTime: string;
time: string;
time: Date;
duration: number;
length: number;
signature: string;
......
......@@ -73,7 +73,7 @@ function Jensen() {
const RECV_BUFF_SIZE = 51200;
const _check_conn_status = () => {
if (device?.opened == false) {
if (device?.opened === false) {
try {
clearTimeout(statusTimeout);
if (this.ondisconnect && !this.isStopConnectionCheck) this.ondisconnect();
......@@ -292,9 +292,9 @@ function Jensen() {
};
const read_int = function (a, b, c, d) {
if (arguments.length == 2) {
if (arguments.length === 2) {
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);
}
};
......@@ -373,12 +373,12 @@ function Jensen() {
let msg = rst.message;
// 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 = [];
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'));
}
if (msg.id != TRANSFER_FILE)
if (msg.id !== TRANSFER_FILE)
Logger.debug(
'jensen',
'receive',
......@@ -435,7 +435,7 @@ function Jensen() {
const decodeMessage = function (dataView, startIndex, buffLength) {
let dataLen = buffLength - startIndex;
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
let idx = 2;
// let cmdid = this.nextShort(idx);
......@@ -482,7 +482,7 @@ function Jensen() {
};
this.to_bcd = function (str) {
let x = new Array();
let x = [];
for (let i = 0; i < str.length; i += 2) {
let h = (str.charCodeAt(i) - 48) & 0xff;
let l = (str.charCodeAt(i + 1) - 48) & 0xff;
......@@ -504,7 +504,7 @@ function Jensen() {
function Command(id) {
this.command = id;
this.msgBody = new Array();
this.msgBody = [];
this.index = 0;
this.expireTime = 0;
this.timeout = 0;
......@@ -778,8 +778,7 @@ Jensen.prototype.setNotification = function (enable, seconds) {
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);
};
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);
}
......@@ -826,17 +825,16 @@ Jensen.prototype.getFileBlock = async function(filename, length, ondata) {
return this.send(new Command(GET_FILE_BLOCK).body(data));
}
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(BNC_DEMO_TEST, commonMessageParser);
Jensen.registerHandler(DELETE_FILE, (msg) => {
let rst = 'failed';
if (msg.body[0] == 0x00) rst = 'success';
else if (msg.body[0] == 0x01) rst = 'not-exists';
else if (msg.body[0] == 0x02) rst = 'failed';
if (msg.body[0] === 0x00) rst = 'success';
else if (msg.body[0] === 0x01) rst = 'not-exists';
else if (msg.body[0] === 0x02) rst = 'failed';
return { result: rst };
});
Jensen.registerHandler(QUERY_DEVICE_INFO, (msg, jensen) => {
......@@ -875,11 +873,11 @@ Jensen.registerHandler(QUERY_DEVICE_TIME, (msg, jensen) => {
msg.body[6] & 0xff,
);
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) => {
if (msg.body.length == 0) return { count: 0 };
if (msg.body.length === 0) return { count: 0 };
let c = 0;
for (let i = 0; i < 4; i++) {
let b = msg.body[i] & 0xff;
......@@ -891,9 +889,9 @@ Jensen.registerHandler(GET_SETTINGS, (msg) => {
let r1 = msg.body[3];
let r2 = msg.body[7];
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) {
let r3 = msg.body[11] == 1;
let r3 = msg.body[11] === 1;
rst['notification'] = r3;
}
return rst;
......@@ -903,15 +901,15 @@ Jensen.registerHandler(FACTORY_RESET, commonMessageParser);
Jensen.registerHandler(REQUEST_FIRMWARE_UPGRADE, (msg) => {
let rst = '';
let c = msg.body[0];
if (c == 0x00) rst = 'accepted';
if (c == 0x01) rst = 'wrong-version';
if (c == 0x02) rst = 'busy';
if (c == 0x03) return 'unknown';
if (c === 0x00) rst = 'accepted';
if (c === 0x01) rst = 'wrong-version';
if (c === 0x02) rst = 'busy';
if (c === 0x03) return 'unknown';
return { result: rst };
});
Jensen.registerHandler(FIRMWARE_UPLOAD, (msg) => {
let c = msg.body[0];
return { result: c == 0x00 ? 'success' : 'failed' };
return { result: c === 0x00 ? 'success' : 'failed' };
});
Jensen.registerHandler(READ_CARD_INFO, (msg) => {
let i = 0;
......@@ -923,9 +921,9 @@ Jensen.registerHandler(READ_CARD_INFO, (msg) => {
});
Jensen.registerHandler(FORMAT_CARD, commonMessageParser);
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 {
var fname = [];
let fname = [];
for (var i = 0; i < msg.body.length; 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