Initial implementation
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 31 Jul 2015 21:28:36 +0000 (17:28 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sun, 5 Jan 2020 05:44:35 +0000 (00:44 -0500)
x_plane_data.ml [new file with mode: 0644]

diff --git a/x_plane_data.ml b/x_plane_data.ml
new file mode 100644 (file)
index 0000000..d3091e1
--- /dev/null
@@ -0,0 +1,67 @@
+module Datum = struct
+  type t =
+    { index : int
+    ;    v1 : float
+    ;    v2 : float
+    ;    v3 : float
+    ;    v4 : float
+    ;    v5 : float
+    ;    v6 : float
+    ;    v7 : float
+    ;    v8 : float
+    }
+
+  let of_bitstring bits =
+    bitmatch bits with
+    | { index : 32 : littleendian
+      ;    v1 : 32 : littleendian
+      ;    v2 : 32 : littleendian
+      ;    v3 : 32 : littleendian
+      ;    v4 : 32 : littleendian
+      ;    v5 : 32 : littleendian
+      ;    v6 : 32 : littleendian
+      ;    v7 : 32 : littleendian
+      ;    v8 : 32 : littleendian
+      } ->
+        { index = Int32.to_int        index
+        ;    v1 = Int32.float_of_bits v1
+        ;    v2 = Int32.float_of_bits v2
+        ;    v3 = Int32.float_of_bits v3
+        ;    v4 = Int32.float_of_bits v4
+        ;    v5 = Int32.float_of_bits v5
+        ;    v6 = Int32.float_of_bits v6
+        ;    v7 = Int32.float_of_bits v7
+        ;    v8 = Int32.float_of_bits v8
+        }
+
+  let show {index; v1; v2; v3; v4; v5; v6; v7; v8} =
+    Printf.sprintf
+      "| %3d | %11f | %11f | %11f | %11f | %11f | %11f | %11f | %11f |"
+      index   v1   v2   v3   v4   v5   v6   v7   v8
+end
+
+let sample_packet_base64 =
+  "REFUQUADAAAAbcpGQLt81EBfZNlATnUoNwDAecSow2RAnCv6QLrbQTcRAAAA3i8VQFL3ZT6dPfFCx4IFQwDAecQAwHnEAMB5xADAecQUAAAA1ZciQg6ik8JGBv9AdDxoPgAAgD9G/o3CAAAgQgAAlsI="
+
+let rec split blocks =
+  bitmatch blocks with
+  | { block  : 36 * 8 : bitstring
+    ; blocks : -1     : bitstring
+    } ->
+      block :: (split blocks)
+  | {_ : 0 : bitstring} ->
+      []
+
+let main () =
+  let packet = B64.decode sample_packet_base64 in
+  let packet = Bitstring.bitstring_of_string packet in
+  ( bitmatch packet with
+  | { "DATA" : 4 * 8 : string
+    ; "@"    : 1 * 8 : string
+    ; blocks : -1    : bitstring
+    } ->
+      let blocks = split blocks in
+      List.iter (fun b -> print_endline (Datum.show (Datum.of_bitstring b))) blocks;
+  )
+
+let () = main ()
\ No newline at end of file
This page took 0.023146 seconds and 4 git commands to generate.