2024-11-11 15:41:31 +13:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "errorhelper.h"
|
|
|
|
#include "subsurface-string.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "dive.h"
|
|
|
|
#include "divelist.h"
|
|
|
|
#include "divelog.h"
|
|
|
|
#include "extradata.h"
|
|
|
|
#include "format.h"
|
|
|
|
#include "libdivecomputer.h"
|
|
|
|
|
2024-11-11 15:41:31 +13:00
|
|
|
// As supplied by Divesoft
|
2025-01-01 16:50:21 +13:00
|
|
|
static constexpr std::string_view divesoft_liberty_serial_prefix = "7026";
|
|
|
|
static constexpr std::string_view divesoft_freedom_serial_prefix = "7044";
|
|
|
|
static constexpr std::string_view divesoft_freedom_plus_serial_prefix = "7273";
|
2024-11-11 15:41:31 +13:00
|
|
|
|
|
|
|
// From libdivecomputer
|
2025-01-01 16:50:21 +13:00
|
|
|
static constexpr int divesoft_liberty_model = 10;
|
|
|
|
static constexpr int divesoft_freedom_model = 19;
|
2024-11-11 15:41:31 +13:00
|
|
|
|
2025-01-01 16:50:21 +13:00
|
|
|
int divesoft_import(const std::string &buffer, struct divelog *log)
|
2024-11-11 15:41:31 +13:00
|
|
|
{
|
2025-01-01 16:50:21 +13:00
|
|
|
std::string model_identifier = buffer.substr(52, 4);
|
2024-11-11 15:41:31 +13:00
|
|
|
int model = 0;
|
2025-01-01 16:50:21 +13:00
|
|
|
if (model_identifier == divesoft_liberty_serial_prefix)
|
2024-11-11 15:41:31 +13:00
|
|
|
model = divesoft_liberty_model;
|
2025-01-01 16:50:21 +13:00
|
|
|
else if (model_identifier == divesoft_freedom_serial_prefix || model_identifier == divesoft_freedom_plus_serial_prefix)
|
2024-11-11 15:41:31 +13:00
|
|
|
model = divesoft_freedom_model;
|
2025-01-01 16:50:21 +13:00
|
|
|
|
2024-11-11 15:41:31 +13:00
|
|
|
device_data_t devdata;
|
2025-01-01 16:50:21 +13:00
|
|
|
devdata.log = log;
|
2024-11-11 15:41:31 +13:00
|
|
|
int ret = prepare_device_descriptor(model, DC_FAMILY_DIVESOFT_FREEDOM, devdata);
|
|
|
|
if (ret == 0)
|
|
|
|
return report_error("%s", translate("gettextFromC", "Unknown DC"));
|
|
|
|
|
|
|
|
auto d = std::make_unique<dive>();
|
|
|
|
d->dcs[0].model = devdata.vendor + " " + devdata.model + " (Imported from file)";
|
|
|
|
|
|
|
|
// Parse the dive data
|
2025-01-01 16:50:21 +13:00
|
|
|
dc_status_t rc = libdc_buffer_parser(d.get(), &devdata, (const unsigned char *)buffer.data(), buffer.size());
|
2024-11-11 15:41:31 +13:00
|
|
|
if (rc != DC_STATUS_SUCCESS)
|
|
|
|
return report_error(translate("gettextFromC", "Error - %s - parsing dive %d"), errmsg(rc), d->number);
|
|
|
|
|
|
|
|
log->dives.record_dive(std::move(d));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|