JavaScript Block - Tags and Messages
A JavaScript Block reads and rewrites stream tags while a shipped message-only JavaScript block adds metadata to a PDU.
- Author Marc
- Category JavaScript Blocks
- Blocks 11
- Connections 7
- File
javascript/js_tags_and_messages.grc
Blocks used
| Block | Module | Used |
|---|---|---|
| Char To Float | GNU Radio | 1 |
| GUI Layout | GNU Radio | 1 |
| JS Block | GNU Radio | 1 |
| Message Debug | GNU Radio | 1 |
| Message Strobe | GNU Radio | 1 |
| PDU Length Metadata | GNU Radio | 1 |
| QT GUI Time Sink | GNU Radio | 1 |
| Tag Debug | GNU Radio | 1 |
| Tag Object | GNU Radio | 1 |
| Throttle | GNU Radio | 1 |
| Vector Source | GNU Radio | 1 |
Flowgraph source
javascript/js_tags_and_messages.grc
options:
parameters:
author: Marc
comment: ''
copyright: ''
description: A JavaScript Block reads and rewrites stream tags while a shipped message-only JavaScript block adds metadata to a PDU.
generate_options: qt_gui
id: JavaScript_Block___Tags_and_Messages
title: JavaScript Block - Tags and Messages
states:
coordinate: [10, 10]
rotation: 0
state: enabled
blocks:
- name: blocks_char_to_float_0
id: blocks_char_to_float
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
scale: '1'
vlen: '1'
states:
coordinate: [940, 50]
rotation: 0
state: enabled
- name: input_tag
id: variable_tag_object
parameters:
affinity: ''
alias: ''
comment: ''
key: pmt.intern("input_tag")
offset: '0'
src: pmt.intern("tag_source")
value: pmt.from_long(7)
states:
coordinate: [590, 10]
rotation: 0
state: enabled
- name: js_pdu
id: js_pdu_length
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
states:
coordinate: [490, 340]
rotation: 0
state: enabled
- name: js_tags
id: wasm_js_block
parameters:
_js_io: '{"decim":1,"doc":"","general":false,"hasStart":false,"hasStop":false,"history":1,"inputs":[{"dtype":"byte","vlen":1}],"interp":1,"label":"JS Tag Transform","numericParams":[],"outputMultiple":0,"outputs":[{"dtype":"byte","vlen":1}],"overridesForecast":false,"params":[],"relativeRate":1,"tagPropagation":3}'
_js_source: ''
_source_code: "gr.export({\n label: 'JS Tag Transform',\n inputs: ['byte'],\n outputs: ['byte'],\n\n init() {\n // TPP_CUSTOM means this block deliberately propagates its own tags.\n this.set_tag_propagation_policy(gr.TPP_CUSTOM);\n },\n\n work(nout, input, output) {\n output[0].set(input[0].subarray(0, nout));\n const read = this.nitems_read(0);\n const written = this.nitems_written(0);\n const key = pmt.intern('input_tag');\n\n // The range and window spellings return the same native four-field tags.\n const ranged = this.get_tags_in_range(0, read, read + nout, key);\n const windowed = this.get_tags_in_window(0, 0, nout, key);\n if (ranged.length !== windowed.length)\n throw new Error('tag range/window mismatch');\n\n for (const tag of windowed) {\n this.add_item_tag(\n 0, written + tag.offset - read, pmt.intern('js_tag'),\n pmt.from_long(pmt.to_long(tag.value) + 1));\n }\n return nout;\n },\n});\n"
affinity: ''
alias: ''
comment: ''
states:
coordinate: [620, 190]
rotation: 0
state: enabled
- name: message_debug
id: blocks_message_debug
parameters:
affinity: ''
alias: ''
comment: ''
en_uvec: 'True'
log_level: info
states:
coordinate: [920, 330]
rotation: 0
state: enabled
- name: message_strobe
id: blocks_message_strobe
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
msg: pmt.cons(pmt.make_dict(), pmt.init_u8vector(4, [11, 22, 33, 44]))
period: '500'
states:
coordinate: [90, 340]
rotation: 0
state: enabled
- name: qtgui_time_sink_x_0
id: qtgui_time_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1'
alpha10: '1'
alpha2: '1'
alpha3: '1'
alpha4: '1'
alpha5: '1'
alpha6: '1'
alpha7: '1'
alpha8: '1'
alpha9: '1'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: dark blue
color2: red
color3: green
color4: black
color5: cyan
color6: magenta
color7: yellow
color8: dark red
color9: dark green
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
label1: Signal 1
label10: Signal 10
label2: Signal 2
label3: Signal 3
label4: Signal 4
label5: Signal 5
label6: Signal 6
label7: Signal 7
label8: Signal 8
label9: Signal 9
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
name: Scope
nconnections: '1'
samp_rate: '200'
size: '32'
stemplot: 'False'
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: ''
type: float
update_time: '0.1'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '5'
ymin: '0'
yunit: ''
states:
coordinate: [1220, 30]
rotation: 0
state: enabled
- name: tag_debug
id: blocks_tag_debug
parameters:
affinity: ''
alias: ''
comment: ''
display: 'True'
filter: '"js_tag"'
name: js_tag_output
num_inputs: '1'
type: byte
vlen: '1'
states:
coordinate: [910, 180]
rotation: 0
state: enabled
- name: tag_source
id: blocks_vector_source_x
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
repeat: 'True'
tags: '[input_tag]'
type: byte
vector: '[1, 2, 3, 4]'
vlen: '1'
states:
coordinate: [10, 180]
rotation: 0
state: enabled
- name: tag_throttle
id: blocks_throttle2
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
limit: time
maximum: '0.1'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: '200'
type: byte
vlen: '1'
states:
coordinate: [290, 170]
rotation: 0
state: enabled
- name: wasm_gui_layout_0
id: wasm_gui_layout
parameters:
affinity: ''
alias: ''
columns: '12'
comment: ''
layout: '{}'
row_height: '60'
states:
coordinate: [300, 10]
rotation: 0
state: enabled
connections:
- [blocks_char_to_float_0, '0', qtgui_time_sink_x_0, '0']
- src_blk_id: js_pdu
src_port_id: out
snk_blk_id: message_debug
snk_port_id: print_pdu
- [js_tags, '0', blocks_char_to_float_0, '0']
- [js_tags, '0', tag_debug, '0']
- src_blk_id: message_strobe
src_port_id: strobe
snk_blk_id: js_pdu
snk_port_id: in
- [tag_source, '0', tag_throttle, '0']
- [tag_throttle, '0', js_tags, '0']
metadata:
file_format: 2
grc_version: 3.11.0.0