aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-07-11 17:40:07 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-07-17 10:50:07 +0200
commit7db8c3df0b4abdb0bb643ca3220b3bfbc9a4db83 (patch)
treed04fcff3d5519779218b4c4ab49a1870f829cfeb
parentb3303810b1edbe0a9bc7c066fb6c4ea96cb65c12 (diff)
added api verb for RDS information
Added a verb to retrieve the RDS information. Notice that it is only supported on the kingfisher implementation. Change-Id: I0e2a830ff77154eb8cbb780bb599fb49f71a5b1c Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
-rw-r--r--binding/radio-binding.c32
-rw-r--r--binding/radio_impl.h2
-rw-r--r--binding/radio_impl_kingfisher.c40
3 files changed, 71 insertions, 3 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" },
diff --git a/binding/radio_impl.h b/binding/radio_impl.h
index f745f12..49efe24 100644
--- a/binding/radio_impl.h
+++ b/binding/radio_impl.h
@@ -76,6 +76,8 @@ typedef struct {
void (*set_stereo_mode)(radio_stereo_mode_t mode);
+ char * (*get_rds_info)(void);
+
} radio_impl_ops_t;
#endif /* _RADIO_IMPL_H */
diff --git a/binding/radio_impl_kingfisher.c b/binding/radio_impl_kingfisher.c
index d88176d..e183c1b 100644
--- a/binding/radio_impl_kingfisher.c
+++ b/binding/radio_impl_kingfisher.c
@@ -250,6 +250,43 @@ static void kf_set_frequency_callback(radio_freq_callback_t callback,
freq_callback_data = data;
}
+static char * kf_get_rds_info(void) {
+ char cmd[SI_CTL_CMDLINE_MAXLEN];
+ char line[SI_CTL_OUTPUT_MAXLEN];
+ char * rds = NULL;
+ FILE *fp;
+
+ if (scanning)
+ goto done;
+
+ snprintf(cmd, SI_CTL_CMDLINE_MAXLEN, "%s /dev/i2c-12 0x65 -m", SI_CTL);
+ fp = popen(cmd, "r");
+ if(fp == NULL) {
+ fprintf(stderr, "Could not run: %s!\n", cmd);
+ goto done;
+ }
+ // Look for "Name:" in output
+ while (fgets(line, SI_CTL_OUTPUT_MAXLEN, fp) != NULL) {
+
+ char* nS = strstr(line, "Name:");
+ char * end;
+ if (!nS)
+ continue;
+
+ end = nS+strlen("Name:");
+ /* remove the trailing \n */
+ end[strlen(end)-1] = '\0';
+
+ rds = strdup(end);
+ break;
+ }
+
+ // Make sure si_ctl has finished
+ pclose(fp);
+done:
+ return rds;
+}
+
static radio_band_t kf_get_band(void)
{
return BAND_FM;
@@ -417,5 +454,6 @@ radio_impl_ops_t kf_impl_ops = {
.scan_start = kf_scan_start,
.scan_stop = kf_scan_stop,
.get_stereo_mode = kf_get_stereo_mode,
- .set_stereo_mode = kf_set_stereo_mode
+ .set_stereo_mode = kf_set_stereo_mode,
+ .get_rds_info = kf_get_rds_info
};