summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--binding/radio-binding.c28
-rw-r--r--binding/radio_impl_null.c4
3 files changed, 28 insertions, 7 deletions
diff --git a/README.md b/README.md
index 2155649..90184b7 100644
--- a/README.md
+++ b/README.md
@@ -21,12 +21,13 @@ respective audio stream.
| scan_start | start scanning for station | *Request:* {"direction": "forward" or "backward"} |
| scan_stop | stop scanning for station | |
| stereo_mode | get/set stereo or mono mode | *Request:* {"value": "stereo" or "mono"} |
+| rds | get current RDS data | |
## Events
### frequency Event JSON Response
-JSON response has a single field **frequency** which is the currently tuned frequency.
+JSON response has a single field **value** which is the currently tuned frequency.
### station_found Event JSON Response
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index 34eb53e..45e8ecb 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -90,11 +90,26 @@ static void frequency(afb_req_t request)
if(value) {
char *p;
+ radio_band_t band;
+ uint32_t min_frequency;
+ uint32_t max_frequency;
+ uint32_t step;
+
frequency = (uint32_t) strtoul(value, &p, 10);
if(frequency && *p == '\0') {
+ band = radio_impl_ops->get_band();
+ min_frequency = radio_impl_ops->get_min_frequency(band);
+ max_frequency = radio_impl_ops->get_max_frequency(band);
+ step = radio_impl_ops->get_frequency_step(band);
+ if(frequency < min_frequency ||
+ frequency > max_frequency ||
+ (frequency - min_frequency) % step) {
+ afb_req_reply(request, NULL, "failed", "Invalid frequency");
+ return;
+ }
radio_impl_ops->set_frequency(frequency);
} else {
- afb_req_reply(request, NULL, "failed", "Invalid scan direction");
+ afb_req_reply(request, NULL, "failed", "Invalid frequency");
return;
}
}
@@ -104,11 +119,12 @@ static void frequency(afb_req_t request)
afb_req_reply(request, ret_json, NULL, NULL);
}
-/* @brief Get RDS information
-*
-* @param afb_req_t : an afb request structure
-*
-*/
+/*
+ * @brief Get RDS information
+ *
+ * @param afb_req_t : an afb request structure
+ *
+ */
static void rds(afb_req_t request)
{
json_object *ret_json;
diff --git a/binding/radio_impl_null.c b/binding/radio_impl_null.c
index 8c28bca..a90835b 100644
--- a/binding/radio_impl_null.c
+++ b/binding/radio_impl_null.c
@@ -120,6 +120,10 @@ static uint32_t null_get_frequency(void)
static void null_set_frequency(uint32_t frequency)
{
+ if(frequency < known_fm_band_plans[bandplan].min ||
+ frequency > known_fm_band_plans[bandplan].max)
+ return;
+
current_frequency = frequency;
if(freq_callback)