ReceiverThread::ReceiverThread(boatReal * parent) { qRegisterMetaType<nmeaINFO>("nmeaINFO"); connect(this,SIGNAL(updateBoat(nmeaINFO)),parent,SLOT(updateBoat(nmeaINFO))); connect(this,SIGNAL(finished()),parent,SLOT(slot_threadStartedOrFinished())); connect(this,SIGNAL(started()),parent,SLOT(slot_threadStartedOrFinished())); port=NULL; //initPort(); this->parent=parent; nmea_zero_INFO(&info); nmea_parser_init(&parser); if(parser.buff_size==0) qWarning()<<"no parser!!!"; this->listNMEA=NULL; }
void update(Boat boats[], Fish *fishes, int *fishesInCell,double dt){ // This should all be separate for each of the processes // So one process each for each of the cells, // and a process each for the captains. for(int j = 0; j < GRIDCELLS; j++){ for(int i =0; i < fishesInCell[j];i++){ updateFish(boats,&fishes[FISHCOORD(j,i)],dt); } } for(int i = 0; i < NUMBOATS; i++){ updateBoat(&boats[i]); } }
void ReceiverThread::run() { //qWarning() << "Starting thread loop (1)"; int numBytes = 0; int l = 512; #ifndef GPS_FILE if(!port ||(port && !port->isOpen())) { qWarning()<<"anomaly 1"; if(port) { delete port; port=NULL; } /*retry to open the port*/ if(!this->initPort()) { qWarning() << "Port not open => not starting GPS thread"; if(port) port->close(); delete port; port=NULL; exit(); return; } } #else QFile fakeGPS("fakeGPS.data"); if(!fakeGPS.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning()<<"failed to open fakeGPS.data"; return; } #endif //qWarning() << "Starting thread loop (2)"; /*clear port*/ //port->readAll(); while (!parent->getPause() && port && port->isOpen()) { #ifndef GPS_FILE numBytes = port->bytesAvailable(); #else numBytes=513; #endif if(numBytes > l) { QByteArray buffer; #ifndef GPS_FILE while(port->bytesAvailable()>0) { buffer=buffer+port->read(512); } #else buffer.clear(); for(int pass=0;pass<50;++pass) { if(fakeGPS.atEnd()) { fakeGPS.seek(0); qWarning()<<"restarting fakeGPS file"; } buffer=fakeGPS.readLine(); #endif QList<QByteArray> lines=buffer.split('\n'); for (int n=0;n<lines.count();++n) { if(lines.at(n).count()>1) { #ifndef GPS_FILE QString temp=QString(lines.at(n).left(lines.at(n).length()-1)); #else QString temp=lines.at(n); #endif // if(temp.contains("RMC")) // qWarning()<<temp; #ifndef GPS_FILE QByteArray data=lines.at(n).left(lines.at(n).length()-1); #else QByteArray data=lines.at(n); #endif //data.replace("$II","$GP"); would have been good but... checksum data.push_back('\r' ); data.push_back('\n'); char * record=data.data(); nmea_parse(&parser, record, data.size(), &info); if(listNMEA) { listNMEA->addItem(temp); } } } emit updateBoat(info); #ifdef GPS_FILE } #endif } this->msleep(3000); } if(port) { if(port->isOpen()) port->close(); //qWarning()<<"deleting port"; delete port; port=NULL; } //qWarning() << "Exiting thread loop"; this->exit(); }