How can I programmatically change attributes in my GNUradio flow? - gnuradio

I need to change the receive and transmit gain on my source/sink respectively based on data that will be calculated in my own piece of code. What is the best way to do this? None of the tutorials describe how this is done.
Ideally the GNUradio python script would just call a couple functions in a loop, and they would return the gain values and the system would change dynamically.

UHD sink/source can be controlled by a specific command syntax at the message port. For details see https://gnuradio.org/doc/doxygen/page_uhd.html#uhd_command_syntax .
Here is an example embedded python block with an incoming message port for gain double values and outgoing port which have to be connected to the USRP Sink/Source
from gnuradio import gr
class tuning_uhd(gr.sync_block):
def __init__(self):
gr.sync_block.__init__(self,
name="Gain Tuning",
in_sig=[],
out_sig=[]
)
# Message ports
self.message_port_register_out(gr.pmt.intern("uhd"))
self.message_port_register_in(gr.pmt.intern("gain"))
self.set_msg_handler(gr.pmt.intern('gain'), self.handle_msg)
def handle_msg(self, msg):
self.message_port_pub(gr.pmt.intern('uhd'), gr.pmt.to_pmt({'gain': gr.pmt.to_double(msg) })

I had a similar need for this functionality a few months ago. My implementation involved making a copy of the automatically generated Python 2.7 file, then editing it to add the desired functionality. In my case I needed a quick and simple way to generate multiple channels and setting variables when executing the file. This was accomplished through the use of the click module, which allowed for setting variables and executing the file via a terminal window.
If you are trying to dynamically calculate and change variables during execution, my suggestion would be to create a separate thread in the main() function using the threading module (or equivalent). This new thread should call a separate function that loops through your piece of code. Inside this function your algorithm should make use of the variablename_get and variablename_set functions that have also been automatically generated by GRC.
It is unclear where the data you are using to calculate these changes in gain comes from, but hopefully this answer is helpful.

Related

Configure .eds file to map channels of a CANopen Client PLC

In Order use a PLC as a Client (formerly “Slave”), one has to configure the PDO channels, since the default values of the manufacturer are often not suitable. In my case, I need the PDOs so send INT valued instead of the default UNSIGNED8 (see. Picture).
Therefore my question: What kind of workflow would you recommend, to map the CANopen Client PDO channels?
I found the following workflow suitable, however I appreciate any improvements and recommendations from your side!
Start by locating the .eds file from the manufacturer. The image show this in the B&R Automation Studio Programming Environment
Open the file in a eds. Editor. I found the free Vector CANEds Editor very useful. Delete all RxPODs and RxPDO mappings that you don’t need.
Assign the needed Data Type (e.g. INTEGER16) and Channel Name (“1 Byte In (1)”).
Add the necessary PDOs and PDO mapping from the database. (This might actually be a bug, but if you just edit the PDOs without deleting and recreating them, I always receive error messages)
Map the Date to the Channels
Don't forget to write the number of channels in the first entry (in this image: 1601sub0)
Check the eds file for Errors (press F5) and copy&paste the eds file to the original location point 1.)
Add the PLC Client device in Automation Studio and you should see the correct mappings.
(PS: I couldn't make the images smaller ... any recommendations about formating this question are welcome!)

Event Processing - Module channel

Could you explain what is the usage of Modules with select query?
For example if I write (as shown on this page https://cumulocity.com/guides/users-guide/administration/):
select * from MeasurementCreated
Is it useful to get real time notifications by subscribing of the related channel? Is the module reachable by an angularJs Module? Can this module be used in other CEL statements?
Just selecting data without putting it into another stream can make sense in the case you want to make this data available via a real-time channel to some external application (this could be of course AngularJs).
Take a look at this section in the docs: http://cumulocity.com/guides/reference/real-time-statements/#notifications
This very one example though does not make a lot of sense because raw measurement data is already provided on a real-time channel
http://www.cumulocity.com/guides/reference/measurements/#notifications
As for the second part of the question:
Yes it is possible to communicate with other modules within your tenant.
e.g. You can declare some stream in module a and it will be available in module b.

noflo-ui: Load and save projects/graphs/components from external database or api

I'm trying to create a custom build of noflo-ui that is effectively only a graph editor. Don't need it to connect to any runtimes.
I'm struggling to find where I can inject this code as it appears part of noflo-ui is written in noflo itself and I cannot find the scripts for those pieces.
For example, in graphs/main.fbp, there is this line:
'user,main,project,github,runtime,context' -> ROUTES Dispatch
Three questions on this:
Where is the source behind the Dispatch component?
If I add my own interface elements to Load data from an external api, where would be the best place to inject that data?
I see a lot of event driven code, so I'm guessing I would add a new polymer element, do my ajax call, the emit or fire something. I believe this is what happens when connecting to a noflo-nodejs runtime; I've traced the connection to line 51312 in a built noflo-ui.js
return port.send({
componentDefinition: definition
});
... but I can't figure out where it goes past here. A port on the main.fbp graph? As per my 1st question, I cannot find the source behind these core graphs.
And this leads to my last question
The code I pasted above from noflo-ui, I cannot find this code anywhere pre-build. I even searched the entire project tree for "componentDefinition: definition". Where is this coming from?
Any pointers on this would be greatly appreciated! Thanks
The FBP runtime protocol is the primary extension point of noflo-ui. You can implement a "runtime" which just provides components and graphs (for instance from a database), without a way to run these.
A network:persist message to let the UI indicate that "this is a good point to save the graphs" has been specced but is currently not implemented. For now you can just autosave latest state.

In Emacs, is there a way to Call Interactive Function non-interactively from init.el?

Is it possible, in general, to call an interactive function from init.el, if it's parameters are known?
Let me give a concrete example: In the sql package, there is a interactive function sql-connect.
When invoked as
M-x sql-connect
it asks for Connection in the minibuffer. Answering
my-mysql-localhost-connection1
opens an SQL buffer with mysql prompt which it what I want.
I would like to start the connection in a SQL buffer on Emacs startup. But adding, in my init.el:
(sql-connect 'my-mysql-localhost-connection1)
does not do anything. Is what I am trying to achieve possible in this case, and for a general interactive function (which parameters are known)
Thanks
In general:
Yes, and you can use repeat-complex-command (C-xM-:) after the interactive call to find out what the arguments ended up looking like. This is a useful approach to remember, because sometimes there are hidden manipulations in an interactive form which can transform the user's input into something different1.
That doesn't necessarily give you the best arguments to use in a non-interactive call (that will always be dependent on the function in question), but it's probably the best place to start if you're unsure how to translate the one to the other2.
1 align-regexp is a good example of this.
2 Assuming that you've at least read the docstring for the function in question -- it's not uncommon for a given interactive command to be the wrong thing to call in a non-interactive context, and the function help is usually good enough to point this out.
The answer to your general question is yes: you can invoke an interactive function from code, instead of using M-x.
Wrt your more specific question:
You should not need to call the function interactively (i.e., no need to use call-interactively) unless for some reason you really want to invoke it interactively for some reason (e.g., to prompt the user). ;-)
Just call it by supplying the necessary arguments, and you should be OK. IOW this should work:
(sql-connect 'my-mysql-localhost-connection1)
But the doc says that the CONNECTION arg must define actual connection settings, per sql-connection-alist. Check that my-mysql-localhost-connection1 does follow sql-connection-alist in defining connection settings properly so that the user is not prompted for any login parameters.

Notifications in wxWidgets?

I'm working on a small application using C++/wxWidgets, where several parts of the GUI need to be updated based on e.g. received UDP datagrams. More specifically, a secondary thread tries to keep a list of available "clients" in the network (which may come and go away) and e.g. corresponding comboboxes in the UI need to be updated to reflect the changes.
The documentation mentions that for this kind of thing EVT_UPDATE_UI would be a good choice. As far as I can understand from the sparse documentation, this event is sent automatically by the system and provides some support for assisted UI change.
However, I'd feel more comfortable using a more direct approach, i.e. where e.g. a window object could register/subscribe to receive notifications (either events or callbacks) upon particular events and another part of the code is sending out these notifications when required. I could do this in C++ using my own code, however I guess if wxWidgets already supports something like that, I should make use of it. However I haven't found anything in that regards.
So, the question is: does wxWidgets support this kind of notification system (or similar alternatives) or would I be best served coding my own?
AFAIK there is nothing directly usable in wxWidgets, but doing it on your own seems easy.
What I would do:
Create a wxEvtHandler-descendent class to hold the list of available "clients" in the network. Let this class have a wxCriticalSection, and use a wxCriticalSectionLocker for that in all methods that add or delete "clients".
Create a worker thread class by inheriting wxThread to handle your UDP datagrams, using blocking calls. The thread should directly call methods of the client list object whenever a client has to be added or removed. In these methods update the list of clients, and ::wxPostEvent() an event to itself (this will execute the whole notification calls in the main GUI thread).
Handle the event in the client list class, and notify all listeners that the list of clients has changed. The observer pattern seems to me a good fit. You could either call a method of all registered listeners directly, or send a wxCommandEvent to them.
Have you tried calling Update() on the widget(s) that change? Once you update the contents of the combo box, call Update(), and the contents should update.