All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Signals | Public Member Functions | Protected Member Functions
GeopsyCore::CityScanner Class Reference

Brief description of class still missing. More...

#include <CityScanner.h>

Inheritance diagram for GeopsyCore::CityScanner:
QGpCoreTools::Thread

List of all members.

Signals

void signalsChanged ()

Public Member Functions

const CitySignalat (int index) const
 CityScanner (QObject *parent=0)
void cleanStop ()
void clear ()
int count ()
void erase ()
QFile * readStream ()
bool setPath (const QDir &cardPath)
QString softwareVersion () const
 ~CityScanner ()

Protected Member Functions

QFile * fichbaseStream (const QDir &cardPath, QIODevice::OpenModeFlag mode)
void normalScan ()
virtual void run ()
QFile * sectcityStream (const QDir &cardPath, QIODevice::OpenModeFlag mode)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

GeopsyCore::CityScanner::CityScanner ( QObject *  parent = 0)

Description of constructor still missing

References TRACE.

                                         : Thread(parent)
{
  TRACE;
  _softwareVersion="????";
  _stopRequest=false;
  _stream=0;
}

References clear(), and TRACE.

{
  TRACE;
  clear();
}

Member Function Documentation

const CitySignal* GeopsyCore::CityScanner::at ( int  index) const [inline]

Referenced by GeopsyGui::CitySignalItem::data(), and GeopsyGui::CityLoader::on_loadBut_clicked().

{return _signals.at(index);}

References TRACE.

Referenced by clear(), GeopsyGui::CityLoader::on_clearBut_clicked(), GeopsyGui::CityLoader::on_closeBut_clicked(), and GeopsyGui::CityLoader::on_loadBut_clicked().

{
  TRACE;
  if(isRunning()) {
    _stopRequest.fetchAndStoreOrdered(true);
    wait();
  }
}

References cleanStop(), signalsChanged(), and TRACE.

Referenced by GeopsyGui::CityLoader::on_unmountBut_clicked(), setPath(), and ~CityScanner().

{
  TRACE;
  cleanStop();
  _cardPath=QDir();
  qDeleteAll(_signals);
  _signals.clear();
  emit signalsChanged();
  if(_stream) {
    delete _stream;
    _stream=0;
  }
}

Set files as erased and init card for new files (flash card is modified)

References count(), QGpCoreTools::endl(), GeopsyCore::CitySignal::erase(), fichbaseStream(), sectcityStream(), signalsChanged(), QGpCoreTools::tr(), and TRACE.

Referenced by GeopsyGui::CityLoader::on_clearBut_clicked().

{
  TRACE;
  QFile * f;
  f=fichbaseStream(_cardPath, QIODevice::ReadWrite);
  if(f) {
    int n=count();
    for(int i=0;i < n;i++ ) {
      CitySignal * sig=_signals.at(i);
      if(!sig->erase(f)) {
        App::stream() << tr("Cannot write to flash card");
      }
    }
    delete f;
  } else {
    App::stream() << tr("Cannot open fichbase in %1").arg(_cardPath.path()) << endl;
  }
  f=sectcityStream(_cardPath, QIODevice::ReadWrite);
  if(f) {
    // Format:
    // 24 bytes   "CARTE FLASH NEUVE       "
    // 8 bytes    ASCII Hexadecimal for flash card size
    // 2016 bytes null characters
    f->write("CARTE FLASH NEUVE       ", 24);
    f->seek(32);
    char nullChars[2016];
    memset(nullChars, 0, 2016);
    f->write(nullChars, 2016);
    delete f;
  } else {
    App::stream() << tr("Cannot open sectcity in %1").arg(_cardPath.path()) << endl;
  }
  emit signalsChanged();
}
QFile * GeopsyCore::CityScanner::fichbaseStream ( const QDir &  cardPath,
QIODevice::OpenModeFlag  mode 
) [protected]

References QGpCoreTools::endl(), QGpCoreTools::tr(), and TRACE.

Referenced by erase(), and setPath().

{
  TRACE;
  QFile * f=new QFile(cardPath.absoluteFilePath("fichbase.dat"));
  if( !f->open(mode) ) {
    f->setFileName(cardPath.absoluteFilePath("FICHBASE.DAT"));
    if( !f->open(mode) ) {
      App::stream(this) << tr(" # Error # Cannot open file %1 or %2.")
                             .arg(cardPath.absoluteFilePath("fichbase.dat"))
                             .arg(cardPath.absoluteFilePath("FICHBASE.DAT")) << endl;
      delete f;
      return 0;
    } else {
      App::stream(this) << tr("Opening file %1.").arg(cardPath.absoluteFilePath("FICHBASE.DAT")) << endl;
    }
 } else {
    App::stream(this) << tr("Opening file %1.").arg(cardPath.absoluteFilePath("fichbase.dat")) << endl;
  }
  return f;
}

