@geastack/cli 0.1.89 → 0.1.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/package.json +1 -1
- package/src/boards/usb.mjs +23 -24
- package/src/serial-devices.mjs +1 -1
package/NOTICE
ADDED
package/package.json
CHANGED
package/src/boards/usb.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { execFileSync } from 'node:child_process'
|
|
|
2
2
|
import { existsSync, readdirSync, realpathSync } from 'node:fs'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
|
|
5
|
-
import { detectSerialDevices } from '../serial-devices.mjs'
|
|
5
|
+
import { detectSerialDevices, serialFromLinuxById } from '../serial-devices.mjs'
|
|
6
6
|
|
|
7
7
|
// A board is identified by its USB SERIAL, never by a /dev path: enumerated
|
|
8
8
|
// paths change on every plug-in and identical boards routinely share one.
|
|
@@ -59,7 +59,10 @@ function linuxSerialByIdCandidates(serial) {
|
|
|
59
59
|
if (!existsSync(dir)) return []
|
|
60
60
|
const needle = normalizedSerial(serial)
|
|
61
61
|
return readdirSync(dir)
|
|
62
|
-
.filter((name) =>
|
|
62
|
+
.filter((name) => {
|
|
63
|
+
const deviceSerial = serialFromLinuxById(name)
|
|
64
|
+
return normalizedSerial(deviceSerial) === needle
|
|
65
|
+
})
|
|
63
66
|
.map((name) => path.join(dir, name))
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -98,10 +101,6 @@ function macUsbDeviceForSerial(serial, ioreg = runIoreg) {
|
|
|
98
101
|
) || null
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
function locationDigits(locationHex) {
|
|
102
|
-
return locationHex.toLowerCase().replace(/^0+/, '').replace(/0+$/, '').replace(/[^0-9a-f]/g, '')
|
|
103
|
-
}
|
|
104
|
-
|
|
105
104
|
function macUsbCalloutPortsForSerial(serial, ioreg = runIoreg) {
|
|
106
105
|
const output = ioreg(['-p', 'IOService', '-l', '-w0'], { maxBuffer: 64 * 1024 * 1024 })
|
|
107
106
|
const stack = []
|
|
@@ -173,21 +172,13 @@ function runIoreg(args, options = {}) {
|
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
function resolveMacUsbSerialPort(serial, ioreg = runIoreg) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (digits) {
|
|
184
|
-
const locationMatches = candidates.filter((candidate) => normalizedSerial(path.basename(candidate)).includes(digits))
|
|
185
|
-
if (locationMatches.length === 1) return locationMatches[0]
|
|
186
|
-
const registryMatches = macUsbCalloutPortsForSerial(serial, ioreg)
|
|
187
|
-
if (registryMatches.length === 1) return registryMatches[0]
|
|
188
|
-
if (registryMatches.length > 1) {
|
|
189
|
-
throw new Error([`USB serial ${serial} maps to multiple /dev/cu.* ports:`, ...registryMatches.map((c) => ` ${c}`)].join('\n'))
|
|
190
|
-
}
|
|
175
|
+
// A location fragment is not an identity: "1" also matches usbmodem21301.
|
|
176
|
+
// During re-enumeration that heuristic selected a different connected board.
|
|
177
|
+
// Only accept the callout inherited from this exact serial in IORegistry.
|
|
178
|
+
const registryMatches = macUsbCalloutPortsForSerial(serial, ioreg)
|
|
179
|
+
if (registryMatches.length === 1) return registryMatches[0]
|
|
180
|
+
if (registryMatches.length > 1) {
|
|
181
|
+
throw new Error([`USB serial ${serial} maps to multiple /dev/cu.* ports:`, ...registryMatches.map((c) => ` ${c}`)].join('\n'))
|
|
191
182
|
}
|
|
192
183
|
throw new Error(`Could not map USB serial ${serial} to a /dev/cu.* port. Check that the board is attached.`)
|
|
193
184
|
}
|
|
@@ -233,17 +224,25 @@ export async function waitForSerialPort({
|
|
|
233
224
|
label = 'USB serial port',
|
|
234
225
|
pollSeconds = 1,
|
|
235
226
|
log = (line) => process.stderr.write(`${line}\n`),
|
|
236
|
-
resolver = resolveUsbSerialPort
|
|
227
|
+
resolver = resolveUsbSerialPort,
|
|
228
|
+
portPresent = serialPortPresent
|
|
237
229
|
} = {}) {
|
|
238
230
|
const startedAt = Date.now()
|
|
239
231
|
let nextLog = startedAt
|
|
240
232
|
while (true) {
|
|
241
233
|
if (port) {
|
|
242
|
-
if (
|
|
234
|
+
if (portPresent(port)) {
|
|
235
|
+
if (!serial) return port
|
|
236
|
+
try {
|
|
237
|
+
if (resolver({ serial }) === port) return port
|
|
238
|
+
} catch {
|
|
239
|
+
// An explicit path does not override the registered board identity.
|
|
240
|
+
}
|
|
241
|
+
}
|
|
243
242
|
} else if (serial) {
|
|
244
243
|
try {
|
|
245
244
|
const resolved = resolver({ serial })
|
|
246
|
-
if (resolved &&
|
|
245
|
+
if (resolved && portPresent(resolved)) return resolved
|
|
247
246
|
} catch {
|
|
248
247
|
// not attached yet
|
|
249
248
|
}
|
package/src/serial-devices.mjs
CHANGED
|
@@ -130,7 +130,7 @@ function normalizeDevice(input) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
function serialFromLinuxById(name) {
|
|
133
|
+
export function serialFromLinuxById(name) {
|
|
134
134
|
const cleaned = name.replace(/-if\d+.*$/i, '')
|
|
135
135
|
const parts = cleaned.split('_').map((part) => part.trim()).filter(Boolean)
|
|
136
136
|
return parts.at(-1) || ''
|