Changeset 831

Show
Ignore:
Timestamp:
08/17/08 19:24:57 (3 months ago)
Author:
liamstask
Message:

setting externals prop

Location:
mchelper/branches/v25/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • mchelper/branches/v25/src

  • mchelper/branches/v25/src/Inspector.cpp

    r588 r831  
    197197  webserverBox->setForegroundRole( role ); // same... 
    198198} 
     199 
     200 
     201 
  • mchelper/branches/v25/src/MainWindow.cpp

    r655 r831  
    317317} 
    318318 
     319void MainWindow::statusMsg(QString msg, int duration) 
     320{ 
     321  statusBar()->showMessage(msg, duration); 
     322} 
     323 
    319324QColor MainWindow::msgColor(MsgType::Type type) 
    320325{ 
  • mchelper/branches/v25/src/Uploader.cpp

    r588 r831  
    11 
    2 #include <QTextStream> 
     2#include <QFileInfo> 
    33#include <QSettings> 
    44#include "Uploader.h" 
     
    1414{ 
    1515  this->mainWindow = mainWindow; 
    16   uploaderProgress = new QProgressDialog("Uploading...", "Cancel", 0, 100); 
    17   connect(uploaderProgress, SIGNAL(canceled()), this, SLOT(terminate())); 
    18   connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); 
    19   connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readError())); 
     16  uploaderProgress = new QProgressDialog(); 
     17  connect(uploaderProgress, SIGNAL(canceled()), this, SLOT(kill())); 
     18  connect(uploaderProgress, SIGNAL(finished(int)), this, SLOT(onProgressDialogFinished(int))); 
     19  connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(filterOutput())); 
     20  connect(this, SIGNAL(readyReadStandardError()), this, SLOT(filterError())); 
    2021  connect(this, SIGNAL(started()), this, SLOT(uploadStarted())); 
    2122  connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(uploadFinished(int, QProcess::ExitStatus))); 
     23  connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError))); 
    2224} 
    2325 
     
    2628  QSettings settings("MakingThings", "mchelper"); 
    2729  QString uploaderName = settings.value("sam7_path", DEFAULT_SAM7_PATH).toString(); 
     30  currentFile = filename; 
    2831  QStringList uploaderArgs; 
    29   uploaderArgs << "flash " + filename << "boot_from_flash"; 
     32  uploaderArgs << "-e" << "set_clock"; 
     33  uploaderArgs << "-e" << "unlock_regions"; 
     34  uploaderArgs << "-e" << QString("flash -show_progress %1").arg(currentFile); 
     35  uploaderArgs << "-e" << "boot_from_flash"; 
     36  uploaderArgs << "-e" << "reset"; 
    3037  start(uploaderName, uploaderArgs); 
    3138} 
    3239 
    33 void Uploader::readOutput( ) 
     40void Uploader::filterOutput( ) 
    3441{ 
    35   //mainWindow->printOutput(readAll()); 
    36   printf( "sam7: %s", qPrintable(QString(readAll()))); 
    37 //  QTextStream in(uploader); 
    38 //  QString line = in.readLine(); 
    39 //  while (!line.isNull()) 
    40 //  { 
    41 //    mainWindow->printOutput(line.append("\n")); 
    42 //    line = in.readLine(); 
    43 //  }  
     42  QString output(readAllStandardOutput()); 
     43  QRegExp re("upload progress: (\\d+)%"); 
     44  int pos = 0; 
     45  bool matched = false; 
     46  while((pos = re.indexIn(output, pos)) != -1) 
     47  { 
     48    int progress = re.cap(1).toInt(); 
     49    if(progress != uploaderProgress->value()) 
     50      uploaderProgress->setValue(progress); 
     51    pos += re.matchedLength(); 
     52    matched = true; 
     53  } 
     54  if(!matched) 
     55    qDebug("upload output: %s", qPrintable(output)); 
    4456} 
    4557 
    46 void Uploader::readError( ) 
     58void Uploader::filterError( ) 
    4759{ 
    48   //mainWindow->printOutputError(readAll()); 
    49 //  QTextStream in(uploader); 
    50 //  QString line = in.readLine(); 
    51 //  while (!line.isNull()) 
    52 //  { 
    53 //    mainWindow->printOutputError(line.append("\n")); 
    54 //    line = in.readLine(); 
    55 //  }  
     60  QString err(readAllStandardError()); 
     61  if(err.startsWith("can't find boot agent")) 
     62    mainWindow->statusMsg("Error - couldn't find an unprogrammed board to upload to."); 
     63  else 
     64    qDebug("upload err: %s", qPrintable(err)); 
    5665} 
    5766 
    5867void Uploader::uploadStarted( ) 
    5968{ 
    60   uploaderProgress->show(); 
     69  QFileInfo fi(currentFile); 
     70  uploaderProgress->setLabelText(QString("Uploading %1...").arg(fi.fileName())); 
     71  uploaderProgress->show(); 
    6172} 
    6273 
     
    6576  (void)exitCode; 
    6677  (void)exitStatus; 
    67   uploaderProgress->hide(); 
    68   uploaderProgress->setValue(0); 
     78  uploaderProgress->reset(); 
    6979} 
     80 
     81/* 
     82  The uploader has reported an error. 
     83  Check what kind it was and print out a message to the user. 
     84*/ 
     85void Uploader::onError(QProcess::ProcessError error) 
     86{ 
     87  QString msg; 
     88  switch(error) 
     89  { 
     90    case QProcess::FailedToStart: 
     91      msg = "uploader failed to start.  sam7 is either missing, or doesn't have the correct permissions"; 
     92      break; 
     93    case QProcess::Crashed: 
     94      msg = "uploader (sam7) was canceled or crashed."; 
     95      break; 
     96    case QProcess::Timedout: 
     97      msg = "uploader (sam7) timed out."; 
     98      break; 
     99    case QProcess::WriteError: 
     100      msg = "uploader (sam7) reported a write error."; 
     101      break; 
     102    case QProcess::ReadError: 
     103      msg = "uploader (sam7) reported a read error."; 
     104      break; 
     105    case QProcess::UnknownError: 
     106      msg = "uploader (sam7) - unknown error type."; 
     107      break; 
     108  } 
     109  mainWindow->statusMsg("Error - " + msg); 
     110} 
     111 
     112/* 
     113  The progress dialog was clicked out of, instead of the the cancel button being hit. 
     114  Cancel it just the same. 
     115*/ 
     116void Uploader::onProgressDialogFinished(int result) 
     117{ 
     118  if(result == QDialog::Rejected && state() == QProcess::Running) 
     119    kill(); 
     120} 
     121 
     122 
     123 
     124 
  • mchelper/branches/v25/src/main.cpp

    r588 r831  
    1414  return app.exec(); 
    1515} 
     16 
     17