cip.h 4.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
// Copyright © 2011 Moritz Hanke

// Based on Lossless Data Compression. Blue Book. Issue 1. May 1997.
// CCSDS 121.0-B-1
// 
// http://public.ccsds.org/publications/bluebooks.aspx
// http://public.ccsds.org/publications/archive/121x0b1c2.pdf

// Compression Identification Packet (optinal)
// The CIP is used to configure the decompressor in case no configuration
// data is available.
// It is comprised of the cip Primary Header (as described in "CCSDS Space
// Packet Protocol Blue Book") and the Packet Data Field.

enum cip_packet_type {

   TELEMETRY,   // reporting
   TELECOMMAND, // requesting (makes no sense for compression)
};

enum cip_sequence_flag {

   CONTINUE    = 0,
   FIRST       = 1,
   LAST        = 2,
   UNSEGMENTED = 3,
};

enum cip_compression_technique {

   NO       = 0, // no compression is used
   LOSSLESS = 1, // lossless compression is used
};

enum cip_predictor_type {

   BYPASS_P       = 0, // bypass predictor
   UNIT_DELAY_P   = 1, // unit delay predictor
   APP_SPECIFIC_P = 7, // application-specific predictor
};

enum cip_mapper_type {

   STANDARD_M     = 0, // standard prediction error mapper as described in the reference
   APP_SPECIFIC_M = 3, // application-specific mapper
};

enum cip_data_sense {

   TWOS_COMPLEMENT = 0, // two's complement
   POSITIVE        = 1, // positive (mandatory if preprocessor is bypassed)
};

enum entropy_coder_option {

   OPTION_S = 1, // for resolution      n <= 8
   OPTION_M = 2, // for resolution  8 < n <= 16
   OPTION_L = 3, // for resolution 16 < n <= 32
};

struct cip_header {

   //----------------------------
   // Packet Primary Header data
   //----------------------------

   char packet_version_number; // Packet Version Number

   // Packet Identification
   enum cip_packet_type type; // Packet Type
   char secondary_header_available; // Sequence Header Flag
   unsigned apid; // Application Process Identifier

   // Packet Sequence Control
   enum cip_sequence_flag sequence_flag; // Sequence Flags
   unsigned sequence_count; // Packet Sequence Count
                            // in case of a TELECOMMAND type cip
                            // data package this contains the
                            // Packet Name

   unsigned data_length; // length of the Packet Data Field - 1 in byte
};

struct cip_preprocessor_configuration {

   char preprocessor_present; // Preprocessor Status (0 - absent, 1 - present)

   enum cip_predictor_type predictor_type; // Predictor type (undefined if preprocessor is absent)

   enum cip_mapper_type mapper_type; // Mapper type (undefined if preprocessor is absent)

   char block_size; // Block size (8, 16 or application specific)

   enum cip_data_sense data_sense;

   char resolution; // Input data sample resolution (1-32)
};

struct cip_entropy_coder_configuration {

   enum entropy_coder_option option; // Entropy Coder option

   unsigned num_cds_per_packet; // Number of coded data sets per packet
};
   
struct cip_source_data_field {

   unsigned grouping_data_length; // Grouping Data Length

   enum cip_compression_technique compression_technique; // Compression Technique Identification

   unsigned reference_sample_interval; // Reference Sample Interval
                                       //  - in case a preprocessor is
                                       //    used that requires a
                                       //    reference sample
                                       //  - in case of the zero-block
                                       //    option it contains the
                                       //    interval of input data sample
                                       //    blocks

   struct cip_preprocessor_configuration preprocessor_config; // Preprocessor Configuration

   struct cip_entropy_coder_configuration entropy_coder_config; // Entropy Coder Configuration
};

struct cip {

   struct cip_header header; // Information from the Primary Header
   struct cip_source_data_field sdf; // Information on the data
};

void * decode_cip(void * buffer, struct cip * cip);
      // data: buffer starting with a cip
      // cip:  in case cip is not NULL the configuration information
      //       contained in the cip is written to it
      // returns a pointer to the compressed data without the cip
      // returns NULL in case an error occured while decoding