Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions design/linkhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ Before any vehicle heartbeat, MAVLink status has an empty `base_mode` mask and
vehicle. Consumers must still use connection/readiness and observed heartbeats
to distinguish unknown state from confirmed disarmed state.

### Configured CSV feeds

`--csv-map` loads a JSON source/column mapping at startup for the generic
`/v1/csv` HTTP receiver. The mapping, not Rust code, owns incoming column order,
output field names, value types, and the unsigned sequence column. The checked
example describes ESP32 strain measurements, but the receiver is sensor-agnostic.
Invalid mappings fail startup; malformed batches are validated before any rows
are accepted. Header-only uploads acknowledge file creation without fabricating
measurements.

Accepted rows become ordinary `diagnostic.event` records with event `csv.sample`
and the configured source. The existing journal owns ordering, persistence,
retry deduplication (source, filename, device sequence), cursor reads, and
experiment inclusion. There is no separate CSV transport archive. A per-run
five-row cache exposes recent and latest mapped values and host receive time without
claiming a device clock, units, or freshness. HTTP ingestion works independently
of MAVLink readiness. It never commands or reconfigures the sending device.
See [CSV usage and mapping format](../linkhub/README.md#generic-csv-ingestion).

### Bluetooth bench motor

`--motor-name-prefix` enables the external rotor-drive backend. It starts
Expand Down
13 changes: 13 additions & 0 deletions linkhub-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ JavaScript numbers represent all supported Int32 values exactly. Classic
MAVLink encoding limits still apply at the vehicle boundary; see
[Parameter values](../design/linkhub.md#parameter-values).

## CSVs pane

When LinkHub receives CSV rows, the **CSVs** button appears and its pane opens.
It shows the last five newly accepted rows, their filenames and host receive
times, with columns driven by the runtime mapping rather than sensor-specific
code. Use the button to collapse/reopen it. Polling is independent of MAVLink,
so no vehicle heartbeat is needed. Old values retain their receive time; network
errors are displayed explicitly, not presented as fresh readings.
The offline demo has no CSV feed and does not fabricate samples.

Enable the receiver with `LINKHUB_CSV_MAP` or `--csv-map`; see
[CSV ingestion and the ESP32 example](../linkhub/README.md#generic-csv-ingestion).

## Build and launch

### Standalone offline demo / GitHub Pages
Expand Down
2 changes: 2 additions & 0 deletions linkhub-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h1>Live vehicle state</h1>
<button id="wobble-toggle" type="button" aria-pressed="false" aria-controls="wobble-panel" title="Pixhawk roll, pitch and yaw wobble frequency analysis">Wobble</button>
<button id="swash-toggle" type="button" aria-pressed="false" aria-controls="swash-panel" title="Disarmed collective/cyclic calibration and servo readback">Swash</button>
<button id="motor-toggle" type="button" aria-pressed="false" aria-controls="motor-panel" title="External Bluetooth rotor motor speed and power">Motor</button>
<button id="csv-toggle" type="button" aria-pressed="false" aria-controls="csv-panel" title="Recent received CSV rows" hidden>CSVs</button>
<div id="connection-state" class="badge offline">connecting</div>
</div>
<button id="link-throughput" type="button" aria-expanded="false" aria-controls="link-details" title="MAVLink frame throughput, averaged over 3 seconds; excludes UART and radio overhead. Click for a per-message breakdown.">RX — · TX —</button>
Expand Down Expand Up @@ -72,6 +73,7 @@ <h1>Live vehicle state</h1>
<section id="wobble-panel" class="wobble-panel" aria-label="Pixhawk wobble frequency analysis"></section>
<section id="swash-panel" class="swash-panel" aria-label="Collective and cyclic calibration"></section>
<section id="motor-panel" class="motor-panel" aria-label="Bluetooth rotor motor"></section>
<section id="csv-panel" class="csv-panel" aria-label="Recent CSV samples" hidden></section>
</section>
<section class="panel terminal-panel">
<header>
Expand Down
9 changes: 9 additions & 0 deletions linkhub-ui/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
CommandResult,
CameraStatus,
CsvStatus,
ExperimentInfo,
JsonObject,
LinkHubStatus,
Expand Down Expand Up @@ -157,6 +158,14 @@ export class LinkHubApi {
return this.request("GET", "/v1/camera", undefined, AbortSignal.timeout(3_000));
}

csvStatus(signal?: AbortSignal): Promise<CsvStatus> {
const timeout = AbortSignal.timeout(3_000);
return this.request(
"GET", "/v1/csv", undefined,
signal ? AbortSignal.any([signal, timeout]) : timeout,
);
}

async currentCursor(signal?: AbortSignal): Promise<string> {
return (await this.status(signal)).cursor;
}
Expand Down
110 changes: 110 additions & 0 deletions linkhub-ui/src/csv-panel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import type { LinkHubApi } from "./api";
import type { CsvStatus } from "./types";

export class CsvPanel {
private readonly controller = new AbortController();
private readonly state: HTMLElement;
private readonly rows: HTMLElement;
private timer: ReturnType<typeof setTimeout> | undefined;
private received = false;
private disposed = false;
private lastError: string | null = null;

constructor(
private readonly button: HTMLButtonElement,
private readonly root: HTMLElement,
private readonly api: Pick<LinkHubApi, "csvStatus">,
private readonly onError: (message: string) => void,
) {
root.innerHTML = `
<div class="csv-head"><h2>CSVs</h2><span data-csv="state" role="status"></span></div>
<div class="csv-rows" data-csv="rows"></div>
`;
this.state = this.element('[data-csv="state"]');
this.rows = this.element('[data-csv="rows"]');
button.hidden = true;
root.hidden = true;
button.addEventListener("click", this.toggle);
void this.refresh();
}

dispose(): void {
this.disposed = true;
clearTimeout(this.timer);
this.controller.abort();
this.button.removeEventListener("click", this.toggle);
}

private readonly toggle = (): void => {
this.root.hidden = !this.root.hidden;
this.button.setAttribute("aria-pressed", String(!this.root.hidden));
};

private async refresh(): Promise<void> {
try {
const status = await this.api.csvStatus(this.controller.signal);
if (this.disposed) return;
this.lastError = null;
this.render(status);
} catch (error) {
if (this.disposed) return;
const message = `CSV status unavailable: ${error instanceof Error ? error.message : String(error)}`;
this.state.textContent = message;
this.state.classList.toggle("error", true);
if (message !== this.lastError) this.onError(message);
this.lastError = message;
} finally {
if (!this.disposed) this.timer = setTimeout(() => void this.refresh(), 1_000);
}
}

private render(status: CsvStatus): void {
if (!status.available || !status.latest || status.recent.length === 0) {
this.button.hidden = true;
this.root.hidden = true;
this.button.setAttribute("aria-pressed", "false");
this.rows.replaceChildren();
this.received = false;
return;
}
this.button.hidden = false;
if (!this.received) {
this.root.hidden = false;
this.button.setAttribute("aria-pressed", "true");
this.received = true;
}
const time = (ns: number) => new Date(ns / 1e6).toLocaleTimeString();
this.state.classList.toggle("error", false);
this.state.textContent = `${status.latest.source} | ${status.latest.filename} | last received ${time(status.latest.received_time_ns)}`;
const table = document.createElement("table");
const head = document.createElement("thead");
const heading = document.createElement("tr");
for (const name of ["File", "Received", ...status.columns]) {
const cell = document.createElement("th");
cell.textContent = name;
heading.append(cell);
}
head.append(heading);
const body = document.createElement("tbody");
for (const row of status.recent) {
const tr = document.createElement("tr");
for (const value of [
row.filename, time(row.received_time_ns),
...status.columns.map((field) => String(row.values[field])),
]) {
const cell = document.createElement("td");
cell.textContent = value;
tr.append(cell);
}
body.append(tr);
}
table.append(head, body);
this.rows.replaceChildren(table);
}

private element(selector: string): HTMLElement {
const element = this.root.querySelector<HTMLElement>(selector);
if (!element) throw new Error(`Missing CSV panel element ${selector}`);
return element;
}
}
3 changes: 3 additions & 0 deletions linkhub-ui/src/demo-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ export class DemoBackend {
const body = init?.body === undefined ? {} : object(JSON.parse(String(init.body)));
const path = url.pathname;
if (method === "GET" && path === "/v1/motor") return json({ available: false });
if (method === "GET" && path === "/v1/csv") {
return json({ available: false, columns: [], latest: null, recent: [] });
}
if (path.startsWith("/v1/motor")) return json({ message: READ_ONLY }, 403);
if (method === "GET" && path === "/v1/experiment") return json({ active: null });
if (path.startsWith("/v1/experiment")) return json({ message: READ_ONLY }, 403);
Expand Down
8 changes: 8 additions & 0 deletions linkhub-ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { LinkHubStatus } from "./types";
import { ExperimentController } from "./experiment";
import { ExperimentButton } from "./experiment-button";
import { CameraPanel } from "./camera-panel";
import { CsvPanel } from "./csv-panel";
import { formatCopterMode } from "./modes";
import { isArmed } from "./mav";
import { PassiveController, type PassivePhase } from "./passive";
Expand Down Expand Up @@ -94,6 +95,13 @@ const experimentButton = new ExperimentButton(
write,
);
const scene = new VehicleScene(required<HTMLElement>("#scene"), telemetry, sceneOptions);
const csvPanel = new CsvPanel(
required<HTMLButtonElement>("#csv-toggle"),
required<HTMLElement>("#csv-panel"),
api,
(message) => write(message, "error"),
);
window.addEventListener("beforeunload", () => csvPanel.dispose(), { once: true });

function updateOverlay(): void {
const status = telemetry.status;
Expand Down
33 changes: 31 additions & 2 deletions linkhub-ui/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ h2 {
#yaw-toggle,
#wobble-toggle,
#swash-toggle,
#motor-toggle {
#motor-toggle,
#csv-toggle {
padding: 4px 10px;
border: 1px solid #40506b;
border-radius: 999px;
Expand All @@ -419,7 +420,8 @@ h2 {
#yaw-toggle[aria-pressed="true"],
#wobble-toggle[aria-pressed="true"],
#swash-toggle[aria-pressed="true"],
#motor-toggle[aria-pressed="true"] {
#motor-toggle[aria-pressed="true"],
#csv-toggle[aria-pressed="true"] {
border-color: #2d8f6f;
color: #71ddb4;
background: rgba(30, 123, 89, 0.14);
Expand Down Expand Up @@ -520,6 +522,33 @@ h2 {
.motor-warning, .motor-panel .error { color: #f0c36b; }
.motor-panel small { color: #aebdd2; }

.csv-panel {
position: relative;
z-index: 3;
flex: none;
max-height: 30vh;
overflow: auto;
padding: 10px;
border-top: 1px solid #263249;
background: #080d16;
font-size: 11px;
}

.csv-panel[hidden] { display: none; }
.csv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.csv-head h2 { font-size: 13px; }
.csv-head span { color: #aebdd2; }
.csv-head .error { color: #f0c36b; }
.csv-rows { overflow-x: auto; margin-top: 8px; }
.csv-rows table { width: 100%; border-collapse: collapse; }
.csv-rows th, .csv-rows td {
padding: 4px 8px;
border-bottom: 1px solid #263249;
text-align: left;
white-space: nowrap;
}
.csv-rows th { color: #7591b8; }

.swash-head, .swash-actions {
display: flex;
flex-wrap: wrap;
Expand Down
16 changes: 16 additions & 0 deletions linkhub-ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import type {

export type JsonObject = Record<string, unknown>;

export interface CsvReading {
source: string;
filename: string;
received_time_ns: number;
sequence: number;
source_sequence: number;
values: Record<string, string | number>;
}

export interface CsvStatus {
available: boolean;
columns: string[];
latest: CsvReading | null;
recent: CsvReading[];
}

export interface MotorDevice {
id: string;
name: string;
Expand Down
13 changes: 13 additions & 0 deletions linkhub-ui/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ describe("formatMavResult", () => {
});

describe("typed wire contract", () => {
it("reads CSV rows independently and propagates caller cancellation", async () => {
const status = { available: false, columns: [], latest: null, recent: [] };
const fetchMock = stubFetch(status);
const controller = new AbortController();
expect(await new LinkHubApi().csvStatus(controller.signal)).toEqual(status);
expect(fetchMock).toHaveBeenCalledWith(
"/v1/csv", expect.objectContaining({ method: "GET", signal: expect.any(AbortSignal) }),
);
const signal = fetchMock.mock.lastCall?.[1].signal as AbortSignal;
controller.abort();
expect(signal.aborted).toBe(true);
});

it("uses the motor discovery, exact selection, leased command and stop endpoints", async () => {
const fetchMock = stubFetch({ available: true });
const api = new LinkHubApi();
Expand Down
Loading
Loading