mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
You can now load images into memory.
This commit is contained in:
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
public:
|
||||
const_iterator(const wrapped_iterator_t& it): _it(it) {}
|
||||
const Sector* operator* () { return _it->second.get(); }
|
||||
std::shared_ptr<const Sector> operator* () { return _it->second; }
|
||||
void operator++ () { _it++; }
|
||||
bool operator== (const const_iterator& other) const { return _it == other._it; }
|
||||
bool operator!= (const const_iterator& other) const { return _it != other._it; }
|
||||
|
||||
10
lib/logger.h
10
lib/logger.h
@@ -8,9 +8,15 @@ class TrackDataFlux;
|
||||
class TrackFlux;
|
||||
class Sector;
|
||||
|
||||
struct ErrorLogMessage
|
||||
{
|
||||
std::string message;
|
||||
};
|
||||
|
||||
struct BeginSpeedOperationLogMessage
|
||||
{
|
||||
};
|
||||
|
||||
struct EndSpeedOperationLogMessage
|
||||
{
|
||||
nanoseconds_t rotationalPeriod;
|
||||
@@ -50,7 +56,9 @@ struct EndWriteOperationLogMessage
|
||||
|
||||
class TrackFlux;
|
||||
|
||||
typedef std::variant<std::string,
|
||||
typedef std::variant<
|
||||
std::string,
|
||||
ErrorLogMessage,
|
||||
TrackReadLogMessage,
|
||||
DiskReadLogMessage,
|
||||
BeginSpeedOperationLogMessage,
|
||||
|
||||
@@ -59,7 +59,7 @@ wxThread::ExitCode FluxEngineApp::Entry()
|
||||
}
|
||||
catch (const ErrorException& e)
|
||||
{
|
||||
Logger() << (e.message + '\n');
|
||||
Logger() << ErrorLogMessage { e.message+'\n' };
|
||||
}
|
||||
catch (const EmergencyStopException& e)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "logger.h"
|
||||
#include "reader.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "decoders/decoders.h"
|
||||
#include "lib/usb/usbfinder.h"
|
||||
#include "fmt/format.h"
|
||||
@@ -44,6 +45,7 @@ MainWindow::MainWindow(): MainWindowGen(nullptr)
|
||||
fluxSourceSinkCombo->SetValue(fluxSourceSinkCombo->GetString(0));
|
||||
|
||||
readFluxButton->Bind(wxEVT_BUTTON, &MainWindow::OnReadFluxButton, this);
|
||||
readImageButton->Bind(wxEVT_BUTTON, &MainWindow::OnReadImageButton, this);
|
||||
stopButton->Bind(wxEVT_BUTTON, &MainWindow::OnStopButton, this);
|
||||
|
||||
UpdateState();
|
||||
@@ -63,33 +65,11 @@ void MainWindow::OnReadFluxButton(wxCommandEvent&)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto formatSelection = formatChoice->GetSelection();
|
||||
if (formatSelection == wxNOT_FOUND)
|
||||
Error() << "no format selected";
|
||||
|
||||
ConfigProto config = *_formats[formatChoice->GetSelection()];
|
||||
ConfigProto config = PrepareConfig();
|
||||
|
||||
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;
|
||||
@@ -110,6 +90,74 @@ void MainWindow::OnReadFluxButton(wxCommandEvent&)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnReadImageButton(wxCommandEvent&)
|
||||
{
|
||||
auto filename = wxFileSelector("Choose a file to open");
|
||||
if (filename.empty())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
ConfigProto config = PrepareConfig();
|
||||
if (!config.has_image_reader())
|
||||
Error() << "This format is read-only.";
|
||||
|
||||
ImageReader::updateConfigForFilename(
|
||||
config.mutable_image_reader(), filename.ToStdString());
|
||||
|
||||
runOnWorkerThread(
|
||||
[config, this]() {
|
||||
::config = config;
|
||||
auto imageReader = ImageReader::create(config.image_reader());
|
||||
std::unique_ptr<const Image> image = imageReader->readImage();
|
||||
runOnUiThread(
|
||||
[&]() {
|
||||
auto disk = std::make_shared<DiskFlux>();
|
||||
disk = std::make_shared<DiskFlux>();
|
||||
disk->image = std::move(image);
|
||||
_currentDisk = disk;
|
||||
visualiser->SetDiskData(_currentDisk);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (const ErrorException& e)
|
||||
{
|
||||
wxMessageBox(e.message, "Error", wxOK | wxICON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigProto MainWindow::PrepareConfig()
|
||||
{
|
||||
auto formatSelection = formatChoice->GetSelection();
|
||||
if (formatSelection == wxNOT_FOUND)
|
||||
Error() << "no format selected";
|
||||
|
||||
ConfigProto config = *_formats[formatChoice->GetSelection()];
|
||||
|
||||
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;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void MainWindow::ApplyCustomSettings(ConfigProto& config)
|
||||
{
|
||||
for (int i=0; i < additionalSettingsEntry->GetNumberOfLines(); i++)
|
||||
@@ -143,6 +191,12 @@ void MainWindow::OnLogMessage(std::shared_ptr<const AnyLogMessage> message)
|
||||
{
|
||||
},
|
||||
|
||||
/* A fatal error. */
|
||||
[&](const ErrorLogMessage& m)
|
||||
{
|
||||
wxMessageBox(m.message, "Error", wxOK | wxICON_ERROR);
|
||||
},
|
||||
|
||||
/* Indicates that we're starting a write operation. */
|
||||
[&](const BeginWriteOperationLogMessage& m)
|
||||
{
|
||||
|
||||
@@ -17,11 +17,13 @@ private:
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnStopButton(wxCommandEvent&);
|
||||
void OnReadFluxButton(wxCommandEvent&);
|
||||
void OnReadImageButton(wxCommandEvent&);
|
||||
void OnLogMessage(std::shared_ptr<const AnyLogMessage> message);
|
||||
|
||||
public:
|
||||
void UpdateState();
|
||||
void UpdateDevices();
|
||||
ConfigProto PrepareConfig();
|
||||
void ApplyCustomSettings(ConfigProto& config);
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "fluxmap.h"
|
||||
#include "flux.h"
|
||||
#include "sector.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
#define BORDER 20
|
||||
@@ -164,5 +165,12 @@ void VisualisationControl::SetTrackData(std::shared_ptr<const TrackFlux> track)
|
||||
|
||||
void VisualisationControl::SetDiskData(std::shared_ptr<const DiskFlux> disk)
|
||||
{
|
||||
_sectors.clear();
|
||||
for (const auto& sector : *(disk->image))
|
||||
{
|
||||
key_t key = {sector->physicalCylinder, sector->physicalHead};
|
||||
_sectors.insert({key, sector});
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user