mirror of
https://github.com/lights0123/n-link.git
synced 2024-12-23 10:45:27 +00:00
Add debug info
This commit is contained in:
parent
ed55b255d7
commit
44f99c5d2a
|
@ -36,6 +36,10 @@
|
||||||
</button>
|
</button>
|
||||||
<input v-if="nativeUpload" ref="upload" type="file" class="hidden" :accept="info.os_extension"
|
<input v-if="nativeUpload" ref="upload" type="file" class="hidden" :accept="info.os_extension"
|
||||||
@change="uploadNative"/>
|
@change="uploadNative"/>
|
||||||
|
<button class="mt-4 button gray-button"
|
||||||
|
@click="copyLogs">
|
||||||
|
Copy logs
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -73,6 +77,10 @@ export default class FileView extends Vue {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
if (file) this.$devices.uploadOsFile(this.dev, file);
|
if (file) this.$devices.uploadOsFile(this.dev, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyLogs() {
|
||||||
|
navigator.clipboard.writeText(this.$devices.devices[this.dev].log).catch(alert);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ const PID = 0xe012;
|
||||||
/// The USB vendor ID used by all CX II calculators.
|
/// The USB vendor ID used by all CX II calculators.
|
||||||
const PID_CX2 = 0xe022;
|
const PID_CX2 = 0xe022;
|
||||||
|
|
||||||
async function promisified(...a: any[]): Promise<any> {
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkerExt = Worker & { rpc: RpcProvider };
|
type WorkerExt = Worker & { rpc: RpcProvider };
|
||||||
export type Device = {
|
export type Device = {
|
||||||
|
@ -25,6 +23,7 @@ export type Device = {
|
||||||
progress?: Progress;
|
progress?: Progress;
|
||||||
queue?: Cmd[];
|
queue?: Cmd[];
|
||||||
running?: boolean;
|
running?: boolean;
|
||||||
|
log: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function downloadFile(
|
async function downloadFile(
|
||||||
|
@ -178,6 +177,7 @@ class Devices extends Vue implements GenericDevices {
|
||||||
name: device.productName,
|
name: device.productName,
|
||||||
isCxIi: device.productId === PID_CX2,
|
isCxIi: device.productId === PID_CX2,
|
||||||
needsDrivers: false,
|
needsDrivers: false,
|
||||||
|
log: '',
|
||||||
} as Device);
|
} as Device);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -189,7 +189,10 @@ class Devices extends Vue implements GenericDevices {
|
||||||
await device.open();
|
await device.open();
|
||||||
const worker: Worker & Partial<WorkerExt> = new UsbWorker();
|
const worker: Worker & Partial<WorkerExt> = new UsbWorker();
|
||||||
const sab = new SharedArrayBuffer(10000);
|
const sab = new SharedArrayBuffer(10000);
|
||||||
const compat = new UsbCompat(sab);
|
const writeMessage = (messages: any[]) => {
|
||||||
|
this.devices[dev].log += messages.map(message => ['string', 'number'].includes(typeof message) ? message : JSON.stringify(message)).join(' ') + '\n';
|
||||||
|
};
|
||||||
|
const compat = new UsbCompat(sab, writeMessage);
|
||||||
const id = compat.addDevice(device);
|
const id = compat.addDevice(device);
|
||||||
const rpc = new RpcProvider((message, transfer: any) =>
|
const rpc = new RpcProvider((message, transfer: any) =>
|
||||||
worker.postMessage(message, transfer)
|
worker.postMessage(message, transfer)
|
||||||
|
@ -203,6 +206,10 @@ class Devices extends Vue implements GenericDevices {
|
||||||
}
|
}
|
||||||
rpc.dispatch(data);
|
rpc.dispatch(data);
|
||||||
};
|
};
|
||||||
|
rpc.registerSignalHandler('log', (messages: any[]) => {
|
||||||
|
console.log(messages.join(' '));
|
||||||
|
writeMessage(messages);
|
||||||
|
});
|
||||||
this.$set(this.devices[dev], 'worker', worker as WorkerExt);
|
this.$set(this.devices[dev], 'worker', worker as WorkerExt);
|
||||||
|
|
||||||
await rpc.rpc('init', {id, sab, vid: device.vendorId, pid: device.productId});
|
await rpc.rpc('init', {id, sab, vid: device.vendorId, pid: device.productId});
|
||||||
|
|
|
@ -85,9 +85,11 @@ let count = 0;
|
||||||
export default class UsbCompat {
|
export default class UsbCompat {
|
||||||
devices: Record<number, USBDevice> = {};
|
devices: Record<number, USBDevice> = {};
|
||||||
arr: SharedArrayBuffer;
|
arr: SharedArrayBuffer;
|
||||||
|
log: (data: any[]) => void;
|
||||||
|
|
||||||
constructor(arr: SharedArrayBuffer) {
|
constructor(arr: SharedArrayBuffer, log: (data: any[]) => void) {
|
||||||
this.arr = arr;
|
this.arr = arr;
|
||||||
|
this.log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
addDevice(dev: USBDevice) {
|
addDevice(dev: USBDevice) {
|
||||||
|
@ -154,8 +156,10 @@ export default class UsbCompat {
|
||||||
}
|
}
|
||||||
|
|
||||||
async processCmd(cmd: Cmd) {
|
async processCmd(cmd: Cmd) {
|
||||||
|
this.log(['in:', cmd]);
|
||||||
console.log(cmd);
|
console.log(cmd);
|
||||||
const msg = await this._processCmd(cmd);
|
const msg = await this._processCmd(cmd);
|
||||||
|
this.log(['out:', msg]);
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
const encoded = encoder.encode(msg);
|
const encoded = encoder.encode(msg);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { RpcProvider } from 'worker-rpc';
|
||||||
// eslint-disable-next-line import/no-absolute-path
|
// eslint-disable-next-line import/no-absolute-path
|
||||||
import type { Calculator } from 'web-libnspire';
|
import type { Calculator } from 'web-libnspire';
|
||||||
|
|
||||||
console.log('worker!');
|
|
||||||
const ctx: Worker = self as any;
|
const ctx: Worker = self as any;
|
||||||
const module = import('@/web-libusb/web-libnspire/pkg');
|
const module = import('@/web-libusb/web-libnspire/pkg');
|
||||||
let calc: Calculator | undefined;
|
let calc: Calculator | undefined;
|
||||||
|
@ -13,6 +12,13 @@ const rpcProvider = new RpcProvider((message, transfer: any) =>
|
||||||
);
|
);
|
||||||
ctx.onmessage = (e) => rpcProvider.dispatch(e.data);
|
ctx.onmessage = (e) => rpcProvider.dispatch(e.data);
|
||||||
|
|
||||||
|
const origLog = console.log;
|
||||||
|
console.log = (...args: any[]) => {
|
||||||
|
origLog(...args);
|
||||||
|
rpcProvider.signal('log', args);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('worker!');
|
||||||
type Path = { path: string };
|
type Path = { path: string };
|
||||||
type Data = { data: Uint8Array };
|
type Data = { data: Uint8Array };
|
||||||
type SrcDest = { src: string; dest: string };
|
type SrcDest = { src: string; dest: string };
|
||||||
|
|
Loading…
Reference in a new issue