diff options
| author | Bdale Garbee <bdale@gag.com> | 2017-12-11 21:39:38 -0700 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2017-12-11 21:39:38 -0700 | 
| commit | 8e0b575ad1dfd5a49136d3fe945d27f6afda1178 (patch) | |
| tree | 74657870764e6a3792bdd7e90acd725353c20904 /altoslib/AltosEepromRecord.java | |
| parent | 132b92a95bdebabf573a680301bfb1e93eaa6721 (diff) | |
| parent | fe38c22595b050435dbacd35f1baae064fb7de75 (diff) | |
Merge branch 'branch-1.8' into debian
Diffstat (limited to 'altoslib/AltosEepromRecord.java')
| -rw-r--r-- | altoslib/AltosEepromRecord.java | 33 | 
1 files changed, 19 insertions, 14 deletions
diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index 094584fe..43e8ea4d 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -50,8 +50,22 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>  		return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16) | (data8(i+3) << 24);  	} +	public boolean empty(int s) { +		for (int i = 0; i < length; i++) +			if (eeprom.data8(s + i) != 0xff) +				return false; +		return true; +	} +  	public boolean valid(int s) { -		return AltosConvert.checksum(eeprom.data, s, length) == 0; +		int	ck = AltosConvert.checksum(eeprom.data, s, length); + +		if (ck != 0) { +			++eeprom.errors; +			System.out.printf("invalid checksum 0x%x at 0x%x\n", ck, s); +			return false; +		} +		return true;  	}  	public boolean valid() { @@ -83,18 +97,16 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>  	/* AltosDataProvider */  	public void provide_data(AltosDataListener listener, AltosCalData cal_data) { -		cal_data.set_tick(tick()); +		listener.set_tick(tick());  		if (cmd() == AltosLib.AO_LOG_FLIGHT)  			cal_data.set_boost_tick();  		listener.set_time(cal_data.time());  		/* Flush any pending GPS changes */  		if (!AltosLib.is_gps_cmd(cmd())) { -			AltosGPS gps = cal_data.temp_gps(); -			if (gps != null) { +			AltosGPS gps = listener.temp_gps(); +			if (gps != null)  				listener.set_gps(gps); -				cal_data.reset_temp_gps(); -			}  		}  	} @@ -102,25 +114,18 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord>  		int	s = start + length;  		while (s + length <= eeprom.data.size()) { -			if (valid(s)) +			if (!empty(s) && valid(s))  				return s;  			s += length;  		}  		return -1;  	} -	public boolean hasNext() { -		return next_start() >= 0; -	} -  	public abstract AltosEepromRecord next();  	public AltosEepromRecord(AltosEeprom eeprom, int start, int length) {  		this.eeprom = eeprom;  		this.start = start;  		this.length = length; - -		while (start + length < eeprom.data.size() && !valid()) -			start += length;  	}  }  | 
