#include "qggrifobeamupform.h" #include "ui_qggrifobeamupform.h" #include #include "qgpropertywidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "qzip.h" #include "bsk_tftp_pfs.h" #include #include "downloadablefile.h" #include "mydebug.h" #include "historydbform.h" enum fpga_t { fpga_no_specific = 0, fpga_carrier1_fpga1 = 1, fpga_carrier1_fpga2 = 2, fpga_carrier2_fpga1 = 3, fpga_carrier2_fpga2 = 4, fpga_digital_ctrl = 5 }; QString ShowFileInfo(const QString& fname, bool popup=true); static QString probeNetworks(const QString& prefered_net, QComboBox* cb) { unsigned int prefered_index=0; static bool privateSubnet=false; static QString preferedNetwork("127.0.0.1"); if (!prefered_net.isEmpty()) preferedNetwork=prefered_net; QHostInfo hi=QHostInfo::fromName(QHostInfo::localHostName()); //ui->groupBox->setTitle(QString("Host: %1").arg(hi.hostName())); QList hal=QNetworkInterface::allInterfaces(); if (hal.isEmpty()) { MyDebug().logMsg(type_log_error, origin_msg_generic, "Network Config: NO HOST ADDRESSES"); cb->addItem(""); cb->setEnabled(false); } else { foreach(QNetworkInterface nif, hal) { //QList nhal=nif.allAddresses(); QList nhal=nif.addressEntries(); foreach(QNetworkAddressEntry aentry, nhal) { bool private_subnet=false; QHostAddress a=aentry.ip(); if (!(a.toString().startsWith("192.168") || a.toString().startsWith("169.254") || a.toString().startsWith("127."))) continue; cb->addItem(QString("%1 (%2) [%3]").arg(nif.humanReadableName()).arg(a.toString()).arg(nif.index()), a.toString()); int currentIndex=cb->count()-1; //if (a.toString().startsWith("192.168.0") ||a.toString().startsWith("192.168.2")) if (a.toString().startsWith(preferedNetwork)) { prefered_index=currentIndex; private_subnet=true; privateSubnet=privateSubnet; } cb->setItemData(currentIndex, private_subnet, Qt::UserRole+1); cb->setItemData(currentIndex, nif.index(), Qt::UserRole+2); //ui->comboBoxInterface->seIif (nif.flags() & QNetworkInterface::IsUp) } } if (prefered_index) cb->setCurrentIndex(prefered_index); } return hi.hostName(); } #define MAX_TARGETS 64 struct targets_t { unsigned int valid; QgGrifoDownloadSite sites[MAX_TARGETS]; }; static targets_t targets; struct PgmSteps { QLabel* lbl; QCheckBox* chk; }; static PgmSteps pgmSteps[10]; QgGrifoBeamUpForm::QgGrifoBeamUpForm(QWidget *parent) : QWidget(parent), props(QgGrifoBeamupProperties::instance()), ui(new Ui::QgGrifoBeamUpForm), settings("./grifo_beamup.ini", QSettings::IniFormat) { QStyle* st=QApplication::style(); ui->setupUi(this); ui->tbRefresh->setIcon(st->standardIcon(QStyle::SP_DriveNetIcon) //SP_BrowserReload) //QIcon(":/qt-project.org/styles/commonstyle/images/refresh-32.png") ); ui->tbFileSelect->setIcon(st->standardIcon(QStyle::SP_FileIcon) //QIcon(":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png") //":/qt-project.orqg/styles/commonstyle/images/file-32.png" //":/qt-project.org/styles/commonstyle/images/filecontents-128.png" ); ui->tbGo->setIcon(st->standardIcon(QStyle::SP_ArrowUp) //QIcon(":/qt-project.org/styles/commonstyle/images/up-32.png" ); ui->tbDropSelect->setIcon(st->standardIcon(QStyle::SP_FileDialogNewFolder) //QIcon(":/qt-project.org/styles/commonstyle/images/newdirectory-32.png") ); ui->tbSettings->setIcon(st->standardIcon(QStyle::SP_FileDialogListView) //QIcon(":/qt-project.org/styles/commonstyle/images/viewlist-32.png") ); ui->tbFileInfo->setIcon(st->standardIcon(QStyle::SP_FileDialogInfoView) //QIcon(":/qt-project.org/styles/commonstyle/images/viewdetailed-32.png") ); entitiesForm=new QgGrifoDownloadEntitiesForm; int ipos=ui->verticalLayout->indexOf(ui->placeholder); ui->verticalLayout->insertWidget(ipos, entitiesForm); ui->placeholder->setVisible(false); ui->leMsg->setMaximumBlockCount(100); entitiesForm->setVisible(false); //QString host=populateNetworks(ui->cbNetowrkSelection); { QHostInfo hi=QHostInfo::fromName(QHostInfo::localHostName()); QString host=QString("Host: %1").arg(hi.hostName()); ui->hostName->setText(host); } ui->progressBar->setValue(0); ui->progressBar->setEnabled(false); ui->progressBar->setTextVisible(false); //setState(1); fileSelector.setObjectName("GrifoBeamUpFileSelector"); fileSelector.setOption(QFileDialog::ReadOnly, true); fileSelector.setViewMode(QFileDialog::Detail); fileSelector.setNameFilters( QStringList()<<"archive (*.zip)"<<"Binary (*.bin)"<<"ELF (*.elf *.out)"<<"Any files (*)"); connect(ui->tbFileSelect, &QToolButton::clicked, this, [this](bool) { QString tmp=fileSelector.directory().absolutePath(); fileSelector.setOption(QFileDialog::ReadOnly, true); fileSelector.setFileMode(QFileDialog::AnyFile); fileSelector.setDirectory(tmp); if (fileSelector.exec()) { ui->leFile->setText(fileSelector.selectedFiles().at(0)); //stateReady(); selectByFile(fileSelector.selectedFiles().at(0)); } } ); connect(ui->tbDropSelect, &QToolButton::clicked, this, [this](bool) { fileSelector.setFileMode(QFileDialog::Directory); if (fileSelector.exec()) { selectWatchDir(fileSelector.selectedFiles().at(0)); //ui->leDir->setText(fileSelector.selectedFiles().at(0)); //fileWatcher.removePath(fileWatcher.) //fileWatcher.addPath(fileSelector.selectedFiles().at(0)); } }); connect(&fileWatcher, &QFileSystemWatcher::directoryChanged, this, &QgGrifoBeamUpForm::updateWatchedDirectory); connect(&fileWatcher, &QFileSystemWatcher::fileChanged, this, &QgGrifoBeamUpForm::updateWatchedFile); connect(ui->tbGo, &QToolButton::clicked, this, &QgGrifoBeamUpForm::uploadGo); #if 0 connect(&tftp, &QgGrifoBeamUpTftp::progressInfo, this, [this](int n, const QString& msg) { if (n==-1) ui->progressBar->setRange(0, 0); else { ui->progressBar->setRange(0, 100); ui->progressBar->setValue(n); } ui->progressLabel->setText(msg); }); connect(&tftp, &QgGrifoBeamUpTftp::sendTerminated, this, [this]() { ui->progressBar->setRange(0, 100); ui->progressBar->setValue(100); showMessage("Completed"); //ui->progressLabel->setText("Completed"); stateReady(); }); connect(&tftp, &QgGrifoBeamUpTftp::transferError, this, [this](int code, const QString& msg) { showMessage(QString("%1 (%2)").arg(msg).arg(code)); //ui->progressLabel->setText(QString("%1 (%2)").arg(msg).arg(code)); ui->progressBar->reset(); ui->progressBar->setRange(0, 100); ui->progressBar->setValue(0); ui->progressBar->setEnabled(false); QMessageBox::critical(this, QString(), QString("Transfer Error: %1 (%2)").arg(msg).arg(code)); stateReady(); }); connect(&tftp, &QgGrifoBeamUpTftp::serverHello, this, [this](unsigned int ip, int port, const QString& msg) { ui->leMsg->appendPlainText(msg); //setText(msg); serverHello(ip, port, msg); }); #endif //general configuration of app { QSettings& s=settings;//("./grifo_beamup.ini", QSettings::IniFormat); s.beginGroup("GrifoBeamUp"); QString prefnet=s.value("preferedNetwork", QString("$127.0.0")).toString(); if (prefnet.startsWith('$')) prefnet=prefnet.remove('$'); probeNetworks(prefnet, ui->cbNetwork); QgNetworkInterface::setNetworkIP(prefnet); ui->leFile->setText(s.value("file", QString()).toString()); fileSelector.restoreState(s.value("fileselector").toByteArray()); s.endGroup(); } #if 0 tftp.bind(QHostAddress(QgNetworkInterface::networkIP())); ui->tbNetwork->setText(netDlg->hostNetworkName()); QgNetworkInterface::setNetworkIP(netDlg->hostAddress()); connect(ui->tbNetwork, &QToolButton::clicked, this, [this](bool) { netDlg->exec(); if (netDlg->result()==QDialog::Accepted) { QgNetworkInterface::setNetworkInterface(QHostAddress(netDlg->hostAddress())); ui->tbNetwork->setText(netDlg->hostNetworkName()); //QgNetworkInterface::networkIP()); } }); #endif connect(ui->tbRefresh, &QToolButton::clicked, this, [this](bool) { refreshServers(); }); connect(ui->tbSettings, &QToolButton::clicked, this, [this](bool) { static QgPropertyDialog dlg(&props, this); dlg.show(); }); props.restoreSettings(settings); if (!props.property("lastDirectory").toString().isEmpty()) fileSelector.setDirectory(props.property("lastDirectory").toString()); pingTimer.setSingleShot(true); pingTimer.setInterval(2000); connect(&pingTimer, &QTimer::timeout, this, [this]() { ui->tbRefresh->setEnabled(true); }); ui->cbTarget->setDuplicatesEnabled(false); ui->cbPartition->setDuplicatesEnabled(false); ui->cbTarget->addItem(QgNetworkInterface::networkIP()+":"+QString("%1").arg(props.property("tftpFirstPort").toInt())); connect(entitiesForm, &QgGrifoDownloadEntitiesForm::itemSelected, this, [this](void*xs, void*xp) { bsk_download_site_t* s=(bsk_download_site_t*)xs; bsk_download_partition_t* p=(bsk_download_partition_t*)xp; updateSelected(s, p); }); stateReady(); /* * Configuration target from file */ readConfigFile(); programmer=new FgpaProgrammer; connect(ui->leFile, &QLineEdit::editingFinished, this, [this]() { selectByFile(ui->leFile->text()); }); selectWatchDir(props.property("watchedDirectory").toString()); setAcceptDrops(true); ui->groupBox->setEnabled(false); connect(entitiesForm, &QgGrifoDownloadEntitiesForm::fileDroppped, this, [this](QTreeWidgetItem* i, const QString& name) { selectByFile(name, i); }); { QGridLayout* g=ui->gridLayout_2; for(int i=0; i<7; ++i) { pgmSteps[i].chk=new QCheckBox; if (i<1) pgmSteps[i].chk->setChecked(false); else pgmSteps[i].chk->setChecked(true); pgmSteps[i].lbl=new QLabel("..."); g->addWidget(pgmSteps[i].chk, i+1, 0); g->addWidget(pgmSteps[i].lbl, i+1, 2); } } connect(programmer, &FgpaProgrammer::statusChanged, this, &QgGrifoBeamUpForm::statusUpdated, Qt::QueuedConnection); programmer->setSimulate(ui->cbSimulate->isChecked()); programmer->setSRIOMemory(ui->cb_TargetAddress->isChecked()); _dbHistory = dbHistory::instance(); QHostInfo hi=QHostInfo::fromName(QHostInfo::localHostName()); _dbHistory->setParam(hi.hostName()); _dbHistory->refreshList(); } QgGrifoBeamUpForm::~QgGrifoBeamUpForm() { delete ui; } void QgGrifoBeamUpForm::updateSelected(const bsk_download_site_t* site,const bsk_download_partition_t* p) { if (!site) return; MyDebug().logMsg(type_log_info, origin_msg_generic, QString("select: %1 %2").arg(site->name).arg(p->name)); int ti=-1; for(int i=0; icbTarget->count(); ++i) { bsk_download_site_t* is=(bsk_download_site_t*)ui->cbTarget->itemData(i).toULongLong(); if (is==site) { ti=i; break; } } if (ti<0) { return; } ui->cbTarget->setCurrentIndex(ti); ui->cbPartition->clear(); for(int i=0; ipartitions[i].name[0]==0) break; ui->cbPartition->addItem(site->partitions[i].name, (unsigned long long)&site->partitions[i]); } ui->cbPartition->addItem("", 0); ui->cbPartition->setCurrentIndex(ui->cbPartition->count()-1); if (p) { for(int i=0; icbPartition->count(); ++i) { if (ui->cbPartition->itemData(i).toULongLong()==(unsigned long long)p) { ui->cbPartition->setCurrentIndex(i); } } } if(_dbHistory != NULL) { delete _dbHistory; _dbHistory = NULL; } } #include void QgGrifoBeamUpForm::selectByFile(const QString& fname, QTreeWidgetItem*) { QFileInfo finfo(fname); QString n=finfo.fileName(); DownloadableFile df; df.open(fname); BinaryFileInfo bfi=df.info(); const TgtMatch* m=tgtMatchSet.lookup(n); if (m==0) m=tgtMatchSet.lookupArch(bfi.binaryInfo.archName()); if (m) { bsk_download_site_t* s=0; bsk_download_partition_t* p=0; if (m->wi) { bool valid=bfi.binaryInfo.archName()==m->archName; m->wi->setDisabled(!valid); if (!valid) m->wi->setText(3, "Invadid format: "+finfo.fileName()); else m->wi->setText(3, finfo.fileName()); m->wi->setToolTip(3, finfo.absoluteFilePath()+ShowFileInfo(fname, false)); QWidget* tmp=m->wi->treeWidget()->itemWidget(m->wi, 2); if (tmp) { QProgressBar* b=qobject_cast(tmp); b->setVisible(true); b->setValue(0); //b->setFormat("pending"); } } for(int i=0; icbTarget->count(); ++i) { unsigned long long raws=ui->cbTarget->itemData(i).toULongLong(); if (!raws) { continue; } s=(bsk_download_site_t*)raws; if (m->tgtName.compare(s->name, Qt::CaseInsensitive)!=0) { s=0; continue; } for(int j=0; jpartName.compare(s->partitions[j].name)) break; if (m->partName.compare(s->partitions[j].name, Qt::CaseInsensitive)==0) { p=(bsk_download_partition_t*)&s->partitions[j]; updateSelected(s, p); //break; } } //break; } //updateSelected(s, p); } } void QgGrifoBeamUpForm::refreshServers() { if (ui->cbNetwork->count()<1) return; if (ui->cbNetwork->isEnabled()) { QString ip=ui->cbNetwork->itemData(ui->cbNetwork->currentIndex()).toString(); bool match=ip.startsWith("127.0.", Qt::CaseInsensitive); if (match) { tftp.bindRemote(QHostAddress("127.0.0.1"), 50069); ui->cbTarget->setCurrentText(QString("%1:%2").arg("127.0.0.1").arg(50069)); } else { tftp.bindRemote(QHostAddress(default_ip), 50069); ui->cbTarget->setCurrentText(QString("%1:%2").arg(default_ip).arg(50069)); } QgNetworkInterface::setNetworkInterface(QHostAddress(ip)); QgNetworkInterface::setNetworkIP(ip); MyDebug().logMsg(type_log_info, origin_msg_tftp, QString("%1").arg(QgNetworkInterface::networkIP())); tftp.bind(QHostAddress(QgNetworkInterface::networkIP())); ui->cbNetwork->setEnabled(false); ui->groupBox->setEnabled(true); } ui->tbRefresh->setEnabled(false); programmer->setTftp(&tftp); #if 0 entitiesForm->clear(); ui->cbTarget->clear(); ui->cbPartition->clear(); ui->cbPartition->addItem("", 0); targets.valid=0; int last=props.property("tftpLastPort").toInt(); for(int i=props.property("tftpFirstPort").toInt(); i<=last; ++i) { MyDebug()<<"Ping server:"<site, 0, sizeof s->site); bsk_download_site_t* site=&s->site; int r=bsk_tftp_mfs_decode_site(site, msg.toLatin1().constData()); site->media_address=ip; site->media_port=port; s->tgt=0; if (r==0) { TgtMatch* tgt=tgtMatchSet.lookupCSCI(site->name, site->address); if (tgt) s->tgt=tgt; //appName=tgt->appName; entitiesForm->addSite(s); QHostAddress ha(site->media_address); QString n=QString("%1:%2/%3").arg(ha.toString()).arg(site->media_port).arg(site->name); ui->cbTarget->addItem(n, (quint64)site); ++targets.valid; for(int i=0; ipartitions[i].name[0]==0) break; QString queryStr=QString("$PGM:%1/$version$").arg(site->partitions[i].name); tftp.queryVersion(ip, port, queryStr); } pingTimer.start(); } entitiesForm->setVisible(true); #endif } void QgGrifoBeamUpForm::partitionUpdate(unsigned int /*ip*/, int /*port*/, const QString& /*msg*/) { } void QgGrifoBeamUpForm::saveSettings() { { QSettings& s=settings; //("./grifo_beamup.ini", QSettings::IniFormat); s.beginGroup("GrifoBeamUp"); s.setValue("preferedNetwork", QString('$')+QgNetworkInterface::networkIP()); s.setValue("file", ui->leFile->text()); s.setValue("fileselector", fileSelector.saveState()); props.setProperty("lastDirectory", fileSelector.directory().absolutePath()); s.setValue("dirHistory", fileSelector.history()); s.endGroup(); props.saveSettings(settings); } } void QgGrifoBeamUpForm::updateWatchedDirectory(const QString& path) { QDir dir(path); QStringList currentList=dir.entryList(); QStringList changed; foreach(QString s, currentList) { bool hit=watchedFiles.contains(s); if (!hit) changed.append(s); } watchedFiles=currentList; MyDebug().logMsg(type_log_info, origin_msg_generic, QString("Directory update: %1 %2").arg(path).arg(changed.count())); if (changed.size()>0) { for(int i=0; ileFile->setText(dir.absoluteFilePath(changed.at(0))); } } } void QgGrifoBeamUpForm::updateWatchedFile(const QString& path) { MyDebug().logMsg(type_log_info, origin_msg_generic, QString("File update: %1").arg(path)); } void QgGrifoBeamUpForm::setState(int s) { state=s; bool enable=false; if (state==0) { enable=true; //ui->cbNetowrkSelection->setEnabled(false); ui->tbGo->setText("Upload..."); } else ui->tbGo->setText("Break..."); //ui->tbNetwork->setEnabled(enable); ui->tbRefresh->setEnabled(enable); //ui->tbGo->setEnabled(enable); ui->tbFileSelect->setEnabled(enable); ui->tbDropSelect->setEnabled(enable); ui->leFile->setEnabled(enable); //ui->leDir->setEnabled(enable); ui->cbPartition->setEnabled(enable); ui->cbTarget->setEnabled(enable); entitiesForm->setEnabled(enable); if (enable) { if (ui->progressBar->minimum()==ui->progressBar->maximum()) { ui->progressBar->setRange(0, 100); ui->progressBar->setValue(0); ui->progressBar->setEnabled(false); } } ui->groupBox->setEnabled(enable); } void QgGrifoBeamUpForm::stateReady() { setState(0); if (pendingList.count()) { QString tmp=pendingList.at(0); pendingList.pop_front(); if (tmp.isEmpty()) { return; } ui->leFile->setText(tmp); selectByFile(tmp); uploadGo(); } } void QgGrifoBeamUpForm::stateBusy() { setState(1); } void QgGrifoBeamUpForm::uploadGo() { if (state!=0) { /*int r=*/QMessageBox::question(this, QString(), QString("Break operation?")); return; } int n=ui->cbTarget->currentIndex(); //controlla se è stato selezionato un indirizzo target valido if (n<0) { ui->progressLabel->setText("Target not selected"); QMessageBox::information(this, QString(), QString("File not selected")); return; } //controlla se il file da spedire è leggibile QFileInfo finfo(ui->leFile->text()); if (!finfo.isReadable()) { QMessageBox::critical(this, QString(), QString("File not readable")); return; } //controlla se l'indirizzo ftp del server a cui collegarci è valido QString tgtStr=ui->cbTarget->currentText(); tgtStr="ftp://"+ui->cbTarget->currentText(); QUrl url(tgtStr); if (!url.isValid()) { QString msg=QString("Invalid URL %1").arg(tgtStr); ui->progressLabel->setText(msg); QMessageBox::critical(this, QString(), msg); return; } //apertura connessione con server tftp remoto QHostAddress ha(url.host()); int port=url.port(); tftp.bindRemote(ha, port); //ui->progressLabel->setText(tmp); { MyDebug().logMsg(type_log_info, origin_msg_generic, QString("Upload to %1 %2@%3:%4...").arg(tgtStr).arg("?").arg(ha.toString()).arg(port)); } QString partName; n=ui->cbPartition->currentIndex(); if (n>=0) { unsigned long long p=ui->cbPartition->currentData().toULongLong(); if (p && !ui->cbPartition->currentText().isEmpty()) partName="$PGM:"+ui->cbPartition->currentText()+"/%1"; } if (partName=="") { partName ="$PGM:uploadfile/%1"; } QString fnameStr=finfo.fileName(); #if 0 { QZipReader zip(ui->leFile->text()); QList zlst=zip.fileInfoList(); if(zlst.size()) { QString tmpname=zlst.at(0).filePath; //standardDialog()->setFileInfo(QString("%1 (%2)").arg(tmpname).arg(params.simplifiedFileName)); fnameStr+="("+tmpname+")"; } } #endif QString opmsg=QString("%1 -> %2/%3").arg(fnameStr).arg(ui->cbTarget->currentText()).arg(partName); showMessage(opmsg); int qr=QMessageBox::question(this, QString(), opmsg, QMessageBox::Yes|QMessageBox::No|QMessageBox::Abort); if (qr!=QMessageBox::Yes) { if (qr==QMessageBox::Abort) pendingList.clear(); return; } //ui->progressLabel->setText("Upload start..."); bool ok=tftp.sendFile(ui->leFile->text(), partName); //ui->tbNetwork->setEnabled(false); ui->lbOperation->setText(opmsg); if (ok) { stateBusy(); //ui->tbGo->setEnabled(false); ui->progressBar->reset(); ui->progressBar->setRange(0, 0); ui->progressBar->setEnabled(true); } } void QgGrifoBeamUpForm::dragEnterEvent(QDragEnterEvent * event) { if (event->mimeData()->hasUrls()) { QList lst=event->mimeData()->urls(); if ((lst.size()>0) && lst.size()<10) { //if (lst.at(0).isLocalFile()) event->acceptProposedAction(); } } } void QgGrifoBeamUpForm::dropEvent(QDropEvent * event) { QList lst=event->mimeData()->urls(); if (lst.size()>0) { for(int i=0; ileFile->setText(lst.at(0).path()); //selectByFile(lst.at(0).path()); addPendingList(lst.at(i).toLocalFile()); } } } } void QgGrifoBeamUpForm::selectWatchDir(const QString& dName) { if (dName.isEmpty()) return; QDir dir(dName); if (!dir.isReadable()) return; ui->leDir->setText(dName); fileWatcher.removePaths(fileWatcher.directories()); fileWatcher.addPath(dName); props.setProperty("watchedDirectory", dName); watchedFiles.clear(); watchedFiles=dir.entryList(QDir::Files|QDir::NoDotAndDotDot); } void QgGrifoBeamUpForm::addPendingList(const QString& file) { pendingList.append(file); if (state==0) { stateReady(); //ui->leFile->setText(lst.at(0).path()); selectByFile(file); //lst.at(0).path()); //uploadGo(); } } void QgGrifoBeamUpForm::showMessage(const QString& msg) { ui->progressLabel->setText(msg); ui->leMsg->appendPlainText(msg); } QString ShowFileInfo(const QString& fname, bool popup) { DownloadableFile df; df.open(fname); BinaryFileInfo bfi=df.info(); BinaryInfo bi=bfi.binaryInfo; QString infoText= "File: "+bfi.filename+"

