Skip to content

Commit

Permalink
refactor: start bringing common type declarations together
Browse files Browse the repository at this point in the history
  • Loading branch information
ssimek committed Jan 15, 2025
1 parent e1a792e commit 595ccd5
Show file tree
Hide file tree
Showing 26 changed files with 366 additions and 330 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.useTabStops": false,
"files.trimTrailingWhitespace": false,
"files.exclude": {
"out": false,
"dist": true,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ export class MI2 extends EventEmitter implements IBackend {
}
}

private onOutputStderr(lines) {
lines = lines.split('\n') as string[];
private onOutputStderr(text: string) {
const lines = text.split('\n');
lines.forEach((line) => {
this.log('stderr', line);
});
}

private onOutputPartial(line) {
private onOutputPartial(line: string) {
if (couldBeOutput(line)) {
this.logNoNewLine('stdout', line);
return true;
Expand Down
77 changes: 6 additions & 71 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as os from 'os';
import * as stream from 'stream';
import * as path from 'path';
import { GDBDebugSession } from './gdb';
import { SWOConfiguration } from './common/types/swo';
import { RTTConfiguration, RTTDecoderOpts } from "./common/types/rtt";
const readline = require('readline');

export enum ADAPTER_DEBUG_MODE {
Expand Down Expand Up @@ -88,62 +90,17 @@ export class SWOConfigureEvent extends Event implements DebugProtocol.Event {
}
}

export enum TerminalInputMode {
COOKED = 'cooked',
RAW = 'raw',
RAWECHO = 'rawecho',
DISABLED = 'disabled'
}
export interface RTTCommonDecoderOpts {
type: string; // 'console', 'graph', ...
tcpPort: string; // [hostname:]port
port: number; // RTT Channel number

// Following two used for 'Advanced' category
tcpPorts: string[];
ports: number[];
}

export enum TextEncoding {
UTF8 = 'utf8',
UTF16LE = 'utf16le',
ASCII = 'ascii',
UCS2 = 'ucs2'
}

export enum BinaryEncoding {
UNSIGNED = 'unsigned',
SIGNED = 'signed',
Q1616 = 'Q16.16',
FLOAT = 'float'
}

export interface CTIOpenOCDConfig {
enabled: boolean;
initCommands: string[];
pauseCommands: string[];
resumeCommands: string[];
}

export interface RTTConsoleDecoderOpts extends RTTCommonDecoderOpts {
// Console options
label: string; // label for window
prompt: string; // Prompt to use
noprompt: boolean; // disable prompt
noclear: boolean; // do not clear screen buffer on connect
logfile: string; // log IO to file
inputmode: TerminalInputMode;
iencoding: TextEncoding; // Encoding used for input
timestamp: boolean;
// Binary only options
scale: number;
encoding: BinaryEncoding;
}

export class RTTConfigureEvent extends Event implements DebugProtocol.Event {
public body: {
type: string, // Currently, only 'socket' is supported
decoder: RTTCommonDecoderOpts;
decoder: RTTDecoderOpts;
};
public event: string;

Expand Down Expand Up @@ -196,28 +153,6 @@ export interface ChainedConfigurations {
inherits: string[];
}

export interface SWOConfiguration {
enabled: boolean;
cpuFrequency: number;
swoFrequency: number;
decoders: any[];
profile: boolean;
source: string;
swoPort: string;
swoPath: string;
}

export interface RTTConfiguration {
enabled: boolean;
address: string;
searchSize: number;
searchId: string;
clearSearch: boolean;
polling_interval: number;
rtt_start_retry: number;
decoders: RTTCommonDecoderOpts[];
}

export interface ElfSection {
name: string;
address: number; // New base address
Expand Down Expand Up @@ -419,7 +354,7 @@ export class RTTServerHelper {
// basis depending on the gdb-server type
const dummy = '??';
for (const dec of cfg.decoders) {
if (dec.ports && (dec.ports.length > 0)) {
if (dec.type === 'advanced') {
dec.tcpPorts = [];
for (const p of dec.ports) {
this.rttLocalPortMap[p] = dummy;
Expand All @@ -433,7 +368,7 @@ export class RTTServerHelper {
const portFinderOpts = { min: startPort, max: startPort + 2000, retrieve: count, consecutive: false };
return TcpPortScanner.findFreePorts(portFinderOpts, GDBServer.LOCALHOST).then((ports) => {
for (const dec of cfg.decoders) {
if (dec.ports && (dec.ports.length > 0)) {
if (dec.type === 'advanced') {
dec.tcpPorts = [];
for (const p of dec.ports) {
let str = this.rttLocalPortMap[p];
Expand All @@ -459,7 +394,7 @@ export class RTTServerHelper {
let ret = false;
if (cfg.enabled) {
for (const dec of cfg.decoders) {
if (dec.tcpPort || dec.tcpPorts) {
if ((dec.type === 'advanced' && dec.tcpPorts) || (dec.type !== 'advanced' && dec.tcpPort)) {
obj.emit('event', new RTTConfigureEvent({
type: 'socket',
decoder: dec
Expand Down
45 changes: 45 additions & 0 deletions src/common/types/decoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export enum BinaryEncoding {
UNSIGNED = 'unsigned',
SIGNED = 'signed',
Q1616 = 'q16.16',
FLOAT = 'float'
}

export enum TextEncoding {
UTF8 = 'utf8',
UTF16LE = 'utf16le',
ASCII = 'ascii',
UCS2 = 'ucs2'
}

export interface CommonDecoderConfig {
logfile: string;
}

export interface BasicDecoderConfig extends CommonDecoderConfig {
port: number;
}

export interface ConsoleDecoderConfig extends BasicDecoderConfig {
label: string;
encoding: TextEncoding;
timestamp: boolean;
}

export interface BinaryDecoderConfig extends BasicDecoderConfig {
encoding: BinaryEncoding;
scale: number;
label: string;
}

export interface GraphDecoderConfig extends BasicDecoderConfig {
encoding: BinaryEncoding;
scale: number;
graphId: string;
}

export interface AdvancedDecoderConfig {
decoder: string;
config: any;
ports: number[];
}
80 changes: 80 additions & 0 deletions src/common/types/grapher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { SWOProfileConfig } from './swo';

export interface CommonGraphConfiguration {
label: string;
}

export interface TimeseriesGraphConfiguration extends CommonGraphConfiguration {
type: 'realtime';
minimum: number;
maximum: number;
timespan: number;
plots: Array<{
graphId: string,
label: string,
color: string
}>;
}

export interface XYGraphConfiguration extends CommonGraphConfiguration {
type: 'x-y-plot';
xPort: number;
yPort: number;
xMinimum: number;
xMaximum: number;
yMinimum: number;
yMaximum: number;
initialX: number;
initialY: number;
timespan: number;
xGraphId: string;
yGraphId: string;
}

export type GraphConfiguration = TimeseriesGraphConfiguration | XYGraphConfiguration;

export interface GrapherMessageBase {
timestamp?: number;
}

export interface GrapherUnsupportedMessage extends GrapherMessageBase {
type: '';
}

export interface GrapherInitMessage extends GrapherMessageBase {
type: 'init';
}

export interface GrapherStatusMessage extends GrapherMessageBase {
type: 'status';
status: 'stopped' | 'terminated' | 'continued';
}

export interface GrapherDataMessage extends GrapherMessageBase {
type: 'data';
id: string;
data: number;
}

export type GrapherProgramStats = Array<[ string, number ]>;

export interface GrapherProgramCounterMessage extends GrapherMessageBase {
type: 'program-counter';
function: string;
counter: number;
}

export interface GrapherConfigurationMessage extends GrapherMessageBase {
type: 'configure';
graphs: [ GraphConfiguration ];
profile: SWOProfileConfig;
status: 'stopped' | 'terminated' | 'continued';
}

export type GrapherMessage =
GrapherUnsupportedMessage |
GrapherInitMessage |
GrapherStatusMessage |
GrapherDataMessage |
GrapherProgramCounterMessage |
GrapherConfigurationMessage;
4 changes: 4 additions & 0 deletions src/common/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './decoder';
export * from './grapher';
export * from './rtt';
export * from './swo';
56 changes: 56 additions & 0 deletions src/common/types/rtt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { AdvancedDecoderConfig, BasicDecoderConfig, BinaryDecoderConfig, ConsoleDecoderConfig, GraphDecoderConfig } from './decoder';

export enum TerminalInputMode {
COOKED = 'cooked',
RAW = 'raw',
RAWECHO = 'rawecho',
DISABLED = 'disabled'
}

export interface RTTCommonDecoderOpts {
noclear: boolean; // do not clear screen buffer on connect
logfile: string; // log IO to file
}

export interface RTTBasicDecoderOpts extends RTTCommonDecoderOpts, BasicDecoderConfig {
tcpPort: string; // [hostname:]port
}

export interface RTTCommonTerminalDecoderOpts extends RTTBasicDecoderOpts {
label: string; // label for window
prompt: string; // Prompt to use
noprompt: boolean; // disable prompt
inputmode: TerminalInputMode;
}

export interface RTTConsoleDecoderOpts extends RTTBasicDecoderOpts, RTTCommonTerminalDecoderOpts, ConsoleDecoderConfig {
type: 'console';
}

export interface RTTBinaryDecoderOpts extends RTTBasicDecoderOpts, RTTCommonTerminalDecoderOpts, BinaryDecoderConfig {
type: 'binary';
}

export type RTTTerminalDecoderOpts = RTTBinaryDecoderOpts | RTTConsoleDecoderOpts;

export interface RTTGraphDecoderOpts extends RTTBasicDecoderOpts, GraphDecoderConfig {
type: 'graph';
}

export interface RTTAdvancedDecoderOpts extends RTTCommonDecoderOpts, AdvancedDecoderConfig {
type: 'advanced';
tcpPorts: string[];
}

export type RTTDecoderOpts = RTTConsoleDecoderOpts | RTTBinaryDecoderOpts | RTTGraphDecoderOpts | RTTAdvancedDecoderOpts;

export interface RTTConfiguration {
enabled: boolean;
address: string;
searchSize: number;
searchId: string;
clearSearch: boolean;
polling_interval: number;
rtt_start_retry: number;
decoders: RTTDecoderOpts[];
}
Loading

0 comments on commit 595ccd5

Please sign in to comment.