Actually start using bits of the decoder framework.

This commit is contained in:
David Given
2022-02-21 22:02:28 +01:00
parent c6cef191a7
commit e14030e369
10 changed files with 78 additions and 33 deletions

View File

@@ -46,8 +46,8 @@ $(error You must have these pkg-config packages installed: $(PACKAGES))
endif endif
export PROTOC = protoc export PROTOC = protoc
export CC = gcc export CC = clang
export CXX = g++ export CXX = clang++
export AR = ar rc export AR = ar rc
export RANLIB = ranlib export RANLIB = ranlib
export STRIP = strip export STRIP = strip

View File

@@ -17,7 +17,7 @@ USB::~USB() {}
static std::unique_ptr<CandidateDevice> selectDevice() static std::unique_ptr<CandidateDevice> selectDevice()
{ {
auto candidates = findUsbDevices({FLUXENGINE_ID, GREASEWEAZLE_ID}); auto candidates = findUsbDevices();
if (candidates.size() == 0) if (candidates.size() == 0)
Error() << "no devices found (is one plugged in? Do you have the " Error() << "no devices found (is one plugged in? Do you have the "
"appropriate permissions?"; "appropriate permissions?";

View File

@@ -5,8 +5,11 @@
#include "fmt/format.h" #include "fmt/format.h"
#include "usbfinder.h" #include "usbfinder.h"
#include "greaseweazle.h" #include "greaseweazle.h"
#include "protocol.h"
#include "libusbp.hpp" #include "libusbp.hpp"
static const std::set<uint32_t> VALID_DEVICES = { GREASEWEAZLE_ID, FLUXENGINE_ID };
static const std::string get_serial_number(const libusbp::device& device) static const std::string get_serial_number(const libusbp::device& device)
{ {
try try
@@ -21,8 +24,7 @@ static const std::string get_serial_number(const libusbp::device& device)
} }
} }
std::vector<std::unique_ptr<CandidateDevice>> findUsbDevices( std::vector<std::unique_ptr<CandidateDevice>> findUsbDevices()
const std::set<uint32_t>& ids)
{ {
std::vector<std::unique_ptr<CandidateDevice>> candidates; std::vector<std::unique_ptr<CandidateDevice>> candidates;
for (const auto& it : libusbp::list_connected_devices()) for (const auto& it : libusbp::list_connected_devices())
@@ -31,7 +33,7 @@ std::vector<std::unique_ptr<CandidateDevice>> findUsbDevices(
candidate->device = it; candidate->device = it;
uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id(); uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id();
if (ids.find(id) != ids.end()) if (VALID_DEVICES.find(id) != VALID_DEVICES.end())
{ {
candidate->id = id; candidate->id = id;
candidate->serial = get_serial_number(it); candidate->serial = get_serial_number(it);

View File

@@ -12,7 +12,7 @@ struct CandidateDevice
std::string serialPort; std::string serialPort;
}; };
extern std::vector<std::unique_ptr<CandidateDevice>> findUsbDevices(const std::set<uint32_t>& id); extern std::vector<std::unique_ptr<CandidateDevice>> findUsbDevices();
#endif #endif

View File

@@ -565,6 +565,7 @@ buildlibrary libfrontend.a \
buildlibrary libgui.a \ buildlibrary libgui.a \
-I$OBJDIR/proto \ -I$OBJDIR/proto \
-Idep/libusbp/include \
-d $OBJDIR/proto/libconfig.def \ -d $OBJDIR/proto/libconfig.def \
src/gui/main.cc \ src/gui/main.cc \
src/gui/layout.cpp \ src/gui/layout.cpp \

View File

@@ -53,20 +53,17 @@ MainWindowGen::MainWindowGen( wxWindow* parent, wxWindowID id, const wxString& t
m_staticText4->Wrap( -1 ); m_staticText4->Wrap( -1 );
fgSizer3->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 ); fgSizer3->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 );
wxArrayString deviceChoiceChoices; deviceCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_SORT );
deviceChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, deviceChoiceChoices, 0 ); fgSizer3->Add( deviceCombo, 0, wxALL, 5 );
deviceChoice->SetSelection( 0 );
fgSizer3->Add( deviceChoice, 0, wxALL|wxEXPAND, 5 );
m_staticText5 = new wxStaticText( this, wxID_ANY, wxT("Flux source/sink:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText5 = new wxStaticText( this, wxID_ANY, wxT("Flux source/sink:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 ); m_staticText5->Wrap( -1 );
fgSizer3->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 ); fgSizer3->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 );
wxString fluxSourceSinkChoiceChoices[] = { wxT("drive:0"), wxT("drive:1"), wxT("file") }; fluxSourceSinkCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
int fluxSourceSinkChoiceNChoices = sizeof( fluxSourceSinkChoiceChoices ) / sizeof( wxString ); fluxSourceSinkCombo->Append( wxT("drive:0") );
fluxSourceSinkChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, fluxSourceSinkChoiceNChoices, fluxSourceSinkChoiceChoices, 0 ); fluxSourceSinkCombo->Append( wxT("drive:1") );
fluxSourceSinkChoice->SetSelection( 0 ); fgSizer3->Add( fluxSourceSinkCombo, 0, wxALL|wxEXPAND, 5 );
fgSizer3->Add( fluxSourceSinkChoice, 0, wxALL|wxEXPAND, 5 );
m_staticText51 = new wxStaticText( this, wxID_ANY, wxT("Format:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText51 = new wxStaticText( this, wxID_ANY, wxT("Format:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText51->Wrap( -1 ); m_staticText51->Wrap( -1 );

View File

@@ -310,11 +310,11 @@
<property name="wrap">-1</property> <property name="wrap">-1</property>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL</property>
<property name="proportion">0</property> <property name="proportion">0</property>
<object class="wxChoice" expanded="0"> <object class="wxComboBox" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
<property name="RightDockable">1</property> <property name="RightDockable">1</property>
@@ -350,7 +350,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">deviceChoice</property> <property name="name">deviceCombo</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
@@ -358,10 +358,10 @@
<property name="pin_button">1</property> <property name="pin_button">1</property>
<property name="pos"></property> <property name="pos"></property>
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="selection">0</property> <property name="selection">-1</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
<property name="style"></property> <property name="style">wxCB_SORT</property>
<property name="subclass">; ; forward_declare</property> <property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property> <property name="toolbar_pane">0</property>
<property name="tooltip"></property> <property name="tooltip"></property>
@@ -369,6 +369,7 @@
<property name="validator_style">wxFILTER_NONE</property> <property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property> <property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property> <property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
@@ -435,11 +436,11 @@
<property name="wrap">-1</property> <property name="wrap">-1</property>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property> <property name="proportion">0</property>
<object class="wxChoice" expanded="0"> <object class="wxComboBox" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
<property name="RightDockable">1</property> <property name="RightDockable">1</property>
@@ -453,7 +454,7 @@
<property name="caption"></property> <property name="caption"></property>
<property name="caption_visible">1</property> <property name="caption_visible">1</property>
<property name="center_pane">0</property> <property name="center_pane">0</property>
<property name="choices">&quot;drive:0&quot; &quot;drive:1&quot; &quot;file&quot;</property> <property name="choices">&quot;drive:0&quot; &quot;drive:1&quot;</property>
<property name="close_button">1</property> <property name="close_button">1</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="context_menu">1</property> <property name="context_menu">1</property>
@@ -475,7 +476,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">fluxSourceSinkChoice</property> <property name="name">fluxSourceSinkCombo</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
@@ -483,7 +484,7 @@
<property name="pin_button">1</property> <property name="pin_button">1</property>
<property name="pos"></property> <property name="pos"></property>
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="selection">0</property> <property name="selection">-1</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
<property name="style"></property> <property name="style"></property>
@@ -494,6 +495,7 @@
<property name="validator_style">wxFILTER_NONE</property> <property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property> <property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property> <property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>

View File

@@ -21,6 +21,7 @@
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/stattext.h> #include <wx/stattext.h>
#include <wx/combobox.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/checkbox.h> #include <wx/checkbox.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
@@ -41,9 +42,9 @@ class MainWindowGen : public wxFrame
VisualisationControl* visualiser; VisualisationControl* visualiser;
wxButton* stopButton; wxButton* stopButton;
wxStaticText* m_staticText4; wxStaticText* m_staticText4;
wxChoice* deviceChoice; wxComboBox* deviceCombo;
wxStaticText* m_staticText5; wxStaticText* m_staticText5;
wxChoice* fluxSourceSinkChoice; wxComboBox* fluxSourceSinkCombo;
wxStaticText* m_staticText51; wxStaticText* m_staticText51;
wxChoice* formatChoice; wxChoice* formatChoice;
wxCheckBox* highDensityToggle; wxCheckBox* highDensityToggle;

View File

@@ -1,6 +1,9 @@
#include "globals.h" #include "globals.h"
#include "proto.h" #include "proto.h"
#include "gui.h" #include "gui.h"
#include "fluxsource/fluxsource.h"
#include "decoders/decoders.h"
#include "lib/usb/usbfinder.h"
#include "fmt/format.h" #include "fmt/format.h"
#include <wx/wx.h> #include <wx/wx.h>
#include "mainwindow.h" #include "mainwindow.h"
@@ -18,10 +21,14 @@ MainWindow::MainWindow(): MainWindowGen(nullptr)
continue; continue;
formatChoice->Append(it.first); formatChoice->Append(it.first);
_formats[it.first] = std::move(config); _formats.push_back(std::move(config));
} }
UpdateDevices(); UpdateDevices();
if (deviceCombo->GetCount() > 0)
deviceCombo->SetValue(deviceCombo->GetString(0));
readFluxButton->Bind(wxEVT_BUTTON, &MainWindow::OnReadFluxButton, this);
} }
void MainWindow::OnExit(wxCommandEvent& event) void MainWindow::OnExit(wxCommandEvent& event)
@@ -29,8 +36,39 @@ void MainWindow::OnExit(wxCommandEvent& event)
Close(true); Close(true);
} }
void MainWindow::UpdateDevices() void MainWindow::OnReadFluxButton(wxCommandEvent&)
{ {
//auto candidates = findUsbDevices({FLUXENGINE_ID, GREASEWEAZLE_ID}); ConfigProto config = *_formats[formatChoice->GetSelection()];
FluxSource::updateConfigForFilename(config.mutable_flux_source(),
fluxSourceSinkCombo->GetValue().ToStdString());
auto serial = deviceCombo->GetValue().ToStdString();
if (!serial.empty() && (serial[0] = '/'))
setProtoByString(&config, "usb.greaseweazle.port", serial);
else
setProtoByString(&config, "usb.serial", serial);
runOnWorkerThread(
/* Must make another copy of all local parameters. */
[=]() {
auto fluxSource = FluxSource::create(config.flux_source());
auto decoder = AbstractDecoder::create(config.decoder());
printf("Worker thread!\n");
}
);
}
void MainWindow::UpdateDevices()
{
auto candidates = findUsbDevices();
deviceCombo->Clear();
_devices.clear();
for (auto& candidate : candidates)
{
deviceCombo->Append(candidate->serial);
_devices.push_back(std::move(candidate));
}
} }

View File

@@ -3,7 +3,9 @@
#include "layout.h" #include "layout.h"
class CandidateDevice;
class ConfigProto; class ConfigProto;
class MainWindow : public MainWindowGen class MainWindow : public MainWindowGen
{ {
public: public:
@@ -11,11 +13,13 @@ public:
private: private:
void OnExit(wxCommandEvent& event); void OnExit(wxCommandEvent& event);
void OnReadFluxButton(wxCommandEvent&);
void UpdateDevices(); void UpdateDevices();
private: private:
std::map<std::string, std::unique_ptr<ConfigProto>> _formats; std::vector<std::unique_ptr<ConfigProto>> _formats;
std::vector<std::unique_ptr<CandidateDevice>> _devices;
}; };
#endif #endif