mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cochran.c: coding style cleanup
- empty lines - indentation - { placement - others... Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4bc9b7748b
commit
e64a25d715
1 changed files with 199 additions and 233 deletions
112
cochran.c
112
cochran.c
|
@ -45,11 +45,11 @@ struct config {
|
|||
|
||||
|
||||
// Convert 4 bytes into an INT
|
||||
#define array_uint16_le(p) ( (unsigned int) (p)[0] \
|
||||
#define array_uint16_le(p) ((unsigned int) (p)[0] \
|
||||
+ ((p)[1]<<8) )
|
||||
#define array_uint32_le(p) ( (unsigned int) (p)[0] \
|
||||
#define array_uint32_le(p) ((unsigned int) (p)[0] \
|
||||
+ ((p)[1]<<8) + ((p)[2]<<16) \
|
||||
+ ((p)[3]<<24) )
|
||||
+ ((p)[3]<<24))
|
||||
|
||||
/*
|
||||
* The Cochran file format is designed to be annoying to read. It's roughly:
|
||||
|
@ -143,19 +143,15 @@ static void cochran_debug_write(const unsigned char *data, unsigned size)
|
|||
return;
|
||||
|
||||
int show = 1, i;
|
||||
|
||||
|
||||
for (i = 0; i < size; i += 16)
|
||||
show = show_line(i, data + i, size - i, show);
|
||||
}
|
||||
|
||||
static void cochran_debug_sample(const char * s, unsigned int seconds)
|
||||
static void cochran_debug_sample(const char *s, unsigned int seconds)
|
||||
{
|
||||
switch (config.type)
|
||||
{
|
||||
switch (config.type) {
|
||||
case TYPE_GEMINI:
|
||||
switch (seconds % 4)
|
||||
{
|
||||
switch (seconds % 4) {
|
||||
case 0:
|
||||
printf("Hex: %02x %02x ", s[0], s[1]);
|
||||
break;
|
||||
|
@ -171,8 +167,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
|
|||
}
|
||||
break;
|
||||
case TYPE_COMMANDER:
|
||||
switch (seconds % 2)
|
||||
{
|
||||
switch (seconds % 2) {
|
||||
case 0:
|
||||
printf("Hex: %02x %02x ", s[0], s[1]);
|
||||
break;
|
||||
|
@ -182,8 +177,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
|
|||
}
|
||||
break;
|
||||
case TYPE_EMC:
|
||||
switch (seconds % 2)
|
||||
{
|
||||
switch (seconds % 2) {
|
||||
case 0:
|
||||
printf("Hex: %02x %02x %02x ", s[0], s[1], s[2]);
|
||||
break;
|
||||
|
@ -200,8 +194,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
|
|||
|
||||
#endif // COCHRAN_DEBUG
|
||||
|
||||
static void cochran_parse_header(
|
||||
const unsigned char *decode, unsigned mod,
|
||||
static void cochran_parse_header(const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
{
|
||||
unsigned char *buf = malloc(size);
|
||||
|
@ -223,8 +216,7 @@ static void cochran_parse_header(
|
|||
partial_decode(0x5414, size, decode, 0, mod, in, size, buf);
|
||||
|
||||
// Detect log type
|
||||
switch (buf[0x133])
|
||||
{
|
||||
switch (buf[0x133]) {
|
||||
case '2': // Cochran Commander, version II log format
|
||||
config.logbook_size = 256;
|
||||
if (buf[0x132] == 0x10) {
|
||||
|
@ -254,70 +246,57 @@ static void cochran_parse_header(
|
|||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bytes expected after a pre-dive event code
|
||||
*/
|
||||
|
||||
static int cochran_predive_event_bytes (unsigned char code)
|
||||
static int cochran_predive_event_bytes(unsigned char code)
|
||||
{
|
||||
|
||||
int x = 0;
|
||||
|
||||
int gem_event_bytes[15][2] = { {0x00, 10}, {0x02, 17}, {0x08, 18},
|
||||
int gem_event_bytes[15][2] = {{0x00, 10}, {0x02, 17}, {0x08, 18},
|
||||
{0x09, 18}, {0x0c, 18}, {0x0d, 18},
|
||||
{0x0e, 18},
|
||||
{ -1, 0} };
|
||||
int cmdr_event_bytes[15][2] = { {0x00, 16}, {0x01, 20}, {0x02, 17},
|
||||
{-1, 0}};
|
||||
int cmdr_event_bytes[15][2] = {{0x00, 16}, {0x01, 20}, {0x02, 17},
|
||||
{0x03, 16}, {0x06, 18}, {0x07, 18},
|
||||
{0x08, 18}, {0x09, 18}, {0x0a, 18},
|
||||
{0x0b, 20}, {0x0c, 18}, {0x0d, 18},
|
||||
{0x0e, 18}, {0x10, 20},
|
||||
{ -1, 0} };
|
||||
int emc_event_bytes[15][2] = { {0x00, 18}, {0x01, 22}, {0x02, 19},
|
||||
{-1, 0}};
|
||||
int emc_event_bytes[15][2] = {{0x00, 18}, {0x01, 22}, {0x02, 19},
|
||||
{0x03, 18}, {0x06, 20}, {0x07, 20},
|
||||
{0x0a, 20}, {0x0b, 20}, {0x0f, 18},
|
||||
{0x10, 20},
|
||||
{ -1, 0} };
|
||||
{-1, 0}};
|
||||
|
||||
switch (config.type)
|
||||
{
|
||||
switch (config.type) {
|
||||
case TYPE_GEMINI:
|
||||
while (gem_event_bytes[x][0] != code && gem_event_bytes[x][0] != -1)
|
||||
x++;
|
||||
|
||||
return gem_event_bytes[x][1];
|
||||
break;
|
||||
case TYPE_COMMANDER:
|
||||
while (cmdr_event_bytes[x][0] != code && cmdr_event_bytes[x][0] != -1)
|
||||
x++;
|
||||
|
||||
return cmdr_event_bytes[x][1];
|
||||
break;
|
||||
case TYPE_EMC:
|
||||
while (emc_event_bytes[x][0] != code && emc_event_bytes[x][0] != -1)
|
||||
x++;
|
||||
|
||||
return emc_event_bytes[x][1];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int cochran_dive_event_bytes(unsigned char event)
|
||||
{
|
||||
if (event == 0xAD || event == 0xAB)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
return (event == 0xAD || event == 0xAB) ? 4 : 0;
|
||||
}
|
||||
|
||||
static void cochran_dive_event(struct divecomputer *dc, const unsigned char *s,
|
||||
unsigned int seconds, unsigned int *in_deco,
|
||||
unsigned int *deco_ceiling, unsigned int *deco_time)
|
||||
{
|
||||
switch (s[0])
|
||||
{
|
||||
switch (s[0]) {
|
||||
case 0xC5: // Deco obligation begins
|
||||
*in_deco = 1;
|
||||
add_event(dc, seconds, SAMPLE_EVENT_DECOSTOP,
|
||||
|
@ -446,11 +425,9 @@ static void cochran_dive_event(struct divecomputer *dc, const unsigned char *s,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse sample data, extract events and build a dive
|
||||
*/
|
||||
|
||||
static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
||||
const unsigned char *samples, int size,
|
||||
unsigned int *duration, double *max_depth,
|
||||
|
@ -473,23 +450,21 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
*max_depth = 0, *avg_depth = 0, *min_temp = 0xFF;
|
||||
|
||||
// Get starting depth and temp (tank PSI???)
|
||||
switch (config.type)
|
||||
{
|
||||
switch (config.type) {
|
||||
case TYPE_GEMINI:
|
||||
depth = (float) (log_cmdr->start_depth[0]
|
||||
depth = (float)(log_cmdr->start_depth[0]
|
||||
+ log_cmdr->start_depth[1] * 256) / 4;
|
||||
psi = log_cmdr->start_psi[0] + log_cmdr->start_psi[1] * 256;
|
||||
sgc_rate = (float) (log_cmdr->start_sgc[0]
|
||||
sgc_rate = (float)(log_cmdr->start_sgc[0]
|
||||
+ log_cmdr->start_sgc[1] * 256) / 2;
|
||||
break;
|
||||
|
||||
case TYPE_COMMANDER:
|
||||
depth = (float) (log_cmdr->start_depth[0]
|
||||
depth = (float)(log_cmdr->start_depth[0]
|
||||
+ log_cmdr->start_depth[1] * 256) / 4;
|
||||
break;
|
||||
|
||||
case TYPE_EMC:
|
||||
depth = (float) log_emc->start_depth[0] / 256
|
||||
depth = (float)log_emc->start_depth[0] / 256
|
||||
+ log_emc->start_depth[1];
|
||||
temp = log_emc->start_temperature;
|
||||
break;
|
||||
|
@ -499,11 +474,11 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
unsigned int x = 0;
|
||||
if (samples[x] != 0x40) {
|
||||
unsigned int c;
|
||||
while ( (samples[x] & 0x80) == 0 && samples[x] != 0x40 && x < size) {
|
||||
while ((samples[x] & 0x80) == 0 && samples[x] != 0x40 && x < size) {
|
||||
c = cochran_predive_event_bytes(samples[x]) + 1;
|
||||
#ifdef COCHRAN_DEBUG
|
||||
printf ("Predive event: ", samples[x]);
|
||||
for (int y = 0; y < c; y++) printf ("%02x ", samples[x + y]);
|
||||
printf("Predive event: ", samples[x]);
|
||||
for (int y = 0; y < c; y++) printf("%02x ", samples[x + y]);
|
||||
putchar('\n');
|
||||
#endif
|
||||
x += c;
|
||||
|
@ -527,18 +502,16 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
}
|
||||
|
||||
// Depth is in every sample
|
||||
depth_sample = (float) (s[0] & 0x3F) / 4 * (s[0] & 0x40 ? -1 : 1);
|
||||
depth_sample = (float)(s[0] & 0x3F) / 4 * (s[0] & 0x40 ? -1 : 1);
|
||||
depth += depth_sample;
|
||||
|
||||
#ifdef COCHRAN_DEBUG
|
||||
cochran_debug_sample(s, seconds);
|
||||
#endif
|
||||
|
||||
switch (config.type)
|
||||
{
|
||||
switch (config.type) {
|
||||
case TYPE_COMMANDER:
|
||||
switch (seconds % 2)
|
||||
{
|
||||
switch (seconds % 2) {
|
||||
case 0: // Ascent rate
|
||||
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1);
|
||||
break;
|
||||
|
@ -549,35 +522,32 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
break;
|
||||
case TYPE_GEMINI:
|
||||
// Gemini with tank pressure and SAC rate.
|
||||
switch (seconds % 4)
|
||||
{
|
||||
switch (seconds % 4) {
|
||||
case 0: // Ascent rate
|
||||
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1);
|
||||
break;
|
||||
case 2: // PSI change
|
||||
psi -= (float) (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 4;
|
||||
psi -= (float)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 4;
|
||||
break;
|
||||
case 1: // SGC rate
|
||||
sgc_rate -= (float) (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 2;
|
||||
sgc_rate -= (float)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 2;
|
||||
break;
|
||||
case 3: // Temperature
|
||||
temp = (float) s[1] / 2 + 20;
|
||||
temp = (float)s[1] / 2 + 20;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TYPE_EMC:
|
||||
switch (seconds % 2)
|
||||
{
|
||||
switch (seconds % 2) {
|
||||
case 0: // Ascent rate
|
||||
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1);
|
||||
break;
|
||||
case 1: // Temperature
|
||||
temp = (float) s[1] / 2 + 20;
|
||||
temp = (float)s[1] / 2 + 20;
|
||||
break;
|
||||
}
|
||||
// Get NDL and deco information
|
||||
switch (seconds % 24)
|
||||
{
|
||||
switch (seconds % 24) {
|
||||
case 20:
|
||||
if (in_deco) {
|
||||
// Fist stop time
|
||||
|
@ -623,7 +593,6 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
*duration = seconds - 1;
|
||||
}
|
||||
|
||||
|
||||
static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
||||
const unsigned char *in, unsigned size)
|
||||
{
|
||||
|
@ -687,8 +656,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
struct cochran_cmdr_log_t *cmdr_log = (struct cochran_cmdr_log_t *) (buf + 0x4914);
|
||||
struct cochran_emc_log_t *emc_log = (struct cochran_emc_log_t *) (buf + 0x4914);
|
||||
|
||||
switch (config.type)
|
||||
{
|
||||
switch (config.type) {
|
||||
case TYPE_GEMINI:
|
||||
case TYPE_COMMANDER:
|
||||
if (config.type == TYPE_GEMINI) {
|
||||
|
@ -756,7 +724,6 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
tm.tm_sec = emc_log->seconds;
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
|
||||
dive->when = dc->when = utc_mktime(&tm);
|
||||
dive->number = emc_log->number[0] + emc_log->number[1] * 256 + 1;
|
||||
dc->duration.seconds = (emc_log->bt[0] + emc_log->bt[1] * 256) * 60;
|
||||
|
@ -816,7 +783,6 @@ int try_to_open_cochran(const char *filename, struct memblock *mem)
|
|||
return 0;
|
||||
|
||||
mod = decode[0x100] + 1;
|
||||
|
||||
cochran_parse_header(decode, mod, mem->buffer + 0x40000, dive1 - 0x40000);
|
||||
|
||||
// Decode each dive
|
||||
|
|
Loading…
Add table
Reference in a new issue