Commit e1a8f86c authored by martin hou's avatar martin hou

fix: 调整和适配surface pro的消息传输

parent 9e8dcfb1
...@@ -196,15 +196,15 @@ export function Home() { ...@@ -196,15 +196,15 @@ export function Home() {
let filename = ''; let filename = '';
let filelength = 0; let filelength = 0;
const transferFile = async () => { const transferFile = async () => {
// if (files == null || files.length == 0) return alert('请先点击List Files'); if (files == null || files.length == 0) return alert('请先点击List Files');
// let idx = prompt('请输入需要获取的文件序号(从0开始):', '0'); let idx = prompt('请输入需要获取的文件序号(从0开始):', '0');
// if (idx === undefined || idx === null) return; if (idx === undefined || idx === null) return;
// let num = parseInt(idx); let num = parseInt(idx);
// if (isNaN(num) || num < 0 || num >= files.length) return alert('请输入正确的序号'); if (isNaN(num) || num < 0 || num >= files.length) return alert('请输入正确的序号');
// let file = files[num]; let file = files[num];
// 2025Jun24-165914-Wip00.hda, 232704 @ 19392 // 2025Jun24-165914-Wip00.hda, 232704 @ 19392
filename = '2025Jun24-165914-Wip00.hda'; filename = file.name;
filelength = 232704; filelength = file.length;
get_file(); get_file();
} }
......
...@@ -108,7 +108,7 @@ function Jensen(log, conn) { ...@@ -108,7 +108,7 @@ function Jensen(log, conn) {
this.lastTimerInvoked = new Date().getTime(); this.lastTimerInvoked = new Date().getTime();
this.wakeupTime = null; this.wakeupTime = null;
const RECV_BUFF_SIZE = 3200; const RECV_BUFF_SIZE = 512000;
const _check_conn_status = () => { const _check_conn_status = () => {
if (device?.opened === false) { if (device?.opened === false) {
...@@ -335,6 +335,7 @@ function Jensen(log, conn) { ...@@ -335,6 +335,7 @@ function Jensen(log, conn) {
Logger.debug('jensen', 'sendNext', pid + '-command: ' + current + ', data bytes: ' + data.byteLength); Logger.debug('jensen', 'sendNext', pid + '-command: ' + current + ', data bytes: ' + data.byteLength);
self.timewait = cmd.command == TRANSFER_FILE || cmd.command == GET_FILE_BLOCK ? 1000 : 10; self.timewait = cmd.command == TRANSFER_FILE || cmd.command == GET_FILE_BLOCK ? 1000 : 10;
// self.timewait = 10000;
console.log(pid + '-send', data); console.log(pid + '-send', data);
if (self.onprogress && cmd.command == TRANSFER_FILE) if (self.onprogress && cmd.command == TRANSFER_FILE)
{ {
...@@ -486,11 +487,12 @@ function Jensen(log, conn) { ...@@ -486,11 +487,12 @@ function Jensen(log, conn) {
totalBuffLen += blocks[i].byteLength; totalBuffLen += blocks[i].byteLength;
} }
Logger.info('jensen', 'transfer', `try to decode buffer with ${totalBuffLen} bytes`); Logger.info('jensen', 'transfer', `try to decode buffer with ${totalBuffLen} bytes`);
console.log('blocks', blocks);
let stime = new Date(); let stime = new Date();
let buff = new ArrayBuffer(RECV_BUFF_SIZE * 2); let buff = new ArrayBuffer(RECV_BUFF_SIZE * 2);
// bview的大小,必须是要大于固件端给出的最大包大小,已知的最大大小为8192字节,但是后面可能会提供整文件大小传输的情况,那个时候大小会变得巨大 // bview的大小,必须是要大于固件端给出的最大包大小,已知的最大大小为8192字节,但是后面可能会提供整文件大小传输的情况,那个时候大小会变得巨大
let bview = new Uint8Array(10240); let bview = new Uint8Array(RECV_BUFF_SIZE * 2);
// buff中实际使用的字节数,有效字节数 // buff中实际使用的字节数,有效字节数
let buffLength = 0; let buffLength = 0;
let crash = false; let crash = false;
...@@ -515,7 +517,7 @@ function Jensen(log, conn) { ...@@ -515,7 +517,7 @@ function Jensen(log, conn) {
} }
else Logger.info('jensen', 'decode', `start: ${startIndex}, length: ${buffLength}, cut: ${rst.length}`); else Logger.info('jensen', 'decode', `start: ${startIndex}, length: ${buffLength}, cut: ${rst.length}`);
} catch (e) { } catch (e) {
// Logger.error('jensen', 'decode', String(e)); Logger.error('jensen', 'decode', String(e));
crash = true; crash = true;
break; break;
} }
...@@ -579,6 +581,7 @@ function Jensen(log, conn) { ...@@ -579,6 +581,7 @@ function Jensen(log, conn) {
}; };
const decodeMessage = function (dataView, startIndex, buffLength) { const decodeMessage = function (dataView, startIndex, buffLength) {
console.log('decodeMessage', startIndex, buffLength, dataView);
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');
...@@ -897,6 +900,8 @@ Jensen.prototype.listFiles = async function () { ...@@ -897,6 +900,8 @@ Jensen.prototype.listFiles = async function () {
} }
}); });
console.log('files', files);
if ((fc && files.length >= fc.count) || (fcount > -1 && files.length >= fcount)) { if ((fc && files.length >= fc.count) || (fcount > -1 && files.length >= fcount)) {
// delete jensen[tag]; // delete jensen[tag];
jensen[tag] = null; jensen[tag] = null;
......
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