MCPcopy Create free account
hub / github.com/Marus/cortex-debug / SWORTTGraphProcessor

Class SWORTTGraphProcessor

src/frontend/swo/decoders/graph.ts:13–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export class SWORTTGraphProcessor extends EventEmitter implements SWORTTDecoder {
14 public readonly format: string = 'graph';
15 private port: number;
16 private scale: number;
17 private encoding: string;
18 private graphId: string;
19 private logFd: number = -1;
20 private logfile: string;
21
22 constructor(config: SWOGraphDecoderConfig) {
23 super();
24 // core.socketServer.registerProcessor(this);
25 this.port = config.port;
26 this.encoding = config.encoding || 'unsigned';
27 this.scale = config.scale || 1;
28 this.graphId = config.graphId;
29 if (config.logfile) {
30 this.logfile = config.logfile;
31 try {
32 this.logFd = fs.openSync(config.logfile, 'w');
33 }
34 catch (e) {
35 const msg = `Could not open file ${config.logfile} for writing. ${e.toString()}`;
36 vscode.window.showErrorMessage(msg);
37 }
38 }
39 }
40
41 public softwareEvent(packet: Packet) {
42 if (packet.port !== this.port) { return; }
43
44 const raw = packet.data.toString('hex');
45 const decodedValue = parseEncoded(packet.data, this.encoding);
46 const scaledValue = decodedValue * this.scale;
47
48 const message: GrapherDataMessage = { type: 'data', data: scaledValue, id: this.graphId };
49 this.emit('message', message);
50
51 if (this.logFd >= 0) {
52 try {
53 fs.writeSync(this.logFd, packet.data);
54 }
55 catch (e) {
56 const msg = `Could not write to file ${this.logfile} for writing. ${e.toString()}`;
57 vscode.window.showErrorMessage(msg);
58 try { fs.closeSync(this.logFd); } catch {}
59 this.logFd = -1;
60 }
61 }
62 }
63
64 public hardwareEvent(event: Packet) {}
65 public synchronized() {}
66 public lostSynchronization() {}
67 public dispose() { this.close(); }
68
69 public close() {
70 if (this.logFd >= 0) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected