Skip to content

Commit a66ddf8

Browse files
committed
Merge branch 'master' of https://github.com/Marus/cortex-debug
2 parents ed869ea + 17ad3b4 commit a66ddf8

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/frontend/swo/decoders/console.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -108,35 +108,42 @@ export class SWOConsoleProcessor implements SWORTTDecoder {
108108
}
109109
}
110110

111+
private logFileWrite(text: string) {
112+
if ( (this.logFd < 0) || (text === '') ) {
113+
return;
114+
}
115+
try {
116+
fs.writeSync(this.logFd, text);
117+
}
118+
catch (e) {
119+
const msg = `Could not write to file ${this.logfile}. ${e.toString()}`;
120+
vscode.window.showErrorMessage(msg);
121+
try { fs.closeSync(this.logFd); } catch {}
122+
this.logFd = -1;
123+
}
124+
}
125+
111126
public softwareEvent(packet: Packet) {
112127
if (packet.port !== this.port) { return; }
128+
let text = '';
113129
const letters = packet.data.toString(this.encoding);
114-
115-
if (this.logFd >= 0) {
116-
try {
117-
fs.writeSync(this.logFd, letters);
118-
}
119-
catch (e) {
120-
const msg = `Could not write to file ${this.logfile} for writing. ${e.toString()}`;
121-
vscode.window.showErrorMessage(msg);
122-
try { fs.closeSync(this.logFd); } catch {}
123-
this.logFd = -1;
124-
}
125-
}
126-
127130
for (const letter of letters) {
128131
if (this.timeout) { clearTimeout(this.timeout); this.timeout = null; }
129132

130133
if (letter === '\n') {
134+
text += '\n';
131135
this.pushOutput('\n');
132136
this.position = 0;
133137
continue;
134138
}
135139

136140
if (this.position === 0) {
137-
this.pushOutput(this.createDateHeaderUs());
141+
const timestampHeader = this.createDateHeaderUs();
142+
text += timestampHeader;
143+
this.pushOutput(timestampHeader);
138144
}
139145

146+
text += letter;
140147
this.pushOutput(letter);
141148
this.position += 1;
142149

@@ -145,12 +152,14 @@ export class SWOConsoleProcessor implements SWORTTDecoder {
145152
clearTimeout(this.timeout);
146153
}
147154
this.timeout = setTimeout(() => {
155+
text += '\n';
148156
this.pushOutput('\n');
149157
this.position = 0;
150158
this.timeout = null;
151159
}, 5000);
152160
}
153161
}
162+
this.logFileWrite(text);
154163
}
155164

156165
public hardwareEvent(event: Packet) {}

0 commit comments

Comments
 (0)