-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample2.pyx
63 lines (56 loc) · 2.24 KB
/
sample2.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
#
# Copyright © 2016 Associated Universities, Inc. Washington DC, USA.
#
# This file is part of vysmaw.
#
# vysmaw is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# vysmaw is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# vysmaw. If not, see <http://www.gnu.org/licenses/>.
#
from vysmaw cimport *
from libc.stdint cimport *
from libc.stdlib cimport *
from cy_vysmaw cimport *
import cy_vysmaw
import sys
# A predicate that selects no spectra. The "pass_filter" array elements _must_
# be assigned values, as they are always uninitialized at function entry.
cdef void cb(const char *config_id, const uint8_t *stns,
uint8_t bb_idx, uint8_t bb_id, uint8_t spw, uint8_t pol,
const vys_spectrum_info *infos, uint8_t num_infos,
void *user_data, bool *pass_filter) nogil:
for i in range(num_infos):
pass_filter[i] = False
return
# Use configuration file if provided on command line, otherwise use defaults.
cdef Configuration config
if len(sys.argv) > 1:
config = cy_vysmaw.Configuration(sys.argv[1])
else:
config = cy_vysmaw.Configuration()
# Allocate client resources
handle, consumer = config.start(cb, NULL)
# Immediately shut down client resources, since we don't intend to receive
# any spectra.
handle.shutdown()
# Messages should always be retrieved from the consumer queue until an
# EndMessage appears; here, since no spectra are selected by the callback,
# and the handle shutdown method has already been called, the only message
# should be the EndMessage.
msg = consumer.pop()
assert(isinstance(msg, cy_vysmaw.EndMessage))
# display the message
print(str(msg))
# unref the message; this would happen automatically when the msg variable
# is reclaimed, but it's good practice to do this explicitly with every
# message as soon as possible.
msg.unref()