Coverage Report

Created: 2025-06-15 00:57

/src/cmp_tool/lib/common/cmp_data_types.h
Line
Count
Source
1
/**
2
 * @file   cmp_data_types.h
3
 * @author Dominik Loidolt (dominik.loidolt@univie.ac.at)
4
 * @date   2020
5
 * @brief definition of the different compression data types
6
 *
7
 * @copyright GPLv2
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms and conditions of the GNU General Public License,
10
 * version 2, as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope it will be useful, but WITHOUT
13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
 * more details.
16
 *
17
 * @see for N-DPU packed definition: PLATO-LESIA-PL-RP-0031 Issue: 2.9 (N-DPU->ICU data rate)
18
 * @see for calculation of the max used bits: PLATO-LESIA-PDC-TN-0054 Issue: 1.7
19
 *
20
 * Three data rates (for N-DPU):
21
 * fast cadence (nominally 25s)
22
 * short cadence (nominally 50s)
23
 * long cadence (nominally 600s)
24
 *
25
 * The science products are identified as this:
26
 * exp_flags = selected exposure flags
27
 * fx = normal light flux
28
 * ncob = normal center of brightness
29
 * efx = extended light flux
30
 * ecob = extended center of brightness
31
 * The prefixes f, s and l stand for fast, short and long cadence
32
 */
33
34
#ifndef CMP_DATA_TYPE_H
35
#define CMP_DATA_TYPE_H
36
37
#include <stddef.h>
38
#include <stdint.h>
39
40
#include "compiler.h"
41
#include "../common/cmp_support.h"
42
43
44
/* subservice types for service 212 */
45
7.72k
#define SST_NCxx_S_SCIENCE_IMAGETTE   3 /* N-Camera imagette data */
46
61.7k
#define SST_NCxx_S_SCIENCE_SAT_IMAGETTE   4 /* Extended imagettes for saturated star extra pixels */
47
7.60k
#define SST_NCxx_S_SCIENCE_OFFSET   5 /* Offset values Mean of the pixels of offset windows */
48
7.92k
#define SST_NCxx_S_SCIENCE_BACKGROUND   6 /* Background values Mean of the pixels of background windows */
49
15.8k
#define SST_NCxx_S_SCIENCE_SMEARING   7 /* Smearing array values */
50
/* subservice Type 8 is not defined */
51
120k
#define SST_NCxx_S_SCIENCE_S_FX     9 /* Short cadence FX data using normal masks */
52
46.9k
#define SST_NCxx_S_SCIENCE_S_FX_EFX   10 /* Short cadence FX data using normal and extended masks */
53
58.0k
#define SST_NCxx_S_SCIENCE_S_FX_NCOB    11 /* Short cadence FX and CoB using normal masks */
54
59.5k
#define SST_NCxx_S_SCIENCE_S_FX_EFX_NCOB_ECOB 12 /* Short cadence FX and CoB using normal and extended masks */
55
24.4k
#define SST_NCxx_S_SCIENCE_L_FX     13 /* Long cadence FX data using normal masks */
56
15.8k
#define SST_NCxx_S_SCIENCE_L_FX_EFX   14 /* Long cadence FX data using normal and extended masks */
57
16.8k
#define SST_NCxx_S_SCIENCE_L_FX_NCOB    15 /* Long cadence FX and CoB data using normal masks */
58
25.7k
#define SST_NCxx_S_SCIENCE_L_FX_EFX_NCOB_ECOB 16 /* Long cadence FX and CoB data using normal and extended masks */
59
330
#define SST_NCxx_S_SCIENCE_F_FX     17 /* Fast cadence FX data using normal masks */
60
97
#define SST_NCxx_S_SCIENCE_F_FX_EFX   18 /* Fast cadence FX and CoB using normal and extended masks */
61
95
#define SST_NCxx_S_SCIENCE_F_FX_NCOB    19 /* Fast cadence FX and CoB using normal masks */
62
155
#define SST_NCxx_S_SCIENCE_F_FX_EFX_NCOB_ECOB 20 /* Fast cadence FX and CoB using normal and extended masks */
63
64
/* subservice types for service 228 */
65
3.59k
#define SST_FCx_S_SCIENCE_IMAGETTE  1 /* Imagettes from F-camera. */
66
6.55k
#define SST_FCx_S_SCIENCE_OFFSET_VALUES 2 /* Offset values Mean of the pixels of offset windows */
67
32.5k
#define SST_FCx_S_BACKGROUND_VALUES 25 /* TBC: Background values. Mean of the pixels of background windows */
68
69
/* size of a collection (multi entry) header */
70
7.53M
#define COLLECTION_HDR_SIZE 12
71
72
enum col_packet_type {
73
  COL_WINDOW_PKT_TYPE = 0,
74
  COL_SCI_PKTS_TYPE = 1
75
};
76
77
78
/**
79
 * @brief source data header structure for collection packet
80
 * @note a collection package contains a collection header followed by multiple
81
 *  entries of the same science data
82
 * @see PLATO-LESIA-PL-RP-0031(N-DPU->ICU data rate)
83
 */
