summaryrefslogtreecommitdiffstats
path: root/binding/radio-binding.c
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2020-12-06 16:17:51 -0500
committerScott Murray <scott.murray@konsulko.com>2020-12-06 16:24:43 -0500
commit47d61abc94a8c7140c3950329890d0f71f5714eb (patch)
tree23458664ae2611950d75330d15b88154cf3ceff3 /binding/radio-binding.c
parentd4fb6eb7a4648b74f930af667f9231226e4ce208 (diff)
Rework hardware probing and RTL-SDR helper startup
The lazy startup of the separate helper program for the RTL-SDR backend on playback start was incorrect with respect to the expected behavior the frequency setting verbs. This was not visible during usage by the radio application, but was triggering failures in several tests in the pyagl binding wrapper test suite. To facilitate starting the helper during backend initialization, the probing part of the backend "init" has been split into a separate "probe" function, and all backends have been updated to reflect this change. Logic has been added to enforce that "init" is only called after "probe" has succeeded for a backend, and a comment has been added to radio_impl.h to document this intended behavior. Bug-AGL: SPEC-3717 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Ic37331a92bae7cc01ee448e69894fa5f49d08a74
Diffstat (limited to 'binding/radio-binding.c')
-rw-r--r--binding/radio-binding.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index 3b8561d..8b5559c 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -678,36 +678,41 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object
static int init(afb_api_t api)
{
- // Look for RTL-SDR USB adapter
+ // Probe for radio backends
radio_impl_ops = &rtlsdr_impl_ops;
- int rc = radio_impl_ops->init();
+ int rc = radio_impl_ops->probe();
if(rc != 0) {
// Look for Kingfisher Si4689
radio_impl_ops = &kf_impl_ops;
- rc = radio_impl_ops->init();
+ rc = radio_impl_ops->probe();
}
if(rc != 0) {
radio_impl_ops = &tef665x_impl_ops;
- rc = radio_impl_ops->init();
+ rc = radio_impl_ops->probe();
}
if (rc != 0) {
radio_impl_ops = &null_impl_ops;
- rc = radio_impl_ops->init();
+ rc = radio_impl_ops->probe();
}
if (rc != 0) {
- // We don't expect the null implementation to fail init, but just in case...
+ // We don't expect the null implementation to fail probe, but just in case...
AFB_API_ERROR(afbBindingV3root, "No radio device found, exiting");
+ return rc;
}
- if(rc == 0) {
- AFB_API_NOTICE(afbBindingV3root, "%s found\n", radio_impl_ops->name);
- radio_impl_ops->set_frequency_callback(freq_callback, NULL);
- if(radio_impl_ops->set_rds_callback)
- {
- radio_impl_ops->set_rds_callback(rds_callback);
- }
- } else {
+ // Try to initialize detected backend
+ rc = radio_impl_ops->init();
+ if(rc < 0) {
+ AFB_API_ERROR(afbBindingV3root,
+ "%s initialization failed\n",
+ radio_impl_ops->name);
return rc;
}
+ AFB_API_NOTICE(afbBindingV3root, "%s found\n", radio_impl_ops->name);
+ radio_impl_ops->set_frequency_callback(freq_callback, NULL);
+ radio_impl_ops->set_frequency_callback(freq_callback, NULL);
+ if(radio_impl_ops->set_rds_callback) {
+ radio_impl_ops->set_rds_callback(rds_callback);
+ }
rc = afb_daemon_require_api("signal-composer", 1);
if (rc) {