-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_utils.py
More file actions
81 lines (70 loc) · 2.55 KB
/
tag_utils.py
File metadata and controls
81 lines (70 loc) · 2.55 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2017 Thomas Goodwin and Geon Technologies
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr
import bulkio
from ossie.properties import props_from_dict, props_to_dict
RH_PACKET_TAG_KEY = 'rh_packet'
RH_PACKET_KEY_SRI = 'sri'
RH_PACKET_KEY_CHANGED = 'changed'
RH_PACKET_KEY_T = 'T'
RH_PACKET_KEY_EOS = 'EOS'
def sri_to_dict(sri):
sri.keywords = props_to_dict(sri.keywords)
return sri.__dict__
def sri_from_dict(sridict):
sri = bulkio.sri.create()
sri.__dict__ = sridict
sri.keywords = props_from_dict(sri.keywords)
return sri
def rh_packet_to_tag(packet, tag_index=0):
rh_dict = dict({
RH_PACKET_KEY_SRI: sri_to_dict(packet.SRI),
RH_PACKET_KEY_CHANGED: packet.sriChanged,
RH_PACKET_KEY_T: packet.T.__dict__,
RH_PACKET_KEY_EOS: packet.EOS
})
rh_pmt = gr.pmt.to_pmt(rh_dict)
tag = gr.python_to_tag((
tag_index,
gr.pmt.string_to_symbol(RH_PACKET_TAG_KEY),
rh_pmt,
gr.pmt.string_to_symbol(packet.SRI.streamID)
))
return tag
# Converts from a stream tag to a REDHAWK Packet fields
# Note: We omit the timestamp, T, since for some reason tags do not
# reliably get delivered, and therefore we re-stamp at the sink.
def tag_to_rh_packet(tag):
# Defaults
changed = False
EOS = False
SRI = bulkio.sri.create()
# Convert
tag_p = gr.tag_to_python(tag)
tag_dict = tag_p.__dict__
if tag_dict['key'] == RH_PACKET_TAG_KEY:
packet = tag_dict.pop('value')
SRI = sri_from_dict(packet.get(RH_PACKET_KEY_SRI, SRI.__dict__))
changed = packet.get(RH_PACKET_KEY_CHANGED, changed)
EOS = packet.get(RH_PACKET_KEY_EOS, EOS)
return (SRI, changed, EOS)
if __name__ == "__main__":
pass