Added the initial implementation for the Heinrichs Weikamp OSTC.
This commit is contained in:
parent
a87398b7c6
commit
7e6a57bd1c
@ -17,7 +17,8 @@ bin_PROGRAMS = \
|
||||
veo250 \
|
||||
vtpro \
|
||||
nemo \
|
||||
puck
|
||||
puck \
|
||||
ostc
|
||||
|
||||
if IRDA
|
||||
bin_PROGRAMS += smart
|
||||
@ -55,6 +56,8 @@ nemo_SOURCES = mares_nemo_test.c
|
||||
|
||||
puck_SOURCES = mares_puck_test.c
|
||||
|
||||
ostc_SOURCES = hw_ostc_test.c
|
||||
|
||||
if IRDA
|
||||
smart_SOURCES = uwatec_smart_test.c
|
||||
endif
|
||||
|
||||
121
examples/hw_ostc_test.c
Normal file
121
examples/hw_ostc_test.c
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* libdivecomputer
|
||||
*
|
||||
* Copyright (C) 2009 Jef Driesen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h> // fopen, fwrite, fclose
|
||||
|
||||
#include "hw_ostc.h"
|
||||
#include "utils.h"
|
||||
|
||||
device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("hw_ostc_device_open\n");
|
||||
device_status_t rc = hw_ostc_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
|
||||
message ("Dumping data\n");
|
||||
FILE* fp = fopen (filename, "wb");
|
||||
if (fp != NULL) {
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
errmsg (device_status_t rc)
|
||||
{
|
||||
switch (rc) {
|
||||
case DEVICE_STATUS_SUCCESS:
|
||||
return "Success";
|
||||
case DEVICE_STATUS_UNSUPPORTED:
|
||||
return "Unsupported operation";
|
||||
case DEVICE_STATUS_TYPE_MISMATCH:
|
||||
return "Device type mismatch";
|
||||
case DEVICE_STATUS_ERROR:
|
||||
return "Generic error";
|
||||
case DEVICE_STATUS_IO:
|
||||
return "Input/output error";
|
||||
case DEVICE_STATUS_MEMORY:
|
||||
return "Memory error";
|
||||
case DEVICE_STATUS_PROTOCOL:
|
||||
return "Protocol error";
|
||||
case DEVICE_STATUS_TIMEOUT:
|
||||
return "Timeout";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
message_set_logfile ("OSTC.LOG");
|
||||
|
||||
#ifdef _WIN32
|
||||
const char* name = "COM1";
|
||||
#else
|
||||
const char* name = "/dev/ttyS0";
|
||||
#endif
|
||||
|
||||
if (argc > 1) {
|
||||
name = argv[1];
|
||||
}
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "OSTC.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
message ("test_dump_memory: %s\n", errmsg (a));
|
||||
|
||||
message_set_logfile (NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -32,6 +32,7 @@
|
||||
#include <uwatec.h>
|
||||
#include <oceanic.h>
|
||||
#include <mares.h>
|
||||
#include <hw.h>
|
||||
#include <utils.h>
|
||||
|
||||
typedef struct backend_table_t {
|
||||
@ -55,7 +56,8 @@ static const backend_table_t g_backends[] = {
|
||||
{"veo250", DEVICE_TYPE_OCEANIC_VEO250},
|
||||
{"atom2", DEVICE_TYPE_OCEANIC_ATOM2},
|
||||
{"nemo", DEVICE_TYPE_MARES_NEMO},
|
||||
{"puck", DEVICE_TYPE_MARES_PUCK}
|
||||
{"puck", DEVICE_TYPE_MARES_PUCK},
|
||||
{"ostc", DEVICE_TYPE_HW_OSTC}
|
||||
};
|
||||
|
||||
static device_type_t
|
||||
@ -232,6 +234,9 @@ dowork (device_type_t backend, const char *devname, const char *filename)
|
||||
case DEVICE_TYPE_MARES_PUCK:
|
||||
rc = mares_puck_device_open (&device, devname);
|
||||
break;
|
||||
case DEVICE_TYPE_HW_OSTC:
|
||||
rc = hw_ostc_device_open (&device, devname);
|
||||
break;
|
||||
default:
|
||||
rc = DEVICE_STATUS_ERROR;
|
||||
break;
|
||||
|
||||
@ -192,6 +192,10 @@
|
||||
RelativePath="..\src\device.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\hw_ostc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\irda.c"
|
||||
>
|
||||
@ -362,6 +366,14 @@
|
||||
RelativePath="..\src\device.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\hw.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\hw_ostc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\irda.h"
|
||||
>
|
||||
|
||||
@ -29,7 +29,9 @@ libdivecomputer_HEADERS = \
|
||||
oceanic_vtpro.h \
|
||||
mares.h \
|
||||
mares_nemo.h \
|
||||
mares_puck.h
|
||||
mares_puck.h \
|
||||
hw.h \
|
||||
hw_ostc.h
|
||||
|
||||
#
|
||||
# Source files.
|
||||
@ -68,6 +70,8 @@ libdivecomputer_la_SOURCES = \
|
||||
mares_common.h mares_common.c \
|
||||
mares_nemo.h mares_nemo.c mares_nemo_parser.c \
|
||||
mares_puck.h mares_puck.c \
|
||||
hw.h \
|
||||
hw_ostc.h hw_ostc.c \
|
||||
ringbuffer.h ringbuffer.c \
|
||||
checksum.h checksum.c \
|
||||
array.h array.c \
|
||||
|
||||
@ -45,7 +45,8 @@ typedef enum device_type_t {
|
||||
DEVICE_TYPE_OCEANIC_VEO250,
|
||||
DEVICE_TYPE_OCEANIC_VTPRO,
|
||||
DEVICE_TYPE_MARES_NEMO,
|
||||
DEVICE_TYPE_MARES_PUCK
|
||||
DEVICE_TYPE_MARES_PUCK,
|
||||
DEVICE_TYPE_HW_OSTC
|
||||
} device_type_t;
|
||||
|
||||
typedef enum device_status_t {
|
||||
|
||||
27
src/hw.h
Normal file
27
src/hw.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* libdivecomputer
|
||||
*
|
||||
* Copyright (C) 2009 Jef Driesen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef HW_H
|
||||
#define HW_H
|
||||
|
||||
#include "hw_ostc.h"
|
||||
|
||||
#endif /* HW_H */
|
||||
180
src/hw_ostc.c
Normal file
180
src/hw_ostc.c
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* libdivecomputer
|
||||
*
|
||||
* Copyright (C) 2009 Jef Driesen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h> // memcmp, memcpy
|
||||
#include <stdlib.h> // malloc, free
|
||||
#include <assert.h> // assert
|
||||
|
||||
#include "device-private.h"
|
||||
#include "hw_ostc.h"
|
||||
#include "serial.h"
|
||||
#include "checksum.h"
|
||||
#include "utils.h"
|
||||
#include "array.h"
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
typedef struct hw_ostc_device_t {
|
||||
device_t base;
|
||||
struct serial *port;
|
||||
} hw_ostc_device_t;
|
||||
|
||||
static device_status_t hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t hw_ostc_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t hw_ostc_device_backend = {
|
||||
DEVICE_TYPE_HW_OSTC,
|
||||
NULL, /* set_fingerprint */
|
||||
NULL, /* version */
|
||||
NULL, /* read */
|
||||
NULL, /* write */
|
||||
hw_ostc_device_dump, /* dump */
|
||||
NULL, /* foreach */
|
||||
hw_ostc_device_close /* close */
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
device_is_hw_ostc (device_t *abstract)
|
||||
{
|
||||
if (abstract == NULL)
|
||||
return 0;
|
||||
|
||||
return abstract->backend == &hw_ostc_device_backend;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
hw_ostc_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
|
||||
// Allocate memory.
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) malloc (sizeof (hw_ostc_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, &hw_ostc_device_backend);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
|
||||
// Open the device.
|
||||
int rc = serial_open (&device->port, name);
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (115200 8N1).
|
||||
rc = serial_configure (device->port, 115200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (INFINITE).
|
||||
if (serial_set_timeout (device->port, -1) == -1) {
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
}
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
hw_ostc_device_close (device_t *abstract)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, HW_OSTC_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
progress.maximum = HW_OSTC_MEMORY_SIZE;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Send the command.
|
||||
unsigned char command[1] = {'a'};
|
||||
int rc = serial_write (device->port, command, sizeof (command));
|
||||
if (rc != sizeof (command)) {
|
||||
WARNING ("Failed to send the command.");
|
||||
return EXITCODE (rc);
|
||||
}
|
||||
|
||||
// Receive the answer.
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
rc = serial_read (device->port, data, HW_OSTC_MEMORY_SIZE);
|
||||
if (rc != HW_OSTC_MEMORY_SIZE) {
|
||||
WARNING ("Failed to receive the answer.");
|
||||
return EXITCODE (rc);
|
||||
}
|
||||
|
||||
// Update and emit a progress event.
|
||||
progress.current += HW_OSTC_MEMORY_SIZE;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
39
src/hw_ostc.h
Normal file
39
src/hw_ostc.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* libdivecomputer
|
||||
*
|
||||
* Copyright (C) 2009 Jef Driesen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef HW_OSTC_H
|
||||
#define HW_OSTC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#define HW_OSTC_MEMORY_SIZE 33034
|
||||
|
||||
device_status_t
|
||||
hw_ostc_device_open (device_t **device, const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* HW_OSTC_H */
|
||||
@ -92,6 +92,7 @@ uwatec_aladin_extract_dives
|
||||
uwatec_memomouse_device_open
|
||||
uwatec_memomouse_device_set_timestamp
|
||||
uwatec_memomouse_extract_dives
|
||||
hw_ostc_device_open
|
||||
#endif
|
||||
|
||||
#ifdef IRDA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user