altosui: Add a few simple unit conversions
[fw/altos] / altosui / AltosConvert.java
index 6a9b699cfe158c025d275fe1bc99767a9eb24e97..db7039ec5294a5dc16b8e99248a6612360fb3a0a 100644 (file)
@@ -190,30 +190,24 @@ public class AltosConvert {
                return ignite / 32767 * 15.0;
        }
 
-       static double
-       radio_setting_to_frequency(int setting, int cal) {
+       static double radio_to_frequency(int setting, int cal, int channel) {
                double  f;
 
+               if (setting <= 0)
+                       setting = cal;
                f = 434.550 * setting / cal;
                /* Round to nearest 50KHz */
                f = Math.floor (20.0 * f + 0.5) / 20.0;
-               return f;
+               return f + channel * 0.100;
        }
 
-       static int
-       radio_frequency_to_setting(double frequency, int cal) {
+       static int radio_frequency_to_setting(double frequency, int cal) {
                double  set = frequency / 434.550 * cal;
 
                return (int) Math.floor (set + 0.5);
        }
 
-       static double
-       radio_channel_to_frequency(int channel) {
-               return 434.550 + channel * 0.100;
-       }
-
-       static int
-       radio_frequency_to_channel(double frequency) {
+       static int radio_frequency_to_channel(double frequency) {
                int     channel = (int) Math.floor ((frequency - 434.550) / 0.100 + 0.5);
 
                if (channel < 0)
@@ -222,4 +216,40 @@ public class AltosConvert {
                        channel = 9;
                return channel;
        }
+
+       static double radio_channel_to_frequency(int channel) {
+               return 434.550 + channel * 0.100;
+       }
+
+       static int[] ParseHex(String line) {
+               String[] tokens = line.split("\\s+");
+               int[] array = new int[tokens.length];
+
+               for (int i = 0; i < tokens.length; i++)
+                       try {
+                               array[i] = Integer.parseInt(tokens[i], 16);
+                       } catch (NumberFormatException ne) {
+                               return null;
+                       }
+               return array;
+       }
+
+       static double meters_to_feet(double meters) {
+               return meters * (100 / (2.54 * 12));
+       }
+
+       static double meters_to_mach(double meters) {
+               return meters / 343;            /* something close to mach at usual rocket sites */
+       }
+
+       static double meters_to_g(double meters) {
+               return meters / 9.80665;
+       }
+
+       static int checksum(int[] data, int start, int length) {
+               int     csum = 0x5a;
+               for (int i = 0; i < length; i++)
+                       csum += data[i + start];
+               return csum & 0xff;
+       }
 }