\n" +"  Size: "+QString("%1").arg(bfi.uncompressed_size)+" ("+QString("%1").arg(bfi.compressed_size)+")

\n" +"  Container hash: "+bfi.file_md5+"

\n" +"File CRC32: "+QString("%1").arg(bfi.zip_crc32, 0, 16).toUpper()+"

\n"; infoText+= " Name: "+bi.m_name+"

\n" +" Version: "+bi.m_version+" "+bi.m_bid+"

\n" +" Date: "+bi.m_date+"

\n" +" IBC: "+bi.m_ibc+"

\n" +" P/N: "+bi.m_pn+"

\n" +" Part Type: "+bi.m_partType+"

\n" +" Architecture: "+bi.m_pn+" - "+bi.m_archName+"

\n" +" Format: "+bi.m_fmtName+"

\n" +" Generator: "+bi.m_generator+"

\n" //+" Version: "+bi.m_bid+"

\n" +" Info: "+bi.m_usr+"

\n" +" Host: "+bi.m_host+"

\n" +" Signature: "+bi.m_md5+"

\n"; if (popup) QMessageBox::information(0, "File: "+QString("

")+bfi.sourcefile, infoText); return infoText; } void QgGrifoBeamUpForm::on_tbFileInfo_clicked() { ShowFileInfo(ui->leFile->text()); } void QgGrifoBeamUpForm::on_btnStart_clicked(bool checked) { //indivisuare il profilo da usare per le operazione di programmazione if (!getProfile(ui->sbSectorSize->value(),ui->sbBase->value())) { //profile not valid to program return; } profile.writeRamp = (ui->cbWriteRamp->checkState()==Qt::Checked); profile.verifyFinal = (ui->cbVerifyAll->checkState()==Qt::Checked); profile.verifySector = (ui->cbVerifySector->checkState()==Qt::Checked); profile.FileToSend = ui->leFile->text(); QString address = QString("%1-%2").arg(profile.address_start_area).arg(profile.address_stop_area); QString srio = QString("%1@%2:%3").arg(profile.slotAddress).arg(profile.ip).arg(profile.port); int spi = int(profile.spiport); _dbHistory->addNewFile(profile.FileToSend, db_error_no_error, profile.fName, db_status_started, address, srio, spi); if (ui->cbSimulate->checkState()==Qt::Checked) { //è simulazione con dati di test if (checked) programmer->start(1, ui->sbSectorSize->value(), ui->sbBase->value()); else programmer->start(0, ui->sbSectorSize->value(), ui->sbBase->value()); } else { //non è simulazione programmer->start(profile); } } void QgGrifoBeamUpForm::statusUpdated(int sts, int progress, const QString& msg) { pgmSteps[sts].lbl->setText(msg); if (progress>0) ui->progressBar->setValue(progress); else if (progress==0) { } else { } } void QgGrifoBeamUpForm::on_btnStart_clicked() { } /*void QgGrifoBeamUpForm::on_pushButton_2_clicked() { }*/ /*void QgGrifoBeamUpForm::on_cbFPGA_currentIndexChanged(int index) { }*/ void QgGrifoBeamUpForm::on_btnReset_clicked() { //indivisuare il profilo da usare per le operazione di programmazione if (!getProfile(ui->sbSectorSize->value(),ui->sbBase->value())) { //profile not valid to program return; } profile.FileToSend = ui->leFile->text(); programmer->reset(profile); } void QgGrifoBeamUpForm::on_btnErase_clicked() { programmer->erase(1, ui->sbSectorSize->value(), ui->sbBase->value()); } void QgGrifoBeamUpForm::on_btnFlashID_clicked() { //indivisuare il profilo da usare per le operazione di programmazione if (!getProfile(ui->sbSectorSize->value(),ui->sbBase->value())) { //profile not valid to program return; } profile.FileToSend = ui->leFile->text(); programmer->readFlashID(profile); } void QgGrifoBeamUpForm::on_btnGetStatus_clicked() { //indivisuare il profilo da usare per le operazione di programmazione if (!getProfile(ui->sbSectorSize->value(),ui->sbBase->value())) { //profile not valid to program return; } profile.FileToSend = ui->leFile->text(); programmer->readStatusSPI(profile); } void QgGrifoBeamUpForm::on_btnFinish_clicked() { //indivisuare il profilo da usare per le operazione di programmazione if (!getProfile(ui->sbSectorSize->value(),ui->sbBase->value())) { //profile not valid to program return; } profile.FileToSend = ui->leFile->text(); programmer->terminate(profile); } void QgGrifoBeamUpForm::on_cbSimulate_clicked(bool checked) { programmer->setSimulate(checked); } void QgGrifoBeamUpForm::on_tbGo_clicked() { } void QgGrifoBeamUpForm::clearTargets() { memset(&targets, 0, sizeof targets); } //*********************************************************************** // update Grifo Download Site // Input parameters: checked = true if I also have to view the golden area of the flash // false if I have to display only the user area of the flash // Returns: //*********************************************************************** void QgGrifoBeamUpForm::updateGrifoDownloadSite(Qt::CheckState checked) { //clear targets struct clearTargets(); //clear treewidget for targets entitiesForm->clear(); QString ip = ""; //for every targets read from configuration files for (int i = 0; isite, 0, sizeof s->site); bsk_download_site_t* site=&s->site; strncpy(site->address, tgt.slotAddress.toLatin1(), sizeof site->address); //int r=bsk_tftp_mfs_decode_site(site, msg.toLatin1().constData()); //site->media_address=ip; //site->media_port=port; s->tgt=&tgt; s->site.media_address=QHostAddress(ip).toIPv4Address(); s->site.media_port=tgt.port; //50069; strncpy(s->site.name, tgt.appName.toLatin1().constData(), sizeof s->site.name); ++targets.valid; entitiesForm->addSite(s); } } } } //*********************************************************************** // Read config file // Input parameters: // Returns: //*********************************************************************** void QgGrifoBeamUpForm::readConfigFile() { QSettings& xs=settings; xs.beginGroup("GrifoBeamUp"); QString tgtlist=xs.value("tgtlist", QString("./grifo_beamup_targets.ini")).toString(); xs.endGroup(); QFileInfo finfo(tgtlist); if (!finfo.isReadable()) { tgtlist=":/settings/targets.ini"; } QSettings config(tgtlist, QSettings::IniFormat); //DEFAULT SECTION config.beginGroup("default"); QString def_ip = config.value("ip", QString("192.168.2.100")).toString(); int def_port = config.value("port", 69).toInt(); QString def_part = config.value("section", QString("OPER")).toString(); QString def_target = config.value("defTarget", QString("TGT-0")).toString(); config.endGroup(); default_ip = def_ip; //TARGET GROUP QStringList groups=config.childGroups(); foreach(QString g, groups) { if (g.startsWith("TGT", Qt::CaseInsensitive)) { config.beginGroup(g); QString appName = config.value("appName").toString(); QString tgtSection = g; QString slotAddress = config.value("slotAddress", QString()).toString(); QString name = config.value("name", QString("CPU")).toString(); QString part = config.value("section", def_part).toString(); QString filePrefix = config.value("filePrefix").toString(); QString description = config.value("description").toString(); QString arch = config.value("arch", QString("?")).toString(); int port = config.value("port", def_port).toInt(); QString ip = config.value("ip", def_ip).toString(); slotAddress=slotAddress.remove('$'); QString address_start_area = config.value("addressStartArea", QString()).toString(); QString address_stop_area = config.value("addressStopArea", QString()).toString(); flash_firmware_area_t firmware_area = (flash_firmware_area_t)config.value("area", flash_firmware_area_user).toInt(); flash_type_t type = (flash_type_t)config.value("type", flash_type_xcku040).toInt(); reg_moder_byteaddress_t byteaddress= (reg_moder_byteaddress_t)config.value("3_4Byte", bytes3address).toInt(); reg_moder_qspiport_t spiPort = (reg_moder_qspiport_t)config.value("spiPort", primarySpiPort).toInt(); config.endGroup(); TgtMatch* tgt=tgtMatchSet.add( appName, slotAddress, name, part, filePrefix, description, arch, address_start_area, address_stop_area, firmware_area, type, byteaddress, spiPort, ip, port, tgtSection); if ((ui->cb_GoldenFlash->checkState()==Qt::Checked) || (ui->cb_GoldenFlash->checkState()==Qt::Unchecked && firmware_area!=flash_firmware_area_golden)) { MyDebug().logMsg(type_log_info, origin_msg_generic, QString("%1 %2 %3 %4 %5 %6").arg(g).arg(appName).arg(slotAddress).arg(name).arg(filePrefix).arg(arch)); QHostAddress ha(ip); if (ha.toIPv4Address()<256) { QHostAddress dha(def_ip); auto tmp=dha.toIPv4Address() & 0xFFFFFF00; tmp|=ha.toIPv4Address(); ip=QHostAddress(tmp).toString(); } //Site {//Site QgGrifoDownloadSite* s=&targets.sites[targets.valid]; memset(&s->site, 0, sizeof s->site); bsk_download_site_t* site=&s->site; strncpy(site->address, slotAddress.toLatin1(), sizeof site->address); //int r=bsk_tftp_mfs_decode_site(site, msg.toLatin1().constData()); //site->media_address=ip; //site->media_port=port; s->tgt=tgt; s->site.media_address=QHostAddress(ip/*"192.168.2.101"*/).toIPv4Address(); s->site.media_port=port; //50069; strncpy(s->site.name, tgt->appName.toLatin1().constData(), sizeof s->site.name); ++targets.valid; entitiesForm->addSite(s); }//Site } entitiesForm->setDefaultTarget(def_target); } else { MyDebug().logMsg(type_log_info, origin_msg_generic, QString("? %1").arg(g)); } } entitiesForm->setVisible(true); } void QgGrifoBeamUpForm::on_cb_GoldenFlash_stateChanged() { updateGrifoDownloadSite(ui->cb_GoldenFlash->checkState()); } //*********************************************************************** // Show target info // Input parameters: // popup = display the dialog box // Returns: the complete string of target information //*********************************************************************** QString QgGrifoBeamUpForm::ShowTargetInfo(bool popup) { QString fName = entitiesForm->getFirstSelectedTarget(); const TgtMatch* tgt=tgtMatchSet.lookupAppName(fName); if (!tgt) return QString(""); QString infoText= "Target: "+fName+"

