File: rdspanel.py

package info (click to toggle)
gr-rds 3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,520 kB
  • sloc: cpp: 18,696; python: 9,650; ansic: 26; makefile: 10
file content (177 lines) | stat: -rw-r--r-- 8,025 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import pmt
from gnuradio import gr, blocks

from PyQt5 import Qt, QtCore, QtWidgets
from PyQt5.QtCore import pyqtSlot, pyqtSignal

class rdsPanel(gr.sync_block, QtWidgets.QWidget):

        msg_signal = pyqtSignal(int, str)

        def __init__(self, freq, *args, **kwds):
                gr.sync_block.__init__(
                        self,
                        name = "rds_panel",
                        in_sig = None,
                        out_sig = None,
                )
                self.message_port_register_in(pmt.intern('in'))
                self.set_msg_handler(pmt.intern('in'), self.handle_msg)

                QtWidgets.QWidget.__init__(self)
                self.msg_signal.connect(self.msg_slot)

                vlayout = Qt.QVBoxLayout()

                hlayout = Qt.QHBoxLayout()

                hlayout.addWidget(Qt.QLabel("Frequency"))
                self.freq = Qt.QLabel("%.1f" % (float(freq) / 1e6))
                self.freq.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.freq)
                hlayout.addWidget(Qt.QLabel("Station Name"))
                self.station= Qt.QLabel("")
                self.station.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.station)
                hlayout.addWidget(Qt.QLabel("Program Type"))
                self.program = Qt.QLabel("")
                self.program.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.program)
                hlayout.addWidget(Qt.QLabel("PI"))
                self.pi = Qt.QLabel("")
                self.pi.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.pi)

                vlayout.addLayout(hlayout)

                hlayout = Qt.QHBoxLayout()
                self.TP = Qt.QLabel("TP")
                self.TP.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.TP)
                self.TA = Qt.QLabel("TA")
                self.TA.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.TA)
                self.music = Qt.QLabel("music")
                self.music.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.music)
                self.stereo = Qt.QLabel("stereo")
                self.stereo.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.stereo)
                self.AH = Qt.QLabel("AH")
                self.AH.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.AH)
                self.CMP = Qt.QLabel("CMP")
                self.CMP.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.CMP)
                self.stPTY = Qt.QLabel("stPTY")
                self.stPTY.setStyleSheet("font-weight: bold; color: gray")
                hlayout.addWidget(self.stPTY)

                vlayout.addLayout(hlayout)

                hlayout = Qt.QHBoxLayout()

                hlayout.addWidget(Qt.QLabel("Clock Time"))
                self.clock_time = Qt.QLabel("")
                self.clock_time.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.clock_time)
                hlayout.addWidget(Qt.QLabel("Alt. Frequencies"))
                self.alt_freq = Qt.QLabel("")
                self.alt_freq.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.alt_freq)

                vlayout.addLayout(hlayout)

                hlayout = Qt.QHBoxLayout()

                hlayout.addWidget(Qt.QLabel("Radiotext"))
                self.radiotext = Qt.QLabel("")
                self.radiotext.setStyleSheet("font-weight: bold")
                hlayout.addWidget(self.radiotext)

                vlayout.addLayout(hlayout)

                self.setLayout(vlayout)

        def set_frequency(self, freq):
                freq_str = "%.1f" % float(freq)
                self.msg_signal.emit(7, freq_str)

        def clear_data(self):
                self.station.setText("")
                self.program.setText("")
                self.pi.setText("")
                self.TP.setStyleSheet("font-weight: bold; color: gray")
                self.TA.setStyleSheet("font-weight: bold; color: gray")
                self.music.setStyleSheet("font-weight: bold; color: gray")
                self.stereo.setStyleSheet("font-weight: bold; color: gray")
                self.AH.setStyleSheet("font-weight: bold; color: gray")
                self.CMP.setStyleSheet("font-weight: bold; color: gray")
                self.stPTY.setStyleSheet("font-weight: bold; color: gray")
                self.clock_time.setText("")
                self.alt_freq.setText("")
                self.radiotext.setText("")

        def handle_msg(self, msg):

                if(not pmt.is_tuple(msg)):
                        return

                msg_type = pmt.to_long(pmt.tuple_ref(msg, 0))
                msg = pmt.symbol_to_string(pmt.tuple_ref(msg, 1))
                msg = msg

                self.msg_signal.emit(msg_type, msg)

        @pyqtSlot(int, str)
        def msg_slot(self, msg_type, msg):

                if (msg_type==0):     #program information
                        self.program.setText(msg)
                elif (msg_type==1):   #station name
                        self.station.setText(msg)
                elif (msg_type==2):   #program type
                        self.pi.setText(msg)
                elif (msg_type==3):   #flags
                        flags=msg
                        if (flags[0]=='1'):
                                self.TP.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.TP.setStyleSheet("font-weight: bold; color: gray")
                        if (flags[1]=='1'):
                                self.TA.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.TA.setStyleSheet("font-weight: bold; color: gray")
                        if (flags[2]=='1'):
                                self.music.setText("Music")
                                self.music.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.music.setText("Speech")
                                self.music.setStyleSheet("font-weight: bold; color: red")
                        if (flags[3]=='1'):
                                self.stereo.setText("Mono")
                                self.stereo.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.stereo.setText("Stereo")
                                self.stereo.setStyleSheet("font-weight: bold; color: red")
                        if (flags[4]=='1'):
                                self.AH.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.AH.setStyleSheet("font-weight: bold; color: gray")
                        if (flags[5]=='1'):
                                self.CMP.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.CMP.setStyleSheet("font-weight: bold; color: gray")
                        if (flags[6]=='1'):
                                self.stPTY.setStyleSheet("font-weight: bold; color: red")
                        else:
                                self.stPTY.setStyleSheet("font-weight: bold; color: gray")
                elif (msg_type==4):   #radiotext
                        self.radiotext.setText(msg)
                elif (msg_type==5):   #clocktime
                        self.clock_time.setText(msg)
                elif (msg_type==6):   #alternative frequencies
                        self.alt_freq.setText(msg)
                elif (msg_type==7):   #alternative frequencies
                        self.freq.setText(msg)
                        self.clear_data()