Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
67076ad
Improve msp send
haslinghuis Jun 10, 2025
3f54a2b
Fixes per review coderabbit
haslinghuis Jun 10, 2025
d73550b
Refactor
haslinghuis Jun 10, 2025
db43fa9
Mitigate failed retry attempts
haslinghuis Jun 10, 2025
574e1b0
More coderabbit improvements
haslinghuis Jun 10, 2025
052b0e1
Improve timeout optimization
haslinghuis Jun 10, 2025
d1d79c2
Add dynamic retries
haslinghuis Jun 10, 2025
5c3144e
Improve duplicate message detection by also checking payload
haslinghuis Jun 10, 2025
1df1f2b
Remove dynamic timeout overhead
haslinghuis Jun 10, 2025
5e2220f
Fix sonar
haslinghuis Jun 10, 2025
f62524b
Add queue elements for debugging
haslinghuis Jun 11, 2025
f288215
Centralize timer cleanup
haslinghuis Jun 11, 2025
7db15ae
Add MSP debugging tools
haslinghuis Jun 12, 2025
a0df701
Suggestions per Coderabbit
haslinghuis Jun 12, 2025
e65a31f
Sonar
haslinghuis Jun 12, 2025
bc01ca4
Add lazy init
haslinghuis Jun 12, 2025
b01aedc
More coderabbit
haslinghuis Jun 12, 2025
9bc5c62
More coderabbit ...
haslinghuis Jun 12, 2025
164ddb0
More coderabbit ......
haslinghuis Jun 12, 2025
6277679
Make available
haslinghuis Jun 12, 2025
2d9ab79
Increase queue limit
haslinghuis Jun 12, 2025
6185e8a
coderabbit again
haslinghuis Jun 12, 2025
a0d87a1
Review per coderabbit
haslinghuis Jun 15, 2025
cfe428d
More
haslinghuis Jun 15, 2025
9a0a462
More ...
haslinghuis Jun 15, 2025
9412fbb
Prevent XSS attack
haslinghuis Jun 15, 2025
4ee718a
Fix performance violations
haslinghuis Jun 15, 2025
a17f29a
Prevent runtime errors
haslinghuis Jun 15, 2025
a159f52
More from coderabbit
haslinghuis Jun 23, 2025
3433db1
Use subpath for debug tools
haslinghuis Aug 3, 2025
8526b78
Update src/js/msp/debug/msp_queue_monitor.js
haslinghuis Aug 26, 2025
935e385
fix test
haslinghuis Aug 26, 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
42 changes: 15 additions & 27 deletions src/js/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ 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: [],
Expand Down Expand Up @@ -378,28 +375,19 @@ const MSP = {
serial.send(bufferOut);
},
send_message(code, data, callback_sent, callback_msp, doCallbackOnError) {
const connected = serial.connected;

if (code === undefined || !connected || CONFIGURATOR.virtualMode) {
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 requestExists = this.callbacks.some((instance) => instance.code === code);

const bufferOut = code <= 254 ? this.encode_message_v1(code, data) : this.encode_message_v2(code, data);

const obj = {
code: code,
code,
requestBuffer: bufferOut,
callback: callback_msp,
callbackOnError: doCallbackOnError,
Expand All @@ -416,31 +404,31 @@ const MSP = {
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
Loading