-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: paulober <[email protected]>
- Loading branch information
Showing
12 changed files
with
281 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const { spawn } = require('child_process'); | ||
|
||
class DefmtDecoder { | ||
constructor() { | ||
this.process = null; | ||
this.elfPath = null; | ||
this.displayOutput = null; | ||
this.graphData = null; | ||
this.ports = []; | ||
} | ||
|
||
init(config, displayOutput, graphData) { | ||
// Store the callbacks and elfPath from the config | ||
this.elfPath = config.elfPath; | ||
this.displayOutput = displayOutput; | ||
this.graphData = graphData; | ||
this.ports = config.ports; | ||
|
||
const defmtPrintPath = `${process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME}/.cargo/bin/defmt-print${process.platform === "win32" ? ".exe" : ""}`; | ||
|
||
// Spawn the defmt-print process with the provided ELF path | ||
this.process = spawn(defmtPrintPath, ['-e', this.elfPath, "stdin"]); | ||
|
||
// Handle data from defmt-print stdout and relay it to the displayOutput callback | ||
this.process.stdout.on('data', (data) => { | ||
if (this.displayOutput) { | ||
this.displayOutput(data.toString()); | ||
} | ||
}); | ||
|
||
// Handle errors from defmt-print stderr | ||
this.process.stderr.on('data', (data) => { | ||
if (this.displayOutput) { | ||
this.displayOutput(data.toString()); | ||
} | ||
}); | ||
|
||
// Handle when the process closes | ||
this.process.on('close', (code) => { | ||
if (this.displayOutput) { | ||
this.displayOutput(`Decoding process exited with code: ${code}`); | ||
} | ||
}); | ||
} | ||
|
||
sendData(input) { | ||
// Write input data to defmt-print's stdin | ||
try { | ||
if (this.process && this.process.stdin.writable) { | ||
this.process.stdin.write(input); | ||
return; | ||
} | ||
} catch { } | ||
|
||
throw new Error('Process stdin is not writable.'); | ||
} | ||
|
||
// Expected methods from the SWODecoder API conforming to the AdvancedDecoder interface | ||
|
||
typeName() { | ||
return 'DefmtDecoder'; | ||
} | ||
|
||
outputLabel() { | ||
return 'RPi Pico'; | ||
} | ||
|
||
softwareEvent(port, data) { | ||
if (this.ports.indexOf(port) !== -1) { | ||
// Handle the software event, potentially by sending data to defmt-print stdin | ||
this.sendData(data); | ||
} | ||
} | ||
|
||
synchronized() { | ||
// Handle the synchronized event | ||
if (this.displayOutput) { | ||
this.displayOutput('Synchronized'); | ||
} | ||
} | ||
|
||
lostSynchronization() { | ||
// Handle the lost synchronization event | ||
if (this.displayOutput) { | ||
this.displayOutput('Lost synchronization'); | ||
} | ||
} | ||
|
||
dispose() { | ||
// Clean up the process | ||
if (this.process) { | ||
this.process.kill(); | ||
this.process = null; | ||
} | ||
} | ||
} | ||
|
||
module.exports = exports = DefmtDecoder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { spawn } from 'child_process'; | ||
import EventEmitter from 'events'; | ||
|
||
/* | ||
interface AdvancedDecoder { | ||
init( | ||
config: SWOAdvancedDecoderConfig, | ||
outputData: (output: string) => void, | ||
graphData: (data: number, id: string) => void | ||
): void; | ||
typeName(): string; | ||
outputLabel(): string; | ||
softwareEvent(port: number, data: Buffer): void; | ||
synchronized(): void; | ||
lostSynchronization(): void; | ||
}*/ | ||
|
||
class DefmtDecoder extends EventEmitter { | ||
constructor() { | ||
this.process = null; | ||
this.elfPath = null; | ||
this.displayOutput = null; | ||
this.graphData = null; | ||
} | ||
|
||
init(config, displayOutput, graphData) { | ||
// Store the callbacks and elfPath from the config | ||
this.elfPath = config.config.elfPath; | ||
this.displayOutput = displayOutput; | ||
this.graphData = graphData; | ||
|
||
const defmtPrintPath = `${process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME}/.cargo/bin/defmt-print${process.platform === "win32" ? ".exe" : ""}`; | ||
|
||
// Spawn the defmt-print process with the provided ELF path | ||
this.process = spawn(defmtPrintPath, ['-e', this.elfPath, "stdin"]); | ||
|
||
// Handle data from defmt-print stdout and relay it to the displayOutput callback | ||
this.process.stdout.on('data', (data) => { | ||
if (this.displayOutput) { | ||
this.displayOutput(data.toString()); | ||
} | ||
}); | ||
|
||
// Handle errors from defmt-print stderr | ||
this.process.stderr.on('data', (data) => { | ||
if (this.displayOutput) { | ||
//this.displayOutput(`Error: ${data.toString()}`); | ||
this.displayOutput(data.toString()); | ||
} | ||
}); | ||
|
||
// Handle when the process closes | ||
this.process.on('close', (code) => { | ||
if (this.displayOutput) { | ||
this.displayOutput(`Decoding process exited with code: ${code}`); | ||
} | ||
}); | ||
} | ||
|
||
//sendData(input: Buffer): void; | ||
sendData(input) { | ||
// Write input data to defmt-print's stdin | ||
try { | ||
if (this.process && this.process.stdin.writable) { | ||
this.process.stdin.write(input); | ||
return; | ||
} | ||
} catch { } | ||
|
||
throw new Error('Process stdin is not writable.'); | ||
} | ||
|
||
// Expected methods from the SWODecoder API conforming to the AdvancedDecoder interface | ||
|
||
//typeName(): string; | ||
typeName() { | ||
return 'DefmtDecoder'; | ||
} | ||
|
||
//outputLabel(): string; | ||
outputLabel() { | ||
return 'RPi Pico'; | ||
} | ||
|
||
//softwareEvent(port: number, data: Buffer): void; | ||
softwareEvent(port, data) { | ||
if (this.ports.indexOf(port) !== -1) { | ||
// Handle the software event, potentially by sending data to defmt-print stdin | ||
this.sendData(data); | ||
} | ||
} | ||
|
||
//synchronized(): void; | ||
synchronized() { | ||
// Handle the synchronized event | ||
if (this.displayOutput) { | ||
this.displayOutput('Synchronized'); | ||
} | ||
} | ||
|
||
//lostSynchronization(): void; | ||
lostSynchronization() { | ||
// Handle the lost synchronization event | ||
if (this.displayOutput) { | ||
this.displayOutput('Lost synchronization'); | ||
} | ||
} | ||
|
||
// own dispose method | ||
|
||
dispose() { | ||
// Clean up the process | ||
if (this.process) { | ||
this.process.kill(); | ||
this.process = null; | ||
} | ||
this.emit('dispose'); | ||
} | ||
} | ||
|
||
export default DefmtDecoder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Logger from "../logger.mjs"; | ||
import { CommandWithResult } from "./command.mjs"; | ||
import { Uri } from "vscode"; | ||
|
||
export default class GetRTTDecoderPathCommand extends CommandWithResult<string> { | ||
private readonly _logger = new Logger("GetRTTDecoderPathCommand"); | ||
|
||
public static readonly id = "getRTTDecoderPath"; | ||
|
||
constructor(private readonly _extensionUri: Uri) { | ||
super(GetRTTDecoderPathCommand.id); | ||
} | ||
|
||
execute(): string { | ||
this._logger.debug("Retrieving RTT decoder path"); | ||
|
||
return Uri.joinPath(this._extensionUri, "scripts", "rttDecoder.cjs").fsPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.