mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-24 00:35:14 +03:00
[Simulator] Fix startup when using a new file for radio data (file is now properly created, errors from Storage are ignored); Do not start simulator at all in case of data errors; Fix startup option dialog when finding radio type from profile for first time; Fix RadioOptions struct version control; Cleanup unused WinConsole code; Fix a warning and a missing const reference; Move ~SimulatedUIWidget() to public.
This commit is contained in:
parent
32dc0dd2a0
commit
fae095ea18
9 changed files with 54 additions and 52 deletions
|
@ -815,17 +815,6 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
||||||
{
|
{
|
||||||
SimulatorInterface * simulator = getCurrentSimulator();
|
SimulatorInterface * simulator = getCurrentSimulator();
|
||||||
if (simulator) {
|
if (simulator) {
|
||||||
#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO)
|
|
||||||
bool freeConsoleOnClose = false;
|
|
||||||
if (!GetConsoleWindow()) {
|
|
||||||
AllocConsole();
|
|
||||||
SetConsoleTitle("Companion Console");
|
|
||||||
freeConsoleOnClose = true;
|
|
||||||
freopen("conin$", "r", stdin);
|
|
||||||
freopen("conout$", "w", stdout);
|
|
||||||
freopen("conout$", "w", stderr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
RadioData * simuData = new RadioData(radioData);
|
RadioData * simuData = new RadioData(radioData);
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
|
@ -837,19 +826,17 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
||||||
SimulatorDialog * dialog = new SimulatorDialog(parent, simulator, flags);
|
SimulatorDialog * dialog = new SimulatorDialog(parent, simulator, flags);
|
||||||
if (IS_HORUS(getCurrentBoard()) && !dialog->useTempDataPath(true)) {
|
if (IS_HORUS(getCurrentBoard()) && !dialog->useTempDataPath(true)) {
|
||||||
QMessageBox::critical(NULL, QObject::tr("Data Load Error"), QObject::tr("Error: Could not create temporary directory in '%1'").arg(QDir::tempPath()));
|
QMessageBox::critical(NULL, QObject::tr("Data Load Error"), QObject::tr("Error: Could not create temporary directory in '%1'").arg(QDir::tempPath()));
|
||||||
|
delete dialog;
|
||||||
|
delete simuData;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dialog->setRadioData(simuData);
|
dialog->setRadioData(simuData);
|
||||||
qDebug() << __FILE__ << __LINE__ << "Starting" << getCurrentFirmware()->getName() << "simulation with SD path" << dialog->getSdPath() << "and models/settings path" << dialog->getDataPath();
|
qDebug() << __FILE__ << __LINE__ << "Starting" << getCurrentFirmware()->getName() << "simulation with SD path" << dialog->getSdPath() << "and models/settings path" << dialog->getDataPath();
|
||||||
dialog->start();
|
dialog->start();
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
dialog->deleteLater();
|
delete dialog;
|
||||||
// TODO Horus tmp directory is deleted on simulator close OR we could use it to get back data from the simulation
|
// TODO Horus tmp directory is deleted on simulator close OR we could use it to get back data from the simulation
|
||||||
delete simuData; // TODO same with simuData, could read it back and update the file data
|
delete simuData; // TODO same with simuData, could read it back and update the file data
|
||||||
#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO)
|
|
||||||
if (freeConsoleOnClose)
|
|
||||||
FreeConsole();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
|
|
|
@ -46,10 +46,11 @@ class SimulatedUIWidget : public QWidget
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
explicit SimulatedUIWidget(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
|
explicit SimulatedUIWidget(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
|
||||||
~SimulatedUIWidget();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
~SimulatedUIWidget();
|
||||||
|
|
||||||
RadioUiAction * addRadioUiAction(RadioUiAction * act);
|
RadioUiAction * addRadioUiAction(RadioUiAction * act);
|
||||||
RadioUiAction * addRadioUiAction(int index = -1, int key = 0, const QString &text = "", const QString &descript = "");
|
RadioUiAction * addRadioUiAction(int index = -1, int key = 0, const QString &text = "", const QString &descript = "");
|
||||||
RadioUiAction * addRadioUiAction(int index, QList<int> keys, const QString &text = "", const QString &descript = "");
|
RadioUiAction * addRadioUiAction(int index, QList<int> keys, const QString &text = "", const QString &descript = "");
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct SimulatorOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
quint16 _version = SIMULATOR_OPTIONS_VERSION; // structure definition version
|
quint16 _version; // structure definition version
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// v1 fields
|
// v1 fields
|
||||||
|
@ -60,7 +60,7 @@ struct SimulatorOptions
|
||||||
|
|
||||||
friend QDataStream & operator << (QDataStream &out, const SimulatorOptions & o)
|
friend QDataStream & operator << (QDataStream &out, const SimulatorOptions & o)
|
||||||
{
|
{
|
||||||
out << o._version << o.startupDataType << o.firmwareId << o.dataFile << o.dataFolder
|
out << quint16(SIMULATOR_OPTIONS_VERSION) << o.startupDataType << o.firmwareId << o.dataFile << o.dataFolder
|
||||||
<< o.sdPath << o.windowGeometry << o.controlsState << o.lcdColor;
|
<< o.sdPath << o.windowGeometry << o.controlsState << o.lcdColor;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ void SimulatorDialog::setRadioSettings(const GeneralSettings settings)
|
||||||
* with the same data when start() is called.
|
* with the same data when start() is called.
|
||||||
* If you already have a valid RadioData structure, call setRadioData() instead.
|
* If you already have a valid RadioData structure, call setRadioData() instead.
|
||||||
*/
|
*/
|
||||||
void SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFile)
|
bool SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFile)
|
||||||
{
|
{
|
||||||
RadioData simuData;
|
RadioData simuData;
|
||||||
quint16 ret = 1;
|
quint16 ret = 1;
|
||||||
|
@ -195,13 +195,18 @@ void SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFil
|
||||||
}
|
}
|
||||||
else if (QString(dataSource).endsWith(".otx", Qt::CaseInsensitive)) {
|
else if (QString(dataSource).endsWith(".otx", Qt::CaseInsensitive)) {
|
||||||
// FIXME : Right now there's no way to read data back into the .otx file after simulation finishes.
|
// FIXME : Right now there's no way to read data back into the .otx file after simulation finishes.
|
||||||
setRadioData(&simuData);
|
return setRadioData(&simuData);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
startupData = dataSource; // save the file name for start()
|
startupData = dataSource; // save the file name for start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// again there's no way to tell what the error from Storage actually was, so if the file doesn't exist we'll create a new one
|
||||||
|
else if (!QFile(QString(dataSource)).exists()) {
|
||||||
|
startupData = dataSource;
|
||||||
|
startupFromFile = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
error = store.error();
|
error = store.error();
|
||||||
}
|
}
|
||||||
|
@ -221,43 +226,50 @@ void SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFil
|
||||||
if (error.isEmpty())
|
if (error.isEmpty())
|
||||||
error = tr("Could not load data, possibly wrong format.");
|
error = tr("Could not load data, possibly wrong format.");
|
||||||
QMessageBox::critical(this, tr("Data Load Error"), error);
|
QMessageBox::critical(this, tr("Data Load Error"), error);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
radioSettings = simuData.generalSettings;
|
radioSettings = simuData.generalSettings;
|
||||||
startupFromFile = fromFile;
|
startupFromFile = fromFile;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorDialog::setRadioData(RadioData * radioData)
|
bool SimulatorDialog::setRadioData(RadioData * radioData)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
if (radioDataPath.isEmpty()) {
|
if (radioDataPath.isEmpty()) {
|
||||||
QByteArray eeprom(getEEpromSize(m_board), 0);
|
QByteArray eeprom(getEEpromSize(m_board), 0);
|
||||||
if (firmware->getEEpromInterface()->save((uint8_t *)eeprom.data(), *radioData, 0, firmware->getCapability(SimulatorVariant)) > 0)
|
if (firmware->getEEpromInterface()->save((uint8_t *)eeprom.data(), *radioData, 0, firmware->getCapability(SimulatorVariant)) > 0)
|
||||||
setStartupData(eeprom, false);
|
ret = setStartupData(eeprom, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
saveRadioData(radioData, radioDataPath);
|
if ((ret = saveRadioData(radioData, radioDataPath)))
|
||||||
radioSettings = radioData->generalSettings;
|
radioSettings = radioData->generalSettings;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorDialog::setOptions(SimulatorOptions & options, bool withSave)
|
bool SimulatorDialog::setOptions(SimulatorOptions & options, bool withSave)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
setSdPath(options.sdPath);
|
setSdPath(options.sdPath);
|
||||||
if (options.startupDataType == SimulatorOptions::START_WITH_FOLDER && !options.dataFolder.isEmpty()) {
|
if (options.startupDataType == SimulatorOptions::START_WITH_FOLDER && !options.dataFolder.isEmpty()) {
|
||||||
setDataPath(options.dataFolder);
|
setDataPath(options.dataFolder);
|
||||||
setStartupData();
|
ret = setStartupData();
|
||||||
}
|
}
|
||||||
else if (options.startupDataType == SimulatorOptions::START_WITH_SDPATH && !options.sdPath.isEmpty()) {
|
else if (options.startupDataType == SimulatorOptions::START_WITH_SDPATH && !options.sdPath.isEmpty()) {
|
||||||
setDataPath(options.sdPath);
|
setDataPath(options.sdPath);
|
||||||
setStartupData();
|
ret = setStartupData();
|
||||||
}
|
}
|
||||||
else if (options.startupDataType == SimulatorOptions::START_WITH_FILE && !options.dataFile.isEmpty()) {
|
else if (options.startupDataType == SimulatorOptions::START_WITH_FILE && !options.dataFile.isEmpty()) {
|
||||||
setStartupData(options.dataFile.toLocal8Bit(), true);
|
ret = setStartupData(options.dataFile.toLocal8Bit(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withSave)
|
if (ret && withSave)
|
||||||
g.profile[radioProfileId].simulatorOptions(options);
|
g.profile[radioProfileId].simulatorOptions(options);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimulatorDialog::saveRadioData(RadioData * radioData, const QString & path, QString * error)
|
bool SimulatorDialog::saveRadioData(RadioData * radioData, const QString & path, QString * error)
|
||||||
|
|
|
@ -80,9 +80,9 @@ class SimulatorDialog : public QDialog
|
||||||
void setDataPath(const QString & dataPath);
|
void setDataPath(const QString & dataPath);
|
||||||
void setPaths(const QString & sdPath, const QString & dataPath);
|
void setPaths(const QString & sdPath, const QString & dataPath);
|
||||||
void setRadioSettings(const GeneralSettings settings);
|
void setRadioSettings(const GeneralSettings settings);
|
||||||
void setStartupData(const QByteArray & dataSource = NULL, bool fromFile = false);
|
bool setStartupData(const QByteArray & dataSource = NULL, bool fromFile = false);
|
||||||
void setRadioData(RadioData * radioData);
|
bool setRadioData(RadioData * radioData);
|
||||||
void setOptions(SimulatorOptions & options, bool withSave = true);
|
bool setOptions(SimulatorOptions & options, bool withSave = true);
|
||||||
bool saveRadioData(RadioData * radioData, const QString & path = "", QString * error = NULL);
|
bool saveRadioData(RadioData * radioData, const QString & path = "", QString * error = NULL);
|
||||||
bool useTempDataPath(bool deleteOnClose = true, bool saveOnClose = false);
|
bool useTempDataPath(bool deleteOnClose = true, bool saveOnClose = false);
|
||||||
bool saveTempData();
|
bool saveTempData();
|
||||||
|
|
|
@ -56,13 +56,14 @@ SimulatorStartupDialog::SimulatorStartupDialog(SimulatorOptions * options, int *
|
||||||
ui->btnSelectDataFolder->setIcon(icon);
|
ui->btnSelectDataFolder->setIcon(icon);
|
||||||
ui->btnSelectSdPath->setIcon(icon);
|
ui->btnSelectSdPath->setIcon(icon);
|
||||||
|
|
||||||
|
loadRadioProfile(*m_profileId);
|
||||||
|
|
||||||
QObject::connect(ui->radioProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(onRadioProfileChanged(int)));
|
QObject::connect(ui->radioProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(onRadioProfileChanged(int)));
|
||||||
QObject::connect(ui->radioType, SIGNAL(currentIndexChanged(int)), this, SLOT(onRadioTypeChanged(int)));
|
QObject::connect(ui->radioType, SIGNAL(currentIndexChanged(int)), this, SLOT(onRadioTypeChanged(int)));
|
||||||
QObject::connect(ui->btnSelectDataFile, &QToolButton::clicked, this, &SimulatorStartupDialog::onDataFileSelect);
|
QObject::connect(ui->btnSelectDataFile, &QToolButton::clicked, this, &SimulatorStartupDialog::onDataFileSelect);
|
||||||
QObject::connect(ui->btnSelectDataFolder, &QToolButton::clicked, this, &SimulatorStartupDialog::onDataFolderSelect);
|
QObject::connect(ui->btnSelectDataFolder, &QToolButton::clicked, this, &SimulatorStartupDialog::onDataFolderSelect);
|
||||||
QObject::connect(ui->btnSelectSdPath, &QToolButton::clicked, this, &SimulatorStartupDialog::onSdPathSelect);
|
QObject::connect(ui->btnSelectSdPath, &QToolButton::clicked, this, &SimulatorStartupDialog::onSdPathSelect);
|
||||||
|
|
||||||
loadRadioProfile(*m_profileId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulatorStartupDialog::~SimulatorStartupDialog()
|
SimulatorStartupDialog::~SimulatorStartupDialog()
|
||||||
|
@ -98,10 +99,9 @@ QString SimulatorStartupDialog::findRadioId(const QString & str)
|
||||||
QString radioId(str);
|
QString radioId(str);
|
||||||
int pos = str.indexOf("-");
|
int pos = str.indexOf("-");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
radioId = str.mid(pos+1);
|
pos = str.indexOf("-", pos + 1);
|
||||||
pos = radioId.lastIndexOf("-");
|
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
radioId = radioId.mid(0, pos);
|
radioId = str.mid(0, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return radioId;
|
return radioId;
|
||||||
|
@ -116,6 +116,9 @@ QString SimulatorStartupDialog::radioEepromFileName(const QString & firmwareId,
|
||||||
folder = g.eepromDir();
|
folder = g.eepromDir();
|
||||||
|
|
||||||
QString radioId = findRadioId(firmwareId);
|
QString radioId = findRadioId(firmwareId);
|
||||||
|
int pos = radioId.indexOf("-");
|
||||||
|
if (pos > 0)
|
||||||
|
radioId = radioId.mid(pos+1);
|
||||||
if (usesCategorizedStorage(radioId))
|
if (usesCategorizedStorage(radioId))
|
||||||
ext = "otx";
|
ext = "otx";
|
||||||
|
|
||||||
|
@ -155,10 +158,8 @@ void SimulatorStartupDialog::loadRadioProfile(int id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i = ui->radioProfile->findData(id);
|
i = ui->radioProfile->findData(id);
|
||||||
if (i > -1 && ui->radioProfile->currentIndex() != i) {
|
if (i > -1 && ui->radioProfile->currentIndex() != i)
|
||||||
ui->radioProfile->setCurrentIndex(i);
|
ui->radioProfile->setCurrentIndex(i);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*m_options = g.profile[id].simulatorOptions();
|
*m_options = g.profile[id].simulatorOptions();
|
||||||
|
|
||||||
|
@ -167,7 +168,7 @@ void SimulatorStartupDialog::loadRadioProfile(int id)
|
||||||
tmpstr = g.profile[id].fwType();
|
tmpstr = g.profile[id].fwType();
|
||||||
else if (getSimulatorFactory(tmpstr))
|
else if (getSimulatorFactory(tmpstr))
|
||||||
tmpstr = getSimulatorFactory(tmpstr)->name();
|
tmpstr = getSimulatorFactory(tmpstr)->name();
|
||||||
i = ui->radioType->findText(findRadioId(tmpstr), Qt::MatchFixedString | Qt::MatchContains);
|
i = ui->radioType->findText(findRadioId(tmpstr), Qt::MatchContains);
|
||||||
if (i > -1)
|
if (i > -1)
|
||||||
ui->radioType->setCurrentIndex(i);
|
ui->radioType->setCurrentIndex(i);
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,12 @@ class LcdWidget : public QWidget
|
||||||
memset(previousBuf, 0, lcdSize);
|
memset(previousBuf, 0, lcdSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgDefaultColor(QColor color)
|
void setBgDefaultColor(const QColor & color)
|
||||||
{
|
{
|
||||||
bgDefaultColor = color;
|
bgDefaultColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackgroundColor(QColor color)
|
void setBackgroundColor(const QColor & color)
|
||||||
{
|
{
|
||||||
bgColor = color;
|
bgColor = color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ class RadioSwitchWidget : public RadioWidget
|
||||||
|
|
||||||
void setToggleLocked(bool lock)
|
void setToggleLocked(bool lock)
|
||||||
{
|
{
|
||||||
if (m_flags != lock) {
|
if (m_flags != (quint16)lock) {
|
||||||
m_flags = lock;
|
m_flags = lock;
|
||||||
setValue((int)lock);
|
setValue((int)lock);
|
||||||
emit flagsChanged(m_flags);
|
emit flagsChanged(m_flags);
|
||||||
|
|
|
@ -273,15 +273,16 @@ int main(int argc, char *argv[])
|
||||||
g.id(profileId);
|
g.id(profileId);
|
||||||
g.simuLastProfId(profileId);
|
g.simuLastProfId(profileId);
|
||||||
|
|
||||||
|
int result = 1;
|
||||||
SimulatorDialog * dialog = new SimulatorDialog(NULL, simulator, SIMULATOR_FLAGS_STANDALONE);
|
SimulatorDialog * dialog = new SimulatorDialog(NULL, simulator, SIMULATOR_FLAGS_STANDALONE);
|
||||||
dialog->setRadioProfileId(profileId);
|
dialog->setRadioProfileId(profileId);
|
||||||
dialog->setOptions(simOptions, true);
|
if ((result = (int)dialog->setOptions(simOptions, true))) {
|
||||||
dialog->start();
|
dialog->start();
|
||||||
dialog->show();
|
dialog->show();
|
||||||
int result = app.exec();
|
result = app.exec();
|
||||||
|
}
|
||||||
g.id(oldProfId);
|
g.id(oldProfId);
|
||||||
dialog->deleteLater();
|
delete dialog;
|
||||||
delete simulator;
|
delete simulator;
|
||||||
|
|
||||||
return finish(result);
|
return finish(result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue