File: qa_mobitex_deframer.py

package info (click to toggle)
gr-satellites 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,836 kB
  • sloc: python: 29,546; cpp: 5,448; ansic: 1,247; sh: 118; makefile: 24
file content (74 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2020 Daniel Estevez <daniel@destevez.net>
#           2025 Fabian P. Schmidt <kerel@mailbox.org>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gnuradio import gr, blocks, gr_unittest
import numpy as np
import pmt

# bootstrap satellites module, even from build dir
try:
    import python as satellites
except ImportError:
    pass
else:
    import sys
    sys.modules['satellites'] = satellites

from satellites.components.deframers import mobitex_deframer


class qa_mobitex_deframer(gr_unittest.TestCase):
    def setUp(self):
        file_base = __file__.rstrip('.py')
        self.symbols_path = file_base + '_symbols.f32'
        self.frame_path = file_base + '_frame.bin'

        self.tb = gr.top_block()

        self.frames_desired = [np.fromfile(self.frame_path, dtype='uint8')]

    def tearDown(self):
        self.tb = None

    def test_mobitex_deframer(self):
        """Test mobitex deframer

        Loads symbols from a BEESAT-9 packet and checks if mobitex_deframer
        produces the expected output and intermediate data (stored in
        reference files)"""
        input = blocks.file_source(gr.sizeof_float, self.symbols_path)

        deframer = mobitex_deframer(
            nx=True,
            callsign='DP0BEM',
            callsign_threshold=0,
            syncword_threshold=0,
        )
        dbg_frame = blocks.message_debug()

        self.tb.connect(input, deframer)
        self.tb.msg_connect((deframer, 'out'), (dbg_frame, 'store'))
        self.tb.start()
        self.tb.wait()

        num_msgs_desired = len(self.frames_desired)
        num_msgs_actual = dbg_frame.num_messages()
        self.assertEqual(num_msgs_actual, num_msgs_desired)

        for idx, frame_desired in enumerate(self.frames_desired):
            frame_actual = np.array(
                pmt.u8vector_elements(pmt.cdr(dbg_frame.get_message(idx))),
                dtype=np.uint8)
            np.testing.assert_array_equal(frame_actual, frame_desired)


if __name__ == '__main__':
    gr_unittest.run(qa_mobitex_deframer)