CCSDS AOS (Advanced Orbiting Systems) Transfer Frame for satellite downlinks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

irmin: add Schema.kinded for content-based dispatch (IPLD kinded unions)

+54 -54
+11 -11
fuzz/fuzz_aos.ml
··· 7 7 8 8 (** {1 Decode crash safety} *) 9 9 10 - let test_decode_crash buf = 11 - ignore (Aos.decode buf) 10 + let test_decode_crash buf = ignore (Aos.decode buf) 12 11 13 12 (** {1 Roundtrip: encode then decode recovers the same frame} *) 14 13 ··· 32 31 match Aos.decode encoded with 33 32 | Error e -> fail (Fmt.str "decode failed: %a" Aos.pp_error e) 34 33 | Ok frame' -> 35 - check_eq ~pp:Fmt.int (Aos.scid_to_int frame.header.scid) 34 + check_eq ~pp:Fmt.int 35 + (Aos.scid_to_int frame.header.scid) 36 36 (Aos.scid_to_int frame'.header.scid); 37 37 check_eq ~pp:Fmt.(option int) frame.ocf frame'.ocf) 38 38 | _ -> () ··· 57 57 let encoded = Aos.encode ~with_fecf:true frame in 58 58 let len = String.length encoded in 59 59 if len > 2 then begin 60 - let byte_pos = (bit_pos mod (len - 2)) in 60 + let byte_pos = bit_pos mod (len - 2) in 61 61 let buf = Bytes.of_string encoded in 62 62 let old = Bytes.get_uint8 buf byte_pos in 63 63 Bytes.set_uint8 buf byte_pos (old lxor 1); ··· 67 67 | Ok _ -> 68 68 (* Allowed: if the flip is in FECF itself, the CRC may 69 69 accidentally match. Otherwise this is a real miss. *) 70 - if byte_pos < len - 2 then 71 - fail "FECF did not detect corruption" 70 + if byte_pos < len - 2 then fail "FECF did not detect corruption" 72 71 end 73 72 | _ -> () 74 73 ··· 85 84 86 85 let test_clcw_roundtrip scid_val vcid_val vcfc clcw_vcid report_value data = 87 86 match (Aos.scid scid_val, Aos.vcid vcid_val) with 88 - | Some scid, Some vcid -> 87 + | Some scid, Some vcid -> ( 89 88 let clcw_vcid = clcw_vcid mod 64 in 90 89 let report_value = report_value mod 256 in 91 90 let clcw = Clcw.v ~vcid:clcw_vcid ~report_value () in 92 91 let frame = Aos.with_clcw ~scid ~vcid ~vcfc ~clcw data in 93 92 let encoded = Aos.encode frame in 94 - (match Aos.decode encoded with 93 + match Aos.decode encoded with 95 94 | Error e -> fail (Fmt.str "decode failed: %a" Aos.pp_error e) 96 95 | Ok frame' -> ( 97 96 match Aos.clcw frame' with ··· 114 113 115 114 let test_wire_header_roundtrip buf = 116 115 let buf = 117 - if String.length buf < 6 then buf ^ String.make (6 - String.length buf) '\x00' 116 + if String.length buf < 6 then 117 + buf ^ String.make (6 - String.length buf) '\x00' 118 118 else String.sub buf 0 6 119 119 in 120 120 let bytes_buf = Bytes.of_string buf in 121 121 match Aos.decode_bytes bytes_buf with 122 122 | Error _ -> () 123 - | Ok hdr -> 123 + | Ok hdr -> ( 124 124 let encoded = Aos.encode_bytes hdr in 125 - (match Aos.decode_bytes encoded with 125 + match Aos.decode_bytes encoded with 126 126 | Error _ -> fail "re-decode of encoded header failed" 127 127 | Ok hdr' -> check_eq ~pp:pp_int hdr.version hdr'.version) 128 128
+43 -43
lib/aos.ml
··· 410 410 let min_size = 411 411 header_len + insert_zone_len 412 412 + (if expect_ocf then ocf_len else 0) 413 - + (if expect_fecf then fecf_len else 0) 413 + + if expect_fecf then fecf_len else 0 414 414 in 415 415 if frame_len < min_size then 416 416 Error (Truncated { need = min_size; have = frame_len }) 417 417 else 418 - match Wire.Codec.decode_with frame_codec env frame_buf 0 with 419 - | Error _ -> Error (Truncated { need = frame_len; have = buf_len }) 420 - | Ok pf -> ( 421 - if pf.pf_version > 1 then Error (Invalid_version pf.pf_version) 422 - else 423 - match 424 - of_packed_header 425 - { 426 - version = pf.pf_version; 427 - scid = pf.pf_scid; 428 - vcid = pf.pf_vcid; 429 - vcfc = pf.pf_vcfc; 430 - replay_flag = pf.pf_replay_flag; 431 - vc_count_flag = pf.pf_vc_count_flag; 432 - spare = pf.pf_spare; 433 - vc_count_cycle = pf.pf_vc_count_cycle; 434 - } 435 - with 436 - | Error `Invalid_scid -> Error (Invalid_scid pf.pf_scid) 437 - | Error `Invalid_vcid -> Error (Invalid_vcid pf.pf_vcid) 438 - | Ok header -> 439 - let insert_zone = 440 - if insert_zone_len > 0 then Some pf.pf_insert_zone else None 441 - in 442 - let frame = 418 + match Wire.Codec.decode_with frame_codec env frame_buf 0 with 419 + | Error _ -> Error (Truncated { need = frame_len; have = buf_len }) 420 + | Ok pf -> ( 421 + if pf.pf_version > 1 then Error (Invalid_version pf.pf_version) 422 + else 423 + match 424 + of_packed_header 443 425 { 444 - header; 445 - insert_zone; 446 - data = pf.pf_data; 447 - ocf = pf.pf_ocf; 448 - fecf = pf.pf_fecf; 426 + version = pf.pf_version; 427 + scid = pf.pf_scid; 428 + vcid = pf.pf_vcid; 429 + vcfc = pf.pf_vcfc; 430 + replay_flag = pf.pf_replay_flag; 431 + vc_count_flag = pf.pf_vc_count_flag; 432 + spare = pf.pf_spare; 433 + vc_count_cycle = pf.pf_vc_count_cycle; 449 434 } 450 - in 451 - if expect_fecf && check_fecf then 452 - match pf.pf_fecf with 453 - | Some actual -> 454 - let computed = 455 - compute_fecf (String.sub buf 0 (frame_len - 2)) 456 - in 457 - if computed <> actual then 458 - Error (Fecf_mismatch { expected = computed; actual }) 459 - else Ok frame 460 - | None -> Ok frame 461 - else Ok frame) 435 + with 436 + | Error `Invalid_scid -> Error (Invalid_scid pf.pf_scid) 437 + | Error `Invalid_vcid -> Error (Invalid_vcid pf.pf_vcid) 438 + | Ok header -> 439 + let insert_zone = 440 + if insert_zone_len > 0 then Some pf.pf_insert_zone else None 441 + in 442 + let frame = 443 + { 444 + header; 445 + insert_zone; 446 + data = pf.pf_data; 447 + ocf = pf.pf_ocf; 448 + fecf = pf.pf_fecf; 449 + } 450 + in 451 + if expect_fecf && check_fecf then 452 + match pf.pf_fecf with 453 + | Some actual -> 454 + let computed = 455 + compute_fecf (String.sub buf 0 (frame_len - 2)) 456 + in 457 + if computed <> actual then 458 + Error (Fecf_mismatch { expected = computed; actual }) 459 + else Ok frame 460 + | None -> Ok frame 461 + else Ok frame) 462 462 463 463 let encode_header buf off hdr = 464 464 let packed = to_packed_header hdr in