Scan flash card until not finding anymore signal. Signals are suposed to be recorded one after the last one. No gap between files are accepted. This is the normal situation when recording with cityshark. The more complex scan achived by run() can recover partly over written data.

References QGpCoreTools::endl(), GeopsyCore::CitySignal::readHeader(), QGpCoreTools::tr(), and TRACE.

Referenced by run().

{
  TRACE;
  while(!_stream->atEnd()) {
    CitySignal * sig=new CitySignal;
    if(sig->readHeader(_stream, _softwareVersion.toInt())) {
      _signals.append(sig);
    }
    else {
      App::stream() << tr("         %1 files are read from flash card.").arg(_signals.count()) << endl;
      delete sig;
      break;
    }
    if(_stopRequest.testAndSetOrdered(true,true)) return;
  }
}

Referenced by GeopsyGui::CityLoader::on_loadBut_clicked().

{return fichbaseStream(_cardPath, QIODevice::ReadOnly);}
void GeopsyCore::CityScanner::run ( ) [protected, virtual]

Scan flash card until reaching the end of file. The complex scan can recover partly over written data.

References BLOCK_SIZE, QGpCoreTools::endl(), normalScan(), signalsChanged(), QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  if(!_stream) return;
  char currentBlock[BLOCK_SIZE+1];
  currentBlock[BLOCK_SIZE]='\0';
  // Read software version
  readSoftwareVersion();
  while(!_stream->atEnd()) {
    //  DEB, DEB2, ERASED or ERASED2
    qint64 pos=_stream->pos();
    _stream->read(currentBlock, BLOCK_SIZE);
    if(strncmp(currentBlock,"DEB",3)==0 || strncmp(currentBlock,"ERASED",6)==0) {
      _stream->seek(_stream->pos()-9);
      normalScan();
      emit signalsChanged();
    } else {
      _stream->seek(pos+1);
    }
    if(_stopRequest.testAndSetOrdered(true,true)) {
      delete _stream;
      _stream=0;
      return;
    }
  }
  delete _stream;
  _stream=0;
  App::stream() << tr("         scan of flash card finished.") << endl;
}
QFile * GeopsyCore::CityScanner::sectcityStream ( const QDir &  cardPath,
QIODevice::OpenModeFlag  mode 
) [protected]

References QGpCoreTools::endl(), QGpCoreTools::tr(), and TRACE.

Referenced by erase().

{
  TRACE;
  QFile * f=new QFile(cardPath.absoluteFilePath("sectcity.hex"));
  if( !f->open(mode)) {
    f->setFileName(cardPath.absoluteFilePath("SECTCITY.HEX"));
    if( !f->open(mode)) {
      App::stream(this) << tr(" # Error # Cannot open file %1 or %2.")
                             .arg(cardPath.absoluteFilePath("sectcity.hex"))
                             .arg(cardPath.absoluteFilePath("SECTCITY.HEX")) << endl;
      delete f;
      return 0;
    } else {
      App::stream(this) << tr("Opening file %1.").arg(cardPath.absoluteFilePath("SECTCITY.HEX")) << endl;
    }
 } else {
    App::stream(this) << tr("Opening file %1.").arg(cardPath.absoluteFilePath("sectcity.hex")) << endl;
  }
  return f;
}
bool GeopsyCore::CityScanner::setPath ( const QDir &  cardPath)

Set path for cityshark. If scanner is running, it stops it. After setting the path, scanner is automatically started.

References clear(), fichbaseStream(), QGpCoreTools::Thread::start(), and TRACE.

Referenced by GeopsyGui::CityLoader::scan().

{
  TRACE;
  // Check if a scanner is already running and stop it
  clear();
  // Try to access flash card in the new location
  QFile * f=fichbaseStream(cardPath, QIODevice::ReadOnly);
  if(!f) return false;
  // Set flash card path
  _cardPath=cardPath;
  _stream=f;
  _stopRequest=false;
  start();
  return true;
}

Referenced by clear(), erase(), and run().

QString GeopsyCore::CityScanner::softwareVersion ( ) const [inline]
{return _softwareVersion;}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines