void Packet::setData(char* p_data, unsigned int p_size) { if (p_size <= PACKET_BUFFER_SIZE) { m_dataSize = p_size; memcpy(&m_data[0], p_data, p_size); readHeaderData(&m_data[0]); } else throw invalid_argument("Attempting to set data beyond the allowed data size (255)"); }
bool OpenAipPoiLoader::getHeaderData( QString &path, QString fileType, int fileVersion ) { QFile inFile(path); if( !inFile.open(QIODevice::ReadOnly) ) { qWarning("OpenAip: Cannot open file %s!", path.toLatin1().data()); return false; } QDataStream in(&inFile); in.setVersion( Q_DATA_STREAM ); bool ok = readHeaderData( in, fileType, fileVersion ); inFile.close(); return ok; }
bool OpenAipPoiLoader::readCompiledFile( QString &fileName, QList<RadioPoint>& navAidList ) { QTime t; t.start(); QFile inFile( fileName ); if( !inFile.open(QIODevice::ReadOnly) ) { qWarning("OAIP: Cannot open navAid file %s!", fileName.toLatin1().data()); return false; } QDataStream in( &inFile ); in.setVersion( Q_DATA_STREAM ); bool ok = readHeaderData( in, FILE_TYPE_NAV_AIDS_OAIP_C, FILE_VERSION_NAV_AIDS_C ); if( ok == false ) { inFile.close(); return false; } // read number of records in the file quint32 lrn; in >> lrn; // Preallocate list memory for new elements to be added. if( lrn ) { navAidList.reserve( navAidList.size() + lrn ); } quint8 type; QByteArray utf8_temp; WGSPoint wgsPos; QPoint position; float elevation; float inFrequency; float range; float declination; quint8 isAligned2TrueNorth; uint counter = 0; while( ! in.atEnd() ) { counter++; RadioPoint rp; in >> type; rp.setTypeID( static_cast<BaseMapElement::objectType>(type) ); // read long name ShortLoad(in, utf8_temp); rp.setName(QString::fromUtf8(utf8_temp)); // read short name ShortLoad(in, utf8_temp); rp.setWPName(QString::fromUtf8(utf8_temp)); // read the 2 letter country code ShortLoad(in, utf8_temp); rp.setCountry(QString::fromUtf8(utf8_temp)); // read ICAO ShortLoad(in, utf8_temp); rp.setICAO(QString::fromUtf8(utf8_temp)); // read comment ShortLoad(in, utf8_temp); rp.setComment(QString::fromUtf8(utf8_temp)); in >> wgsPos; rp.setWGSPosition(wgsPos); in >> position; rp.setPosition(position); in >> elevation; rp.setElevation(elevation); // Frequency in MHz in >> inFrequency; rp.setFrequency( inFrequency ); // Channel info ShortLoad(in, utf8_temp); rp.setChannel(QString::fromUtf8(utf8_temp)); // Service range as float in >> range; rp.setRange(range); // Declination in >> declination; rp.setDeclination(declination); // Aligned2TrueNorth in >> isAligned2TrueNorth; rp.setAligned2TrueNorth(isAligned2TrueNorth); // Add the radio point element to the list. navAidList.append( rp ); } inFile.close(); qDebug( "OAIP: %d navAids read from %s in %dms", counter, fileName.toLatin1().data(), t.elapsed() ); return true; }
bool OpenAipPoiLoader::readCompiledFile( QString &fileName, QList<Airfield>& airfieldList ) { QTime t; t.start(); QFile inFile( fileName ); if( !inFile.open(QIODevice::ReadOnly) ) { qWarning("OAIP: Cannot open airfield file %s!", fileName.toLatin1().data()); return false; } QDataStream in( &inFile ); in.setVersion( Q_DATA_STREAM ); bool ok = readHeaderData( in, FILE_TYPE_AIRFIELD_OAIP_C, FILE_VERSION_AIRFIELD_C ); if( ok == false ) { inFile.close(); return false; } // read number of records in the file quint32 lrn; in >> lrn; // Preallocate list memory for new elements to be added. if( lrn ) { airfieldList.reserve( airfieldList.size() + lrn ); } quint8 afType; QByteArray utf8_temp; WGSPoint wgsPos; QPoint position; float elevation; quint16 inFrequency; uint counter = 0; while( ! in.atEnd() ) { counter++; Airfield af; in >> afType; af.setTypeID( static_cast<BaseMapElement::objectType>(afType) ); // read long name ShortLoad(in, utf8_temp); af.setName(QString::fromUtf8(utf8_temp)); // read short name ShortLoad(in, utf8_temp); af.setWPName(QString::fromUtf8(utf8_temp)); // read the 2 letter country code ShortLoad(in, utf8_temp); af.setCountry(QString::fromUtf8(utf8_temp)); // read ICAO ShortLoad(in, utf8_temp); af.setICAO(QString::fromUtf8(utf8_temp)); // read comment ShortLoad(in, utf8_temp); af.setComment(QString::fromUtf8(utf8_temp)); in >> wgsPos; af.setWGSPosition(wgsPos); in >> position; af.setPosition(position); in >> elevation; af.setElevation(elevation); in >> inFrequency; if( inFrequency == 0 ) { af.setFrequency( 0.0 ); } else { af.setFrequency((((float) inFrequency) / 1000.0) + 100.); } // The runway list has to be read quint8 listSize; in >> listSize; for( short i = 0; i < (short) listSize; i++ ) { float length; float width; quint16 heading; quint8 surface; quint8 isOpen; quint8 isBidirectional; in >> length; in >> width; in >> heading; in >> surface; in >> isOpen; in >> isBidirectional; Runway rwy( length, heading, surface, isOpen, isBidirectional, width ); af.addRunway( rwy ); } // Add the airfield site to the list. airfieldList.append( af ); } inFile.close(); qDebug( "OAIP: %d airfields read from %s in %dms", counter, fileName.toLatin1().data(), t.elapsed() ); return true; }
bool OpenAipPoiLoader::readCompiledFile( QString &fileName, QList<SinglePoint>& spList ) { QTime t; t.start(); QFile inFile( fileName ); if( !inFile.open(QIODevice::ReadOnly) ) { qWarning("OAIP: Cannot open single point file %s!", fileName.toLatin1().data()); return false; } QDataStream in( &inFile ); in.setVersion( Q_DATA_STREAM ); bool ok = readHeaderData( in, FILE_TYPE_HOTSPOTS_OAIP_C, FILE_VERSION_HOTSPOT_C ); if( ok == false ) { inFile.close(); return false; } // read number of records in the file quint32 lrn; in >> lrn; // Preallocate list memory for new elements to be added. if( lrn ) { spList.reserve( spList.size() + lrn ); } quint8 type; QByteArray utf8_temp; WGSPoint wgsPos; QPoint position; float elevation; uint counter = 0; while( ! in.atEnd() ) { counter++; SinglePoint sp; in >> type; sp.setTypeID( static_cast<BaseMapElement::objectType>(type) ); // read long name ShortLoad(in, utf8_temp); sp.setName(QString::fromUtf8(utf8_temp)); // read short name ShortLoad(in, utf8_temp); sp.setWPName(QString::fromUtf8(utf8_temp)); // read the 2 letter country code ShortLoad(in, utf8_temp); sp.setCountry(QString::fromUtf8(utf8_temp)); // read comment ShortLoad(in, utf8_temp); sp.setComment(QString::fromUtf8(utf8_temp)); in >> wgsPos; sp.setWGSPosition(wgsPos); in >> position; sp.setPosition(position); in >> elevation; sp.setElevation(elevation); // Add the single point element to the list. spList.append( sp ); } inFile.close(); qDebug( "OAIP: %d single points read from %s in %dms", counter, fileName.toLatin1().data(), t.elapsed() ); return true; }