From 600bad9154a7eb60b25b67cf3982b98333365f0d Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 31 Jul 2015 17:28:36 -0400 Subject: [PATCH] Initial implementation --- x_plane_data.ml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 x_plane_data.ml diff --git a/x_plane_data.ml b/x_plane_data.ml new file mode 100644 index 0000000..d3091e1 --- /dev/null +++ b/x_plane_data.ml @@ -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 -- 2.20.1