summaryrefslogtreecommitdiffstats
path: root/binding/radio-binding.c
diff options
context:
space:
mode:
Diffstat (limited to 'binding/radio-binding.c')
-rw-r--r--binding/radio-binding.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index 715ec35..3f34150 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -23,12 +23,15 @@
#include <unistd.h>
#include <sys/types.h>
#include <json-c/json.h>
+
#include <afb/afb-binding.h>
#include "radio_impl.h"
#include "radio_impl_rtlsdr.h"
#include "radio_impl_kingfisher.h"
+#define RADIO_MODE_NAME_MAXLEN 8
+
static radio_impl_ops_t *radio_impl_ops;
static struct afb_event freq_event;
@@ -84,6 +87,30 @@ static void frequency(struct afb_req request)
afb_req_success(request, ret_json, NULL);
}
+/* @brief Get RDS information
+*
+* @param struct afb_req : an afb request structure
+*
+*/
+static void rds(struct afb_req request)
+{
+ json_object *ret_json;
+ char * rds;
+
+ if (radio_impl_ops->get_rds_info == NULL) {
+ afb_req_fail(request, "failed", "not supported");
+ return;
+ }
+
+ ret_json = json_object_new_object();
+
+ rds = radio_impl_ops->get_rds_info();
+ json_object_object_add(ret_json, "rds", json_object_new_string(rds?rds:""));
+ free(rds);
+
+ afb_req_success(request, ret_json, NULL);
+}
+
/*
* @brief Get (and optionally set) frequency band
*
@@ -364,7 +391,7 @@ static void stereo_mode(struct afb_req request)
const char *value = afb_req_value(request, "value");
int valid = 0;
radio_stereo_mode_t mode;
- char mode_name[4];
+ char mode_name[RADIO_MODE_NAME_MAXLEN];
if(value) {
if(!strcasecmp(value, "mono")) {
@@ -396,7 +423,7 @@ static void stereo_mode(struct afb_req request)
}
ret_json = json_object_new_object();
mode = radio_impl_ops->get_stereo_mode();
- sprintf(mode_name, "%s", mode == MONO ? "mono" : "stereo");
+ snprintf(mode_name, RADIO_MODE_NAME_MAXLEN, "%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);
}
@@ -448,6 +475,7 @@ static void unsubscribe(struct afb_req request)
static const struct afb_verb_v2 verbs[]= {
{ .verb = "frequency", .session = AFB_SESSION_NONE, .callback = frequency, .info = "Get/Set frequency" },
{ .verb = "band", .session = AFB_SESSION_NONE, .callback = band, .info = "Get/Set band" },
+ { .verb = "rds", .session = AFB_SESSION_NONE, .callback = rds, .info = "Get RDS information" },
{ .verb = "band_supported", .session = AFB_SESSION_NONE, .callback = band_supported, .info = "Check band support" },
{ .verb = "frequency_range", .session = AFB_SESSION_NONE, .callback = frequency_range, .info = "Get frequency range" },
{ .verb = "frequency_step", .session = AFB_SESSION_NONE, .callback = frequency_step, .info = "Get frequency step" },