Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9a7d021
Improve msp send
haslinghuis Jun 10, 2025
36b30d0
Fixes per review coderabbit
haslinghuis Jun 10, 2025
56226c1
Refactor
haslinghuis Jun 10, 2025
9154add
Mitigate failed retry attempts
haslinghuis Jun 10, 2025
c20bd71
More coderabbit improvements
haslinghuis Jun 10, 2025
50dfdf4
Improve timeout optimization
haslinghuis Jun 10, 2025
8aac506
Add dynamic retries
haslinghuis Jun 10, 2025
241b3ca
Improve duplicate message detection by also checking payload
haslinghuis Jun 10, 2025
deaf72f
Remove dynamic timeout overhead
haslinghuis Jun 10, 2025
7da9814
Fix sonar
haslinghuis Jun 10, 2025
3160760
Add queue elements for debugging
haslinghuis Jun 11, 2025
0742b6d
Centralize timer cleanup
haslinghuis Jun 11, 2025
d8e0354
Add MSP debugging tools
haslinghuis Jun 12, 2025
f8129bb
Suggestions per Coderabbit
haslinghuis Jun 12, 2025
b79b72d
Sonar
haslinghuis Jun 12, 2025
6f9ee1a
Add lazy init
haslinghuis Jun 12, 2025
c8f817e
More coderabbit
haslinghuis Jun 12, 2025
8bf713b
More coderabbit ...
haslinghuis Jun 12, 2025
730a997
More coderabbit ......
haslinghuis Jun 12, 2025
16ff869
Make available
haslinghuis Jun 12, 2025
cc99902
Increase queue limit
haslinghuis Jun 12, 2025
e2486e6
coderabbit again
haslinghuis Jun 12, 2025
b2f93d8
Review per coderabbit
haslinghuis Jun 15, 2025
b6d88dc
More
haslinghuis Jun 15, 2025
1c03218
More ...
haslinghuis Jun 15, 2025
b23cd0b
Prevent XSS attack
haslinghuis Jun 15, 2025
ca4ba55
Fix performance violations
haslinghuis Jun 15, 2025
c4244ee
Prevent runtime errors
haslinghuis Jun 15, 2025
34714f2
More from coderabbit
haslinghuis Jun 23, 2025
d30a340
Use subpath for debug tools
haslinghuis Aug 3, 2025
8303107
Update src/js/msp/debug/msp_queue_monitor.js
haslinghuis Aug 26, 2025
ef9218c
fix test
haslinghuis Aug 26, 2025
c6f8631
jumbo was removed in 2defc901a9499ef8f15a3f951c430e7464cf09bb
haslinghuis Sep 19, 2025
4a17c89
More coderabbit
haslinghuis Sep 19, 2025
9d3cee3
Remove unused callbackonerror
haslinghuis Sep 19, 2025
363fb56
Remove unused JUMBO size define
haslinghuis Sep 19, 2025
abc5383
Also check for payload when checking existing msp messages
haslinghuis Sep 19, 2025
16f1a95
Remove static timeout
haslinghuis Sep 19, 2025
f39a39b
Compare payload
haslinghuis Sep 19, 2025
b5be8e7
Fix per review coderabbit
haslinghuis Sep 19, 2025
306a51c
Clear timeout not interval
haslinghuis Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import { updateTabList } from "./utils/updateTabList.js";
import * as THREE from "three";
import NotificationManager from "./utils/notifications.js";

import("./msp/debug/msp_debug_tools.js")
.then(() => {
console.log("🔧 MSP Debug Tools loaded for development environment");
console.log("• Press Ctrl+Shift+M to toggle debug dashboard");
console.log("• Use MSPTestRunner.help() for all commands");
})
.catch((err) => {
console.warn("Failed to load MSP debug tools:", err);
});

