mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Datatrak import rework: changes on helper funcs
Remove dtrak_profile() profile parsing func as this work is left to libdivecomputer. Simplifies read_file_header() to return the number of dives in the log file as we don't use the rest of header data. Add dtrak_prepare_data() to achieve a device_data_t structure and get the correct libdc model number for the device. Remove checking macro substituted with JUMP in header file. Add dt_libdc_buffer() to get a buffer parseable with libdivecomputer. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
This commit is contained in:
parent
22f07f5ada
commit
ceb54e6e9e
1 changed files with 44 additions and 71 deletions
115
core/datatrak.c
115
core/datatrak.c
|
@ -8,19 +8,17 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "gettext.h"
|
||||||
#include "datatrak.h"
|
#include "datatrak.h"
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "units.h"
|
#include "units.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "gettext.h"
|
#include "file.h"
|
||||||
|
|
||||||
extern struct sample *add_sample(struct sample *sample, int time, struct divecomputer *dc);
|
|
||||||
|
|
||||||
unsigned char lector_bytes[2], lector_word[4], tmp_1byte, *byte;
|
unsigned char lector_bytes[2], lector_word[4], tmp_1byte, *byte;
|
||||||
unsigned int tmp_2bytes;
|
unsigned int tmp_2bytes;
|
||||||
char is_nitrox, is_O2, is_SCR;
|
char is_nitrox, is_O2, is_SCR;
|
||||||
unsigned long tmp_4bytes;
|
unsigned long tmp_4bytes, maxbuf;
|
||||||
|
|
||||||
static unsigned int two_bytes_to_int(unsigned char x, unsigned char y)
|
static unsigned int two_bytes_to_int(unsigned char x, unsigned char y)
|
||||||
{
|
{
|
||||||
|
@ -89,83 +87,58 @@ static char *to_utf8(unsigned char *in_string)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Subsurface sample structure doesn't support the flags and alarms in the dt .log
|
* Reads the header of a datatrak buffer and returns the number of
|
||||||
* so will treat them as dc events.
|
* dives; zero on error (meaning this isn't a datatrak file).
|
||||||
|
* All other info in the header is useless for Subsurface.
|
||||||
*/
|
*/
|
||||||
static struct sample *dtrak_profile(struct dive *dt_dive, FILE *archivo)
|
static int read_file_header(unsigned char *buffer)
|
||||||
{
|
{
|
||||||
int i, j = 1, interval, o2percent = dt_dive->cylinder[0].gasmix.o2.permille / 10;
|
int n = 0;
|
||||||
struct sample *sample = dt_dive->dc.sample;
|
|
||||||
struct divecomputer *dc = &dt_dive->dc;
|
|
||||||
|
|
||||||
for (i = 1; i <= dt_dive->dc.alloc_samples; i++) {
|
if (two_bytes_to_int(buffer[0], buffer[1]) == 0xA100)
|
||||||
if (fread(&lector_bytes, 1, 2, archivo) != 2)
|
n = two_bytes_to_int(buffer[7], buffer[6]);
|
||||||
return sample;
|
return n;
|
||||||
interval= 20 * (i + 1);
|
|
||||||
sample = add_sample(sample, interval, dc);
|
|
||||||
sample->depth.mm = (two_bytes_to_int(lector_bytes[0], lector_bytes[1]) & 0xFFC0) * 1000 / 410;
|
|
||||||
byte = byte_to_bits(two_bytes_to_int(lector_bytes[0], lector_bytes[1]) & 0x003F);
|
|
||||||
if (byte[0] != 0)
|
|
||||||
sample->in_deco = true;
|
|
||||||
else
|
|
||||||
sample->in_deco = false;
|
|
||||||
if (byte[1] != 0)
|
|
||||||
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "rbt"));
|
|
||||||
if (byte[2] != 0)
|
|
||||||
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "ascent"));
|
|
||||||
if (byte[3] != 0)
|
|
||||||
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "ceiling"));
|
|
||||||
if (byte[4] != 0)
|
|
||||||
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "workload"));
|
|
||||||
if (byte[5] != 0)
|
|
||||||
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "transmitter"));
|
|
||||||
if (j == 3) {
|
|
||||||
read_bytes(1);
|
|
||||||
if (is_O2) {
|
|
||||||
read_bytes(1);
|
|
||||||
o2percent = tmp_1byte;
|
|
||||||
}
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
free(byte);
|
|
||||||
|
|
||||||
// In commit 5f44fdd setpoint replaced po2, so although this is not necessarily CCR dive ...
|
|
||||||
if (is_O2)
|
|
||||||
sample->setpoint.mbar = calculate_depth_to_mbar(sample->depth.mm, dt_dive->surface_pressure, 0) * o2percent / 100;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
bail:
|
|
||||||
return sample;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads the header of a file and returns the header struct
|
* Fills a device_data_t structure based on the info from g_models table, using
|
||||||
* If it's not a DATATRAK file returns header zero initalized
|
* the dc's model number as start point.
|
||||||
|
* Returns libdc's equivalent model number (also from g_models) or zero if
|
||||||
|
* this a manual dive.
|
||||||
*/
|
*/
|
||||||
static dtrakheader read_file_header(FILE *archivo)
|
static int dtrak_prepare_data(int model, device_data_t *dev_data)
|
||||||
{
|
{
|
||||||
dtrakheader fileheader = { 0 };
|
dc_descriptor_t *d = NULL;
|
||||||
const short headerbytes = 12;
|
int i = 0;
|
||||||
unsigned char *lector = (unsigned char *)malloc(headerbytes);
|
|
||||||
|
|
||||||
if (fread(lector, 1, headerbytes, archivo) != headerbytes) {
|
while (model != g_models[i].model_num && g_models[i].model_num != 0xEE)
|
||||||
free(lector);
|
i++;
|
||||||
return fileheader;
|
dev_data->model = copy_string(g_models[i].name);
|
||||||
}
|
sscanf(g_models[i].name,"%m[A-Za-z] ", &dev_data->vendor);
|
||||||
if (two_bytes_to_int(lector[0], lector[1]) != 0xA100) {
|
dev_data->product = copy_string(strchr(g_models[i].name, ' ') + 1);
|
||||||
report_error(translate("gettextFromC", "Error: the file does not appear to be a DATATRAK dive log"));
|
|
||||||
free(lector);
|
d = get_descriptor(g_models[i].type, g_models[i].libdc_num);
|
||||||
return fileheader;
|
if (d)
|
||||||
}
|
dev_data->descriptor = d;
|
||||||
fileheader.header = (lector[0] << 8) + lector[1];
|
else
|
||||||
fileheader.dc_serial_1 = two_bytes_to_int(lector[2], lector[3]);
|
return 0;
|
||||||
fileheader.dc_serial_2 = two_bytes_to_int(lector[4], lector[5]);
|
return g_models[i].libdc_num;
|
||||||
fileheader.divesNum = two_bytes_to_int(lector[7], lector[6]);
|
|
||||||
free(lector);
|
|
||||||
return fileheader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK(_func, _val) if ((_func) != (_val)) goto bail
|
/*
|
||||||
|
* Reads the size of a datatrak profile from actual position in buffer *ptr,
|
||||||
|
* zero padds it with a faked header and inserts the model number for
|
||||||
|
* libdivecomputer parsing. Puts the completed buffer in a pre-allocated
|
||||||
|
* compl_buffer, and returns status.
|
||||||
|
*/
|
||||||
|
static dc_status_t dt_libdc_buffer(unsigned char *ptr, int prf_length, int dc_model, unsigned char *compl_buffer)
|
||||||
|
{
|
||||||
|
if (compl_buffer == NULL)
|
||||||
|
return DC_STATUS_NOMEMORY;
|
||||||
|
compl_buffer[3] = (unsigned char) dc_model;
|
||||||
|
memcpy(compl_buffer + 18, ptr, prf_length);
|
||||||
|
return DC_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parses the dive extracting its data and filling a subsurface's dive structure
|
* Parses the dive extracting its data and filling a subsurface's dive structure
|
||||||
|
|
Loading…
Add table
Reference in a new issue