CCSDS TM Transfer Frames (CCSDS 132.0-B-3)
0
fork

Configure Feed

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

Port monorepo to latest ocaml-wire (opam pin)

Migrate all consumers to the new wire API:
- wire.c library → wire.3d (Wire_c → Wire_3d)
- Wire.struct_/module_ → Wire.Everparse.struct_/module_
- Wire.Codec: record/|+/seal → Codec.v with Field.v and $
- Wire.bf_uint* → Wire.U8/U16/U16be/U32/U32be
- Wire.UInt32 → Wire.Private.UInt32
- Wire.cases → Wire.lookup, Wire.map now uses labeled args
- Wire.Codec.decode now returns result
- Add wire pin to root.opam.template

+66 -63
+7 -3
bench/bench_tm.ml
··· 38 38 match Tm.decode_header s with Ok h -> h | Error _ -> assert false) 39 39 test_headers_str 40 40 41 - let test_wire_headers = 42 - Array.map (fun b -> Tm.decode_packed_header b 0) test_headers 41 + let decode_exn b off = 42 + match Tm.decode_packed_header b off with 43 + | Ok v -> v 44 + | Error e -> Fmt.failwith "decode: %a" Wire.pp_parse_error e 45 + 46 + let test_wire_headers = Array.map (fun b -> decode_exn b 0) test_headers 43 47 44 48 (** {1 Original Tm (string-based)} *) 45 49 ··· 82 86 83 87 let wire_roundtrip () = 84 88 for i = 0 to Array.length test_headers - 1 do 85 - let t = Tm.decode_packed_header test_headers.(i) 0 in 89 + let t = decode_exn test_headers.(i) 0 in 86 90 let buf = Bytes.create 6 in 87 91 Tm.encode_packed_header t buf 0; 88 92 let _ = buf in
+15 -13
c/TmHeader.3d
··· 1 - /*++ CCSDS TM Transfer Frame Primary Header (132.0-B-3) --*/ 1 + extern typedef struct _WireCtx WireCtx 2 + 3 + extern unit WireSetU16BE(mutable WireCtx *ctx, UINT32 idx, UINT16BE v) 2 4 3 5 entrypoint 4 - typedef struct _TmHeader 6 + typedef struct _TmHeader(mutable WireCtx *ctx) 5 7 { 6 - UINT16BE version : 2; 7 - UINT16BE scid : 10; 8 - UINT16BE vcid : 3; 9 - UINT16BE ocf_flag : 1; 10 - UINT16BE mcfc : 8; 11 - UINT16BE vcfc : 8; 12 - UINT16BE sec_hdr : 1; 13 - UINT16BE sync_flag : 1; 14 - UINT16BE pkt_order : 1; 15 - UINT16BE seg_len_id : 2; 16 - UINT16BE first_hdr_ptr : 11; 8 + UINT16BE version : 2 {:act WireSetU16BE(ctx, (UINT32) 0, version); }; 9 + UINT16BE scid : 10 {:act WireSetU16BE(ctx, (UINT32) 1, scid); }; 10 + UINT16BE vcid : 3 {:act WireSetU16BE(ctx, (UINT32) 2, vcid); }; 11 + UINT16BE ocf_flag : 1 {:act WireSetU16BE(ctx, (UINT32) 3, ocf_flag); }; 12 + UINT16BE mcfc : 8 {:act WireSetU16BE(ctx, (UINT32) 4, mcfc); }; 13 + UINT16BE vcfc : 8 {:act WireSetU16BE(ctx, (UINT32) 5, vcfc); }; 14 + UINT16BE sec_hdr : 1 {:act WireSetU16BE(ctx, (UINT32) 6, sec_hdr); }; 15 + UINT16BE sync_flag : 1 {:act WireSetU16BE(ctx, (UINT32) 7, sync_flag); }; 16 + UINT16BE pkt_order : 1 {:act WireSetU16BE(ctx, (UINT32) 8, pkt_order); }; 17 + UINT16BE seg_len_id : 2 {:act WireSetU16BE(ctx, (UINT32) 9, seg_len_id); }; 18 + UINT16BE first_hdr_ptr : 11 {:act WireSetU16BE(ctx, (UINT32) 10, first_hdr_ptr); }; 17 19 } TmHeader; 18 20 19 21
+1 -1
c/dune
··· 6 6 (executable 7 7 (name gen) 8 8 (modules gen) 9 - (libraries tm wire.c)) 9 + (libraries tm wire.3d)) 10 10 11 11 (rule 12 12 (mode promote)
+1 -6
c/gen.ml
··· 1 - let () = 2 - Wire_c.main ~package:"tm" 3 - [ 4 - Wire_c.schema ~name:"TmHeader" ~module_:Tm.module_ 5 - ~wire_size:(Wire.Codec.wire_size Tm.codec); 6 - ] 1 + let () = Wire_3d.main ~package:"tm" [ Wire.Everparse.schema Tm.codec ]
+1 -1
lib/dune
··· 1 1 (library 2 2 (name tm) 3 3 (public_name tm) 4 - (libraries clcw crc fmt wire)) 4 + (libraries clcw crc fmt wire wire.stubs))
+37 -36
lib/tm.ml
··· 329 329 330 330 (* Wire Codec *) 331 331 let codec = 332 - let open Wire.Codec in 333 - let bits n = Wire.bits ~width:n Wire.bf_uint16be in 332 + let bits n = Wire.bits ~width:n Wire.U16be in 334 333 let bool = Wire.bool (bits 1) in 335 - record "TmHeader" 336 - (fun 337 - version 338 - scid 339 - vcid 340 - ocf_flag 341 - mcfc 342 - vcfc 343 - sec_hdr 344 - sync_flag 345 - pkt_order 346 - seg_len_id 347 - first_hdr_ptr 348 - -> 334 + let f_version = Wire.Field.v "version" (bits 2) in 335 + let f_scid = Wire.Field.v "scid" (bits 10) in 336 + let f_vcid = Wire.Field.v "vcid" (bits 3) in 337 + let f_ocf_flag = Wire.Field.v "ocf_flag" bool in 338 + let f_mcfc = Wire.Field.v "mcfc" (bits 8) in 339 + let f_vcfc = Wire.Field.v "vcfc" (bits 8) in 340 + let f_sec_hdr = Wire.Field.v "sec_hdr" bool in 341 + let f_sync_flag = Wire.Field.v "sync_flag" bool in 342 + let f_pkt_order = Wire.Field.v "pkt_order" bool in 343 + let f_seg_len_id = Wire.Field.v "seg_len_id" (bits 2) in 344 + let f_first_hdr_ptr = Wire.Field.v "first_hdr_ptr" (bits 11) in 345 + Wire.Codec.v "TmHeader" 346 + (fun version scid vcid ocf_flag mcfc vcfc sec_hdr sync_flag pkt_order 347 + seg_len_id first_hdr_ptr -> 349 348 { 350 349 version; 351 350 scid; ··· 359 358 seg_len_id; 360 359 first_hdr_ptr; 361 360 }) 362 - |+ field "version" (bits 2) (fun t -> t.version) 363 - |+ field "scid" (bits 10) (fun t -> t.scid) 364 - |+ field "vcid" (bits 3) (fun t -> t.vcid) 365 - |+ field "ocf_flag" bool (fun t -> t.ocf_flag) 366 - |+ field "mcfc" (bits 8) (fun t -> t.mcfc) 367 - |+ field "vcfc" (bits 8) (fun t -> t.vcfc) 368 - |+ field "sec_hdr" bool (fun t -> t.sec_hdr) 369 - |+ field "sync_flag" bool (fun t -> t.sync_flag) 370 - |+ field "pkt_order" bool (fun t -> t.pkt_order) 371 - |+ field "seg_len_id" (bits 2) (fun t -> t.seg_len_id) 372 - |+ field "first_hdr_ptr" (bits 11) (fun t -> t.first_hdr_ptr) 373 - |> seal 361 + Wire.Codec. 362 + [ 363 + (f_version $ fun t -> t.version); 364 + (f_scid $ fun t -> t.scid); 365 + (f_vcid $ fun t -> t.vcid); 366 + (f_ocf_flag $ fun t -> t.ocf_flag); 367 + (f_mcfc $ fun t -> t.mcfc); 368 + (f_vcfc $ fun t -> t.vcfc); 369 + (f_sec_hdr $ fun t -> t.sec_hdr); 370 + (f_sync_flag $ fun t -> t.sync_flag); 371 + (f_pkt_order $ fun t -> t.pkt_order); 372 + (f_seg_len_id $ fun t -> t.seg_len_id); 373 + (f_first_hdr_ptr $ fun t -> t.first_hdr_ptr); 374 + ] 374 375 375 - let struct_ = Wire.Codec.to_struct codec 376 + let struct_ = Wire.Everparse.struct_of_codec codec 376 377 377 378 let module_ = 378 - Wire.module_ ~doc:"CCSDS TM Transfer Frame Primary Header (132.0-B-3)" 379 - "TmHeader" 380 - [ Wire.typedef ~entrypoint:true struct_ ] 379 + Wire.Everparse.Raw.module_ 380 + ~doc:"CCSDS TM Transfer Frame Primary Header (132.0-B-3)" 381 + [ Wire.Everparse.Raw.typedef ~entrypoint:true struct_ ] 381 382 382 383 (* Wire Parse/Encode *) 383 384 let decode_packed_header = Wire.Codec.decode codec ··· 427 428 let decode_bytes buf = 428 429 if Bytes.length buf < wire_size then 429 430 Error (Wire.Unexpected_eof { expected = wire_size; got = Bytes.length buf }) 430 - else Ok (Wire.Codec.decode codec buf 0) 431 + else Wire.Codec.decode codec buf 0 431 432 432 433 let decode_string s = 433 434 if String.length s < wire_size then 434 435 Error (Wire.Unexpected_eof { expected = wire_size; got = String.length s }) 435 - else Ok (Wire.Codec.decode codec (Bytes.of_string s) 0) 436 + else Wire.Codec.decode codec (Bytes.of_string s) 0 436 437 437 438 let encode_string t = 438 439 let buf = Bytes.create wire_size in ··· 445 446 buf 446 447 447 448 (* FFI Code Generation *) 448 - let c_stubs () = Wire.to_c_stubs [ struct_ ] 449 - let ml_stubs () = Wire.to_ml_stubs [ struct_ ] 449 + let c_stubs () = Wire_stubs.to_c_stubs [ struct_ ] 450 + let ml_stubs () = Wire_stubs.to_ml_stubs [ struct_ ]
+4 -3
lib/tm.mli
··· 282 282 val codec : packed_header Wire.Codec.t 283 283 (** [codec] is the wire codec for [packed_header]. *) 284 284 285 - val struct_ : Wire.struct_ 285 + val struct_ : Wire.Everparse.struct_ 286 286 (** Wire struct descriptor. *) 287 287 288 - val module_ : Wire.module_ 288 + val module_ : Wire.Everparse.module_ 289 289 (** Wire module descriptor. *) 290 290 291 291 (** {1 Wire Parse/Encode} *) ··· 293 293 val wire_size : int 294 294 (** Wire size of a packed header in bytes. *) 295 295 296 - val decode_packed_header : bytes -> int -> packed_header 296 + val decode_packed_header : 297 + bytes -> int -> (packed_header, Wire.parse_error) result 297 298 (** [decode_packed_header buf off] decodes a packed header from [buf] at offset 298 299 [off]. *) 299 300