mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Handle more tanks than gasmixes
When Suunto Vytecs are used in gauge mode they don't record gasmixes. If a tank pressure sensor is present they nevertheless record the pressures. This patch handles this situation by assuming the tanks contain air (and warning the user about this). Reported-by: antonnorth@gmail.com Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									bc8c9f4c6f
								
							
						
					
					
						commit
						99595542ec
					
				
					 1 changed files with 35 additions and 27 deletions
				
			
		| 
						 | 
					@ -94,45 +94,53 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
 | 
				
			||||||
	unsigned int ntanks = 0;
 | 
						unsigned int ntanks = 0;
 | 
				
			||||||
	rc = dc_parser_get_field(parser, DC_FIELD_TANK_COUNT, 0, &ntanks);
 | 
						rc = dc_parser_get_field(parser, DC_FIELD_TANK_COUNT, 0, &ntanks);
 | 
				
			||||||
	if (rc == DC_STATUS_SUCCESS) {
 | 
						if (rc == DC_STATUS_SUCCESS) {
 | 
				
			||||||
		if (ntanks && ntanks != ngases) {
 | 
							if (ntanks && ntanks < ngases) {
 | 
				
			||||||
			shown_warning = true;
 | 
								shown_warning = true;
 | 
				
			||||||
			report_error("different number of gases (%d) and tanks (%d)", ngases, ntanks);
 | 
								report_error("Warning: different number of gases (%d) and tanks (%d)", ngases, ntanks);
 | 
				
			||||||
 | 
							} else if (ntanks > ngases) {
 | 
				
			||||||
 | 
								shown_warning = true;
 | 
				
			||||||
 | 
								report_error("Warning: smaller number of gases (%d) than tanks (%d). Assuming air.", ngases, ntanks);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
						bool no_volume = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ngases; i++) {
 | 
						for (i = 0; i < ngases || i < ntanks; i++) {
 | 
				
			||||||
		dc_gasmix_t gasmix = { 0 };
 | 
							if (i < ngases) {
 | 
				
			||||||
		int o2, he;
 | 
								dc_gasmix_t gasmix = { 0 };
 | 
				
			||||||
		bool no_volume = true;
 | 
								int o2, he;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rc = dc_parser_get_field(parser, DC_FIELD_GASMIX, i, &gasmix);
 | 
								rc = dc_parser_get_field(parser, DC_FIELD_GASMIX, i, &gasmix);
 | 
				
			||||||
		if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED)
 | 
								if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED)
 | 
				
			||||||
			return rc;
 | 
									return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (i >= MAX_CYLINDERS)
 | 
								if (i >= MAX_CYLINDERS)
 | 
				
			||||||
			continue;
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		o2 = rint(gasmix.oxygen * 1000);
 | 
								 o2 = rint(gasmix.oxygen * 1000);
 | 
				
			||||||
		he = rint(gasmix.helium * 1000);
 | 
								he = rint(gasmix.helium * 1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Ignore bogus data - libdivecomputer does some crazy stuff */
 | 
								/* Ignore bogus data - libdivecomputer does some crazy stuff */
 | 
				
			||||||
		if (o2 + he <= O2_IN_AIR || o2 > 1000) {
 | 
								if (o2 + he <= O2_IN_AIR || o2 > 1000) {
 | 
				
			||||||
			if (!shown_warning) {
 | 
									if (!shown_warning) {
 | 
				
			||||||
				shown_warning = true;
 | 
										shown_warning = true;
 | 
				
			||||||
				report_error("unlikely dive gas data from libdivecomputer: o2 = %d he = %d", o2, he);
 | 
										report_error("unlikely dive gas data from libdivecomputer: o2 = %d he = %d", o2, he);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									o2 = 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			o2 = 0;
 | 
								if (he < 0 || o2 + he > 1000) {
 | 
				
			||||||
		}
 | 
									if (!shown_warning) {
 | 
				
			||||||
		if (he < 0 || o2 + he > 1000) {
 | 
										shown_warning = true;
 | 
				
			||||||
			if (!shown_warning) {
 | 
										report_error("unlikely dive gas data from libdivecomputer: o2 = %d he = %d", o2, he);
 | 
				
			||||||
				shown_warning = true;
 | 
									}
 | 
				
			||||||
				report_error("unlikely dive gas data from libdivecomputer: o2 = %d he = %d", o2, he);
 | 
									he = 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			he = 0;
 | 
								dive->cylinder[i].gasmix.o2.permille = o2;
 | 
				
			||||||
 | 
								dive->cylinder[i].gasmix.he.permille = he;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								dive->cylinder[i].gasmix.o2.permille = 0;
 | 
				
			||||||
 | 
								dive->cylinder[i].gasmix.he.permille = 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		dive->cylinder[i].gasmix.o2.permille = o2;
 | 
					 | 
				
			||||||
		dive->cylinder[i].gasmix.he.permille = he;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN)
 | 
					#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN)
 | 
				
			||||||
		if (i < ntanks) {
 | 
							if (i < ntanks) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue