How can I trigger a GNURadio flowgraph to load and start running? - gnuradio-companion

Using Ubuntu. I have a flowgraph that runs in GNURadio which opens a file (containing IQ signal data) and displays it to a QT GUI frequency sink. It works fine when I manually load the grc file into gnuradio-companion and click the green GO arrow. However, I want to trigger this to run from another program (C or Python, whichever works). I can get the flowgraph to load, but I can't get it to run.
It appears to require keyboard input. I have tried sending it commands using named pipes as well as tried it with 4 different keystroke emulators (keyboard, pynput, xdotool, mkfifo), with and without running under sudo (always in a separate terminal window). The GNURadio companion does not react to any of my attempts to send it the keystrokes to run the flowgraph (i.e., using the actual keys, one can use alt-r to bring up the Run menu, the down key to move down to select Run, and the enter key to trigger it to run; and that works). I have made sure to identify the window when needed (you can do this using the search feature in xdotool, for example; the Python methods seem to require you to manually select the gnuradio-companion window).
What am I missing? Does GNURadio use some type of linux window that looks for something different than the standard X-terminal input?
The grc file I am trying to use follows. The file I am trying to display was previously saved by gnuradio-companion (it is IQIQIQ... , 32-bit floating point spectrum).
options:
parameters:
author: ''
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: A2
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: showfile
window_size: ''
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: samp_rate
id: variable
parameters:
comment: ''
value: '32000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 12]
rotation: 0
state: enabled
- name: blocks_file_source_0
id: blocks_file_source
parameters:
affinity: ''
alias: ''
begin_tag: pmt.PMT_NIL
comment: ''
file: /home/odroid/projects/signaldata/f3.dat
length: '0'
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
repeat: 'True'
type: float
vlen: '1024'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [200, 200.0]
rotation: 0
state: true
- name: blocks_throttle_0
id: blocks_throttle
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: samp_rate
type: float
vlen: '1024'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [440, 204.0]
rotation: 0
state: true
- name: qtgui_vector_sink_f_0
id: qtgui_vector_sink_f
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
average: '1.0'
color1: '"blue"'
color10: '"dark blue"'
color2: '"red"'
color3: '"green"'
color4: '"black"'
color5: '"cyan"'
color6: '"magenta"'
color7: '"yellow"'
color8: '"dark red"'
color9: '"dark green"'
comment: ''
grid: 'False'
gui_hint: ''
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
ref_level: '0'
showports: 'False'
update_time: '0.10'
vlen: '1024'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
x_axis_label: '"x-Axis"'
x_start: '0'
x_step: '1.0'
x_units: '""'
y_axis_label: '"y-Axis"'
y_units: '""'
ymax: '2'
ymin: '-2'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [800, 132.0]
rotation: 0
state: true
connections:
- [blocks_file_source_0, '0', blocks_throttle_0, '0']
- [blocks_throttle_0, '0', qtgui_vector_sink_f_0, '0']
metadata:
file_format: 1

Related

Swagger - How to write an example for a Free-Form Object?

We have a response type "Error" that may contain a field "extraInfo".
Error:
type: object
properties:
code:
type: string
message:
type: string
extraInfo:
description: any complementary information
type: object
// how to provide examples here?
One example for it can be :
"extraInfo": {
"doors": {
"frontLeftClosed": false,
"frontRightClosed": true,
"rearLeftClosed": true,
"rearRightClosed": true,
"trunkClosed": true
},
"windows": {
"frontLeftClosed": false,
"rearLeftClosed": true,
"trunkClosed": false
}
}
another could be :
"extraInfo": {
"transactionId": "77812783001"
}
Since it s a free form object, is there a way to provide examples for it in Swagger?
Couldn't find it in the spec : https://swagger.io/docs/specification/data-models/data-types/
Use the example keyword and specify the example value using the YAML or JSON object syntax:
extraInfo:
description: any complementary information
type: object
example: # <-------
doors:
frontLeftClosed: false
frontRightClosed: true
rearLeftClosed: true
rearRightClosed: true
trunkClosed: true
windows:
frontLeftClosed: false
rearLeftClosed: true
trunkClosed: false
OpenAPI 3.1 (which is compatible with JSON Schema 2020-12) also supports multiple examples for schemas and properties.
# openapi: 3.1.0
extraInfo:
description: any complementary information
type: object
# A list of examples
examples:
# Example 1
- transactionId: '77812783001'
# Example 2
- doors:
frontLeftClosed: false
frontRightClosed: true
rearLeftClosed: true
rearRightClosed: true
trunkClosed: true
windows:
frontLeftClosed: false
rearLeftClosed: true
trunkClosed: false

Ruby efficient each loop

Is there a better way to write this? markdown is a StringIO
coverage_hash_arr = [
{
"Module": "Mobile",
"name": "Sheila Chapman",
"age": 21
},
{
"Module": "Web",
"name": "Hendricks Walton",
"age": 40
},
{
"Module": "Misc",
"name": "Torres Mcdonald",
"age": 39
}
]
coverage_hash_arr.each do |the_hash|
    markdown << "------- Status on #{the_hash[:Module]} -------\n"
    the_hash.delete(:Module)
    the_hash.each {|key, value| markdown << "- #{key}: #{value} \n"}
    markdown << "----------------------------------------------\n"
