diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2017-05-07 13:41:09 +0300 |
---|---|---|
committer | Miika Turkia <miika.turkia@gmail.com> | 2017-05-07 13:53:52 +0300 |
commit | 0dfa448d8c7132bd0058a6fb3bc820fdde2a4759 (patch) | |
tree | cd1b2e74436ea9c2aa41d6290b68fc8a0f8a0ef2 /core/qthelper.cpp | |
parent | ab1813a4454cbe639e99eaee7cd1115bfed1cf8f (diff) | |
download | subsurface-0dfa448d8c7132bd0058a6fb3bc820fdde2a4759.tar.gz |
Refactor Seabear import
Moving the GUI independent Seabear import functionality to Subsurface
core. This will allow Robert to call it directly from download from DC.
Tested with H3 against released and daily versions of Subsurface. The
result differs somewhat, but it is actually fixing 2 bugs:
- Temperature was mis-interpreted previously
- Sample interval for a dive with 1 second interval was parsed
incorrectly
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r-- | core/qthelper.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 993ecbf7d..0673a78ce 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -1510,6 +1510,97 @@ QString getUUID() return uuidString; } +int parse_seabear_header(const char *filename, char **params, int pnr) +{ + QFile f(filename); + + f.open(QFile::ReadOnly); + QString parseLine = f.readLine(); + + /* + * Parse header - currently only interested in sample + * interval and hardware version. If we have old format + * the interval value is missing from the header. + */ + + while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { + if (parseLine.contains("//Hardware Version: ")) { + params[pnr++] = strdup("hw"); + params[pnr++] = strdup(parseLine.replace(QString::fromLatin1("//Hardware Version: "), QString::fromLatin1("\"Seabear ")).trimmed().append("\"").toUtf8().data()); + break; + } + } + + /* + * Note that we scan over the "Log interval" on purpose + */ + + while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { + if (parseLine.contains("//Log interval: ")) { + params[pnr++] = strdup("delta"); + params[pnr++] = strdup(parseLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s")).toUtf8().data()); + } + } + + /* + * Parse CSV fields + */ + + parseLine = f.readLine().trimmed(); + + QStringList currColumns = parseLine.split(';'); + unsigned short index = 0; + Q_FOREACH (QString columnText, currColumns) { + if (columnText == "Time") { + params[pnr++] = strdup("timeField"); + params[pnr++] = intdup(index++); + } else if (columnText == "Depth") { + params[pnr++] = strdup("depthField"); + params[pnr++] = intdup(index++); + } else if (columnText == "Temperature") { + params[pnr++] = strdup("tempField"); + params[pnr++] = intdup(index++); + } else if (columnText == "NDT") { + params[pnr++] = strdup("ndlField"); + params[pnr++] = intdup(index++); + } else if (columnText == "TTS") { + params[pnr++] = strdup("ttsField"); + params[pnr++] = intdup(index++); + } else if (columnText == "pO2_1") { + params[pnr++] = strdup("o2sensor1Field"); + params[pnr++] = intdup(index++); + } else if (columnText == "pO2_2") { + params[pnr++] = strdup("o2sensor2Field"); + params[pnr++] = intdup(index++); + } else if (columnText == "pO2_3") { + params[pnr++] = strdup("o2sensor3Field"); + params[pnr++] = intdup(index++); + } else if (columnText == "Ceiling") { + /* TODO: Add support for dive computer reported ceiling*/ + params[pnr++] = strdup("ceilingField"); + params[pnr++] = intdup(index++); + } else if (columnText == "Tank pressure") { + params[pnr++] = strdup("pressureField"); + params[pnr++] = intdup(index++); + } else { + // We do not know about this value + qDebug() << "Seabear import found an un-handled field: " << columnText; + } + } + + /* Separator is ';' and the index for that in DiveLogImportDialog constructor is 2 */ + params[pnr++] = strdup("separatorIndex"); + params[pnr++] = intdup(2); + + /* And metric units */ + params[pnr++] = strdup("units"); + params[pnr++] = intdup(0); + + params[pnr] = NULL; + f.close(); + return pnr; +} + char *intdup(int index) { char tmpbuf[21]; |