mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Errors are now caught.
This commit is contained in:
@@ -31,13 +31,22 @@ extern double getCurrentTime();
|
||||
extern void hexdump(std::ostream& stream, const Bytes& bytes);
|
||||
extern void hexdumpForSrp16(std::ostream& stream, const Bytes& bytes);
|
||||
|
||||
struct ErrorException
|
||||
{
|
||||
const std::string message;
|
||||
};
|
||||
|
||||
class Error
|
||||
{
|
||||
public:
|
||||
[[ noreturn ]] ~Error()
|
||||
Error()
|
||||
{
|
||||
_stream << "Error: ";
|
||||
}
|
||||
|
||||
[[ noreturn ]] ~Error() noexcept(false)
|
||||
{
|
||||
std::cerr << "Error: " << _stream.str() << std::endl;
|
||||
exit(1);
|
||||
throw ErrorException { _stream.str() };
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -141,7 +141,17 @@ int main(int argc, const char* argv[])
|
||||
for (Command& c : commands)
|
||||
{
|
||||
if (command == c.name)
|
||||
return c.main(argc-1, argv+1);
|
||||
{
|
||||
try
|
||||
{
|
||||
return c.main(argc-1, argv+1);
|
||||
}
|
||||
catch (const ErrorException& e)
|
||||
{
|
||||
std::cerr << e.message << '\n';
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "fluxengine: unrecognised command (try --help)\n";
|
||||
|
||||
@@ -57,6 +57,10 @@ wxThread::ExitCode FluxEngineApp::Entry()
|
||||
if (_callback)
|
||||
_callback();
|
||||
}
|
||||
catch (const ErrorException& e)
|
||||
{
|
||||
Logger() << (e.message + '\n');
|
||||
}
|
||||
catch (const EmergencyStopException& e)
|
||||
{
|
||||
Logger() << "Emergency stop!\n";
|
||||
|
||||
@@ -61,42 +61,53 @@ void MainWindow::OnStopButton(wxCommandEvent&)
|
||||
|
||||
void MainWindow::OnReadFluxButton(wxCommandEvent&)
|
||||
{
|
||||
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);
|
||||
|
||||
ApplyCustomSettings(config);
|
||||
|
||||
try
|
||||
{
|
||||
std::string s;
|
||||
google::protobuf::TextFormat::PrintToString(config, &s);
|
||||
protoConfigEntry->Clear();
|
||||
protoConfigEntry->AppendText(s);
|
||||
}
|
||||
auto formatSelection = formatChoice->GetSelection();
|
||||
if (formatSelection == wxNOT_FOUND)
|
||||
Error() << "no format selected";
|
||||
|
||||
visualiser->Clear();
|
||||
logEntry->Clear();
|
||||
_currentDisk = nullptr;
|
||||
runOnWorkerThread(
|
||||
[config, this]() {
|
||||
::config = config;
|
||||
auto fluxSource = FluxSource::create(config.flux_source());
|
||||
auto decoder = AbstractDecoder::create(config.decoder());
|
||||
auto diskflux = readDiskCommand(*fluxSource, *decoder);
|
||||
runOnUiThread(
|
||||
[&]() {
|
||||
visualiser->SetDiskData(diskflux);
|
||||
}
|
||||
);
|
||||
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);
|
||||
|
||||
ApplyCustomSettings(config);
|
||||
|
||||
{
|
||||
std::string s;
|
||||
google::protobuf::TextFormat::PrintToString(config, &s);
|
||||
protoConfigEntry->Clear();
|
||||
protoConfigEntry->AppendText(s);
|
||||
}
|
||||
);
|
||||
|
||||
visualiser->Clear();
|
||||
logEntry->Clear();
|
||||
_currentDisk = nullptr;
|
||||
runOnWorkerThread(
|
||||
[config, this]() {
|
||||
::config = config;
|
||||
auto fluxSource = FluxSource::create(config.flux_source());
|
||||
auto decoder = AbstractDecoder::create(config.decoder());
|
||||
auto diskflux = readDiskCommand(*fluxSource, *decoder);
|
||||
runOnUiThread(
|
||||
[&]() {
|
||||
visualiser->SetDiskData(diskflux);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (const ErrorException& e)
|
||||
{
|
||||
wxMessageBox(e.message, "Error", wxOK | wxICON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::ApplyCustomSettings(ConfigProto& config)
|
||||
|
||||
Reference in New Issue
Block a user