diff --git a/lib b/lib index aaa5296f..c4d7c904 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit aaa5296f177cc12f2a7ae622bc3f3c3064baae0b +Subproject commit c4d7c9047dd335da3ca6caebb625c3e2f00730af diff --git a/src/ngscopeclient/AddInstrumentDialog.cpp b/src/ngscopeclient/AddInstrumentDialog.cpp index b2893deb..99d8ab59 100644 --- a/src/ngscopeclient/AddInstrumentDialog.cpp +++ b/src/ngscopeclient/AddInstrumentDialog.cpp @@ -54,12 +54,14 @@ AddInstrumentDialog::AddInstrumentDialog( : Dialog( title, string("AddInstrument") + to_string_hex(reinterpret_cast(this)), - ImVec2(600, 180), + ImVec2(600, 200), session, parent) , m_nickname(nickname) , m_selectedDriver(0) , m_selectedTransport(0) + , m_selectedTransportType(SCPITransportType::TRANSPORT_HID) + , m_selectedEndpoint(0) , m_selectedModel(0) , m_path(path) { @@ -199,6 +201,19 @@ bool AddInstrumentDialog::DoRender() else if(dropdownOpen) //suppress further bubbles if dropdown is active showedBubble = true; + if(!m_endpoints.empty()) + { // Endpoint discovery available: create endpoint combo + if(Combo("Endpoint", m_endpointNames, m_selectedEndpoint, &dropdownOpen)) + { + UpdatePath(); + } + HelpMarker("Select the transport endpoint from the list and/or edit the path manually."); + ImGui::SameLine(); + if(ImGui::Button("⟳")) + { + UpdateCombos(); + } + } if(ImGui::InputText("Path", &m_path)) m_pathEdited = !(m_path.empty() || (m_path == m_defaultPath)); HelpMarker( @@ -282,11 +297,27 @@ bool AddInstrumentDialog::DoConnect(SCPITransport* transport) return m_session->CreateAndAddInstrument(m_drivers[m_selectedDriver], transport, m_nickname); } +void AddInstrumentDialog::UpdatePath() +{ + if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID) + { // Special handling for HID transport: replace the whole path with endpoint value + m_path = m_endpoints[m_selectedEndpoint].path; + } + else + { + size_t pos = m_path.find(':'); + string suffix = (pos == std::string::npos) ? "" : m_path.substr(pos); + m_path = m_endpoints[m_selectedEndpoint].path + suffix; + } +} + void AddInstrumentDialog::UpdateCombos() { // Update transoport list according to selected driver an connection string according to transport string driver = m_drivers[m_selectedDriver]; auto supportedModels = SCPIInstrument::GetSupportedModels(driver); + m_endpoints.clear(); + m_endpointNames.clear(); if(!supportedModels.empty()) { m_models.clear(); @@ -315,13 +346,19 @@ void AddInstrumentDialog::UpdateCombos() for(auto transport : selectedModel.supportedTransports) { string transportName = to_string(transport.transportType); + // Prepare transport type for default value + if(transportIndex == 0) m_selectedTransportType = transport.transportType; if(m_supportedTransports.find(transportName) != m_supportedTransports.end()) { m_transports.push_back(transportName); - if(transportIndex == m_selectedTransport && !m_pathEdited) + if(transportIndex == m_selectedTransport) { - m_path = transport.connectionString; - m_defaultPath = m_path; + m_selectedTransportType = transport.transportType; + if(!m_pathEdited) + { + m_path = transport.connectionString; + m_defaultPath = m_path; + } } transportIndex++; } @@ -332,6 +369,25 @@ void AddInstrumentDialog::UpdateCombos() if(!m_pathEdited) m_path = ""; } + // Update endpoint list + auto endpoints = SCPITransport::EnumEndpoints(m_transports[m_selectedTransport]); + int endpointIndex = 0; + for(auto endpoint : endpoints) + { + m_endpoints.push_back(endpoint); + m_endpointNames.push_back(endpoint.path + " ("+ endpoint.description +")"); + if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID && (endpoint.path.rfind(m_path) == 0)) + { // Special handling for HID : select the endpoint matching the path provided by the driver + m_selectedEndpoint = endpointIndex; + } + endpointIndex++; + } + if(m_selectedEndpoint >= (int)m_endpoints.size()) + { + m_selectedEndpoint = 0; + } + if(m_endpoints.size()>0) + UpdatePath(); } else { // Supported transports not provided => add all transports diff --git a/src/ngscopeclient/AddInstrumentDialog.h b/src/ngscopeclient/AddInstrumentDialog.h index 10cddc6a..dcd900e7 100644 --- a/src/ngscopeclient/AddInstrumentDialog.h +++ b/src/ngscopeclient/AddInstrumentDialog.h @@ -61,6 +61,9 @@ class AddInstrumentDialog : public Dialog virtual bool DoConnect(SCPITransport* transport); void UpdateCombos(); + + void UpdatePath(); + //GUI widget values std::string m_nickname; std::string m_originalNickname; @@ -69,7 +72,11 @@ class AddInstrumentDialog : public Dialog int m_selectedDriver; std::vector m_drivers; int m_selectedTransport; + SCPITransportType m_selectedTransportType; std::vector m_transports; + int m_selectedEndpoint; + std::vector m_endpoints; + std::vector m_endpointNames; int m_selectedModel; std::vector m_models; std::unordered_set m_supportedTransports;