I am new to GNUradio and I am making a FM Receiver. I am recording the data into the file sink. But I need the data of just 1 millisecond. How can I specify this time so that my flowgraph automatically stop after this time?
I also read some solutions regarding the calling of stop() and start() methods and I tried that in GRC generated python file also but it didn't work for me, may be I made a mistake.
Simply use the "Head" block to stop after passing the 1msĀ·sample rate of samples.
Related
I am using C in Objective C and I want to capture stdout to UIView from Console.
Here is the line I'm talking about:
print(stdout, v=toplevel_eval(v));
Other than you are writing in C I have no idea how much you know about C, "Unix" and Cocoa I/O - so some of this you may already know.
Here is one possible solution, it looks more complicated than it is.
Reading:
You need to understand the system calls pipe, dup2 and read.
You need to understand the GCD function dispatch_async and how to obtain a GCD queue.
pipe and dup2 are often used in conjunction with fork and exec to launch a process and write/read to/from that process standard input/output. What you will be doing uses some of the same basic ideas so looking up examples of this common pattern will help you understand how these calls work. Here are some notes from a University: Pipe, Fork, Exec and Related Topics.
Outline:
Using dispatch_async schedule a block to handle the reading and writing of the data. The block will:
Use pipe To create a pipe and dup2 To connect stdout - file descriptor 1 - it.
Enter a loop which uses read to obtain the available data from the pipe. Data read will be in a byte array.
Within the loop convert the read bytes into an NSString
Within the loop append that string to your view - you must do this on the main thread as it involves the UI, and you can do that using another dispatch_async specifying the main queue.
That is it. Your block will now execute concurrently in the background reading whatever your C code writes to the standard output and adding it to your view.
If you get stuck you can ask a new question showing the code you have written and describing what doesn't work.
HTH
In my extension, I need to write a huge file (say around 20 gigs) to the disk. Currently I am doing it in the main thread, but file creation is very expensive operation. I was about to move the whole file creation process to a ChromeWorker, but based on https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers I cannot have access to the nsiFile from a ChromeWorker.
So my questions are:
1. Is it possible to access Cc, Ci, and Cu from within a ChromeWorker?
2. If not what would be the most efficient way to create and fill large files in Firefox. Note that I need to write the file based on segments and offsets (Ci.nsISeekableStream).
It's not possible to access nsIFile from ChromeWorker. But nsIFile is horrible synchronus option.
Go with OS.File: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/OSFile.jsm
On that page go to the link for usage on workers: https://developer.mozilla.org/docs/Mozilla/JavaScript_code_modules/OSFile.jsm/OS.File_for_workers
On the mainthread os.file returns promises.
In worker they are synchronus. Wrap your os.file functions in worker with a try-catch, as when an error occurs, (like os.file.remove with option of ignoreAbsent set to false) then the catch will hold the OS.File.Error object.
Great move to ChromeWorker btw! I'm a huge fan of ChromeWorkers. I wrote a simple example of jsm using chromeworker here: https://github.com/Noitidart/jpm-chromeworker
For segments, you'll have to OS.File.open and then on the return value do a .setPosition() then you can read certain number of bytes from that position, or write, or whatever. Its awesome stuff. OS.File is the new way and the recommended way to do file operations. Its been around awhile now though since like Firefox 29 or before that.
I have a rails app that needs to make use of a Javascript library on the server. Up until now I have been running system commands from rails to nodejs whenever this is necessary. However, I have a particularly computationally intensive task that has made it necessary to cache data to speed it up. I also have to pass large inputs to the node program. As a result I've hit the buffer size of inputs to the node program. I am currently just sending it to separate node processes multiple times in chunks small enough to fit in the buffer, but this is causing performance problems because I now no longer get to take advantage of caching over as many runs. I would like to use a pipe to do this, but my pipe hits the buffer as well, and I don't know how to empty it. So far I have...
#ruby file
output=[]
node_pipe=IO.popen("nodejs /home/user/node_program.js","w+")
10_000.times do |time|
node_pipe.write("a lot of stuff")
#here I would like to read contents and push contents to output array but still be
#able to write to the same process in the next loop to take advantage of the cache
end
//node_program.js
var input=process.stdin;
var cache={};
input.resume();
input.on('data',function(chunk){
cache[chunk]=library_function(chunk);
console.log(String(other_library_function(chunk)));
}
Any suggestions?
`
With fconfigure you can get and set channel options. -buffering specifies the type of buffering, and by default it is line for stdin.
Is there a way to check if the buffer at stdin is empty or not?
Please see this question: How to check if stdin is pending in TCL?
Obviously you could set the channel mode to non-blocking and read from it. If the read returns 0 length then nothing was available. However, I suspect you mean to test for data present but not a complete line given your mentioning of the line buffering there. The fblocked command tests a channel for this. See fblocked(1) for the details but for a line buffered channel this lets you know that an incomplete line is present.
Another useful command when reading stdin, if you are reading interactive script commands is to use the info complete command. With this you can just accumulate lines until info complete returns true then evaluate the whole buffer in one.
You can check Tcl's input buffer with chan pending input stdin (requires at least Tcl 8.5). This does not indicate whether the OS has anything in its buffers though; those are checked by trying to read the data (gets or read) or by using a script that triggers off of a readable fileevent, when at least one byte is present. (Well, strictly what is actually promised is that an attempt to read a single byte won't block, but it could be because of an error condition which causes immediate failure. That's the semantics of how OS-level file descriptor readiness works.)
The -buffering option only affects output channels; it's useless on stdin (or any other read-only channel) and has no effect at all. Really. (It is, however, too much trouble to remove.)
I know this is an old question but it sparked some research on my end and I found a function called fileevent which calls an event handler when the stream, i.e. stdin, has something in it that can be read. It may be helpful.
Source: http://wiki.tcl.tk/880
how can i stop or freeze the kernel32 event? for example stop the copy file??
You can't stop the kernel from copying files. If you want to stop the user from copying files, then you need to write a hook that implements the ICopyHook interface.
I'm not sure what exactly you want to do, but if you are using CopyFile winapi, then you should look at CopyFileEx
You can pass there lpProgressRoutine - pointer to your function, and then return from it PROGRESS_CANCEL when you want stop your file copy operation.
Also, starting from Vista, you can cancel sync. IO operations from different thread by CancelSynchronousIo, so you should be able to stop CopyFile operation.