Replacing ublox.js with updated code in assist-now.js; #2551
Replacing ublox.js with updated code in assist-now.js; #2551DHaacke wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
Conversation
…ty and (coming soon) Configurator functionality.
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
There was a problem hiding this comment.
High-level Suggestion
Replace the inefficient setInterval polling in the UBXReceiver class with a more robust, event-driven approach for handling asynchronous responses. This can be achieved using an event emitter or by resolving pending promises directly from the _onData method. [High-level, importance: 8]
Solution Walkthrough:
Before:
class UBXReceiver {
async sendAndWait(msg, prefix, timeoutMs) {
this.expectedPrefix = prefix;
this.messageQueue = [];
await this.send(msg);
return new Promise((resolve) => {
const interval = setInterval(() => {
if (this.messageQueue.length > 0) {
clearInterval(interval);
resolve(this.messageQueue.shift());
}
// ... timeout logic
}, 50);
});
}
}After:
class UBXReceiver {
constructor() {
// ...
this.pendingRequests = new Map(); // or a single pending promise
}
_onData(chunk) {
// ... parse message `msg`
// Find a matching pending request and resolve it
const resolver = this.findAndRemoveMatchingResolver(msg);
if (resolver) {
resolver(msg);
}
}
async sendAndWait(msg, prefix, timeoutMs) {
return new Promise((resolve, reject) => {
// Store resolver to be called from _onData
this.addPendingResolver(prefix, resolve);
this.send(msg);
// ... timeout logic that calls reject
});
}
}|
Quick note: The older ublox.js code is still there and active. I have only added the new file assist-now.js. The new file can run standalone in Node (see instructions at top of code). I wanted to get the code pushed before I start the arduous task of integrating it with the Configurator UI which I plan on starting on in the coming days. Thanks, and holler if you have questions or concerns. -Doug |
|
Inadvertently closed. Reopening.... |
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
There was a problem hiding this comment.
High-level Suggestion
Refactor assist-now.js to use the application's existing serial connection management instead of creating its own. This avoids hardware access conflicts and allows for proper integration into the Configurator. [High-level, importance: 9]
Solution Walkthrough:
Before:
// assist-now.js
import { SerialPort } from "serialport";
class UBXReceiver {
constructor(portPath, baudRate) {
// Creates a new, independent serial port connection.
this.port = new SerialPort({ path: portPath, baudRate, autoOpen: true });
this.port.on("data", (chunk) => this._onData(chunk));
// ...
}
// ...
}
async function runAssistNow(args) {
// Instantiates the receiver with a port path string.
const gnss = new UBXReceiver(args.port, args.baudRate);
// ... uses gnss to communicate
}After:
// assist-now.js
class UBXReceiver {
constructor(connection) { // Expects an existing connection object
// Reuses the application's main serial connection.
this.port = connection;
this.port.on("data", (chunk) => this._onData(chunk));
// ...
}
// ...
}
async function runAssistNow(args, connection) { // Pass connection from the main app
// Instantiates the receiver with the existing connection.
const gnss = new UBXReceiver(connection);
// ... uses gnss to communicate
}
User description
Replacing ublox.js with updated code in assist-now.js; Provides standalone functionality and (coming soon) Configurator functionality.
PR Type
Enhancement, New Feature
Description
Port of u-blox AssistNow Python example to Node.js with standalone and Configurator support
Implements Zero Touch Provisioning (ZTP) for secure orbit data download and injection
Provides UBX message handling with serial communication and ACK/NAK validation
Supports both predictive and live orbit modes with GNSS receiver cold-reset and TTFF measurement
Diagram Walkthrough
File Walkthrough
assist-now.js
Complete Node.js port of u-blox AssistNow with ZTPjs/ublox/assist-now.js
AssistNow functionality
verification, and ACK waiting
data download
rate, ZTP token, and orbit mode selection
after cold-reset