end
I tried this and it seems to work but I wonder if there's a better way (recursion)?
coverage_hash_arr.collect do |the_hash|
the_hash.each do |key,value|
key == :Module ? markdown << "--------- Status for #{value} ----------\n" : markdown << " - #{key}: #{value} \n"
end
markdown << "------------------------------------\n\n"
end
You could:
use puts instead of << to avoid explicit newlines
use center to center the caption horizontally
use map to generate the attribute strings and utilize puts' behavior of printing array elements on separate lines
use without to get a hash without the :Module key
use * to repeat a string
Applied to your code:
markdown = StringIO.new
coverage_hash_arr.each do |hash|
markdown.puts " Status on #{hash[:Module]} ".center(46, '-')
markdown.puts hash.without(:Module).map { |k, v| "- #{k}: #{v}" }
markdown.puts '-' * 46
markdown.puts
end
Output via puts markdown.string:
-------------- Status on Mobile --------------
- name: Sheila Chapman
- age: 21
----------------------------------------------
--------------- Status on Web ----------------
- name: Hendricks Walton
- age: 40
----------------------------------------------
--------------- Status on Misc ---------------
- name: Torres Mcdonald
- age: 39
----------------------------------------------
Note that the above isn't proper Markdown syntax. You might want to change your output to something like this:
### Status on Mobile
- name: Sheila Chapman
- age: 21
### Status on Web
- name: Hendricks Walton
- age: 40
### Status on Misc
- name: Torres Mcdonald
- age: 39
Here's a more streamlined version which has been adapted to be more idiomatic Ruby:
# Define your hashes with keys having consistent case, and omit extraneous
# surrounding quotes unless defining keys like "this-name" which are not
# valid without escaping.
coverage = [
{
module: "Mobile",
name: "Sheila Chapman",
age: 21
},
{
module: "Web",
name: "Hendricks Walton",
age: 40
},
{
module: "Misc",
name: "Torres Mcdonald",
age: 39
}
]
# Iterate over each of these elements...
coverage.each do |entry|
markdown << "------- Status on #{entry[:module]} -------\n"
entry.each do |key, value|
# Skip a particular key
next if (key == :module)
markdown << "- #{key}: #{value} \n"
end
markdown << "----------------------------------------------\n"
end
This can be adapted to have a list of keys to exclude, or the inverse, of having a list of keys to actually print.
There's really nothing wrong with your approach specifically. The major faux-pas committed is in using delete on the data, which mangles it, rendering it useless if you needed to print this again.
It's generally best to try and avoid tampering with the data you're iterating over unless the purpose of that code is clear in its intent to alter it.
It looks like your input data has always the same key/value pairs and I would be more explicit to make it easier to read and to understand what the actual output is:
coverage_hash_arr.each do |hash|
markdown << <<~STRING
------- Status on #{hash[:Module]} -------
- name: #{hash[:name]}
- age: #{hash[:age]}
----------------------------------------------
STRING
end

Jenkinsfile Groovy Pipeline Text Parameter Whitespace