84
union collection_id {
85
  uint16_t collection_id;
86
  __extension__
87
  struct {
88
#ifdef __LITTLE_ENDIAN
89
    uint16_t sequence_num:7;
90
    uint16_t ccd_id:2;
91
    uint16_t subservice:6;
92
    uint16_t pkt_type:1;
93
#else
94
    uint16_t pkt_type:1;
95
    uint16_t subservice:6;
96
    uint16_t ccd_id:2;
97
    uint16_t sequence_num:7;
98
#endif
99
  } field __attribute__((packed));
100
} __attribute__((packed));
101
102
__extension__
103
struct collection_hdr {
104
  uint64_t timestamp:48;    /**< Time when the science observation was made */
105
  uint16_t configuration_id;  /**< ID of the configuration of the instrument */
106
  uint16_t collection_id;   /**< ID of a collection */
107
  uint16_t collection_length; /**< Expected number of data bytes in the target science packet */
108
  char  entry[];
109
} __attribute__((packed));
110
compile_time_assert(sizeof(struct collection_hdr) == COLLECTION_HDR_SIZE, N_DPU_ICU_COLLECTION_HDR_SIZE_IS_NOT_CORRECT);
111
compile_time_assert(sizeof(struct collection_hdr) % sizeof(uint32_t) == 0, N_DPU_ICU_COLLECTION_HDR_NOT_4_BYTE_ALLIED);
112
compile_time_assert(sizeof(((struct collection_hdr *)0)->collection_id) == sizeof(union collection_id), N_DPU_ICU_COLLECTION_COLLECTION_ID_DO_NOT_MATCH);
113
114
115
/**
116
 * @brief short cadence normal light flux entry definition
117
 */
118
119
struct s_fx {
120
  uint8_t exp_flags; /**< selected exposure flags (2 flags + 6 spare bits) */
121
  uint32_t fx;       /**< normal light flux */
122
} __attribute__((packed));
123
124
125
/**
126
 * @brief short cadence normal and extended light flux entry definition
127
 */
128
129
struct s_fx_efx {
130
  uint8_t exp_flags;
131
  uint32_t fx;
132
  uint32_t efx;
133
} __attribute__((packed));
134
135
136
/**
137
 * @brief short cadence normal light flux, normal center of brightness entry definition
138
 */
139
140
struct s_fx_ncob {
141
  uint8_t exp_flags;
142
  uint32_t fx;
143
  uint32_t ncob_x;
144
  uint32_t ncob_y;
145
} __attribute__((packed));
146
147
148
/**
149
 * @brief short cadence normal and extended flux, normal and extended center of brightness entry definition
150
 */
151
152
struct s_fx_efx_ncob_ecob {
153
  uint8_t exp_flags;
154
  uint32_t fx;
155
  uint32_t ncob_x;
156
  uint32_t ncob_y;
157
  uint32_t efx;
158
  uint32_t ecob_x;
159
  uint32_t ecob_y;
160
} __attribute__((packed));
161
162
163
/**
164
 * @brief fast cadence normal light flux entry definition
165
 */
166
167
struct f_fx {
168
  uint32_t fx;
169
} __attribute__((packed));
170
171
172
/**
173
 * @brief fast cadence normal and extended light flux entry definition
174
 */
175
176
struct f_fx_efx {
177
  uint32_t fx;
178
  uint32_t efx;
179
} __attribute__((packed));
180
181
182
/**
183
 * @brief fast cadence normal light flux, normal center of brightness entry definition
184
 */
185
186
struct f_fx_ncob {
187
  uint32_t fx;
188
  uint32_t ncob_x;
189
  uint32_t ncob_y;
190
} __attribute__((packed));
191
192
193
/**
194
 * @brief fast cadence normal and extended flux, normal and extended center of
195
 *  brightness entry definition
196
 */
197
198
struct f_fx_efx_ncob_ecob {
199
  uint32_t fx;
200
  uint32_t ncob_x;
201
  uint32_t ncob_y;
202
  uint32_t efx;
203
  uint32_t ecob_x;
204
  uint32_t ecob_y;
205
} __attribute__((packed));
206
207
208
/**
209
 * @brief long cadence normal light flux entry definition
210
 */
211
212
__extension__
213
struct l_fx {
214
  uint32_t exp_flags:24; /* selected exposure flags (24 flags) */
215
  uint32_t fx;
216
  uint32_t fx_variance;
217
} __attribute__((packed));
218
219
220
/**
221
 * @brief long cadence normal and extended light flux entry definition
222
 */
