Fix frequency setting bug in Radio API
authorManuel Bachmann <manuel.bachmann@iot.bzh>
Sun, 20 Dec 2015 22:00:56 +0000 (23:00 +0100)
committerManuel Bachmann <manuel.bachmann@iot.bzh>
Sun, 20 Dec 2015 22:00:56 +0000 (23:00 +0100)
Passing floats between functions seems to cause problems...
not sure why ; anyway, fix this by using a double variable.

Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
plugins/radio/radio-api.c
plugins/radio/radio-rtlsdr.c

index 3048f7b..3de8e04 100644 (file)
@@ -219,6 +219,7 @@ STATIC json_object* freq (AFB_request *request) {        /* AFB_SESSION_CHECK */
     radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
     const char *value = getQueryValue (request, "value");
     json_object *jresp = json_object_new_object();
+    double freq;
     char freq_str[256];
 
     /* no "?value=" parameter : return current state */
@@ -229,8 +230,9 @@ STATIC json_object* freq (AFB_request *request) {        /* AFB_SESSION_CHECK */
 
     /* "?value=" parameter, set frequency */
     else {
-        ctx->freq = strtof (value, NULL);
-        _radio_set_freq (ctx->idx, ctx->freq);
+        freq = strtod (value, NULL);
+        _radio_set_freq (ctx->idx, freq);
+        ctx->freq = (float)freq;
 
         snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
         json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
index e5a609e..bba0d89 100644 (file)
@@ -82,11 +82,11 @@ PUBLIC void _radio_set_mode (unsigned int num, Mode mode) {
     _radio_apply_params(dev_ctx[num]);
 }
 
-PUBLIC void _radio_set_freq (unsigned int num, float freq) {
+PUBLIC void _radio_set_freq (unsigned int num, double freq) {
     if (!dev_ctx || !dev_ctx[num])
         return;
 
-    dev_ctx[num]->freq = freq;
+    dev_ctx[num]->freq = (float)freq;
     _radio_apply_params(dev_ctx[num]);
 }