X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMag.java;h=351125bf407d6919d116e30d5e3d2a4e7159ce24;hb=HEAD;hp=e89ec0debf5742abff50960451dd0006b02b3493;hpb=1085ec5d57e0ed5d132f2bbdac1a0b6a32c0ab4a;p=fw%2Faltos diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index e89ec0de..6e11f3fd 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -16,39 +16,80 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_14; import java.util.concurrent.*; import java.io.*; public class AltosMag implements Cloneable { - public int along; - public int across; - public int through; + public int along = AltosLib.MISSING; + public int across = AltosLib.MISSING; + public int through = AltosLib.MISSING; - public static final double counts_per_gauss = 1090; + public static final int model_hmc5883 = 0; + public static final int model_mmc5983 = 1; - public static double convert_gauss(double counts) { - return counts / counts_per_gauss; + public int mag_model = AltosLib.MISSING; + + public static final double counts_per_gauss_hmc5883 = 1090; + public static final double counts_per_gauss_mmc5983 = 4096; + + public static double counts_per_gauss(int imu_type, int mag_model) { + switch(mag_model) { + case AltosLib.model_hmc5883: + return counts_per_gauss_hmc5883; + case AltosLib.model_mmc5983: + return counts_per_gauss_mmc5983; + } + switch (imu_type) { + case AltosIMU.imu_type_telemega_v1_v2: + case AltosIMU.imu_type_easymega_v1: + return counts_per_gauss_hmc5883; + case AltosIMU.imu_type_easytimer_v2: + return counts_per_gauss_mmc5983; + } + + return AltosIMU.counts_per_gauss(imu_type, mag_model); + } + + public static double convert_gauss(double counts, int imu_type, int mag_model) { + double cpg = counts_per_gauss(imu_type, mag_model); + + if (cpg == AltosLib.MISSING) + return AltosLib.MISSING; + + return counts / cpg; } public boolean parse_string(String line) { -// if (line.startsWith("Syntax error")) { -// along = across = through = 0; -// return true; -// } - if (!line.startsWith("X:")) - return false; + if (line.startsWith("X:")) { + + String[] items = line.split("\\s+"); - String[] items = line.split("\\s+"); + mag_model = model_hmc5883; - if (items.length >= 6) { - along = Integer.parseInt(items[1]); - across = Integer.parseInt(items[3]); - through = Integer.parseInt(items[5]); + if (items.length >= 6) { + across = Integer.parseInt(items[1]); + through = Integer.parseInt(items[3]); + along = Integer.parseInt(items[5]); + } + return true; + } + if (line.startsWith("MMC5983:")) { + String[] items = line.split("\\s+"); + + mag_model = model_mmc5983; + + if (items.length >= 4) { + along = Integer.parseInt(items[1]); + across = Integer.parseInt(items[2]); + through = Integer.parseInt(items[3]); + } + return true; } - return true; + + return false; } public AltosMag clone() { @@ -61,23 +102,20 @@ public class AltosMag implements Cloneable { } public AltosMag() { - along = AltosLib.MISSING; - across = AltosLib.MISSING; - through = AltosLib.MISSING; - } - - public AltosMag(int along, int across, int through) { - this.along = along; - this.across = across; - this.through = through; } - static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException { + static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException { try { AltosMag mag = new AltosMag(link); - - if (mag != null) - state.set_mag(mag); + AltosCalData cal_data = listener.cal_data(); + + if (mag != null) { + if (mag.mag_model != AltosLib.MISSING) + cal_data.set_mag_model(mag.mag_model); + listener.set_mag(cal_data.mag_along(mag.along), + cal_data.mag_across(mag.across), + cal_data.mag_through(mag.through)); + } } catch (TimeoutException te) { } }