223
224
__extension__
225
struct l_fx_efx {
226
  uint32_t exp_flags:24; /* selected exposure flags (24 flags) */
227
  uint32_t fx;
228
  uint32_t efx;
229
  uint32_t fx_variance;
230
} __attribute__((packed));
231
232
233
/**
234
 * @brief long cadence normal light flux, normal center of brightness entry definition
235
 */
236
237
__extension__
238
struct l_fx_ncob {
239
  uint32_t exp_flags:24; /* selected exposure flags (24 flags) */
240
  uint32_t fx;
241
  uint32_t ncob_x;
242
  uint32_t ncob_y;
243
  uint32_t fx_variance;
244
  uint32_t cob_x_variance;
245
  uint32_t cob_y_variance;
246
} __attribute__((packed));
247
248
249
/**
250
 * @brief long cadence normal and extended flux, normal and extended center of
251
 *  brightness entry definition
252
 */
253
254
__extension__
255
struct l_fx_efx_ncob_ecob {
256
  uint32_t exp_flags:24; /* selected exposure flags (24 flags) */
257
  uint32_t fx;
258
  uint32_t ncob_x;
259
  uint32_t ncob_y;
260
  uint32_t efx;
261
  uint32_t ecob_x;
262
  uint32_t ecob_y;
263
  uint32_t fx_variance;
264
  uint32_t cob_x_variance;
265
  uint32_t cob_y_variance;
266
} __attribute__((packed));
267
268
269
/**
270
 * @brief normal and fast offset entry definition
271
 */
272
273
struct offset {
274
  uint32_t mean;
275
  uint32_t variance;
276
} __attribute__((packed));
277
278
279
/**
280
 * @brief normal and fast background entry definition
281
 */
282
283
struct background {
284
  uint32_t mean;
285
  uint32_t variance;
286
  uint16_t outlier_pixels;
287
} __attribute__((packed));
288
289
290
/**
291
 * @brief smearing entry definition
292
 */
293
294
struct smearing {
295
  uint32_t mean;
296
  uint16_t variance_mean;
297
  uint16_t outlier_pixels;
298
} __attribute__((packed));
299
300
301
/* collection header setter functions */
302
uint64_t cmp_col_get_timestamp(const struct collection_hdr *col);
303
uint16_t cmp_col_get_configuration_id(const struct collection_hdr *col);
304
305
uint16_t cmp_col_get_col_id(const struct collection_hdr *col);
306
uint8_t  cmp_col_get_pkt_type(const struct collection_hdr *col);
307
uint8_t  cmp_col_get_subservice(const struct collection_hdr *col);
308
uint8_t  cmp_col_get_ccd_id(const struct collection_hdr *col);
309
uint8_t  cmp_col_get_sequence_num(const struct collection_hdr *col);
310
311
uint16_t cmp_col_get_data_length(const struct collection_hdr *col);
312
uint32_t cmp_col_get_size(const struct collection_hdr *col);
313
314
315
/* collection header getter functions */
316
int cmp_col_set_timestamp(struct collection_hdr *col, uint64_t timestamp);
317
int cmp_col_set_configuration_id(struct collection_hdr *col, uint16_t configuration_id);
318
319
int cmp_col_set_col_id(struct collection_hdr *col, uint16_t collection_id);
320
int cmp_col_set_pkt_type(struct collection_hdr *col, uint8_t pkt_type);
321
int cmp_col_set_subservice(struct collection_hdr *col, uint8_t subservice);
322
int cmp_col_set_ccd_id(struct collection_hdr *col, uint8_t ccd_id);
323
int cmp_col_set_sequence_num(struct collection_hdr *col, uint8_t sequence_num);
324
325
int cmp_col_set_data_length(struct collection_hdr *col, uint16_t length);
326
327
enum cmp_data_type convert_subservice_to_cmp_data_type(uint8_t subservice);
328
uint8_t convert_cmp_data_type_to_subservice(enum cmp_data_type data_type);
329
330
size_t size_of_a_sample(enum cmp_data_type data_type);
331
332
333
/* endianness functions */
334
int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type data_type);
335
#define cpu_to_be_data_type(data, data_size_byte, data_type) be_to_cpu_data_type(data, data_size_byte, data_type)
336
337
int be_to_cpu_chunk(uint8_t *chunk, size_t chunk_size);
338
152
#define cpu_to_be_chunk(chunk, chunk_size) be_to_cpu_chunk(chunk, chunk_size)
339
340
int cmp_input_big_to_cpu_endianness(void *data, uint32_t data_size_byte,
341
            enum cmp_data_type data_type);
342
343
#endif /* CMP_DATA_TYPE_H */