mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-16 01:19:57 +00:00
SrmRideFile: hacked up v9 support
This commit is contained in:
@@ -74,14 +74,14 @@ static qint32 readSignedLong(QDataStream &in)
|
||||
|
||||
struct marker
|
||||
{
|
||||
int start, end;
|
||||
quint32 start, end;
|
||||
QString note;
|
||||
};
|
||||
|
||||
struct blockhdr
|
||||
{
|
||||
QDateTime dt;
|
||||
quint16 chunkcnt;
|
||||
quint32 chunkcnt;
|
||||
};
|
||||
|
||||
static int srmFileReaderRegistered =
|
||||
@@ -114,6 +114,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
// ok
|
||||
break;
|
||||
|
||||
@@ -163,8 +164,8 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
mcomment[mcommentlen] = '\0';
|
||||
|
||||
quint8 active = readByte(in);
|
||||
quint16 start = readShort(in);
|
||||
quint16 end = readShort(in);
|
||||
quint32 start = version < 9 ? readShort(in) : readLong(in );;
|
||||
quint32 end = version < 9 ? readShort(in) : readLong(in );
|
||||
quint16 avgwatts = readShort(in);
|
||||
quint16 avghr = readShort(in);
|
||||
quint16 avgcad = readShort(in);
|
||||
@@ -207,7 +208,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
}
|
||||
|
||||
blockhdr *blockhdrs = new blockhdr[blockcnt+1];
|
||||
int blockchunkcnt = 0;
|
||||
quint32 blockchunkcnt = 0;
|
||||
for (int i = 0; i < blockcnt; ++i) {
|
||||
// In the .srm files generated by Rainer Clasen's srmcmd,
|
||||
// hsecsincemidn is a *signed* 32-bit integer. I haven't seen a
|
||||
@@ -215,7 +216,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
// since the number of hundredths of a second in a day is << 2^31,
|
||||
// it seems safe to always treat this number as signed.
|
||||
qint32 hsecsincemidn = readLong(in);
|
||||
blockhdrs[i].chunkcnt = readShort(in);
|
||||
blockhdrs[i].chunkcnt = version < 9 ? readShort(in) : readLong(in);
|
||||
blockhdrs[i].dt = QDateTime(date);
|
||||
blockhdrs[i].dt = blockhdrs[i].dt.addMSecs(hsecsincemidn * 10);
|
||||
blockchunkcnt += blockhdrs[i].chunkcnt;
|
||||
@@ -229,7 +230,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
|
||||
quint16 zero = readShort(in);
|
||||
quint16 slope = readShort(in);
|
||||
quint16 datacnt = readShort(in);
|
||||
quint32 datacnt = version < 9 ? readShort(in) : readLong(in);
|
||||
readByte(in); // padding
|
||||
|
||||
// fail early to tell devs whats wrong with file
|
||||
@@ -257,15 +258,16 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
.arg(blockchunkcnt);
|
||||
}
|
||||
|
||||
int blknum = 0, blkidx = 0, mrknum = 0, interval = 0;
|
||||
quint32 blkidx = 0;
|
||||
int blknum = 0, mrknum = 0, interval = 0;
|
||||
double km = 0.0, secs = 0.0;
|
||||
|
||||
if (markercnt > 0)
|
||||
mrknum = 1;
|
||||
|
||||
for (int i = 0; i < blockchunkcnt; ++i) {
|
||||
for (quint32 i = 0; i < blockchunkcnt; ++i) {
|
||||
int cad, hr, watts;
|
||||
double kph, alt;
|
||||
double kph, alt, lon = 0, lat = 0;
|
||||
double temp=-255;
|
||||
if (version < 7) {
|
||||
quint8 ps[3];
|
||||
@@ -277,7 +279,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
watts = (ps[1] & 0x0f) | (ps[2] << 0x4);
|
||||
alt = 0.0;
|
||||
}
|
||||
else if (version == 7 ){
|
||||
else {
|
||||
watts = readShort(in);
|
||||
cad = readByte(in);
|
||||
hr = readByte(in);
|
||||
@@ -287,11 +289,11 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
|
||||
alt = readSignedLong(in);
|
||||
temp = 0.1 * readSignedShort(in);
|
||||
}
|
||||
else {
|
||||
errorStrings << QString("unsupported SRM file version: %1")
|
||||
.arg( version );
|
||||
return NULL;
|
||||
|
||||
if( version == 9 ){
|
||||
lat = readSignedLong(in) * 180.0 / 0x7fffffff;
|
||||
lon = readSignedLong(in) * 180.0 / 0x7fffffff;
|
||||
}
|
||||
}
|
||||
|
||||
if( in.status() != QDataStream::Ok ){
|
||||
@@ -314,7 +316,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
km += result->recIntSecs() * kph / 3600.0;
|
||||
|
||||
double nm = watts / 2.0 / PI / cad * 60.0;
|
||||
result->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, 0.0, 0.0, 0.0, 0.0, temp, 0.0,
|
||||
result->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, lon, lat, 0.0, 0.0, temp, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, interval);
|
||||
|
||||
@@ -357,9 +359,9 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
double last = 0.0;
|
||||
for (int i = 1; i < markers.size(); ++i) {
|
||||
const marker &marker = markers[i];
|
||||
int start = qMin(marker.start, result->dataPoints().size()) - 1;
|
||||
quint32 start = qMin(marker.start, (quint32)result->dataPoints().size()) - 1;
|
||||
double start_secs = result->dataPoints()[start]->secs;
|
||||
int end = qMin(marker.end - 1, result->dataPoints().size() - 1);
|
||||
quint32 end = qMin(marker.end - 1, (quint32)result->dataPoints().size() - 1);
|
||||
double end_secs = result->dataPoints()[end]->secs + result->recIntSecs();
|
||||
if( last < start_secs )
|
||||
result->addInterval(RideFileInterval::DEVICE, last, start_secs, "");
|
||||
@@ -370,7 +372,7 @@ RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QL
|
||||
result->addInterval(RideFileInterval::DEVICE, start_secs, end_secs, note );
|
||||
last = end_secs;
|
||||
}
|
||||
if (!markers.empty() && markers.last().end < result->dataPoints().size()) {
|
||||
if (!markers.empty() && markers.last().end < (quint32)result->dataPoints().size()) {
|
||||
double start_secs = result->dataPoints().last()->secs + result->recIntSecs();
|
||||
result->addInterval(RideFileInterval::DEVICE, last, start_secs, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user