summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-06-17 00:02:05 -0700
committerKeith Packard <keithp@keithp.com>2016-06-17 01:03:40 -0700
commit7175774c4f60ed3efd54417f2035b50ea0108c7b (patch)
tree4b4233eb3fad7a5c62e5fee90d55243899f8c38e
parent8df6afe843e184e98e5d965cee3af562dfa30a3b (diff)
altoslib: Improve AltosState save/restore debugging
When save/restore generate different values, write out the two versions to one.json and two.json for easy comparison. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altoslib/AltosState.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java
index 26cedce9..93586e8c 100644
--- a/altoslib/AltosState.java
+++ b/altoslib/AltosState.java
@@ -315,7 +315,7 @@ public class AltosState implements Cloneable, AltosJsonable {
computed.finish_update();
}
- AltosCValue() {
+ public AltosCValue() {
measured = new AltosIValue();
computed = new AltosIValue();
}
@@ -1638,16 +1638,27 @@ public class AltosState implements Cloneable, AltosJsonable {
AltosState s = new AltosState();
s.copy(this);
+ /* Code to test state save/restore. Enable only for that purpose
+ */
if (false) {
- AltosJson json = json();
+ AltosJson json = new AltosJson(this);
String onetrip = json.toPrettyString();
AltosJson back = AltosJson.fromString(onetrip);
- AltosState tripstate = AltosState.fromJson(back);
- AltosJson tripjson = tripstate.json();
+ AltosState tripstate = (AltosState) back.make(this.getClass());
+ AltosJson tripjson = new AltosJson(tripstate);
String twotrip = tripjson.toPrettyString();
if (!onetrip.equals(twotrip)) {
- System.out.printf("one:\n%s\ntwo:\n%s\n", onetrip, twotrip);
+ try {
+ FileWriter one_file = new FileWriter("one.json", true);
+ one_file.write(onetrip);
+ one_file.flush();
+ FileWriter two_file = new FileWriter("two.json", true);
+ two_file.write(twotrip);
+ two_file.flush();
+ } catch (Exception e) {
+ }
+ System.out.printf("json error\n");
System.exit(1);
}
}