Skip to content
Snippets Groups Projects
Commit bcf9c653 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Adding the possibility to import non-imagette data

parent 8b9c39d5
No related branches found
No related tags found
1 merge request!11decompression/compression for non-imagette data
......@@ -32,6 +32,7 @@
#include "cmp_guess.h"
#include "cmp_entity.h"
#include "rdcu_pkt_to_file.h"
#include "cmp_data_types.h"
#define BUFFER_LENGTH_DEF_FAKTOR 2
......@@ -189,7 +190,7 @@ int main(int argc, char **argv)
verbose_en = 1;
break;
case 'V': /* --version */
printf("%s version %s\n", PROGRAM_NAME, CMP_TOOL_VERSION);
printf("%s version %s\n", PROGRAM_NAME, VERSION);
exit(EXIT_SUCCESS);
break;
case DIFF_CFG_OPTION:
......@@ -272,9 +273,9 @@ int main(int argc, char **argv)
printf("#########################################################\n");
printf("### PLATO Compression/Decompression Tool Version %s ###\n",
CMP_TOOL_VERSION);
VERSION);
printf("#########################################################\n");
if (!strcmp(CMP_TOOL_VERSION, "0.07") || !strcmp(CMP_TOOL_VERSION, "0.08"))
if (!strcmp(VERSION, "0.07") || !strcmp(VERSION, "0.08"))
printf("Info: Note that the behaviour of the cmp_tool has changed. From now on, the compressed data will be preceded by a header by default. The old behaviour can be achieved with the --no_header option.\n\n");
if (!data_file_name) {
......@@ -628,7 +629,7 @@ static int add_cmp_ent_hdr(struct cmp_cfg *cfg, struct cmp_info *info,
cmp_bit_to_4byte(info->cmp_size));
ent = (struct cmp_entity *)cfg->icu_output_buf;
s = cmp_ent_build(ent, data_type, cmp_tool_gen_version_id(CMP_TOOL_VERSION),
s = cmp_ent_build(ent, data_type, cmp_tool_gen_version_id(VERSION),
start_time, cmp_ent_create_timestamp(NULL), model_id,
model_counter, info, cfg);
if (!s) {
......
......@@ -33,6 +33,8 @@
#include <stdint.h>
#include "compiler.h"
#define MODE_RAW_S_FX 100
#define MODE_MODEL_ZERO_S_FX 101
#define MODE_DIFF_ZERO_S_FX 102
......@@ -90,11 +92,25 @@ int lossy_rounding_32(uint32_t *data_buf, unsigned int samples, unsigned int
int de_lossy_rounding_32(uint32_t *data_buf, uint32_t samples_used, uint32_t
round_used);
/* @see PLATO-LESIA-PL-RP-0031 Issue: 1.9 (N-DPU->ICU data rate) */
struct __attribute__((packed)) S_FX {
void cmp_input_big_to_cpu_endiannessy(void *data, u_int32_t data_size_byte,
uint32_t cmp_mode);
/* @see for packed definition: PLATO-LESIA-PL-RP-0031 Issue: 1.9 (N-DPU->ICU data rate) */
#define N_DPU_ICU_MULTI_ENTRY_HDR_SIZE 12
struct n_dpu_icu_multi_entry_hdr {
uint64_t ncxx_timestamp:48;
uint16_t ncxx_configuration_id;
uint16_t ncxx_collection_id;
uint16_t ncxx_collection_length;
} __attribute__((packed));
compile_time_assert(sizeof(struct n_dpu_icu_multi_entry_hdr) == N_DPU_ICU_MULTI_ENTRY_HDR_SIZE, N_DPU_ICU_MULTI_ENTRY_HDR_SIZE_IS_NOT_CORRECT);
struct S_FX {
uint8_t EXPOSURE_FLAGS;
uint32_t FX;
};
} __attribute__((packed));
struct S_FX sub_S_FX(struct S_FX a, struct S_FX b);
struct S_FX add_S_FX(struct S_FX a, struct S_FX b);
......@@ -135,9 +151,9 @@ int lossy_rounding_S_FX_NCOB(struct S_FX_NCOB *data_buf, unsigned int samples,
unsigned int round);
int de_lossy_rounding_S_FX_NCOB(struct S_FX_NCOB *data_buf, unsigned int
samples_used, unsigned int round_used);
struct S_FX_NCOB cal_up_model_S_FX_NCOB(struct S_FX_NCOB data_buf, struct
S_FX_NCOB model_buf, unsigned int
model_value);
struct S_FX_NCOB cal_up_model_S_FX_NCOB(struct S_FX_NCOB data_buf,
struct S_FX_NCOB model_buf,
unsigned int model_value);
struct S_FX_EFX_NCOB_ECOB {
......
......@@ -31,14 +31,12 @@ void print_help(const char *program_name);
int read_cmp_cfg(const char *file_name, struct cmp_cfg *cfg, int verbose_en);
int read_cmp_info(const char *file_name, struct cmp_info *info, int verbose_en);
ssize_t read_file8(const char *file_name, uint8_t *buf, uint32_t n_word,
int verbose_en);
ssize_t read_file16(const char *file_name, uint16_t *buf, uint32_t samples,
int verbose_en);
ssize_t read_file32(const char *file_name, uint32_t *buf, uint32_t samples,
int verbose_en);
ssize_t read_file_data(const char *file_name, unsigned int cmp_mode, void *buf,
uint32_t buf_size, int verbose_en);
ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent,
uint32_t ent_size, int verbose_en);
ssize_t read_file32(const char *file_name, uint32_t *buf, uint32_t buf_size,
int verbose_en);
uint32_t cmp_tool_gen_version_id(const char *version);
......
......@@ -179,6 +179,7 @@ uint32_t get_max_spill(unsigned int golomb_par, unsigned int cmp_mode);
uint32_t cmp_get_good_spill(unsigned int golomb_par, unsigned int cmp_mode);
size_t size_of_a_sample(unsigned int cmp_mode);
int cmp_input_size_to_samples(unsigned int size, unsigned int cmp_mode);
unsigned int cmp_bit_to_4byte(unsigned int cmp_size_bit);
unsigned int cmp_cal_size_of_data(unsigned int samples, unsigned int cmp_mode);
......
......@@ -20,6 +20,7 @@
#include "../include/cmp_data_types.h"
#include "../include/cmp_support.h"
#include "../include/cmp_debug.h"
#include "../include/byteorder.h"
/**
......@@ -96,6 +97,15 @@ int de_lossy_rounding_16(uint16_t *data_buf, uint32_t samples_used, uint32_t
}
static void be_to_cpus_16(uint16_t *a, uint32_t samples)
{
size_t i;
for (i = 0; i < samples; ++i)
be16_to_cpus(&a[i]);
}
/**
* @brief rounding down the least significant digits of a uint32_t data buffer
*
......@@ -261,6 +271,15 @@ struct S_FX cal_up_model_S_FX(struct S_FX data_buf, struct S_FX model_buf,
}
void be_to_cpus_S_FX(struct S_FX *a, uint32_t samples)
{
size_t i;
for (i = 0; i < samples; ++i)
a[i].FX = be32_to_cpu(a[i].FX);
}
struct S_FX_EFX sub_S_FX_EFX(struct S_FX_EFX a, struct S_FX_EFX b)
{
struct S_FX_EFX result;
......@@ -371,6 +390,17 @@ struct S_FX_EFX cal_up_model_S_FX_EFX(struct S_FX_EFX data_buf, struct S_FX_EFX
}
void be_to_cpus_S_FX_EFX(struct S_FX_EFX *a, uint32_t samples)
{
size_t i;
for (i = 0; i < samples; ++i) {
a[i].FX = be32_to_cpu(a[i].FX);
a[i].EFX = be32_to_cpu(a[i].EFX);
}
}
struct S_FX_NCOB sub_S_FX_NCOB(struct S_FX_NCOB a, struct S_FX_NCOB b)
{
struct S_FX_NCOB result;
......@@ -490,6 +520,18 @@ struct S_FX_NCOB cal_up_model_S_FX_NCOB(struct S_FX_NCOB data_buf, struct S_FX_N
}
void be_to_cpus_S_FX_NCOB(struct S_FX_NCOB *a, uint32_t samples)
{
size_t i;
for (i = 0; i < samples; ++i) {
a[i].FX = be32_to_cpu(a[i].FX);
a[i].NCOB_X = be32_to_cpu(a[i].NCOB_X);
a[i].NCOB_Y = be32_to_cpu(a[i].NCOB_Y);
}
}
struct S_FX_EFX_NCOB_ECOB sub_S_FX_EFX_NCOB_ECOB(struct S_FX_EFX_NCOB_ECOB a,
struct S_FX_EFX_NCOB_ECOB b)
{
......@@ -638,3 +680,107 @@ struct S_FX_EFX_NCOB_ECOB cal_up_model_S_FX_EFX_NCOB_ECOB
return result;
}
void be_to_cpus_S_FX_EFX_NCOB_ECOB(struct S_FX_EFX_NCOB_ECOB *a, uint32_t samples)
{
size_t i;
for (i = 0; i < samples; ++i) {
a[i].FX = be32_to_cpu(a[i].FX);
a[i].NCOB_X = be32_to_cpu(a[i].NCOB_X);
a[i].NCOB_Y = be32_to_cpu(a[i].NCOB_Y);
a[i].EFX = be32_to_cpu(a[i].EFX);
a[i].ECOB_X = be32_to_cpu(a[i].ECOB_X);
a[i].ECOB_Y = be32_to_cpu(a[i].ECOB_Y);
}
}
/**
* @brief swap the endianness of science products form big endian to the cpu
* endianness in place
*
* @param data pointer to a data sample
* @param cmp_mode compression mode
*/
void cmp_input_big_to_cpu_endiannessy(void *data, u_int32_t data_size_byte,
uint32_t cmp_mode)
{
int samples = cmp_input_size_to_samples(data_size_byte, cmp_mode);
if (!data)
return;
if (samples < 0) {
debug_print("Error: Can not convert data size in samples.\n");
return;
}
if (!rdcu_supported_mode_is_used(cmp_mode))
data = (uint8_t *)data + N_DPU_ICU_MULTI_ENTRY_HDR_SIZE;
switch (cmp_mode) {
case MODE_RAW:
case MODE_MODEL_ZERO:
case MODE_MODEL_MULTI:
case MODE_DIFF_ZERO:
case MODE_DIFF_MULTI:
be_to_cpus_16(data, samples);
break;
case MODE_RAW_S_FX:
case MODE_MODEL_ZERO_S_FX:
case MODE_MODEL_MULTI_S_FX:
case MODE_DIFF_ZERO_S_FX:
case MODE_DIFF_MULTI_S_FX:
be_to_cpus_S_FX(data, samples);
break;
case MODE_MODEL_ZERO_S_FX_EFX:
case MODE_MODEL_MULTI_S_FX_EFX:
case MODE_DIFF_ZERO_S_FX_EFX:
case MODE_DIFF_MULTI_S_FX_EFX:
be_to_cpus_S_FX_EFX(data, samples);
break;
case MODE_MODEL_ZERO_S_FX_EFX_NCOB_ECOB:
case MODE_MODEL_MULTI_S_FX_EFX_NCOB_ECOB:
case MODE_DIFF_ZERO_S_FX_EFX_NCOB_ECOB:
case MODE_DIFF_MULTI_S_FX_EFX_NCOB_ECOB:
be_to_cpus_S_FX_EFX_NCOB_ECOB(data, samples);
break;
case MODE_MODEL_ZERO_F_FX:
case MODE_MODEL_MULTI_F_FX:
case MODE_DIFF_ZERO_F_FX:
case MODE_DIFF_MULTI_F_FX:
/* be_to_cpus_F_FX(data, samples); */
/* break; */
case MODE_MODEL_ZERO_F_FX_EFX:
case MODE_MODEL_MULTI_F_FX_EFX:
case MODE_DIFF_ZERO_F_FX_EFX:
case MODE_DIFF_MULTI_F_FX_EFX:
/* be_to_cpus_F_FX_EFX(data, samples); */
/* break; */
case MODE_MODEL_ZERO_F_FX_NCOB:
case MODE_MODEL_MULTI_F_FX_NCOB:
case MODE_DIFF_ZERO_F_FX_NCOB:
case MODE_DIFF_MULTI_F_FX_NCOB:
/* be_to_cpus_F_FX_NCOB(data, samples); */
/* break; */
case MODE_MODEL_ZERO_F_FX_EFX_NCOB_ECOB:
case MODE_MODEL_MULTI_F_FX_EFX_NCOB_ECOB:
case MODE_DIFF_ZERO_F_FX_EFX_NCOB_ECOB:
case MODE_DIFF_MULTI_F_FX_EFX_NCOB_ECOB:
/* be_to_cpus_F_FX_EFX_NCOB_ECOB(data, samples); */
/* break; */
case MODE_RAW_32:
case MODE_MODEL_ZERO_32:
case MODE_MODEL_MULTI_32:
case MODE_DIFF_ZERO_32:
case MODE_DIFF_MULTI_32:
/* be32_to_cpus(data); */
/* break; */
default:
debug_print("Error: Compression mode not supported.\n");
break;
}
}
......@@ -29,6 +29,7 @@
#include "cmp_support.h"
#include "rdcu_cmd.h"
#include "byteorder.h"
#include "cmp_data_types.h"
/**
......
......@@ -558,6 +558,36 @@ size_t size_of_a_sample(unsigned int cmp_mode)
}
/**
* @brief calculates the number of samples for a given data size for the
* different compression modes
*
* @param size size of the data me
* @param cmp_mode compression mode
*
* @returns the number samples for the given compression mode; negative on error
*/
int cmp_input_size_to_samples(unsigned int size, unsigned int cmp_mode)
{
unsigned int samples_size = size_of_a_sample(cmp_mode);
if (!samples_size)
return -1;
if (!rdcu_supported_mode_is_used(cmp_mode)) {
if (size < N_DPU_ICU_MULTI_ENTRY_HDR_SIZE)
return -1;
size -= N_DPU_ICU_MULTI_ENTRY_HDR_SIZE;
}
if (size % samples_size)
return -1;
return size/samples_size;
}
/**
* @brief calculate the need bytes to hold a bitstream
*
......@@ -579,12 +609,19 @@ unsigned int cmp_bit_to_4byte(unsigned int cmp_size_bit)
* @param samples number of data samples
* @param cmp_mode used compression mode
*
* @note for non RDCU modes the N_DPU ICU multi entry header size is added
*
* @returns the size in bytes to store the data sample
*/
unsigned int cmp_cal_size_of_data(unsigned int samples, unsigned int cmp_mode)
{
return samples * size_of_a_sample(cmp_mode);
unsigned int s = samples * size_of_a_sample(cmp_mode);
if (!rdcu_supported_mode_is_used(cmp_mode))
s += N_DPU_ICU_MULTI_ENTRY_HDR_SIZE;
return s;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment