Skip to content

Commit

Permalink
Merge branch 'main' into bug_fix/TSP-839-Fix-visa-ip-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GT, Shreya committed Oct 16, 2024
2 parents 62f9802 + f28ffd1 commit dcf9215
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 416 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

- Added walkthrough document
- Added macOS support (LAN only)
- Added file logging for extension code

### Changed

Expand All @@ -34,6 +35,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
the instrument
- When entering only visa instrument address, connection is saved with correct model and serial number (TSP-839)

### Removed

- Removed VSCode Output pane logging

## [0.18.1]

### Added
Expand Down
18 changes: 13 additions & 5 deletions src/communicationmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
KicProcessMgr,
} from "./resourceManager"
import { createTerminal } from "./extension"
import { Log, SourceLocation } from "./logging"

export class CommunicationManager {
public connectionRE = /(?:(\w+)@)?(\d+.*)/
Expand Down Expand Up @@ -143,11 +144,11 @@ export class CommunicationManager {
kicTerminals.forEach((t) => {
const k: string =
t.name +
"@" +
(
(t.creationOptions as vscode.TerminalOptions)
?.shellArgs as string[]
)[1] ?? ""
"@" +
(
(t.creationOptions as vscode.TerminalOptions)
?.shellArgs as string[]
)[1]
kicDict[k] = t
})
if ((await vscode.window.showInputBox(options)) != undefined) {
Expand Down Expand Up @@ -181,13 +182,18 @@ export class CommunicationManager {
address: string,
filePath?: string,
): [info: string, verified_name?: string] {
const LOGLOC: SourceLocation = {
file: "extension.ts",
func: `CommunicationManager.createTerminal("${term_name}", "${connType.toString()}", "${address}", "${filePath ?? ""}")`,
}
let res: [string, string?] = ["", undefined]
const maxerr: number =
vscode.workspace.getConfiguration("tsp").get("errorLimit") ?? 0

switch (connType) {
case IoType.Lan:
{
Log.trace("Connecting via LAN", LOGLOC)
const parts = address.match(CONNECTION_RE)
if (parts == null) return ["", undefined]
const ip_addr = parts[2]
Expand All @@ -203,6 +209,7 @@ export class CommunicationManager {
break
case IoType.Usb:
{
Log.trace("Connecting via USB", LOGLOC)
let unique_string = address
const string_split = address.split("@")
if (string_split.length > 1) {
Expand All @@ -219,6 +226,7 @@ export class CommunicationManager {
break
case IoType.Visa:
{
Log.trace("Connecting via VISA", LOGLOC)
let unique_string = address
const string_split = address.split("@")
if (string_split.length > 1) {
Expand Down
99 changes: 96 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
RELATIVE_TSP_CONFIG_FILE_PATH,
updateConfiguration,
} from "./workspaceManager"
import { Log, SourceLocation } from "./logging"

let _activeConnectionManager: CommunicationManager
//let _terminationMgr: TerminationManager
Expand All @@ -44,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
Expand All @@ -54,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",
)
Expand All @@ -73,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 == "") {
Expand All @@ -86,54 +106,77 @@ 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
}

// Called when the extension is activated.
export function activate(context: vscode.ExtensionContext) {
const LOGLOC: SourceLocation = { file: "extension.ts", func: "activate()" }
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "tspcomms" is now active!')
Log.info("TSP Toolkit activating", LOGLOC)

Log.trace("Updating extension settings", LOGLOC)
updateExtensionSettings()

Log.trace("Starting ConnectionHelper", LOGLOC)
_connHelper = new ConnectionHelper()

Log.trace("Starting KicProcessMgr", LOGLOC)
_kicProcessMgr = new KicProcessMgr(_connHelper)

// Create an object of Communication Manager
Log.trace("Starting CommunicationManager", LOGLOC)
_activeConnectionManager = new CommunicationManager(
context,
_kicProcessMgr,
_connHelper,
)
//_terminationMgr = new TerminationManager()
Log.trace("Creating new InstrumentExplorer", LOGLOC)
_instrExplorer = new InstrumentsExplorer(context, _kicProcessMgr)

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
Log.trace("Registering `tsp.openTerminal` command", LOGLOC)
const openTerminal = vscode.commands.registerCommand(
"tsp.openTerminal",
pickConnection,
)

Log.trace("Registering `InstrumentExplorer.connect` command", LOGLOC)
const add_new_connection = vscode.commands.registerCommand(
"InstrumentsExplorer.connect",
async () => {
await pickConnection("New Connection")
},
)

Log.trace("Setting up HelpDocumentWebView", LOGLOC)
context.subscriptions.push(add_new_connection)

HelpDocumentWebView.createOrShow(context)
Expand All @@ -153,7 +196,10 @@ export function activate(context: vscode.ExtensionContext) {
},
*/

Log.trace("Registering `tsp.openTerminalIP` command", LOGLOC)
vscode.commands.registerCommand("tsp.openTerminalIP", connectCmd)

Log.trace("Registering `InstrumentExplorer.rename` command", LOGLOC)
vscode.commands.registerCommand("InstrumentsExplorer.rename", async (e) => {
await startRename(e)
})
Expand All @@ -164,9 +210,19 @@ export function activate(context: vscode.ExtensionContext) {
//context.subscriptions.push(terminateAll) TODO: This isn't connected in ki-comms...
//context.subscriptions.push(rclick)

Log.trace(
"Checking to see if workspace folder contains `*.tsp` files",
LOGLOC,
)
// call function which is required to call first time while activating the plugin
void processWorkspaceFolders()

Log.trace("Update local and global configuration for TSP", LOGLOC)
void configure_initial_workspace_configurations()
Log.trace(
"Subscribing to TSP configuration changes in all workspace folders",
LOGLOC,
)
hookTspConfigFileChange(context, vscode.workspace.workspaceFolders?.slice())

// Register a handler to process files whenever file is saved
Expand All @@ -190,19 +246,30 @@ export function activate(context: vscode.ExtensionContext) {
}),
)

Log.info("TSP Toolkit activation complete", LOGLOC)

return base_api
}

// Called when the extension is deactivated.
export function deactivate() {
Log.info("Deactivating TSP Toolkit", {
file: "extensions.ts",
func: "deactivate()",
})
/* empty */
}

function updateExtensionSettings() {
const LOGLOC: SourceLocation = {
file: "extension.ts",
func: "updateExtensionSettings()",
}
const settingsList = ["connectionList", "savedInstrumentList"]
settingsList.forEach((setting) => {
if (vscode.workspace.getConfiguration("tsp").get(setting)) {
console.log(setting)
Log.warn(`Found deprecated setting: \`${setting}\``, LOGLOC)
void vscode.window
.showInformationMessage(
setting +
Expand All @@ -211,10 +278,18 @@ function updateExtensionSettings() {
)
.then((selection) => {
if (selection == "Remove") {
Log.info(
`User chose to remove \`${setting}\`. Removing.`,
LOGLOC,
)
void vscode.workspace
.getConfiguration("tsp")
.update(setting, undefined, true)
.then(() => {
Log.info(
`Setting \`${setting}\` removed`,
LOGLOC,
)
void vscode.window.showInformationMessage(
"removed setting: " + setting,
)
Expand Down Expand Up @@ -463,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.`,
)
}
}

Expand Down
20 changes: 19 additions & 1 deletion src/instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
KicProcessMgr,
} from "./resourceManager"
import { LOG_DIR } from "./utility"
import { Log, SourceLocation } from "./logging"
//import { LoggerManager } from "./logging"

const DISCOVERY_TIMEOUT = 5
Expand Down Expand Up @@ -740,7 +741,12 @@ export class NewTDPModel {

//add from connect
public addFromConnectToSavedList(ioType: IoType, instr_details: InstrInfo) {
const LOGLOC: SourceLocation = {
file: "instruments.ts",
func: `NewTDPModel.addFromConnectToSavedList("${ioType.toString()}", "${String(instr_details)}")`,
}
if (instr_details != undefined) {
Log.trace("Adding instrument to list", LOGLOC)
this._savedNodeProvider?.saveInstrToList(
DiscoveryHelper.createUniqueID(instr_details),
)
Expand Down Expand Up @@ -768,8 +774,11 @@ export class NewTDPModel {
saved_list ?? [],
true,
)
break
}
return
}
Log.warn("Instrument details not provided", LOGLOC)
}

public addSavedList(instr: unknown) {
Expand Down Expand Up @@ -1223,6 +1232,11 @@ export class InstrTDP implements newTDP {
ioType: IoType,
instr_details: InstrInfo,
): void {
const LOGLOC: SourceLocation = {
file: "instruments.ts",
func: `InstrTDP.saveInstrumentFromConnect("${ioType.toString()}", "${String(instr_details)}")`,
}
Log.trace("Add from connect to saved list", LOGLOC)
this.instrModel?.addFromConnectToSavedList(ioType, instr_details)
this.reloadTreeData()
}
Expand Down Expand Up @@ -1423,6 +1437,10 @@ export class InstrumentsExplorer {
friendly_name: string,
port: string | undefined,
) {
const LOGLOC: SourceLocation = {
file: "instruments.ts",
func: `InstrumentExplorer.saveWhileConnect("${ip}", "${ioType.toString()}", "${info}", "${friendly_name}", "${port}")`,
}
const _info = <IIDNInfo>JSON.parse(info)
const __info = new InstrInfo()
__info.io_type = ioType
Expand All @@ -1438,7 +1456,7 @@ export class InstrumentsExplorer {
const categ = instr_map.get(_info.model)
if (categ != undefined) __info.instr_categ = categ

//FriendlyNameMgr.checkandAddFriendlyName(__info, friendly_name)
Log.trace("Saving Instrument", LOGLOC)

this.treeDataProvider?.saveInstrumentFromConnect(ioType, __info)
}
Expand Down
Loading

0 comments on commit dcf9215

Please sign in to comment.