1#!/usr/bin/env python3
2
3"""Test PUS TM ingestion code."""
4
5import sys
6
7from chartepssg import project # must come first
8from chart.common.path import Path
9from chart.products.pus.ccsds_io import gen_ccsds_from_raw
10from chart.products.rapidfile.rapid_io import gen_rapid_from_raw
11from chart.products.pus.ccsds_ingest import read_packet
12from chart.common.log import init_log
13from chart.common.traits import is_listlike
14from chart.common.test_utils import show
15from chart.common.test_utils import compare
16from chart.project import settings
17
18project.init_epssg()
19
20
21PROJECT_ROOT_DIR = settings.PROJECT_HOME_DIR.parent
22TM_PRODUCT_DIR = PROJECT_ROOT_DIR.joinpath("tests", "application", "products", "tm")
23
24target = sys.stdout
25
26
27def test_tm_MSY_ACK00010_decode():
28 """A basic packet containing 8 static numerical fields"""
29 source = gen_ccsds_from_raw(
30 TM_PRODUCT_DIR.joinpath("MSY_ACK00010.ccsds").open("rb")
31 )
32 ccsds_container = next(iter(source))
33 packet_def = ccsds_container.packet_def
34 ccsds = ccsds_container.ccsds
35 rows = list(read_packet(packet_def, ccsds_container))
36 assert len(rows) == 2
37 act = rows[
38 1
39 ] # for each table to be written to, we get a tuple of TableInfo, values
40
41 req = {
42 "MST00350": 6668,
43 "MST00351": 51899,
44 "MST00352": 8193,
45 "MST00356": 9,
46 "MST00357": 129,
47 "MST00358": 12,
48 "MST00354": 0,
49 "MST00355": 0,
50 }
51
52 show("Comparing actual", act)
53 show("to req", req)
54 comp = compare(req, act)
55 if comp is not None:
56 target.write("\n".join(comp) + "\n")
57 assert False
58
59
60def test_tm_CSY_PM_20420_decode():
61 """A readout packet containing an array of 1 pair deduced fields, holding a 192-byte array."""
62 source = gen_ccsds_from_raw(
63 TM_PRODUCT_DIR.joinpath("CSY_PM_20420.ccsds").open("rb")
64 )
65 ccsds_container = next(iter(source))
66 packet_def = ccsds_container.packet_def
67 ccsds = ccsds_container.ccsds
68 rows = list(read_packet(packet_def, ccsds_container))
69 assert len(rows) == 2
70 act = rows[
71 1
72 ] # for each table to be written to, we get a tuple of TableInfo, values
73
74 # deduced parameter is CLTG2131
75
76 req = {
77 "CST00203": 1,
78 "CST00045": [212930637],
79 "CST00046": [
80 "0x0000000000000000000000000000000001f0f0f0ffffffffffffffffffffffff"
81 "02f0f0f0ffffffffffffffffffffffff030f0f0f0f0ffffe00f0f0f0f0f0f0f0"
82 "04f0f0f00000f3cc0000f3cc00007fff05f0f0f0ffffffffffffffffffffffff"
83 "06f0f0f0ffffffffffffffffffffffff07f0f0f00000a9be0000a9be0003ffff"
84 "08f0f0f00000a9be0000a9be0003ffff09f0f0f000005000027f0000000018e0"
85 "0af0f0f0000068e0027c800000004af40bf0f0f0040000000200000000100000"
86 ],
87 }
88
89 show("Comparing actual", act)
90 show("to req", req)
91 comp = compare(req, act)
92 if comp is not None:
93 target.write("\n".join(comp) + "\n")
94 assert False
95
96
97def test_tm_ASY_MON32305_decode():
98 """A complex packet with arrays of dual pidrefs but no deduced parameters."""
99 # packet param def:
100
101 # Table Byte Len Gap Pos Group Rpt Dis Off Name Unit Cal Description Dim
102 # ----- ---- --- --- --- ----- --- ------ --- -------- ---- --- ------------------- ---
103 # TM
104 # 8 - 0 AST00060 MONITORING_STATE 0
105 # 8 - 0 AST00061 MAX_REP_DELAY 0
106 # 8 - 15 0 AST00063 NR_MONITORING 0
107 # 8 - 0 AST00062 MONITORING_ID 1
108 # 32 - pidref 0 AST00045 PARAMETER_ID 1
109 # 32 - pidref 0 AST00064 VALIDITY_PARAMETER 1
110 # 16 - 0 AST00065 MONITORING_INTERVAL 1
111 # 8 - 0 AST00066 REPETITION_INTERVAL 1
112 # 8 - 0 AST00067 MONITORING_STATE 1
113 # 8 - 0 AST00068 NOL 1
114 # - 0 AST00069 LOW_LIMIT 1
115 # 16 - 0 AST00070 LOW_LIMIT_EID 1
116 # - 0 AST00071 HIGH_LIMIT 1
117 # 16 - 0 AST00072 HIGH_LIMIT_EID 1
118 # 8 - 0 AST00091 NOE 1
119 # 32 - 0 AST00074 MASK 1
120 # - 0 AST00092 EXPECTED_VALUE 1
121 # 16 - 0 AST00093 EXPECTED_VALUE_EID 1
122
123 # actual contents:
124
125 # Counter: 0
126 # Length: 2048
127 # File position: 4541629
128 # Sensing time: 2023-06-21 19:23:15.561534
129 # Name: ASY_MON32305
130 # Description: AOCS Monitoring list report
131 # SPID: 32305
132 # APID: 179 (11/3)
133 # Sequence count: 78
134 # Length: 2041 (2048)
135 # Service: 12
136 # Subservice: 9
137 # OBT: 1371410613/36800/174
138 # Param1: 0
139 # Param2: 0
140
141 # Deciders:
142 # AST00045 value 169869921 name CST31002 datatype uint length 32
143 # AST00064 value 186716162 name name AST08001 datatype uint length
144
145 # repeat counts 45
146 # repeat length 1+4+4+2+1+1+1+4+2+4+2+1+4+4+2=37 + offsets 8+8+4=20 = 57
147 # total repeat 45 *
148
149 # total len 2048
150 # 18 + 2 + 1 + 2025 + 2 = 2048
151 #
152
153 source = gen_ccsds_from_raw(
154 TM_PRODUCT_DIR.joinpath("ASY_MON32305.ccsds").open("rb")
155 )
156 ccsds_container = next(iter(source))
157 packet_def = ccsds_container.packet_def
158 ccsds = ccsds_container.ccsds
159 rows = list(read_packet(packet_def, ccsds_container))
160 assert len(rows) == 2
161 act = rows[
162 1
163 ] # for each table to be written to, we get a tuple of TableInfo, values
164
165 req = {
166 "AST00060": 1,
167 "AST00061": 0,
168 "AST00063": 45,
169 "AST00062": [
170 1,
171 2,
172 7,
173 8,
174 9,
175 15,
176 16,
177 17,
178 18,
179 19,
180 20,
181 21,
182 22,
183 23,
184 24,
185 25,
186 26,
187 27,
188 28,
189 29,
190 30,
191 31,
192 32,
193 33,
194 34,
195 35,
196 37,
197 38,
198 39,
199 40,
200 41,
201 42,
202 43,
203 45,
204 46,
205 47,
206 48,
207 57,
208 58,
209 59,
210 60,
211 61,
212 62,
213 63,
214 64,
215 ],
216 "AST00045": [
217 169869921,
218 169869922,
219 169869933,
220 169869934,
221 169869945,
222 178328297,
223 178328311,
224 170012839,
225 170012839,
226 196608190,
227 196608198,
228 196608191,
229 196608199,
230 170013674,
231 170013674,
232 178328299,
233 178328313,
234 170012838,
235 170012838,
236 178328141,
237 178332274,
238 178328142,
239 178332275,
240 170013673,
241 170013673,
242 196806809,
243 196806549,
244 196087949,
245 195041665,
246 196092045,
247 195045761,
248 196096141,
249 195049857,
250 196346142,
251 196346143,
252 196346144,
253 196346145,
254 196349962,
255 196354060,
256 196358157,
257 196362254,
258 196806711,
259 196806712,
260 196806713,
261 196411537,
262 ],
263 "AST00064": [
264 186716162,
265 186720258,
266 186650626,
267 186654722,
268 186658818,
269 187174913,
270 187179009,
271 187174915,
272 187179011,
273 187174915,
274 187179011,
275 187174915,
276 187179011,
277 187174915,
278 187179011,
279 187461633,
280 187461889,
281 187461635,
282 187461891,
283 187461635,
284 187461891,
285 187461635,
286 187461891,
287 187461635,
288 187461891,
289 196806821,
290 196806812,
291 186650627,
292 186650626,
293 186654723,
294 186654722,
295 186658819,
296 186658818,
297 186912771,
298 186916867,
299 186920963,
300 186925059,
301 186912770,
302 186916866,
303 186920962,
304 186925058,
305 0,
306 0,
307 0,
308 186978306,
309 ],
310 "AST00065": [
311 2,
312 2,
313 2,
314 2,
315 2,
316 20,
317 20,
318 1,
319 1,
320 2,
321 2,
322 2,
323 2,
324 1,
325 1,
326 20,
327 20,
328 1,
329 1,
330 2,
331 2,
332 2,
333 2,
334 1,
335 1,
336 10,
337 2,
338 1,
339 30,
340 1,
341 30,
342 1,
343 30,
344 2,
345 2,
346 2,
347 2,
348 2,
349 2,
350 2,
351 2,
352 2,
353 2,
354 2,
355 2,
356 ],
357 "AST00066": [
358 9,
359 9,
360 7,
361 7,
362 7,
363 2,
364 2,
365 28,
366 28,
367 3,
368 3,
369 3,
370 3,
371 28,
372 28,
373 2,
374 2,
375 28,
376 28,
377 3,
378 3,
379 3,
380 3,
381 28,
382 28,
383 220,
384 20,
385 52,
386 3,
387 52,
388 3,
389 52,
390 3,
391 20,
392 20,
393 20,
394 20,
395 7,
396 7,
397 7,
398 7,
399 6,
400 6,
401 6,
402 13,
403 ],
404 "AST00067": [
405 1,
406 1,
407 1,
408 1,
409 1,
410 1,
411 1,
412 1,
413 1,
414 1,
415 1,
416 1,
417 1,
418 1,
419 1,
420 1,
421 1,
422 1,
423 1,
424 1,
425 1,
426 1,
427 1,
428 1,
429 1,
430 1,
431 1,
432 1,
433 1,
434 1,
435 1,
436 1,
437 1,
438 1,
439 1,
440 1,
441 1,
442 0,
443 0,
444 0,
445 0,
446 1,
447 1,
448 1,
449 1,
450 ],
451 "AST00068": [
452 1,
453 1,
454 1,
455 1,
456 1,
457 1,
458 1,
459 0,
460 0,
461 1,
462 1,
463 1,
464 1,
465 1,
466 1,
467 1,
468 1,
469 0,
470 0,
471 1,
472 1,
473 1,
474 1,
475 1,
476 1,
477 0,
478 1,
479 1,
480 1,
481 1,
482 1,
483 1,
484 1,
485 1,
486 1,
487 1,
488 1,
489 1,
490 1,
491 1,
492 1,
493 1,
494 1,
495 1,
496 0,
497 ],
498 "AST00069": [
499 0,
500 0,
501 0,
502 0,
503 0,
504 5692,
505 5692,
506 0,
507 0,
508 22711,
509 22711,
510 -27758,
511 -27758,
512 2,
513 2,
514 4962,
515 4962,
516 0,
517 0,
518 22711,
519 22711,
520 -27758,
521 -27758,
522 4,
523 4,
524 0,
525 -10.0,
526 0,
527 -300,
528 0,
529 -300,
530 0,
531 -300,
532 -0.05,
533 -0.05,
534 -0.05,
535 -0.05,
536 2051,
537 2051,
538 2051,
539 2051,
540 -0.025,
541 -0.025,
542 -0.025,
543 0,
544 ],
545 "AST00070": [
546 38304,
547 38306,
548 38316,
549 38318,
550 38320,
551 38332,
552 38334,
553 0,
554 0,
555 38340,
556 38342,
557 38344,
558 38346,
559 38348,
560 38350,
561 38352,
562 38354,
563 0,
564 0,
565 38360,
566 38362,
567 38364,
568 38366,
569 38368,
570 38370,
571 0,
572 38376,
573 38378,
574 38380,
575 38382,
576 38384,
577 38386,
578 38388,
579 38392,
580 38394,
581 38396,
582 38398,
583 38416,
584 38418,
585 38420,
586 38422,
587 38424,
588 38426,
589 38428,
590 0,
591 ],
592 "AST00071": [
593 0,
594 0,
595 0,
596 0,
597 0,
598 60480,
599 60480,
600 0,
601 0,
602 27758,
603 27758,
604 -22711,
605 -22711,
606 2,
607 2,
608 60480,
609 60480,
610 0,
611 0,
612 27758,
613 27758,
614 -22711,
615 -22711,
616 4,
617 4,
618 0,
619 0.02,
620 4,
621 300,
622 4,
623 300,
624 4,
625 300,
626 0.05,
627 0.05,
628 0.05,
629 0.05,
630 36883,
631 36883,
632 36883,
633 36883,
634 0.025,
635 0.025,
636 0.025,
637 0,
638 ],
639 "AST00072": [
640 38305,
641 38307,
642 38317,
643 38319,
644 38321,
645 38333,
646 38335,
647 0,
648 0,
649 38341,
650 38343,
651 38345,
652 38347,
653 38349,
654 38351,
655 38353,
656 38355,
657 0,
658 0,
659 38361,
660 38363,
661 38365,
662 38367,
663 38369,
664 38371,
665 0,
666 38377,
667 38379,
668 38381,
669 38383,
670 38385,
671 38387,
672 38389,
673 38393,
674 38395,
675 38397,
676 38399,
677 38417,
678 38419,
679 38421,
680 38423,
681 38425,
682 38427,
683 38429,
684 0,
685 ],
686 "AST00091": [
687 0,
688 0,
689 0,
690 0,
691 0,
692 0,
693 0,
694 1,
695 1,
696 0,
697 0,
698 0,
699 0,
700 0,
701 0,
702 0,
703 0,
704 1,
705 1,
706 0,
707 0,
708 0,
709 0,
710 0,
711 0,
712 1,
713 0,
714 0,
715 0,
716 0,
717 0,
718 0,
719 0,
720 0,
721 0,
722 0,
723 0,
724 0,
725 0,
726 0,
727 0,
728 0,
729 0,
730 0,
731 1,
732 ],
733 "AST00074": [
734 0,
735 0,
736 0,
737 0,
738 0,
739 0,
740 0,
741 4294967295,
742 4294967295,
743 0,
744 0,
745 0,
746 0,
747 0,
748 0,
749 0,
750 0,
751 4294967295,
752 4294967295,
753 0,
754 0,
755 0,
756 0,
757 0,
758 0,
759 4294967295,
760 0,
761 0,
762 0,
763 0,
764 0,
765 0,
766 0,
767 0,
768 0,
769 0,
770 0,
771 0,
772 0,
773 0,
774 0,
775 0,
776 0,
777 0,
778 4294967295,
779 ],
780 "AST00092": [
781 0,
782 0,
783 0,
784 0,
785 0,
786 0,
787 0,
788 0,
789 0,
790 0,
791 0,
792 0,
793 0,
794 0,
795 0,
796 0,
797 0,
798 0,
799 0,
800 0,
801 0,
802 0,
803 0,
804 0,
805 0,
806 0,
807 0.0,
808 0,
809 0,
810 0,
811 0,
812 0,
813 0,
814 0.0,
815 0.0,
816 0.0,
817 0.0,
818 0,
819 0,
820 0,
821 0,
822 0.0,
823 0.0,
824 0.0,
825 1,
826 ],
827 "AST00093": [
828 0,
829 0,
830 0,
831 0,
832 0,
833 0,
834 0,
835 38336,
836 38338,
837 0,
838 0,
839 0,
840 0,
841 0,
842 0,
843 0,
844 0,
845 38356,
846 38358,
847 0,
848 0,
849 0,
850 0,
851 0,
852 0,
853 38372,
854 0,
855 0,
856 0,
857 0,
858 0,
859 0,
860 0,
861 0,
862 0,
863 0,
864 0,
865 0,
866 0,
867 0,
868 0,
869 0,
870 0,
871 0,
872 38430,
873 ],
874 }
875
876 assert ccsds.pec == 51273
877 show("Comparing actual", act)
878 show("to req", req)
879 comp = compare(req, act)
880 if comp is not None:
881 target.write("\n".join(comp) + "\n")
882 assert False