\n" +"   Description: "+QString("%1").arg(tgt->description)+"

\n" +"   appName: "+QString("%1").arg(tgt->appName)+"

\n" +"   Name: "+QString("%1").arg(tgt->tgtName)+"

\n" +"   Arch: "+QString("%1").arg(tgt->archName)+"

\n" +"   Slot Address: "+QString("%1").arg(tgt->slotAddress)+"

\n" +"   IP:PORT: "+QString("%1").arg(tgt->ip)+":"+QString("%1").arg(tgt->port)+"

\n" +"

\n" +" FLASH:

\n"; if (tgt->type==flash_type_xcku040) { infoText+= " ->  Type: XCKU040

\n"; } else if(tgt->type==flash_type_xcku060) { infoText+= " ->  Type: XCKU060

\n"; } else { infoText+= " ->  Type: XC7A200

\n"; } if (tgt->firmware_area==flash_firmware_area_golden) { infoText+= " ->  Firmware area: GOLDEN

\n"; } else { infoText+= " ->  Firmware area: USER

\n"; } if (tgt->byteaddress==bytes3address) { infoText+= " ->  Address: 3 bytes address

\n"; } else { infoText+= " ->  Address: 4 bytes address

\n"; } infoText+= " ->  Start-Stop address: "+QString("%1").arg(tgt->address_start_area)+"-"+QString("%1").arg(tgt->address_stop_area)+"

