diff --git a/cmp_tool.c b/cmp_tool.c index 90aa1df4ab1211682691b5c121ad9907f2232c50..e3b27165e867488fe48393a8eed7e342ebc3f542 100755 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -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) { diff --git a/include/cmp_data_types.h b/include/cmp_data_types.h index 345c0ae185cb488cd877daaaf6236d0b332b5d8e..2ec635e03664543ea7c7958e0da4e1e6897550c4 100644 --- a/include/cmp_data_types.h +++ b/include/cmp_data_types.h @@ -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); @@ -110,7 +126,7 @@ struct S_FX_EFX { uint8_t EXPOSURE_FLAGS; uint32_t FX; uint32_t EFX; -}__attribute__((packed)); +} __attribute__((packed)); struct S_FX_EFX sub_S_FX_EFX(struct S_FX_EFX a, struct S_FX_EFX b); struct S_FX_EFX add_S_FX_EFX(struct S_FX_EFX a, struct S_FX_EFX b); @@ -127,7 +143,7 @@ struct S_FX_NCOB { uint32_t FX; uint32_t NCOB_X; uint32_t NCOB_Y; -}__attribute__((packed)); +} __attribute__((packed)); struct S_FX_NCOB sub_S_FX_NCOB(struct S_FX_NCOB a, struct S_FX_NCOB b); struct S_FX_NCOB add_S_FX_NCOB(struct S_FX_NCOB a, struct S_FX_NCOB 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 { @@ -148,7 +164,7 @@ struct S_FX_EFX_NCOB_ECOB { uint32_t EFX; uint32_t ECOB_X; uint32_t ECOB_Y; -}__attribute__((packed)); +} __attribute__((packed)); 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); @@ -162,20 +178,20 @@ int de_lossy_rounding_S_FX_EFX_NCOB_ECOB(struct S_FX_EFX_NCOB_ECOB *data_buf, struct F_FX { uint32_t FX; -}__attribute__((packed)); +} __attribute__((packed)); struct F_FX_EFX { uint32_t FX; uint32_t EFX; -}__attribute__((packed)); +} __attribute__((packed)); struct F_FX_NCOB { uint32_t FX; uint32_t NCOB_X; uint32_t NCOB_Y; -}__attribute__((packed)); +} __attribute__((packed)); struct F_FX_EFX_NCOB_ECOB { @@ -185,6 +201,6 @@ struct F_FX_EFX_NCOB_ECOB { uint32_t EFX; uint32_t ECOB_X; uint32_t ECOB_Y; -}__attribute__((packed)); +} __attribute__((packed)); #endif /* CMP_DATA_TYPE_H */ diff --git a/include/cmp_io.h b/include/cmp_io.h index 179d59f04d910b89d34f53ffbd0f85c321a5412b..39cfe5953c20a1e0cacc7feab83a641c5bd4bf74 100644 --- a/include/cmp_io.h +++ b/include/cmp_io.h @@ -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); + 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); diff --git a/include/cmp_support.h b/include/cmp_support.h index 0c1c90f6288c733d6c9db4c51f99b0b5e09d4c26..cfe4bbd56a3915d71751569a191c889b9ffc5b6b 100644 --- a/include/cmp_support.h +++ b/include/cmp_support.h @@ -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); diff --git a/lib/cmp_data_types.c b/lib/cmp_data_types.c index 1df363cb274aa698815432ef3e9ed51557c88d5b..cf8c08ce4e1f7ffeaf14d0c4f739508c25f8ef03 100644 --- a/lib/cmp_data_types.c +++ b/lib/cmp_data_types.c @@ -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; + } +} diff --git a/lib/cmp_io.c b/lib/cmp_io.c index 9dc9ba1f0c64d9e0cfc0d22ddca2db774945258b..7c00d567ae6c5ca121dddb93ffdb890bbc76fbcb 100644 --- a/lib/cmp_io.c +++ b/lib/cmp_io.c @@ -29,6 +29,7 @@ #include "cmp_support.h" #include "rdcu_cmd.h" #include "byteorder.h" +#include "cmp_data_types.h" /** diff --git a/lib/cmp_support.c b/lib/cmp_support.c index a9459718e1a8c79cc913e574e1072b268fff0f72..93db7b63de381d200e9e799b85475e7d8197ce1b 100644 --- a/lib/cmp_support.c +++ b/lib/cmp_support.c @@ -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; }