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
				
			
		
							
								
								
									
										66
									
								
								cochran.c
									
										
									
									
									
								
							
							
						
						
									
										66
									
								
								cochran.c
									
										
									
									
									
								
							|  | @ -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) | ||||
| { | ||||
| 	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,16 +246,12 @@ static void cochran_parse_header( | |||
| 	free(buf); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
| * Bytes expected after a pre-dive event 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}, | ||||
| 	                               {0x09, 18}, {0x0c, 18}, {0x0d, 18}, | ||||
| 	                               {0x0e, 18}, | ||||
|  | @ -280,44 +268,35 @@ static int cochran_predive_event_bytes (unsigned char code) | |||
| 	                               {0x10, 20}, | ||||
| 	                               {-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,8 +450,7 @@ 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] | ||||
| 			+ 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] | ||||
| 			+ log_cmdr->start_sgc[1] * 256) / 2; | ||||
| 		break; | ||||
| 
 | ||||
| 	case TYPE_COMMANDER: | ||||
| 		depth = (float)(log_cmdr->start_depth[0] | ||||
| 			+ 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); | ||||
| #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,8 +522,7 @@ 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; | ||||
|  | @ -566,8 +538,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log, | |||
| 			} | ||||
| 			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; | ||||
|  | @ -576,8 +547,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log, | |||
| 				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
		Add a link
		
	
		Reference in a new issue