aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorManuel Bachmann <manuel.bachmann@iot.bzh>2016-05-23 16:39:52 +0200
committerManuel Bachmann <manuel.bachmann@iot.bzh>2016-05-23 16:39:52 +0200
commitbc54194e4d9ff8f25f7bbb1561b84bee074d8262 (patch)
tree2c5c614cd6c83e8f1548d69fae8d7109ec450069 /plugins
parent83b48bb7331232020068d537716435458786a0cd (diff)
Fix Radio plugin linking, improve Radio code
Radio plugin now links correctly again (-lm was missing). Fix Radio plugin logic for new API, guard against some undefined values. Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/audio/audio-pulse.c2
-rw-r--r--plugins/radio/CMakeLists.txt2
-rw-r--r--plugins/radio/radio-api.c71
-rw-r--r--plugins/radio/radio-rtlsdr.c4
-rw-r--r--plugins/radio/radio-rtlsdr.h4
5 files changed, 58 insertions, 25 deletions
diff --git a/plugins/audio/audio-pulse.c b/plugins/audio/audio-pulse.c
index 89e5c21c..7f511be1 100644
--- a/plugins/audio/audio-pulse.c
+++ b/plugins/audio/audio-pulse.c
@@ -42,7 +42,7 @@ unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) {
/* allocate the global array if it hasn't been done */
if (!dev_ctx_p)
- dev_ctx_p = (dev_ctx_pulse_T**) malloc (sizeof(dev_ctx_pulse_T));
+ dev_ctx_p = (dev_ctx_pulse_T**) malloc (sizeof(dev_ctx_pulse_T*));
/* create a temporary device, to be held until sink gets discovered */
dev_ctx_pulse_T *dev_ctx_p_t = (dev_ctx_pulse_T*) malloc (sizeof(dev_ctx_pulse_T));
diff --git a/plugins/radio/CMakeLists.txt b/plugins/radio/CMakeLists.txt
index d86ca2b5..2aa765da 100644
--- a/plugins/radio/CMakeLists.txt
+++ b/plugins/radio/CMakeLists.txt
@@ -10,7 +10,7 @@ IF(librtlsdr_FOUND)
PREFIX ""
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map"
)
- TARGET_LINK_LIBRARIES(radio-api ${link_libraries} ${librtlsdr_LIBRARIES})
+ TARGET_LINK_LIBRARIES(radio-api ${link_libraries} ${librtlsdr_LIBRARIES} -lm)
INSTALL(TARGETS radio-api
LIBRARY DESTINATION ${plugin_install_dir})
diff --git a/plugins/radio/radio-api.c b/plugins/radio/radio-api.c
index 3ef098a9..0ed60e1c 100644
--- a/plugins/radio/radio-api.c
+++ b/plugins/radio/radio-api.c
@@ -43,8 +43,8 @@ void updateRadioDevList(pluginHandleT *handle) {
// loop on existing radio if any
for (idx = 0; idx < _radio_dev_count(); idx++) {
if (idx == MAX_RADIO) break;
- handle->radios[idx] = calloc(1, sizeof(radioDevT)); /* use calloc to set used to FALSE */
- handle->radios[idx]->name = (char *) _radio_dev_name(idx);
+ handle->radios[idx] = calloc(1, sizeof(radioDevT)); /* use calloc to set "used" to FALSE */
+ handle->radios[idx]->name = (char *) _radio_dev_name(idx);
}
handle->devCount = _radio_dev_count();
}
@@ -52,10 +52,11 @@ void updateRadioDevList(pluginHandleT *handle) {
/* global plugin context creation ; at loading time [radio devices might not be visible] */
static void initRadioPlugin() {
- pluginHandleT *handle = the_radio;
+ pluginHandleT *handle;
handle = calloc (1, sizeof(pluginHandleT));
updateRadioDevList (handle);
+ the_radio = handle;
}
/* private client context creation ; default values */
@@ -76,6 +77,7 @@ static radioCtxHandleT* initRadioCtx () {
/* reserve a radio device for requesting client, power it on */
unsigned char reserveRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
+
unsigned int idx;
/* loop on all devices, find an unused one */
@@ -85,8 +87,9 @@ unsigned char reserveRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
}
return 0;
- found_radio:
+ found_radio:
/* try to power it on, passing client context info such as frequency... */
+
_radio_on (idx, ctx);
/* TODO : try to re-iterate from the next ones if it failed ! */
@@ -134,9 +137,13 @@ static void freeRadio (void *context) {
static void init (struct afb_req request) { /* AFB_SESSION_CHECK */
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
json_object *jresp;
+ /* create a global plugin handle */
+ if (!the_radio)
+ initRadioPlugin();
+
/* create a private client context */
if (!ctx) {
ctx = initRadioCtx();
@@ -145,22 +152,29 @@ static void init (struct afb_req request) { /* AFB_SESSION_CHECK */
jresp = json_object_new_object();
json_object_object_add(jresp, "init", json_object_new_string ("success"));
- afb_req_success (request, jresp, "Radio - Initialized");
+ afb_req_success (request, jresp, "Radio initialized");
}
static void power (struct afb_req request) { /* AFB_SESSION_CHECK */
pluginHandleT *handle = the_radio;
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
const char *value = afb_req_value (request, "value");
json_object *jresp;
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
+ jresp = json_object_new_object();
+
/* no "?value=" parameter : return current state */
if (!value) {
- jresp = json_object_new_object();
ctx->radio ?
json_object_object_add (jresp, "power", json_object_new_string ("on"))
: json_object_object_add (jresp, "power", json_object_new_string ("off"));
+ afb_req_success (request, jresp, "Radio - Power status obtained");
+ return;
}
/* "?value=" parameter is "1" or "true" */
@@ -171,7 +185,6 @@ static void power (struct afb_req request) { /* AFB_SESSION_CHECK */
return;
}
}
- jresp = json_object_new_object();
json_object_object_add (jresp, "power", json_object_new_string ("on"));
}
@@ -183,7 +196,6 @@ static void power (struct afb_req request) { /* AFB_SESSION_CHECK */
return;
}
}
- jresp = json_object_new_object();
json_object_object_add (jresp, "power", json_object_new_string ("off"));
}
else
@@ -194,9 +206,15 @@ static void power (struct afb_req request) { /* AFB_SESSION_CHECK */
static void mode (struct afb_req request) { /* AFB_SESSION_CHECK */
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
const char *value = afb_req_value (request, "value");
- json_object *jresp = json_object_new_object();
+ json_object *jresp;
+
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
+ jresp = json_object_new_object();
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
@@ -224,12 +242,18 @@ static void mode (struct afb_req request) { /* AFB_SESSION_CHECK */
static void freq (struct afb_req request) { /* AFB_SESSION_CHECK */
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
const char *value = afb_req_value (request, "value");
- json_object *jresp = json_object_new_object();
+ json_object *jresp;
double freq;
char freq_str[256];
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
+ jresp = json_object_new_object();
+
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
@@ -251,10 +275,15 @@ static void freq (struct afb_req request) { /* AFB_SESSION_CHECK */
static void mute (struct afb_req request) { /* AFB_SESSION_CHECK */
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
const char *value = afb_req_value (request, "value");
json_object *jresp = json_object_new_object();
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
+
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
ctx->mute ?
@@ -281,9 +310,14 @@ static void mute (struct afb_req request) { /* AFB_SESSION_CHECK */
static void play (struct afb_req request) { /* AFB_SESSION_CHECK */
- radioCtxHandleT *ctx = (radioCtxHandleT*) afb_req_context_get(request);
+ radioCtxHandleT *ctx = afb_req_context_get (request);
const char *value = afb_req_value (request, "value");
json_object *jresp = json_object_new_object();
+
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
@@ -316,7 +350,7 @@ static void ping (struct afb_req request) { /* AFB_SESSION_NONE */
}
-static const struct AFB_verb_desc_v1 verbs[]= {
+static const struct AFB_verb_desc_v1 verbs[] = {
{"init" , AFB_SESSION_CHECK, init , "Radio API - init"},
{"power" , AFB_SESSION_CHECK, power , "Radio API - power"},
{"mode" , AFB_SESSION_CHECK, mode , "Radio API - mode"},
@@ -336,8 +370,7 @@ static const struct AFB_plugin pluginDesc = {
}
};
-const struct AFB_plugin *pluginAfbV1Entry (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
{
- initRadioPlugin();
return &pluginDesc;
}
diff --git a/plugins/radio/radio-rtlsdr.c b/plugins/radio/radio-rtlsdr.c
index 626ecbdd..7f76306e 100644
--- a/plugins/radio/radio-rtlsdr.c
+++ b/plugins/radio/radio-rtlsdr.c
@@ -23,6 +23,10 @@
#include "radio-api.h"
#include "radio-rtlsdr.h"
+static void* _dongle_thread_fn (void *);
+static void* _demod_thread_fn (void *);
+static void* _output_thread_fn (void *);
+
static unsigned int init_dev_count = 0;
static struct dev_ctx **dev_ctx = NULL;
diff --git a/plugins/radio/radio-rtlsdr.h b/plugins/radio/radio-rtlsdr.h
index ad22908d..2308f27e 100644
--- a/plugins/radio/radio-rtlsdr.h
+++ b/plugins/radio/radio-rtlsdr.h
@@ -97,8 +97,4 @@ void _radio_apply_params (struct dev_ctx *);
void _radio_start_threads (struct dev_ctx *);
void _radio_stop_threads (struct dev_ctx *);
-static void* _dongle_thread_fn (void *);
-static void* _demod_thread_fn (void *);
-static void* _output_thread_fn (void *);
-
#endif /* RADIO_RTLSDR_H */