本文整理汇总了C++中QByteArray::fill方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::fill方法的具体用法?C++ QByteArray::fill怎么用?C++ QByteArray::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::fill方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wrapInFunction
//.........这里部分代码省略.........
// ba == "ABCDEFGHIJ"
//! [9]
//! [10]
QByteArray ba("Stockholm");
ba.truncate(5); // ba == "Stock"
//! [10]
//! [11]
QByteArray ba("STARTTLS\r\n");
ba.chop(2); // ba == "STARTTLS"
//! [11]
//! [12]
QByteArray x("free");
QByteArray y("dom");
x += y;
// x == "freedom"
//! [12]
//! [13]
QByteArray().isNull(); // returns true
QByteArray("").isNull(); // returns false
QByteArray("abc").isNull(); // returns false
//! [13]
//! [14]
QByteArray ba("Istambul");
ba.fill('o');
// ba == "oooooooo"
ba.fill('X', 2);
// ba == "XX"
//! [14]
//! [15]
QByteArray x("ship");
QByteArray y("air");
x.prepend(y);
// x == "airship"
//! [15]
//! [16]
QByteArray x("free");
QByteArray y("dom");
x.append(y);
// x == "freedom"
//! [16]
//! [17]
QByteArray ba("Meal");
ba.insert(1, QByteArray("ontr"));
// ba == "Montreal"
//! [17]
//! [18]
QByteArray ba("Montreal");
示例2: addGlyphs
void QPF::addGlyphs(QFontEngine *fe, const QList<CharacterRange> &ranges)
{
const quint16 glyphCount = fe->glyphCount();
QByteArray gmap;
gmap.resize(glyphCount * sizeof(quint32));
gmap.fill(char(0xff));
//qDebug() << "glyphCount" << glyphCount;
QByteArray glyphs;
if (options & RenderGlyphs) {
// this is only a rough estimation
glyphs.reserve(glyphCount
* (sizeof(QFontEngineQPF::Glyph)
+ qRound(fe->maxCharWidth() * (fe->ascent() + fe->descent()).toReal())));
QGlyphLayoutArray<10> layout;
foreach (CharacterRange range, ranges) {
if (debugVerbosity > 2)
qDebug() << "rendering range from" << range.start << "to" << range.end;
for (uint uc = range.start; uc < range.end; ++uc) {
QChar ch(uc);
int nglyphs = 10;
if (!fe->stringToCMap(&ch, 1, &layout, &nglyphs, /*flags*/ 0))
continue;
if (nglyphs != 1)
continue;
const quint32 glyphIndex = layout.glyphs[0];
if (!glyphIndex)
continue;
Q_ASSERT(glyphIndex < glyphCount);
QImage img = fe->alphaMapForGlyph(glyphIndex).convertToFormat(QImage::Format_Indexed8);
glyph_metrics_t metrics = fe->boundingBox(glyphIndex);
const quint32 oldSize = glyphs.size();
glyphs.resize(glyphs.size() + sizeof(QFontEngineQPF::Glyph) + img.byteCount());
uchar *data = reinterpret_cast<uchar *>(glyphs.data() + oldSize);
uchar *gmapPtr = reinterpret_cast<uchar *>(gmap.data() + glyphIndex * sizeof(quint32));
qToBigEndian(oldSize, gmapPtr);
QFontEngineQPF::Glyph *glyph = reinterpret_cast<QFontEngineQPF::Glyph *>(data);
glyph->width = img.width();
glyph->height = img.height();
glyph->bytesPerLine = img.bytesPerLine();
glyph->x = qRound(metrics.x);
glyph->y = qRound(metrics.y);
glyph->advance = qRound(metrics.xoff);
data += sizeof(QFontEngineQPF::Glyph);
if (debugVerbosity && uc >= 'A' && uc <= 'z' || debugVerbosity > 1) {
qDebug() << "adding glyph with index" << glyphIndex << " uc =" << char(uc) << ":\n"
<< " glyph->x =" << glyph->x << "rounded from" << metrics.x << "\n"
<< " glyph->y =" << glyph->y << "rounded from" << metrics.y << "\n"
<< " width =" << glyph->width << "height =" << glyph->height
<< " advance =" << glyph->advance << "rounded from" << metrics.xoff
;
}
memcpy(data, img.bits(), img.byteCount());
}
}
}
示例3: propertyFlagsTests
//.........这里部分代码省略.........
QCOMPARE(propsC.getHasProperty(EXAMPLE_PROP_VISIBLE), false);
encoded = propsC.encode();
if (verbose) {
qDebug() << "propsC... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
}
}
{
if (verbose) {
qDebug() << "Test 12: ExamplePropertyFlags: decode tests";
}
ExamplePropertyFlags props;
props << EXAMPLE_PROP_VISIBLE;
props << EXAMPLE_PROP_ANIMATION_URL;
props << EXAMPLE_PROP_ANIMATION_FPS;
props << EXAMPLE_PROP_ANIMATION_FRAME_INDEX;
props << EXAMPLE_PROP_ANIMATION_PLAYING;
props << EXAMPLE_PROP_PAUSE_SIMULATION;
QByteArray encoded = props.encode();
if (verbose) {
qDebug() << "encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "encoded.size()=" << encoded.size();
}
ExamplePropertyFlags propsDecoded;
propsDecoded.decode(encoded);
QCOMPARE(propsDecoded, props);
QByteArray encodedAfterDecoded = propsDecoded.encode();
QCOMPARE(encoded, encodedAfterDecoded);
if (verbose) {
qDebug() << "fill encoded byte array with extra garbage (as if it was bitstream with more content)";
}
QByteArray extraContent;
extraContent.fill(0xbaU, 10);
encoded.append(extraContent);
if (verbose) {
qDebug() << "encoded.size()=" << encoded.size() << "includes extra garbage";
}
ExamplePropertyFlags propsDecodedExtra;
propsDecodedExtra.decode(encoded);
QCOMPARE(propsDecodedExtra, props);
QByteArray encodedAfterDecodedExtra = propsDecodedExtra.encode();
if (verbose) {
qDebug() << "encodedAfterDecodedExtra=";
outputBufferBits((const unsigned char*)encodedAfterDecodedExtra.constData(), encodedAfterDecodedExtra.size());
}
}
{
if (verbose) {
qDebug() << "Test 13: ExamplePropertyFlags: QByteArray << / >> tests";
}
ExamplePropertyFlags props;
props << EXAMPLE_PROP_VISIBLE;
props << EXAMPLE_PROP_ANIMATION_URL;
props << EXAMPLE_PROP_ANIMATION_FPS;
props << EXAMPLE_PROP_ANIMATION_FRAME_INDEX;
props << EXAMPLE_PROP_ANIMATION_PLAYING;
props << EXAMPLE_PROP_PAUSE_SIMULATION;
if (verbose) {
qDebug() << "testing encoded << props";
}
QByteArray encoded;
encoded << props;
if (verbose) {
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
}
ExamplePropertyFlags propsDecoded;
if (verbose) {
qDebug() << "testing encoded >> propsDecoded";
}
encoded >> propsDecoded;
QCOMPARE(propsDecoded, props);
}
if (verbose) {
qDebug() << "******************************************************************************************";
}
}
示例4: getTreeAsString
QByteArray TapParameterDialog::getTreeAsString(st_format_type format)
{
QByteArray ba;
QTreeWidgetItemIterator it(ui->statsTreeWidget, QTreeWidgetItemIterator::NotHidden);
QList<int> col_widths;
QByteArray footer;
// Title + header
switch (format) {
case ST_FORMAT_PLAIN:
{
QTreeWidgetItemIterator width_it(it);
QString plain_header;
while (*width_it) {
QList<QVariant> tid = treeItemData((*width_it));
int col = 0;
foreach (QVariant var, tid) {
if (col_widths.size() <= col) {
col_widths.append(ui->statsTreeWidget->headerItem()->text(col).length());
}
if (var.type() == QVariant::String) {
col_widths[col] = qMax(col_widths[col], itemDataToPlain(var).length());
}
col++;
}
++width_it;
}
QStringList ph_parts;
for (int col = 0; col < ui->statsTreeWidget->columnCount() && col < col_widths.length(); col++) {
ph_parts << ui->statsTreeWidget->headerItem()->text(col);
}
plain_header = ph_parts.join(plain_sep_);
QByteArray top_separator;
top_separator.fill('=', plain_header.length());
top_separator.append('\n');
QString file_header = QString("%1 - %2:\n").arg(windowSubtitle(), cap_file_.fileName());
footer.fill('-', plain_header.length());
footer.append('\n');
plain_header.append('\n');
ba.append(top_separator);
ba.append(file_header);
ba.append(plain_header);
ba.append(footer);
break;
}
case ST_FORMAT_CSV:
{
QString csv_header;
QStringList ch_parts;
for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) {
ch_parts << QString("\"%1\"").arg(ui->statsTreeWidget->headerItem()->text(col));
}
csv_header = ch_parts.join(",");
csv_header.append('\n');
ba.append(csv_header.toUtf8().constData());
break;
}
case ST_FORMAT_XML:
{
// XXX What's a useful format? This mostly conforms to DocBook.
ba.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
QString title;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
title = Qt::escape(windowSubtitle());
#else
title = QString(windowSubtitle()).toHtmlEscaped();
#endif
QString xml_header = QString("<table>\n<title>%1</title>\n").arg(title);
ba.append(xml_header.toUtf8());
ba.append("<thead>\n<row>\n");
for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) {
title = ui->statsTreeWidget->headerItem()->text(col);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
title = Qt::escape(title);
#else
title = title.toHtmlEscaped();
#endif
title = QString(" <entry>%1</entry>\n").arg(title);
ba.append(title.toUtf8());
}
ba.append("</row>\n</thead>\n");
ba.append("<tbody>\n");
footer = "</tbody>\n</table>\n";
break;
}
case ST_FORMAT_YAML:
{
QString yaml_header;
ba.append("---\n");
yaml_header = QString("Description: \"%1\"\nFile: \"%2\"\nItems:\n").arg(windowSubtitle()).arg(cap_file_.fileName());
ba.append(yaml_header.toUtf8());
break;
}
default:
break;
}
//.........这里部分代码省略.........
示例5: propertyFlagsTests
//.........这里部分代码省略.........
<< "{ expect false }";
qDebug() << "props << PARTICLE_PROP_VISIBLE;";
props << PARTICLE_PROP_VISIBLE;
encoded = props.encode();
qDebug() << "props... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "props.getHasProperty(PARTICLE_PROP_VISIBLE)" << (props.getHasProperty(PARTICLE_PROP_VISIBLE))
<< "{ expect true }";
qDebug() << "props << PARTICLE_PROP_ANIMATION_URL;";
props << PARTICLE_PROP_ANIMATION_URL;
encoded = props.encode();
qDebug() << "props... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "props.getHasProperty(PARTICLE_PROP_VISIBLE)" << (props.getHasProperty(PARTICLE_PROP_VISIBLE))
<< "{ expect true }";
qDebug() << "props << ... more ...";
props << PARTICLE_PROP_ANIMATION_FPS;
props << PARTICLE_PROP_ANIMATION_FRAME_INDEX;
props << PARTICLE_PROP_ANIMATION_PLAYING;
props << PARTICLE_PROP_PAUSE_SIMULATION;
encoded = props.encode();
qDebug() << "props... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "props.getHasProperty(PARTICLE_PROP_VISIBLE)" << (props.getHasProperty(PARTICLE_PROP_VISIBLE))
<< "{ expect true }";
qDebug() << "ParticlePropertyFlags propsB = props & PARTICLE_PROP_VISIBLE;";
ParticlePropertyFlags propsB = props & PARTICLE_PROP_VISIBLE;
qDebug() << "propsB.getHasProperty(PARTICLE_PROP_VISIBLE)" << (propsB.getHasProperty(PARTICLE_PROP_VISIBLE))
<< "{ expect true }";
encoded = propsB.encode();
qDebug() << "propsB... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "ParticlePropertyFlags propsC = ~propsB;";
ParticlePropertyFlags propsC = ~propsB;
qDebug() << "propsC.getHasProperty(PARTICLE_PROP_VISIBLE)" << (propsC.getHasProperty(PARTICLE_PROP_VISIBLE))
<< "{ expect false }";
encoded = propsC.encode();
qDebug() << "propsC... encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
}
{
qDebug() << "Test 8: ParticlePropertyFlags: decode tests";
ParticlePropertyFlags props;
props << PARTICLE_PROP_VISIBLE;
props << PARTICLE_PROP_ANIMATION_URL;
props << PARTICLE_PROP_ANIMATION_FPS;
props << PARTICLE_PROP_ANIMATION_FRAME_INDEX;
props << PARTICLE_PROP_ANIMATION_PLAYING;
props << PARTICLE_PROP_PAUSE_SIMULATION;
QByteArray encoded = props.encode();
qDebug() << "encoded=";
outputBufferBits((const unsigned char*)encoded.constData(), encoded.size());
qDebug() << "encoded.size()=" << encoded.size();
ParticlePropertyFlags propsDecoded;
propsDecoded.decode(encoded);
qDebug() << "propsDecoded == props:" << (propsDecoded == props) << "{ expect true }";
QByteArray encodedAfterDecoded = propsDecoded.encode();
qDebug() << "encodedAfterDecoded=";
outputBufferBits((const unsigned char*)encodedAfterDecoded.constData(), encodedAfterDecoded.size());
qDebug() << "fill encoded byte array with extra garbage (as if it was bitstream with more content)";
QByteArray extraContent;
extraContent.fill(0xba, 10);
encoded.append(extraContent);
qDebug() << "encoded.size()=" << encoded.size() << "includes extra garbage";
ParticlePropertyFlags propsDecodedExtra;
propsDecodedExtra.decode(encoded);
qDebug() << "propsDecodedExtra == props:" << (propsDecodedExtra == props) << "{ expect true }";
QByteArray encodedAfterDecodedExtra = propsDecodedExtra.encode();
qDebug() << "encodedAfterDecodedExtra=";
outputBufferBits((const unsigned char*)encodedAfterDecodedExtra.constData(), encodedAfterDecodedExtra.size());
}
qDebug() << "******************************************************************************************";
}
示例6: propertyFlagsTests
//.........这里部分代码省略.........
ParticlePropertyFlags propsDecoded;
propsDecoded.decode(encoded);
if (verbose) {
qDebug() << "propsDecoded == props:" << (propsDecoded == props) << "{ expect true }";
}
testsTaken++;
bool resultA = (propsDecoded == props);
bool expectedA = true;
if (resultA == expectedA) {
testsPassed++;
} else {
testsFailed++;
qDebug() << "FAILED - Test 12a: propsDecoded == props";
}
QByteArray encodedAfterDecoded = propsDecoded.encode();
if (verbose) {
qDebug() << "encodedAfterDecoded=";
outputBufferBits((const unsigned char*)encodedAfterDecoded.constData(), encodedAfterDecoded.size());
}
testsTaken++;
bool resultB = (encoded == encodedAfterDecoded);
bool expectedB = true;
if (resultB == expectedB) {
testsPassed++;
} else {
testsFailed++;
qDebug() << "FAILED - Test 12b: (encoded == encodedAfterDecoded)";
}
if (verbose) {
qDebug() << "fill encoded byte array with extra garbage (as if it was bitstream with more content)";
}
QByteArray extraContent;
extraContent.fill(0xba, 10);
encoded.append(extraContent);
if (verbose) {
qDebug() << "encoded.size()=" << encoded.size() << "includes extra garbage";
}
ParticlePropertyFlags propsDecodedExtra;
propsDecodedExtra.decode(encoded);
if (verbose) {
qDebug() << "propsDecodedExtra == props:" << (propsDecodedExtra == props) << "{ expect true }";
}
testsTaken++;
bool resultC = (propsDecodedExtra == props);
bool expectedC = true;
if (resultC == expectedC) {
testsPassed++;
} else {
testsFailed++;
qDebug() << "FAILED - Test 12c: (propsDecodedExtra == props)";
}
QByteArray encodedAfterDecodedExtra = propsDecodedExtra.encode();
if (verbose) {
qDebug() << "encodedAfterDecodedExtra=";
outputBufferBits((const unsigned char*)encodedAfterDecodedExtra.constData(), encodedAfterDecodedExtra.size());
}
}
示例7: run
//.........这里部分代码省略.........
tmp_br += bytes_consumed;
}
#ifndef Q_OS_WIN
if ( tmp_time >= 1000.0 )
{
emit playC.updateBitrate( round( ( tmp_br << 3 ) / tmp_time ), -1, -1.0 );
tmp_br = tmp_time = 0;
}
#endif
delay = writer->getParam( "delay" ).toDouble();
foreach ( AudioFilter *filter, filters )
{
if ( flushAudio )
filter->clearBuffers();
delay += filter->filter( decoded, hasBufferedSamples );
}
if ( flushAudio )
playC.flushAudio = false;
int decodedSize = decoded.size();
int decodedPos = 0;
br2 = false;
while ( decodedSize > 0 && !playC.paused && !br && !br2 )
{
const double max_len = 0.02; //TODO: zrobić opcje?
const int chunk = qMin( decodedSize, ( int )( ceil( realSample_rate * max_len ) * realChannels * sizeof( float ) ) );
const float vol = ( playC.muted || playC.vol == 0.0 ) ? 0.0 : playC.replayGain * ( playC.vol == 1.0 ? 1.0 : playC.vol * playC.vol );
QByteArray decodedChunk;
if ( vol == 0.0 )
decodedChunk.fill( 0, chunk );
else
decodedChunk = QByteArray::fromRawData( decoded.data() + decodedPos, chunk );
decodedPos += chunk;
decodedSize -= chunk;
playC.audio_last_delay = ( double )decodedChunk.size() / ( double )( sizeof( float ) * realChannels * realSample_rate );
if ( packet.ts.isValid() )
{
audio_pts = playC.audio_current_pts = packet.ts - delay;
if ( !playC.vThr )
{
#ifdef Q_OS_WIN
playC.chPos( playC.audio_current_pts, playC.flushAudio );
#else
playC.chPos( playC.audio_current_pts );
#endif
}
}
tmp_time += playC.audio_last_delay * 1000.0;
packet.ts += playC.audio_last_delay;
#ifdef Q_OS_WIN
canRefresh = true;
#endif
if ( playC.skipAudioFrame <= 0.0 )
{
const double speed = playC.speed;
if ( speed != lastSpeed )
{
示例8: assert
//from Kwalletbackend.
// this should be SHA-512 for release probably
QString Hash::password2hash(const QByteArray& password) {
SHA1 sha;
QByteArray hash;
hash.resize(20);
hash.fill(0);
int shasz = sha.size() / 8;
assert(shasz >= 20);
QByteArray block1(shasz, 0);
sha.process(password.data(), qMin(password.size(), 16));
// To make brute force take longer
for (int i = 0; i < 2000; i++) {
memcpy(block1.data(), sha.hash(), shasz);
sha.reset();
sha.process(block1.data(), shasz);
}
sha.reset();
if (password.size() > 16) {
sha.process(password.data() + 16, qMin(password.size() - 16, 16));
QByteArray block2(shasz, 0);
// To make brute force take longer
for (int i = 0; i < 2000; i++) {
memcpy(block2.data(), sha.hash(), shasz);
sha.reset();
sha.process(block2.data(), shasz);
}
sha.reset();
if (password.size() > 32) {
sha.process(password.data() + 32, qMin(password.size() - 32, 16));
QByteArray block3(shasz, 0);
// To make brute force take longer
for (int i = 0; i < 2000; i++) {
memcpy(block3.data(), sha.hash(), shasz);
sha.reset();
sha.process(block3.data(), shasz);
}
sha.reset();
if (password.size() > 48) {
sha.process(password.data() + 48, password.size() - 48);
QByteArray block4(shasz, 0);
// To make brute force take longer
for (int i = 0; i < 2000; i++) {
memcpy(block4.data(), sha.hash(), shasz);
sha.reset();
sha.process(block4.data(), shasz);
}
sha.reset();
// split 14/14/14/14
hash.resize(56);
memcpy(hash.data(), block1.data(), 14);
memcpy(hash.data() + 14, block2.data(), 14);
memcpy(hash.data() + 28, block3.data(), 14);
memcpy(hash.data() + 42, block4.data(), 14);
block4.fill(0);
} else {
// split 20/20/16
hash.resize(56);
memcpy(hash.data(), block1.data(), 20);
memcpy(hash.data() + 20, block2.data(), 20);
memcpy(hash.data() + 40, block3.data(), 16);
}
block3.fill(0);
} else {
// split 20/20
hash.resize(40);
memcpy(hash.data(), block1.data(), 20);
memcpy(hash.data() + 20, block2.data(), 20);
}
block2.fill(0);
} else {
// entirely block1
hash.resize(20);
memcpy(hash.data(), block1.data(), 20);
}
block1.fill(0);
//MCH: to store hash as a String...
QString output, tmp;
unsigned char *digest;
digest = (unsigned char*) hash.data();
for (int i = 0; i < 20; ++i)
output += tmp.sprintf("%02x", digest[i]);
output = output.toUpper();
qDebug()<<"HASH::Result == "<<output;
//.........这里部分代码省略.........
示例9: loadFromMotFile
bool MotorolaSRecordProvider::loadFromMotFile(QString name, QByteArray & data,MotorolaSRecordHeader & h)
{
Q_UNUSED(h);
int lastAddress = 0;
unsigned int currentAddress;
int bytesCount = 0;
unsigned char crc;
data.clear();
QFile motFile(name);
if(!motFile.open(QIODevice::ReadOnly))return false;
while(!motFile.atEnd())
{
QByteArray srecord = motFile.readLine();
if(srecord[srecord.size()-1]=='\n') srecord=srecord.left(srecord.size()-1);
if(srecord[srecord.size()-1]=='\r') srecord=srecord.left(srecord.size()-1);
srecord[0] = '0';
QByteArray record;
record= QByteArray::fromHex(srecord);
QByteArray ca;
crc = 0;
for(int i=0;i<record.size()-1;i++)
{
crc+=record[i];
}
crc=0x100-crc+1;
// if(crc!=(unsigned char)record[record.size()-1]) return false; // invalid crc
bytesCount = record[1];
if((int)record[0]==0) // header record
{
// do nothing. no examples found
continue;
}
if((int)record[0]==1) // 2 address bytes
{
ca = record.left(4).right(2);
unsigned char a = ca.at(0);
unsigned char b = ca.at(1);
currentAddress = a*0x100+b;
bytesCount=bytesCount-1-2;
}
if((int)record[0]==2) // 3 address bytes
{
ca = record.left(5).right(3);
unsigned char a = ca.at(0);
unsigned char b = ca.at(1);
unsigned char c = ca.at(2);
currentAddress = a*0x10000+b*0x100+c;
bytesCount=bytesCount-1-3;
}
if((int)record[0]==3) // 4 address bytes
{
ca = record.left(6).right(4);
unsigned char a = ca.at(0);
unsigned char b = ca.at(1);
unsigned char c = ca.at(2);
unsigned char d = ca.at(3);
currentAddress = a*0x1000000+b*0x10000+c*0x100+d;
bytesCount=bytesCount-1-4;
}
//other type record not containing data
if((int)record[0]==4 || (int)record[0]==5 || (int)record[0]==6 || (int)record[0]==7 || (int)record[0]==8 || (int)record[0]==9)
{
continue;
}
record = record.left(record.length()-1).right(bytesCount);
if(currentAddress +record.length() > abs(data.length()))
{
QByteArray br;
br.fill(0x00,currentAddress+record.length());
data.append(br);
}
data.replace(currentAddress,record.length(),record);
lastAddress = currentAddress + record.length();
}
//.........这里部分代码省略.........
示例10: run
void udpthread::run()
{
QByteArray temp;
temp.resize(4);
temp.fill(0x00, 4);
int i = 0;
unsigned short broad = 0;
unsigned short channel = 0;
unsigned short parameter = 0;
unsigned int index = 0;
unsigned short cmd = 0;
while(flag) {
/* 设备信息 */
temp[1] = 0x10;
temp[3] = 0x11;
i = recv_data.indexOf(temp);
if (i > 0 && checkdata(recv_data.mid(i - 2, 136))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
emit broadinfo(broad, recv_data.mid(i + 4, 128));
recv_data.remove(0, i + 134);
}
/* 配置信息 */
temp[1] = 0x11;
temp[3] = 0x00;
i = recv_data.indexOf(temp);
if (i > 0 && checkdata(recv_data.mid(i - 2, 8))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
emit configinfo(broad);
recv_data.remove(0, i + 6);
}
/* adc通道实时信息 */
temp[1] = 0x14;
temp[3] = 0x00;
i = recv_data.indexOf(temp.mid(0, 2));
if (i > 0 && checkdata(recv_data.mid(i - 2, 525))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
channel = (recv_data[i + 2] << 8) | recv_data[i + 3];
index = (recv_data[i + 4] << 24) | (recv_data[i + 5] << 16) |
(recv_data[i + 6] << 8) | recv_data[i + 7];
emit adcdata(broad, channel, index, recv_data.mid(i + 8, 512));
recv_data.remove(0, i + 523);
}
/* sd卡信息 */
temp[1] = 0x13;
temp[3] = 0x00;
i = recv_data.indexOf(temp.mid(0, 2));
if (i > 0 && checkdata(recv_data.mid(i - 2, 525))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
parameter = (recv_data[i + 2] << 8) | recv_data[i + 3];
index = (recv_data[i + 4] << 24) | (recv_data[i + 5] << 16) |
(recv_data[i + 6] << 8) | recv_data[i + 7];
emit sddata(broad, parameter, index, recv_data.mid(i + 8, 512));
recv_data.remove(0, i + 523);
}
/* 固件下载起始应答 */
temp[1] = 0x20;
temp[3] = 0x00;
i = recv_data.indexOf(temp);
if (i > 0 && checkdata(recv_data.mid(i - 2, 18))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
emit fireware_write_start_ack(broad);
recv_data.remove(0, i + 16);
}
/* 固件下载请求下一个包 */
temp[1] = 0x21;
temp[3] = 0x00;
i = recv_data.indexOf(temp);
if (i > 0 && checkdata(recv_data.mid(i - 2, 15))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
index = (recv_data[i + 4] << 40) | (recv_data[i + 5] << 32) |
(recv_data[i + 6] << 24) | (recv_data[i + 7] << 16) |
(recv_data[i + 8] << 8) | (recv_data[i + 9]);
emit fireware_next_package_request(broad, index);
recv_data.remove(0, i + 13);
}
/* 固件下载重新请求包 */
temp[1] = 0x22;
temp[3] = 0x00;
i = recv_data.indexOf(temp);
if (i > 0 && checkdata(recv_data.mid(i - 2, 15))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
index = (recv_data[i + 4] << 40) | (recv_data[i + 5] << 32) |
(recv_data[i + 6] << 24) | (recv_data[i + 7] << 16) |
(recv_data[i + 8] << 8) | (recv_data[i + 9]);
emit fireware_repeat_package_request(broad, index);
recv_data.remove(0, i + 13);
}
/* 错误信息 */
temp[1] = 0x50;
temp[3] = 0x00;
i = recv_data.indexOf(temp.mid(0, 2));
if (i > 0 && checkdata(recv_data.mid(i - 2, 8))) {
broad = (recv_data[i - 2] << 8) | recv_data[i - 1];
parameter = (recv_data[i + 2] << 8) | recv_data[i + 3];
emit error(broad, cmd);
recv_data.remove(0, i + 6);
}
}
quit();
}