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
1 change: 1 addition & 0 deletions changelog/2026-11-30-trial-waits-usb-function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module tests on the Octatrack: a USB Audio trial now reports itself running, or rolled back, only once the Octatrack is back on USB, so the soak and the readings after it no longer lose the unit to its reconnect.
21 changes: 20 additions & 1 deletion scripts/device.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ async function trial(session, pkg) {
const original = session.status
const baseline = ((await transport.capabilities())?.features ?? 0) & RuntimeFeature.moduleSets ? await transport.setIdentity() : undefined
await stopping(() => session.stage(pkg, { signal: interrupt.signal })); await session.activate(); await session.startTrial()
await usbSettled()
console.log(`trial: ${pkg.sha256.slice(0, 16)}… running`)
for (let second = 1; second <= seconds && !interrupt.signal.aborted; second++) {
await wait(1000)
Expand Down Expand Up @@ -718,8 +719,25 @@ async function trial(session, pkg) {
}
const left = Date.now(), status = await session.leaveUploadMode()
console.log(`left upload mode in ${Date.now() - left} ms`) // the card-set save runs first, in the same task
await usbSettled()
return status
}
/** A package with a USB function (USB Audio) takes the unit off USB a second or so after its trial starts or ends, and
* up to UF_PATIENCE later while it plays (usb_function.c): wait until the base's USB function (request 41) has settled on
* what the modules ask for, so the next reading or soak does not meet the reconnect. 40 s at most; a base without USB
* functions answers at once. */
async function usbSettled() {
const start = Date.now(), took = () => ((Date.now() - start) / 1000).toFixed(1) + ' s'
for (; Date.now() - start < 40000; await wait(500)) {
const reply = await unit.controlTransferIn({ requestType: 'vendor', recipient: 'interface', request: 41, value: 0, index }, 8).catch(() => undefined)
if (!reply) continue // away: the reconnect is under way
if (reply.status !== 'ok' || reply.data?.byteLength !== 8) return // no ot_usb_functions
// live: the configuration the host read holds a module's function; table: a module asks for one (set as the trial publishes)
const [state, live, table] = new Uint8Array(reply.data.buffer, reply.data.byteOffset, 3)
if (state === 0 && !live === !table) { if (Date.now() - start > 1000) console.log('USB function settled after ' + took()); return }
}
console.log('USB function not settled after ' + took())
}

/** After a RAM boot or flash: wait until the unit has gone away and come back far enough to answer HELLO, and has started again.
* `before` is the log read before arming (readLog): the unit is back only on a larger boot number, so a USB drop of the same
Expand Down Expand Up @@ -790,7 +808,8 @@ if (command === 'serve') {
line += d
if (!line.includes('\n')) return
const request = line.slice(0, line.indexOf('\n')), waits = [...request.matchAll(/\bw(\d+)\b/g)].reduce((sum, m) => sum + Number(m[1]), 0)
const limit = 20000 + waits // 20 s beyond the waits the sequence asks for: a hung request answers at once
// 20 s beyond the waits the sequence asks for: a hung request answers at once. A try or remove also waits for its USB function (usbSettled).
const limit = 20000 + waits + (/^(?:try|remove)\b/.test(request) ? 40000 : 0)
serial(() => {
const work = capture(request, Date.now() + limit)
Promise.race([work, wait(limit).then(() => `error: no answer from the unit within ${Math.round(limit / 1000)} s\n`)]).then(reply => c.end(reply))
Expand Down
Loading