if (typeof String.prototype.replaceAll === "undefined") {
String.prototype.replaceAll = function (match, replace) {
return this.replace(new RegExp(match, "g"), () => replace);
Expand Down Expand Up @@ -111,7 +121,8 @@ function startProcess() {
console.log(`Libraries: jQuery - ${$.fn.jquery}, three.js - ${THREE.REVISION}`);

// Check if this is the first visit
if (getConfig("firstRun").firstRun === undefined) {
const firstRunCfg = getConfig("firstRun") ?? {};
if (firstRunCfg.firstRun === undefined) {
setConfig({ firstRun: true });
import("./tabs/static_tab.js").then(({ staticTab }) => {
staticTab.initialize("options", () => {
Expand Down
68 changes: 28 additions & 40 deletions src/js/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,18 @@ const MSP = {
message_buffer: null,
message_buffer_uint8_view: null,
message_checksum: 0,
messageIsJumboFrame: false,
crcError: false,

callbacks: [],
packet_error: 0,
unsupported: 0,

MIN_TIMEOUT: 200,
MAX_TIMEOUT: 2000,
timeout: 200,
TIMEOUT: 1000,

last_received_timestamp: null,
listeners: [],

JUMBO_FRAME_SIZE_LIMIT: 255,

cli_buffer: [], // buffer for CLI charactor output
cli_buffer: [], // buffer for CLI character output
cli_output: [],
cli_callback: null,

Expand Down Expand Up @@ -280,7 +275,6 @@ const MSP = {
// Reset variables
this.message_length_received = 0;
this.state = 0;
this.messageIsJumboFrame = false;
this.crcError = false;
},
notify() {
Expand All @@ -289,7 +283,7 @@ const MSP = {
});
},
listen(listener) {
if (this.listeners.indexOf(listener) == -1) {
if (this.listeners.indexOf(listener) === -1) {
this.listeners.push(listener);
}
},
Expand Down Expand Up @@ -318,8 +312,8 @@ const MSP = {
const dataLength = data ? data.length : 0;
// always reserve 6 bytes for protocol overhead !
const bufferSize = dataLength + 6;
let bufferOut = new ArrayBuffer(bufferSize);
let bufView = new Uint8Array(bufferOut);
const bufferOut = new ArrayBuffer(bufferSize);
const bufView = new Uint8Array(bufferOut);

bufView[0] = 36; // $
bufView[1] = 77; // M
Expand Down Expand Up @@ -377,70 +371,64 @@ const MSP = {

serial.send(bufferOut);
},
send_message(code, data, callback_sent, callback_msp, doCallbackOnError) {
const connected = serial.connected;

if (code === undefined || !connected || CONFIGURATOR.virtualMode) {
send_message(code, data, callback_sent, callback_msp) {
if (code === undefined || !serial.connected || CONFIGURATOR.virtualMode) {
if (callback_msp) {
callback_msp();
}
return false;
}

let requestExists = false;
for (const instance of this.callbacks) {
if (instance.code === code) {
requestExists = true;

break;
}
}

const bufferOut = code <= 254 ? this.encode_message_v1(code, data) : this.encode_message_v2(code, data);
const view = new Uint8Array(bufferOut);
const keyCrc = this.crc8_dvb_s2_data(view, 0, view.length);
const requestExists = this.callbacks.some(
(i) =>
i.code === code &&
i.requestBuffer?.byteLength === bufferOut.byteLength &&
this.crc8_dvb_s2_data(new Uint8Array(i.requestBuffer), 0, i.requestBuffer.byteLength) === keyCrc,
);

const obj = {
code: code,
code,
requestBuffer: bufferOut,
callback: callback_msp,
callbackOnError: doCallbackOnError,
start: performance.now(),
};

if (!requestExists) {
obj.timer = setTimeout(() => {
console.warn(
`MSP: data request timed-out: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab} TIMEOUT: ${
this.timeout
} QUEUE: ${this.callbacks.length} (${this.callbacks.map((e) => e.code)})`,
`MSP: data request timed-out: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab} QUEUE: ${this.callbacks.length} (${this.callbacks.map((e) => e.code)})`,
);
serial.send(bufferOut, (_sendInfo) => {
obj.stop = performance.now();
const executionTime = Math.round(obj.stop - obj.start);
this.timeout = Math.max(this.MIN_TIMEOUT, Math.min(executionTime, this.MAX_TIMEOUT));
// We should probably give up connection if the request takes too long ?
if (executionTime > 5000) {
console.warn(
`MSP: data request took too long: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab} EXECUTION TIME: ${executionTime}ms`,
);
}

clearTimeout(obj.timer); // prevent leaks
});
}, this.timeout);
}, this.TIMEOUT);
}

this.callbacks.push(obj);

// always send messages with data payload (even when there is a message already in the queue)
if (data || !requestExists) {
if (this.timeout > this.MIN_TIMEOUT) {
this.timeout--;
}

serial.send(bufferOut, (sendInfo) => {
if (sendInfo.bytesSent === bufferOut.byteLength) {
if (callback_sent) {
callback_sent();
}
if (sendInfo.bytesSent === bufferOut.byteLength && callback_sent) {
callback_sent();
}
});
}

return true;
},

/**
* resolves: {command: code, data: data, length: message_length}
*/
Expand Down
5 changes: 2 additions & 3 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,14 +1759,13 @@ MspHelper.prototype.process_data = function (dataHandler) {
if (dataHandler.callbacks[i]?.code === code) {
// save callback reference
const callback = dataHandler.callbacks[i].callback;
const callbackOnError = dataHandler.callbacks[i].callbackOnError;

// remove timeout
clearInterval(dataHandler.callbacks[i].timer);
clearTimeout(dataHandler.callbacks[i].timer);

// remove object from array
dataHandler.callbacks.splice(i, 1);
if (!crcError || callbackOnError) {
if (!crcError) {
// fire callback
if (callback) {
callback({ command: code, data: data, length: data.byteLength, crcError: crcError });
Expand Down
Loading