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:
Lubomir I. Ivanov 2014-10-28 13:35:14 +02:00 committed by Dirk Hohndel
parent 4bc9b7748b
commit e64a25d715

View file

@ -143,19 +143,15 @@ static void cochran_debug_write(const unsigned char *data, unsigned size)
return; return;
int show = 1, i; int show = 1, i;
for (i = 0; i < size; i += 16) for (i = 0; i < size; i += 16)
show = show_line(i, data + i, size - i, show); 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: case TYPE_GEMINI:
switch (seconds % 4) switch (seconds % 4) {
{
case 0: case 0:
printf("Hex: %02x %02x ", s[0], s[1]); printf("Hex: %02x %02x ", s[0], s[1]);
break; break;
@ -171,8 +167,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
} }
break; break;
case TYPE_COMMANDER: case TYPE_COMMANDER:
switch (seconds % 2) switch (seconds % 2) {
{
case 0: case 0:
printf("Hex: %02x %02x ", s[0], s[1]); printf("Hex: %02x %02x ", s[0], s[1]);
break; break;
@ -182,8 +177,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
} }
break; break;
case TYPE_EMC: case TYPE_EMC:
switch (seconds % 2) switch (seconds % 2) {
{
case 0: case 0:
printf("Hex: %02x %02x %02x ", s[0], s[1], s[2]); printf("Hex: %02x %02x %02x ", s[0], s[1], s[2]);
break; break;
@ -200,8 +194,7 @@ static void cochran_debug_sample(const char * s, unsigned int seconds)
#endif // COCHRAN_DEBUG #endif // COCHRAN_DEBUG
static void cochran_parse_header( static void cochran_parse_header(const unsigned char *decode, unsigned mod,
const unsigned char *decode, unsigned mod,
const unsigned char *in, unsigned size) const unsigned char *in, unsigned size)
{ {
unsigned char *buf = malloc(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); partial_decode(0x5414, size, decode, 0, mod, in, size, buf);
// Detect log type // Detect log type
switch (buf[0x133]) switch (buf[0x133]) {
{
case '2': // Cochran Commander, version II log format case '2': // Cochran Commander, version II log format
config.logbook_size = 256; config.logbook_size = 256;
if (buf[0x132] == 0x10) { if (buf[0x132] == 0x10) {
@ -254,16 +246,12 @@ static void cochran_parse_header(
free(buf); free(buf);
} }
/* /*
* Bytes expected after a pre-dive event code * 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 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}, {0x09, 18}, {0x0c, 18}, {0x0d, 18},
{0x0e, 18}, {0x0e, 18},
@ -280,44 +268,35 @@ static int cochran_predive_event_bytes (unsigned char code)
{0x10, 20}, {0x10, 20},
{-1, 0}}; {-1, 0}};
switch (config.type) switch (config.type) {
{
case TYPE_GEMINI: case TYPE_GEMINI:
while (gem_event_bytes[x][0] != code && gem_event_bytes[x][0] != -1) while (gem_event_bytes[x][0] != code && gem_event_bytes[x][0] != -1)
x++; x++;
return gem_event_bytes[x][1]; return gem_event_bytes[x][1];
break; break;
case TYPE_COMMANDER: case TYPE_COMMANDER:
while (cmdr_event_bytes[x][0] != code && cmdr_event_bytes[x][0] != -1) while (cmdr_event_bytes[x][0] != code && cmdr_event_bytes[x][0] != -1)
x++; x++;
return cmdr_event_bytes[x][1]; return cmdr_event_bytes[x][1];
break; break;
case TYPE_EMC: case TYPE_EMC:
while (emc_event_bytes[x][0] != code && emc_event_bytes[x][0] != -1) while (emc_event_bytes[x][0] != code && emc_event_bytes[x][0] != -1)
x++; x++;
return emc_event_bytes[x][1]; return emc_event_bytes[x][1];
break; break;
} }
} }
int cochran_dive_event_bytes(unsigned char event) int cochran_dive_event_bytes(unsigned char event)
{ {
if (event == 0xAD || event == 0xAB) return (event == 0xAD || event == 0xAB) ? 4 : 0;
return 4;
else
return 0;
} }
static void cochran_dive_event(struct divecomputer *dc, const unsigned char *s, static void cochran_dive_event(struct divecomputer *dc, const unsigned char *s,
unsigned int seconds, unsigned int *in_deco, unsigned int seconds, unsigned int *in_deco,
unsigned int *deco_ceiling, unsigned int *deco_time) unsigned int *deco_ceiling, unsigned int *deco_time)
{ {
switch (s[0]) switch (s[0]) {
{
case 0xC5: // Deco obligation begins case 0xC5: // Deco obligation begins
*in_deco = 1; *in_deco = 1;
add_event(dc, seconds, SAMPLE_EVENT_DECOSTOP, 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 * Parse sample data, extract events and build a dive
*/ */
static void cochran_parse_samples(struct dive *dive, const unsigned char *log, static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
const unsigned char *samples, int size, const unsigned char *samples, int size,
unsigned int *duration, double *max_depth, unsigned int *duration, double *max_depth,
@ -473,8 +450,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
*max_depth = 0, *avg_depth = 0, *min_temp = 0xFF; *max_depth = 0, *avg_depth = 0, *min_temp = 0xFF;
// Get starting depth and temp (tank PSI???) // Get starting depth and temp (tank PSI???)
switch (config.type) switch (config.type) {
{
case TYPE_GEMINI: case TYPE_GEMINI:
depth = (float)(log_cmdr->start_depth[0] depth = (float)(log_cmdr->start_depth[0]
+ log_cmdr->start_depth[1] * 256) / 4; + log_cmdr->start_depth[1] * 256) / 4;
@ -482,7 +458,6 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
sgc_rate = (float)(log_cmdr->start_sgc[0] sgc_rate = (float)(log_cmdr->start_sgc[0]
+ log_cmdr->start_sgc[1] * 256) / 2; + log_cmdr->start_sgc[1] * 256) / 2;
break; break;
case TYPE_COMMANDER: case TYPE_COMMANDER:
depth = (float)(log_cmdr->start_depth[0] depth = (float)(log_cmdr->start_depth[0]
+ log_cmdr->start_depth[1] * 256) / 4; + log_cmdr->start_depth[1] * 256) / 4;
@ -534,11 +509,9 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
cochran_debug_sample(s, seconds); cochran_debug_sample(s, seconds);
#endif #endif
switch (config.type) switch (config.type) {
{
case TYPE_COMMANDER: case TYPE_COMMANDER:
switch (seconds % 2) switch (seconds % 2) {
{
case 0: // Ascent rate case 0: // Ascent rate
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1); ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1);
break; break;
@ -549,8 +522,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
break; break;
case TYPE_GEMINI: case TYPE_GEMINI:
// Gemini with tank pressure and SAC rate. // Gemini with tank pressure and SAC rate.
switch (seconds % 4) switch (seconds % 4) {
{
case 0: // Ascent rate case 0: // Ascent rate
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1); ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1);
break; break;
@ -566,8 +538,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
} }
break; break;
case TYPE_EMC: case TYPE_EMC:
switch (seconds % 2) switch (seconds % 2) {
{
case 0: // Ascent rate case 0: // Ascent rate
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1); ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1);
break; break;
@ -576,8 +547,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
break; break;
} }
// Get NDL and deco information // Get NDL and deco information
switch (seconds % 24) switch (seconds % 24) {
{
case 20: case 20:
if (in_deco) { if (in_deco) {
// Fist stop time // Fist stop time
@ -623,7 +593,6 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
*duration = seconds - 1; *duration = seconds - 1;
} }
static void cochran_parse_dive(const unsigned char *decode, unsigned mod, static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
const unsigned char *in, unsigned size) 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_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); 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_GEMINI:
case TYPE_COMMANDER: case TYPE_COMMANDER:
if (config.type == TYPE_GEMINI) { 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_sec = emc_log->seconds;
tm.tm_isdst = -1; tm.tm_isdst = -1;
dive->when = dc->when = utc_mktime(&tm); dive->when = dc->when = utc_mktime(&tm);
dive->number = emc_log->number[0] + emc_log->number[1] * 256 + 1; 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; 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; return 0;
mod = decode[0x100] + 1; mod = decode[0x100] + 1;
cochran_parse_header(decode, mod, mem->buffer + 0x40000, dive1 - 0x40000); cochran_parse_header(decode, mod, mem->buffer + 0x40000, dive1 - 0x40000);
// Decode each dive // Decode each dive