Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/tsp 757 default connection name #38

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

### Added
- Add logging for terminal and discover
- Default friendly name if user doesn't provide one (TSP-757)

## [0.16.4]

Expand Down
8 changes: 3 additions & 5 deletions src/communicationmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class CommunicationManager {
//this is the main create
//create a KIC terminal
public createTerminal(
term_name: string,
instrumentIp?: string,
usb_unique_string?: string,
filePath?: string
Expand All @@ -184,7 +185,6 @@ export class CommunicationManager {
if (instrumentIp != undefined) {
const parts = instrumentIp.match(CONNECTION_RE)
if (parts == null) return ""
const name = typeof parts[1] == "undefined" ? "KIC" : parts[1]
const ip_addr = parts[2]
const ip = ip_addr.split(":")[0] //take only IPv4 address, don't include socket.

Expand All @@ -210,22 +210,20 @@ export class CommunicationManager {
// })

info = this._kicProcessMgr.createKicCell(
name,
term_name,
ip,
"lan",
maxerr,
filePath
)
} else if (usb_unique_string != undefined) {
let unique_string = usb_unique_string
let name = "KIC"
const string_split = usb_unique_string.split("@")
if (string_split.length > 1) {
name = string_split[0]
unique_string = string_split[1]
}
info = this._kicProcessMgr.createKicCell(
name,
term_name,
unique_string,
"usb",
undefined,
Expand Down
29 changes: 12 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,14 @@ export async function createTerminal(
if (connection_string.split("@").length > 1) {
name = connection_string.split("@")[0]
ip = connection_string.split("@")[1]
} else {
const name_entered = await vscode.window.showInputBox({
placeHolder: "Enter friendly name to proceed",
})
if (
//ToDo: need to add a common regex for all friendly name inputs
name_entered === undefined ||
name_entered === null ||
name_entered.length === 0
) {
void vscode.window.showErrorMessage(
"Cannot proceed with empty friendly name"
)
return
} else {
name = name_entered
}
}

if (_connHelper.IPTest(ip) == false) {
//USB
//This only works if selected from Instrument discovery
if (name == "") {
name = FriendlyNameMgr.generateUniqueName(IoType.Usb, model_serial)
}
if (
!FriendlyNameMgr.checkForDuplicateFriendlyName(
IoType.Usb,
Expand All @@ -86,6 +72,7 @@ export async function createTerminal(
return
}
info = _activeConnectionManager?.createTerminal(
name,
undefined,
connection_string,
command_text
Expand All @@ -95,6 +82,12 @@ export async function createTerminal(
msn = await _connHelper.getModelAndSerialNumber(ip) //const to let
if (msn != undefined) {
model_serial_no = msn.model + "#" + msn.sn //const to let
if (name == "") {
name = FriendlyNameMgr.generateUniqueName(
IoType.Lan,
model_serial_no
)
}
if (
!FriendlyNameMgr.checkForDuplicateFriendlyName(
IoType.Lan,
Expand All @@ -113,6 +106,7 @@ export async function createTerminal(
msn.sn
)
info = _activeConnectionManager?.createTerminal(
name,
`${connection_string}:${msn.port}`,
undefined,
command_text
Expand All @@ -121,6 +115,7 @@ export async function createTerminal(
//TODO: Remove this else statement once lxi page is ready for versatest
else {
info = _activeConnectionManager?.createTerminal(
name,
connection_string,
undefined,
command_text
Expand Down
45 changes: 45 additions & 0 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ export class FriendlyNameMgr {
return handled
}

/**
* method generates unique friendly name for instrument if user
* does not provide one
*
* @param io_type - Lan, Usb etc.
* @param model_serial - model and serial number of instrument
* @returns - unique friendly name for given instrument
*/
public static generateUniqueName(
io_type: IoType,
model_serial: string | undefined
): string {
let unique_name = ""
let found = false
const connections: Array<InstrInfo> =
vscode.workspace.getConfiguration("tsp").get("savedInstruments") ??
[]

if (connections.length > 0) {
connections.forEach((instr) => {
if (
io_type === instr.io_type &&
model_serial == instr.model + "#" + instr.serial_number
) {
unique_name = instr.friendly_name
found = true
return
}
})
}

if (!found) {
const baseString = model_serial ?? "instrument"
let counter = 1
let uniqueString = baseString

while (connections.some((i) => i.friendly_name == uniqueString)) {
uniqueString = baseString + "_" + String(counter)
counter++
}
unique_name = uniqueString
}
return unique_name
}

/**
* method checks and adds/updates new friendly name
*
Expand Down
Loading