\n"; if (tgt->spiPort==primarySpiPort) { infoText+= " ->  SPI port: use primary SPI interface port

\n"; } else { infoText+= " ->  SPI port: use secondary SPI interface port

\n"; } if (popup) QMessageBox::information(0, "Target: "+fName, infoText); return infoText; } void QgGrifoBeamUpForm::on_btnGetTargetInfo_clicked() { ShowTargetInfo(true); } //*********************************************************************** // Set profile, read information form selected fpga // Input parameters: // Returns: //*********************************************************************** bool QgGrifoBeamUpForm::getProfile(unsigned int sectorSize, unsigned int baseOffset) { QString fName = entitiesForm->getFirstSelectedTarget(); const TgtMatch* tgt=tgtMatchSet.lookupAppName(fName); if (!tgt) { return false; } profile.fName = fName; bool bStatus= false; profile.address_start_area = QString(tgt->address_start_area).toUInt(&bStatus, 16); if (!bStatus) { return false; } profile.address_stop_area = tgt->address_stop_area.toUInt(&bStatus, 16); if (!bStatus) { return false; } profile.BaseAddress = tgt->address_start_area.toUInt(&bStatus, 16); if (!bStatus) { return false; } profile.BaseOffset = baseOffset; profile.byteddress = tgt->byteaddress; profile.ip = tgt->ip; profile.port = tgt->port; profile.SectorSize_KBytes = sectorSize; profile.slotAddress = tgt->slotAddress; profile.spiport = tgt->spiPort; if (tgt->type==flash_type_xcku040) { //xcku040 profile.dimMbit = FLASH_128Mbit; } else { //xc7a200 and xcku060 profile.dimMbit = FLASH_256Mbit; } profile.writeRamp = (ui->cbWriteRamp->checkState()==Qt::Checked); profile.verifyFinal = (ui->cbVerifyAll->checkState()==Qt::Checked); profile.verifySector = (ui->cbVerifySector->checkState()==Qt::Checked); return true; } void QgGrifoBeamUpForm::on_cb_TargetAddress_clicked(bool checked) { programmer->setSRIOMemory(checked); } void QgGrifoBeamUpForm::on_btnGetValue_clicked() { QString address = ui->sbGetValue->text(); unsigned int len=256; char data[len]; uint32_t dataInt[256]; //legge mediante srio un valore presente in memoria all'indirizzo indicato QString remoteFile=QString("$SRIO:%1/%2+%3").arg(profile.slotAddress).arg(address, 0, 16).arg(len); MyDebug().logMsg(type_log_info, origin_msg_srio, QString("Command %1").arg(remoteFile)); try { Q_EMIT programmer->readRequest(remoteFile, dataInt, len); //programmer->waitRxEvent(); } catch (...) { MyDebug().logMsg(type_log_error, origin_msg_tftp, "not inizialized"); } sprintf (data, "0x%8.8lX", (long unsigned int)dataInt[0]); ui->lblGetValue->setText(data); } void QgGrifoBeamUpForm::on_btnMem_clicked() { ui->sbGetValue->setText(QString("0x%1").arg(BASE_ADDRESS_MEM,0,16)); } void QgGrifoBeamUpForm::on_btnFPGA_clicked() { ui->sbGetValue->setText(QString("0x%1").arg(BASE_ADDRESS_IF,0,16)); } void QgGrifoBeamUpForm::on_btnHistory_clicked() { HistoryDBForm HistoryDBWindow; HistoryDBWindow.setWindowTitle("History DB"); HistoryDBWindow.setDB(_dbHistory); HistoryDBWindow.exec(); } void QgGrifoBeamUpForm::on_btnAddHistory_clicked() { //(QString _file, db_error_t _error, QString _where) QString fileName = ui->leFile->text(); db_error_t _error = db_error_t(ui->cbError->currentIndex()); db_status_t _status = db_status_t(ui->cbStatus->currentIndex()); QString fName = entitiesForm->getFirstSelectedTarget(); const TgtMatch* tgt=tgtMatchSet.lookupAppName(fName); if (!tgt) return; QString address = QString("%1-%2").arg(tgt->address_start_area).arg(tgt->address_stop_area); QString srio = QString("%1@%2:%3").arg(tgt->slotAddress).arg(tgt->ip).arg(tgt->port); int spi = int(tgt->spiPort); _dbHistory->addNewFile(fileName, _error, fName, _status, address, srio, spi); }