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>
/* allocate the global array if it hasn't been done */
if (!dev_ctx_p)
/* 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));
/* 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));
PREFIX ""
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map"
)
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})
INSTALL(TARGETS radio-api
LIBRARY DESTINATION ${plugin_install_dir})
// loop on existing radio if any
for (idx = 0; idx < _radio_dev_count(); idx++) {
if (idx == MAX_RADIO) break;
// 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();
}
}
handle->devCount = _radio_dev_count();
}
/* global plugin context creation ; at loading time [radio devices might not be visible] */
static void initRadioPlugin() {
/* global plugin context creation ; at loading time [radio devices might not be visible] */
static void initRadioPlugin() {
- pluginHandleT *handle = the_radio;
handle = calloc (1, sizeof(pluginHandleT));
updateRadioDevList (handle);
handle = calloc (1, sizeof(pluginHandleT));
updateRadioDevList (handle);
}
/* private client context creation ; default values */
}
/* private client context creation ; default values */
/* reserve a radio device for requesting client, power it on */
unsigned char reserveRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
/* 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 */
unsigned int idx;
/* loop on all devices, find an unused one */
/* try to power it on, passing client context info such as frequency... */
/* 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 ! */
_radio_on (idx, ctx);
/* TODO : try to re-iterate from the next ones if it failed ! */
static void init (struct afb_req request) { /* AFB_SESSION_CHECK */
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);
+ /* create a global plugin handle */
+ if (!the_radio)
+ initRadioPlugin();
+
/* create a private client context */
if (!ctx) {
ctx = initRadioCtx();
/* create a private client context */
if (!ctx) {
ctx = initRadioCtx();
jresp = json_object_new_object();
json_object_object_add(jresp, "init", json_object_new_string ("success"));
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;
}
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;
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) {
/* 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"));
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" */
}
/* "?value=" parameter is "1" or "true" */
- jresp = json_object_new_object();
json_object_object_add (jresp, "power", json_object_new_string ("on"));
}
json_object_object_add (jresp, "power", json_object_new_string ("on"));
}
- jresp = json_object_new_object();
json_object_object_add (jresp, "power", json_object_new_string ("off"));
}
else
json_object_object_add (jresp, "power", json_object_new_string ("off"));
}
else
static void mode (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");
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) {
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
static void freq (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");
const char *value = afb_req_value (request, "value");
- json_object *jresp = json_object_new_object();
double freq;
char freq_str[256];
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);
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
static void mute (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();
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 ?
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
ctx->mute ?
static void play (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();
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) {
/* no "?value=" parameter : return current state */
if (!value || !ctx->radio) {
-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"},
{"init" , AFB_SESSION_CHECK, init , "Radio API - init"},
{"power" , AFB_SESSION_CHECK, power , "Radio API - power"},
{"mode" , AFB_SESSION_CHECK, mode , "Radio API - mode"},
-const struct AFB_plugin *pluginAfbV1Entry (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
#include "radio-api.h"
#include "radio-rtlsdr.h"
#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;
static unsigned int init_dev_count = 0;
static struct dev_ctx **dev_ctx = NULL;
void _radio_start_threads (struct dev_ctx *);
void _radio_stop_threads (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 */
#endif /* RADIO_RTLSDR_H */