Split PRS1DataChunk::ReadHeader into ReadHeader/ReadNormalHeaderV2/ReadNormalHeaderV3.

This commit is contained in:
sawinglogz 2019-05-15 12:32:39 -04:00
parent d3c6d6445b
commit c8cd66992a
2 changed files with 70 additions and 40 deletions

View File

@ -3521,51 +3521,24 @@ bool PRS1DataChunk::ReadHeader(QFile & f)
break; break;
} }
bool hasHeaderDataBlock = (this->fileVersion == 3); bool hdr_ok = false;
if (this->ext < 5) { // Not a waveform chunk if (this->ext < 5) { // Not a waveform chunk
QByteArray headerB2; switch (this->fileVersion) {
case 2:
// Check if this is a newer machine with a header data block hdr_ok = ReadNormalHeaderV2(f);
if (hasHeaderDataBlock) {
// This is a new machine, byte 15 is header data block length
// followed by variable, data byte pairs
QByteArray extra = f.read(1);
if (extra.size() < 1) {
qWarning() << this->m_path << "read error extended header";
break; break;
} case 3:
this->m_header.append(extra); hdr_ok = ReadNormalHeaderV3(f);
header = (unsigned char *)this->m_header.data(); break;
default:
int hdb_len = header[15]; //hdr_ok remains false, warning is above
int hdb_size = hdb_len * 2;
headerB2 = f.read(hdb_size);
if (headerB2.size() != hdb_size) {
qWarning() << this->m_path << "read error in extended header";
break; break;
}
this->m_header.append(headerB2);
header = (unsigned char *)this->m_header.data();
const unsigned char * hd = (unsigned char *)headerB2.constData();
int pos = 0;
int recs = header[15];
for (int i=0; i<recs; i++) {
this->hblock[hd[pos]] = hd[pos+1];
pos += 2;
}
} else {
headerB2 = QByteArray();
} }
this->m_headerblock = headerB2;
} else { // Waveform Chunk } else { // Waveform Chunk
bool hdr_ok = ReadWaveformHeader(f); hdr_ok = ReadWaveformHeader(f);
if (!hdr_ok) { }
break; if (!hdr_ok) {
} break;
} }
// The 8bit checksum comes at the end. // The 8bit checksum comes at the end.
@ -3595,6 +3568,57 @@ bool PRS1DataChunk::ReadHeader(QFile & f)
} }
bool PRS1DataChunk::ReadNormalHeaderV2(QFile & /*f*/)
{
this->m_headerblock = QByteArray();
return true; // always OK
}
bool PRS1DataChunk::ReadNormalHeaderV3(QFile & f)
{
bool ok = false;
unsigned char * header;
QByteArray headerB2;
// This is a new machine, byte 15 is header data block length
// followed by variable, data byte pairs
do {
QByteArray extra = f.read(1);
if (extra.size() < 1) {
qWarning() << this->m_path << "read error extended header";
break;
}
this->m_header.append(extra);
header = (unsigned char *)this->m_header.data();
int hdb_len = header[15];
int hdb_size = hdb_len * 2;
headerB2 = f.read(hdb_size);
if (headerB2.size() != hdb_size) {
qWarning() << this->m_path << "read error in extended header";
break;
}
this->m_headerblock = headerB2;
this->m_header.append(headerB2);
header = (unsigned char *)this->m_header.data();
const unsigned char * hd = (unsigned char *)headerB2.constData();
int pos = 0;
int recs = header[15];
for (int i=0; i<recs; i++) {
this->hblock[hd[pos]] = hd[pos+1];
pos += 2;
}
ok = true;
} while (false);
return ok;
}
bool PRS1DataChunk::ReadWaveformHeader(QFile & f) bool PRS1DataChunk::ReadWaveformHeader(QFile & f)
{ {
bool ok = false; bool ok = false;

View File

@ -117,6 +117,12 @@ public:
bool ReadData(class QFile & f); bool ReadData(class QFile & f);
protected: protected:
//! \brief Read and parse the non-waveform header data from a V2 PRS1 file
bool ReadNormalHeaderV2(class QFile & f);
//! \brief Read and parse the non-waveform header data from a V3 PRS1 file
bool ReadNormalHeaderV3(class QFile & f);
//! \brief Read and parse the waveform-specific header data from a PRS1 file //! \brief Read and parse the waveform-specific header data from a PRS1 file
bool ReadWaveformHeader(class QFile & f); bool ReadWaveformHeader(class QFile & f);
}; };