bool GpsClient::flarmBinMode() { // Binary switch command for Flarm interface const char* pflax = "$PFLAX\r\n"; FlarmBinComLinux fbc( fd ); // Precondition is that the NMEA output of the Flarm device was disabled by // the calling method before! // qDebug() << "Switch Flarm to binary mode"; // I made the experience, that the Flarm device did not answer to the first // binary transfer switch. Therefore I make several tries. Flarm tool makes // the same, as I could observe with a RS232 port sniffer. bool pingOk = false; int loop = 5; while( loop-- ) { // Switch connection to binary mode. if( write( fd, pflax, strlen(pflax) ) <= 0 ) { // write failed break; } // Check connection with a ping command. if( fbc.ping() == true ) { FlarmBase::setProtocolMode( FlarmBase::binary ); pingOk = true; break; } } if( pingOk == false ) { // Switch to binary mode failed qWarning() << "GpsClient::flarmBinMode(): Switch failed!"; } else { qDebug() << "GpsClient::flarmBinMode(): Switch Ok!"; } return pingOk; }
bool GpsClient::flarmReset() { qDebug() << "GpsClient::flarmReset()"; // Switch off timeout control last = QTime(); if( ! flarmBinMode() ) { last.start(); return false; } FlarmBinComLinux fbc( fd ); bool res = fbc.exit(); // Switch Flarm back to text mode. FlarmBase::setProtocolMode( FlarmBase::text ); activateTimeout = true; last.start(); return res; }
void test_solver(BfmSolver solver,LatticeFermion &src) { g5dParams parms; int Ls=8; double M5=1.8; double mq=0.01; double wilson_lo = 0.05; double wilson_hi = 6.8; double shamir_lo = 0.025; double shamir_hi = 1.7; double ht_scale=2.0; double hw_scale=1.0; if ( solver == HtCayleyTanh ) { Printf("Testing HtCayleyTanh aka DWF\n"); parms.ShamirCayleyTanh(mq,M5,Ls); } else if ( solver == HmCayleyTanh ) { parms.ScaledShamirCayleyTanh(mq,M5,Ls,ht_scale); Printf("Testing HmCayleyTanh Moebius\n"); } else if ( solver == HwCayleyTanh ) { parms.WilsonCayleyTanh(mq,M5,Ls,hw_scale); Printf("Testing HwCayleyTanh aka Borici\n"); } else { exit(-1); } multi1d<LatticeColorMatrix> u(4); HotSt(u); multi1d<LatticeFermion> X(Ls); multi1d<LatticeFermion> Y(Ls); for(int s=0;s<Ls;s++){ gaussian(X[s]); gaussian(Y[s]); } multi1d<LatticeColorMatrix> Fb(4); multi1d<LatticeColorMatrix> F (4); int lx = QDP::Layout::subgridLattSize()[0]; int ly = QDP::Layout::subgridLattSize()[1]; int lz = QDP::Layout::subgridLattSize()[2]; int lt = QDP::Layout::subgridLattSize()[3]; multi1d<int> procs = QDP::Layout::logicalSize(); /******************************************************** * Setup DWF operator ******************************************************** */ bfmarg dwfa; dwfa.node_latt[0] = lx; dwfa.node_latt[1] = ly; dwfa.node_latt[2] = lz; dwfa.node_latt[3] = lt; for(int mu=0;mu<4;mu++){ if ( procs[mu]>1 ) { dwfa.local_comm[mu] = 0; } else { dwfa.local_comm[mu] = 1; } } bfm_qmp dwf_qmp; dwfa.mass = parms.mass; dwfa.M5 = parms.M5; dwfa.Csw = 0.0; dwfa.precon_5d=0; dwfa.residual=1.0e-5; dwfa.max_iter=5000; dwfa.Ls = parms.Ls; dwfa.solver= parms.solver; dwfa.zolo_lo = parms.zolo_lo; dwfa.zolo_hi = parms.zolo_hi; dwfa.mobius_scale = parms.mobius_scale; dwf_qmp.init(dwfa); dwf_qmp.importGauge(u); Fermion_t X_t; Fermion_t Y_t; Matrix_t Force_t[2]; X_t = dwf_qmp.allocFermion(); Y_t = dwf_qmp.allocFermion(); for(int cb=0;cb<2;cb++){ Force_t[cb] = dwf_qmp.allocMatrix(); printf("Force_t pointer %lx\n",Force_t[cb]); } multi1d<int> bcs(Nd); bcs[0] = bcs[1] = bcs[2] = bcs[3] = 1; Handle<FermBC<T,U,U> > fbc(new SimpleFermBC< T, U, U >(bcs)); Handle<CreateFermState<T,U,U> > cfs( new CreateSimpleFermState<T,U,U>(fbc)); Handle<FermState<T,U,U> > fs ((*cfs)(u)); //! Params for NEFF EvenOddPrecKNOFermActArrayParams kparams; Real scale = dwf_qmp.mobius_scale; kparams.OverMass = dwf_qmp.M5; kparams.Mass = dwf_qmp.mass; kparams.a5 = 1.0; kparams.coefs.resize(Ls); for(int s=0;s<Ls;s++) kparams.coefs[s] = scale; kparams.N5 = dwf_qmp.Ls; EvenOddPrecKNOFermActArray FA(cfs,kparams); Handle< DiffLinearOperatorArray<Phi,P,Q> > M(FA.linOp(fs)); for( int dag=0;dag<2;dag++){ Fb=zero; F=zero; dwf_qmp.importFermion(X,X_t,1); dwf_qmp.importFermion(Y,Y_t,1); dwf_qmp.zeroMatrix(Force_t[0]); dwf_qmp.zeroMatrix(Force_t[1]); dwf_qmp.MprecDeriv(X_t,Y_t,Force_t,dag); for(int cb=0;cb<2;cb++) dwf_qmp.exportForce(Force_t[cb],Fb,cb); Printf("Calling S_f deriv\n"); if( dag==1 ) M->deriv(F, X, Y, MINUS); else M->deriv(F, X, Y, PLUS); for(int mu=0;mu<4;mu++){ QDPIO::cout << "dag "<< dag<<"mu "<<mu<<" n2diff " << norm2(Fb[mu]-F[mu])<<endl; } #if 0 QDPIO::cout << "Calling force term" << endl; dwf_qmp.zeroMatrix(Force_t[0]); dwf_qmp.zeroMatrix(Force_t[1]); dwf_qmp.TwoFlavorRatioForce(X_t,Force_t,1.0,dwf_qmp.mass); for(int cb=0;cb<2;cb++) dwf_qmp.exportForce(Force_t[cb],Fb,cb); for(int mu=0;mu<4;mu++){ QDPIO::cout << "dag "<< dag<<"mu "<<mu<<" TwoFlavorForce " << norm2(Fb[mu])<<endl; } #endif // { // EvenOddPrecConstDetTwoFlavorRatioConvConvWilsonTypeFermMonomial5D Monomial(); // } } dwf_qmp.freeMatrix(Force_t[0]); dwf_qmp.freeMatrix(Force_t[1]); exit(0); }
void GpsClient::getFlarmIgcFiles(QString& args) { // The argument string contains at the first position the destination directory // for the files and then the indexes of the flights separated by vertical tabs. QStringList idxList = args.split("\v"); if( idxList.size() < 2 ) { return; } // Switch off timeout control last = QTime(); FlarmBinComLinux fbc( fd ); if( flarmBinMode() == false ) { flarmFlightDowloadInfo( "Error" ); return; } // read out flights char buffer[MAXSIZE]; int progress = 0; // Check, if the download directory exists. Here we take the directory element // from the list. QDir igcDir( idxList.takeFirst() ); if( ! igcDir.exists() ) { if( ! igcDir.mkpath( igcDir.absolutePath() ) ) { flarmFlightDowloadInfo( "Error create directory" ); return; } } QTime dlTime; for( int idx = 0; idx < idxList.size(); idx++ ) { dlTime.start(); downloadTimeControl.start(); // Select the flight to be downloaded int recNo = idxList.at(idx).toInt(); QStringList flightData; if( fbc.selectRecord(recNo ) == true ) { // read flight header data if( fbc.getRecordInfo( buffer ) ) { flightData = QString( buffer ).split("|"); } else { // Entry not available, although select answered positive! // Not conform to the specification. flarmFlightDowloadInfo( "Error" ); return; } // Open an IGC file for writing download data. QFile f( igcDir.absolutePath() + "/" + flightData.at(0) ); if( ! f.open( QIODevice::WriteOnly ) ) { // could not open file ... qWarning() << "Cannot open file: " << f.fileName(); flarmFlightDowloadInfo( "Error open file" ); return; } int lastProgress = -1; bool eof = false; while( fbc.getIGCData(buffer, &progress) ) { if( lastProgress != progress || downloadTimeControl.elapsed() >= 10000 ) { // After a certain time a progress must be reported otherwise // the GUI thread runs in a timeout. downloadTimeControl.start(); // That eliminates a lot of intermediate steps flarmFlightDowloadProgress(recNo, progress); lastProgress = progress; } if( buffer[strlen(buffer) - 1] == 0x1A ) { // EOF was send by the Flarm, remove it from the data stream. buffer[strlen(buffer) - 1] = '\0'; eof = true; } f.write(buffer); if( eof ) { break; } } f.close(); if( eof == false ) { // Abort downloads due to timeout error flarmFlightDowloadInfo( "Error" ); return; } qDebug() << flightData.at(0) << "downloaded in" << (dlTime.elapsed() / 1000.0) << "s"; } } flarmFlightDowloadInfo( "Finished" ); }
void GpsClient::getFlarmFlightList() { // Switch off timeout control last = QTime(); FlarmBinComLinux fbc( fd ); if( flarmBinMode() == false ) { flarmFlightListError(); return; } // read out flight header records int recNo = 0; char buffer[MAXSIZE]; int flights = 0; while( true ) { if( fbc.selectRecord( recNo ) == true ) { recNo++; if( fbc.getRecordInfo( buffer ) ) { // Send every flight header to the application. That is done in this // way because the read out of the whole flight list can take different // times in dependency of the UART transfer speed and the amount of // entries. If the time is too long, a timeout will raise an error // box in the GUI thread. QByteArray ba( MSG_FLARM_FLIGHT_LIST_RES ); ba.append( " " ); ba.append( buffer ); writeForwardMsg( ba.data() ); flights++; } else { qWarning() << "GpsClient::getFlarmFlightList(): GetRecordInfo(" << (recNo - 1) << ") failed!"; break; } } else { // No more records available break; } } QByteArray ba( MSG_FLARM_FLIGHT_LIST_RES ); if( flights == 0 ) { // The flight list in Flarm is empty. ba.append( " Empty" ); } else { // All flight headers are transfered. ba.append( " End" ); } writeForwardMsg( ba.data() ); }