currently I wish to added a multliline text parmeter to a groovy pipeline. If the text parameter is not left column alighed (no space before paramter), then whitespace is injected into the text parameter list.
Any ideas on how to resolve this?
Here is the code
#!/usr/bin/env groovy
node {
def startTime = new Date()
println "Build start time : " + startTime
// Load system parameters
def projectProperties = [
[$class: 'EnvInjectJobProperty', info: [loadFilesFromMaster: false, secureGroovyScript: [classpath: [], sandbox: false, script: '']], keepBuildVariables: true, keepJenkinsSystemVariables: true, on: true]
]
// Set project parameters
projectProperties.add(parameters([
string(name: 'infraRepo', description: 'Repo Name', defaultValue: 'my-infrastructure' ),
string(name: 'infraBranch', description: 'Repo Branch', defaultValue: 'develop' ),
string(name: 'projectName', description: 'Project name', defaultValue: 'think-more' ),
// Text field not left side aligned now whitespace will be injected
text(name: 'ecrRepoAndVersion', description: 'ECR Docker name and version number',
defaultValue:'''address=3.0.1
address-details=3.0.1
auth=3.2.1'''),
choice(name: 'clusterName', description: 'Ecs cluster name', choices: '---Select---\nblue-ci\ngreen-ci', defaultValue: '---Select---'),
]))
properties(projectProperties)
// Print system variables
sh 'env | sort'
}
And here is an image of how the Jenkins Job UI looks after this pipeline is executed. Note the whitespace in the ecrRepoAndVersion field.
Thank you - that worked perfectly.
text(name: 'ecrRepoAndVersion', description: 'ECR Docker name and
version number',defaultValue:"""address=3.0.7-RC\n
address-details=3.0.3-RC\nauth=3.2.3-RC""")
Setting aside the need for this logic, I would add a bit more readability and ease of maintenance by joining a list of items, instead of verbatim specification:
def ecrRepoAndVersionItemsDefault = [
"address=3.0.7-RC",
"address-details=3.0.3-RC",
"auth=3.2.3-RC",
]
...
// then construct an ArrayList
def jobParams = []
jobParams << ...
...
jobParams << text(
name: 'ecrRepoAndVersion',
description: 'ECR Docker name and version number',
defaultValue: ecrRepoAndVersionItemsDefault.join('\n')
)
// then add the properties
...
projectProperties.add(parameters(jobParams))
...
properties(projectProperties)
...
// etc.

disable Rubocop complaint about method

I have a method that goes like this return if amount == 0 and rubocop is complaining that it should be like return if amount.zero?. How can I have it skip over that method? Here is my .rubocop.yml:
rubocop
StringLiterals:
EnforcedStyle: double_quotes
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: false
Style/TrailingCommaInLiteral:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/CaseEquality:
Enabled: false
Documentation:
Description: "Document classes and non-namespace modules."
Enabled: false
Metrics/MethodLength:
CountComments: false
Max: 15
Rails/Delegate:
Enabled: false
AllCops:
Exclude:
- db/**/*
- config/**/*
- script/**/*
- vendor/**/*
- bin/**/*
- Rakefile
- spec/spec_helper.rb
- spec/rails_helper.rb
- spec/teaspoon_env.rb
TargetRubyVersion: 2.3
Rails:
Enabled: true
submit_ticket_payment.rb
def call
return if amount == 0
Stripe::Charge.create(
amount: amount,
currency: "usd",
description: event_name,
receipt_email: context.rsvp.email,
source: context.token,
statement_descriptor: event_name
)
rescue Stripe::StripeError
context.fail!
end
So basically how can I have it not care about that particular instance?
The check in question is implemented by the Style/NumericPredicate cop.
If you generally want it to be enabled but not complain about an individual occurence, you can temporarily disable it with a special comment:
# rubocop:disable Style/NumericPredicate
return if amount == 0
# rubocop:enable Style/NumericPredicate
Note that it needs to be enabled again; otherwise it will skip the check for the whole remainder of the file.
If you wish to skip rule only for this particular method then:
# rubocop:disable Style/NumericPredicate
def call
return if amount == 0
# ...
end
# rubocop:enable Style/NumericPredicate

what is the proper syntax for seeding a database with an array?

I am a rails noob and I am trying to seed my database with an array and then a loop to fill assign the relevant code to the relevant variable. However, it isn't working. Please help.
Customer.delete_all
b[0]=[1231215,'Jeremy', 'G', '9177477337',
'jt#gmail.com', 'Central Ave', 'Rockaway', 'NY', ' 12291', '76 Son Court',
'ft lauderdale','Florida', '32423', '1', '0', '1', '1', '1', '1', '0', '0', '1', '0', '9.95',
'Honda', '2012', 'Civic', '2.4 Turbo', 'Special', '1J474GFGDHDH8883334D0','fart monkey trap']
b[1]=[46545465,'Se', 'Wof', '521428788',
'steven.j.wolfman#gmail.com', '13 NE 17 Street', 'broward', 'FL', ' 32222', '13 NE 17 Street',
'boca','Florida', '32222', '0', '0', '1',
'0', '0', '1', '1',
'1', '1', '1', '19.95',
'Ford', '2012', 'Taurus', '4.0', 'Faster', '3458GDHD3YU34D0','it smells']
i=0
while i<2 do
Customer.create(
:uid=>b[i][0],
:fname=>b[i][1],
:lname=>b[i][2],
:devphone=> b[i][3],
:email=>b[i][4],
:address=>b[i][5],
:city=>b[i][6],
:state=>b[i][7],
:zip=>b[i][8],
:baddress=>b[i][9],
:bcity=>b[i][10],
:bstate=>b[i][11],
:bzip=>b[i][12],
:roadass=>b[i][13],
:crisisass=>b[i][14],
:autocrash=>b[i][15],
:emergencyass=>b[i][16],
:remotediag=>b[i][17],
:carfind=>b[i][18],
:familytrack=>b[i][19],
:lowbatt=>b[i][20],
:towalerts=>b[i][21],
:monthlycost=>b[i][22],
:Make=>b[i][23],
:Year=>b[i][24],
:Model=>b[i][25],
:Engine=>b[i][26],
:VehicleSystem=>b[i][27],
:vinnum=>b[i][28],
:signupdate=>b[i][29],
:password=>b[i][30],
)
i+=1
end
This is the error I get when running db:seed:
rake aborted!
undefined local variable or method `b' for main:Object
You are not instantiating b as an Array before you try to assign a value. When you call b[0] the b is still a NilClass.
To get this working "as is" you would need to insert
b = []
Just under Customer.delete_all.
A much better way to do this would be
b.each |customer_record|
customer = Customer.create!
Customer.first.attributes.each_with_index do |column_name, index|
customer[column_name[0]] = customer_record[index]
end
customer.save!
end

Resources