Enable diagnostic logs from dc configuration

This implements support for writing debug/diagnostic logs when
configuring dive computers and upgrading the firmware.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2015-05-27 21:19:12 +02:00 committed by Dirk Hohndel
parent 4124052b38
commit 4321ef1d88
3 changed files with 91 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "configuredivecomputerthreads.h"
#include "libdivecomputer/hw.h"
#include "libdivecomputer.h"
#include <QDateTime>
#include <QStringList>
@ -1463,9 +1464,26 @@ ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) : D
void ReadSettingsThread::run()
{
FILE *fp = NULL;
bool supported = false;
dc_status_t rc;
if (m_data->libdc_log)
fp = subsurface_fopen(logfile_name, "w");
m_data->libdc_logfile = fp;
rc = dc_context_new(&m_data->context);
if (rc != DC_STATUS_SUCCESS) {
emit error(tr("Unable to create libdivecomputer context"));
return;
}
if (fp) {
dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc(m_data->context, logfunc, fp);
}
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
@ -1516,6 +1534,10 @@ void ReadSettingsThread::run()
} else {
emit error(tr("Could not a establish connection to the dive computer."));
}
dc_context_free(m_data->context);
if (fp)
fclose(fp);
}
WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data) : DeviceThread(parent, data)
@ -1529,9 +1551,26 @@ void WriteSettingsThread::setDeviceDetails(DeviceDetails *details)
void WriteSettingsThread::run()
{
FILE *fp = NULL;
bool supported = false;
dc_status_t rc;
if (m_data->libdc_log)
fp = subsurface_fopen(logfile_name, "w");
m_data->libdc_logfile = fp;
rc = dc_context_new(&m_data->context);
if (rc != DC_STATUS_SUCCESS) {
emit error(tr("Unable to create libdivecomputer context"));
return;
}
if (fp) {
dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc(m_data->context, logfunc, fp);
}
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
switch (dc_device_get_type(m_data->device)) {
@ -1576,6 +1615,11 @@ void WriteSettingsThread::run()
} else {
emit error(tr("Could not a establish connection to the dive computer."));
}
dc_context_free(m_data->context);
if (fp)
fclose(fp);
}
@ -1585,16 +1629,33 @@ FirmwareUpdateThread::FirmwareUpdateThread(QObject *parent, device_data_t *data,
void FirmwareUpdateThread::run()
{
FILE *fp = NULL;
bool supported = false;
dc_status_t rc;
if (m_data->libdc_log)
fp = subsurface_fopen(logfile_name, "w");
m_data->libdc_logfile = fp;
rc = dc_context_new(&m_data->context);
if (rc != DC_STATUS_SUCCESS) {
emit error(tr("Unable to create libdivecomputer context"));
return;
}
if (fp) {
dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc(m_data->context, logfunc, fp);
}
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
rc = dc_device_set_events(m_data->device, DC_EVENT_PROGRESS, DeviceThread::event_cb, this);
if (rc != DC_STATUS_SUCCESS) {
emit error("Error registering the event handler.");
dc_device_close(m_data->device);
return;
goto firmware_run_out;
}
switch (dc_device_get_type(m_data->device)) {
#if DC_VERSION_CHECK(0, 5, 0)
@ -1621,6 +1682,11 @@ void FirmwareUpdateThread::run()
} else {
emit error(tr("Could not a establish connection to the dive computer."));
}
firmware_run_out:
dc_context_free(m_data->context);
if (fp)
fclose(fp);
}
@ -1630,8 +1696,26 @@ ResetSettingsThread::ResetSettingsThread(QObject *parent, device_data_t *data) :
void ResetSettingsThread::run()
{
FILE *fp = NULL;
bool supported = false;
dc_status_t rc;
if (m_data->libdc_log)
fp = subsurface_fopen(logfile_name, "w");
m_data->libdc_logfile = fp;
rc = dc_context_new(&m_data->context);
if (rc != DC_STATUS_SUCCESS) {
emit error(tr("Unable to create libdivecomputer context"));
return;
}
if (fp) {
dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc(m_data->context, logfunc, fp);
}
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
if (rc == DC_STATUS_SUCCESS) {
#if DC_VERSION_CHECK(0, 5, 0)
@ -1649,4 +1733,8 @@ void ResetSettingsThread::run()
} else {
emit error(tr("Could not a establish connection to the dive computer."));
}
dc_context_free(m_data->context);
if (fp)
fclose(fp);
}

View file

@ -874,7 +874,7 @@ static const char *do_device_import(device_data_t *data)
return NULL;
}
static void
void
logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
{
const char *loglevels[] = { "NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL" };

View file

@ -45,6 +45,7 @@ const char *errmsg (dc_status_t rc);
const char *do_libdivecomputer_import(device_data_t *data);
const char *do_uemis_import(device_data_t *data);
dc_status_t libdc_buffer_parser(struct dive *dive, device_data_t *data, unsigned char *buffer, int size);
void logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata);
extern int import_thread_cancelled;
extern const char *progress_bar_text;