Reed-Solomon error correction over GF(2^8)
0
fork

Configure Feed

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

ocaml-reed-solomon: enable MDX on lib/{gf256,reed_solomon}.mli

Run mdx on lib/{gf256,reed_solomon}.mli so the {[ ... ]} odoc blocks
now type-check. Two issues:

- gf256.mli wrapped the CCSDS field instantiation in `let module F =
... in`. Moved it to a top-level `module F = Reed_solomon.Gf256.Make
(...)` so the example reads the way a user would write it in their
own file.

- reed_solomon.mli was a single chained `let ... in` expression with
unwrapped statements (`Bytes.blit ...;`) that does not parse at the
top level. Restructured as a sequence of top-level `let` bindings,
qualified `ccsds`/`pp_error` with `Reed_solomon.`, and put the
decode match under `let () = ...` so the assert (recovered = padded)
documents the expected outcome.

+23 -14
+4
lib/dune
··· 2 2 (name reed_solomon) 3 3 (public_name reed-solomon) 4 4 (libraries fmt)) 5 + 6 + (mdx 7 + (files reed_solomon.mli gf256.mli) 8 + (libraries reed-solomon fmt))
+6 -5
lib/gf256.mli
··· 8 8 9 9 {[ 10 10 (* CCSDS field: polynomial 0x187, primitive element 11 *) 11 - let module F = Gf256.Make (struct 11 + module F = Reed_solomon.Gf256.Make (struct 12 12 let primitive_poly = 0x187 13 13 let primitive_element = 11 14 - end) in 15 - let product = F.mul 0xA3 0x7B in 16 - let inverse = F.inv 0xA3 in 17 - assert (F.mul product inverse = 0x7B) 14 + end) 15 + 16 + let product = F.mul 0xA3 0x7B 17 + let inverse = F.inv 0xA3 18 + let () = assert (F.mul product inverse = 0x7B) 18 19 ]} 19 20 20 21 {2 References}
+13 -9
lib/reed_solomon.mli
··· 9 9 {2 Usage} 10 10 11 11 {[ 12 - let data = Bytes.of_string "Hello, Reed-Solomon!" in 12 + let data = Bytes.of_string "Hello, Reed-Solomon!" 13 + 13 14 (* Pad to 223 bytes for CCSDS RS(255,223) *) 14 - let padded = Bytes.make 223 '\x00' in 15 - Bytes.blit data 0 padded 0 (Bytes.length data); 16 - let codeword = Reed_solomon.encode_systematic ccsds padded in 15 + let padded = Bytes.make 223 '\x00' 16 + let () = Bytes.blit data 0 padded 0 (Bytes.length data) 17 + let codeword = Reed_solomon.encode_systematic Reed_solomon.ccsds padded 18 + 17 19 (* Inject up to 16 symbol errors... *) 18 - Bytes.set codeword 0 '\xff'; 19 - Bytes.set codeword 42 '\xab'; 20 - match Reed_solomon.decode ccsds codeword with 21 - | Ok recovered -> assert (recovered = padded) 22 - | Error e -> Fmt.epr "decode failed: %a\n" Reed_solomon.pp_error e 20 + let () = Bytes.set codeword 0 '\xff' 21 + let () = Bytes.set codeword 42 '\xab' 22 + 23 + let () = 24 + match Reed_solomon.decode Reed_solomon.ccsds codeword with 25 + | Ok recovered -> assert (recovered = padded) 26 + | Error e -> Fmt.epr "decode failed: %a@." Reed_solomon.pp_error e 23 27 ]} 24 28 25 29 {2 References}