Commit | Line | Data |
---|---|---|
600bad91 SK |
1 | module Datum = struct |
2 | type t = | |
3 | { index : int | |
4 | ; v1 : float | |
5 | ; v2 : float | |
6 | ; v3 : float | |
7 | ; v4 : float | |
8 | ; v5 : float | |
9 | ; v6 : float | |
10 | ; v7 : float | |
11 | ; v8 : float | |
12 | } | |
13 | ||
14 | let of_bitstring bits = | |
15 | bitmatch bits with | |
16 | | { index : 32 : littleendian | |
17 | ; v1 : 32 : littleendian | |
18 | ; v2 : 32 : littleendian | |
19 | ; v3 : 32 : littleendian | |
20 | ; v4 : 32 : littleendian | |
21 | ; v5 : 32 : littleendian | |
22 | ; v6 : 32 : littleendian | |
23 | ; v7 : 32 : littleendian | |
24 | ; v8 : 32 : littleendian | |
25 | } -> | |
26 | { index = Int32.to_int index | |
27 | ; v1 = Int32.float_of_bits v1 | |
28 | ; v2 = Int32.float_of_bits v2 | |
29 | ; v3 = Int32.float_of_bits v3 | |
30 | ; v4 = Int32.float_of_bits v4 | |
31 | ; v5 = Int32.float_of_bits v5 | |
32 | ; v6 = Int32.float_of_bits v6 | |
33 | ; v7 = Int32.float_of_bits v7 | |
34 | ; v8 = Int32.float_of_bits v8 | |
35 | } | |
36 | ||
37 | let show {index; v1; v2; v3; v4; v5; v6; v7; v8} = | |
38 | Printf.sprintf | |
39 | "| %3d | %11f | %11f | %11f | %11f | %11f | %11f | %11f | %11f |" | |
40 | index v1 v2 v3 v4 v5 v6 v7 v8 | |
41 | end | |
42 | ||
43 | let sample_packet_base64 = | |
44 | "REFUQUADAAAAbcpGQLt81EBfZNlATnUoNwDAecSow2RAnCv6QLrbQTcRAAAA3i8VQFL3ZT6dPfFCx4IFQwDAecQAwHnEAMB5xADAecQUAAAA1ZciQg6ik8JGBv9AdDxoPgAAgD9G/o3CAAAgQgAAlsI=" | |
45 | ||
46 | let rec split blocks = | |
47 | bitmatch blocks with | |
48 | | { block : 36 * 8 : bitstring | |
49 | ; blocks : -1 : bitstring | |
50 | } -> | |
51 | block :: (split blocks) | |
52 | | {_ : 0 : bitstring} -> | |
53 | [] | |
54 | ||
55 | let main () = | |
56 | let packet = B64.decode sample_packet_base64 in | |
57 | let packet = Bitstring.bitstring_of_string packet in | |
c80ac351 | 58 | bitmatch packet with |
600bad91 SK |
59 | | { "DATA" : 4 * 8 : string |
60 | ; "@" : 1 * 8 : string | |
61 | ; blocks : -1 : bitstring | |
62 | } -> | |
63 | let blocks = split blocks in | |
c80ac351 | 64 | List.iter (fun b -> print_endline (Datum.show (Datum.of_bitstring b))) blocks |
600bad91 SK |
65 | |
66 | let () = main () |