Add debug info

This commit is contained in:
lights0123 2020-11-22 13:22:11 -05:00
parent ed55b255d7
commit 44f99c5d2a
No known key found for this signature in database
GPG key ID: 28F315322E37972F
4 changed files with 30 additions and 5 deletions

View file

@ -36,6 +36,10 @@
</button>
<input v-if="nativeUpload" ref="upload" type="file" class="hidden" :accept="info.os_extension"
@change="uploadNative"/>
<button class="mt-4 button gray-button"
@click="copyLogs">
Copy logs
</button>
</div>
</template>
@ -73,6 +77,10 @@ export default class FileView extends Vue {
const file = e.target.files?.[0];
if (file) this.$devices.uploadOsFile(this.dev, file);
}
copyLogs() {
navigator.clipboard.writeText(this.$devices.devices[this.dev].log).catch(alert);
}
}
</script>

View file

@ -11,8 +11,6 @@ const PID = 0xe012;
/// The USB vendor ID used by all CX II calculators.
const PID_CX2 = 0xe022;
async function promisified(...a: any[]): Promise<any> {
}
type WorkerExt = Worker & { rpc: RpcProvider };
export type Device = {
@ -25,6 +23,7 @@ export type Device = {
progress?: Progress;
queue?: Cmd[];
running?: boolean;
log: string;
};
async function downloadFile(
@ -178,6 +177,7 @@ class Devices extends Vue implements GenericDevices {
name: device.productName,
isCxIi: device.productId === PID_CX2,
needsDrivers: false,
log: '',
} as Device);
} catch (e) {
console.error(e);
@ -189,7 +189,10 @@ class Devices extends Vue implements GenericDevices {
await device.open();
const worker: Worker & Partial<WorkerExt> = new UsbWorker();
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 rpc = new RpcProvider((message, transfer: any) =>
worker.postMessage(message, transfer)
@ -203,6 +206,10 @@ class Devices extends Vue implements GenericDevices {
}
rpc.dispatch(data);
};
rpc.registerSignalHandler('log', (messages: any[]) => {
console.log(messages.join(' '));
writeMessage(messages);
});
this.$set(this.devices[dev], 'worker', worker as WorkerExt);
await rpc.rpc('init', {id, sab, vid: device.vendorId, pid: device.productId});

View file

@ -85,9 +85,11 @@ let count = 0;
export default class UsbCompat {
devices: Record<number, USBDevice> = {};
arr: SharedArrayBuffer;
log: (data: any[]) => void;
constructor(arr: SharedArrayBuffer) {
constructor(arr: SharedArrayBuffer, log: (data: any[]) => void) {
this.arr = arr;
this.log = log;
}
addDevice(dev: USBDevice) {
@ -154,8 +156,10 @@ export default class UsbCompat {
}
async processCmd(cmd: Cmd) {
this.log(['in:', cmd]);
console.log(cmd);
const msg = await this._processCmd(cmd);
this.log(['out:', msg]);
console.log(msg);
const encoded = encoder.encode(msg);

View file

@ -4,7 +4,6 @@ import { RpcProvider } from 'worker-rpc';
// eslint-disable-next-line import/no-absolute-path
import type { Calculator } from 'web-libnspire';
console.log('worker!');
const ctx: Worker = self as any;
const module = import('@/web-libusb/web-libnspire/pkg');
let calc: Calculator | undefined;
@ -13,6 +12,13 @@ const rpcProvider = new RpcProvider((message, transfer: any) =>
);
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 Data = { data: Uint8Array };
type SrcDest = { src: string; dest: string };