move diagnostics out of routing

This commit is contained in:
pelikhan 2020-12-16 21:54:28 +01:00
Родитель 6de5f97676
Коммит 948abfe4c2
3 изменённых файлов: 33 добавлений и 29 удалений

31
diagnostics.ts Normal file
Просмотреть файл

@ -0,0 +1,31 @@
namespace jacdac {
/**
* Gets the internal diagnostics data from the JACDAC transport layer
*/
export function diagnostics(): jacdac.JDDiagnostics {
return new jacdac.JDDiagnostics(jacdac.__physGetDiagnostics());
}
export class JDDiagnostics {
busState: number;
busLoError: number;
busUartError: number;
busTimeoutError: number;
packetsSent: number;
packetsReceived: number;
packetsDropped: number;
constructor(buf: Buffer) {
if (!buf) return;
[
this.busState,
this.busLoError,
this.busUartError,
this.busTimeoutError,
this.packetsSent,
this.packetsReceived,
this.packetsDropped
] = jdunpack<number[]>(buf, "u32 u32 u32 u32 u32 u32 u32")
}
}
}

Просмотреть файл

@ -28,6 +28,7 @@
"service.ts",
"pipes.ts",
"actuator.ts",
"diagnostics.ts",
"ns.ts",
"system/constants.ts",
"base/constants.ts",
@ -75,4 +76,4 @@
"url": "https://microsoft.github.io/jacdac-ts/makecode-editor-extension",
"localUrl": "http://localhost:8000/tools/makecode-editor-extension"
}
}
}

Просмотреть файл

@ -879,32 +879,4 @@ namespace jacdac {
});
loggerHost.start()
}
export function diagnostics(): jacdac.JDDiagnostics {
return new jacdac.JDDiagnostics(jacdac.__physGetDiagnostics());
}
export class JDDiagnostics {
bus_state: number;
bus_lo_error: number;
bus_uart_error: number;
bus_timeout_error: number;
packets_sent: number;
packets_received: number;
packets_dropped: number;
constructor(buf: Buffer) {
if (!buf) return;
[
this.bus_state,
this.bus_lo_error,
this.bus_uart_error,
this.bus_timeout_error,
this.packets_sent,
this.packets_received,
this.packets_dropped
] = pins.unpackBuffer("7I", buf)
}
}
}