# ## Copyright 2002 Phil Karn, KA9Q ## Portions copyright (c) 1995-2008 University Corporation for Atmospheric Research ## All rights reserved # my $pkgdoc = <<'EOD'; #/**---------------------------------------------------------------------- # @file RSTools.pm # # Tools for generating and manipulating CCSCS Reed-Solomon parity frames. # # @author Phil Karn, Doug Hunt # @since 1/25/2008 # @cdaacTask no # @version $URL: svn://svn1.cosmic.ucar.edu/trunk/src/BJutils/RSTools.pm $ $Id: RSTools.pm 18928 2015-01-08 20:01:56Z vanhove $ # -----------------------------------------------------------------------*/ EOD # $Log: not supported by cvs2svn $ package RSTools; use strict; use warnings; # Use for debug, causes a re-compile each time, and sets -g for debugging #use Inline 'Info', 'Force', 'Noclean'; #use Inline 'C' => Config => INC => '-I/ops/tools/include', OPTIMIZE => '-g'; use Inline 'C' => Config => INC => "-I."; use Inline 'C' => <<'END_C'; /* * Copyright 2002 Phil Karn, KA9Q * May be used under the terms of the GNU General Public License (GPL) * Consolidated, added comments, made perl callable and added interleaving code--2008 Doug Hunt, UCAR */ #include #include #include /* Configure the RS codec with fixed parameters for CCSDS standard * (255,223) code over GF(256). Note: the conventional basis is still * used; the dual-basis mappings are performed in [en|de]code_rs_ccsds.c */ static inline int mod255(int x){ while (x >= 255) { x -= 255; x = (x >> 8) + (x & 255); } return x; } #define MODNN(x) mod255(x) #define NN 255 #define A0 (NN) #define NROOTS 32 #define N_MSG 223 #define N_INTERLEAVE 5 // Function pre-declarations void encode_rs_ccsds(unsigned char *data, unsigned char *parity); void encode_rs_8 (unsigned char *data, unsigned char *bb); /**---------------------------------------------------------------------- * @sub encode_interleaved * * Perform a standard CCSDS Reed-Solomon encoding of the input 1115 byte * frame. A description of this is found in the CCSCS Blue Book * 101.0-B-6 called 'Telemetry Channel Encoding', chapter 3. * This routine does only the sort of encoding used for COSMIC: * 255 byte blocks with 32 bytes of RS solomon check words, interleaved * 5-fold to make a total of 1115 byte frames and 160 byte RS info. * * So, from Telemetry Channel Encoding, J=8, E=16 and I=5. * * @parameter unsigned char *msg C pointer to 1115 bytes of info to be encoded * @ unsigned char *rs Output C pointer to 160 bytes of RS check info * @return nothing * ----------------------------------------------------------------------*/ void encode_interleaved(char *msg, char *rs) { unsigned char block[NN]; int i, j; for (i=0;i