-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
46 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 |
---|---|---|
|
@@ -45,6 +45,10 @@ export function createTerminal( | |
model_serial?: string, | ||
command_text?: string, | ||
): boolean { | ||
const LOGLOC: SourceLocation = { | ||
file: "extension.ts", | ||
func: `createTerminal("${connection_string}", "${model_serial}", "${command_text}")`, | ||
} | ||
//'example@5e6:2461@2' OR '[email protected]' | ||
let res: [string, string?] = ["", undefined] | ||
let ip = connection_string | ||
|
@@ -55,17 +59,26 @@ export function createTerminal( | |
} | ||
|
||
if (_connHelper.IPTest(ip)) { | ||
Log.debug("Connection type was determined to be LAN", LOGLOC) | ||
//LAN | ||
Log.trace("Creating terminal", LOGLOC) | ||
res = _activeConnectionManager?.createTerminal( | ||
name, | ||
IoType.Lan, | ||
connection_string, | ||
command_text, | ||
) | ||
|
||
//const instr_to_save: string = "Lan:" + model_serial_no | ||
Log.trace( | ||
`createTerminal responded with '${res.toString().replace("\n", "").trim()}'`, | ||
LOGLOC, | ||
) | ||
const info = res[0].replace("\n", "") | ||
if (info == "") { | ||
Log.trace( | ||
"Unable to read response from createTerminal, could not connect to instrument", | ||
LOGLOC, | ||
) | ||
void vscode.window.showErrorMessage( | ||
"Unable to connect to instrument", | ||
) | ||
|
@@ -74,8 +87,14 @@ export function createTerminal( | |
name = res[1] == undefined ? name : res[1] | ||
const port_number = "5025" | ||
|
||
Log.trace( | ||
`Details from createTerminal - info: "${info}", name: "${name}"`, | ||
LOGLOC, | ||
) | ||
Log.trace("Saving connection", LOGLOC) | ||
_instrExplorer.saveWhileConnect(ip, IoType.Lan, info, name, port_number) | ||
} else { | ||
Log.debug("Connection type was determined to be VISA", LOGLOC) | ||
//VISA | ||
//This only works if selected from Instrument discovery | ||
if (name == "") { | ||
|
@@ -87,16 +106,27 @@ export function createTerminal( | |
connection_string, | ||
command_text, | ||
) | ||
Log.trace(`createTerminal responded with '${res.toString()}'`, LOGLOC) | ||
|
||
const info = res[0].replace("\n", "") | ||
if (info == "") { | ||
Log.trace( | ||
"Unable to read response from createTerminal, could not connect to instrument", | ||
LOGLOC, | ||
) | ||
void vscode.window.showErrorMessage( | ||
"Unable to connect to instrument", | ||
) | ||
return false | ||
} | ||
name = res[1] == undefined ? name : res[1] | ||
|
||
Log.trace( | ||
`Details from createTerminal - info: "${info}", name: "${name}"`, | ||
LOGLOC, | ||
) | ||
|
||
Log.trace("Saving connection", LOGLOC) | ||
_instrExplorer.saveWhileConnect(ip, IoType.Visa, info, name, undefined) | ||
} | ||
return true | ||
|
@@ -256,7 +286,10 @@ function updateExtensionSettings() { | |
.getConfiguration("tsp") | ||
.update(setting, undefined, true) | ||
.then(() => { | ||
Log.info(`Setting \`${setting}\` removed`) | ||
Log.info( | ||
`Setting \`${setting}\` removed`, | ||
LOGLOC, | ||
) | ||
void vscode.window.showInformationMessage( | ||
"removed setting: " + setting, | ||
) | ||
|
@@ -505,13 +538,31 @@ async function startRename(def: unknown): Promise<void> { | |
} | ||
|
||
function connectCmd(def: object) { | ||
const LOGLOC: SourceLocation = { | ||
file: "extension.ts", | ||
func: `connectCmd(${String(def)})`, | ||
} | ||
|
||
Log.trace("Fetching connection args", LOGLOC) | ||
const [connection_str, model_serial] = | ||
_instrExplorer.fetchConnectionArgs(def) | ||
|
||
Log.trace( | ||
`Connection string: '${connection_str}', Model serial: '${model_serial}'`, | ||
LOGLOC, | ||
) | ||
|
||
if (_activeConnectionManager?.connectionRE.test(connection_str)) { | ||
Log.trace("Connection string is valid. Creating Terminal", LOGLOC) | ||
createTerminal(connection_str, model_serial) | ||
} else { | ||
void vscode.window.showErrorMessage("Unable to connect.") | ||
Log.error( | ||
"Connection string is invalid. Unable to connect to instrument.", | ||
LOGLOC, | ||
) | ||
void vscode.window.showErrorMessage( | ||
`Unable to connect. "${connection_str}" is not a valid connection string.`, | ||
) | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -7,10 +7,10 @@ enum LogLevel { | |
DEBUG = 1, | ||
INFO = 2, | ||
WARN = 3, | ||
CRITICAL = 4, | ||
ERROR = 4, | ||
} | ||
|
||
const LOGLEVEL_PAD = 8 | ||
const LOGLEVEL_PAD = 5 | ||
|
||
function logLevelToString(level: LogLevel): string { | ||
switch (level) { | ||
|
@@ -22,54 +22,59 @@ function logLevelToString(level: LogLevel): string { | |
return "INFO" | ||
case LogLevel.WARN: | ||
return "WARN" | ||
case LogLevel.CRITICAL: | ||
return "CRITICAL" | ||
case LogLevel.ERROR: | ||
return "ERROR" | ||
} | ||
} | ||
export class Log { | ||
/** | ||
* Write a trace-level log to the log file. | ||
* | ||
* @param msg The message to write to the log file | ||
* @param location The location in which the log took place | ||
*/ | ||
public static trace(msg: string, location?: SourceLocation): void { | ||
public static trace(msg: string, location: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.TRACE, msg, location) | ||
} | ||
|
||
/** | ||
* Write a debug-level log to the log file. | ||
* | ||
* @param msg The message to write to the log file | ||
* @param location The location in which the log took place | ||
*/ | ||
public static debug(msg: string, location?: SourceLocation): void { | ||
public static debug(msg: string, location: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.DEBUG, msg, location) | ||
} | ||
|
||
/** | ||
* Write an info-level log to the log file. | ||
* | ||
* @param msg The message to write to the log file | ||
* @param location The location in which the log took place | ||
*/ | ||
public static info(msg: string, location?: SourceLocation): void { | ||
public static info(msg: string, location: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.INFO, msg, location) | ||
} | ||
|
||
/** | ||
* Write a warning-level log to the log file. | ||
* | ||
* @param msg The message to write to the log file | ||
* @param location The location in which the log took place | ||
*/ | ||
public static warn(msg: string, location?: SourceLocation): void { | ||
public static warn(msg: string, location: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.WARN, msg, location) | ||
} | ||
|
||
/** | ||
* Write a critical-level log to the log file. | ||
* | ||
* @param msg The message to write to the log file | ||
* @param location The location in which the log took place | ||
*/ | ||
public static crit(msg: string, location: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.CRITICAL, msg, location) | ||
public static error(msg: string, location?: SourceLocation): void { | ||
Log.instance().writeln(new Date(), LogLevel.ERROR, msg, location) | ||
} | ||
|
||
private date: Date | ||
|
@@ -138,7 +143,11 @@ export class Log { | |
): void { | ||
//2024-10-15T12:34:56.789Z [INFO ] [email protected]: Some message to write to the log file | ||
const content = `${timestamp.toISOString()} [${logLevelToString(level).padEnd(LOGLEVEL_PAD, " ")}] ${toString(location)}${msg}\n` | ||
appendFileSync(this.file, content) | ||
try { | ||
appendFileSync(this.file, content) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.