aboutsummaryrefslogtreecommitdiffstats
path: root/binding/radio-binding.c
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2017-12-21 20:13:52 -0500
committerScott Murray <scott.murray@konsulko.com>2017-12-21 20:13:52 -0500
commit62518e9fdefa82a8d454e3dbcc28fd2efdc08fa0 (patch)
tree71426b7560d371983b9bcaa8f324b80372922aa5 /binding/radio-binding.c
parent55fddbb3186412f61fb8b8ea57b76a74f392d30b (diff)
Add conditionally compilable support for the Si4689 radio on the M3ULCB Kingfisher infotainment board. The codebase has been refactored to allow multiple radio implementations, and when Kingfisher support is enabled, the binding will first look for a USB RTL-SDR adapter, then fallback to the Kingfisher Si4689 if one is not found. This allows easily switching to a RTL-SDR adapter if this initial Kingfisher support encounters issues. The back end implementation relies on a patched version of the "si_ctl" utility from Cogent Embedded's Kingfisher BSP changes. The modifications to it add FM band plan selection and scanning threshold tweaking for poor radio environments. Audio output is achieved by looping the radio's PulseAudio source to the appropriate sink depending on 4A or non-4A operation. For 4A compatibility, the PulseAudio source is created if it does not exist, which currently is the case due to PulseAudio's udev module being disabled when 4A is enabled. Additionally, the FM band plan for Japan has been corrected to go to 95 MHz, and a README.md file has been added documenting the optional configuration that can be done via /etc/xdg/AGL.conf for band plan selection and scanning sensitivity. Change-Id: I204906fed741d917fc3b8be962deadb4e59989db Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'binding/radio-binding.c')
-rw-r--r--binding/radio-binding.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index f9b7e34..63c2491 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -29,6 +29,12 @@
#include <afb/afb-service-itf.h>
#include "radio_impl.h"
+#include "radio_impl_rtlsdr.h"
+#ifdef HAVE_KINGFISHER
+#include "radio_impl_kingfisher.h"
+#endif
+
+static radio_impl_ops_t *radio_impl_ops;
static struct afb_event freq_event;
static struct afb_event scan_event;
@@ -71,14 +77,14 @@ static void frequency(struct afb_req request)
char *p;
frequency = strtoul(value, &p, 10);
if(frequency && *p == '\0') {
- radio_impl_set_frequency(frequency);
+ radio_impl_ops->set_frequency(frequency);
} else {
afb_req_fail(request, "failed", "Invalid scan direction");
return;
}
}
ret_json = json_object_new_object();
- frequency = radio_impl_get_frequency();
+ frequency = radio_impl_ops->get_frequency();
json_object_object_add(ret_json, "frequency", json_object_new_int((int32_t) frequency));
afb_req_success(request, ret_json, NULL);
}
@@ -119,14 +125,14 @@ static void band(struct afb_req request)
}
}
if(valid) {
- radio_impl_set_band(band);
+ radio_impl_ops->set_band(band);
} else {
afb_req_fail(request, "failed", "Invalid band");
return;
}
}
ret_json = json_object_new_object();
- band = radio_impl_get_band();
+ band = radio_impl_ops->get_band();
sprintf(band_name, "%s", band == BAND_AM ? "AM" : "FM");
json_object_object_add(ret_json, "band", json_object_new_string(band_name));
afb_req_success(request, ret_json, NULL);
@@ -174,7 +180,7 @@ static void band_supported(struct afb_req request)
ret_json = json_object_new_object();
json_object_object_add(ret_json,
"supported",
- json_object_new_int(radio_impl_band_supported(band)));
+ json_object_new_int(radio_impl_ops->band_supported(band)));
afb_req_success(request, ret_json, NULL);
}
@@ -220,8 +226,8 @@ static void frequency_range(struct afb_req request)
return;
}
ret_json = json_object_new_object();
- min_frequency = radio_impl_get_min_frequency(band);
- max_frequency = radio_impl_get_max_frequency(band);
+ min_frequency = radio_impl_ops->get_min_frequency(band);
+ max_frequency = radio_impl_ops->get_max_frequency(band);
json_object_object_add(ret_json, "min", json_object_new_int((int32_t) min_frequency));
json_object_object_add(ret_json, "max", json_object_new_int((int32_t) max_frequency));
afb_req_success(request, ret_json, NULL);
@@ -268,7 +274,7 @@ static void frequency_step(struct afb_req request)
return;
}
ret_json = json_object_new_object();
- step = radio_impl_get_frequency_step(band);
+ step = radio_impl_ops->get_frequency_step(band);
json_object_object_add(ret_json, "step", json_object_new_int((int32_t) step));
afb_req_success(request, ret_json, NULL);
}
@@ -281,7 +287,7 @@ static void frequency_step(struct afb_req request)
*/
static void start(struct afb_req request)
{
- radio_impl_start();
+ radio_impl_ops->start();
afb_req_success(request, NULL, NULL);
}
@@ -293,7 +299,7 @@ static void start(struct afb_req request)
*/
static void stop(struct afb_req request)
{
- radio_impl_stop();
+ radio_impl_ops->stop();
afb_req_success(request, NULL, NULL);
}
@@ -335,7 +341,7 @@ static void scan_start(struct afb_req request)
afb_req_fail(request, "failed", "Invalid direction");
return;
}
- radio_impl_scan_start(direction, scan_callback, NULL);
+ radio_impl_ops->scan_start(direction, scan_callback, NULL);
afb_req_success(request, NULL, NULL);
}
@@ -347,7 +353,7 @@ static void scan_start(struct afb_req request)
*/
static void scan_stop(struct afb_req request)
{
- radio_impl_scan_stop();
+ radio_impl_ops->scan_stop();
afb_req_success(request, NULL, NULL);
}
@@ -387,14 +393,14 @@ static void stereo_mode(struct afb_req request)
}
}
if(valid) {
- radio_impl_set_stereo_mode(mode);
+ radio_impl_ops->set_stereo_mode(mode);
} else {
afb_req_fail(request, "failed", "Invalid mode");
return;
}
}
ret_json = json_object_new_object();
- mode = radio_impl_get_stereo_mode();
+ mode = radio_impl_ops->get_stereo_mode();
sprintf(mode_name, "%s", mode == MONO ? "mono" : "stereo");
json_object_object_add(ret_json, "mode", json_object_new_string(mode_name));
afb_req_success(request, ret_json, NULL);
@@ -467,11 +473,20 @@ static int init()
freq_event = afb_daemon_make_event("frequency");
scan_event = afb_daemon_make_event("station_found");
- rc = radio_impl_init();
+ // Look for RTL-SDR USB adapter
+ radio_impl_ops = &rtlsdr_impl_ops;
+ rc = radio_impl_ops->init();
+#ifdef HAVE_KINGFISHER
+ if(rc != 0) {
+ // Look for Kingfisher Si4689
+ radio_impl_ops = &kf_impl_ops;
+ rc = radio_impl_ops->init();
+ }
+#endif
if(rc == 0) {
- radio_impl_set_frequency_callback(freq_callback, NULL);
+ printf("%s found\n", radio_impl_ops->name);
+ radio_impl_ops->set_frequency_callback(freq_callback, NULL);
}
-
return rc;
}