Cool! By the way, if you know the samples being processed by your block have a sampling
rate, you can also use `nitems_written(0)` to check how many items have been passed by. It
should look a bit like this:
in __init__:
def __init__(self):
gr.sync_block.__init__(
self,
name='GPS Tagger',
in_sig=[np.complex64],
out_sig=[np.complex64]
)
gpsd.connect()
self.tag_interval = interval # you might want to add a parameter to the
# __init__(self,…) method called interval, so you
get a block
# parameter
self.next_tag = 0 # add the first tag immediately
self.key = pmt.intern("gps") # never going to change
in work:
# Doing `while` instead of `if`, so that we really add 2 tags if we're facing
two
# intervals worth of samples. Depends on whether you want that or your original
behaviour.
# Both seem sensible in some applications. If you just want one position tag
(the
# position is not going to change in between these two calls to add_a_tag
anyways), just
# convert back to `if`.
def work(self, input_items, output_items):
while self.nitems_written(0) + len(output_items[0]) >= self.next_tag:
self.add_a_tag(self.next_tag)
self.next_tag += self.tag_interval
output_items[0][:] = input_items[0]
return len(output_items[0])
def add_a_tag(self, when):
try:
packet = gpsd.get_current()
value = (packet.position()[0], packet.position()[1])
except gpsd.NoFixError:
value = (0.0, 0.0)
except Exception as exception:
print(f"GPS ERROR ({exception})")
value = (0.0, 0.0)
print(value)
value = pmt.to_pmt(value)
self.add_item_tag(0, when, self.key, value)
If you have GNU Radio 3.10.5.0 or later, you can replace your `print` calls with
`self.logger.error(f"GPS ERROR ({exception})")`, for example. (Use an appropriate logging
level for error/warning/info/debug messages, e.g. `print(value)` might be something you
don't want to see on your console all the time, so `self.logger.debug(f"position @{where}:
{value}")` or so)
Cheers, and keep up the good work!
Marcus
On 07.05.23 13:53, Fabian Schwartau wrote:
Doing it the way Marcus M. described wasn actually not that complicated as I expected. I
have a small "Embedded Python Block" that does more or less what I need. The file is
attached, if anyone else needs this :)
The error handling is a bit rough and there are probably many things to improve on, but
its a starting point.
Am 07.05.23 um 13:09 schrieb Fabian Schwartau:
Hi again,
as I described earlier, I am now using a "Tags Strobe" block to periodically tag the
data with the current gps coordinates. Within the "Tag Strobes" I use a function call to
create the value:
pmt.to_pmt(gps.get_current_gps_position())
And this function is defined in a "Python Module" block.
But it seems that the function is only called once at startup and then never again.
Which is quite useless in my case. Is that correct? Is there any other easy way to get
the gps data into a stream as tags within GRC? I am not familiar with programming my own
blocks and I don't see myself capable of doing what Marcus M. suggested earier, without
spending a considerable amount of time.
Best,
Fabian
Am 05.05.23 um 09:58 schrieb Marcus Müller:
Hi Fabian,
it's interleaved real, imag, real, imag. If you used dtype=np.complex64 instead of
float32 (and then not double the count), you'd get it interpreted exactly that way :)
Cheers,
Marcus
On 04.05.23 19:38, Fabian Schwartau wrote:
Sorry again, never mind... I found the problem.
The source code for reading the data does not include the fact that I am reading
complex data and also three streams. Change the one line to:
data=np.fromfile(file=fh, dtype=np.float32, count=3*2*int(header_info['nitems']),
sep='', offset=0)
and everything seems to work as expected. Now I just have to figure out how the data
is ordered in that blob ;)
Best,
Fabian
Am 04.05.23 um 19:19 schrieb Fabian Schwartau:
Hi everyone,
I think I got hit by https://github.com/gnuradio/gnuradio/issues/5568.
Exactly the same error message. Is there any update on that issue or a
workaround?
Attached are my files.
Best,
Fabian
Am 03.05.23 um 21:01 schrieb Marcus D. Leech:
On 03/05/2023 14:59, Fabian Schwartau wrote:
Sorry, forget it. Wrong sink...
You probably want:
https://wiki.gnuradio.org/index.php/File_Meta_Sink
Am 03.05.23 um 20:52 schrieb Fabian Schwartau:
OK, I think I found an easier way (at least for me), without having to write my
own module - never done that.
I used the "Tags Strobe" block in combination with the "Python Module" for my
gps_get_position() function.
Anyway, where can I find a definition of the format of the "Tagged File Sink"? I
need to read this with antoher program, without gnuradio, but in python.
Best,
Fabian
Am 03.05.23 um 20:04 schrieb Marcus Müller:
Hi Fabian,
I'd write a block that copies a stream in- to output. It might query gpsd every
time the work() function is called, or have a FIFO into which data from gspd is
being pushed by a separate thread (or by reading from a socket or however gspd
works, I must admit I'm not sure).
You then take that info, and encode the long, lat, uncertainty as (double,
double, double) PMT tuple. You then use add_item_tag to add that PMT to the first
sample in your output buffer.
You'd feed the result into a metadata file sink block: That saves things in a
serialized format ready for retrieval.
Best,
Marcus
On 5/3/23 19:52, Fabian Schwartau wrote:
Hi everyone,
I am trying to record some data from an SDR and would like to sync/tag the data
with the current gps position from gpsd. I am kind of stuck and don't know how a
possible solution for that might look like in grc.
I have a python function that gets the current position as a tuple, but how do I
get this into my data stream, which I would like to write to a CSV file or similar?
I am not asking for a solution of my problem, just point me in the right
direction ;)
Best,
Fabian