##// END OF EJS Templates
slight modification to the binAbove calcultion (reaction wheels filtering))
paul -
r288:3e4133f0e255 R3_plus draft
parent child
Show More
@@ -1,1524 +1,1524
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 19 ring_node kcoefficient_node_1;
20 20 ring_node kcoefficient_node_2;
21 21
22 22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 23 {
24 24 /** This function updates the LFR registers with the incoming common parameters.
25 25 *
26 26 * @param TC points to the TeleCommand packet that is being processed
27 27 *
28 28 *
29 29 */
30 30
31 31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 33 set_wfp_data_shaping( );
34 34 return LFR_SUCCESSFUL;
35 35 }
36 36
37 37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 38 {
39 39 /** This function updates the LFR registers with the incoming normal parameters.
40 40 *
41 41 * @param TC points to the TeleCommand packet that is being processed
42 42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 43 *
44 44 */
45 45
46 46 int result;
47 47 int flag;
48 48 rtems_status_code status;
49 49
50 50 flag = LFR_SUCCESSFUL;
51 51
52 52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 55 flag = LFR_DEFAULT;
56 56 }
57 57
58 58 // CHECK THE PARAMETERS SET CONSISTENCY
59 59 if (flag == LFR_SUCCESSFUL)
60 60 {
61 61 flag = check_normal_par_consistency( TC, queue_id );
62 62 }
63 63
64 64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_l( TC );
68 68 result = set_sy_lfr_n_swf_p( TC );
69 69 result = set_sy_lfr_n_bp_p0( TC );
70 70 result = set_sy_lfr_n_bp_p1( TC );
71 71 result = set_sy_lfr_n_asm_p( TC );
72 72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 73 }
74 74
75 75 return flag;
76 76 }
77 77
78 78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 79 {
80 80 /** This function updates the LFR registers with the incoming burst parameters.
81 81 *
82 82 * @param TC points to the TeleCommand packet that is being processed
83 83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 84 *
85 85 */
86 86
87 87 int flag;
88 88 rtems_status_code status;
89 89 unsigned char sy_lfr_b_bp_p0;
90 90 unsigned char sy_lfr_b_bp_p1;
91 91 float aux;
92 92
93 93 flag = LFR_SUCCESSFUL;
94 94
95 95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 97 flag = LFR_DEFAULT;
98 98 }
99 99
100 100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102 102
103 103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 104 if (flag == LFR_SUCCESSFUL)
105 105 {
106 106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 107 {
108 108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 113 if (flag == LFR_SUCCESSFUL)
114 114 {
115 115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 116 {
117 117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
118 118 flag = WRONG_APP_DATA;
119 119 }
120 120 }
121 121 //****************************************************************
122 122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 123 if (flag == LFR_SUCCESSFUL)
124 124 {
125 125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 128 if (aux > FLOAT_EQUAL_ZERO)
129 129 {
130 130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET THE PARAMETERS
136 136 if (flag == LFR_SUCCESSFUL)
137 137 {
138 138 flag = set_sy_lfr_b_bp_p0( TC );
139 139 flag = set_sy_lfr_b_bp_p1( TC );
140 140 }
141 141
142 142 return flag;
143 143 }
144 144
145 145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 146 {
147 147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 148 *
149 149 * @param TC points to the TeleCommand packet that is being processed
150 150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 151 *
152 152 */
153 153
154 154 int flag;
155 155 rtems_status_code status;
156 156 unsigned char sy_lfr_s1_bp_p0;
157 157 unsigned char sy_lfr_s1_bp_p1;
158 158 float aux;
159 159
160 160 flag = LFR_SUCCESSFUL;
161 161
162 162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 164 flag = LFR_DEFAULT;
165 165 }
166 166
167 167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169 169
170 170 // sy_lfr_s1_bp_p0
171 171 if (flag == LFR_SUCCESSFUL)
172 172 {
173 173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 174 {
175 175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
176 176 flag = WRONG_APP_DATA;
177 177 }
178 178 }
179 179 // sy_lfr_s1_bp_p1
180 180 if (flag == LFR_SUCCESSFUL)
181 181 {
182 182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 183 {
184 184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
185 185 flag = WRONG_APP_DATA;
186 186 }
187 187 }
188 188 //******************************************************************
189 189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 190 if (flag == LFR_SUCCESSFUL)
191 191 {
192 192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
193 193 if (aux > FLOAT_EQUAL_ZERO)
194 194 {
195 195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 196 flag = LFR_DEFAULT;
197 197 }
198 198 }
199 199
200 200 // SET THE PARAMETERS
201 201 if (flag == LFR_SUCCESSFUL)
202 202 {
203 203 flag = set_sy_lfr_s1_bp_p0( TC );
204 204 flag = set_sy_lfr_s1_bp_p1( TC );
205 205 }
206 206
207 207 return flag;
208 208 }
209 209
210 210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 211 {
212 212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 213 *
214 214 * @param TC points to the TeleCommand packet that is being processed
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 216 *
217 217 */
218 218
219 219 int flag;
220 220 rtems_status_code status;
221 221 unsigned char sy_lfr_s2_bp_p0;
222 222 unsigned char sy_lfr_s2_bp_p1;
223 223 float aux;
224 224
225 225 flag = LFR_SUCCESSFUL;
226 226
227 227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 229 flag = LFR_DEFAULT;
230 230 }
231 231
232 232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 234
235 235 // sy_lfr_s2_bp_p0
236 236 if (flag == LFR_SUCCESSFUL)
237 237 {
238 238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 239 {
240 240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 241 flag = WRONG_APP_DATA;
242 242 }
243 243 }
244 244 // sy_lfr_s2_bp_p1
245 245 if (flag == LFR_SUCCESSFUL)
246 246 {
247 247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 248 {
249 249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 250 flag = WRONG_APP_DATA;
251 251 }
252 252 }
253 253 //******************************************************************
254 254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 255 if (flag == LFR_SUCCESSFUL)
256 256 {
257 257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 260 if (aux > FLOAT_EQUAL_ZERO)
261 261 {
262 262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 263 flag = LFR_DEFAULT;
264 264 }
265 265 }
266 266
267 267 // SET THE PARAMETERS
268 268 if (flag == LFR_SUCCESSFUL)
269 269 {
270 270 flag = set_sy_lfr_s2_bp_p0( TC );
271 271 flag = set_sy_lfr_s2_bp_p1( TC );
272 272 }
273 273
274 274 return flag;
275 275 }
276 276
277 277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 278 {
279 279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 280 *
281 281 * @param TC points to the TeleCommand packet that is being processed
282 282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 283 *
284 284 */
285 285
286 286 int flag;
287 287
288 288 flag = LFR_DEFAULT;
289 289
290 290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 291
292 292 return flag;
293 293 }
294 294
295 295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 296 {
297 297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 298 *
299 299 * @param TC points to the TeleCommand packet that is being processed
300 300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 301 *
302 302 */
303 303
304 304 int flag;
305 305
306 306 flag = LFR_DEFAULT;
307 307
308 308 flag = set_sy_lfr_fbins( TC );
309 309
310 310 return flag;
311 311 }
312 312
313 313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 314 {
315 315 /** This function updates the LFR registers with the incoming sbm2 parameters.
316 316 *
317 317 * @param TC points to the TeleCommand packet that is being processed
318 318 * @param queue_id is the id of the queue which handles TM related to this execution step
319 319 *
320 320 */
321 321
322 322 int flag;
323 323
324 324 flag = LFR_DEFAULT;
325 325
326 326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
327 327
328 328 if (flag == LFR_SUCCESSFUL)
329 329 {
330 330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
331 331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
332 332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
333 333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
334 334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
335 335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
336 336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
337 337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
338 338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
339 339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
340 340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
341 341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
342 342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
343 343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
344 344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
345 345
346 346 // store the parameter sy_lfr_sc_rw_delta_f as a float
347 347 copyFloatByChar( (unsigned char*) &sy_lfr_sc_rw_delta_f,
348 348 (unsigned char*) &parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] );
349 349 }
350 350
351 351 return flag;
352 352 }
353 353
354 354 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
355 355 {
356 356 /** This function updates the LFR registers with the incoming sbm2 parameters.
357 357 *
358 358 * @param TC points to the TeleCommand packet that is being processed
359 359 * @param queue_id is the id of the queue which handles TM related to this execution step
360 360 *
361 361 */
362 362
363 363 unsigned int address;
364 364 rtems_status_code status;
365 365 unsigned int freq;
366 366 unsigned int bin;
367 367 unsigned int coeff;
368 368 unsigned char *kCoeffPtr;
369 369 unsigned char *kCoeffDumpPtr;
370 370
371 371 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
372 372 // F0 => 11 bins
373 373 // F1 => 13 bins
374 374 // F2 => 12 bins
375 375 // 36 bins to dump in two packets (30 bins max per packet)
376 376
377 377 //*********
378 378 // PACKET 1
379 379 // 11 F0 bins, 13 F1 bins and 6 F2 bins
380 380 kcoefficients_dump_1.destinationID = TC->sourceID;
381 381 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
382 382 for( freq=0;
383 383 freq<NB_BINS_COMPRESSED_SM_F0;
384 384 freq++ )
385 385 {
386 386 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
387 387 bin = freq;
388 388 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
389 389 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
390 390 {
391 391 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
392 392 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
393 393 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
394 394 }
395 395 }
396 396 for( freq=NB_BINS_COMPRESSED_SM_F0;
397 397 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
398 398 freq++ )
399 399 {
400 400 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
401 401 bin = freq - NB_BINS_COMPRESSED_SM_F0;
402 402 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
403 403 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
404 404 {
405 405 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
406 406 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
407 407 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
408 408 }
409 409 }
410 410 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
411 411 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
412 412 freq++ )
413 413 {
414 414 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
415 415 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
416 416 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
417 417 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
418 418 {
419 419 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
420 420 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
421 421 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
422 422 }
423 423 }
424 424 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
425 425 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
426 426 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
427 427 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
428 428 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
429 429 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
430 430 // SEND DATA
431 431 kcoefficient_node_1.status = 1;
432 432 address = (unsigned int) &kcoefficient_node_1;
433 433 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
434 434 if (status != RTEMS_SUCCESSFUL) {
435 435 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
436 436 }
437 437
438 438 //********
439 439 // PACKET 2
440 440 // 6 F2 bins
441 441 kcoefficients_dump_2.destinationID = TC->sourceID;
442 442 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
443 443 for( freq=0; freq<6; freq++ )
444 444 {
445 445 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
446 446 bin = freq + 6;
447 447 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
448 448 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
449 449 {
450 450 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
451 451 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
452 452 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
453 453 }
454 454 }
455 455 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
456 456 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
457 457 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
458 458 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
459 459 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
460 460 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
461 461 // SEND DATA
462 462 kcoefficient_node_2.status = 1;
463 463 address = (unsigned int) &kcoefficient_node_2;
464 464 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
465 465 if (status != RTEMS_SUCCESSFUL) {
466 466 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
467 467 }
468 468
469 469 return status;
470 470 }
471 471
472 472 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
473 473 {
474 474 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
475 475 *
476 476 * @param queue_id is the id of the queue which handles TM related to this execution step.
477 477 *
478 478 * @return RTEMS directive status codes:
479 479 * - RTEMS_SUCCESSFUL - message sent successfully
480 480 * - RTEMS_INVALID_ID - invalid queue id
481 481 * - RTEMS_INVALID_SIZE - invalid message size
482 482 * - RTEMS_INVALID_ADDRESS - buffer is NULL
483 483 * - RTEMS_UNSATISFIED - out of message buffers
484 484 * - RTEMS_TOO_MANY - queue s limit has been reached
485 485 *
486 486 */
487 487
488 488 int status;
489 489
490 490 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
491 491 parameter_dump_packet.destinationID = TC->sourceID;
492 492
493 493 // UPDATE TIME
494 494 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
495 495 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
496 496 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
497 497 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
498 498 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
499 499 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
500 500 // SEND DATA
501 501 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
502 502 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
503 503 if (status != RTEMS_SUCCESSFUL) {
504 504 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
505 505 }
506 506
507 507 return status;
508 508 }
509 509
510 510 //***********************
511 511 // NORMAL MODE PARAMETERS
512 512
513 513 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
514 514 {
515 515 unsigned char msb;
516 516 unsigned char lsb;
517 517 int flag;
518 518 float aux;
519 519 rtems_status_code status;
520 520
521 521 unsigned int sy_lfr_n_swf_l;
522 522 unsigned int sy_lfr_n_swf_p;
523 523 unsigned int sy_lfr_n_asm_p;
524 524 unsigned char sy_lfr_n_bp_p0;
525 525 unsigned char sy_lfr_n_bp_p1;
526 526 unsigned char sy_lfr_n_cwf_long_f3;
527 527
528 528 flag = LFR_SUCCESSFUL;
529 529
530 530 //***************
531 531 // get parameters
532 532 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
533 533 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
534 534 sy_lfr_n_swf_l = msb * 256 + lsb;
535 535
536 536 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
537 537 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
538 538 sy_lfr_n_swf_p = msb * 256 + lsb;
539 539
540 540 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
541 541 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
542 542 sy_lfr_n_asm_p = msb * 256 + lsb;
543 543
544 544 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
545 545
546 546 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
547 547
548 548 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
549 549
550 550 //******************
551 551 // check consistency
552 552 // sy_lfr_n_swf_l
553 553 if (sy_lfr_n_swf_l != 2048)
554 554 {
555 555 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
556 556 flag = WRONG_APP_DATA;
557 557 }
558 558 // sy_lfr_n_swf_p
559 559 if (flag == LFR_SUCCESSFUL)
560 560 {
561 561 if ( sy_lfr_n_swf_p < 22 )
562 562 {
563 563 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
564 564 flag = WRONG_APP_DATA;
565 565 }
566 566 }
567 567 // sy_lfr_n_bp_p0
568 568 if (flag == LFR_SUCCESSFUL)
569 569 {
570 570 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
571 571 {
572 572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
573 573 flag = WRONG_APP_DATA;
574 574 }
575 575 }
576 576 // sy_lfr_n_asm_p
577 577 if (flag == LFR_SUCCESSFUL)
578 578 {
579 579 if (sy_lfr_n_asm_p == 0)
580 580 {
581 581 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
582 582 flag = WRONG_APP_DATA;
583 583 }
584 584 }
585 585 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
586 586 if (flag == LFR_SUCCESSFUL)
587 587 {
588 588 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
589 589 if (aux > FLOAT_EQUAL_ZERO)
590 590 {
591 591 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
592 592 flag = WRONG_APP_DATA;
593 593 }
594 594 }
595 595 // sy_lfr_n_bp_p1
596 596 if (flag == LFR_SUCCESSFUL)
597 597 {
598 598 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
599 599 {
600 600 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
601 601 flag = WRONG_APP_DATA;
602 602 }
603 603 }
604 604 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
605 605 if (flag == LFR_SUCCESSFUL)
606 606 {
607 607 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
608 608 if (aux > FLOAT_EQUAL_ZERO)
609 609 {
610 610 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
611 611 flag = LFR_DEFAULT;
612 612 }
613 613 }
614 614 // sy_lfr_n_cwf_long_f3
615 615
616 616 return flag;
617 617 }
618 618
619 619 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
620 620 {
621 621 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
622 622 *
623 623 * @param TC points to the TeleCommand packet that is being processed
624 624 * @param queue_id is the id of the queue which handles TM related to this execution step
625 625 *
626 626 */
627 627
628 628 int result;
629 629
630 630 result = LFR_SUCCESSFUL;
631 631
632 632 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
633 633 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
634 634
635 635 return result;
636 636 }
637 637
638 638 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
639 639 {
640 640 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
641 641 *
642 642 * @param TC points to the TeleCommand packet that is being processed
643 643 * @param queue_id is the id of the queue which handles TM related to this execution step
644 644 *
645 645 */
646 646
647 647 int result;
648 648
649 649 result = LFR_SUCCESSFUL;
650 650
651 651 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
652 652 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
653 653
654 654 return result;
655 655 }
656 656
657 657 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
658 658 {
659 659 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
660 660 *
661 661 * @param TC points to the TeleCommand packet that is being processed
662 662 * @param queue_id is the id of the queue which handles TM related to this execution step
663 663 *
664 664 */
665 665
666 666 int result;
667 667
668 668 result = LFR_SUCCESSFUL;
669 669
670 670 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
671 671 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
672 672
673 673 return result;
674 674 }
675 675
676 676 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
677 677 {
678 678 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
679 679 *
680 680 * @param TC points to the TeleCommand packet that is being processed
681 681 * @param queue_id is the id of the queue which handles TM related to this execution step
682 682 *
683 683 */
684 684
685 685 int status;
686 686
687 687 status = LFR_SUCCESSFUL;
688 688
689 689 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
690 690
691 691 return status;
692 692 }
693 693
694 694 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
695 695 {
696 696 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
697 697 *
698 698 * @param TC points to the TeleCommand packet that is being processed
699 699 * @param queue_id is the id of the queue which handles TM related to this execution step
700 700 *
701 701 */
702 702
703 703 int status;
704 704
705 705 status = LFR_SUCCESSFUL;
706 706
707 707 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
708 708
709 709 return status;
710 710 }
711 711
712 712 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
713 713 {
714 714 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
715 715 *
716 716 * @param TC points to the TeleCommand packet that is being processed
717 717 * @param queue_id is the id of the queue which handles TM related to this execution step
718 718 *
719 719 */
720 720
721 721 int status;
722 722
723 723 status = LFR_SUCCESSFUL;
724 724
725 725 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
726 726
727 727 return status;
728 728 }
729 729
730 730 //**********************
731 731 // BURST MODE PARAMETERS
732 732 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
733 733 {
734 734 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
735 735 *
736 736 * @param TC points to the TeleCommand packet that is being processed
737 737 * @param queue_id is the id of the queue which handles TM related to this execution step
738 738 *
739 739 */
740 740
741 741 int status;
742 742
743 743 status = LFR_SUCCESSFUL;
744 744
745 745 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
746 746
747 747 return status;
748 748 }
749 749
750 750 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
751 751 {
752 752 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
753 753 *
754 754 * @param TC points to the TeleCommand packet that is being processed
755 755 * @param queue_id is the id of the queue which handles TM related to this execution step
756 756 *
757 757 */
758 758
759 759 int status;
760 760
761 761 status = LFR_SUCCESSFUL;
762 762
763 763 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
764 764
765 765 return status;
766 766 }
767 767
768 768 //*********************
769 769 // SBM1 MODE PARAMETERS
770 770 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
771 771 {
772 772 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
773 773 *
774 774 * @param TC points to the TeleCommand packet that is being processed
775 775 * @param queue_id is the id of the queue which handles TM related to this execution step
776 776 *
777 777 */
778 778
779 779 int status;
780 780
781 781 status = LFR_SUCCESSFUL;
782 782
783 783 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
784 784
785 785 return status;
786 786 }
787 787
788 788 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
789 789 {
790 790 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
791 791 *
792 792 * @param TC points to the TeleCommand packet that is being processed
793 793 * @param queue_id is the id of the queue which handles TM related to this execution step
794 794 *
795 795 */
796 796
797 797 int status;
798 798
799 799 status = LFR_SUCCESSFUL;
800 800
801 801 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
802 802
803 803 return status;
804 804 }
805 805
806 806 //*********************
807 807 // SBM2 MODE PARAMETERS
808 808 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
809 809 {
810 810 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
811 811 *
812 812 * @param TC points to the TeleCommand packet that is being processed
813 813 * @param queue_id is the id of the queue which handles TM related to this execution step
814 814 *
815 815 */
816 816
817 817 int status;
818 818
819 819 status = LFR_SUCCESSFUL;
820 820
821 821 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
822 822
823 823 return status;
824 824 }
825 825
826 826 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
827 827 {
828 828 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
829 829 *
830 830 * @param TC points to the TeleCommand packet that is being processed
831 831 * @param queue_id is the id of the queue which handles TM related to this execution step
832 832 *
833 833 */
834 834
835 835 int status;
836 836
837 837 status = LFR_SUCCESSFUL;
838 838
839 839 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
840 840
841 841 return status;
842 842 }
843 843
844 844 //*******************
845 845 // TC_LFR_UPDATE_INFO
846 846 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
847 847 {
848 848 unsigned int status;
849 849
850 850 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
851 851 || (mode == LFR_MODE_BURST)
852 852 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
853 853 {
854 854 status = LFR_SUCCESSFUL;
855 855 }
856 856 else
857 857 {
858 858 status = LFR_DEFAULT;
859 859 }
860 860
861 861 return status;
862 862 }
863 863
864 864 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
865 865 {
866 866 unsigned int status;
867 867
868 868 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
869 869 || (mode == TDS_MODE_BURST)
870 870 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
871 871 || (mode == TDS_MODE_LFM))
872 872 {
873 873 status = LFR_SUCCESSFUL;
874 874 }
875 875 else
876 876 {
877 877 status = LFR_DEFAULT;
878 878 }
879 879
880 880 return status;
881 881 }
882 882
883 883 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
884 884 {
885 885 unsigned int status;
886 886
887 887 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
888 888 || (mode == THR_MODE_BURST))
889 889 {
890 890 status = LFR_SUCCESSFUL;
891 891 }
892 892 else
893 893 {
894 894 status = LFR_DEFAULT;
895 895 }
896 896
897 897 return status;
898 898 }
899 899
900 900 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
901 901 {
902 902 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
903 903 *
904 904 * @param TC points to the TeleCommand packet that is being processed
905 905 *
906 906 */
907 907
908 908 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
909 909
910 910 bytePosPtr = (unsigned char *) &TC->packetID;
911 911
912