Skip to content

Commit 28f73e8

Browse files
committed
Merge branch 'enumerate-transport-endpoints' of github.com:fredzo/scopehal-apps into fredzo-enumerate-transport-endpoints
2 parents 7053e9e + ef2d219 commit 28f73e8

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

src/ngscopeclient/AddInstrumentDialog.cpp

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ AddInstrumentDialog::AddInstrumentDialog(
5454
: Dialog(
5555
title,
5656
string("AddInstrument") + to_string_hex(reinterpret_cast<uintptr_t>(this)),
57-
ImVec2(600, 180),
57+
ImVec2(600, 200),
5858
session,
5959
parent)
6060
, m_nickname(nickname)
6161
, m_selectedDriver(0)
6262
, m_selectedTransport(0)
63+
, m_selectedTransportType(SCPITransportType::TRANSPORT_HID)
64+
, m_selectedEndpoint(0)
6365
, m_selectedModel(0)
6466
, m_path(path)
6567
{
@@ -199,6 +201,19 @@ bool AddInstrumentDialog::DoRender()
199201
else if(dropdownOpen) //suppress further bubbles if dropdown is active
200202
showedBubble = true;
201203

204+
if(!m_endpoints.empty())
205+
{ // Endpoint discovery available: create endpoint combo
206+
if(Combo("Endpoint", m_endpointNames, m_selectedEndpoint, &dropdownOpen))
207+
{
208+
UpdatePath();
209+
}
210+
HelpMarker("Select the transport endpoint from the list and/or edit the path manually.");
211+
ImGui::SameLine();
212+
if(ImGui::Button(""))
213+
{
214+
UpdateCombos();
215+
}
216+
}
202217
if(ImGui::InputText("Path", &m_path))
203218
m_pathEdited = !(m_path.empty() || (m_path == m_defaultPath));
204219
HelpMarker(
@@ -282,11 +297,27 @@ bool AddInstrumentDialog::DoConnect(SCPITransport* transport)
282297
return m_session->CreateAndAddInstrument(m_drivers[m_selectedDriver], transport, m_nickname);
283298
}
284299

300+
void AddInstrumentDialog::UpdatePath()
301+
{
302+
if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID)
303+
{ // Special handling for HID transport: replace the whole path with endpoint value
304+
m_path = m_endpoints[m_selectedEndpoint].path;
305+
}
306+
else
307+
{
308+
size_t pos = m_path.find(':');
309+
string suffix = (pos == std::string::npos) ? "" : m_path.substr(pos);
310+
m_path = m_endpoints[m_selectedEndpoint].path + suffix;
311+
}
312+
}
313+
285314
void AddInstrumentDialog::UpdateCombos()
286315
{
287316
// Update transoport list according to selected driver an connection string according to transport
288317
string driver = m_drivers[m_selectedDriver];
289318
auto supportedModels = SCPIInstrument::GetSupportedModels(driver);
319+
m_endpoints.clear();
320+
m_endpointNames.clear();
290321
if(!supportedModels.empty())
291322
{
292323
m_models.clear();
@@ -315,13 +346,19 @@ void AddInstrumentDialog::UpdateCombos()
315346
for(auto transport : selectedModel.supportedTransports)
316347
{
317348
string transportName = to_string(transport.transportType);
349+
// Prepare transport type for default value
350+
if(transportIndex == 0) m_selectedTransportType = transport.transportType;
318351
if(m_supportedTransports.find(transportName) != m_supportedTransports.end())
319352
{
320353
m_transports.push_back(transportName);
321-
if(transportIndex == m_selectedTransport && !m_pathEdited)
354+
if(transportIndex == m_selectedTransport)
322355
{
323-
m_path = transport.connectionString;
324-
m_defaultPath = m_path;
356+
m_selectedTransportType = transport.transportType;
357+
if(!m_pathEdited)
358+
{
359+
m_path = transport.connectionString;
360+
m_defaultPath = m_path;
361+
}
325362
}
326363
transportIndex++;
327364
}
@@ -332,6 +369,25 @@ void AddInstrumentDialog::UpdateCombos()
332369
if(!m_pathEdited)
333370
m_path = "";
334371
}
372+
// Update endpoint list
373+
auto endpoints = SCPITransport::EnumEndpoints(m_transports[m_selectedTransport]);
374+
int endpointIndex = 0;
375+
for(auto endpoint : endpoints)
376+
{
377+
m_endpoints.push_back(endpoint);
378+
m_endpointNames.push_back(endpoint.path + " ("+ endpoint.description +")");
379+
if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID && (endpoint.path.rfind(m_path) == 0))
380+
{ // Special handling for HID : select the endpoint matching the path provided by the driver
381+
m_selectedEndpoint = endpointIndex;
382+
}
383+
endpointIndex++;
384+
}
385+
if(m_selectedEndpoint >= (int)m_endpoints.size())
386+
{
387+
m_selectedEndpoint = 0;
388+
}
389+
if(m_endpoints.size()>0)
390+
UpdatePath();
335391
}
336392
else
337393
{ // Supported transports not provided => add all transports

src/ngscopeclient/AddInstrumentDialog.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class AddInstrumentDialog : public Dialog
6161
virtual bool DoConnect(SCPITransport* transport);
6262

6363
void UpdateCombos();
64+
65+
void UpdatePath();
66+
6467
//GUI widget values
6568
std::string m_nickname;
6669
std::string m_originalNickname;
@@ -69,7 +72,11 @@ class AddInstrumentDialog : public Dialog
6972
int m_selectedDriver;
7073
std::vector<std::string> m_drivers;
7174
int m_selectedTransport;
75+
SCPITransportType m_selectedTransportType;
7276
std::vector<std::string> m_transports;
77+
int m_selectedEndpoint;
78+
std::vector<TransportEndpoint> m_endpoints;
79+
std::vector<std::string> m_endpointNames;
7380
int m_selectedModel;
7481
std::vector<std::string> m_models;
7582
std::unordered_set<std::string> m_supportedTransports;

0 commit comments

Comments
 (0)