Companion can now read and write Firmware in massstorage mode. Big code

refactoring (code was duplicated in many locations) around read/write
firmware/eeprom/backups, who could do some more tests before next
release? Thanks in advance!
This commit is contained in:
bsongis
2014-05-31 16:22:45 +02:00
parent a02cdca62c
commit 72dc69086c
4 changed files with 268 additions and 334 deletions
+26 -25
View File
@@ -133,39 +133,40 @@ BOOL KillProcessByName(char *szProcessToKill){
void avrOutputDialog::doCopy() void avrOutputDialog::doCopy()
{ {
hasErrors=false; char buf[BLKSIZE];
char buf[READBUF];
char * pointer=buf;
QFile source(sourceFile); QFile source(sourceFile);
int blocks=(source.size()/BLKSIZE); int blocks = (source.size() + BLKSIZE - 1) / BLKSIZE;
ui->progressBar->setMaximum(blocks-1); ui->progressBar->setMaximum(blocks-1);
if (!source.open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, tr("Error"),tr("Cannot open source file")); if (source.open(QIODevice::ReadOnly)) {
hasErrors=true;
}
else {
source.read(buf,READBUF);
source.close();
QFile dest(destFile); QFile dest(destFile);
if (!dest.open(QIODevice::WriteOnly)) { if (dest.open(QIODevice::WriteOnly)) {
QMessageBox::warning(this, tr("Error"),tr("Cannot write destination")); for (int i=0; i<blocks; i++) {
hasErrors=true; addText(tr("Writing file: "));
} else { int read = source.read(buf, BLKSIZE);
addText(tr("Writing file: ")); if (dest.write(buf, read) == read) {
for (int i=0;i<blocks;i++) { dest.flush();
if (dest.write(pointer,BLKSIZE)!=BLKSIZE) { ui->progressBar->setValue(i);
hasErrors=true; if ((i%2) != 0)
addText("#");
}
else {
QMessageBox::warning(this, tr("Error"), tr("Write error"));
break; break;
}; }
dest.flush();
pointer+=BLKSIZE;
ui->progressBar->setValue(i);
if ((i%2)!=0)
addText("#");
} }
dest.close(); dest.close();
} }
else {
QMessageBox::warning(this, tr("Error"),tr("Cannot write destination"));
}
} }
else {
QMessageBox::warning(this, tr("Error"),tr("Cannot open source file"));
}
source.close();
doFinished(0); doFinished(0);
} }
+225 -233
View File
@@ -834,10 +834,12 @@ QStringList MainWindow::GetReceiveEEpromCommand(const QString &filename)
QStringList ret; QStringList ret;
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
// return NULL; // to be implemented // impossible
} else if (IS_SKY9X(eepromInterface->getBoard())) { }
else if (IS_SKY9X(eepromInterface->getBoard())) {
ret=GetSambaArguments(QString("SERIALFLASH::Init 0\n") + "receive_file {SerialFlash AT25} \"" + filename + "\" 0x0 0x80000 0\n"); ret=GetSambaArguments(QString("SERIALFLASH::Init 0\n") + "receive_file {SerialFlash AT25} \"" + filename + "\" 0x0 0x80000 0\n");
} else { }
else {
ret=GetAvrdudeArguments("eeprom:r:", filename); ret=GetAvrdudeArguments("eeprom:r:", filename);
} }
return ret; return ret;
@@ -848,10 +850,12 @@ QStringList MainWindow::GetSendEEpromCommand(const QString &filename)
QStringList ret; QStringList ret;
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
// return NULL; // to be implemented // impossible
} else if (IS_SKY9X(eepromInterface->getBoard())) { }
else if (IS_SKY9X(eepromInterface->getBoard())) {
ret=GetSambaArguments(QString("SERIALFLASH::Init 0\n") + "send_file {SerialFlash AT25} \"" + filename + "\" 0x0 0\n"); ret=GetSambaArguments(QString("SERIALFLASH::Init 0\n") + "send_file {SerialFlash AT25} \"" + filename + "\" 0x0 0\n");
} else { }
else {
ret=GetAvrdudeArguments("eeprom:w:", filename); ret=GetAvrdudeArguments("eeprom:w:", filename);
} }
return ret; return ret;
@@ -863,11 +867,14 @@ QStringList MainWindow::GetSendFlashCommand(const QString &filename)
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
ret=GetDFUUtilArguments("-D", filename); ret=GetDFUUtilArguments("-D", filename);
} else if (eepromInterface->getBoard() == BOARD_SKY9X) { }
else if (eepromInterface->getBoard() == BOARD_SKY9X) {
ret=GetSambaArguments(QString("send_file {Flash} \"") + filename + "\" 0x400000 0\n" + "FLASH::ScriptGPNMV 2\n"); ret=GetSambaArguments(QString("send_file {Flash} \"") + filename + "\" 0x400000 0\n" + "FLASH::ScriptGPNMV 2\n");
} else if (eepromInterface->getBoard() == BOARD_9XRPRO) { }
else if (eepromInterface->getBoard() == BOARD_9XRPRO) {
ret=GetSambaArguments(QString("send_file {Flash} \"") + filename + "\" 0x400000 0\n" + "FLASH::ScriptGPNMV 2\n"); ret=GetSambaArguments(QString("send_file {Flash} \"") + filename + "\" 0x400000 0\n" + "FLASH::ScriptGPNMV 2\n");
} else { }
else {
ret=GetAvrdudeArguments("flash:w:", filename); ret=GetAvrdudeArguments("flash:w:", filename);
} }
return ret; return ret;
@@ -878,19 +885,20 @@ QStringList MainWindow::GetReceiveFlashCommand(const QString &filename)
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
return GetDFUUtilArguments("-U", filename); return GetDFUUtilArguments("-U", filename);
} else if (eepromInterface->getBoard() == BOARD_SKY9X) { }
else if (eepromInterface->getBoard() == BOARD_SKY9X) {
return GetSambaArguments(QString("receive_file {Flash} \"") + filename + "\" 0x400000 0x40000 0\n"); return GetSambaArguments(QString("receive_file {Flash} \"") + filename + "\" 0x400000 0x40000 0\n");
} else if (eepromInterface->getBoard() == BOARD_9XRPRO) { }
else if (eepromInterface->getBoard() == BOARD_9XRPRO) {
return GetSambaArguments(QString("receive_file {Flash} \"") + filename + "\" 0x400000 0x80000 0\n"); return GetSambaArguments(QString("receive_file {Flash} \"") + filename + "\" 0x400000 0x80000 0\n");
} else { }
else {
return GetAvrdudeArguments("flash:r:", filename); return GetAvrdudeArguments("flash:r:", filename);
} }
} }
QString MainWindow::FindTaranisPath() QString MainWindow::FindMassstoragePath(QString filename)
{ {
int pathcount=0;
QString path;
QString temppath; QString temppath;
QStringList drives; QStringList drives;
QString eepromfile; QString eepromfile;
@@ -904,66 +912,40 @@ QString MainWindow::FindTaranisPath()
DWORD dwFileSystemFlags=0; DWORD dwFileSystemFlags=0;
bool ret = GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256); bool ret = GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256);
if(ret) { if(ret) {
QString vName=QString::fromUtf16 ( (const ushort *) szVolumeName) ; QString vName = QString::fromUtf16 ( (const ushort *) szVolumeName) ;
if (vName.contains("TARANIS")) { if (vName.contains("TARANIS")) {
temppath=drive.absolutePath(); temppath = drive.absolutePath();
eepromfile=temppath; eepromfile = temppath;
eepromfile.append("/EEPROM.BIN"); eepromfile.append("/" + filename);
if (QFile::exists(eepromfile)) { if (QFile::exists(eepromfile)) {
pathcount++; return eepromfile;
path=eepromfile;
}
else {
eepromfile=temppath;
eepromfile.append("/TARANIS.BIN");
if (QFile::exists(eepromfile)) {
pathcount++;
path=eepromfile;
}
} }
} }
} }
} }
#else #else
struct mount_entry *entry; struct mount_entry *entry;
entry = read_file_system_list(true); entry = read_file_system_list(true);
while (entry != NULL) { while (entry != NULL) {
if (!drives.contains(entry->me_devname)) { if (!drives.contains(entry->me_devname)) {
drives.append(entry->me_devname); drives.append(entry->me_devname);
temppath=entry->me_mountdir; temppath = entry->me_mountdir;
eepromfile=temppath; eepromfile = temppath;
eepromfile.append("/EEPROM.BIN"); eepromfile.append("/" + filename);
#if !defined __APPLE__ && !defined WIN32 #if !defined __APPLE__
QString fstype = entry->me_type; QString fstype = entry->me_type;
if (QFile::exists(eepromfile) && fstype.contains("fat") ) { if (QFile::exists(eepromfile) && fstype.contains("fat") ) {
#else #else
if (QFile::exists(eepromfile)) { if (QFile::exists(eepromfile)) {
#endif #endif
pathcount++; return eepromfile;
path=eepromfile;
}
else {
eepromfile=temppath;
eepromfile.append("/TARANIS.BIN");
#if !defined __APPLE__ && !defined WIN32
QString fstype = entry->me_type;
if (QFile::exists(eepromfile) && fstype.contains("fat") ) {
#else
if (QFile::exists(eepromfile)) {
#endif
pathcount++;
path=eepromfile;
}
} }
} }
entry = entry->me_next; ; entry = entry->me_next;
} }
#endif #endif
if (pathcount==1) {
return path; return QString();
} else {
return "";
}
} }
@@ -971,37 +953,15 @@ void MainWindow::readEeprom()
{ {
QString tempDir = QDir::tempPath(); QString tempDir = QDir::tempPath();
QString tempFile; QString tempFile;
int res=0;
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_ARM(eepromInterface->getBoard())) if (IS_ARM(eepromInterface->getBoard()))
tempFile = tempDir + "/temp.bin"; tempFile = tempDir + "/temp.bin";
else else
tempFile = tempDir + "/temp.hex"; tempFile = tempDir + "/temp.hex";
if (QFile::exists(tempFile)) {
unlink(tempFile.toAscii());
}
if (IS_TARANIS(eepromInterface->getBoard())) { if (readEepromFromRadio(tempFile, tr("Read Models and Settings From Radio"))) {
QString path=FindTaranisPath();
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
res=false;
} else {
QStringList str;
str << path << tempFile;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Read Models and Settings From Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
res = ad->exec();
sleep(1);
}
} else {
QStringList str = GetReceiveEEpromCommand(tempFile);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
res = ad->exec();
}
if (QFileInfo(tempFile).exists() && res) {
MdiChild *child = createMdiChild(); MdiChild *child = createMdiChild();
child->newFile(); child->newFile();
child->loadFile(tempFile, false); child->loadFile(tempFile, false);
@@ -1009,6 +969,152 @@ void MainWindow::readEeprom()
} }
} }
bool MainWindow::readFirmwareFromRadio(const QString filename)
{
bool result = false;
QString message = tr("Read Firmware From Radio");
QFile file(filename);
if (file.exists()) {
file.remove();
}
g.flashDir(QFileInfo(filename).dir().absolutePath());
if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = FindMassstoragePath("FIRMWARE.BIN");
if (!path.isEmpty()) {
QStringList str;
str << path << filename;
avrOutputDialog *ad = new avrOutputDialog(this, "", str, message);
ad->setWindowIcon(CompanionIcon("read_flash.png"));
ad->exec();
delete ad;
sleep(1);
result = true;
}
}
if (result == false) {
QStringList str = GetReceiveFlashCommand(filename);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, message);
ad->setWindowIcon(CompanionIcon("read_flash.png"));
ad->exec();
delete ad;
result = true;
}
if (!QFileInfo(filename).exists())
result = false;
return result;
}
bool MainWindow::writeFirmwareToRadio(const QString filename)
{
bool result = false;
QString message = tr("Write Firmware To Radio");
if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = FindMassstoragePath("FIRMWARE.BIN");
if (!path.isEmpty()) {
QStringList str;
str << filename << path;
avrOutputDialog *ad = new avrOutputDialog(this, "", str, message);
ad->setWindowIcon(CompanionIcon("write_flash.png"));
ad->exec();
delete ad;
sleep(1);
result = true;
}
}
if (result == false) {
QStringList str = GetSendFlashCommand(filename);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, message, AVR_DIALOG_CLOSE_IF_SUCCESSFUL);
CompanionIcon iconw("write_flash.png");
ad->setWindowIcon(iconw);
result = ad->exec();
delete ad;
}
return result;
}
bool MainWindow::readEepromFromRadio(const QString filename, const QString message)
{
bool result = false;
QFile file(filename);
if (file.exists()) {
file.remove();
}
if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = FindMassstoragePath("EEPROM.BIN");
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
}
else {
QStringList str;
str << path << filename;
avrOutputDialog *ad = new avrOutputDialog(this, "", str, message);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
result = true;
}
}
else {
QStringList str = GetReceiveEEpromCommand(filename);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, message);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
result = true;
}
if (!QFileInfo(filename).exists())
result = false;
return result;
}
bool MainWindow::writeEepromToRadio(const QString filename, const QString message)
{
if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = FindMassstoragePath("EEPROM.BIN");
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return false;
}
else {
QStringList str;
str << filename << path;
avrOutputDialog *ad = new avrOutputDialog(this, "", str, message);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
return true;
}
}
else {
QStringList str = GetSendEEpromCommand(filename);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Write Backup To Radio", AVR_DIALOG_SHOW_DONE);
ad->setWindowIcon(CompanionIcon("write_eeprom.png"));
ad->exec();
delete ad;
return true;
}
}
void MainWindow::writeBackup() void MainWindow::writeBackup()
{ {
QString fileName; QString fileName;
@@ -1031,50 +1137,32 @@ void MainWindow::writeBackup()
} }
backupEnable = false; backupEnable = false;
} }
} else { }
else {
backupEnable = false; backupEnable = false;
} }
EEPROMInterface *eepromInterface = GetEepromInterface();
if (backup) { if (backup) {
if (backupEnable) { if (backupEnable) {
QString backupFile = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin"; QString backupFile = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin";
if (IS_TARANIS(eepromInterface->getBoard())) { if (!readEepromFromRadio(backupFile, tr("Backup Models and Settings From Radio")))
QString path=FindTaranisPath(); return;
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
} else {
QStringList str;
str << path << backupFile;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Backup Models and Settings From Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
sleep(1);
}
} else {
QStringList str = GetReceiveEEpromCommand(backupFile);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Backup Models and Settings From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
sleep(1);
}
} }
int oldrev = getEpromVersion(fileName); int oldrev = getEpromVersion(fileName);
QString tempDir = QDir::tempPath(); QString tempDir = QDir::tempPath();
QString tempFlash = tempDir + "/flash.bin"; QString tempFlash = tempDir + "/flash.bin";
QStringList str = GetReceiveFlashCommand(tempFlash);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Radio"); if (!readFirmwareFromRadio(tempFlash))
ad->setWindowIcon(CompanionIcon("read_flash.png")); return;
ad->exec();
sleep(1);
QString restoreFile = tempDir + "/compat.bin"; QString restoreFile = tempDir + "/compat.bin";
if (!convertEEPROM(fileName, restoreFile, tempFlash)) { if (!convertEEPROM(fileName, restoreFile, tempFlash)) {
int ret = QMessageBox::question(this, "Error", tr("Cannot check Models and Settings compatibility! Continue anyway?") , int ret = QMessageBox::question(this, "Error", tr("Cannot check Models and Settings compatibility! Continue anyway?") ,
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (ret==QMessageBox::No) if (ret==QMessageBox::No)
return; return;
} else { }
else {
int rev = getEpromVersion(restoreFile); int rev = getEpromVersion(restoreFile);
if ((rev / 100) != (oldrev / 100)) { if ((rev / 100) != (oldrev / 100)) {
QMessageBox::warning(this, tr("Warning"), tr("The radio firmware belongs to another product family, check file and preferences!")); QMessageBox::warning(this, tr("Warning"), tr("The radio firmware belongs to another product family, check file and preferences!"));
@@ -1087,59 +1175,16 @@ void MainWindow::writeBackup()
QByteArray ba = tempFlash.toLatin1(); QByteArray ba = tempFlash.toLatin1();
char *name = ba.data(); char *name = ba.data();
unlink(name); unlink(name);
} else {
if (backupEnable) {
QString backupFile = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss") + ".bin";
if (IS_TARANIS(eepromInterface->getBoard())) {
QString path=FindTaranisPath();
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
} else {
QStringList str;
str << path << backupFile;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Backup Models and Settings From Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
}
else {
QStringList str = ((MainWindow *)this->parent())->GetReceiveEEpromCommand(backupFile);
avrOutputDialog *ad = new avrOutputDialog(this, ((MainWindow *)this->parent())->GetAvrdudeLocation(), str, tr("Backup Models and Settings From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
}
}
if (IS_TARANIS(eepromInterface->getBoard())) {
QString path=FindTaranisPath();
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
}
else {
QStringList str;
str << fileName << path;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Write Backup To Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
} }
else { else {
QStringList str = GetSendEEpromCommand(fileName); if (backupEnable) {
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Write Backup To Radio", AVR_DIALOG_SHOW_DONE); QString backupFile = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss") + ".bin";
ad->setWindowIcon(CompanionIcon("write_eeprom.png")); if (!readEepromFromRadio(backupFile, tr("Backup Models and Settings From Radio")))
ad->exec(); return;
delete ad; }
} }
if (!writeEepromToRadio(fileName, tr("Write Backup To Radio")))
return;
} }
} }
@@ -1257,27 +1302,20 @@ void MainWindow::writeFlash(QString fileToFlash)
} }
backupEnable=false; backupEnable=false;
} }
} else { }
else {
backupEnable=false; backupEnable=false;
} }
if (backupEnable) { if (backupEnable) {
QDateTime datetime; QDateTime datetime;
backupFile.clear(); backupFile.clear();
backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin"; backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin";
} }
QStringList str = GetReceiveEEpromCommand(backupFile);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Backup Models and Settings From Radio"), AVR_DIALOG_CLOSE_IF_SUCCESSFUL); if (readEepromFromRadio(backupFile, tr("Backup Models and Settings From Radio"))) {
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
int res = ad->exec();
delete ad;
if (QFileInfo(backupFile).exists() && res) {
sleep(1); sleep(1);
QStringList str = GetSendFlashCommand(fileName); int res = writeFirmwareToRadio(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Write Firmware To Radio"), AVR_DIALOG_CLOSE_IF_SUCCESSFUL);
CompanionIcon iconw("write_eeprom.png");
ad->setWindowIcon(iconw);
int res = ad->exec();
delete ad;
if (res) { if (res) {
QString restoreFile = tempDir + "/restore.bin"; QString restoreFile = tempDir + "/restore.bin";
if (!convertEEPROM(backupFile, restoreFile, fileName)) { if (!convertEEPROM(backupFile, restoreFile, fileName)) {
@@ -1285,12 +1323,7 @@ void MainWindow::writeFlash(QString fileToFlash)
restoreFile = backupFile; restoreFile = backupFile;
} }
sleep(1); sleep(1);
QStringList str = GetSendEEpromCommand(restoreFile); if (!writeEepromToRadio(restoreFile, tr("Restore Models and Settings To Radio"))) {
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Restore Models and Settings To Radio"), AVR_DIALOG_CLOSE_IF_SUCCESSFUL);
ad->setWindowIcon(iconw);
res = ad->exec();
delete ad;
if (!res) {
QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFile)); QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFile));
} }
} }
@@ -1313,71 +1346,30 @@ void MainWindow::writeFlash(QString fileToFlash)
} }
if (backupEnable && !IS_TARANIS(GetEepromInterface()->getBoard())) { if (backupEnable && !IS_TARANIS(GetEepromInterface()->getBoard())) {
QDateTime datetime; QDateTime datetime;
QString backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin"; QString backupFile = backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin";
QStringList str = GetReceiveEEpromCommand(backupFile); readEepromFromRadio(backupFile, tr("Backup Models and Settings From Radio"));
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Backup Models and Settings From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
} }
QStringList str = GetSendFlashCommand(fileName); writeFirmwareToRadio(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Write Firmware To Radio"), AVR_DIALOG_SHOW_DONE);
ad->setWindowIcon(CompanionIcon("write_flash.png"));
ad->exec();
delete ad;
} }
} }
} }
void MainWindow::readBackup() void MainWindow::readBackup()
{ {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Radio Backup to File"), g.eepromDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); QString fileName = QFileDialog::getSaveFileName(this, tr("Save Radio Backup to File"), g.eepromDir(), tr(EXTERNAL_EEPROM_FILES_FILTER));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
EEPROMInterface *eepromInterface = GetEepromInterface(); if (!readEepromFromRadio(fileName, tr("Read Radio Backup")))
if (IS_TARANIS(eepromInterface->getBoard())) { return;
QString path=FindTaranisPath(); }
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
}
else {
QStringList str;
str << path << fileName;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Read Radio Backup")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
}
}
else {
g.eepromDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveEEpromCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
}
}
} }
void MainWindow::readFlash() void MainWindow::readFlash()
{ {
QString fileName = QFileDialog::getSaveFileName(this,tr("Read Radio Firmware to File"), g.flashDir(),tr(FLASH_FILES_FILTER)); QString fileName = QFileDialog::getSaveFileName(this,tr("Read Radio Firmware to File"), g.flashDir(),tr(FLASH_FILES_FILTER));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); readFirmwareFromRadio(fileName);
if (file.exists()) { }
file.remove();
}
g.flashDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveFlashCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Radio");
ad->setWindowIcon(CompanionIcon("read_flash.png"));
ad->exec();
delete ad;
}
} }
void MainWindow::burnConfig() void MainWindow::burnConfig()
+6 -1
View File
@@ -183,7 +183,7 @@ class MainWindow : public QMainWindow
void updateIconThemeActions(); void updateIconThemeActions();
int getFileType(const QString &fullFileName); int getFileType(const QString &fullFileName);
QString FindTaranisPath(); QString FindMassstoragePath(QString filename);
QString Theme; QString Theme;
QString ISize; QString ISize;
QString strippedName(const QString &fullFileName); QString strippedName(const QString &fullFileName);
@@ -203,6 +203,11 @@ class MainWindow : public QMainWindow
bool convertEEPROM(QString backupFile, QString restoreFile, QString flashFile); bool convertEEPROM(QString backupFile, QString restoreFile, QString flashFile);
bool isValidEEPROM(QString eepromfile); bool isValidEEPROM(QString eepromfile);
bool readEepromFromRadio(const QString filename, const QString message);
bool writeEepromToRadio(const QString filename, const QString message);
bool readFirmwareFromRadio(const QString filename);
bool writeFirmwareToRadio(const QString filename);
QMdiArea *mdiArea; QMdiArea *mdiArea;
QSignalMapper *windowMapper; QSignalMapper *windowMapper;
+11 -75
View File
@@ -536,7 +536,7 @@ void MdiChild::writeEeprom() // write to Tx
QMessageBox::critical(this,tr("Error"), tr("Cannot write temporary file!")); QMessageBox::critical(this,tr("Error"), tr("Cannot write temporary file!"));
return; return;
} }
EEPROMInterface *eepromInterface = GetEepromInterface();
bool backup=false; bool backup=false;
burnDialog *cd = new burnDialog(this, 1, &tempFile, &backup,strippedName(curFile)); burnDialog *cd = new burnDialog(this, 1, &tempFile, &backup,strippedName(curFile));
cd->exec(); cd->exec();
@@ -544,40 +544,15 @@ void MdiChild::writeEeprom() // write to Tx
if (backup) { if (backup) {
if (backupEnable) { if (backupEnable) {
QString backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss")+".bin"; QString backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss")+".bin";
if (IS_TARANIS(eepromInterface->getBoard())) { if (!((MainWindow *)this->parent())->readEepromFromRadio(backupFile, tr("Backup EEPROM From Radio")))
QString path=((MainWindow *)this->parent())->FindTaranisPath(); return;
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
}
else {
QStringList str;
str << path << backupFile;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Backup EEPROM From Radio")); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
}
else {
QStringList str = ((MainWindow *)this->parent())->GetReceiveEEpromCommand(backupFile);
avrOutputDialog *ad = new avrOutputDialog(this, ((MainWindow *)this->parent())->GetAvrdudeLocation(), str, tr("Backup EEPROM From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
} }
int oldrev=((MainWindow *)this->parent())->getEpromVersion(tempFile); int oldrev=((MainWindow *)this->parent())->getEpromVersion(tempFile);
QString tempFlash=tempDir + "/flash.bin"; QString tempFlash=tempDir + "/flash.bin";
QStringList str = ((MainWindow *)this->parent())->GetReceiveFlashCommand(tempFlash);
avrOutputDialog *ad = new avrOutputDialog(this, ((MainWindow *)this->parent())->GetAvrdudeLocation(), str, "Read Flash From Radio"); if (!((MainWindow *)this->parent())->readFirmwareFromRadio(tempFlash))
ad->setWindowIcon(CompanionIcon("read_flash.png")); return;
ad->exec();
delete ad;
sleep(1);
QString restoreFile = tempDir + "/compat.bin"; QString restoreFile = tempDir + "/compat.bin";
if (!((MainWindow *)this->parent())->convertEEPROM(tempFile, restoreFile, tempFlash)) { if (!((MainWindow *)this->parent())->convertEEPROM(tempFile, restoreFile, tempFlash)) {
int ret = QMessageBox::question(this, tr("Error"), tr("Cannot check eeprom compatibility! Continue anyway?"), QMessageBox::Yes | QMessageBox::No); int ret = QMessageBox::question(this, tr("Error"), tr("Cannot check eeprom compatibility! Continue anyway?"), QMessageBox::Yes | QMessageBox::No);
@@ -601,52 +576,13 @@ void MdiChild::writeEeprom() // write to Tx
else { else {
if (backupEnable) { if (backupEnable) {
QString backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin"; QString backupFile=backupPath+"/backup-"+QDateTime().currentDateTime().toString("yyyy-MM-dd-hhmmss")+".bin";
if (IS_TARANIS(eepromInterface->getBoard())) { if (!((MainWindow *)this->parent())->readEepromFromRadio(backupFile, tr("Backup EEPROM From Radio")))
QString path=((MainWindow *)this->parent())->FindTaranisPath(); return;
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
}
else {
QFile::copy(path,backupFile);
}
}
else {
QStringList str = ((MainWindow *)this->parent())->GetReceiveEEpromCommand(backupFile);
avrOutputDialog *ad = new avrOutputDialog(this, ((MainWindow *)this->parent())->GetAvrdudeLocation(), str, tr("Backup EEPROM From Radio"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
} }
} }
if (IS_TARANIS(eepromInterface->getBoard())) { if (!((MainWindow *)this->parent())->writeEepromToRadio(tempFile, tr("Write EEPROM To Radio")))
QString path=((MainWindow *)this->parent())->FindTaranisPath(); return;
if (path.isEmpty()) {
taranisNotFoundDialog *tnfd = new taranisNotFoundDialog(this);
tnfd->exec();
return;
}
else {
QStringList str;
str << tempFile << path;
avrOutputDialog *ad = new avrOutputDialog(this,"", str, tr("Write EEPROM To Radio"), AVR_DIALOG_SHOW_DONE); //, AVR_DIALOG_KEEP_OPEN);
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
ad->exec();
delete ad;
sleep(1);
}
}
else {
QStringList str = ((MainWindow *)this->parent())->GetSendEEpromCommand(tempFile);
avrOutputDialog *ad = new avrOutputDialog(this, ((MainWindow *)this->parent())->GetAvrdudeLocation(), str, "Write EEPROM To Radio", AVR_DIALOG_SHOW_DONE);
ad->setWindowIcon(CompanionIcon("write_eeprom.png"));
ad->exec();
delete ad;
}
} }
} }